comparison app/helpers/timelog_helper.rb @ 1295:622f24f53b42 redmine-2.3

Update to Redmine SVN revision 11972 on 2.3-stable branch
author Chris Cannam
date Fri, 14 Jun 2013 09:02:21 +0100
parents 433d4f72a19b
children e248c7af89ec
comparison
equal deleted inserted replaced
1294:3e4c3460b6ca 1295:622f24f53b42
1 # encoding: utf-8 1 # encoding: utf-8
2 # 2 #
3 # Redmine - project management software 3 # Redmine - project management software
4 # Copyright (C) 2006-2012 Jean-Philippe Lang 4 # Copyright (C) 2006-2013 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.
54 activities.each { |a| collection << [a.name, a.id] } 54 activities.each { |a| collection << [a.name, a.id] }
55 collection 55 collection
56 end 56 end
57 57
58 def select_hours(data, criteria, value) 58 def select_hours(data, criteria, value)
59 if value.to_s.empty? 59 if value.to_s.empty?
60 data.select {|row| row[criteria].blank? } 60 data.select {|row| row[criteria].blank? }
61 else 61 else
62 data.select {|row| row[criteria].to_s == value.to_s} 62 data.select {|row| row[criteria].to_s == value.to_s}
63 end 63 end
64 end 64 end
65 65
66 def sum_hours(data) 66 def sum_hours(data)
67 sum = 0 67 sum = 0
84 [l(:label_last_n_days, 30), '30_days'], 84 [l(:label_last_n_days, 30), '30_days'],
85 [l(:label_this_year), 'current_year']], 85 [l(:label_this_year), 'current_year']],
86 value) 86 value)
87 end 87 end
88 88
89 def entries_to_csv(entries)
90 decimal_separator = l(:general_csv_decimal_separator)
91 custom_fields = TimeEntryCustomField.find(:all)
92 export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv|
93 # csv header fields
94 headers = [l(:field_spent_on),
95 l(:field_user),
96 l(:field_activity),
97 l(:field_project),
98 l(:field_issue),
99 l(:field_tracker),
100 l(:field_subject),
101 l(:field_hours),
102 l(:field_comments)
103 ]
104 # Export custom fields
105 headers += custom_fields.collect(&:name)
106
107 csv << headers.collect {|c| Redmine::CodesetUtil.from_utf8(
108 c.to_s,
109 l(:general_csv_encoding) ) }
110 # csv lines
111 entries.each do |entry|
112 fields = [format_date(entry.spent_on),
113 entry.user,
114 entry.activity,
115 entry.project,
116 (entry.issue ? entry.issue.id : nil),
117 (entry.issue ? entry.issue.tracker : nil),
118 (entry.issue ? entry.issue.subject : nil),
119 entry.hours.to_s.gsub('.', decimal_separator),
120 entry.comments
121 ]
122 fields += custom_fields.collect {|f| show_value(entry.custom_field_values.detect {|v| v.custom_field_id == f.id}) }
123
124 csv << fields.collect {|c| Redmine::CodesetUtil.from_utf8(
125 c.to_s,
126 l(:general_csv_encoding) ) }
127 end
128 end
129 export
130 end
131
132 def format_criteria_value(criteria_options, value) 89 def format_criteria_value(criteria_options, value)
133 if value.blank? 90 if value.blank?
134 "[#{l(:label_none)}]" 91 "[#{l(:label_none)}]"
135 elsif k = criteria_options[:klass] 92 elsif k = criteria_options[:klass]
136 obj = k.find_by_id(value.to_i) 93 obj = k.find_by_id(value.to_i)
148 decimal_separator = l(:general_csv_decimal_separator) 105 decimal_separator = l(:general_csv_decimal_separator)
149 export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv| 106 export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv|
150 # Column headers 107 # Column headers
151 headers = report.criteria.collect {|criteria| l(report.available_criteria[criteria][:label]) } 108 headers = report.criteria.collect {|criteria| l(report.available_criteria[criteria][:label]) }
152 headers += report.periods 109 headers += report.periods
153 headers << l(:label_total) 110 headers << l(:label_total_time)
154 csv << headers.collect {|c| Redmine::CodesetUtil.from_utf8( 111 csv << headers.collect {|c| Redmine::CodesetUtil.from_utf8(
155 c.to_s, 112 c.to_s,
156 l(:general_csv_encoding) ) } 113 l(:general_csv_encoding) ) }
157 # Content 114 # Content
158 report_criteria_to_csv(csv, report.available_criteria, report.columns, report.criteria, report.periods, report.hours) 115 report_criteria_to_csv(csv, report.available_criteria, report.columns, report.criteria, report.periods, report.hours)
159 # Total row 116 # Total row
160 str_total = Redmine::CodesetUtil.from_utf8(l(:label_total), l(:general_csv_encoding)) 117 str_total = Redmine::CodesetUtil.from_utf8(l(:label_total_time), l(:general_csv_encoding))
161 row = [ str_total ] + [''] * (report.criteria.size - 1) 118 row = [ str_total ] + [''] * (report.criteria.size - 1)
162 total = 0 119 total = 0
163 report.periods.each do |period| 120 report.periods.each do |period|
164 sum = sum_hours(select_hours(report.hours, report.columns, period.to_s)) 121 sum = sum_hours(select_hours(report.hours, report.columns, period.to_s))
165 total += sum 122 total += sum