##// END OF EJS Templates
Fixed that float custom fields do not use CSV decimal separator (#10364)....
Jean-Philippe Lang -
r11211:af92686c62c3
parent child
Show More

The requested changes are too big and content was truncated. Show full diff

@@ -1,413 +1,393
1 # encoding: utf-8
1 # encoding: utf-8
2 #
2 #
3 # Redmine - project management software
3 # Redmine - project management software
4 # Copyright (C) 2006-2013 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.
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, :project => (issue.project_id != ancestor.project_id)))
68 s << '<div>' + content_tag('p', link_to_issue(ancestor, :project => (issue.project_id != ancestor.project_id)))
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 css = "issue issue-#{child.id} hascontextmenu"
83 css = "issue issue-#{child.id} hascontextmenu"
84 css << " idnt idnt-#{level}" if level > 0
84 css << " idnt idnt-#{level}" if level > 0
85 s << content_tag('tr',
85 s << content_tag('tr',
86 content_tag('td', check_box_tag("ids[]", child.id, false, :id => nil), :class => 'checkbox') +
86 content_tag('td', check_box_tag("ids[]", child.id, false, :id => nil), :class => 'checkbox') +
87 content_tag('td', link_to_issue(child, :truncate => 60, :project => (issue.project_id != child.project_id)), :class => 'subject') +
87 content_tag('td', link_to_issue(child, :truncate => 60, :project => (issue.project_id != child.project_id)), :class => 'subject') +
88 content_tag('td', h(child.status)) +
88 content_tag('td', h(child.status)) +
89 content_tag('td', link_to_user(child.assigned_to)) +
89 content_tag('td', link_to_user(child.assigned_to)) +
90 content_tag('td', progress_bar(child.done_ratio, :width => '80px')),
90 content_tag('td', progress_bar(child.done_ratio, :width => '80px')),
91 :class => css)
91 :class => css)
92 end
92 end
93 s << '</table></form>'
93 s << '</table></form>'
94 s.html_safe
94 s.html_safe
95 end
95 end
96
96
97 # Returns a link for adding a new subtask to the given issue
97 # Returns a link for adding a new subtask to the given issue
98 def link_to_new_subtask(issue)
98 def link_to_new_subtask(issue)
99 attrs = {
99 attrs = {
100 :tracker_id => issue.tracker,
100 :tracker_id => issue.tracker,
101 :parent_issue_id => issue
101 :parent_issue_id => issue
102 }
102 }
103 link_to(l(:button_add), new_project_issue_path(issue.project, :issue => attrs))
103 link_to(l(:button_add), new_project_issue_path(issue.project, :issue => attrs))
104 end
104 end
105
105
106 class IssueFieldsRows
106 class IssueFieldsRows
107 include ActionView::Helpers::TagHelper
107 include ActionView::Helpers::TagHelper
108
108
109 def initialize
109 def initialize
110 @left = []
110 @left = []
111 @right = []
111 @right = []
112 end
112 end
113
113
114 def left(*args)
114 def left(*args)
115 args.any? ? @left << cells(*args) : @left
115 args.any? ? @left << cells(*args) : @left
116 end
116 end
117
117
118 def right(*args)
118 def right(*args)
119 args.any? ? @right << cells(*args) : @right
119 args.any? ? @right << cells(*args) : @right
120 end
120 end
121
121
122 def size
122 def size
123 @left.size > @right.size ? @left.size : @right.size
123 @left.size > @right.size ? @left.size : @right.size
124 end
124 end
125
125
126 def to_html
126 def to_html
127 html = ''.html_safe
127 html = ''.html_safe
128 blank = content_tag('th', '') + content_tag('td', '')
128 blank = content_tag('th', '') + content_tag('td', '')
129 size.times do |i|
129 size.times do |i|
130 left = @left[i] || blank
130 left = @left[i] || blank
131 right = @right[i] || blank
131 right = @right[i] || blank
132 html << content_tag('tr', left + right)
132 html << content_tag('tr', left + right)
133 end
133 end
134 html
134 html
135 end
135 end
136
136
137 def cells(label, text, options={})
137 def cells(label, text, options={})
138 content_tag('th', "#{label}:", options) + content_tag('td', text, options)
138 content_tag('th', "#{label}:", options) + content_tag('td', text, options)
139 end
139 end
140 end
140 end
141
141
142 def issue_fields_rows
142 def issue_fields_rows
143 r = IssueFieldsRows.new
143 r = IssueFieldsRows.new
144 yield r
144 yield r
145 r.to_html
145 r.to_html
146 end
146 end
147
147
148 def render_custom_fields_rows(issue)
148 def render_custom_fields_rows(issue)
149 return if issue.custom_field_values.empty?
149 return if issue.custom_field_values.empty?
150 ordered_values = []
150 ordered_values = []
151 half = (issue.custom_field_values.size / 2.0).ceil
151 half = (issue.custom_field_values.size / 2.0).ceil
152 half.times do |i|
152 half.times do |i|
153 ordered_values << issue.custom_field_values[i]
153 ordered_values << issue.custom_field_values[i]
154 ordered_values << issue.custom_field_values[i + half]
154 ordered_values << issue.custom_field_values[i + half]
155 end
155 end
156 s = "<tr>\n"
156 s = "<tr>\n"
157 n = 0
157 n = 0
158 ordered_values.compact.each do |value|
158 ordered_values.compact.each do |value|
159 s << "</tr>\n<tr>\n" if n > 0 && (n % 2) == 0
159 s << "</tr>\n<tr>\n" if n > 0 && (n % 2) == 0
160 s << "\t<th>#{ h(value.custom_field.name) }:</th><td>#{ simple_format_without_paragraph(h(show_value(value))) }</td>\n"
160 s << "\t<th>#{ h(value.custom_field.name) }:</th><td>#{ simple_format_without_paragraph(h(show_value(value))) }</td>\n"
161 n += 1
161 n += 1
162 end
162 end
163 s << "</tr>\n"
163 s << "</tr>\n"
164 s.html_safe
164 s.html_safe
165 end
165 end
166
166
167 def issues_destroy_confirmation_message(issues)
167 def issues_destroy_confirmation_message(issues)
168 issues = [issues] unless issues.is_a?(Array)
168 issues = [issues] unless issues.is_a?(Array)
169 message = l(:text_issues_destroy_confirmation)
169 message = l(:text_issues_destroy_confirmation)
170 descendant_count = issues.inject(0) {|memo, i| memo += (i.right - i.left - 1)/2}
170 descendant_count = issues.inject(0) {|memo, i| memo += (i.right - i.left - 1)/2}
171 if descendant_count > 0
171 if descendant_count > 0
172 issues.each do |issue|
172 issues.each do |issue|
173 next if issue.root?
173 next if issue.root?
174 issues.each do |other_issue|
174 issues.each do |other_issue|
175 descendant_count -= 1 if issue.is_descendant_of?(other_issue)
175 descendant_count -= 1 if issue.is_descendant_of?(other_issue)
176 end
176 end
177 end
177 end
178 if descendant_count > 0
178 if descendant_count > 0
179 message << "\n" + l(:text_issues_destroy_descendants_confirmation, :count => descendant_count)
179 message << "\n" + l(:text_issues_destroy_descendants_confirmation, :count => descendant_count)
180 end
180 end
181 end
181 end
182 message
182 message
183 end
183 end
184
184
185 def sidebar_queries
185 def sidebar_queries
186 unless @sidebar_queries
186 unless @sidebar_queries
187 @sidebar_queries = IssueQuery.visible.all(
187 @sidebar_queries = IssueQuery.visible.all(
188 :order => "#{Query.table_name}.name ASC",
188 :order => "#{Query.table_name}.name ASC",
189 # Project specific queries and global queries
189 # Project specific queries and global queries
190 :conditions => (@project.nil? ? ["project_id IS NULL"] : ["project_id IS NULL OR project_id = ?", @project.id])
190 :conditions => (@project.nil? ? ["project_id IS NULL"] : ["project_id IS NULL OR project_id = ?", @project.id])
191 )
191 )
192 end
192 end
193 @sidebar_queries
193 @sidebar_queries
194 end
194 end
195
195
196 def query_links(title, queries)
196 def query_links(title, queries)
197 # links to #index on issues/show
197 # links to #index on issues/show
198 url_params = controller_name == 'issues' ? {:controller => 'issues', :action => 'index', :project_id => @project} : params
198 url_params = controller_name == 'issues' ? {:controller => 'issues', :action => 'index', :project_id => @project} : params
199
199
200 content_tag('h3', h(title)) +
200 content_tag('h3', h(title)) +
201 queries.collect {|query|
201 queries.collect {|query|
202 css = 'query'
202 css = 'query'
203 css << ' selected' if query == @query
203 css << ' selected' if query == @query
204 link_to(h(query.name), url_params.merge(:query_id => query), :class => css)
204 link_to(h(query.name), url_params.merge(:query_id => query), :class => css)
205 }.join('<br />').html_safe
205 }.join('<br />').html_safe
206 end
206 end
207
207
208 def render_sidebar_queries
208 def render_sidebar_queries
209 out = ''.html_safe
209 out = ''.html_safe
210 queries = sidebar_queries.select {|q| !q.is_public?}
210 queries = sidebar_queries.select {|q| !q.is_public?}
211 out << query_links(l(:label_my_queries), queries) if queries.any?
211 out << query_links(l(:label_my_queries), queries) if queries.any?
212 queries = sidebar_queries.select {|q| q.is_public?}
212 queries = sidebar_queries.select {|q| q.is_public?}
213 out << query_links(l(:label_query_plural), queries) if queries.any?
213 out << query_links(l(:label_query_plural), queries) if queries.any?
214 out
214 out
215 end
215 end
216
216
217 # Returns the textual representation of a journal details
217 # Returns the textual representation of a journal details
218 # as an array of strings
218 # as an array of strings
219 def details_to_strings(details, no_html=false, options={})
219 def details_to_strings(details, no_html=false, options={})
220 options[:only_path] = (options[:only_path] == false ? false : true)
220 options[:only_path] = (options[:only_path] == false ? false : true)
221 strings = []
221 strings = []
222 values_by_field = {}
222 values_by_field = {}
223 details.each do |detail|
223 details.each do |detail|
224 if detail.property == 'cf'
224 if detail.property == 'cf'
225 field_id = detail.prop_key
225 field_id = detail.prop_key
226 field = CustomField.find_by_id(field_id)
226 field = CustomField.find_by_id(field_id)
227 if field && field.multiple?
227 if field && field.multiple?
228 values_by_field[field_id] ||= {:added => [], :deleted => []}
228 values_by_field[field_id] ||= {:added => [], :deleted => []}
229 if detail.old_value
229 if detail.old_value
230 values_by_field[field_id][:deleted] << detail.old_value
230 values_by_field[field_id][:deleted] << detail.old_value
231 end
231 end
232 if detail.value
232 if detail.value
233 values_by_field[field_id][:added] << detail.value
233 values_by_field[field_id][:added] << detail.value
234 end
234 end
235 next
235 next
236 end
236 end
237 end
237 end
238 strings << show_detail(detail, no_html, options)
238 strings << show_detail(detail, no_html, options)
239 end
239 end
240 values_by_field.each do |field_id, changes|
240 values_by_field.each do |field_id, changes|
241 detail = JournalDetail.new(:property => 'cf', :prop_key => field_id)
241 detail = JournalDetail.new(:property => 'cf', :prop_key => field_id)
242 if changes[:added].any?
242 if changes[:added].any?
243 detail.value = changes[:added]
243 detail.value = changes[:added]
244 strings << show_detail(detail, no_html, options)
244 strings << show_detail(detail, no_html, options)
245 elsif changes[:deleted].any?
245 elsif changes[:deleted].any?
246 detail.old_value = changes[:deleted]
246 detail.old_value = changes[:deleted]
247 strings << show_detail(detail, no_html, options)
247 strings << show_detail(detail, no_html, options)
248 end
248 end
249 end
249 end
250 strings
250 strings
251 end
251 end
252
252
253 # Returns the textual representation of a single journal detail
253 # Returns the textual representation of a single journal detail
254 def show_detail(detail, no_html=false, options={})
254 def show_detail(detail, no_html=false, options={})
255 multiple = false
255 multiple = false
256 case detail.property
256 case detail.property
257 when 'attr'
257 when 'attr'
258 field = detail.prop_key.to_s.gsub(/\_id$/, "")
258 field = detail.prop_key.to_s.gsub(/\_id$/, "")
259 label = l(("field_" + field).to_sym)
259 label = l(("field_" + field).to_sym)
260 case detail.prop_key
260 case detail.prop_key
261 when 'due_date', 'start_date'
261 when 'due_date', 'start_date'
262 value = format_date(detail.value.to_date) if detail.value
262 value = format_date(detail.value.to_date) if detail.value
263 old_value = format_date(detail.old_value.to_date) if detail.old_value
263 old_value = format_date(detail.old_value.to_date) if detail.old_value
264
264
265 when 'project_id', 'status_id', 'tracker_id', 'assigned_to_id',
265 when 'project_id', 'status_id', 'tracker_id', 'assigned_to_id',
266 'priority_id', 'category_id', 'fixed_version_id'
266 'priority_id', 'category_id', 'fixed_version_id'
267 value = find_name_by_reflection(field, detail.value)
267 value = find_name_by_reflection(field, detail.value)
268 old_value = find_name_by_reflection(field, detail.old_value)
268 old_value = find_name_by_reflection(field, detail.old_value)
269
269
270 when 'estimated_hours'
270 when 'estimated_hours'
271 value = "%0.02f" % detail.value.to_f unless detail.value.blank?
271 value = "%0.02f" % detail.value.to_f unless detail.value.blank?
272 old_value = "%0.02f" % detail.old_value.to_f unless detail.old_value.blank?
272 old_value = "%0.02f" % detail.old_value.to_f unless detail.old_value.blank?
273
273
274 when 'parent_id'
274 when 'parent_id'
275 label = l(:field_parent_issue)
275 label = l(:field_parent_issue)
276 value = "##{detail.value}" unless detail.value.blank?
276 value = "##{detail.value}" unless detail.value.blank?
277 old_value = "##{detail.old_value}" unless detail.old_value.blank?
277 old_value = "##{detail.old_value}" unless detail.old_value.blank?
278
278
279 when 'is_private'
279 when 'is_private'
280 value = l(detail.value == "0" ? :general_text_No : :general_text_Yes) unless detail.value.blank?
280 value = l(detail.value == "0" ? :general_text_No : :general_text_Yes) unless detail.value.blank?
281 old_value = l(detail.old_value == "0" ? :general_text_No : :general_text_Yes) unless detail.old_value.blank?
281 old_value = l(detail.old_value == "0" ? :general_text_No : :general_text_Yes) unless detail.old_value.blank?
282 end
282 end
283 when 'cf'
283 when 'cf'
284 custom_field = CustomField.find_by_id(detail.prop_key)
284 custom_field = CustomField.find_by_id(detail.prop_key)
285 if custom_field
285 if custom_field
286 multiple = custom_field.multiple?
286 multiple = custom_field.multiple?
287 label = custom_field.name
287 label = custom_field.name
288 value = format_value(detail.value, custom_field.field_format) if detail.value
288 value = format_value(detail.value, custom_field.field_format) if detail.value
289 old_value = format_value(detail.old_value, custom_field.field_format) if detail.old_value
289 old_value = format_value(detail.old_value, custom_field.field_format) if detail.old_value
290 end
290 end
291 when 'attachment'
291 when 'attachment'
292 label = l(:label_attachment)
292 label = l(:label_attachment)
293 end
293 end
294 call_hook(:helper_issues_show_detail_after_setting,
294 call_hook(:helper_issues_show_detail_after_setting,
295 {:detail => detail, :label => label, :value => value, :old_value => old_value })
295 {:detail => detail, :label => label, :value => value, :old_value => old_value })
296
296
297 label ||= detail.prop_key
297 label ||= detail.prop_key
298 value ||= detail.value
298 value ||= detail.value
299 old_value ||= detail.old_value
299 old_value ||= detail.old_value
300
300
301 unless no_html
301 unless no_html
302 label = content_tag('strong', label)
302 label = content_tag('strong', label)
303 old_value = content_tag("i", h(old_value)) if detail.old_value
303 old_value = content_tag("i", h(old_value)) if detail.old_value
304 old_value = content_tag("del", old_value) if detail.old_value and detail.value.blank?
304 old_value = content_tag("del", old_value) if detail.old_value and detail.value.blank?
305 if detail.property == 'attachment' && !value.blank? && atta = Attachment.find_by_id(detail.prop_key)
305 if detail.property == 'attachment' && !value.blank? && atta = Attachment.find_by_id(detail.prop_key)
306 # Link to the attachment if it has not been removed
306 # Link to the attachment if it has not been removed
307 value = link_to_attachment(atta, :download => true, :only_path => options[:only_path])
307 value = link_to_attachment(atta, :download => true, :only_path => options[:only_path])
308 if options[:only_path] != false && atta.is_text?
308 if options[:only_path] != false && atta.is_text?
309 value += link_to(
309 value += link_to(
310 image_tag('magnifier.png'),
310 image_tag('magnifier.png'),
311 :controller => 'attachments', :action => 'show',
311 :controller => 'attachments', :action => 'show',
312 :id => atta, :filename => atta.filename
312 :id => atta, :filename => atta.filename
313 )
313 )
314 end
314 end
315 else
315 else
316 value = content_tag("i", h(value)) if value
316 value = content_tag("i", h(value)) if value
317 end
317 end
318 end
318 end
319
319
320 if detail.property == 'attr' && detail.prop_key == 'description'
320 if detail.property == 'attr' && detail.prop_key == 'description'
321 s = l(:text_journal_changed_no_detail, :label => label)
321 s = l(:text_journal_changed_no_detail, :label => label)
322 unless no_html
322 unless no_html
323 diff_link = link_to 'diff',
323 diff_link = link_to 'diff',
324 {:controller => 'journals', :action => 'diff', :id => detail.journal_id,
324 {:controller => 'journals', :action => 'diff', :id => detail.journal_id,
325 :detail_id => detail.id, :only_path => options[:only_path]},
325 :detail_id => detail.id, :only_path => options[:only_path]},
326 :title => l(:label_view_diff)
326 :title => l(:label_view_diff)
327 s << " (#{ diff_link })"
327 s << " (#{ diff_link })"
328 end
328 end
329 s.html_safe
329 s.html_safe
330 elsif detail.value.present?
330 elsif detail.value.present?
331 case detail.property
331 case detail.property
332 when 'attr', 'cf'
332 when 'attr', 'cf'
333 if detail.old_value.present?
333 if detail.old_value.present?
334 l(:text_journal_changed, :label => label, :old => old_value, :new => value).html_safe
334 l(:text_journal_changed, :label => label, :old => old_value, :new => value).html_safe
335 elsif multiple
335 elsif multiple
336 l(:text_journal_added, :label => label, :value => value).html_safe
336 l(:text_journal_added, :label => label, :value => value).html_safe
337 else
337 else
338 l(:text_journal_set_to, :label => label, :value => value).html_safe
338 l(:text_journal_set_to, :label => label, :value => value).html_safe
339 end
339 end
340 when 'attachment'
340 when 'attachment'
341 l(:text_journal_added, :label => label, :value => value).html_safe
341 l(:text_journal_added, :label => label, :value => value).html_safe
342 end
342 end
343 else
343 else
344 l(:text_journal_deleted, :label => label, :old => old_value).html_safe
344 l(:text_journal_deleted, :label => label, :old => old_value).html_safe
345 end
345 end
346 end
346 end
347
347
348 # Find the name of an associated record stored in the field attribute
348 # Find the name of an associated record stored in the field attribute
349 def find_name_by_reflection(field, id)
349 def find_name_by_reflection(field, id)
350 unless id.present?
350 unless id.present?
351 return nil
351 return nil
352 end
352 end
353 association = Issue.reflect_on_association(field.to_sym)
353 association = Issue.reflect_on_association(field.to_sym)
354 if association
354 if association
355 record = association.class_name.constantize.find_by_id(id)
355 record = association.class_name.constantize.find_by_id(id)
356 return record.name if record
356 return record.name if record
357 end
357 end
358 end
358 end
359
359
360 # Renders issue children recursively
360 # Renders issue children recursively
361 def render_api_issue_children(issue, api)
361 def render_api_issue_children(issue, api)
362 return if issue.leaf?
362 return if issue.leaf?
363 api.array :children do
363 api.array :children do
364 issue.children.each do |child|
364 issue.children.each do |child|
365 api.issue(:id => child.id) do
365 api.issue(:id => child.id) do
366 api.tracker(:id => child.tracker_id, :name => child.tracker.name) unless child.tracker.nil?
366 api.tracker(:id => child.tracker_id, :name => child.tracker.name) unless child.tracker.nil?
367 api.subject child.subject
367 api.subject child.subject
368 render_api_issue_children(child, api)
368 render_api_issue_children(child, api)
369 end
369 end
370 end
370 end
371 end
371 end
372 end
372 end
373
373
374 def issues_to_csv(issues, project, query, options={})
374 def issues_to_csv(issues, project, query, options={})
375 decimal_separator = l(:general_csv_decimal_separator)
376 encoding = l(:general_csv_encoding)
375 encoding = l(:general_csv_encoding)
377 columns = (options[:columns] == 'all' ? query.available_inline_columns : query.inline_columns)
376 columns = (options[:columns] == 'all' ? query.available_inline_columns : query.inline_columns)
378 if options[:description]
377 if options[:description]
379 if description = query.available_columns.detect {|q| q.name == :description}
378 if description = query.available_columns.detect {|q| q.name == :description}
380 columns << description
379 columns << description
381 end
380 end
382 end
381 end
383
382
384 export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv|
383 export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv|
385 # csv header fields
384 # csv header fields
386 csv << [ "#" ] + columns.collect {|c| Redmine::CodesetUtil.from_utf8(c.caption.to_s, encoding) }
385 csv << [ "#" ] + columns.collect {|c| Redmine::CodesetUtil.from_utf8(c.caption.to_s, encoding) }
387
388 # csv lines
386 # csv lines
389 issues.each do |issue|
387 issues.each do |issue|
390 col_values = columns.collect do |column|
388 csv << [ issue.id.to_s ] + columns.collect {|c| Redmine::CodesetUtil.from_utf8(csv_content(c, issue), encoding) }
391 s = if column.is_a?(QueryCustomFieldColumn)
392 cv = issue.custom_field_values.detect {|v| v.custom_field_id == column.custom_field.id}
393 show_value(cv)
394 else
395 value = column.value(issue)
396 if value.is_a?(Date)
397 format_date(value)
398 elsif value.is_a?(Time)
399 format_time(value)
400 elsif value.is_a?(Float)
401 ("%.2f" % value).gsub('.', decimal_separator)
402 else
403 value
404 end
405 end
406 s.to_s
407 end
408 csv << [ issue.id.to_s ] + col_values.collect {|c| Redmine::CodesetUtil.from_utf8(c.to_s, encoding) }
409 end
389 end
410 end
390 end
411 export
391 export
412 end
392 end
413 end
393 end
@@ -1,139 +1,164
1 # encoding: utf-8
1 # encoding: utf-8
2 #
2 #
3 # Redmine - project management software
3 # Redmine - project management software
4 # Copyright (C) 2006-2013 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.
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 QueriesHelper
20 module QueriesHelper
21 def filters_options_for_select(query)
21 def filters_options_for_select(query)
22 options_for_select(filters_options(query))
22 options_for_select(filters_options(query))
23 end
23 end
24
24
25 def filters_options(query)
25 def filters_options(query)
26 options = [[]]
26 options = [[]]
27 options += query.available_filters.map do |field, field_options|
27 options += query.available_filters.map do |field, field_options|
28 [field_options[:name], field]
28 [field_options[:name], field]
29 end
29 end
30 end
30 end
31
31
32 def available_block_columns_tags(query)
32 def available_block_columns_tags(query)
33 tags = ''.html_safe
33 tags = ''.html_safe
34 query.available_block_columns.each do |column|
34 query.available_block_columns.each do |column|
35 tags << content_tag('label', check_box_tag('c[]', column.name.to_s, query.has_column?(column)) + " #{column.caption}", :class => 'inline')
35 tags << content_tag('label', check_box_tag('c[]', column.name.to_s, query.has_column?(column)) + " #{column.caption}", :class => 'inline')
36 end
36 end
37 tags
37 tags
38 end
38 end
39
39
40 def column_header(column)
40 def column_header(column)
41 column.sortable ? sort_header_tag(column.name.to_s, :caption => column.caption,
41 column.sortable ? sort_header_tag(column.name.to_s, :caption => column.caption,
42 :default_order => column.default_order) :
42 :default_order => column.default_order) :
43 content_tag('th', h(column.caption))
43 content_tag('th', h(column.caption))
44 end
44 end
45
45
46 def column_content(column, issue)
46 def column_content(column, issue)
47 value = column.value(issue)
47 value = column.value(issue)
48 if value.is_a?(Array)
48 if value.is_a?(Array)
49 value.collect {|v| column_value(column, issue, v)}.compact.join(', ').html_safe
49 value.collect {|v| column_value(column, issue, v)}.compact.join(', ').html_safe
50 else
50 else
51 column_value(column, issue, value)
51 column_value(column, issue, value)
52 end
52 end
53 end
53 end
54
54
55 def column_value(column, issue, value)
55 def column_value(column, issue, value)
56 case value.class.name
56 case value.class.name
57 when 'String'
57 when 'String'
58 if column.name == :subject
58 if column.name == :subject
59 link_to(h(value), :controller => 'issues', :action => 'show', :id => issue)
59 link_to(h(value), :controller => 'issues', :action => 'show', :id => issue)
60 elsif column.name == :description
60 elsif column.name == :description
61 issue.description? ? content_tag('div', textilizable(issue, :description), :class => "wiki") : ''
61 issue.description? ? content_tag('div', textilizable(issue, :description), :class => "wiki") : ''
62 else
62 else
63 h(value)
63 h(value)
64 end
64 end
65 when 'Time'
65 when 'Time'
66 format_time(value)
66 format_time(value)
67 when 'Date'
67 when 'Date'
68 format_date(value)
68 format_date(value)
69 when 'Fixnum'
69 when 'Fixnum'
70 if column.name == :done_ratio
70 if column.name == :done_ratio
71 progress_bar(value, :width => '80px')
71 progress_bar(value, :width => '80px')
72 else
72 else
73 value.to_s
73 value.to_s
74 end
74 end
75 when 'Float'
75 when 'Float'
76 sprintf "%.2f", value
76 sprintf "%.2f", value
77 when 'User'
77 when 'User'
78 link_to_user value
78 link_to_user value
79 when 'Project'
79 when 'Project'
80 link_to_project value
80 link_to_project value
81 when 'Version'
81 when 'Version'
82 link_to(h(value), :controller => 'versions', :action => 'show', :id => value)
82 link_to(h(value), :controller => 'versions', :action => 'show', :id => value)
83 when 'TrueClass'
83 when 'TrueClass'
84 l(:general_text_Yes)
84 l(:general_text_Yes)
85 when 'FalseClass'
85 when 'FalseClass'
86 l(:general_text_No)
86 l(:general_text_No)
87 when 'Issue'
87 when 'Issue'
88 value.visible? ? link_to_issue(value) : "##{value.id}"
88 value.visible? ? link_to_issue(value) : "##{value.id}"
89 when 'IssueRelation'
89 when 'IssueRelation'
90 other = value.other_issue(issue)
90 other = value.other_issue(issue)
91 content_tag('span',
91 content_tag('span',
92 (l(value.label_for(issue)) + " " + link_to_issue(other, :subject => false, :tracker => false)).html_safe,
92 (l(value.label_for(issue)) + " " + link_to_issue(other, :subject => false, :tracker => false)).html_safe,
93 :class => value.css_classes_for(issue))
93 :class => value.css_classes_for(issue))
94 else
94 else
95 h(value)
95 h(value)
96 end
96 end
97 end
97 end
98
98
99 def csv_content(column, issue)
100 value = column.value(issue)
101 if value.is_a?(Array)
102 value.collect {|v| csv_value(column, issue, v)}.compact.join(', ')
103 else
104 csv_value(column, issue, value)
105 end
106 end
107
108 def csv_value(column, issue, value)
109 case value.class.name
110 when 'Time'
111 format_time(value)
112 when 'Date'
113 format_date(value)
114 when 'Float'
115 sprintf("%.2f", value).gsub('.', l(:general_csv_decimal_separator))
116 when 'IssueRelation'
117 other = value.other_issue(issue)
118 l(value.label_for(issue)) + " ##{other.id}"
119 else
120 value.to_s
121 end
122 end
123
99 # Retrieve query from session or build a new query
124 # Retrieve query from session or build a new query
100 def retrieve_query
125 def retrieve_query
101 if !params[:query_id].blank?
126 if !params[:query_id].blank?
102 cond = "project_id IS NULL"
127 cond = "project_id IS NULL"
103 cond << " OR project_id = #{@project.id}" if @project
128 cond << " OR project_id = #{@project.id}" if @project
104 @query = IssueQuery.find(params[:query_id], :conditions => cond)
129 @query = IssueQuery.find(params[:query_id], :conditions => cond)
105 raise ::Unauthorized unless @query.visible?
130 raise ::Unauthorized unless @query.visible?
106 @query.project = @project
131 @query.project = @project
107 session[:query] = {:id => @query.id, :project_id => @query.project_id}
132 session[:query] = {:id => @query.id, :project_id => @query.project_id}
108 sort_clear
133 sort_clear
109 elsif api_request? || params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil)
134 elsif api_request? || params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil)
110 # Give it a name, required to be valid
135 # Give it a name, required to be valid
111 @query = IssueQuery.new(:name => "_")
136 @query = IssueQuery.new(:name => "_")
112 @query.project = @project
137 @query.project = @project
113 @query.build_from_params(params)
138 @query.build_from_params(params)
114 session[:query] = {:project_id => @query.project_id, :filters => @query.filters, :group_by => @query.group_by, :column_names => @query.column_names}
139 session[:query] = {:project_id => @query.project_id, :filters => @query.filters, :group_by => @query.group_by, :column_names => @query.column_names}
115 else
140 else
116 # retrieve from session
141 # retrieve from session
117 @query = IssueQuery.find_by_id(session[:query][:id]) if session[:query][:id]
142 @query = IssueQuery.find_by_id(session[:query][:id]) if session[:query][:id]
118 @query ||= IssueQuery.new(:name => "_", :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names])
143 @query ||= IssueQuery.new(:name => "_", :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names])
119 @query.project = @project
144 @query.project = @project
120 end
145 end
121 end
146 end
122
147
123 def retrieve_query_from_session
148 def retrieve_query_from_session
124 if session[:query]
149 if session[:query]
125 if session[:query][:id]
150 if session[:query][:id]
126 @query = IssueQuery.find_by_id(session[:query][:id])
151 @query = IssueQuery.find_by_id(session[:query][:id])
127 return unless @query
152 return unless @query
128 else
153 else
129 @query = IssueQuery.new(:name => "_", :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names])
154 @query = IssueQuery.new(:name => "_", :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names])
130 end
155 end
131 if session[:query].has_key?(:project_id)
156 if session[:query].has_key?(:project_id)
132 @query.project_id = session[:query][:project_id]
157 @query.project_id = session[:query][:project_id]
133 else
158 else
134 @query.project = @project
159 @query.project = @project
135 end
160 end
136 @query
161 @query
137 end
162 end
138 end
163 end
139 end
164 end
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
General Comments 0
You need to be logged in to leave comments. Login now