##// END OF EJS Templates
Change the TimelogController's to/from dates based on the project time entries...
Eric Davis -
r3973:cdfc57d5442f
parent child
Show More
@@ -260,8 +260,8 private
260 260 end
261 261
262 262 @from, @to = @to, @from if @from && @to && @from > @to
263 @from ||= (TimeEntry.earilest_date_for_project || Date.today) - 1
264 @to ||= (TimeEntry.latest_date_for_project || Date.today)
263 @from ||= (TimeEntry.earilest_date_for_project(@project) || Date.today)
264 @to ||= (TimeEntry.latest_date_for_project(@project) || Date.today)
265 265 end
266 266
267 267 def load_available_criterias
@@ -494,6 +494,15 class Project < ActiveRecord::Base
494 494 end
495 495 end
496 496
497 # Returns an array of projects that are in this project's hierarchy
498 #
499 # Example: parents, children, siblings
500 def hierarchy
501 parents = project.self_and_ancestors || []
502 descendants = project.descendants || []
503 project_hierarchy = parents | descendants # Set union
504 end
505
497 506 # Returns an auto-generated project identifier based on the last identifier used
498 507 def self.next_identifier
499 508 p = Project.find(:first, :order => 'created_on DESC')
@@ -82,11 +82,19 class TimeEntry < ActiveRecord::Base
82 82 end
83 83 end
84 84
85 def self.earilest_date_for_project
86 TimeEntry.minimum(:spent_on, :include => :project, :conditions => Project.allowed_to_condition(User.current, :view_time_entries))
85 def self.earilest_date_for_project(project=nil)
86 finder_conditions = ARCondition.new(Project.allowed_to_condition(User.current, :view_time_entries))
87 if project
88 finder_conditions << ["project_id IN (?)", project.hierarchy.collect(&:id)]
89 end
90 TimeEntry.minimum(:spent_on, :include => :project, :conditions => finder_conditions.conditions)
87 91 end
88 92
89 def self.latest_date_for_project
90 TimeEntry.maximum(:spent_on, :include => :project, :conditions => Project.allowed_to_condition(User.current, :view_time_entries))
93 def self.latest_date_for_project(project=nil)
94 finder_conditions = ARCondition.new(Project.allowed_to_condition(User.current, :view_time_entries))
95 if project
96 finder_conditions << ["project_id IN (?)", project.hierarchy.collect(&:id)]
97 end
98 TimeEntry.maximum(:spent_on, :include => :project, :conditions => finder_conditions.conditions)
91 99 end
92 100 end
@@ -283,7 +283,7 class TimelogControllerTest < ActionController::TestCase
283 283 assert_not_nil assigns(:total_hours)
284 284 assert_equal "162.90", "%.2f" % assigns(:total_hours)
285 285 # display all time by default
286 assert_equal '2007-03-11'.to_date, assigns(:from)
286 assert_equal '2007-03-12'.to_date, assigns(:from)
287 287 assert_equal '2007-04-22'.to_date, assigns(:to)
288 288 end
289 289
@@ -325,8 +325,8 class TimelogControllerTest < ActionController::TestCase
325 325 assert_equal 2, assigns(:entries).size
326 326 assert_not_nil assigns(:total_hours)
327 327 assert_equal 154.25, assigns(:total_hours)
328 # display all time by default
329 assert_equal '2007-03-11'.to_date, assigns(:from)
328 # display all time based on what's been logged
329 assert_equal '2007-03-12'.to_date, assigns(:from)
330 330 assert_equal '2007-04-22'.to_date, assigns(:to)
331 331 end
332 332
@@ -50,17 +50,50 class TimeEntryTest < ActiveSupport::TestCase
50 50 end
51 51
52 52 context "#earilest_date_for_project" do
53 should "return the lowest spent_on value that is visible to the current user" do
53 setup do
54 54 User.current = nil
55 @public_project = Project.generate!(:is_public => true)
56 @issue = Issue.generate_for_project!(@public_project)
57 TimeEntry.generate!(:spent_on => '2010-01-01',
58 :issue => @issue,
59 :project => @public_project)
60 end
61
62 context "without a project" do
63 should "return the lowest spent_on value that is visible to the current user" do
55 64 assert_equal "2007-03-12", TimeEntry.earilest_date_for_project.to_s
56 65 end
57 66 end
58 67
68 context "with a project" do
69 should "return the lowest spent_on value that is visible to the current user for that project and it's subprojects only" do
70 assert_equal "2010-01-01", TimeEntry.earilest_date_for_project(@public_project).to_s
71 end
72 end
73
74 end
75
59 76 context "#latest_date_for_project" do
60 should "return the highest spent_on value that is visible to the current user" do
77 setup do
61 78 User.current = nil
62 assert_equal "2007-04-22", TimeEntry.latest_date_for_project.to_s
79 @public_project = Project.generate!(:is_public => true)
80 @issue = Issue.generate_for_project!(@public_project)
81 TimeEntry.generate!(:spent_on => '2010-01-01',
82 :issue => @issue,
83 :project => @public_project)
84 end
85
86 context "without a project" do
87 should "return the highest spent_on value that is visible to the current user" do
88 assert_equal "2010-01-01", TimeEntry.latest_date_for_project.to_s
63 89 end
64 90 end
65 91
92 context "with a project" do
93 should "return the highest spent_on value that is visible to the current user for that project and it's subprojects only" do
94 project = Project.find(1)
95 assert_equal "2007-04-22", TimeEntry.latest_date_for_project(project).to_s
96 end
97 end
98 end
66 99 end
General Comments 0
You need to be logged in to leave comments. Login now