@@ -1,375 +1,375 | |||||
1 | # encoding: utf-8 |
|
1 | # encoding: utf-8 | |
2 | # |
|
2 | # | |
3 | # Redmine - project management software |
|
3 | # Redmine - project management software | |
4 | # Copyright (C) 2006-2013 Jean-Philippe Lang |
|
4 | # Copyright (C) 2006-2013 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 |
|
22 | |||
23 | def issue_list(issues, &block) |
|
23 | def issue_list(issues, &block) | |
24 | ancestors = [] |
|
24 | ancestors = [] | |
25 | issues.each do |issue| |
|
25 | issues.each do |issue| | |
26 | while (ancestors.any? && !issue.is_descendant_of?(ancestors.last)) |
|
26 | while (ancestors.any? && !issue.is_descendant_of?(ancestors.last)) | |
27 | ancestors.pop |
|
27 | ancestors.pop | |
28 | end |
|
28 | end | |
29 | yield issue, ancestors.size |
|
29 | yield issue, ancestors.size | |
30 | ancestors << issue unless issue.leaf? |
|
30 | ancestors << issue unless issue.leaf? | |
31 | end |
|
31 | end | |
32 | end |
|
32 | end | |
33 |
|
33 | |||
34 | # Renders a HTML/CSS tooltip |
|
34 | # Renders a HTML/CSS tooltip | |
35 | # |
|
35 | # | |
36 | # To use, a trigger div is needed. This is a div with the class of "tooltip" |
|
36 | # To use, a trigger div is needed. This is a div with the class of "tooltip" | |
37 | # that contains this method wrapped in a span with the class of "tip" |
|
37 | # that contains this method wrapped in a span with the class of "tip" | |
38 | # |
|
38 | # | |
39 | # <div class="tooltip"><%= link_to_issue(issue) %> |
|
39 | # <div class="tooltip"><%= link_to_issue(issue) %> | |
40 | # <span class="tip"><%= render_issue_tooltip(issue) %></span> |
|
40 | # <span class="tip"><%= render_issue_tooltip(issue) %></span> | |
41 | # </div> |
|
41 | # </div> | |
42 | # |
|
42 | # | |
43 | def render_issue_tooltip(issue) |
|
43 | def render_issue_tooltip(issue) | |
44 | @cached_label_status ||= l(:field_status) |
|
44 | @cached_label_status ||= l(:field_status) | |
45 | @cached_label_start_date ||= l(:field_start_date) |
|
45 | @cached_label_start_date ||= l(:field_start_date) | |
46 | @cached_label_due_date ||= l(:field_due_date) |
|
46 | @cached_label_due_date ||= l(:field_due_date) | |
47 | @cached_label_assigned_to ||= l(:field_assigned_to) |
|
47 | @cached_label_assigned_to ||= l(:field_assigned_to) | |
48 | @cached_label_priority ||= l(:field_priority) |
|
48 | @cached_label_priority ||= l(:field_priority) | |
49 | @cached_label_project ||= l(:field_project) |
|
49 | @cached_label_project ||= l(:field_project) | |
50 |
|
50 | |||
51 | link_to_issue(issue) + "<br /><br />".html_safe + |
|
51 | link_to_issue(issue) + "<br /><br />".html_safe + | |
52 | "<strong>#{@cached_label_project}</strong>: #{link_to_project(issue.project)}<br />".html_safe + |
|
52 | "<strong>#{@cached_label_project}</strong>: #{link_to_project(issue.project)}<br />".html_safe + | |
53 | "<strong>#{@cached_label_status}</strong>: #{h(issue.status.name)}<br />".html_safe + |
|
53 | "<strong>#{@cached_label_status}</strong>: #{h(issue.status.name)}<br />".html_safe + | |
54 | "<strong>#{@cached_label_start_date}</strong>: #{format_date(issue.start_date)}<br />".html_safe + |
|
54 | "<strong>#{@cached_label_start_date}</strong>: #{format_date(issue.start_date)}<br />".html_safe + | |
55 | "<strong>#{@cached_label_due_date}</strong>: #{format_date(issue.due_date)}<br />".html_safe + |
|
55 | "<strong>#{@cached_label_due_date}</strong>: #{format_date(issue.due_date)}<br />".html_safe + | |
56 | "<strong>#{@cached_label_assigned_to}</strong>: #{h(issue.assigned_to)}<br />".html_safe + |
|
56 | "<strong>#{@cached_label_assigned_to}</strong>: #{h(issue.assigned_to)}<br />".html_safe + | |
57 | "<strong>#{@cached_label_priority}</strong>: #{h(issue.priority.name)}".html_safe |
|
57 | "<strong>#{@cached_label_priority}</strong>: #{h(issue.priority.name)}".html_safe | |
58 | end |
|
58 | end | |
59 |
|
59 | |||
60 | def issue_heading(issue) |
|
60 | def issue_heading(issue) | |
61 | h("#{issue.tracker} ##{issue.id}") |
|
61 | h("#{issue.tracker} ##{issue.id}") | |
62 | end |
|
62 | end | |
63 |
|
63 | |||
64 | def render_issue_subject_with_tree(issue) |
|
64 | def render_issue_subject_with_tree(issue) | |
65 | s = '' |
|
65 | s = '' | |
66 | ancestors = issue.root? ? [] : issue.ancestors.visible.all |
|
66 | ancestors = issue.root? ? [] : issue.ancestors.visible.all | |
67 | ancestors.each do |ancestor| |
|
67 | ancestors.each do |ancestor| | |
68 | s << '<div>' + content_tag('p', link_to_issue(ancestor, :project => (issue.project_id != ancestor.project_id))) |
|
68 | s << '<div>' + content_tag('p', link_to_issue(ancestor, :project => (issue.project_id != ancestor.project_id))) | |
69 | end |
|
69 | end | |
70 | s << '<div>' |
|
70 | s << '<div>' | |
71 | subject = h(issue.subject) |
|
71 | subject = h(issue.subject) | |
72 | if issue.is_private? |
|
72 | if issue.is_private? | |
73 | subject = content_tag('span', l(:field_is_private), :class => 'private') + ' ' + subject |
|
73 | subject = content_tag('span', l(:field_is_private), :class => 'private') + ' ' + subject | |
74 | end |
|
74 | end | |
75 | s << content_tag('h3', subject) |
|
75 | s << content_tag('h3', subject) | |
76 | s << '</div>' * (ancestors.size + 1) |
|
76 | s << '</div>' * (ancestors.size + 1) | |
77 | s.html_safe |
|
77 | s.html_safe | |
78 | end |
|
78 | end | |
79 |
|
79 | |||
80 | def render_descendants_tree(issue) |
|
80 | def render_descendants_tree(issue) | |
81 | s = '<form><table class="list issues">' |
|
81 | s = '<form><table class="list issues">' | |
82 | issue_list(issue.descendants.visible.sort_by(&:lft)) do |child, level| |
|
82 | issue_list(issue.descendants.visible.sort_by(&:lft)) do |child, level| | |
83 | css = "issue issue-#{child.id} hascontextmenu" |
|
83 | css = "issue issue-#{child.id} hascontextmenu" | |
84 | css << " idnt idnt-#{level}" if level > 0 |
|
84 | css << " idnt idnt-#{level}" if level > 0 | |
85 | s << content_tag('tr', |
|
85 | s << content_tag('tr', | |
86 | content_tag('td', check_box_tag("ids[]", child.id, false, :id => nil), :class => 'checkbox') + |
|
86 | content_tag('td', check_box_tag("ids[]", child.id, false, :id => nil), :class => 'checkbox') + | |
87 | content_tag('td', link_to_issue(child, :truncate => 60, :project => (issue.project_id != child.project_id)), :class => 'subject') + |
|
87 | content_tag('td', link_to_issue(child, :truncate => 60, :project => (issue.project_id != child.project_id)), :class => 'subject') + | |
88 | content_tag('td', h(child.status)) + |
|
88 | content_tag('td', h(child.status)) + | |
89 | content_tag('td', link_to_user(child.assigned_to)) + |
|
89 | content_tag('td', link_to_user(child.assigned_to)) + | |
90 | content_tag('td', progress_bar(child.done_ratio, :width => '80px')), |
|
90 | content_tag('td', progress_bar(child.done_ratio, :width => '80px')), | |
91 | :class => css) |
|
91 | :class => css) | |
92 | end |
|
92 | end | |
93 | s << '</table></form>' |
|
93 | s << '</table></form>' | |
94 | s.html_safe |
|
94 | s.html_safe | |
95 | end |
|
95 | end | |
96 |
|
96 | |||
97 | # Returns a link for adding a new subtask to the given issue |
|
97 | # Returns a link for adding a new subtask to the given issue | |
98 | def link_to_new_subtask(issue) |
|
98 | def link_to_new_subtask(issue) | |
99 | attrs = { |
|
99 | attrs = { | |
100 | :tracker_id => issue.tracker, |
|
100 | :tracker_id => issue.tracker, | |
101 | :parent_issue_id => issue |
|
101 | :parent_issue_id => issue | |
102 | } |
|
102 | } | |
103 | link_to(l(:button_add), new_project_issue_path(issue.project, :issue => attrs)) |
|
103 | link_to(l(:button_add), new_project_issue_path(issue.project, :issue => attrs)) | |
104 | end |
|
104 | end | |
105 |
|
105 | |||
106 | class IssueFieldsRows |
|
106 | class IssueFieldsRows | |
107 | include ActionView::Helpers::TagHelper |
|
107 | include ActionView::Helpers::TagHelper | |
108 |
|
108 | |||
109 | def initialize |
|
109 | def initialize | |
110 | @left = [] |
|
110 | @left = [] | |
111 | @right = [] |
|
111 | @right = [] | |
112 | end |
|
112 | end | |
113 |
|
113 | |||
114 | def left(*args) |
|
114 | def left(*args) | |
115 | args.any? ? @left << cells(*args) : @left |
|
115 | args.any? ? @left << cells(*args) : @left | |
116 | end |
|
116 | end | |
117 |
|
117 | |||
118 | def right(*args) |
|
118 | def right(*args) | |
119 | args.any? ? @right << cells(*args) : @right |
|
119 | args.any? ? @right << cells(*args) : @right | |
120 | end |
|
120 | end | |
121 |
|
121 | |||
122 | def size |
|
122 | def size | |
123 | @left.size > @right.size ? @left.size : @right.size |
|
123 | @left.size > @right.size ? @left.size : @right.size | |
124 | end |
|
124 | end | |
125 |
|
125 | |||
126 | def to_html |
|
126 | def to_html | |
127 | html = ''.html_safe |
|
127 | html = ''.html_safe | |
128 | blank = content_tag('th', '') + content_tag('td', '') |
|
128 | blank = content_tag('th', '') + content_tag('td', '') | |
129 | size.times do |i| |
|
129 | size.times do |i| | |
130 | left = @left[i] || blank |
|
130 | left = @left[i] || blank | |
131 | right = @right[i] || blank |
|
131 | right = @right[i] || blank | |
132 | html << content_tag('tr', left + right) |
|
132 | html << content_tag('tr', left + right) | |
133 | end |
|
133 | end | |
134 | html |
|
134 | html | |
135 | end |
|
135 | end | |
136 |
|
136 | |||
137 | def cells(label, text, options={}) |
|
137 | def cells(label, text, options={}) | |
138 | content_tag('th', "#{label}:", options) + content_tag('td', text, options) |
|
138 | content_tag('th', "#{label}:", options) + content_tag('td', text, options) | |
139 | end |
|
139 | end | |
140 | end |
|
140 | end | |
141 |
|
141 | |||
142 | def issue_fields_rows |
|
142 | def issue_fields_rows | |
143 | r = IssueFieldsRows.new |
|
143 | r = IssueFieldsRows.new | |
144 | yield r |
|
144 | yield r | |
145 | r.to_html |
|
145 | r.to_html | |
146 | end |
|
146 | end | |
147 |
|
147 | |||
148 | def render_custom_fields_rows(issue) |
|
148 | def render_custom_fields_rows(issue) | |
149 | return if issue.custom_field_values.empty? |
|
149 | return if issue.custom_field_values.empty? | |
150 | ordered_values = [] |
|
150 | ordered_values = [] | |
151 | half = (issue.custom_field_values.size / 2.0).ceil |
|
151 | half = (issue.custom_field_values.size / 2.0).ceil | |
152 | half.times do |i| |
|
152 | half.times do |i| | |
153 | ordered_values << issue.custom_field_values[i] |
|
153 | ordered_values << issue.custom_field_values[i] | |
154 | ordered_values << issue.custom_field_values[i + half] |
|
154 | ordered_values << issue.custom_field_values[i + half] | |
155 | end |
|
155 | end | |
156 | s = "<tr>\n" |
|
156 | s = "<tr>\n" | |
157 | n = 0 |
|
157 | n = 0 | |
158 | ordered_values.compact.each do |value| |
|
158 | ordered_values.compact.each do |value| | |
159 | s << "</tr>\n<tr>\n" if n > 0 && (n % 2) == 0 |
|
159 | s << "</tr>\n<tr>\n" if n > 0 && (n % 2) == 0 | |
160 | s << "\t<th>#{ h(value.custom_field.name) }:</th><td>#{ simple_format_without_paragraph(h(show_value(value))) }</td>\n" |
|
160 | s << "\t<th>#{ h(value.custom_field.name) }:</th><td>#{ simple_format_without_paragraph(h(show_value(value))) }</td>\n" | |
161 | n += 1 |
|
161 | n += 1 | |
162 | end |
|
162 | end | |
163 | s << "</tr>\n" |
|
163 | s << "</tr>\n" | |
164 | s.html_safe |
|
164 | s.html_safe | |
165 | end |
|
165 | end | |
166 |
|
166 | |||
167 | def issues_destroy_confirmation_message(issues) |
|
167 | def issues_destroy_confirmation_message(issues) | |
168 | issues = [issues] unless issues.is_a?(Array) |
|
168 | issues = [issues] unless issues.is_a?(Array) | |
169 | message = l(:text_issues_destroy_confirmation) |
|
169 | message = l(:text_issues_destroy_confirmation) | |
170 | descendant_count = issues.inject(0) {|memo, i| memo += (i.right - i.left - 1)/2} |
|
170 | descendant_count = issues.inject(0) {|memo, i| memo += (i.right - i.left - 1)/2} | |
171 | if descendant_count > 0 |
|
171 | if descendant_count > 0 | |
172 | issues.each do |issue| |
|
172 | issues.each do |issue| | |
173 | next if issue.root? |
|
173 | next if issue.root? | |
174 | issues.each do |other_issue| |
|
174 | issues.each do |other_issue| | |
175 | descendant_count -= 1 if issue.is_descendant_of?(other_issue) |
|
175 | descendant_count -= 1 if issue.is_descendant_of?(other_issue) | |
176 | end |
|
176 | end | |
177 | end |
|
177 | end | |
178 | if descendant_count > 0 |
|
178 | if descendant_count > 0 | |
179 | message << "\n" + l(:text_issues_destroy_descendants_confirmation, :count => descendant_count) |
|
179 | message << "\n" + l(:text_issues_destroy_descendants_confirmation, :count => descendant_count) | |
180 | end |
|
180 | end | |
181 | end |
|
181 | end | |
182 | message |
|
182 | message | |
183 | end |
|
183 | end | |
184 |
|
184 | |||
185 | def sidebar_queries |
|
185 | def sidebar_queries | |
186 | unless @sidebar_queries |
|
186 | unless @sidebar_queries | |
187 |
@sidebar_queries = IssueQuery.visible. |
|
187 | @sidebar_queries = IssueQuery.visible. | |
188 |
|
|
188 | order("#{Query.table_name}.name ASC"). | |
189 | # Project specific queries and global queries |
|
189 | # Project specific queries and global queries | |
190 |
|
|
190 | where(@project.nil? ? ["project_id IS NULL"] : ["project_id IS NULL OR project_id = ?", @project.id]). | |
191 |
|
|
191 | all | |
192 | end |
|
192 | end | |
193 | @sidebar_queries |
|
193 | @sidebar_queries | |
194 | end |
|
194 | end | |
195 |
|
195 | |||
196 | def query_links(title, queries) |
|
196 | def query_links(title, queries) | |
197 | return '' if queries.empty? |
|
197 | return '' if queries.empty? | |
198 | # links to #index on issues/show |
|
198 | # links to #index on issues/show | |
199 | url_params = controller_name == 'issues' ? {:controller => 'issues', :action => 'index', :project_id => @project} : params |
|
199 | url_params = controller_name == 'issues' ? {:controller => 'issues', :action => 'index', :project_id => @project} : params | |
200 |
|
200 | |||
201 | content_tag('h3', h(title)) + "\n" + |
|
201 | content_tag('h3', h(title)) + "\n" + | |
202 | content_tag('ul', |
|
202 | content_tag('ul', | |
203 | queries.collect {|query| |
|
203 | queries.collect {|query| | |
204 | css = 'query' |
|
204 | css = 'query' | |
205 | css << ' selected' if query == @query |
|
205 | css << ' selected' if query == @query | |
206 | content_tag('li', link_to(h(query.name), url_params.merge(:query_id => query), :class => css)) |
|
206 | content_tag('li', link_to(h(query.name), url_params.merge(:query_id => query), :class => css)) | |
207 | }.join("\n").html_safe, |
|
207 | }.join("\n").html_safe, | |
208 | :class => 'queries' |
|
208 | :class => 'queries' | |
209 | ) + "\n" |
|
209 | ) + "\n" | |
210 | end |
|
210 | end | |
211 |
|
211 | |||
212 | def render_sidebar_queries |
|
212 | def render_sidebar_queries | |
213 | out = ''.html_safe |
|
213 | out = ''.html_safe | |
214 | out << query_links(l(:label_my_queries), sidebar_queries.reject(&:is_public?)) |
|
214 | out << query_links(l(:label_my_queries), sidebar_queries.reject(&:is_public?)) | |
215 | out << query_links(l(:label_query_plural), sidebar_queries.select(&:is_public?)) |
|
215 | out << query_links(l(:label_query_plural), sidebar_queries.select(&:is_public?)) | |
216 | out |
|
216 | out | |
217 | end |
|
217 | end | |
218 |
|
218 | |||
219 | # Returns the textual representation of a journal details |
|
219 | # Returns the textual representation of a journal details | |
220 | # as an array of strings |
|
220 | # as an array of strings | |
221 | def details_to_strings(details, no_html=false, options={}) |
|
221 | def details_to_strings(details, no_html=false, options={}) | |
222 | options[:only_path] = (options[:only_path] == false ? false : true) |
|
222 | options[:only_path] = (options[:only_path] == false ? false : true) | |
223 | strings = [] |
|
223 | strings = [] | |
224 | values_by_field = {} |
|
224 | values_by_field = {} | |
225 | details.each do |detail| |
|
225 | details.each do |detail| | |
226 | if detail.property == 'cf' |
|
226 | if detail.property == 'cf' | |
227 | field_id = detail.prop_key |
|
227 | field_id = detail.prop_key | |
228 | field = CustomField.find_by_id(field_id) |
|
228 | field = CustomField.find_by_id(field_id) | |
229 | if field && field.multiple? |
|
229 | if field && field.multiple? | |
230 | values_by_field[field_id] ||= {:added => [], :deleted => []} |
|
230 | values_by_field[field_id] ||= {:added => [], :deleted => []} | |
231 | if detail.old_value |
|
231 | if detail.old_value | |
232 | values_by_field[field_id][:deleted] << detail.old_value |
|
232 | values_by_field[field_id][:deleted] << detail.old_value | |
233 | end |
|
233 | end | |
234 | if detail.value |
|
234 | if detail.value | |
235 | values_by_field[field_id][:added] << detail.value |
|
235 | values_by_field[field_id][:added] << detail.value | |
236 | end |
|
236 | end | |
237 | next |
|
237 | next | |
238 | end |
|
238 | end | |
239 | end |
|
239 | end | |
240 | strings << show_detail(detail, no_html, options) |
|
240 | strings << show_detail(detail, no_html, options) | |
241 | end |
|
241 | end | |
242 | values_by_field.each do |field_id, changes| |
|
242 | values_by_field.each do |field_id, changes| | |
243 | detail = JournalDetail.new(:property => 'cf', :prop_key => field_id) |
|
243 | detail = JournalDetail.new(:property => 'cf', :prop_key => field_id) | |
244 | if changes[:added].any? |
|
244 | if changes[:added].any? | |
245 | detail.value = changes[:added] |
|
245 | detail.value = changes[:added] | |
246 | strings << show_detail(detail, no_html, options) |
|
246 | strings << show_detail(detail, no_html, options) | |
247 | elsif changes[:deleted].any? |
|
247 | elsif changes[:deleted].any? | |
248 | detail.old_value = changes[:deleted] |
|
248 | detail.old_value = changes[:deleted] | |
249 | strings << show_detail(detail, no_html, options) |
|
249 | strings << show_detail(detail, no_html, options) | |
250 | end |
|
250 | end | |
251 | end |
|
251 | end | |
252 | strings |
|
252 | strings | |
253 | end |
|
253 | end | |
254 |
|
254 | |||
255 | # Returns the textual representation of a single journal detail |
|
255 | # Returns the textual representation of a single journal detail | |
256 | def show_detail(detail, no_html=false, options={}) |
|
256 | def show_detail(detail, no_html=false, options={}) | |
257 | multiple = false |
|
257 | multiple = false | |
258 | case detail.property |
|
258 | case detail.property | |
259 | when 'attr' |
|
259 | when 'attr' | |
260 | field = detail.prop_key.to_s.gsub(/\_id$/, "") |
|
260 | field = detail.prop_key.to_s.gsub(/\_id$/, "") | |
261 | label = l(("field_" + field).to_sym) |
|
261 | label = l(("field_" + field).to_sym) | |
262 | case detail.prop_key |
|
262 | case detail.prop_key | |
263 | when 'due_date', 'start_date' |
|
263 | when 'due_date', 'start_date' | |
264 | value = format_date(detail.value.to_date) if detail.value |
|
264 | value = format_date(detail.value.to_date) if detail.value | |
265 | old_value = format_date(detail.old_value.to_date) if detail.old_value |
|
265 | old_value = format_date(detail.old_value.to_date) if detail.old_value | |
266 |
|
266 | |||
267 | when 'project_id', 'status_id', 'tracker_id', 'assigned_to_id', |
|
267 | when 'project_id', 'status_id', 'tracker_id', 'assigned_to_id', | |
268 | 'priority_id', 'category_id', 'fixed_version_id' |
|
268 | 'priority_id', 'category_id', 'fixed_version_id' | |
269 | value = find_name_by_reflection(field, detail.value) |
|
269 | value = find_name_by_reflection(field, detail.value) | |
270 | old_value = find_name_by_reflection(field, detail.old_value) |
|
270 | old_value = find_name_by_reflection(field, detail.old_value) | |
271 |
|
271 | |||
272 | when 'estimated_hours' |
|
272 | when 'estimated_hours' | |
273 | value = "%0.02f" % detail.value.to_f unless detail.value.blank? |
|
273 | value = "%0.02f" % detail.value.to_f unless detail.value.blank? | |
274 | old_value = "%0.02f" % detail.old_value.to_f unless detail.old_value.blank? |
|
274 | old_value = "%0.02f" % detail.old_value.to_f unless detail.old_value.blank? | |
275 |
|
275 | |||
276 | when 'parent_id' |
|
276 | when 'parent_id' | |
277 | label = l(:field_parent_issue) |
|
277 | label = l(:field_parent_issue) | |
278 | value = "##{detail.value}" unless detail.value.blank? |
|
278 | value = "##{detail.value}" unless detail.value.blank? | |
279 | old_value = "##{detail.old_value}" unless detail.old_value.blank? |
|
279 | old_value = "##{detail.old_value}" unless detail.old_value.blank? | |
280 |
|
280 | |||
281 | when 'is_private' |
|
281 | when 'is_private' | |
282 | value = l(detail.value == "0" ? :general_text_No : :general_text_Yes) unless detail.value.blank? |
|
282 | value = l(detail.value == "0" ? :general_text_No : :general_text_Yes) unless detail.value.blank? | |
283 | old_value = l(detail.old_value == "0" ? :general_text_No : :general_text_Yes) unless detail.old_value.blank? |
|
283 | old_value = l(detail.old_value == "0" ? :general_text_No : :general_text_Yes) unless detail.old_value.blank? | |
284 | end |
|
284 | end | |
285 | when 'cf' |
|
285 | when 'cf' | |
286 | custom_field = CustomField.find_by_id(detail.prop_key) |
|
286 | custom_field = CustomField.find_by_id(detail.prop_key) | |
287 | if custom_field |
|
287 | if custom_field | |
288 | multiple = custom_field.multiple? |
|
288 | multiple = custom_field.multiple? | |
289 | label = custom_field.name |
|
289 | label = custom_field.name | |
290 | value = format_value(detail.value, custom_field.field_format) if detail.value |
|
290 | value = format_value(detail.value, custom_field.field_format) if detail.value | |
291 | old_value = format_value(detail.old_value, custom_field.field_format) if detail.old_value |
|
291 | old_value = format_value(detail.old_value, custom_field.field_format) if detail.old_value | |
292 | end |
|
292 | end | |
293 | when 'attachment' |
|
293 | when 'attachment' | |
294 | label = l(:label_attachment) |
|
294 | label = l(:label_attachment) | |
295 | end |
|
295 | end | |
296 | call_hook(:helper_issues_show_detail_after_setting, |
|
296 | call_hook(:helper_issues_show_detail_after_setting, | |
297 | {:detail => detail, :label => label, :value => value, :old_value => old_value }) |
|
297 | {:detail => detail, :label => label, :value => value, :old_value => old_value }) | |
298 |
|
298 | |||
299 | label ||= detail.prop_key |
|
299 | label ||= detail.prop_key | |
300 | value ||= detail.value |
|
300 | value ||= detail.value | |
301 | old_value ||= detail.old_value |
|
301 | old_value ||= detail.old_value | |
302 |
|
302 | |||
303 | unless no_html |
|
303 | unless no_html | |
304 | label = content_tag('strong', label) |
|
304 | label = content_tag('strong', label) | |
305 | old_value = content_tag("i", h(old_value)) if detail.old_value |
|
305 | old_value = content_tag("i", h(old_value)) if detail.old_value | |
306 | old_value = content_tag("del", old_value) if detail.old_value and detail.value.blank? |
|
306 | old_value = content_tag("del", old_value) if detail.old_value and detail.value.blank? | |
307 | if detail.property == 'attachment' && !value.blank? && atta = Attachment.find_by_id(detail.prop_key) |
|
307 | if detail.property == 'attachment' && !value.blank? && atta = Attachment.find_by_id(detail.prop_key) | |
308 | # Link to the attachment if it has not been removed |
|
308 | # Link to the attachment if it has not been removed | |
309 | value = link_to_attachment(atta, :download => true, :only_path => options[:only_path]) |
|
309 | value = link_to_attachment(atta, :download => true, :only_path => options[:only_path]) | |
310 | if options[:only_path] != false && atta.is_text? |
|
310 | if options[:only_path] != false && atta.is_text? | |
311 | value += link_to( |
|
311 | value += link_to( | |
312 | image_tag('magnifier.png'), |
|
312 | image_tag('magnifier.png'), | |
313 | :controller => 'attachments', :action => 'show', |
|
313 | :controller => 'attachments', :action => 'show', | |
314 | :id => atta, :filename => atta.filename |
|
314 | :id => atta, :filename => atta.filename | |
315 | ) |
|
315 | ) | |
316 | end |
|
316 | end | |
317 | else |
|
317 | else | |
318 | value = content_tag("i", h(value)) if value |
|
318 | value = content_tag("i", h(value)) if value | |
319 | end |
|
319 | end | |
320 | end |
|
320 | end | |
321 |
|
321 | |||
322 | if detail.property == 'attr' && detail.prop_key == 'description' |
|
322 | if detail.property == 'attr' && detail.prop_key == 'description' | |
323 | s = l(:text_journal_changed_no_detail, :label => label) |
|
323 | s = l(:text_journal_changed_no_detail, :label => label) | |
324 | unless no_html |
|
324 | unless no_html | |
325 | diff_link = link_to 'diff', |
|
325 | diff_link = link_to 'diff', | |
326 | {:controller => 'journals', :action => 'diff', :id => detail.journal_id, |
|
326 | {:controller => 'journals', :action => 'diff', :id => detail.journal_id, | |
327 | :detail_id => detail.id, :only_path => options[:only_path]}, |
|
327 | :detail_id => detail.id, :only_path => options[:only_path]}, | |
328 | :title => l(:label_view_diff) |
|
328 | :title => l(:label_view_diff) | |
329 | s << " (#{ diff_link })" |
|
329 | s << " (#{ diff_link })" | |
330 | end |
|
330 | end | |
331 | s.html_safe |
|
331 | s.html_safe | |
332 | elsif detail.value.present? |
|
332 | elsif detail.value.present? | |
333 | case detail.property |
|
333 | case detail.property | |
334 | when 'attr', 'cf' |
|
334 | when 'attr', 'cf' | |
335 | if detail.old_value.present? |
|
335 | if detail.old_value.present? | |
336 | l(:text_journal_changed, :label => label, :old => old_value, :new => value).html_safe |
|
336 | l(:text_journal_changed, :label => label, :old => old_value, :new => value).html_safe | |
337 | elsif multiple |
|
337 | elsif multiple | |
338 | l(:text_journal_added, :label => label, :value => value).html_safe |
|
338 | l(:text_journal_added, :label => label, :value => value).html_safe | |
339 | else |
|
339 | else | |
340 | l(:text_journal_set_to, :label => label, :value => value).html_safe |
|
340 | l(:text_journal_set_to, :label => label, :value => value).html_safe | |
341 | end |
|
341 | end | |
342 | when 'attachment' |
|
342 | when 'attachment' | |
343 | l(:text_journal_added, :label => label, :value => value).html_safe |
|
343 | l(:text_journal_added, :label => label, :value => value).html_safe | |
344 | end |
|
344 | end | |
345 | else |
|
345 | else | |
346 | l(:text_journal_deleted, :label => label, :old => old_value).html_safe |
|
346 | l(:text_journal_deleted, :label => label, :old => old_value).html_safe | |
347 | end |
|
347 | end | |
348 | end |
|
348 | end | |
349 |
|
349 | |||
350 | # Find the name of an associated record stored in the field attribute |
|
350 | # Find the name of an associated record stored in the field attribute | |
351 | def find_name_by_reflection(field, id) |
|
351 | def find_name_by_reflection(field, id) | |
352 | unless id.present? |
|
352 | unless id.present? | |
353 | return nil |
|
353 | return nil | |
354 | end |
|
354 | end | |
355 | association = Issue.reflect_on_association(field.to_sym) |
|
355 | association = Issue.reflect_on_association(field.to_sym) | |
356 | if association |
|
356 | if association | |
357 | record = association.class_name.constantize.find_by_id(id) |
|
357 | record = association.class_name.constantize.find_by_id(id) | |
358 | return record.name if record |
|
358 | return record.name if record | |
359 | end |
|
359 | end | |
360 | end |
|
360 | end | |
361 |
|
361 | |||
362 | # Renders issue children recursively |
|
362 | # Renders issue children recursively | |
363 | def render_api_issue_children(issue, api) |
|
363 | def render_api_issue_children(issue, api) | |
364 | return if issue.leaf? |
|
364 | return if issue.leaf? | |
365 | api.array :children do |
|
365 | api.array :children do | |
366 | issue.children.each do |child| |
|
366 | issue.children.each do |child| | |
367 | api.issue(:id => child.id) do |
|
367 | api.issue(:id => child.id) do | |
368 | api.tracker(:id => child.tracker_id, :name => child.tracker.name) unless child.tracker.nil? |
|
368 | api.tracker(:id => child.tracker_id, :name => child.tracker.name) unless child.tracker.nil? | |
369 | api.subject child.subject |
|
369 | api.subject child.subject | |
370 | render_api_issue_children(child, api) |
|
370 | render_api_issue_children(child, api) | |
371 | end |
|
371 | end | |
372 | end |
|
372 | end | |
373 | end |
|
373 | end | |
374 | end |
|
374 | end | |
375 | end |
|
375 | end |
General Comments 0
You need to be logged in to leave comments.
Login now