@@ -1,23 +1,23 | |||||
1 |
# |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2011 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 |
# |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 |
# |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | module TimelogHelper |
|
18 | module TimelogHelper | |
19 | include ApplicationHelper |
|
19 | include ApplicationHelper | |
20 |
|
20 | |||
21 | def render_timelog_breadcrumb |
|
21 | def render_timelog_breadcrumb | |
22 | links = [] |
|
22 | links = [] | |
23 | links << link_to(l(:label_project_all), {:project_id => nil, :issue_id => nil}) |
|
23 | links << link_to(l(:label_project_all), {:project_id => nil, :issue_id => nil}) | |
@@ -52,15 +52,15 module TimelogHelper | |||||
52 | activities.each { |a| collection << [a.name, a.id] } |
|
52 | activities.each { |a| collection << [a.name, a.id] } | |
53 | collection |
|
53 | collection | |
54 | end |
|
54 | end | |
55 |
|
55 | |||
56 | def select_hours(data, criteria, value) |
|
56 | def select_hours(data, criteria, value) | |
57 | if value.to_s.empty? |
|
57 | if value.to_s.empty? | |
58 | data.select {|row| row[criteria].blank? } |
|
58 | data.select {|row| row[criteria].blank? } | |
59 |
else |
|
59 | else | |
60 | data.select {|row| row[criteria].to_s == value.to_s} |
|
60 | data.select {|row| row[criteria].to_s == value.to_s} | |
61 | end |
|
61 | end | |
62 | end |
|
62 | end | |
63 |
|
63 | |||
64 | def sum_hours(data) |
|
64 | def sum_hours(data) | |
65 | sum = 0 |
|
65 | sum = 0 | |
66 | data.each do |row| |
|
66 | data.each do |row| | |
@@ -68,7 +68,7 module TimelogHelper | |||||
68 | end |
|
68 | end | |
69 | sum |
|
69 | sum | |
70 | end |
|
70 | end | |
71 |
|
71 | |||
72 | def options_for_period_select(value) |
|
72 | def options_for_period_select(value) | |
73 | options_for_select([[l(:label_all_time), 'all'], |
|
73 | options_for_select([[l(:label_all_time), 'all'], | |
74 | [l(:label_today), 'today'], |
|
74 | [l(:label_today), 'today'], | |
@@ -82,9 +82,9 module TimelogHelper | |||||
82 | [l(:label_this_year), 'current_year']], |
|
82 | [l(:label_this_year), 'current_year']], | |
83 | value) |
|
83 | value) | |
84 | end |
|
84 | end | |
85 |
|
85 | |||
86 | def entries_to_csv(entries) |
|
86 | def entries_to_csv(entries) | |
87 |
ic = Iconv.new(l(:general_csv_encoding), 'UTF-8') |
|
87 | ic = Iconv.new(l(:general_csv_encoding), 'UTF-8') | |
88 | decimal_separator = l(:general_csv_decimal_separator) |
|
88 | decimal_separator = l(:general_csv_decimal_separator) | |
89 | custom_fields = TimeEntryCustomField.find(:all) |
|
89 | custom_fields = TimeEntryCustomField.find(:all) | |
90 | export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv| |
|
90 | export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv| | |
@@ -101,7 +101,7 module TimelogHelper | |||||
101 | ] |
|
101 | ] | |
102 | # Export custom fields |
|
102 | # Export custom fields | |
103 | headers += custom_fields.collect(&:name) |
|
103 | headers += custom_fields.collect(&:name) | |
104 |
|
104 | |||
105 | csv << headers.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end } |
|
105 | csv << headers.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end } | |
106 | # csv lines |
|
106 | # csv lines | |
107 | entries.each do |entry| |
|
107 | entries.each do |entry| | |
@@ -116,13 +116,13 module TimelogHelper | |||||
116 | entry.comments |
|
116 | entry.comments | |
117 | ] |
|
117 | ] | |
118 | fields += custom_fields.collect {|f| show_value(entry.custom_value_for(f)) } |
|
118 | fields += custom_fields.collect {|f| show_value(entry.custom_value_for(f)) } | |
119 |
|
119 | |||
120 | csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end } |
|
120 | csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end } | |
121 | end |
|
121 | end | |
122 | end |
|
122 | end | |
123 | export |
|
123 | export | |
124 | end |
|
124 | end | |
125 |
|
125 | |||
126 | def format_criteria_value(criteria, value) |
|
126 | def format_criteria_value(criteria, value) | |
127 | if value.blank? |
|
127 | if value.blank? | |
128 | l(:label_none) |
|
128 | l(:label_none) | |
@@ -137,7 +137,7 module TimelogHelper | |||||
137 | format_value(value, @available_criterias[criteria][:format]) |
|
137 | format_value(value, @available_criterias[criteria][:format]) | |
138 | end |
|
138 | end | |
139 | end |
|
139 | end | |
140 |
|
140 | |||
141 | def report_to_csv(criterias, periods, hours) |
|
141 | def report_to_csv(criterias, periods, hours) | |
142 | export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv| |
|
142 | export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv| | |
143 | # Column headers |
|
143 | # Column headers | |
@@ -160,7 +160,7 module TimelogHelper | |||||
160 | end |
|
160 | end | |
161 | export |
|
161 | export | |
162 | end |
|
162 | end | |
163 |
|
163 | |||
164 | def report_criteria_to_csv(csv, criterias, periods, hours, level=0) |
|
164 | def report_criteria_to_csv(csv, criterias, periods, hours, level=0) | |
165 | hours.collect {|h| h[criterias[level]].to_s}.uniq.each do |value| |
|
165 | hours.collect {|h| h[criterias[level]].to_s}.uniq.each do |value| | |
166 | hours_for_value = select_hours(hours, criterias[level], value) |
|
166 | hours_for_value = select_hours(hours, criterias[level], value) | |
@@ -176,13 +176,13 module TimelogHelper | |||||
176 | end |
|
176 | end | |
177 | row << "%.2f" %total |
|
177 | row << "%.2f" %total | |
178 | csv << row |
|
178 | csv << row | |
179 |
|
179 | |||
180 | if criterias.length > level + 1 |
|
180 | if criterias.length > level + 1 | |
181 | report_criteria_to_csv(csv, criterias, periods, hours_for_value, level + 1) |
|
181 | report_criteria_to_csv(csv, criterias, periods, hours_for_value, level + 1) | |
182 | end |
|
182 | end | |
183 | end |
|
183 | end | |
184 | end |
|
184 | end | |
185 |
|
185 | |||
186 | def to_utf8(s) |
|
186 | def to_utf8(s) | |
187 | @ic ||= Iconv.new(l(:general_csv_encoding), 'UTF-8') |
|
187 | @ic ||= Iconv.new(l(:general_csv_encoding), 'UTF-8') | |
188 | begin; @ic.iconv(s.to_s); rescue; s.to_s; end |
|
188 | begin; @ic.iconv(s.to_s); rescue; s.to_s; end |
General Comments 0
You need to be logged in to leave comments.
Login now