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