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