<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -12,12 +12,13 @@ class TimesheetController &lt; ApplicationController
   include ApplicationHelper
   helper :timelog
 
+  SessionKey = 'timesheet_filter'
+
   def index
-    @from = Date.today.to_s
-    @to = Date.today.to_s
-    @timesheet = Timesheet.new
+    load_filters_from_session
+    @timesheet ||= Timesheet.new
     @timesheet.allowed_projects = allowed_projects
-    
+
     if @timesheet.allowed_projects.empty?
       render :action =&gt; 'no_projects'
       return
@@ -49,6 +50,8 @@ class TimesheetController &lt; ApplicationController
 
     call_hook(:plugin_timesheet_controller_report_pre_fetch_time_entries, { :timesheet =&gt; @timesheet, :params =&gt; params })
 
+    save_filters_to_session(@timesheet)
+
     @timesheet.fetch_time_entries
 
     # Sums
@@ -111,4 +114,29 @@ class TimesheetController &lt; ApplicationController
       return User.current.projects.find(:all, :order =&gt; 'name ASC')
     end
   end
+
+  def load_filters_from_session
+    if session[SessionKey]
+      @timesheet = Timesheet.new(session[SessionKey])
+      # Default to free period
+      @timesheet.period_type = Timesheet::ValidPeriodType[:free_period]
+    end
+
+    if session[SessionKey] &amp;&amp; session[SessionKey]['projects']
+      @timesheet.projects = allowed_projects.find_all { |project| 
+        session[SessionKey]['projects'].include?(project.id.to_s)
+      }
+    end
+  end
+
+  def save_filters_to_session(timesheet)
+    if params[:timesheet]
+      session[SessionKey] = params[:timesheet]
+    end
+
+    if timesheet
+      session[SessionKey]['date_from'] = timesheet.date_from
+      session[SessionKey]['date_to'] = timesheet.date_to
+    end
+  end
 end</diff>
      <filename>app/controllers/timesheet_controller.rb</filename>
    </modified>
    <modified>
      <diff>@@ -12,10 +12,10 @@
   &lt;%= radio_button_tag 'timesheet[period_type]', '2', @timesheet.period_type  == Timesheet::ValidPeriodType[:free_period] %&gt;
   &lt;span onclick=&quot;$('timesheet_period_type_2').checked = true;&quot;&gt;
     &lt;label for=&quot;timesheet_date_from&quot;&gt;&lt;%= l(:timesheet_date_from_label)%&gt;:&lt;/label&gt;&lt;br /&gt;
-    &lt;%= f.text_field &quot;date_from&quot;, :size =&gt; 10, :value =&gt; @from %&gt;&lt;%= calendar_for('timesheet_date_from') %&gt;&lt;br /&gt;
+    &lt;%= f.text_field &quot;date_from&quot;, :size =&gt; 10 %&gt;&lt;%= calendar_for('timesheet_date_from') %&gt;&lt;br /&gt;
 
     &lt;label for=&quot;timesheet_date_to&quot;&gt;&lt;%= l(:timesheet_date_to_label)%&gt;:&lt;/label&gt;&lt;br /&gt;
-    &lt;%= f.text_field &quot;date_to&quot;, :size =&gt; 10, :value =&gt; @to %&gt;&lt;%= calendar_for('timesheet_date_to') %&gt;&lt;br /&gt;&lt;br /&gt;
+    &lt;%= f.text_field &quot;date_to&quot;, :size =&gt; 10 %&gt;&lt;%= calendar_for('timesheet_date_to') %&gt;&lt;br /&gt;&lt;br /&gt;
   &lt;/span&gt;
 &lt;/p&gt;
 </diff>
      <filename>app/views/timesheet/_form.rhtml</filename>
    </modified>
    <modified>
      <diff>@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/../spec_helper'
 
 module TimesheetControllerHelper
   # Sets up the default mocks
-  def default_mocks
+  def default_mocks(options = {})
     # User
     @current_user = mock_model(User)
     @current_user.stub!(:admin?).and_return(false)
@@ -33,7 +33,8 @@ module TimesheetControllerHelper
     @timesheet.stub!(:time_entries).and_return([ ])
     @timesheet.stub!(:sort)
     @timesheet.stub!(:sort=)
-    stub_timesheet
+    @timesheet.stub!(:period_type=)
+    stub_timesheet unless options[:skip_timesheet_stub]
   end
   
   # Converts current user to admin
@@ -139,15 +140,29 @@ describe TimesheetController,&quot;#index with GET request&quot; do
     get 'index'
     response.should render_template('index')
   end
-  
-    it 'should set the from date to today' do
-    send_request
-    assigns[:from].should eql(Date.today.to_s)
-  end
+end
 
-  it 'should set the to date to today' do
-    send_request
-    assigns[:to].should eql(Date.today.to_s)
+describe TimesheetController,&quot;#index with GET request and a session&quot; do
+  include TimesheetControllerHelper
+  it 'should read the session data' do
+    default_mocks(:skip_timesheet_stub =&gt; true)
+
+    projects = []
+    4.times do |i|
+      projects &lt;&lt; mock_model(Project, :id =&gt; i + 1)
+    end
+    
+    controller.stub!(:allowed_projects).and_return(projects)
+    session[TimesheetController::SessionKey] = HashWithIndifferentAccess.new(
+      :projects =&gt; projects.collect(&amp;:id).collect(&amp;:to_s),
+      :date_to =&gt; '2009-01-01',
+      :date_from =&gt; '2009-01-01'
+    )
+
+    get :index
+    assigns[:timesheet].date_from.should eql('2009-01-01')
+    assigns[:timesheet].date_to.should eql('2009-01-01')
+    assigns[:timesheet].projects.should eql(projects)
   end
 end
 
@@ -216,6 +231,13 @@ describe TimesheetController,&quot;#report with POST request&quot; do
 
     post_report({ :timesheet =&gt; { :projects =&gt; ['1'] } })
   end
+
+  it 'should save the session data' do
+    post_report({ :timesheet =&gt; { :projects =&gt; ['1'] } })
+    session[TimesheetController::SessionKey].should_not be_nil
+    session[TimesheetController::SessionKey].keys.should include('projects')
+    session[TimesheetController::SessionKey]['projects'].should eql(['1'])
+  end
 end
 
 describe TimesheetController,&quot;#report with request with no data&quot; do</diff>
      <filename>spec/controllers/timesheet_controller_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>097a4184e2a7e5ab8d9a4d6c84e102ee23196c1c</id>
    </parent>
  </parents>
  <author>
    <name>Eric Davis</name>
    <email>edavis@littlestreamsoftware.com</email>
  </author>
  <url>http://github.com/edavis10/redmine-timesheet-plugin/commit/fbcdfd618274dc492b8132053b385fc75784b97b</url>
  <id>fbcdfd618274dc492b8132053b385fc75784b97b</id>
  <committed-date>2009-03-04T12:39:36-08:00</committed-date>
  <authored-date>2009-03-04T11:37:50-08:00</authored-date>
  <message>Store and retrieve the Timesheet filters in the session.

* Store filters to the session on report
* Read filters from the session on index
* Updated sticky filters so the dates are using the values from period.
* Use SessionKey constant
* Added spec for saving the session data.
* Added specs to test getting the filters from the session.</message>
  <tree>44ce058c6ef43b16762e17a2d2a73d44bbca1941</tree>
  <committer>
    <name>Eric Davis</name>
    <email>edavis@littlestreamsoftware.com</email>
  </committer>
</commit>
