##// END OF EJS Templates
Add missing links to images in issue history (#22058)....
Jean-Philippe Lang -
r15169:42e8ff4493e5
parent child
Show More
@@ -1,525 +1,526
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, :assigned_to).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 115 content_tag('td', h(child.status), :class => 'status') +
116 116 content_tag('td', link_to_user(child.assigned_to), :class => 'assigned_to') +
117 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 :parent_issue_id => issue
166 166 }
167 167 attrs[:tracker_id] = issue.tracker unless issue.tracker.disabled_core_fields.include?('parent_issue_id')
168 168 link_to(l(:button_add), new_project_issue_path(issue.project, :issue => attrs))
169 169 end
170 170
171 171 def trackers_options_for_select(issue)
172 172 trackers = issue.allowed_target_trackers
173 173 if issue.new_record? && issue.parent_issue_id.present?
174 174 trackers = trackers.reject do |tracker|
175 175 issue.tracker_id != tracker.id && tracker.disabled_core_fields.include?('parent_issue_id')
176 176 end
177 177 end
178 178 trackers.collect {|t| [t.name, t.id]}
179 179 end
180 180
181 181 class IssueFieldsRows
182 182 include ActionView::Helpers::TagHelper
183 183
184 184 def initialize
185 185 @left = []
186 186 @right = []
187 187 end
188 188
189 189 def left(*args)
190 190 args.any? ? @left << cells(*args) : @left
191 191 end
192 192
193 193 def right(*args)
194 194 args.any? ? @right << cells(*args) : @right
195 195 end
196 196
197 197 def size
198 198 @left.size > @right.size ? @left.size : @right.size
199 199 end
200 200
201 201 def to_html
202 202 content =
203 203 content_tag('div', @left.reduce(&:+), :class => 'splitcontentleft') +
204 204 content_tag('div', @right.reduce(&:+), :class => 'splitcontentleft')
205 205
206 206 content_tag('div', content, :class => 'splitcontent')
207 207 end
208 208
209 209 def cells(label, text, options={})
210 210 options[:class] = [options[:class] || "", 'attribute'].join(' ')
211 211 content_tag 'div',
212 212 content_tag('div', label + ":", :class => 'label') + content_tag('div', text, :class => 'value'),
213 213 options
214 214 end
215 215 end
216 216
217 217 def issue_fields_rows
218 218 r = IssueFieldsRows.new
219 219 yield r
220 220 r.to_html
221 221 end
222 222
223 223 def render_custom_fields_rows(issue)
224 224 values = issue.visible_custom_field_values
225 225 return if values.empty?
226 226 half = (values.size / 2.0).ceil
227 227 issue_fields_rows do |rows|
228 228 values.each_with_index do |value, i|
229 229 css = "cf_#{value.custom_field.id}"
230 230 m = (i < half ? :left : :right)
231 231 rows.send m, custom_field_name_tag(value.custom_field), show_value(value), :class => css
232 232 end
233 233 end
234 234 end
235 235
236 236 # Returns the path for updating the issue form
237 237 # with project as the current project
238 238 def update_issue_form_path(project, issue)
239 239 options = {:format => 'js'}
240 240 if issue.new_record?
241 241 if project
242 242 new_project_issue_path(project, options)
243 243 else
244 244 new_issue_path(options)
245 245 end
246 246 else
247 247 edit_issue_path(issue, options)
248 248 end
249 249 end
250 250
251 251 # Returns the number of descendants for an array of issues
252 252 def issues_descendant_count(issues)
253 253 ids = issues.reject(&:leaf?).map {|issue| issue.descendants.ids}.flatten.uniq
254 254 ids -= issues.map(&:id)
255 255 ids.size
256 256 end
257 257
258 258 def issues_destroy_confirmation_message(issues)
259 259 issues = [issues] unless issues.is_a?(Array)
260 260 message = l(:text_issues_destroy_confirmation)
261 261
262 262 descendant_count = issues_descendant_count(issues)
263 263 if descendant_count > 0
264 264 message << "\n" + l(:text_issues_destroy_descendants_confirmation, :count => descendant_count)
265 265 end
266 266 message
267 267 end
268 268
269 269 # Returns an array of users that are proposed as watchers
270 270 # on the new issue form
271 271 def users_for_new_issue_watchers(issue)
272 272 users = issue.watcher_users
273 273 if issue.project.users.count <= 20
274 274 users = (users + issue.project.users.sort).uniq
275 275 end
276 276 users
277 277 end
278 278
279 279 def sidebar_queries
280 280 unless @sidebar_queries
281 281 @sidebar_queries = IssueQuery.visible.
282 282 order("#{Query.table_name}.name ASC").
283 283 # Project specific queries and global queries
284 284 where(@project.nil? ? ["project_id IS NULL"] : ["project_id IS NULL OR project_id = ?", @project.id]).
285 285 to_a
286 286 end
287 287 @sidebar_queries
288 288 end
289 289
290 290 def query_links(title, queries)
291 291 return '' if queries.empty?
292 292 # links to #index on issues/show
293 293 url_params = controller_name == 'issues' ? {:controller => 'issues', :action => 'index', :project_id => @project} : params
294 294
295 295 content_tag('h3', title) + "\n" +
296 296 content_tag('ul',
297 297 queries.collect {|query|
298 298 css = 'query'
299 299 css << ' selected' if query == @query
300 300 content_tag('li', link_to(query.name, url_params.merge(:query_id => query), :class => css))
301 301 }.join("\n").html_safe,
302 302 :class => 'queries'
303 303 ) + "\n"
304 304 end
305 305
306 306 def render_sidebar_queries
307 307 out = ''.html_safe
308 308 out << query_links(l(:label_my_queries), sidebar_queries.select(&:is_private?))
309 309 out << query_links(l(:label_query_plural), sidebar_queries.reject(&:is_private?))
310 310 out
311 311 end
312 312
313 313 def email_issue_attributes(issue, user)
314 314 items = []
315 315 %w(author status priority assigned_to category fixed_version).each do |attribute|
316 316 unless issue.disabled_core_fields.include?(attribute+"_id")
317 317 items << "#{l("field_#{attribute}")}: #{issue.send attribute}"
318 318 end
319 319 end
320 320 issue.visible_custom_field_values(user).each do |value|
321 321 items << "#{value.custom_field.name}: #{show_value(value, false)}"
322 322 end
323 323 items
324 324 end
325 325
326 326 def render_email_issue_attributes(issue, user, html=false)
327 327 items = email_issue_attributes(issue, user)
328 328 if html
329 329 content_tag('ul', items.map{|s| content_tag('li', s)}.join("\n").html_safe)
330 330 else
331 331 items.map{|s| "* #{s}"}.join("\n")
332 332 end
333 333 end
334 334
335 335 # Returns the textual representation of a journal details
336 336 # as an array of strings
337 337 def details_to_strings(details, no_html=false, options={})
338 338 options[:only_path] = (options[:only_path] == false ? false : true)
339 339 strings = []
340 340 values_by_field = {}
341 341 details.each do |detail|
342 342 if detail.property == 'cf'
343 343 field = detail.custom_field
344 344 if field && field.multiple?
345 345 values_by_field[field] ||= {:added => [], :deleted => []}
346 346 if detail.old_value
347 347 values_by_field[field][:deleted] << detail.old_value
348 348 end
349 349 if detail.value
350 350 values_by_field[field][:added] << detail.value
351 351 end
352 352 next
353 353 end
354 354 end
355 355 strings << show_detail(detail, no_html, options)
356 356 end
357 357 if values_by_field.present?
358 358 multiple_values_detail = Struct.new(:property, :prop_key, :custom_field, :old_value, :value)
359 359 values_by_field.each do |field, changes|
360 360 if changes[:added].any?
361 361 detail = multiple_values_detail.new('cf', field.id.to_s, field)
362 362 detail.value = changes[:added]
363 363 strings << show_detail(detail, no_html, options)
364 364 end
365 365 if changes[:deleted].any?
366 366 detail = multiple_values_detail.new('cf', field.id.to_s, field)
367 367 detail.old_value = changes[:deleted]
368 368 strings << show_detail(detail, no_html, options)
369 369 end
370 370 end
371 371 end
372 372 strings
373 373 end
374 374
375 375 # Returns the textual representation of a single journal detail
376 376 def show_detail(detail, no_html=false, options={})
377 377 multiple = false
378 378 show_diff = false
379 379
380 380 case detail.property
381 381 when 'attr'
382 382 field = detail.prop_key.to_s.gsub(/\_id$/, "")
383 383 label = l(("field_" + field).to_sym)
384 384 case detail.prop_key
385 385 when 'due_date', 'start_date'
386 386 value = format_date(detail.value.to_date) if detail.value
387 387 old_value = format_date(detail.old_value.to_date) if detail.old_value
388 388
389 389 when 'project_id', 'status_id', 'tracker_id', 'assigned_to_id',
390 390 'priority_id', 'category_id', 'fixed_version_id'
391 391 value = find_name_by_reflection(field, detail.value)
392 392 old_value = find_name_by_reflection(field, detail.old_value)
393 393
394 394 when 'estimated_hours'
395 395 value = l_hours_short(detail.value.to_f) unless detail.value.blank?
396 396 old_value = l_hours_short(detail.old_value.to_f) unless detail.old_value.blank?
397 397
398 398 when 'parent_id'
399 399 label = l(:field_parent_issue)
400 400 value = "##{detail.value}" unless detail.value.blank?
401 401 old_value = "##{detail.old_value}" unless detail.old_value.blank?
402 402
403 403 when 'is_private'
404 404 value = l(detail.value == "0" ? :general_text_No : :general_text_Yes) unless detail.value.blank?
405 405 old_value = l(detail.old_value == "0" ? :general_text_No : :general_text_Yes) unless detail.old_value.blank?
406 406
407 407 when 'description'
408 408 show_diff = true
409 409 end
410 410 when 'cf'
411 411 custom_field = detail.custom_field
412 412 if custom_field
413 413 label = custom_field.name
414 414 if custom_field.format.class.change_as_diff
415 415 show_diff = true
416 416 else
417 417 multiple = custom_field.multiple?
418 418 value = format_value(detail.value, custom_field) if detail.value
419 419 old_value = format_value(detail.old_value, custom_field) if detail.old_value
420 420 end
421 421 end
422 422 when 'attachment'
423 423 label = l(:label_attachment)
424 424 when 'relation'
425 425 if detail.value && !detail.old_value
426 426 rel_issue = Issue.visible.find_by_id(detail.value)
427 427 value = rel_issue.nil? ? "#{l(:label_issue)} ##{detail.value}" :
428 428 (no_html ? rel_issue : link_to_issue(rel_issue, :only_path => options[:only_path]))
429 429 elsif detail.old_value && !detail.value
430 430 rel_issue = Issue.visible.find_by_id(detail.old_value)
431 431 old_value = rel_issue.nil? ? "#{l(:label_issue)} ##{detail.old_value}" :
432 432 (no_html ? rel_issue : link_to_issue(rel_issue, :only_path => options[:only_path]))
433 433 end
434 434 relation_type = IssueRelation::TYPES[detail.prop_key]
435 435 label = l(relation_type[:name]) if relation_type
436 436 end
437 437 call_hook(:helper_issues_show_detail_after_setting,
438 438 {:detail => detail, :label => label, :value => value, :old_value => old_value })
439 439
440 440 label ||= detail.prop_key
441 441 value ||= detail.value
442 442 old_value ||= detail.old_value
443 443
444 444 unless no_html
445 445 label = content_tag('strong', label)
446 446 old_value = content_tag("i", h(old_value)) if detail.old_value
447 447 if detail.old_value && detail.value.blank? && detail.property != 'relation'
448 448 old_value = content_tag("del", old_value)
449 449 end
450 450 if detail.property == 'attachment' && value.present? &&
451 451 atta = detail.journal.journalized.attachments.detect {|a| a.id == detail.prop_key.to_i}
452 452 # Link to the attachment if it has not been removed
453 453 value = link_to_attachment(atta, :download => true, :only_path => options[:only_path])
454 if options[:only_path] != false && atta.is_text?
454 if options[:only_path] != false && (atta.is_text? || atta.is_image?)
455 value += ' '
455 456 value += link_to(l(:button_view),
456 457 { :controller => 'attachments', :action => 'show',
457 458 :id => atta, :filename => atta.filename },
458 459 :class => 'icon-only icon-magnifier',
459 460 :title => l(:button_view))
460 461 end
461 462 else
462 463 value = content_tag("i", h(value)) if value
463 464 end
464 465 end
465 466
466 467 if show_diff
467 468 s = l(:text_journal_changed_no_detail, :label => label)
468 469 unless no_html
469 470 diff_link = link_to 'diff',
470 471 diff_journal_url(detail.journal_id, :detail_id => detail.id, :only_path => options[:only_path]),
471 472 :title => l(:label_view_diff)
472 473 s << " (#{ diff_link })"
473 474 end
474 475 s.html_safe
475 476 elsif detail.value.present?
476 477 case detail.property
477 478 when 'attr', 'cf'
478 479 if detail.old_value.present?
479 480 l(:text_journal_changed, :label => label, :old => old_value, :new => value).html_safe
480 481 elsif multiple
481 482 l(:text_journal_added, :label => label, :value => value).html_safe
482 483 else
483 484 l(:text_journal_set_to, :label => label, :value => value).html_safe
484 485 end
485 486 when 'attachment', 'relation'
486 487 l(:text_journal_added, :label => label, :value => value).html_safe
487 488 end
488 489 else
489 490 l(:text_journal_deleted, :label => label, :old => old_value).html_safe
490 491 end
491 492 end
492 493
493 494 # Find the name of an associated record stored in the field attribute
494 495 def find_name_by_reflection(field, id)
495 496 unless id.present?
496 497 return nil
497 498 end
498 499 @detail_value_name_by_reflection ||= Hash.new do |hash, key|
499 500 association = Issue.reflect_on_association(key.first.to_sym)
500 501 name = nil
501 502 if association
502 503 record = association.klass.find_by_id(key.last)
503 504 if record
504 505 name = record.name.force_encoding('UTF-8')
505 506 end
506 507 end
507 508 hash[key] = name
508 509 end
509 510 @detail_value_name_by_reflection[[field, id]]
510 511 end
511 512
512 513 # Renders issue children recursively
513 514 def render_api_issue_children(issue, api)
514 515 return if issue.leaf?
515 516 api.array :children do
516 517 issue.children.each do |child|
517 518 api.issue(:id => child.id) do
518 519 api.tracker(:id => child.tracker_id, :name => child.tracker.name) unless child.tracker.nil?
519 520 api.subject child.subject
520 521 render_api_issue_children(child, api)
521 522 end
522 523 end
523 524 end
524 525 end
525 526 end
General Comments 0
You need to be logged in to leave comments. Login now