Mercurial > hg > soundsoftware-site
comparison app/helpers/timelog_helper.rb @ 1115:433d4f72a19b redmine-2.2
Update to Redmine SVN revision 11137 on 2.2-stable branch
author | Chris Cannam |
---|---|
date | Mon, 07 Jan 2013 12:01:42 +0000 |
parents | cbb26bc654de |
children | 622f24f53b42 |
comparison
equal
deleted
inserted
replaced
929:5f33065ddc4b | 1115:433d4f72a19b |
---|---|
1 # encoding: utf-8 | 1 # encoding: utf-8 |
2 # | 2 # |
3 # Redmine - project management software | 3 # Redmine - project management software |
4 # Copyright (C) 2006-2011 Jean-Philippe Lang | 4 # Copyright (C) 2006-2012 Jean-Philippe Lang |
5 # | 5 # |
6 # This program is free software; you can redistribute it and/or | 6 # This program is free software; you can redistribute it and/or |
7 # modify it under the terms of the GNU General Public License | 7 # modify it under the terms of the GNU General Public License |
8 # as published by the Free Software Foundation; either version 2 | 8 # as published by the Free Software Foundation; either version 2 |
9 # of the License, or (at your option) any later version. | 9 # of the License, or (at your option) any later version. |
75 options_for_select([[l(:label_all_time), 'all'], | 75 options_for_select([[l(:label_all_time), 'all'], |
76 [l(:label_today), 'today'], | 76 [l(:label_today), 'today'], |
77 [l(:label_yesterday), 'yesterday'], | 77 [l(:label_yesterday), 'yesterday'], |
78 [l(:label_this_week), 'current_week'], | 78 [l(:label_this_week), 'current_week'], |
79 [l(:label_last_week), 'last_week'], | 79 [l(:label_last_week), 'last_week'], |
80 [l(:label_last_n_weeks, 2), 'last_2_weeks'], | |
80 [l(:label_last_n_days, 7), '7_days'], | 81 [l(:label_last_n_days, 7), '7_days'], |
81 [l(:label_this_month), 'current_month'], | 82 [l(:label_this_month), 'current_month'], |
82 [l(:label_last_month), 'last_month'], | 83 [l(:label_last_month), 'last_month'], |
83 [l(:label_last_n_days, 30), '30_days'], | 84 [l(:label_last_n_days, 30), '30_days'], |
84 [l(:label_this_year), 'current_year']], | 85 [l(:label_this_year), 'current_year']], |
116 (entry.issue ? entry.issue.tracker : nil), | 117 (entry.issue ? entry.issue.tracker : nil), |
117 (entry.issue ? entry.issue.subject : nil), | 118 (entry.issue ? entry.issue.subject : nil), |
118 entry.hours.to_s.gsub('.', decimal_separator), | 119 entry.hours.to_s.gsub('.', decimal_separator), |
119 entry.comments | 120 entry.comments |
120 ] | 121 ] |
121 fields += custom_fields.collect {|f| show_value(entry.custom_value_for(f)) } | 122 fields += custom_fields.collect {|f| show_value(entry.custom_field_values.detect {|v| v.custom_field_id == f.id}) } |
122 | 123 |
123 csv << fields.collect {|c| Redmine::CodesetUtil.from_utf8( | 124 csv << fields.collect {|c| Redmine::CodesetUtil.from_utf8( |
124 c.to_s, | 125 c.to_s, |
125 l(:general_csv_encoding) ) } | 126 l(:general_csv_encoding) ) } |
126 end | 127 end |
127 end | 128 end |
128 export | 129 export |
129 end | 130 end |
130 | 131 |
131 def format_criteria_value(criteria, value) | 132 def format_criteria_value(criteria_options, value) |
132 if value.blank? | 133 if value.blank? |
133 l(:label_none) | 134 "[#{l(:label_none)}]" |
134 elsif k = @available_criterias[criteria][:klass] | 135 elsif k = criteria_options[:klass] |
135 obj = k.find_by_id(value.to_i) | 136 obj = k.find_by_id(value.to_i) |
136 if obj.is_a?(Issue) | 137 if obj.is_a?(Issue) |
137 obj.visible? ? "#{obj.tracker} ##{obj.id}: #{obj.subject}" : "##{obj.id}" | 138 obj.visible? ? "#{obj.tracker} ##{obj.id}: #{obj.subject}" : "##{obj.id}" |
138 else | 139 else |
139 obj | 140 obj |
140 end | 141 end |
141 else | 142 else |
142 format_value(value, @available_criterias[criteria][:format]) | 143 format_value(value, criteria_options[:format]) |
143 end | 144 end |
144 end | 145 end |
145 | 146 |
146 def report_to_csv(criterias, periods, hours) | 147 def report_to_csv(report) |
147 decimal_separator = l(:general_csv_decimal_separator) | 148 decimal_separator = l(:general_csv_decimal_separator) |
148 export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv| | 149 export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv| |
149 # Column headers | 150 # Column headers |
150 headers = criterias.collect {|criteria| l(@available_criterias[criteria][:label]) } | 151 headers = report.criteria.collect {|criteria| l(report.available_criteria[criteria][:label]) } |
151 headers += periods | 152 headers += report.periods |
152 headers << l(:label_total) | 153 headers << l(:label_total) |
153 csv << headers.collect {|c| Redmine::CodesetUtil.from_utf8( | 154 csv << headers.collect {|c| Redmine::CodesetUtil.from_utf8( |
154 c.to_s, | 155 c.to_s, |
155 l(:general_csv_encoding) ) } | 156 l(:general_csv_encoding) ) } |
156 # Content | 157 # Content |
157 report_criteria_to_csv(csv, criterias, periods, hours) | 158 report_criteria_to_csv(csv, report.available_criteria, report.columns, report.criteria, report.periods, report.hours) |
158 # Total row | 159 # Total row |
159 str_total = Redmine::CodesetUtil.from_utf8(l(:label_total), l(:general_csv_encoding)) | 160 str_total = Redmine::CodesetUtil.from_utf8(l(:label_total), l(:general_csv_encoding)) |
160 row = [ str_total ] + [''] * (criterias.size - 1) | 161 row = [ str_total ] + [''] * (report.criteria.size - 1) |
161 total = 0 | 162 total = 0 |
162 periods.each do |period| | 163 report.periods.each do |period| |
163 sum = sum_hours(select_hours(hours, @columns, period.to_s)) | 164 sum = sum_hours(select_hours(report.hours, report.columns, period.to_s)) |
164 total += sum | 165 total += sum |
165 row << (sum > 0 ? ("%.2f" % sum).gsub('.',decimal_separator) : '') | 166 row << (sum > 0 ? ("%.2f" % sum).gsub('.',decimal_separator) : '') |
166 end | 167 end |
167 row << ("%.2f" % total).gsub('.',decimal_separator) | 168 row << ("%.2f" % total).gsub('.',decimal_separator) |
168 csv << row | 169 csv << row |
169 end | 170 end |
170 export | 171 export |
171 end | 172 end |
172 | 173 |
173 def report_criteria_to_csv(csv, criterias, periods, hours, level=0) | 174 def report_criteria_to_csv(csv, available_criteria, columns, criteria, periods, hours, level=0) |
174 decimal_separator = l(:general_csv_decimal_separator) | 175 decimal_separator = l(:general_csv_decimal_separator) |
175 hours.collect {|h| h[criterias[level]].to_s}.uniq.each do |value| | 176 hours.collect {|h| h[criteria[level]].to_s}.uniq.each do |value| |
176 hours_for_value = select_hours(hours, criterias[level], value) | 177 hours_for_value = select_hours(hours, criteria[level], value) |
177 next if hours_for_value.empty? | 178 next if hours_for_value.empty? |
178 row = [''] * level | 179 row = [''] * level |
179 row << Redmine::CodesetUtil.from_utf8( | 180 row << Redmine::CodesetUtil.from_utf8( |
180 format_criteria_value(criterias[level], value).to_s, | 181 format_criteria_value(available_criteria[criteria[level]], value).to_s, |
181 l(:general_csv_encoding) ) | 182 l(:general_csv_encoding) ) |
182 row += [''] * (criterias.length - level - 1) | 183 row += [''] * (criteria.length - level - 1) |
183 total = 0 | 184 total = 0 |
184 periods.each do |period| | 185 periods.each do |period| |
185 sum = sum_hours(select_hours(hours_for_value, @columns, period.to_s)) | 186 sum = sum_hours(select_hours(hours_for_value, columns, period.to_s)) |
186 total += sum | 187 total += sum |
187 row << (sum > 0 ? ("%.2f" % sum).gsub('.',decimal_separator) : '') | 188 row << (sum > 0 ? ("%.2f" % sum).gsub('.',decimal_separator) : '') |
188 end | 189 end |
189 row << ("%.2f" % total).gsub('.',decimal_separator) | 190 row << ("%.2f" % total).gsub('.',decimal_separator) |
190 csv << row | 191 csv << row |
191 if criterias.length > level + 1 | 192 if criteria.length > level + 1 |
192 report_criteria_to_csv(csv, criterias, periods, hours_for_value, level + 1) | 193 report_criteria_to_csv(csv, available_criteria, columns, criteria, periods, hours_for_value, level + 1) |
193 end | 194 end |
194 end | 195 end |
195 end | 196 end |
196 end | 197 end |