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