annotate .svn/pristine/c2/c2f664eacfc767a5b14fde34eb8558e5bf4aa322.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

Fix failure to interpret Javascript when autocompleting members for project
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Thu, 11 Sep 2014 10:24:38 +0100
parents dffacf8a6908
children
rev   line source
Chris@1517 1 # Redmine - project management software
Chris@1517 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
Chris@1517 3 #
Chris@1517 4 # This program is free software; you can redistribute it and/or
Chris@1517 5 # modify it under the terms of the GNU General Public License
Chris@1517 6 # as published by the Free Software Foundation; either version 2
Chris@1517 7 # of the License, or (at your option) any later version.
Chris@1517 8 #
Chris@1517 9 # This program is distributed in the hope that it will be useful,
Chris@1517 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1517 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1517 12 # GNU General Public License for more details.
Chris@1517 13 #
Chris@1517 14 # You should have received a copy of the GNU General Public License
Chris@1517 15 # along with this program; if not, write to the Free Software
Chris@1517 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1517 17
Chris@1517 18 module Redmine
Chris@1517 19 module Helpers
Chris@1517 20 class TimeReport
Chris@1517 21 attr_reader :criteria, :columns, :hours, :total_hours, :periods
Chris@1517 22
Chris@1517 23 def initialize(project, issue, criteria, columns, time_entry_scope)
Chris@1517 24 @project = project
Chris@1517 25 @issue = issue
Chris@1517 26
Chris@1517 27 @criteria = criteria || []
Chris@1517 28 @criteria = @criteria.select{|criteria| available_criteria.has_key? criteria}
Chris@1517 29 @criteria.uniq!
Chris@1517 30 @criteria = @criteria[0,3]
Chris@1517 31
Chris@1517 32 @columns = (columns && %w(year month week day).include?(columns)) ? columns : 'month'
Chris@1517 33 @scope = time_entry_scope
Chris@1517 34
Chris@1517 35 run
Chris@1517 36 end
Chris@1517 37
Chris@1517 38 def available_criteria
Chris@1517 39 @available_criteria || load_available_criteria
Chris@1517 40 end
Chris@1517 41
Chris@1517 42 private
Chris@1517 43
Chris@1517 44 def run
Chris@1517 45 unless @criteria.empty?
Chris@1517 46 time_columns = %w(tyear tmonth tweek spent_on)
Chris@1517 47 @hours = []
Chris@1517 48 @scope.includes(:issue, :activity).
Chris@1517 49 group(@criteria.collect{|criteria| @available_criteria[criteria][:sql]} + time_columns).
Chris@1517 50 joins(@criteria.collect{|criteria| @available_criteria[criteria][:joins]}.compact).
Chris@1517 51 sum(:hours).each do |hash, hours|
Chris@1517 52 h = {'hours' => hours}
Chris@1517 53 (@criteria + time_columns).each_with_index do |name, i|
Chris@1517 54 h[name] = hash[i]
Chris@1517 55 end
Chris@1517 56 @hours << h
Chris@1517 57 end
Chris@1517 58
Chris@1517 59 @hours.each do |row|
Chris@1517 60 case @columns
Chris@1517 61 when 'year'
Chris@1517 62 row['year'] = row['tyear']
Chris@1517 63 when 'month'
Chris@1517 64 row['month'] = "#{row['tyear']}-#{row['tmonth']}"
Chris@1517 65 when 'week'
Chris@1517 66 row['week'] = "#{row['spent_on'].cwyear}-#{row['tweek']}"
Chris@1517 67 when 'day'
Chris@1517 68 row['day'] = "#{row['spent_on']}"
Chris@1517 69 end
Chris@1517 70 end
Chris@1517 71
Chris@1517 72 min = @hours.collect {|row| row['spent_on']}.min
Chris@1517 73 @from = min ? min.to_date : Date.today
Chris@1517 74
Chris@1517 75 max = @hours.collect {|row| row['spent_on']}.max
Chris@1517 76 @to = max ? max.to_date : Date.today
Chris@1517 77
Chris@1517 78 @total_hours = @hours.inject(0) {|s,k| s = s + k['hours'].to_f}
Chris@1517 79
Chris@1517 80 @periods = []
Chris@1517 81 # Date#at_beginning_of_ not supported in Rails 1.2.x
Chris@1517 82 date_from = @from.to_time
Chris@1517 83 # 100 columns max
Chris@1517 84 while date_from <= @to.to_time && @periods.length < 100
Chris@1517 85 case @columns
Chris@1517 86 when 'year'
Chris@1517 87 @periods << "#{date_from.year}"
Chris@1517 88 date_from = (date_from + 1.year).at_beginning_of_year
Chris@1517 89 when 'month'
Chris@1517 90 @periods << "#{date_from.year}-#{date_from.month}"
Chris@1517 91 date_from = (date_from + 1.month).at_beginning_of_month
Chris@1517 92 when 'week'
Chris@1517 93 @periods << "#{date_from.to_date.cwyear}-#{date_from.to_date.cweek}"
Chris@1517 94 date_from = (date_from + 7.day).at_beginning_of_week
Chris@1517 95 when 'day'
Chris@1517 96 @periods << "#{date_from.to_date}"
Chris@1517 97 date_from = date_from + 1.day
Chris@1517 98 end
Chris@1517 99 end
Chris@1517 100 end
Chris@1517 101 end
Chris@1517 102
Chris@1517 103 def load_available_criteria
Chris@1517 104 @available_criteria = { 'project' => {:sql => "#{TimeEntry.table_name}.project_id",
Chris@1517 105 :klass => Project,
Chris@1517 106 :label => :label_project},
Chris@1517 107 'status' => {:sql => "#{Issue.table_name}.status_id",
Chris@1517 108 :klass => IssueStatus,
Chris@1517 109 :label => :field_status},
Chris@1517 110 'version' => {:sql => "#{Issue.table_name}.fixed_version_id",
Chris@1517 111 :klass => Version,
Chris@1517 112 :label => :label_version},
Chris@1517 113 'category' => {:sql => "#{Issue.table_name}.category_id",
Chris@1517 114 :klass => IssueCategory,
Chris@1517 115 :label => :field_category},
Chris@1517 116 'user' => {:sql => "#{TimeEntry.table_name}.user_id",
Chris@1517 117 :klass => User,
Chris@1517 118 :label => :label_user},
Chris@1517 119 'tracker' => {:sql => "#{Issue.table_name}.tracker_id",
Chris@1517 120 :klass => Tracker,
Chris@1517 121 :label => :label_tracker},
Chris@1517 122 'activity' => {:sql => "#{TimeEntry.table_name}.activity_id",
Chris@1517 123 :klass => TimeEntryActivity,
Chris@1517 124 :label => :label_activity},
Chris@1517 125 'issue' => {:sql => "#{TimeEntry.table_name}.issue_id",
Chris@1517 126 :klass => Issue,
Chris@1517 127 :label => :label_issue}
Chris@1517 128 }
Chris@1517 129
Chris@1517 130 # Add time entry custom fields
Chris@1517 131 custom_fields = TimeEntryCustomField.all
Chris@1517 132 # Add project custom fields
Chris@1517 133 custom_fields += ProjectCustomField.all
Chris@1517 134 # Add issue custom fields
Chris@1517 135 custom_fields += (@project.nil? ? IssueCustomField.for_all : @project.all_issue_custom_fields)
Chris@1517 136 # Add time entry activity custom fields
Chris@1517 137 custom_fields += TimeEntryActivityCustomField.all
Chris@1517 138
Chris@1517 139 # Add list and boolean custom fields as available criteria
Chris@1517 140 custom_fields.select {|cf| %w(list bool).include?(cf.field_format) && !cf.multiple?}.each do |cf|
Chris@1517 141 @available_criteria["cf_#{cf.id}"] = {:sql => cf.group_statement,
Chris@1517 142 :joins => cf.join_for_order_statement,
Chris@1517 143 :format => cf.field_format,
Chris@1517 144 :custom_field => cf,
Chris@1517 145 :label => cf.name}
Chris@1517 146 end
Chris@1517 147
Chris@1517 148 @available_criteria
Chris@1517 149 end
Chris@1517 150 end
Chris@1517 151 end
Chris@1517 152 end