##// END OF EJS Templates
Omit blank fields as we do for the description (#21705)....
Jean-Philippe Lang -
r15875:37301d75b3fe
parent child
Show More
@@ -1,544 +1,546
1 # encoding: utf-8
1 # encoding: utf-8
2 #
2 #
3 # Redmine - project management software
3 # Redmine - project management software
4 # Copyright (C) 2006-2016 Jean-Philippe Lang
4 # Copyright (C) 2006-2016 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 include Redmine::Export::PDF::IssuesPdfHelper
22 include Redmine::Export::PDF::IssuesPdfHelper
23
23
24 def issue_list(issues, &block)
24 def issue_list(issues, &block)
25 ancestors = []
25 ancestors = []
26 issues.each do |issue|
26 issues.each do |issue|
27 while (ancestors.any? && !issue.is_descendant_of?(ancestors.last))
27 while (ancestors.any? && !issue.is_descendant_of?(ancestors.last))
28 ancestors.pop
28 ancestors.pop
29 end
29 end
30 yield issue, ancestors.size
30 yield issue, ancestors.size
31 ancestors << issue unless issue.leaf?
31 ancestors << issue unless issue.leaf?
32 end
32 end
33 end
33 end
34
34
35 def grouped_issue_list(issues, query, issue_count_by_group, &block)
35 def grouped_issue_list(issues, query, issue_count_by_group, &block)
36 ancestors = []
36 ancestors = []
37 grouped_query_results(issues, query, issue_count_by_group) do |issue, group_name, group_count, group_totals|
37 grouped_query_results(issues, query, issue_count_by_group) do |issue, group_name, group_count, group_totals|
38 while (ancestors.any? && !issue.is_descendant_of?(ancestors.last))
38 while (ancestors.any? && !issue.is_descendant_of?(ancestors.last))
39 ancestors.pop
39 ancestors.pop
40 end
40 end
41 yield issue, ancestors.size, group_name, group_count, group_totals
41 yield issue, ancestors.size, group_name, group_count, group_totals
42 ancestors << issue unless issue.leaf?
42 ancestors << issue unless issue.leaf?
43 end
43 end
44 end
44 end
45
45
46 # Renders a HTML/CSS tooltip
46 # Renders a HTML/CSS tooltip
47 #
47 #
48 # To use, a trigger div is needed. This is a div with the class of "tooltip"
48 # To use, a trigger div is needed. This is a div with the class of "tooltip"
49 # that contains this method wrapped in a span with the class of "tip"
49 # that contains this method wrapped in a span with the class of "tip"
50 #
50 #
51 # <div class="tooltip"><%= link_to_issue(issue) %>
51 # <div class="tooltip"><%= link_to_issue(issue) %>
52 # <span class="tip"><%= render_issue_tooltip(issue) %></span>
52 # <span class="tip"><%= render_issue_tooltip(issue) %></span>
53 # </div>
53 # </div>
54 #
54 #
55 def render_issue_tooltip(issue)
55 def render_issue_tooltip(issue)
56 @cached_label_status ||= l(:field_status)
56 @cached_label_status ||= l(:field_status)
57 @cached_label_start_date ||= l(:field_start_date)
57 @cached_label_start_date ||= l(:field_start_date)
58 @cached_label_due_date ||= l(:field_due_date)
58 @cached_label_due_date ||= l(:field_due_date)
59 @cached_label_assigned_to ||= l(:field_assigned_to)
59 @cached_label_assigned_to ||= l(:field_assigned_to)
60 @cached_label_priority ||= l(:field_priority)
60 @cached_label_priority ||= l(:field_priority)
61 @cached_label_project ||= l(:field_project)
61 @cached_label_project ||= l(:field_project)
62
62
63 link_to_issue(issue) + "<br /><br />".html_safe +
63 link_to_issue(issue) + "<br /><br />".html_safe +
64 "<strong>#{@cached_label_project}</strong>: #{link_to_project(issue.project)}<br />".html_safe +
64 "<strong>#{@cached_label_project}</strong>: #{link_to_project(issue.project)}<br />".html_safe +
65 "<strong>#{@cached_label_status}</strong>: #{h(issue.status.name)}<br />".html_safe +
65 "<strong>#{@cached_label_status}</strong>: #{h(issue.status.name)}<br />".html_safe +
66 "<strong>#{@cached_label_start_date}</strong>: #{format_date(issue.start_date)}<br />".html_safe +
66 "<strong>#{@cached_label_start_date}</strong>: #{format_date(issue.start_date)}<br />".html_safe +
67 "<strong>#{@cached_label_due_date}</strong>: #{format_date(issue.due_date)}<br />".html_safe +
67 "<strong>#{@cached_label_due_date}</strong>: #{format_date(issue.due_date)}<br />".html_safe +
68 "<strong>#{@cached_label_assigned_to}</strong>: #{h(issue.assigned_to)}<br />".html_safe +
68 "<strong>#{@cached_label_assigned_to}</strong>: #{h(issue.assigned_to)}<br />".html_safe +
69 "<strong>#{@cached_label_priority}</strong>: #{h(issue.priority.name)}".html_safe
69 "<strong>#{@cached_label_priority}</strong>: #{h(issue.priority.name)}".html_safe
70 end
70 end
71
71
72 def issue_heading(issue)
72 def issue_heading(issue)
73 h("#{issue.tracker} ##{issue.id}")
73 h("#{issue.tracker} ##{issue.id}")
74 end
74 end
75
75
76 def render_issue_subject_with_tree(issue)
76 def render_issue_subject_with_tree(issue)
77 s = ''
77 s = ''
78 ancestors = issue.root? ? [] : issue.ancestors.visible.to_a
78 ancestors = issue.root? ? [] : issue.ancestors.visible.to_a
79 ancestors.each do |ancestor|
79 ancestors.each do |ancestor|
80 s << '<div>' + content_tag('p', link_to_issue(ancestor, :project => (issue.project_id != ancestor.project_id)))
80 s << '<div>' + content_tag('p', link_to_issue(ancestor, :project => (issue.project_id != ancestor.project_id)))
81 end
81 end
82 s << '<div>'
82 s << '<div>'
83 subject = h(issue.subject)
83 subject = h(issue.subject)
84 if issue.is_private?
84 if issue.is_private?
85 subject = content_tag('span', l(:field_is_private), :class => 'private') + ' ' + subject
85 subject = content_tag('span', l(:field_is_private), :class => 'private') + ' ' + subject
86 end
86 end
87 s << content_tag('h3', subject)
87 s << content_tag('h3', subject)
88 s << '</div>' * (ancestors.size + 1)
88 s << '</div>' * (ancestors.size + 1)
89 s.html_safe
89 s.html_safe
90 end
90 end
91
91
92 def render_descendants_tree(issue)
92 def render_descendants_tree(issue)
93 s = '<table class="list issues">'
93 s = '<table class="list issues">'
94 issue_list(issue.descendants.visible.preload(:status, :priority, :tracker, :assigned_to).sort_by(&:lft)) do |child, level|
94 issue_list(issue.descendants.visible.preload(:status, :priority, :tracker, :assigned_to).sort_by(&:lft)) do |child, level|
95 css = "issue issue-#{child.id} hascontextmenu #{child.css_classes}"
95 css = "issue issue-#{child.id} hascontextmenu #{child.css_classes}"
96 css << " idnt idnt-#{level}" if level > 0
96 css << " idnt idnt-#{level}" if level > 0
97 s << content_tag('tr',
97 s << content_tag('tr',
98 content_tag('td', check_box_tag("ids[]", child.id, false, :id => nil), :class => 'checkbox') +
98 content_tag('td', check_box_tag("ids[]", child.id, false, :id => nil), :class => 'checkbox') +
99 content_tag('td', link_to_issue(child, :project => (issue.project_id != child.project_id)), :class => 'subject', :style => 'width: 50%') +
99 content_tag('td', link_to_issue(child, :project => (issue.project_id != child.project_id)), :class => 'subject', :style => 'width: 50%') +
100 content_tag('td', h(child.status), :class => 'status') +
100 content_tag('td', h(child.status), :class => 'status') +
101 content_tag('td', link_to_user(child.assigned_to), :class => 'assigned_to') +
101 content_tag('td', link_to_user(child.assigned_to), :class => 'assigned_to') +
102 content_tag('td', child.disabled_core_fields.include?('done_ratio') ? '' : progress_bar(child.done_ratio), :class=> 'done_ratio'),
102 content_tag('td', child.disabled_core_fields.include?('done_ratio') ? '' : progress_bar(child.done_ratio), :class=> 'done_ratio'),
103 :class => css)
103 :class => css)
104 end
104 end
105 s << '</table>'
105 s << '</table>'
106 s.html_safe
106 s.html_safe
107 end
107 end
108
108
109 # Renders the list of related issues on the issue details view
109 # Renders the list of related issues on the issue details view
110 def render_issue_relations(issue, relations)
110 def render_issue_relations(issue, relations)
111 manage_relations = User.current.allowed_to?(:manage_issue_relations, issue.project)
111 manage_relations = User.current.allowed_to?(:manage_issue_relations, issue.project)
112
112
113 s = ''.html_safe
113 s = ''.html_safe
114 relations.each do |relation|
114 relations.each do |relation|
115 other_issue = relation.other_issue(issue)
115 other_issue = relation.other_issue(issue)
116 css = "issue hascontextmenu #{other_issue.css_classes}"
116 css = "issue hascontextmenu #{other_issue.css_classes}"
117 link = manage_relations ? link_to(l(:label_relation_delete),
117 link = manage_relations ? link_to(l(:label_relation_delete),
118 relation_path(relation),
118 relation_path(relation),
119 :remote => true,
119 :remote => true,
120 :method => :delete,
120 :method => :delete,
121 :data => {:confirm => l(:text_are_you_sure)},
121 :data => {:confirm => l(:text_are_you_sure)},
122 :title => l(:label_relation_delete),
122 :title => l(:label_relation_delete),
123 :class => 'icon-only icon-link-break'
123 :class => 'icon-only icon-link-break'
124 ) : nil
124 ) : nil
125
125
126 s << content_tag('tr',
126 s << content_tag('tr',
127 content_tag('td', check_box_tag("ids[]", other_issue.id, false, :id => nil), :class => 'checkbox') +
127 content_tag('td', check_box_tag("ids[]", other_issue.id, false, :id => nil), :class => 'checkbox') +
128 content_tag('td', relation.to_s(@issue) {|other| link_to_issue(other, :project => Setting.cross_project_issue_relations?)}.html_safe, :class => 'subject', :style => 'width: 50%') +
128 content_tag('td', relation.to_s(@issue) {|other| link_to_issue(other, :project => Setting.cross_project_issue_relations?)}.html_safe, :class => 'subject', :style => 'width: 50%') +
129 content_tag('td', other_issue.status, :class => 'status') +
129 content_tag('td', other_issue.status, :class => 'status') +
130 content_tag('td', other_issue.start_date, :class => 'start_date') +
130 content_tag('td', other_issue.start_date, :class => 'start_date') +
131 content_tag('td', other_issue.due_date, :class => 'due_date') +
131 content_tag('td', other_issue.due_date, :class => 'due_date') +
132 content_tag('td', other_issue.disabled_core_fields.include?('done_ratio') ? '' : progress_bar(other_issue.done_ratio), :class=> 'done_ratio') +
132 content_tag('td', other_issue.disabled_core_fields.include?('done_ratio') ? '' : progress_bar(other_issue.done_ratio), :class=> 'done_ratio') +
133 content_tag('td', link, :class => 'buttons'),
133 content_tag('td', link, :class => 'buttons'),
134 :id => "relation-#{relation.id}",
134 :id => "relation-#{relation.id}",
135 :class => css)
135 :class => css)
136 end
136 end
137
137
138 content_tag('table', s, :class => 'list issues')
138 content_tag('table', s, :class => 'list issues')
139 end
139 end
140
140
141 def issue_estimated_hours_details(issue)
141 def issue_estimated_hours_details(issue)
142 if issue.total_estimated_hours.present?
142 if issue.total_estimated_hours.present?
143 if issue.total_estimated_hours == issue.estimated_hours
143 if issue.total_estimated_hours == issue.estimated_hours
144 l_hours_short(issue.estimated_hours)
144 l_hours_short(issue.estimated_hours)
145 else
145 else
146 s = issue.estimated_hours.present? ? l_hours_short(issue.estimated_hours) : ""
146 s = issue.estimated_hours.present? ? l_hours_short(issue.estimated_hours) : ""
147 s << " (#{l(:label_total)}: #{l_hours_short(issue.total_estimated_hours)})"
147 s << " (#{l(:label_total)}: #{l_hours_short(issue.total_estimated_hours)})"
148 s.html_safe
148 s.html_safe
149 end
149 end
150 end
150 end
151 end
151 end
152
152
153 def issue_spent_hours_details(issue)
153 def issue_spent_hours_details(issue)
154 if issue.total_spent_hours > 0
154 if issue.total_spent_hours > 0
155 path = project_time_entries_path(issue.project, :issue_id => "~#{issue.id}")
155 path = project_time_entries_path(issue.project, :issue_id => "~#{issue.id}")
156
156
157 if issue.total_spent_hours == issue.spent_hours
157 if issue.total_spent_hours == issue.spent_hours
158 link_to(l_hours_short(issue.spent_hours), path)
158 link_to(l_hours_short(issue.spent_hours), path)
159 else
159 else
160 s = issue.spent_hours > 0 ? l_hours_short(issue.spent_hours) : ""
160 s = issue.spent_hours > 0 ? l_hours_short(issue.spent_hours) : ""
161 s << " (#{l(:label_total)}: #{link_to l_hours_short(issue.total_spent_hours), path})"
161 s << " (#{l(:label_total)}: #{link_to l_hours_short(issue.total_spent_hours), path})"
162 s.html_safe
162 s.html_safe
163 end
163 end
164 end
164 end
165 end
165 end
166
166
167 # Returns an array of error messages for bulk edited issues
167 # Returns an array of error messages for bulk edited issues
168 def bulk_edit_error_messages(issues)
168 def bulk_edit_error_messages(issues)
169 messages = {}
169 messages = {}
170 issues.each do |issue|
170 issues.each do |issue|
171 issue.errors.full_messages.each do |message|
171 issue.errors.full_messages.each do |message|
172 messages[message] ||= []
172 messages[message] ||= []
173 messages[message] << issue
173 messages[message] << issue
174 end
174 end
175 end
175 end
176 messages.map { |message, issues|
176 messages.map { |message, issues|
177 "#{message}: " + issues.map {|i| "##{i.id}"}.join(', ')
177 "#{message}: " + issues.map {|i| "##{i.id}"}.join(', ')
178 }
178 }
179 end
179 end
180
180
181 # Returns a link for adding a new subtask to the given issue
181 # Returns a link for adding a new subtask to the given issue
182 def link_to_new_subtask(issue)
182 def link_to_new_subtask(issue)
183 attrs = {
183 attrs = {
184 :parent_issue_id => issue
184 :parent_issue_id => issue
185 }
185 }
186 attrs[:tracker_id] = issue.tracker unless issue.tracker.disabled_core_fields.include?('parent_issue_id')
186 attrs[:tracker_id] = issue.tracker unless issue.tracker.disabled_core_fields.include?('parent_issue_id')
187 link_to(l(:button_add), new_project_issue_path(issue.project, :issue => attrs))
187 link_to(l(:button_add), new_project_issue_path(issue.project, :issue => attrs))
188 end
188 end
189
189
190 def trackers_options_for_select(issue)
190 def trackers_options_for_select(issue)
191 trackers = issue.allowed_target_trackers
191 trackers = issue.allowed_target_trackers
192 if issue.new_record? && issue.parent_issue_id.present?
192 if issue.new_record? && issue.parent_issue_id.present?
193 trackers = trackers.reject do |tracker|
193 trackers = trackers.reject do |tracker|
194 issue.tracker_id != tracker.id && tracker.disabled_core_fields.include?('parent_issue_id')
194 issue.tracker_id != tracker.id && tracker.disabled_core_fields.include?('parent_issue_id')
195 end
195 end
196 end
196 end
197 trackers.collect {|t| [t.name, t.id]}
197 trackers.collect {|t| [t.name, t.id]}
198 end
198 end
199
199
200 class IssueFieldsRows
200 class IssueFieldsRows
201 include ActionView::Helpers::TagHelper
201 include ActionView::Helpers::TagHelper
202
202
203 def initialize
203 def initialize
204 @left = []
204 @left = []
205 @right = []
205 @right = []
206 end
206 end
207
207
208 def left(*args)
208 def left(*args)
209 args.any? ? @left << cells(*args) : @left
209 args.any? ? @left << cells(*args) : @left
210 end
210 end
211
211
212 def right(*args)
212 def right(*args)
213 args.any? ? @right << cells(*args) : @right
213 args.any? ? @right << cells(*args) : @right
214 end
214 end
215
215
216 def size
216 def size
217 @left.size > @right.size ? @left.size : @right.size
217 @left.size > @right.size ? @left.size : @right.size
218 end
218 end
219
219
220 def to_html
220 def to_html
221 content =
221 content =
222 content_tag('div', @left.reduce(&:+), :class => 'splitcontentleft') +
222 content_tag('div', @left.reduce(&:+), :class => 'splitcontentleft') +
223 content_tag('div', @right.reduce(&:+), :class => 'splitcontentleft')
223 content_tag('div', @right.reduce(&:+), :class => 'splitcontentleft')
224
224
225 content_tag('div', content, :class => 'splitcontent')
225 content_tag('div', content, :class => 'splitcontent')
226 end
226 end
227
227
228 def cells(label, text, options={})
228 def cells(label, text, options={})
229 options[:class] = [options[:class] || "", 'attribute'].join(' ')
229 options[:class] = [options[:class] || "", 'attribute'].join(' ')
230 content_tag 'div',
230 content_tag 'div',
231 content_tag('div', label + ":", :class => 'label') + content_tag('div', text, :class => 'value'),
231 content_tag('div', label + ":", :class => 'label') + content_tag('div', text, :class => 'value'),
232 options
232 options
233 end
233 end
234 end
234 end
235
235
236 def issue_fields_rows
236 def issue_fields_rows
237 r = IssueFieldsRows.new
237 r = IssueFieldsRows.new
238 yield r
238 yield r
239 r.to_html
239 r.to_html
240 end
240 end
241
241
242 def render_half_width_custom_fields_rows(issue)
242 def render_half_width_custom_fields_rows(issue)
243 values = issue.visible_custom_field_values.reject {|value| value.custom_field.full_width_layout?}
243 values = issue.visible_custom_field_values.reject {|value| value.custom_field.full_width_layout?}
244 return if values.empty?
244 return if values.empty?
245 half = (values.size / 2.0).ceil
245 half = (values.size / 2.0).ceil
246 issue_fields_rows do |rows|
246 issue_fields_rows do |rows|
247 values.each_with_index do |value, i|
247 values.each_with_index do |value, i|
248 css = "cf_#{value.custom_field.id}"
248 css = "cf_#{value.custom_field.id}"
249 m = (i < half ? :left : :right)
249 m = (i < half ? :left : :right)
250 rows.send m, custom_field_name_tag(value.custom_field), show_value(value), :class => css
250 rows.send m, custom_field_name_tag(value.custom_field), show_value(value), :class => css
251 end
251 end
252 end
252 end
253 end
253 end
254
254
255 def render_full_width_custom_fields_rows(issue)
255 def render_full_width_custom_fields_rows(issue)
256 values = issue.visible_custom_field_values.select {|value| value.custom_field.full_width_layout?}
256 values = issue.visible_custom_field_values.select {|value| value.custom_field.full_width_layout?}
257 return if values.empty?
257 return if values.empty?
258
258
259 s = ''.html_safe
259 s = ''.html_safe
260 values.each_with_index do |value, i|
260 values.each_with_index do |value, i|
261 attr_value = show_value(value)
262 next if attr_value.blank?
263
261 if value.custom_field.text_formatting == 'full'
264 if value.custom_field.text_formatting == 'full'
262 attr_value = content_tag('div', show_value(value), class: 'wiki')
265 attr_value = content_tag('div', attr_value, class: 'wiki')
263 else
264 attr_value = show_value(value)
265 end
266 end
267
266 content =
268 content =
267 content_tag('hr') +
269 content_tag('hr') +
268 content_tag('p', content_tag('strong', custom_field_name_tag(value.custom_field) )) +
270 content_tag('p', content_tag('strong', custom_field_name_tag(value.custom_field) )) +
269 content_tag('div', attr_value, class: 'value')
271 content_tag('div', attr_value, class: 'value')
270 s << content_tag('div', content, class: "cf_#{value.custom_field.id} attribute")
272 s << content_tag('div', content, class: "cf_#{value.custom_field.id} attribute")
271 end
273 end
272 s
274 s
273 end
275 end
274
276
275 # Returns the path for updating the issue form
277 # Returns the path for updating the issue form
276 # with project as the current project
278 # with project as the current project
277 def update_issue_form_path(project, issue)
279 def update_issue_form_path(project, issue)
278 options = {:format => 'js'}
280 options = {:format => 'js'}
279 if issue.new_record?
281 if issue.new_record?
280 if project
282 if project
281 new_project_issue_path(project, options)
283 new_project_issue_path(project, options)
282 else
284 else
283 new_issue_path(options)
285 new_issue_path(options)
284 end
286 end
285 else
287 else
286 edit_issue_path(issue, options)
288 edit_issue_path(issue, options)
287 end
289 end
288 end
290 end
289
291
290 # Returns the number of descendants for an array of issues
292 # Returns the number of descendants for an array of issues
291 def issues_descendant_count(issues)
293 def issues_descendant_count(issues)
292 ids = issues.reject(&:leaf?).map {|issue| issue.descendants.ids}.flatten.uniq
294 ids = issues.reject(&:leaf?).map {|issue| issue.descendants.ids}.flatten.uniq
293 ids -= issues.map(&:id)
295 ids -= issues.map(&:id)
294 ids.size
296 ids.size
295 end
297 end
296
298
297 def issues_destroy_confirmation_message(issues)
299 def issues_destroy_confirmation_message(issues)
298 issues = [issues] unless issues.is_a?(Array)
300 issues = [issues] unless issues.is_a?(Array)
299 message = l(:text_issues_destroy_confirmation)
301 message = l(:text_issues_destroy_confirmation)
300
302
301 descendant_count = issues_descendant_count(issues)
303 descendant_count = issues_descendant_count(issues)
302 if descendant_count > 0
304 if descendant_count > 0
303 message << "\n" + l(:text_issues_destroy_descendants_confirmation, :count => descendant_count)
305 message << "\n" + l(:text_issues_destroy_descendants_confirmation, :count => descendant_count)
304 end
306 end
305 message
307 message
306 end
308 end
307
309
308 # Returns an array of users that are proposed as watchers
310 # Returns an array of users that are proposed as watchers
309 # on the new issue form
311 # on the new issue form
310 def users_for_new_issue_watchers(issue)
312 def users_for_new_issue_watchers(issue)
311 users = issue.watcher_users
313 users = issue.watcher_users
312 if issue.project.users.count <= 20
314 if issue.project.users.count <= 20
313 users = (users + issue.project.users.sort).uniq
315 users = (users + issue.project.users.sort).uniq
314 end
316 end
315 users
317 users
316 end
318 end
317
319
318 def email_issue_attributes(issue, user, html)
320 def email_issue_attributes(issue, user, html)
319 items = []
321 items = []
320 %w(author status priority assigned_to category fixed_version).each do |attribute|
322 %w(author status priority assigned_to category fixed_version).each do |attribute|
321 unless issue.disabled_core_fields.include?(attribute+"_id")
323 unless issue.disabled_core_fields.include?(attribute+"_id")
322 if html
324 if html
323 items << content_tag('strong', "#{l("field_#{attribute}")}: ") + (issue.send attribute)
325 items << content_tag('strong', "#{l("field_#{attribute}")}: ") + (issue.send attribute)
324 else
326 else
325 items << "#{l("field_#{attribute}")}: #{issue.send attribute}"
327 items << "#{l("field_#{attribute}")}: #{issue.send attribute}"
326 end
328 end
327 end
329 end
328 end
330 end
329 issue.visible_custom_field_values(user).each do |value|
331 issue.visible_custom_field_values(user).each do |value|
330 if html
332 if html
331 items << content_tag('strong', "#{value.custom_field.name}: ") + show_value(value, false)
333 items << content_tag('strong', "#{value.custom_field.name}: ") + show_value(value, false)
332 else
334 else
333 items << "#{value.custom_field.name}: #{show_value(value, false)}"
335 items << "#{value.custom_field.name}: #{show_value(value, false)}"
334 end
336 end
335 end
337 end
336 items
338 items
337 end
339 end
338
340
339 def render_email_issue_attributes(issue, user, html=false)
341 def render_email_issue_attributes(issue, user, html=false)
340 items = email_issue_attributes(issue, user, html)
342 items = email_issue_attributes(issue, user, html)
341 if html
343 if html
342 content_tag('ul', items.map{|s| content_tag('li', s)}.join("\n").html_safe, :class => "details")
344 content_tag('ul', items.map{|s| content_tag('li', s)}.join("\n").html_safe, :class => "details")
343 else
345 else
344 items.map{|s| "* #{s}"}.join("\n")
346 items.map{|s| "* #{s}"}.join("\n")
345 end
347 end
346 end
348 end
347
349
348 # Returns the textual representation of a journal details
350 # Returns the textual representation of a journal details
349 # as an array of strings
351 # as an array of strings
350 def details_to_strings(details, no_html=false, options={})
352 def details_to_strings(details, no_html=false, options={})
351 options[:only_path] = (options[:only_path] == false ? false : true)
353 options[:only_path] = (options[:only_path] == false ? false : true)
352 strings = []
354 strings = []
353 values_by_field = {}
355 values_by_field = {}
354 details.each do |detail|
356 details.each do |detail|
355 if detail.property == 'cf'
357 if detail.property == 'cf'
356 field = detail.custom_field
358 field = detail.custom_field
357 if field && field.multiple?
359 if field && field.multiple?
358 values_by_field[field] ||= {:added => [], :deleted => []}
360 values_by_field[field] ||= {:added => [], :deleted => []}
359 if detail.old_value
361 if detail.old_value
360 values_by_field[field][:deleted] << detail.old_value
362 values_by_field[field][:deleted] << detail.old_value
361 end
363 end
362 if detail.value
364 if detail.value
363 values_by_field[field][:added] << detail.value
365 values_by_field[field][:added] << detail.value
364 end
366 end
365 next
367 next
366 end
368 end
367 end
369 end
368 strings << show_detail(detail, no_html, options)
370 strings << show_detail(detail, no_html, options)
369 end
371 end
370 if values_by_field.present?
372 if values_by_field.present?
371 multiple_values_detail = Struct.new(:property, :prop_key, :custom_field, :old_value, :value)
373 multiple_values_detail = Struct.new(:property, :prop_key, :custom_field, :old_value, :value)
372 values_by_field.each do |field, changes|
374 values_by_field.each do |field, changes|
373 if changes[:added].any?
375 if changes[:added].any?
374 detail = multiple_values_detail.new('cf', field.id.to_s, field)
376 detail = multiple_values_detail.new('cf', field.id.to_s, field)
375 detail.value = changes[:added]
377 detail.value = changes[:added]
376 strings << show_detail(detail, no_html, options)
378 strings << show_detail(detail, no_html, options)
377 end
379 end
378 if changes[:deleted].any?
380 if changes[:deleted].any?
379 detail = multiple_values_detail.new('cf', field.id.to_s, field)
381 detail = multiple_values_detail.new('cf', field.id.to_s, field)
380 detail.old_value = changes[:deleted]
382 detail.old_value = changes[:deleted]
381 strings << show_detail(detail, no_html, options)
383 strings << show_detail(detail, no_html, options)
382 end
384 end
383 end
385 end
384 end
386 end
385 strings
387 strings
386 end
388 end
387
389
388 # Returns the textual representation of a single journal detail
390 # Returns the textual representation of a single journal detail
389 def show_detail(detail, no_html=false, options={})
391 def show_detail(detail, no_html=false, options={})
390 multiple = false
392 multiple = false
391 show_diff = false
393 show_diff = false
392 no_details = false
394 no_details = false
393
395
394 case detail.property
396 case detail.property
395 when 'attr'
397 when 'attr'
396 field = detail.prop_key.to_s.gsub(/\_id$/, "")
398 field = detail.prop_key.to_s.gsub(/\_id$/, "")
397 label = l(("field_" + field).to_sym)
399 label = l(("field_" + field).to_sym)
398 case detail.prop_key
400 case detail.prop_key
399 when 'due_date', 'start_date'
401 when 'due_date', 'start_date'
400 value = format_date(detail.value.to_date) if detail.value
402 value = format_date(detail.value.to_date) if detail.value
401 old_value = format_date(detail.old_value.to_date) if detail.old_value
403 old_value = format_date(detail.old_value.to_date) if detail.old_value
402
404
403 when 'project_id', 'status_id', 'tracker_id', 'assigned_to_id',
405 when 'project_id', 'status_id', 'tracker_id', 'assigned_to_id',
404 'priority_id', 'category_id', 'fixed_version_id'
406 'priority_id', 'category_id', 'fixed_version_id'
405 value = find_name_by_reflection(field, detail.value)
407 value = find_name_by_reflection(field, detail.value)
406 old_value = find_name_by_reflection(field, detail.old_value)
408 old_value = find_name_by_reflection(field, detail.old_value)
407
409
408 when 'estimated_hours'
410 when 'estimated_hours'
409 value = l_hours_short(detail.value.to_f) unless detail.value.blank?
411 value = l_hours_short(detail.value.to_f) unless detail.value.blank?
410 old_value = l_hours_short(detail.old_value.to_f) unless detail.old_value.blank?
412 old_value = l_hours_short(detail.old_value.to_f) unless detail.old_value.blank?
411
413
412 when 'parent_id'
414 when 'parent_id'
413 label = l(:field_parent_issue)
415 label = l(:field_parent_issue)
414 value = "##{detail.value}" unless detail.value.blank?
416 value = "##{detail.value}" unless detail.value.blank?
415 old_value = "##{detail.old_value}" unless detail.old_value.blank?
417 old_value = "##{detail.old_value}" unless detail.old_value.blank?
416
418
417 when 'is_private'
419 when 'is_private'
418 value = l(detail.value == "0" ? :general_text_No : :general_text_Yes) unless detail.value.blank?
420 value = l(detail.value == "0" ? :general_text_No : :general_text_Yes) unless detail.value.blank?
419 old_value = l(detail.old_value == "0" ? :general_text_No : :general_text_Yes) unless detail.old_value.blank?
421 old_value = l(detail.old_value == "0" ? :general_text_No : :general_text_Yes) unless detail.old_value.blank?
420
422
421 when 'description'
423 when 'description'
422 show_diff = true
424 show_diff = true
423 end
425 end
424 when 'cf'
426 when 'cf'
425 custom_field = detail.custom_field
427 custom_field = detail.custom_field
426 if custom_field
428 if custom_field
427 label = custom_field.name
429 label = custom_field.name
428 if custom_field.format.class.change_no_details
430 if custom_field.format.class.change_no_details
429 no_details = true
431 no_details = true
430 elsif custom_field.format.class.change_as_diff
432 elsif custom_field.format.class.change_as_diff
431 show_diff = true
433 show_diff = true
432 else
434 else
433 multiple = custom_field.multiple?
435 multiple = custom_field.multiple?
434 value = format_value(detail.value, custom_field) if detail.value
436 value = format_value(detail.value, custom_field) if detail.value
435 old_value = format_value(detail.old_value, custom_field) if detail.old_value
437 old_value = format_value(detail.old_value, custom_field) if detail.old_value
436 end
438 end
437 end
439 end
438 when 'attachment'
440 when 'attachment'
439 label = l(:label_attachment)
441 label = l(:label_attachment)
440 when 'relation'
442 when 'relation'
441 if detail.value && !detail.old_value
443 if detail.value && !detail.old_value
442 rel_issue = Issue.visible.find_by_id(detail.value)
444 rel_issue = Issue.visible.find_by_id(detail.value)
443 value = rel_issue.nil? ? "#{l(:label_issue)} ##{detail.value}" :
445 value = rel_issue.nil? ? "#{l(:label_issue)} ##{detail.value}" :
444 (no_html ? rel_issue : link_to_issue(rel_issue, :only_path => options[:only_path]))
446 (no_html ? rel_issue : link_to_issue(rel_issue, :only_path => options[:only_path]))
445 elsif detail.old_value && !detail.value
447 elsif detail.old_value && !detail.value
446 rel_issue = Issue.visible.find_by_id(detail.old_value)
448 rel_issue = Issue.visible.find_by_id(detail.old_value)
447 old_value = rel_issue.nil? ? "#{l(:label_issue)} ##{detail.old_value}" :
449 old_value = rel_issue.nil? ? "#{l(:label_issue)} ##{detail.old_value}" :
448 (no_html ? rel_issue : link_to_issue(rel_issue, :only_path => options[:only_path]))
450 (no_html ? rel_issue : link_to_issue(rel_issue, :only_path => options[:only_path]))
449 end
451 end
450 relation_type = IssueRelation::TYPES[detail.prop_key]
452 relation_type = IssueRelation::TYPES[detail.prop_key]
451 label = l(relation_type[:name]) if relation_type
453 label = l(relation_type[:name]) if relation_type
452 end
454 end
453 call_hook(:helper_issues_show_detail_after_setting,
455 call_hook(:helper_issues_show_detail_after_setting,
454 {:detail => detail, :label => label, :value => value, :old_value => old_value })
456 {:detail => detail, :label => label, :value => value, :old_value => old_value })
455
457
456 label ||= detail.prop_key
458 label ||= detail.prop_key
457 value ||= detail.value
459 value ||= detail.value
458 old_value ||= detail.old_value
460 old_value ||= detail.old_value
459
461
460 unless no_html
462 unless no_html
461 label = content_tag('strong', label)
463 label = content_tag('strong', label)
462 old_value = content_tag("i", h(old_value)) if detail.old_value
464 old_value = content_tag("i", h(old_value)) if detail.old_value
463 if detail.old_value && detail.value.blank? && detail.property != 'relation'
465 if detail.old_value && detail.value.blank? && detail.property != 'relation'
464 old_value = content_tag("del", old_value)
466 old_value = content_tag("del", old_value)
465 end
467 end
466 if detail.property == 'attachment' && value.present? &&
468 if detail.property == 'attachment' && value.present? &&
467 atta = detail.journal.journalized.attachments.detect {|a| a.id == detail.prop_key.to_i}
469 atta = detail.journal.journalized.attachments.detect {|a| a.id == detail.prop_key.to_i}
468 # Link to the attachment if it has not been removed
470 # Link to the attachment if it has not been removed
469 value = link_to_attachment(atta, :download => true, :only_path => options[:only_path])
471 value = link_to_attachment(atta, :download => true, :only_path => options[:only_path])
470 if options[:only_path] != false && (atta.is_text? || atta.is_image?)
472 if options[:only_path] != false && (atta.is_text? || atta.is_image?)
471 value += ' '
473 value += ' '
472 value += link_to(l(:button_view),
474 value += link_to(l(:button_view),
473 { :controller => 'attachments', :action => 'show',
475 { :controller => 'attachments', :action => 'show',
474 :id => atta, :filename => atta.filename },
476 :id => atta, :filename => atta.filename },
475 :class => 'icon-only icon-magnifier',
477 :class => 'icon-only icon-magnifier',
476 :title => l(:button_view))
478 :title => l(:button_view))
477 end
479 end
478 else
480 else
479 value = content_tag("i", h(value)) if value
481 value = content_tag("i", h(value)) if value
480 end
482 end
481 end
483 end
482
484
483 if no_details
485 if no_details
484 s = l(:text_journal_changed_no_detail, :label => label).html_safe
486 s = l(:text_journal_changed_no_detail, :label => label).html_safe
485 elsif show_diff
487 elsif show_diff
486 s = l(:text_journal_changed_no_detail, :label => label)
488 s = l(:text_journal_changed_no_detail, :label => label)
487 unless no_html
489 unless no_html
488 diff_link = link_to 'diff',
490 diff_link = link_to 'diff',
489 diff_journal_url(detail.journal_id, :detail_id => detail.id, :only_path => options[:only_path]),
491 diff_journal_url(detail.journal_id, :detail_id => detail.id, :only_path => options[:only_path]),
490 :title => l(:label_view_diff)
492 :title => l(:label_view_diff)
491 s << " (#{ diff_link })"
493 s << " (#{ diff_link })"
492 end
494 end
493 s.html_safe
495 s.html_safe
494 elsif detail.value.present?
496 elsif detail.value.present?
495 case detail.property
497 case detail.property
496 when 'attr', 'cf'
498 when 'attr', 'cf'
497 if detail.old_value.present?
499 if detail.old_value.present?
498 l(:text_journal_changed, :label => label, :old => old_value, :new => value).html_safe
500 l(:text_journal_changed, :label => label, :old => old_value, :new => value).html_safe
499 elsif multiple
501 elsif multiple
500 l(:text_journal_added, :label => label, :value => value).html_safe
502 l(:text_journal_added, :label => label, :value => value).html_safe
501 else
503 else
502 l(:text_journal_set_to, :label => label, :value => value).html_safe
504 l(:text_journal_set_to, :label => label, :value => value).html_safe
503 end
505 end
504 when 'attachment', 'relation'
506 when 'attachment', 'relation'
505 l(:text_journal_added, :label => label, :value => value).html_safe
507 l(:text_journal_added, :label => label, :value => value).html_safe
506 end
508 end
507 else
509 else
508 l(:text_journal_deleted, :label => label, :old => old_value).html_safe
510 l(:text_journal_deleted, :label => label, :old => old_value).html_safe
509 end
511 end
510 end
512 end
511
513
512 # Find the name of an associated record stored in the field attribute
514 # Find the name of an associated record stored in the field attribute
513 def find_name_by_reflection(field, id)
515 def find_name_by_reflection(field, id)
514 unless id.present?
516 unless id.present?
515 return nil
517 return nil
516 end
518 end
517 @detail_value_name_by_reflection ||= Hash.new do |hash, key|
519 @detail_value_name_by_reflection ||= Hash.new do |hash, key|
518 association = Issue.reflect_on_association(key.first.to_sym)
520 association = Issue.reflect_on_association(key.first.to_sym)
519 name = nil
521 name = nil
520 if association
522 if association
521 record = association.klass.find_by_id(key.last)
523 record = association.klass.find_by_id(key.last)
522 if record
524 if record
523 name = record.name.force_encoding('UTF-8')
525 name = record.name.force_encoding('UTF-8')
524 end
526 end
525 end
527 end
526 hash[key] = name
528 hash[key] = name
527 end
529 end
528 @detail_value_name_by_reflection[[field, id]]
530 @detail_value_name_by_reflection[[field, id]]
529 end
531 end
530
532
531 # Renders issue children recursively
533 # Renders issue children recursively
532 def render_api_issue_children(issue, api)
534 def render_api_issue_children(issue, api)
533 return if issue.leaf?
535 return if issue.leaf?
534 api.array :children do
536 api.array :children do
535 issue.children.each do |child|
537 issue.children.each do |child|
536 api.issue(:id => child.id) do
538 api.issue(:id => child.id) do
537 api.tracker(:id => child.tracker_id, :name => child.tracker.name) unless child.tracker.nil?
539 api.tracker(:id => child.tracker_id, :name => child.tracker.name) unless child.tracker.nil?
538 api.subject child.subject
540 api.subject child.subject
539 render_api_issue_children(child, api)
541 render_api_issue_children(child, api)
540 end
542 end
541 end
543 end
542 end
544 end
543 end
545 end
544 end
546 end
General Comments 0
You need to be logged in to leave comments. Login now