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