##// END OF EJS Templates
Removed unnecessary calculations in time entries index....
Jean-Philippe Lang -
r7965:10509933486a
parent child
Show More
@@ -320,8 +320,6 private
320 320 end
321 321
322 322 @from, @to = @to, @from if @from && @to && @from > @to
323 @from ||= (TimeEntry.earilest_date_for_project(@project) || Date.today)
324 @to ||= (TimeEntry.latest_date_for_project(@project) || Date.today)
325 323 end
326 324
327 325 def parse_params_for_bulk_time_entry_attributes(params)
@@ -53,10 +53,18 class TimeEntry < ActiveRecord::Base
53 53 :include => :project,
54 54 :conditions => project.project_condition(include_subprojects)
55 55 }}
56 named_scope :spent_between, lambda {|from, to| {
57 :conditions => ["#{TimeEntry.table_name}.spent_on BETWEEN ? AND ?", from, to]
58 }}
59
56 named_scope :spent_between, lambda {|from, to|
57 if from && to
58 {:conditions => ["#{TimeEntry.table_name}.spent_on BETWEEN ? AND ?", from, to]}
59 elsif from
60 {:conditions => ["#{TimeEntry.table_name}.spent_on >= ?", from]}
61 elsif to
62 {:conditions => ["#{TimeEntry.table_name}.spent_on <= ?", to]}
63 else
64 {}
65 end
66 }
67
60 68 def after_initialize
61 69 if new_record? && self.activity.nil?
62 70 if default_activity = TimeEntryActivity.default
@@ -96,20 +104,4 class TimeEntry < ActiveRecord::Base
96 104 def editable_by?(usr)
97 105 (usr == user && usr.allowed_to?(:edit_own_time_entries, project)) || usr.allowed_to?(:edit_time_entries, project)
98 106 end
99
100 def self.earilest_date_for_project(project=nil)
101 finder_conditions = ARCondition.new(Project.allowed_to_condition(User.current, :view_time_entries))
102 if project
103 finder_conditions << ["project_id IN (?)", project.hierarchy.collect(&:id)]
104 end
105 TimeEntry.minimum(:spent_on, :include => :project, :conditions => finder_conditions.conditions)
106 end
107
108 def self.latest_date_for_project(project=nil)
109 finder_conditions = ARCondition.new(Project.allowed_to_condition(User.current, :view_time_entries))
110 if project
111 finder_conditions << ["project_id IN (?)", project.hierarchy.collect(&:id)]
112 end
113 TimeEntry.maximum(:spent_on, :include => :project, :conditions => finder_conditions.conditions)
114 end
115 107 end
@@ -270,8 +270,8 class TimelogControllerTest < ActionController::TestCase
270 270 assert_not_nil assigns(:total_hours)
271 271 assert_equal "162.90", "%.2f" % assigns(:total_hours)
272 272 # display all time by default
273 assert_equal '2007-03-12'.to_date, assigns(:from)
274 assert_equal '2007-04-22'.to_date, assigns(:to)
273 assert_nil assigns(:from)
274 assert_nil assigns(:to)
275 275 assert_tag :form,
276 276 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'}
277 277 end
@@ -320,9 +320,9 class TimelogControllerTest < ActionController::TestCase
320 320 assert_equal 2, assigns(:entries).size
321 321 assert_not_nil assigns(:total_hours)
322 322 assert_equal 154.25, assigns(:total_hours)
323 # display all time based on what's been logged
324 assert_equal '2007-03-12'.to_date, assigns(:from)
325 assert_equal '2007-04-22'.to_date, assigns(:to)
323 # display all time
324 assert_nil assigns(:from)
325 assert_nil assigns(:to)
326 326 # TODO: remove /projects/:project_id/issues/:issue_id/time_entries routes
327 327 # to use /issues/:issue_id/time_entries
328 328 assert_tag :form,
@@ -125,52 +125,4 class TimeEntryTest < ActiveSupport::TestCase
125 125 :activity => activity)
126 126 assert_equal project.id, te.project.id
127 127 end
128
129 context "#earilest_date_for_project" do
130 setup do
131 User.current = nil
132 @public_project = Project.generate!(:is_public => true)
133 @issue = Issue.generate_for_project!(@public_project)
134 TimeEntry.generate!(:spent_on => '2010-01-01',
135 :issue => @issue,
136 :project => @public_project)
137 end
138
139 context "without a project" do
140 should "return the lowest spent_on value that is visible to the current user" do
141 assert_equal "2007-03-12", TimeEntry.earilest_date_for_project.to_s
142 end
143 end
144
145 context "with a project" do
146 should "return the lowest spent_on value that is visible to the current user for that project and it's subprojects only" do
147 assert_equal "2010-01-01", TimeEntry.earilest_date_for_project(@public_project).to_s
148 end
149 end
150
151 end
152
153 context "#latest_date_for_project" do
154 setup do
155 User.current = nil
156 @public_project = Project.generate!(:is_public => true)
157 @issue = Issue.generate_for_project!(@public_project)
158 TimeEntry.generate!(:spent_on => '2010-01-01',
159 :issue => @issue,
160 :project => @public_project)
161 end
162
163 context "without a project" do
164 should "return the highest spent_on value that is visible to the current user" do
165 assert_equal "2010-01-01", TimeEntry.latest_date_for_project.to_s
166 end
167 end
168
169 context "with a project" do
170 should "return the highest spent_on value that is visible to the current user for that project and it's subprojects only" do
171 project = Project.find(1)
172 assert_equal "2007-04-22", TimeEntry.latest_date_for_project(project).to_s
173 end
174 end
175 end
176 128 end
General Comments 0
You need to be logged in to leave comments. Login now