diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-12-09 17:57:18 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-12-09 17:57:18 +0000 |
commit | f8895a7cdd9c53f3335825a45be1d53862693370 (patch) | |
tree | 2d75806f7fda54ccc9118cb1f69ff26c6fb541cd /lib/redmine/helpers | |
parent | 10998c9bae314057b5c2adf97418618f68efb3d7 (diff) | |
download | redmine-f8895a7cdd9c53f3335825a45be1d53862693370.tar.gz redmine-f8895a7cdd9c53f3335825a45be1d53862693370.zip |
Adds TimeEntryQuery for listing time entries.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10967 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib/redmine/helpers')
-rw-r--r-- | lib/redmine/helpers/time_report.rb | 27 |
1 files changed, 8 insertions, 19 deletions
diff --git a/lib/redmine/helpers/time_report.rb b/lib/redmine/helpers/time_report.rb index 2c29f6ac8..69a77e790 100644 --- a/lib/redmine/helpers/time_report.rb +++ b/lib/redmine/helpers/time_report.rb @@ -18,9 +18,9 @@ module Redmine module Helpers class TimeReport - attr_reader :criteria, :columns, :from, :to, :hours, :total_hours, :periods + attr_reader :criteria, :columns, :hours, :total_hours, :periods - def initialize(project, issue, criteria, columns, from, to) + def initialize(project, issue, criteria, columns, time_entry_scope) @project = project @issue = issue @@ -30,8 +30,7 @@ module Redmine @criteria = @criteria[0,3] @columns = (columns && %w(year month week day).include?(columns)) ? columns : 'month' - @from = from - @to = to + @scope = time_entry_scope run end @@ -44,15 +43,9 @@ module Redmine def run unless @criteria.empty? - scope = TimeEntry.visible.spent_between(@from, @to) - if @issue - scope = scope.on_issue(@issue) - elsif @project - scope = scope.on_project(@project, Setting.display_subprojects_issues?) - end time_columns = %w(tyear tmonth tweek spent_on) @hours = [] - scope.sum(:hours, :include => :issue, :group => @criteria.collect{|criteria| @available_criteria[criteria][:sql]} + time_columns).each do |hash, hours| + @scope.sum(:hours, :include => :issue, :group => @criteria.collect{|criteria| @available_criteria[criteria][:sql]} + time_columns).each do |hash, hours| h = {'hours' => hours} (@criteria + time_columns).each_with_index do |name, i| h[name] = hash[i] @@ -73,15 +66,11 @@ module Redmine end end - if @from.nil? - min = @hours.collect {|row| row['spent_on']}.min - @from = min ? min.to_date : Date.today - end + min = @hours.collect {|row| row['spent_on']}.min + @from = min ? min.to_date : Date.today - if @to.nil? - max = @hours.collect {|row| row['spent_on']}.max - @to = max ? max.to_date : Date.today - end + max = @hours.collect {|row| row['spent_on']}.max + @to = max ? max.to_date : Date.today @total_hours = @hours.inject(0) {|s,k| s = s + k['hours'].to_f} |