##// END OF EJS Templates
Wrong CSS classes in subtasks tree (#23391)....
Jean-Philippe Lang -
r15357:1fad99ebe388
parent child
Show More
@@ -1,479 +1,479
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 = '<form><table class="list issues">'
93 s = '<form><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 #{issue.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></form>'
105 s << '</table></form>'
106 s.html_safe
106 s.html_safe
107 end
107 end
108
108
109 def issue_estimated_hours_details(issue)
109 def issue_estimated_hours_details(issue)
110 if issue.total_estimated_hours.present?
110 if issue.total_estimated_hours.present?
111 if issue.total_estimated_hours == issue.estimated_hours
111 if issue.total_estimated_hours == issue.estimated_hours
112 l_hours_short(issue.estimated_hours)
112 l_hours_short(issue.estimated_hours)
113 else
113 else
114 s = issue.estimated_hours.present? ? l_hours_short(issue.estimated_hours) : ""
114 s = issue.estimated_hours.present? ? l_hours_short(issue.estimated_hours) : ""
115 s << " (#{l(:label_total)}: #{l_hours_short(issue.total_estimated_hours)})"
115 s << " (#{l(:label_total)}: #{l_hours_short(issue.total_estimated_hours)})"
116 s.html_safe
116 s.html_safe
117 end
117 end
118 end
118 end
119 end
119 end
120
120
121 def issue_spent_hours_details(issue)
121 def issue_spent_hours_details(issue)
122 if issue.total_spent_hours > 0
122 if issue.total_spent_hours > 0
123 path = project_time_entries_path(issue.project, :issue_id => "~#{issue.id}")
123 path = project_time_entries_path(issue.project, :issue_id => "~#{issue.id}")
124
124
125 if issue.total_spent_hours == issue.spent_hours
125 if issue.total_spent_hours == issue.spent_hours
126 link_to(l_hours_short(issue.spent_hours), path)
126 link_to(l_hours_short(issue.spent_hours), path)
127 else
127 else
128 s = issue.spent_hours > 0 ? l_hours_short(issue.spent_hours) : ""
128 s = issue.spent_hours > 0 ? l_hours_short(issue.spent_hours) : ""
129 s << " (#{l(:label_total)}: #{link_to l_hours_short(issue.total_spent_hours), path})"
129 s << " (#{l(:label_total)}: #{link_to l_hours_short(issue.total_spent_hours), path})"
130 s.html_safe
130 s.html_safe
131 end
131 end
132 end
132 end
133 end
133 end
134
134
135 # Returns an array of error messages for bulk edited issues
135 # Returns an array of error messages for bulk edited issues
136 def bulk_edit_error_messages(issues)
136 def bulk_edit_error_messages(issues)
137 messages = {}
137 messages = {}
138 issues.each do |issue|
138 issues.each do |issue|
139 issue.errors.full_messages.each do |message|
139 issue.errors.full_messages.each do |message|
140 messages[message] ||= []
140 messages[message] ||= []
141 messages[message] << issue
141 messages[message] << issue
142 end
142 end
143 end
143 end
144 messages.map { |message, issues|
144 messages.map { |message, issues|
145 "#{message}: " + issues.map {|i| "##{i.id}"}.join(', ')
145 "#{message}: " + issues.map {|i| "##{i.id}"}.join(', ')
146 }
146 }
147 end
147 end
148
148
149 # Returns a link for adding a new subtask to the given issue
149 # Returns a link for adding a new subtask to the given issue
150 def link_to_new_subtask(issue)
150 def link_to_new_subtask(issue)
151 attrs = {
151 attrs = {
152 :parent_issue_id => issue
152 :parent_issue_id => issue
153 }
153 }
154 attrs[:tracker_id] = issue.tracker unless issue.tracker.disabled_core_fields.include?('parent_issue_id')
154 attrs[:tracker_id] = issue.tracker unless issue.tracker.disabled_core_fields.include?('parent_issue_id')
155 link_to(l(:button_add), new_project_issue_path(issue.project, :issue => attrs))
155 link_to(l(:button_add), new_project_issue_path(issue.project, :issue => attrs))
156 end
156 end
157
157
158 def trackers_options_for_select(issue)
158 def trackers_options_for_select(issue)
159 trackers = issue.allowed_target_trackers
159 trackers = issue.allowed_target_trackers
160 if issue.new_record? && issue.parent_issue_id.present?
160 if issue.new_record? && issue.parent_issue_id.present?
161 trackers = trackers.reject do |tracker|
161 trackers = trackers.reject do |tracker|
162 issue.tracker_id != tracker.id && tracker.disabled_core_fields.include?('parent_issue_id')
162 issue.tracker_id != tracker.id && tracker.disabled_core_fields.include?('parent_issue_id')
163 end
163 end
164 end
164 end
165 trackers.collect {|t| [t.name, t.id]}
165 trackers.collect {|t| [t.name, t.id]}
166 end
166 end
167
167
168 class IssueFieldsRows
168 class IssueFieldsRows
169 include ActionView::Helpers::TagHelper
169 include ActionView::Helpers::TagHelper
170
170
171 def initialize
171 def initialize
172 @left = []
172 @left = []
173 @right = []
173 @right = []
174 end
174 end
175
175
176 def left(*args)
176 def left(*args)
177 args.any? ? @left << cells(*args) : @left
177 args.any? ? @left << cells(*args) : @left
178 end
178 end
179
179
180 def right(*args)
180 def right(*args)
181 args.any? ? @right << cells(*args) : @right
181 args.any? ? @right << cells(*args) : @right
182 end
182 end
183
183
184 def size
184 def size
185 @left.size > @right.size ? @left.size : @right.size
185 @left.size > @right.size ? @left.size : @right.size
186 end
186 end
187
187
188 def to_html
188 def to_html
189 content =
189 content =
190 content_tag('div', @left.reduce(&:+), :class => 'splitcontentleft') +
190 content_tag('div', @left.reduce(&:+), :class => 'splitcontentleft') +
191 content_tag('div', @right.reduce(&:+), :class => 'splitcontentleft')
191 content_tag('div', @right.reduce(&:+), :class => 'splitcontentleft')
192
192
193 content_tag('div', content, :class => 'splitcontent')
193 content_tag('div', content, :class => 'splitcontent')
194 end
194 end
195
195
196 def cells(label, text, options={})
196 def cells(label, text, options={})
197 options[:class] = [options[:class] || "", 'attribute'].join(' ')
197 options[:class] = [options[:class] || "", 'attribute'].join(' ')
198 content_tag 'div',
198 content_tag 'div',
199 content_tag('div', label + ":", :class => 'label') + content_tag('div', text, :class => 'value'),
199 content_tag('div', label + ":", :class => 'label') + content_tag('div', text, :class => 'value'),
200 options
200 options
201 end
201 end
202 end
202 end
203
203
204 def issue_fields_rows
204 def issue_fields_rows
205 r = IssueFieldsRows.new
205 r = IssueFieldsRows.new
206 yield r
206 yield r
207 r.to_html
207 r.to_html
208 end
208 end
209
209
210 def render_custom_fields_rows(issue)
210 def render_custom_fields_rows(issue)
211 values = issue.visible_custom_field_values
211 values = issue.visible_custom_field_values
212 return if values.empty?
212 return if values.empty?
213 half = (values.size / 2.0).ceil
213 half = (values.size / 2.0).ceil
214 issue_fields_rows do |rows|
214 issue_fields_rows do |rows|
215 values.each_with_index do |value, i|
215 values.each_with_index do |value, i|
216 css = "cf_#{value.custom_field.id}"
216 css = "cf_#{value.custom_field.id}"
217 m = (i < half ? :left : :right)
217 m = (i < half ? :left : :right)
218 rows.send m, custom_field_name_tag(value.custom_field), show_value(value), :class => css
218 rows.send m, custom_field_name_tag(value.custom_field), show_value(value), :class => css
219 end
219 end
220 end
220 end
221 end
221 end
222
222
223 # Returns the path for updating the issue form
223 # Returns the path for updating the issue form
224 # with project as the current project
224 # with project as the current project
225 def update_issue_form_path(project, issue)
225 def update_issue_form_path(project, issue)
226 options = {:format => 'js'}
226 options = {:format => 'js'}
227 if issue.new_record?
227 if issue.new_record?
228 if project
228 if project
229 new_project_issue_path(project, options)
229 new_project_issue_path(project, options)
230 else
230 else
231 new_issue_path(options)
231 new_issue_path(options)
232 end
232 end
233 else
233 else
234 edit_issue_path(issue, options)
234 edit_issue_path(issue, options)
235 end
235 end
236 end
236 end
237
237
238 # Returns the number of descendants for an array of issues
238 # Returns the number of descendants for an array of issues
239 def issues_descendant_count(issues)
239 def issues_descendant_count(issues)
240 ids = issues.reject(&:leaf?).map {|issue| issue.descendants.ids}.flatten.uniq
240 ids = issues.reject(&:leaf?).map {|issue| issue.descendants.ids}.flatten.uniq
241 ids -= issues.map(&:id)
241 ids -= issues.map(&:id)
242 ids.size
242 ids.size
243 end
243 end
244
244
245 def issues_destroy_confirmation_message(issues)
245 def issues_destroy_confirmation_message(issues)
246 issues = [issues] unless issues.is_a?(Array)
246 issues = [issues] unless issues.is_a?(Array)
247 message = l(:text_issues_destroy_confirmation)
247 message = l(:text_issues_destroy_confirmation)
248
248
249 descendant_count = issues_descendant_count(issues)
249 descendant_count = issues_descendant_count(issues)
250 if descendant_count > 0
250 if descendant_count > 0
251 message << "\n" + l(:text_issues_destroy_descendants_confirmation, :count => descendant_count)
251 message << "\n" + l(:text_issues_destroy_descendants_confirmation, :count => descendant_count)
252 end
252 end
253 message
253 message
254 end
254 end
255
255
256 # Returns an array of users that are proposed as watchers
256 # Returns an array of users that are proposed as watchers
257 # on the new issue form
257 # on the new issue form
258 def users_for_new_issue_watchers(issue)
258 def users_for_new_issue_watchers(issue)
259 users = issue.watcher_users
259 users = issue.watcher_users
260 if issue.project.users.count <= 20
260 if issue.project.users.count <= 20
261 users = (users + issue.project.users.sort).uniq
261 users = (users + issue.project.users.sort).uniq
262 end
262 end
263 users
263 users
264 end
264 end
265
265
266 def email_issue_attributes(issue, user)
266 def email_issue_attributes(issue, user)
267 items = []
267 items = []
268 %w(author status priority assigned_to category fixed_version).each do |attribute|
268 %w(author status priority assigned_to category fixed_version).each do |attribute|
269 unless issue.disabled_core_fields.include?(attribute+"_id")
269 unless issue.disabled_core_fields.include?(attribute+"_id")
270 items << "#{l("field_#{attribute}")}: #{issue.send attribute}"
270 items << "#{l("field_#{attribute}")}: #{issue.send attribute}"
271 end
271 end
272 end
272 end
273 issue.visible_custom_field_values(user).each do |value|
273 issue.visible_custom_field_values(user).each do |value|
274 items << "#{value.custom_field.name}: #{show_value(value, false)}"
274 items << "#{value.custom_field.name}: #{show_value(value, false)}"
275 end
275 end
276 items
276 items
277 end
277 end
278
278
279 def render_email_issue_attributes(issue, user, html=false)
279 def render_email_issue_attributes(issue, user, html=false)
280 items = email_issue_attributes(issue, user)
280 items = email_issue_attributes(issue, user)
281 if html
281 if html
282 content_tag('ul', items.map{|s| content_tag('li', s)}.join("\n").html_safe)
282 content_tag('ul', items.map{|s| content_tag('li', s)}.join("\n").html_safe)
283 else
283 else
284 items.map{|s| "* #{s}"}.join("\n")
284 items.map{|s| "* #{s}"}.join("\n")
285 end
285 end
286 end
286 end
287
287
288 # Returns the textual representation of a journal details
288 # Returns the textual representation of a journal details
289 # as an array of strings
289 # as an array of strings
290 def details_to_strings(details, no_html=false, options={})
290 def details_to_strings(details, no_html=false, options={})
291 options[:only_path] = (options[:only_path] == false ? false : true)
291 options[:only_path] = (options[:only_path] == false ? false : true)
292 strings = []
292 strings = []
293 values_by_field = {}
293 values_by_field = {}
294 details.each do |detail|
294 details.each do |detail|
295 if detail.property == 'cf'
295 if detail.property == 'cf'
296 field = detail.custom_field
296 field = detail.custom_field
297 if field && field.multiple?
297 if field && field.multiple?
298 values_by_field[field] ||= {:added => [], :deleted => []}
298 values_by_field[field] ||= {:added => [], :deleted => []}
299 if detail.old_value
299 if detail.old_value
300 values_by_field[field][:deleted] << detail.old_value
300 values_by_field[field][:deleted] << detail.old_value
301 end
301 end
302 if detail.value
302 if detail.value
303 values_by_field[field][:added] << detail.value
303 values_by_field[field][:added] << detail.value
304 end
304 end
305 next
305 next
306 end
306 end
307 end
307 end
308 strings << show_detail(detail, no_html, options)
308 strings << show_detail(detail, no_html, options)
309 end
309 end
310 if values_by_field.present?
310 if values_by_field.present?
311 multiple_values_detail = Struct.new(:property, :prop_key, :custom_field, :old_value, :value)
311 multiple_values_detail = Struct.new(:property, :prop_key, :custom_field, :old_value, :value)
312 values_by_field.each do |field, changes|
312 values_by_field.each do |field, changes|
313 if changes[:added].any?
313 if changes[:added].any?
314 detail = multiple_values_detail.new('cf', field.id.to_s, field)
314 detail = multiple_values_detail.new('cf', field.id.to_s, field)
315 detail.value = changes[:added]
315 detail.value = changes[:added]
316 strings << show_detail(detail, no_html, options)
316 strings << show_detail(detail, no_html, options)
317 end
317 end
318 if changes[:deleted].any?
318 if changes[:deleted].any?
319 detail = multiple_values_detail.new('cf', field.id.to_s, field)
319 detail = multiple_values_detail.new('cf', field.id.to_s, field)
320 detail.old_value = changes[:deleted]
320 detail.old_value = changes[:deleted]
321 strings << show_detail(detail, no_html, options)
321 strings << show_detail(detail, no_html, options)
322 end
322 end
323 end
323 end
324 end
324 end
325 strings
325 strings
326 end
326 end
327
327
328 # Returns the textual representation of a single journal detail
328 # Returns the textual representation of a single journal detail
329 def show_detail(detail, no_html=false, options={})
329 def show_detail(detail, no_html=false, options={})
330 multiple = false
330 multiple = false
331 show_diff = false
331 show_diff = false
332
332
333 case detail.property
333 case detail.property
334 when 'attr'
334 when 'attr'
335 field = detail.prop_key.to_s.gsub(/\_id$/, "")
335 field = detail.prop_key.to_s.gsub(/\_id$/, "")
336 label = l(("field_" + field).to_sym)
336 label = l(("field_" + field).to_sym)
337 case detail.prop_key
337 case detail.prop_key
338 when 'due_date', 'start_date'
338 when 'due_date', 'start_date'
339 value = format_date(detail.value.to_date) if detail.value
339 value = format_date(detail.value.to_date) if detail.value
340 old_value = format_date(detail.old_value.to_date) if detail.old_value
340 old_value = format_date(detail.old_value.to_date) if detail.old_value
341
341
342 when 'project_id', 'status_id', 'tracker_id', 'assigned_to_id',
342 when 'project_id', 'status_id', 'tracker_id', 'assigned_to_id',
343 'priority_id', 'category_id', 'fixed_version_id'
343 'priority_id', 'category_id', 'fixed_version_id'
344 value = find_name_by_reflection(field, detail.value)
344 value = find_name_by_reflection(field, detail.value)
345 old_value = find_name_by_reflection(field, detail.old_value)
345 old_value = find_name_by_reflection(field, detail.old_value)
346
346
347 when 'estimated_hours'
347 when 'estimated_hours'
348 value = l_hours_short(detail.value.to_f) unless detail.value.blank?
348 value = l_hours_short(detail.value.to_f) unless detail.value.blank?
349 old_value = l_hours_short(detail.old_value.to_f) unless detail.old_value.blank?
349 old_value = l_hours_short(detail.old_value.to_f) unless detail.old_value.blank?
350
350
351 when 'parent_id'
351 when 'parent_id'
352 label = l(:field_parent_issue)
352 label = l(:field_parent_issue)
353 value = "##{detail.value}" unless detail.value.blank?
353 value = "##{detail.value}" unless detail.value.blank?
354 old_value = "##{detail.old_value}" unless detail.old_value.blank?
354 old_value = "##{detail.old_value}" unless detail.old_value.blank?
355
355
356 when 'is_private'
356 when 'is_private'
357 value = l(detail.value == "0" ? :general_text_No : :general_text_Yes) unless detail.value.blank?
357 value = l(detail.value == "0" ? :general_text_No : :general_text_Yes) unless detail.value.blank?
358 old_value = l(detail.old_value == "0" ? :general_text_No : :general_text_Yes) unless detail.old_value.blank?
358 old_value = l(detail.old_value == "0" ? :general_text_No : :general_text_Yes) unless detail.old_value.blank?
359
359
360 when 'description'
360 when 'description'
361 show_diff = true
361 show_diff = true
362 end
362 end
363 when 'cf'
363 when 'cf'
364 custom_field = detail.custom_field
364 custom_field = detail.custom_field
365 if custom_field
365 if custom_field
366 label = custom_field.name
366 label = custom_field.name
367 if custom_field.format.class.change_as_diff
367 if custom_field.format.class.change_as_diff
368 show_diff = true
368 show_diff = true
369 else
369 else
370 multiple = custom_field.multiple?
370 multiple = custom_field.multiple?
371 value = format_value(detail.value, custom_field) if detail.value
371 value = format_value(detail.value, custom_field) if detail.value
372 old_value = format_value(detail.old_value, custom_field) if detail.old_value
372 old_value = format_value(detail.old_value, custom_field) if detail.old_value
373 end
373 end
374 end
374 end
375 when 'attachment'
375 when 'attachment'
376 label = l(:label_attachment)
376 label = l(:label_attachment)
377 when 'relation'
377 when 'relation'
378 if detail.value && !detail.old_value
378 if detail.value && !detail.old_value
379 rel_issue = Issue.visible.find_by_id(detail.value)
379 rel_issue = Issue.visible.find_by_id(detail.value)
380 value = rel_issue.nil? ? "#{l(:label_issue)} ##{detail.value}" :
380 value = rel_issue.nil? ? "#{l(:label_issue)} ##{detail.value}" :
381 (no_html ? rel_issue : link_to_issue(rel_issue, :only_path => options[:only_path]))
381 (no_html ? rel_issue : link_to_issue(rel_issue, :only_path => options[:only_path]))
382 elsif detail.old_value && !detail.value
382 elsif detail.old_value && !detail.value
383 rel_issue = Issue.visible.find_by_id(detail.old_value)
383 rel_issue = Issue.visible.find_by_id(detail.old_value)
384 old_value = rel_issue.nil? ? "#{l(:label_issue)} ##{detail.old_value}" :
384 old_value = rel_issue.nil? ? "#{l(:label_issue)} ##{detail.old_value}" :
385 (no_html ? rel_issue : link_to_issue(rel_issue, :only_path => options[:only_path]))
385 (no_html ? rel_issue : link_to_issue(rel_issue, :only_path => options[:only_path]))
386 end
386 end
387 relation_type = IssueRelation::TYPES[detail.prop_key]
387 relation_type = IssueRelation::TYPES[detail.prop_key]
388 label = l(relation_type[:name]) if relation_type
388 label = l(relation_type[:name]) if relation_type
389 end
389 end
390 call_hook(:helper_issues_show_detail_after_setting,
390 call_hook(:helper_issues_show_detail_after_setting,
391 {:detail => detail, :label => label, :value => value, :old_value => old_value })
391 {:detail => detail, :label => label, :value => value, :old_value => old_value })
392
392
393 label ||= detail.prop_key
393 label ||= detail.prop_key
394 value ||= detail.value
394 value ||= detail.value
395 old_value ||= detail.old_value
395 old_value ||= detail.old_value
396
396
397 unless no_html
397 unless no_html
398 label = content_tag('strong', label)
398 label = content_tag('strong', label)
399 old_value = content_tag("i", h(old_value)) if detail.old_value
399 old_value = content_tag("i", h(old_value)) if detail.old_value
400 if detail.old_value && detail.value.blank? && detail.property != 'relation'
400 if detail.old_value && detail.value.blank? && detail.property != 'relation'
401 old_value = content_tag("del", old_value)
401 old_value = content_tag("del", old_value)
402 end
402 end
403 if detail.property == 'attachment' && value.present? &&
403 if detail.property == 'attachment' && value.present? &&
404 atta = detail.journal.journalized.attachments.detect {|a| a.id == detail.prop_key.to_i}
404 atta = detail.journal.journalized.attachments.detect {|a| a.id == detail.prop_key.to_i}
405 # Link to the attachment if it has not been removed
405 # Link to the attachment if it has not been removed
406 value = link_to_attachment(atta, :download => true, :only_path => options[:only_path])
406 value = link_to_attachment(atta, :download => true, :only_path => options[:only_path])
407 if options[:only_path] != false && (atta.is_text? || atta.is_image?)
407 if options[:only_path] != false && (atta.is_text? || atta.is_image?)
408 value += ' '
408 value += ' '
409 value += link_to(l(:button_view),
409 value += link_to(l(:button_view),
410 { :controller => 'attachments', :action => 'show',
410 { :controller => 'attachments', :action => 'show',
411 :id => atta, :filename => atta.filename },
411 :id => atta, :filename => atta.filename },
412 :class => 'icon-only icon-magnifier',
412 :class => 'icon-only icon-magnifier',
413 :title => l(:button_view))
413 :title => l(:button_view))
414 end
414 end
415 else
415 else
416 value = content_tag("i", h(value)) if value
416 value = content_tag("i", h(value)) if value
417 end
417 end
418 end
418 end
419
419
420 if show_diff
420 if show_diff
421 s = l(:text_journal_changed_no_detail, :label => label)
421 s = l(:text_journal_changed_no_detail, :label => label)
422 unless no_html
422 unless no_html
423 diff_link = link_to 'diff',
423 diff_link = link_to 'diff',
424 diff_journal_url(detail.journal_id, :detail_id => detail.id, :only_path => options[:only_path]),
424 diff_journal_url(detail.journal_id, :detail_id => detail.id, :only_path => options[:only_path]),
425 :title => l(:label_view_diff)
425 :title => l(:label_view_diff)
426 s << " (#{ diff_link })"
426 s << " (#{ diff_link })"
427 end
427 end
428 s.html_safe
428 s.html_safe
429 elsif detail.value.present?
429 elsif detail.value.present?
430 case detail.property
430 case detail.property
431 when 'attr', 'cf'
431 when 'attr', 'cf'
432 if detail.old_value.present?
432 if detail.old_value.present?
433 l(:text_journal_changed, :label => label, :old => old_value, :new => value).html_safe
433 l(:text_journal_changed, :label => label, :old => old_value, :new => value).html_safe
434 elsif multiple
434 elsif multiple
435 l(:text_journal_added, :label => label, :value => value).html_safe
435 l(:text_journal_added, :label => label, :value => value).html_safe
436 else
436 else
437 l(:text_journal_set_to, :label => label, :value => value).html_safe
437 l(:text_journal_set_to, :label => label, :value => value).html_safe
438 end
438 end
439 when 'attachment', 'relation'
439 when 'attachment', 'relation'
440 l(:text_journal_added, :label => label, :value => value).html_safe
440 l(:text_journal_added, :label => label, :value => value).html_safe
441 end
441 end
442 else
442 else
443 l(:text_journal_deleted, :label => label, :old => old_value).html_safe
443 l(:text_journal_deleted, :label => label, :old => old_value).html_safe
444 end
444 end
445 end
445 end
446
446
447 # Find the name of an associated record stored in the field attribute
447 # Find the name of an associated record stored in the field attribute
448 def find_name_by_reflection(field, id)
448 def find_name_by_reflection(field, id)
449 unless id.present?
449 unless id.present?
450 return nil
450 return nil
451 end
451 end
452 @detail_value_name_by_reflection ||= Hash.new do |hash, key|
452 @detail_value_name_by_reflection ||= Hash.new do |hash, key|
453 association = Issue.reflect_on_association(key.first.to_sym)
453 association = Issue.reflect_on_association(key.first.to_sym)
454 name = nil
454 name = nil
455 if association
455 if association
456 record = association.klass.find_by_id(key.last)
456 record = association.klass.find_by_id(key.last)
457 if record
457 if record
458 name = record.name.force_encoding('UTF-8')
458 name = record.name.force_encoding('UTF-8')
459 end
459 end
460 end
460 end
461 hash[key] = name
461 hash[key] = name
462 end
462 end
463 @detail_value_name_by_reflection[[field, id]]
463 @detail_value_name_by_reflection[[field, id]]
464 end
464 end
465
465
466 # Renders issue children recursively
466 # Renders issue children recursively
467 def render_api_issue_children(issue, api)
467 def render_api_issue_children(issue, api)
468 return if issue.leaf?
468 return if issue.leaf?
469 api.array :children do
469 api.array :children do
470 issue.children.each do |child|
470 issue.children.each do |child|
471 api.issue(:id => child.id) do
471 api.issue(:id => child.id) do
472 api.tracker(:id => child.tracker_id, :name => child.tracker.name) unless child.tracker.nil?
472 api.tracker(:id => child.tracker_id, :name => child.tracker.name) unless child.tracker.nil?
473 api.subject child.subject
473 api.subject child.subject
474 render_api_issue_children(child, api)
474 render_api_issue_children(child, api)
475 end
475 end
476 end
476 end
477 end
477 end
478 end
478 end
479 end
479 end
General Comments 0
You need to be logged in to leave comments. Login now