##// END OF EJS Templates
Adds double quotes around issue change details in plain text notifications (#10603)....
Jean-Philippe Lang -
r9234:1334cbf78c1d
parent child
Show More
@@ -1,354 +1,359
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-2011 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.
10 #
10 #
11 # This program is distributed in the hope that it will be useful,
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
14 # GNU General Public License for more details.
15 #
15 #
16 # You should have received a copy of the GNU General Public License
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
19
20 module IssuesHelper
20 module IssuesHelper
21 include ApplicationHelper
21 include ApplicationHelper
22
22
23 def issue_list(issues, &block)
23 def issue_list(issues, &block)
24 ancestors = []
24 ancestors = []
25 issues.each do |issue|
25 issues.each do |issue|
26 while (ancestors.any? && !issue.is_descendant_of?(ancestors.last))
26 while (ancestors.any? && !issue.is_descendant_of?(ancestors.last))
27 ancestors.pop
27 ancestors.pop
28 end
28 end
29 yield issue, ancestors.size
29 yield issue, ancestors.size
30 ancestors << issue unless issue.leaf?
30 ancestors << issue unless issue.leaf?
31 end
31 end
32 end
32 end
33
33
34 # Renders a HTML/CSS tooltip
34 # Renders a HTML/CSS tooltip
35 #
35 #
36 # To use, a trigger div is needed. This is a div with the class of "tooltip"
36 # To use, a trigger div is needed. This is a div with the class of "tooltip"
37 # that contains this method wrapped in a span with the class of "tip"
37 # that contains this method wrapped in a span with the class of "tip"
38 #
38 #
39 # <div class="tooltip"><%= link_to_issue(issue) %>
39 # <div class="tooltip"><%= link_to_issue(issue) %>
40 # <span class="tip"><%= render_issue_tooltip(issue) %></span>
40 # <span class="tip"><%= render_issue_tooltip(issue) %></span>
41 # </div>
41 # </div>
42 #
42 #
43 def render_issue_tooltip(issue)
43 def render_issue_tooltip(issue)
44 @cached_label_status ||= l(:field_status)
44 @cached_label_status ||= l(:field_status)
45 @cached_label_start_date ||= l(:field_start_date)
45 @cached_label_start_date ||= l(:field_start_date)
46 @cached_label_due_date ||= l(:field_due_date)
46 @cached_label_due_date ||= l(:field_due_date)
47 @cached_label_assigned_to ||= l(:field_assigned_to)
47 @cached_label_assigned_to ||= l(:field_assigned_to)
48 @cached_label_priority ||= l(:field_priority)
48 @cached_label_priority ||= l(:field_priority)
49 @cached_label_project ||= l(:field_project)
49 @cached_label_project ||= l(:field_project)
50
50
51 link_to_issue(issue) + "<br /><br />".html_safe +
51 link_to_issue(issue) + "<br /><br />".html_safe +
52 "<strong>#{@cached_label_project}</strong>: #{link_to_project(issue.project)}<br />".html_safe +
52 "<strong>#{@cached_label_project}</strong>: #{link_to_project(issue.project)}<br />".html_safe +
53 "<strong>#{@cached_label_status}</strong>: #{h(issue.status.name)}<br />".html_safe +
53 "<strong>#{@cached_label_status}</strong>: #{h(issue.status.name)}<br />".html_safe +
54 "<strong>#{@cached_label_start_date}</strong>: #{format_date(issue.start_date)}<br />".html_safe +
54 "<strong>#{@cached_label_start_date}</strong>: #{format_date(issue.start_date)}<br />".html_safe +
55 "<strong>#{@cached_label_due_date}</strong>: #{format_date(issue.due_date)}<br />".html_safe +
55 "<strong>#{@cached_label_due_date}</strong>: #{format_date(issue.due_date)}<br />".html_safe +
56 "<strong>#{@cached_label_assigned_to}</strong>: #{h(issue.assigned_to)}<br />".html_safe +
56 "<strong>#{@cached_label_assigned_to}</strong>: #{h(issue.assigned_to)}<br />".html_safe +
57 "<strong>#{@cached_label_priority}</strong>: #{h(issue.priority.name)}".html_safe
57 "<strong>#{@cached_label_priority}</strong>: #{h(issue.priority.name)}".html_safe
58 end
58 end
59
59
60 def issue_heading(issue)
60 def issue_heading(issue)
61 h("#{issue.tracker} ##{issue.id}")
61 h("#{issue.tracker} ##{issue.id}")
62 end
62 end
63
63
64 def render_issue_subject_with_tree(issue)
64 def render_issue_subject_with_tree(issue)
65 s = ''
65 s = ''
66 ancestors = issue.root? ? [] : issue.ancestors.visible.all
66 ancestors = issue.root? ? [] : issue.ancestors.visible.all
67 ancestors.each do |ancestor|
67 ancestors.each do |ancestor|
68 s << '<div>' + content_tag('p', link_to_issue(ancestor))
68 s << '<div>' + content_tag('p', link_to_issue(ancestor))
69 end
69 end
70 s << '<div>'
70 s << '<div>'
71 subject = h(issue.subject)
71 subject = h(issue.subject)
72 if issue.is_private?
72 if issue.is_private?
73 subject = content_tag('span', l(:field_is_private), :class => 'private') + ' ' + subject
73 subject = content_tag('span', l(:field_is_private), :class => 'private') + ' ' + subject
74 end
74 end
75 s << content_tag('h3', subject)
75 s << content_tag('h3', subject)
76 s << '</div>' * (ancestors.size + 1)
76 s << '</div>' * (ancestors.size + 1)
77 s.html_safe
77 s.html_safe
78 end
78 end
79
79
80 def render_descendants_tree(issue)
80 def render_descendants_tree(issue)
81 s = '<form><table class="list issues">'
81 s = '<form><table class="list issues">'
82 issue_list(issue.descendants.visible.sort_by(&:lft)) do |child, level|
82 issue_list(issue.descendants.visible.sort_by(&:lft)) do |child, level|
83 s << content_tag('tr',
83 s << content_tag('tr',
84 content_tag('td', check_box_tag("ids[]", child.id, false, :id => nil), :class => 'checkbox') +
84 content_tag('td', check_box_tag("ids[]", child.id, false, :id => nil), :class => 'checkbox') +
85 content_tag('td', link_to_issue(child, :truncate => 60), :class => 'subject') +
85 content_tag('td', link_to_issue(child, :truncate => 60), :class => 'subject') +
86 content_tag('td', h(child.status)) +
86 content_tag('td', h(child.status)) +
87 content_tag('td', link_to_user(child.assigned_to)) +
87 content_tag('td', link_to_user(child.assigned_to)) +
88 content_tag('td', progress_bar(child.done_ratio, :width => '80px')),
88 content_tag('td', progress_bar(child.done_ratio, :width => '80px')),
89 :class => "issue issue-#{child.id} hascontextmenu #{level > 0 ? "idnt idnt-#{level}" : nil}")
89 :class => "issue issue-#{child.id} hascontextmenu #{level > 0 ? "idnt idnt-#{level}" : nil}")
90 end
90 end
91 s << '</table></form>'
91 s << '</table></form>'
92 s.html_safe
92 s.html_safe
93 end
93 end
94
94
95 def render_custom_fields_rows(issue)
95 def render_custom_fields_rows(issue)
96 return if issue.custom_field_values.empty?
96 return if issue.custom_field_values.empty?
97 ordered_values = []
97 ordered_values = []
98 half = (issue.custom_field_values.size / 2.0).ceil
98 half = (issue.custom_field_values.size / 2.0).ceil
99 half.times do |i|
99 half.times do |i|
100 ordered_values << issue.custom_field_values[i]
100 ordered_values << issue.custom_field_values[i]
101 ordered_values << issue.custom_field_values[i + half]
101 ordered_values << issue.custom_field_values[i + half]
102 end
102 end
103 s = "<tr>\n"
103 s = "<tr>\n"
104 n = 0
104 n = 0
105 ordered_values.compact.each do |value|
105 ordered_values.compact.each do |value|
106 s << "</tr>\n<tr>\n" if n > 0 && (n % 2) == 0
106 s << "</tr>\n<tr>\n" if n > 0 && (n % 2) == 0
107 s << "\t<th>#{ h(value.custom_field.name) }:</th><td>#{ simple_format_without_paragraph(h(show_value(value))) }</td>\n"
107 s << "\t<th>#{ h(value.custom_field.name) }:</th><td>#{ simple_format_without_paragraph(h(show_value(value))) }</td>\n"
108 n += 1
108 n += 1
109 end
109 end
110 s << "</tr>\n"
110 s << "</tr>\n"
111 s.html_safe
111 s.html_safe
112 end
112 end
113
113
114 def issues_destroy_confirmation_message(issues)
114 def issues_destroy_confirmation_message(issues)
115 issues = [issues] unless issues.is_a?(Array)
115 issues = [issues] unless issues.is_a?(Array)
116 message = l(:text_issues_destroy_confirmation)
116 message = l(:text_issues_destroy_confirmation)
117 descendant_count = issues.inject(0) {|memo, i| memo += (i.right - i.left - 1)/2}
117 descendant_count = issues.inject(0) {|memo, i| memo += (i.right - i.left - 1)/2}
118 if descendant_count > 0
118 if descendant_count > 0
119 issues.each do |issue|
119 issues.each do |issue|
120 next if issue.root?
120 next if issue.root?
121 issues.each do |other_issue|
121 issues.each do |other_issue|
122 descendant_count -= 1 if issue.is_descendant_of?(other_issue)
122 descendant_count -= 1 if issue.is_descendant_of?(other_issue)
123 end
123 end
124 end
124 end
125 if descendant_count > 0
125 if descendant_count > 0
126 message << "\n" + l(:text_issues_destroy_descendants_confirmation, :count => descendant_count)
126 message << "\n" + l(:text_issues_destroy_descendants_confirmation, :count => descendant_count)
127 end
127 end
128 end
128 end
129 message
129 message
130 end
130 end
131
131
132 def sidebar_queries
132 def sidebar_queries
133 unless @sidebar_queries
133 unless @sidebar_queries
134 @sidebar_queries = Query.visible.all(
134 @sidebar_queries = Query.visible.all(
135 :order => "#{Query.table_name}.name ASC",
135 :order => "#{Query.table_name}.name ASC",
136 # Project specific queries and global queries
136 # Project specific queries and global queries
137 :conditions => (@project.nil? ? ["project_id IS NULL"] : ["project_id IS NULL OR project_id = ?", @project.id])
137 :conditions => (@project.nil? ? ["project_id IS NULL"] : ["project_id IS NULL OR project_id = ?", @project.id])
138 )
138 )
139 end
139 end
140 @sidebar_queries
140 @sidebar_queries
141 end
141 end
142
142
143 def query_links(title, queries)
143 def query_links(title, queries)
144 # links to #index on issues/show
144 # links to #index on issues/show
145 url_params = controller_name == 'issues' ? {:controller => 'issues', :action => 'index', :project_id => @project} : params
145 url_params = controller_name == 'issues' ? {:controller => 'issues', :action => 'index', :project_id => @project} : params
146
146
147 content_tag('h3', h(title)) +
147 content_tag('h3', h(title)) +
148 queries.collect {|query|
148 queries.collect {|query|
149 css = 'query'
149 css = 'query'
150 css << ' selected' if query == @query
150 css << ' selected' if query == @query
151 link_to(h(query.name), url_params.merge(:query_id => query), :class => css)
151 link_to(h(query.name), url_params.merge(:query_id => query), :class => css)
152 }.join('<br />').html_safe
152 }.join('<br />').html_safe
153 end
153 end
154
154
155 def render_sidebar_queries
155 def render_sidebar_queries
156 out = ''.html_safe
156 out = ''.html_safe
157 queries = sidebar_queries.select {|q| !q.is_public?}
157 queries = sidebar_queries.select {|q| !q.is_public?}
158 out << query_links(l(:label_my_queries), queries) if queries.any?
158 out << query_links(l(:label_my_queries), queries) if queries.any?
159 queries = sidebar_queries.select {|q| q.is_public?}
159 queries = sidebar_queries.select {|q| q.is_public?}
160 out << query_links(l(:label_query_plural), queries) if queries.any?
160 out << query_links(l(:label_query_plural), queries) if queries.any?
161 out
161 out
162 end
162 end
163
163
164 # Returns the textual representation of a journal details
164 # Returns the textual representation of a journal details
165 # as an array of strings
165 # as an array of strings
166 def details_to_strings(details, no_html=false, options={})
166 def details_to_strings(details, no_html=false, options={})
167 options[:only_path] = (options[:only_path] == false ? false : true)
167 options[:only_path] = (options[:only_path] == false ? false : true)
168 strings = []
168 strings = []
169 values_by_field = {}
169 values_by_field = {}
170 details.each do |detail|
170 details.each do |detail|
171 if detail.property == 'cf'
171 if detail.property == 'cf'
172 field_id = detail.prop_key
172 field_id = detail.prop_key
173 field = CustomField.find_by_id(field_id)
173 field = CustomField.find_by_id(field_id)
174 if field && field.multiple?
174 if field && field.multiple?
175 values_by_field[field_id] ||= {:added => [], :deleted => []}
175 values_by_field[field_id] ||= {:added => [], :deleted => []}
176 if detail.old_value
176 if detail.old_value
177 values_by_field[field_id][:deleted] << detail.old_value
177 values_by_field[field_id][:deleted] << detail.old_value
178 end
178 end
179 if detail.value
179 if detail.value
180 values_by_field[field_id][:added] << detail.value
180 values_by_field[field_id][:added] << detail.value
181 end
181 end
182 next
182 next
183 end
183 end
184 end
184 end
185 strings << show_detail(detail, no_html, options)
185 strings << show_detail(detail, no_html, options)
186 end
186 end
187 values_by_field.each do |field_id, changes|
187 values_by_field.each do |field_id, changes|
188 detail = JournalDetail.new(:property => 'cf', :prop_key => field_id)
188 detail = JournalDetail.new(:property => 'cf', :prop_key => field_id)
189 if changes[:added].any?
189 if changes[:added].any?
190 detail.value = changes[:added]
190 detail.value = changes[:added]
191 strings << show_detail(detail, no_html, options)
191 strings << show_detail(detail, no_html, options)
192 elsif changes[:deleted].any?
192 elsif changes[:deleted].any?
193 detail.old_value = changes[:deleted]
193 detail.old_value = changes[:deleted]
194 strings << show_detail(detail, no_html, options)
194 strings << show_detail(detail, no_html, options)
195 end
195 end
196 end
196 end
197 strings
197 strings
198 end
198 end
199
199
200 # Returns the textual representation of a single journal detail
200 # Returns the textual representation of a single journal detail
201 def show_detail(detail, no_html=false, options={})
201 def show_detail(detail, no_html=false, options={})
202 multiple = false
202 multiple = false
203 case detail.property
203 case detail.property
204 when 'attr'
204 when 'attr'
205 field = detail.prop_key.to_s.gsub(/\_id$/, "")
205 field = detail.prop_key.to_s.gsub(/\_id$/, "")
206 label = l(("field_" + field).to_sym)
206 label = l(("field_" + field).to_sym)
207 case detail.prop_key
207 case detail.prop_key
208 when 'due_date', 'start_date'
208 when 'due_date', 'start_date'
209 value = format_date(detail.value.to_date) if detail.value
209 value = format_date(detail.value.to_date) if detail.value
210 old_value = format_date(detail.old_value.to_date) if detail.old_value
210 old_value = format_date(detail.old_value.to_date) if detail.old_value
211
211
212 when 'project_id', 'status_id', 'tracker_id', 'assigned_to_id',
212 when 'project_id', 'status_id', 'tracker_id', 'assigned_to_id',
213 'priority_id', 'category_id', 'fixed_version_id'
213 'priority_id', 'category_id', 'fixed_version_id'
214 value = find_name_by_reflection(field, detail.value)
214 value = find_name_by_reflection(field, detail.value)
215 old_value = find_name_by_reflection(field, detail.old_value)
215 old_value = find_name_by_reflection(field, detail.old_value)
216
216
217 when 'estimated_hours'
217 when 'estimated_hours'
218 value = "%0.02f" % detail.value.to_f unless detail.value.blank?
218 value = "%0.02f" % detail.value.to_f unless detail.value.blank?
219 old_value = "%0.02f" % detail.old_value.to_f unless detail.old_value.blank?
219 old_value = "%0.02f" % detail.old_value.to_f unless detail.old_value.blank?
220
220
221 when 'parent_id'
221 when 'parent_id'
222 label = l(:field_parent_issue)
222 label = l(:field_parent_issue)
223 value = "##{detail.value}" unless detail.value.blank?
223 value = "##{detail.value}" unless detail.value.blank?
224 old_value = "##{detail.old_value}" unless detail.old_value.blank?
224 old_value = "##{detail.old_value}" unless detail.old_value.blank?
225
225
226 when 'is_private'
226 when 'is_private'
227 value = l(detail.value == "0" ? :general_text_No : :general_text_Yes) unless detail.value.blank?
227 value = l(detail.value == "0" ? :general_text_No : :general_text_Yes) unless detail.value.blank?
228 old_value = l(detail.old_value == "0" ? :general_text_No : :general_text_Yes) unless detail.old_value.blank?
228 old_value = l(detail.old_value == "0" ? :general_text_No : :general_text_Yes) unless detail.old_value.blank?
229 end
229 end
230 when 'cf'
230 when 'cf'
231 custom_field = CustomField.find_by_id(detail.prop_key)
231 custom_field = CustomField.find_by_id(detail.prop_key)
232 if custom_field
232 if custom_field
233 multiple = custom_field.multiple?
233 multiple = custom_field.multiple?
234 label = custom_field.name
234 label = custom_field.name
235 value = format_value(detail.value, custom_field.field_format) if detail.value
235 value = format_value(detail.value, custom_field.field_format) if detail.value
236 old_value = format_value(detail.old_value, custom_field.field_format) if detail.old_value
236 old_value = format_value(detail.old_value, custom_field.field_format) if detail.old_value
237 end
237 end
238 when 'attachment'
238 when 'attachment'
239 label = l(:label_attachment)
239 label = l(:label_attachment)
240 end
240 end
241 call_hook(:helper_issues_show_detail_after_setting,
241 call_hook(:helper_issues_show_detail_after_setting,
242 {:detail => detail, :label => label, :value => value, :old_value => old_value })
242 {:detail => detail, :label => label, :value => value, :old_value => old_value })
243
243
244 label ||= detail.prop_key
244 label ||= detail.prop_key
245 value ||= detail.value
245 value ||= detail.value
246 old_value ||= detail.old_value
246 old_value ||= detail.old_value
247
247
248 unless no_html
248 if no_html
249 if value.present?
250 old_value = "\"#{old_value}\"" if old_value.present?
251 value = "\"#{value}\""
252 end
253 else
249 label = content_tag('strong', label)
254 label = content_tag('strong', label)
250 old_value = content_tag("i", h(old_value)) if detail.old_value
255 old_value = content_tag("i", h(old_value)) if detail.old_value
251 old_value = content_tag("strike", old_value) if detail.old_value and detail.value.blank?
256 old_value = content_tag("strike", old_value) if detail.old_value and detail.value.blank?
252 if detail.property == 'attachment' && !value.blank? && atta = Attachment.find_by_id(detail.prop_key)
257 if detail.property == 'attachment' && !value.blank? && atta = Attachment.find_by_id(detail.prop_key)
253 # Link to the attachment if it has not been removed
258 # Link to the attachment if it has not been removed
254 value = link_to_attachment(atta, :download => true, :only_path => options[:only_path])
259 value = link_to_attachment(atta, :download => true, :only_path => options[:only_path])
255 if options[:only_path] != false && atta.is_text?
260 if options[:only_path] != false && atta.is_text?
256 value += link_to(
261 value += link_to(
257 image_tag('magnifier.png'),
262 image_tag('magnifier.png'),
258 :controller => 'attachments', :action => 'show',
263 :controller => 'attachments', :action => 'show',
259 :id => atta, :filename => atta.filename
264 :id => atta, :filename => atta.filename
260 )
265 )
261 end
266 end
262 else
267 else
263 value = content_tag("i", h(value)) if value
268 value = content_tag("i", h(value)) if value
264 end
269 end
265 end
270 end
266
271
267 if detail.property == 'attr' && detail.prop_key == 'description'
272 if detail.property == 'attr' && detail.prop_key == 'description'
268 s = l(:text_journal_changed_no_detail, :label => label)
273 s = l(:text_journal_changed_no_detail, :label => label)
269 unless no_html
274 unless no_html
270 diff_link = link_to 'diff',
275 diff_link = link_to 'diff',
271 {:controller => 'journals', :action => 'diff', :id => detail.journal_id,
276 {:controller => 'journals', :action => 'diff', :id => detail.journal_id,
272 :detail_id => detail.id, :only_path => options[:only_path]},
277 :detail_id => detail.id, :only_path => options[:only_path]},
273 :title => l(:label_view_diff)
278 :title => l(:label_view_diff)
274 s << " (#{ diff_link })"
279 s << " (#{ diff_link })"
275 end
280 end
276 s.html_safe
281 s.html_safe
277 elsif detail.value.present?
282 elsif detail.value.present?
278 case detail.property
283 case detail.property
279 when 'attr', 'cf'
284 when 'attr', 'cf'
280 if detail.old_value.present?
285 if detail.old_value.present?
281 l(:text_journal_changed, :label => label, :old => old_value, :new => value).html_safe
286 l(:text_journal_changed, :label => label, :old => old_value, :new => value).html_safe
282 elsif multiple
287 elsif multiple
283 l(:text_journal_added, :label => label, :value => value).html_safe
288 l(:text_journal_added, :label => label, :value => value).html_safe
284 else
289 else
285 l(:text_journal_set_to, :label => label, :value => value).html_safe
290 l(:text_journal_set_to, :label => label, :value => value).html_safe
286 end
291 end
287 when 'attachment'
292 when 'attachment'
288 l(:text_journal_added, :label => label, :value => value).html_safe
293 l(:text_journal_added, :label => label, :value => value).html_safe
289 end
294 end
290 else
295 else
291 l(:text_journal_deleted, :label => label, :old => old_value).html_safe
296 l(:text_journal_deleted, :label => label, :old => old_value).html_safe
292 end
297 end
293 end
298 end
294
299
295 # Find the name of an associated record stored in the field attribute
300 # Find the name of an associated record stored in the field attribute
296 def find_name_by_reflection(field, id)
301 def find_name_by_reflection(field, id)
297 association = Issue.reflect_on_association(field.to_sym)
302 association = Issue.reflect_on_association(field.to_sym)
298 if association
303 if association
299 record = association.class_name.constantize.find_by_id(id)
304 record = association.class_name.constantize.find_by_id(id)
300 return record.name if record
305 return record.name if record
301 end
306 end
302 end
307 end
303
308
304 # Renders issue children recursively
309 # Renders issue children recursively
305 def render_api_issue_children(issue, api)
310 def render_api_issue_children(issue, api)
306 return if issue.leaf?
311 return if issue.leaf?
307 api.array :children do
312 api.array :children do
308 issue.children.each do |child|
313 issue.children.each do |child|
309 api.issue(:id => child.id) do
314 api.issue(:id => child.id) do
310 api.tracker(:id => child.tracker_id, :name => child.tracker.name) unless child.tracker.nil?
315 api.tracker(:id => child.tracker_id, :name => child.tracker.name) unless child.tracker.nil?
311 api.subject child.subject
316 api.subject child.subject
312 render_api_issue_children(child, api)
317 render_api_issue_children(child, api)
313 end
318 end
314 end
319 end
315 end
320 end
316 end
321 end
317
322
318 def issues_to_csv(issues, project, query, options={})
323 def issues_to_csv(issues, project, query, options={})
319 decimal_separator = l(:general_csv_decimal_separator)
324 decimal_separator = l(:general_csv_decimal_separator)
320 encoding = l(:general_csv_encoding)
325 encoding = l(:general_csv_encoding)
321 columns = (options[:columns] == 'all' ? query.available_columns : query.columns)
326 columns = (options[:columns] == 'all' ? query.available_columns : query.columns)
322
327
323 export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv|
328 export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv|
324 # csv header fields
329 # csv header fields
325 csv << [ "#" ] + columns.collect {|c| Redmine::CodesetUtil.from_utf8(c.caption.to_s, encoding) } +
330 csv << [ "#" ] + columns.collect {|c| Redmine::CodesetUtil.from_utf8(c.caption.to_s, encoding) } +
326 (options[:description] ? [Redmine::CodesetUtil.from_utf8(l(:field_description), encoding)] : [])
331 (options[:description] ? [Redmine::CodesetUtil.from_utf8(l(:field_description), encoding)] : [])
327
332
328 # csv lines
333 # csv lines
329 issues.each do |issue|
334 issues.each do |issue|
330 col_values = columns.collect do |column|
335 col_values = columns.collect do |column|
331 s = if column.is_a?(QueryCustomFieldColumn)
336 s = if column.is_a?(QueryCustomFieldColumn)
332 cv = issue.custom_field_values.detect {|v| v.custom_field_id == column.custom_field.id}
337 cv = issue.custom_field_values.detect {|v| v.custom_field_id == column.custom_field.id}
333 show_value(cv)
338 show_value(cv)
334 else
339 else
335 value = issue.send(column.name)
340 value = issue.send(column.name)
336 if value.is_a?(Date)
341 if value.is_a?(Date)
337 format_date(value)
342 format_date(value)
338 elsif value.is_a?(Time)
343 elsif value.is_a?(Time)
339 format_time(value)
344 format_time(value)
340 elsif value.is_a?(Float)
345 elsif value.is_a?(Float)
341 ("%.2f" % value).gsub('.', decimal_separator)
346 ("%.2f" % value).gsub('.', decimal_separator)
342 else
347 else
343 value
348 value
344 end
349 end
345 end
350 end
346 s.to_s
351 s.to_s
347 end
352 end
348 csv << [ issue.id.to_s ] + col_values.collect {|c| Redmine::CodesetUtil.from_utf8(c.to_s, encoding) } +
353 csv << [ issue.id.to_s ] + col_values.collect {|c| Redmine::CodesetUtil.from_utf8(c.to_s, encoding) } +
349 (options[:description] ? [Redmine::CodesetUtil.from_utf8(issue.description, encoding)] : [])
354 (options[:description] ? [Redmine::CodesetUtil.from_utf8(issue.description, encoding)] : [])
350 end
355 end
351 end
356 end
352 export
357 export
353 end
358 end
354 end
359 end
General Comments 0
You need to be logged in to leave comments. Login now