@@ -1,392 +1,403 | |||||
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 an array of error messages for bulk edited issues |
|
97 | # Returns an array of error messages for bulk edited issues | |
98 | def bulk_edit_error_messages(issues) |
|
98 | def bulk_edit_error_messages(issues) | |
99 | messages = {} |
|
99 | messages = {} | |
100 | issues.each do |issue| |
|
100 | issues.each do |issue| | |
101 | issue.errors.full_messages.each do |message| |
|
101 | issue.errors.full_messages.each do |message| | |
102 | messages[message] ||= [] |
|
102 | messages[message] ||= [] | |
103 | messages[message] << issue |
|
103 | messages[message] << issue | |
104 | end |
|
104 | end | |
105 | end |
|
105 | end | |
106 | messages.map { |message, issues| |
|
106 | messages.map { |message, issues| | |
107 | "#{message}: " + issues.map {|i| "##{i.id}"}.join(', ') |
|
107 | "#{message}: " + issues.map {|i| "##{i.id}"}.join(', ') | |
108 | } |
|
108 | } | |
109 | end |
|
109 | end | |
110 |
|
110 | |||
111 | # Returns a link for adding a new subtask to the given issue |
|
111 | # Returns a link for adding a new subtask to the given issue | |
112 | def link_to_new_subtask(issue) |
|
112 | def link_to_new_subtask(issue) | |
113 | attrs = { |
|
113 | attrs = { | |
114 | :tracker_id => issue.tracker, |
|
114 | :tracker_id => issue.tracker, | |
115 | :parent_issue_id => issue |
|
115 | :parent_issue_id => issue | |
116 | } |
|
116 | } | |
117 | link_to(l(:button_add), new_project_issue_path(issue.project, :issue => attrs)) |
|
117 | link_to(l(:button_add), new_project_issue_path(issue.project, :issue => attrs)) | |
118 | end |
|
118 | end | |
119 |
|
119 | |||
120 | class IssueFieldsRows |
|
120 | class IssueFieldsRows | |
121 | include ActionView::Helpers::TagHelper |
|
121 | include ActionView::Helpers::TagHelper | |
122 |
|
122 | |||
123 | def initialize |
|
123 | def initialize | |
124 | @left = [] |
|
124 | @left = [] | |
125 | @right = [] |
|
125 | @right = [] | |
126 | end |
|
126 | end | |
127 |
|
127 | |||
128 | def left(*args) |
|
128 | def left(*args) | |
129 | args.any? ? @left << cells(*args) : @left |
|
129 | args.any? ? @left << cells(*args) : @left | |
130 | end |
|
130 | end | |
131 |
|
131 | |||
132 | def right(*args) |
|
132 | def right(*args) | |
133 | args.any? ? @right << cells(*args) : @right |
|
133 | args.any? ? @right << cells(*args) : @right | |
134 | end |
|
134 | end | |
135 |
|
135 | |||
136 | def size |
|
136 | def size | |
137 | @left.size > @right.size ? @left.size : @right.size |
|
137 | @left.size > @right.size ? @left.size : @right.size | |
138 | end |
|
138 | end | |
139 |
|
139 | |||
140 | def to_html |
|
140 | def to_html | |
141 | html = ''.html_safe |
|
141 | html = ''.html_safe | |
142 | blank = content_tag('th', '') + content_tag('td', '') |
|
142 | blank = content_tag('th', '') + content_tag('td', '') | |
143 | size.times do |i| |
|
143 | size.times do |i| | |
144 | left = @left[i] || blank |
|
144 | left = @left[i] || blank | |
145 | right = @right[i] || blank |
|
145 | right = @right[i] || blank | |
146 | html << content_tag('tr', left + right) |
|
146 | html << content_tag('tr', left + right) | |
147 | end |
|
147 | end | |
148 | html |
|
148 | html | |
149 | end |
|
149 | end | |
150 |
|
150 | |||
151 | def cells(label, text, options={}) |
|
151 | def cells(label, text, options={}) | |
152 | content_tag('th', "#{label}:", options) + content_tag('td', text, options) |
|
152 | content_tag('th', "#{label}:", options) + content_tag('td', text, options) | |
153 | end |
|
153 | end | |
154 | end |
|
154 | end | |
155 |
|
155 | |||
156 | def issue_fields_rows |
|
156 | def issue_fields_rows | |
157 | r = IssueFieldsRows.new |
|
157 | r = IssueFieldsRows.new | |
158 | yield r |
|
158 | yield r | |
159 | r.to_html |
|
159 | r.to_html | |
160 | end |
|
160 | end | |
161 |
|
161 | |||
162 | def render_custom_fields_rows(issue) |
|
162 | def render_custom_fields_rows(issue) | |
163 | return if issue.custom_field_values.empty? |
|
163 | return if issue.custom_field_values.empty? | |
164 | ordered_values = [] |
|
164 | ordered_values = [] | |
165 | half = (issue.custom_field_values.size / 2.0).ceil |
|
165 | half = (issue.custom_field_values.size / 2.0).ceil | |
166 | half.times do |i| |
|
166 | half.times do |i| | |
167 | ordered_values << issue.custom_field_values[i] |
|
167 | ordered_values << issue.custom_field_values[i] | |
168 | ordered_values << issue.custom_field_values[i + half] |
|
168 | ordered_values << issue.custom_field_values[i + half] | |
169 | end |
|
169 | end | |
170 | s = "<tr>\n" |
|
170 | s = "<tr>\n" | |
171 | n = 0 |
|
171 | n = 0 | |
172 | ordered_values.compact.each do |value| |
|
172 | ordered_values.compact.each do |value| | |
173 | s << "</tr>\n<tr>\n" if n > 0 && (n % 2) == 0 |
|
173 | s << "</tr>\n<tr>\n" if n > 0 && (n % 2) == 0 | |
174 | s << "\t<th>#{ h(value.custom_field.name) }:</th><td>#{ simple_format_without_paragraph(h(show_value(value))) }</td>\n" |
|
174 | s << "\t<th>#{ h(value.custom_field.name) }:</th><td>#{ simple_format_without_paragraph(h(show_value(value))) }</td>\n" | |
175 | n += 1 |
|
175 | n += 1 | |
176 | end |
|
176 | end | |
177 | s << "</tr>\n" |
|
177 | s << "</tr>\n" | |
178 | s.html_safe |
|
178 | s.html_safe | |
179 | end |
|
179 | end | |
180 |
|
180 | |||
181 | def issues_destroy_confirmation_message(issues) |
|
181 | def issues_destroy_confirmation_message(issues) | |
182 | issues = [issues] unless issues.is_a?(Array) |
|
182 | issues = [issues] unless issues.is_a?(Array) | |
183 | message = l(:text_issues_destroy_confirmation) |
|
183 | message = l(:text_issues_destroy_confirmation) | |
184 | descendant_count = issues.inject(0) {|memo, i| memo += (i.right - i.left - 1)/2} |
|
184 | descendant_count = issues.inject(0) {|memo, i| memo += (i.right - i.left - 1)/2} | |
185 | if descendant_count > 0 |
|
185 | if descendant_count > 0 | |
186 | issues.each do |issue| |
|
186 | issues.each do |issue| | |
187 | next if issue.root? |
|
187 | next if issue.root? | |
188 | issues.each do |other_issue| |
|
188 | issues.each do |other_issue| | |
189 | descendant_count -= 1 if issue.is_descendant_of?(other_issue) |
|
189 | descendant_count -= 1 if issue.is_descendant_of?(other_issue) | |
190 | end |
|
190 | end | |
191 | end |
|
191 | end | |
192 | if descendant_count > 0 |
|
192 | if descendant_count > 0 | |
193 | message << "\n" + l(:text_issues_destroy_descendants_confirmation, :count => descendant_count) |
|
193 | message << "\n" + l(:text_issues_destroy_descendants_confirmation, :count => descendant_count) | |
194 | end |
|
194 | end | |
195 | end |
|
195 | end | |
196 | message |
|
196 | message | |
197 | end |
|
197 | end | |
198 |
|
198 | |||
199 | def sidebar_queries |
|
199 | def sidebar_queries | |
200 | unless @sidebar_queries |
|
200 | unless @sidebar_queries | |
201 | @sidebar_queries = IssueQuery.visible. |
|
201 | @sidebar_queries = IssueQuery.visible. | |
202 | order("#{Query.table_name}.name ASC"). |
|
202 | order("#{Query.table_name}.name ASC"). | |
203 | # Project specific queries and global queries |
|
203 | # Project specific queries and global queries | |
204 | where(@project.nil? ? ["project_id IS NULL"] : ["project_id IS NULL OR project_id = ?", @project.id]). |
|
204 | where(@project.nil? ? ["project_id IS NULL"] : ["project_id IS NULL OR project_id = ?", @project.id]). | |
205 | all |
|
205 | all | |
206 | end |
|
206 | end | |
207 | @sidebar_queries |
|
207 | @sidebar_queries | |
208 | end |
|
208 | end | |
209 |
|
209 | |||
210 | def query_links(title, queries) |
|
210 | def query_links(title, queries) | |
211 | return '' if queries.empty? |
|
211 | return '' if queries.empty? | |
212 | # links to #index on issues/show |
|
212 | # links to #index on issues/show | |
213 | url_params = controller_name == 'issues' ? {:controller => 'issues', :action => 'index', :project_id => @project} : params |
|
213 | url_params = controller_name == 'issues' ? {:controller => 'issues', :action => 'index', :project_id => @project} : params | |
214 |
|
214 | |||
215 | content_tag('h3', title) + "\n" + |
|
215 | content_tag('h3', title) + "\n" + | |
216 | content_tag('ul', |
|
216 | content_tag('ul', | |
217 | queries.collect {|query| |
|
217 | queries.collect {|query| | |
218 | css = 'query' |
|
218 | css = 'query' | |
219 | css << ' selected' if query == @query |
|
219 | css << ' selected' if query == @query | |
220 | content_tag('li', link_to(query.name, url_params.merge(:query_id => query), :class => css)) |
|
220 | content_tag('li', link_to(query.name, url_params.merge(:query_id => query), :class => css)) | |
221 | }.join("\n").html_safe, |
|
221 | }.join("\n").html_safe, | |
222 | :class => 'queries' |
|
222 | :class => 'queries' | |
223 | ) + "\n" |
|
223 | ) + "\n" | |
224 | end |
|
224 | end | |
225 |
|
225 | |||
226 | def render_sidebar_queries |
|
226 | def render_sidebar_queries | |
227 | out = ''.html_safe |
|
227 | out = ''.html_safe | |
228 | out << query_links(l(:label_my_queries), sidebar_queries.reject(&:is_public?)) |
|
228 | out << query_links(l(:label_my_queries), sidebar_queries.reject(&:is_public?)) | |
229 | out << query_links(l(:label_query_plural), sidebar_queries.select(&:is_public?)) |
|
229 | out << query_links(l(:label_query_plural), sidebar_queries.select(&:is_public?)) | |
230 | out |
|
230 | out | |
231 | end |
|
231 | end | |
232 |
|
232 | |||
233 | # Returns the textual representation of a journal details |
|
233 | # Returns the textual representation of a journal details | |
234 | # as an array of strings |
|
234 | # as an array of strings | |
235 | def details_to_strings(details, no_html=false, options={}) |
|
235 | def details_to_strings(details, no_html=false, options={}) | |
236 | options[:only_path] = (options[:only_path] == false ? false : true) |
|
236 | options[:only_path] = (options[:only_path] == false ? false : true) | |
237 | strings = [] |
|
237 | strings = [] | |
238 | values_by_field = {} |
|
238 | values_by_field = {} | |
239 | details.each do |detail| |
|
239 | details.each do |detail| | |
240 | if detail.property == 'cf' |
|
240 | if detail.property == 'cf' | |
241 | field_id = detail.prop_key |
|
241 | field_id = detail.prop_key | |
242 | field = CustomField.find_by_id(field_id) |
|
242 | field = CustomField.find_by_id(field_id) | |
243 | if field && field.multiple? |
|
243 | if field && field.multiple? | |
244 | values_by_field[field_id] ||= {:added => [], :deleted => []} |
|
244 | values_by_field[field_id] ||= {:added => [], :deleted => []} | |
245 | if detail.old_value |
|
245 | if detail.old_value | |
246 | values_by_field[field_id][:deleted] << detail.old_value |
|
246 | values_by_field[field_id][:deleted] << detail.old_value | |
247 | end |
|
247 | end | |
248 | if detail.value |
|
248 | if detail.value | |
249 | values_by_field[field_id][:added] << detail.value |
|
249 | values_by_field[field_id][:added] << detail.value | |
250 | end |
|
250 | end | |
251 | next |
|
251 | next | |
252 | end |
|
252 | end | |
253 | end |
|
253 | end | |
254 | strings << show_detail(detail, no_html, options) |
|
254 | strings << show_detail(detail, no_html, options) | |
255 | end |
|
255 | end | |
256 | values_by_field.each do |field_id, changes| |
|
256 | values_by_field.each do |field_id, changes| | |
257 | detail = JournalDetail.new(:property => 'cf', :prop_key => field_id) |
|
257 | detail = JournalDetail.new(:property => 'cf', :prop_key => field_id) | |
258 | if changes[:added].any? |
|
258 | if changes[:added].any? | |
259 | detail.value = changes[:added] |
|
259 | detail.value = changes[:added] | |
260 | strings << show_detail(detail, no_html, options) |
|
260 | strings << show_detail(detail, no_html, options) | |
261 | elsif changes[:deleted].any? |
|
261 | elsif changes[:deleted].any? | |
262 | detail.old_value = changes[:deleted] |
|
262 | detail.old_value = changes[:deleted] | |
263 | strings << show_detail(detail, no_html, options) |
|
263 | strings << show_detail(detail, no_html, options) | |
264 | end |
|
264 | end | |
265 | end |
|
265 | end | |
266 | strings |
|
266 | strings | |
267 | end |
|
267 | end | |
268 |
|
268 | |||
269 | # Returns the textual representation of a single journal detail |
|
269 | # Returns the textual representation of a single journal detail | |
270 | def show_detail(detail, no_html=false, options={}) |
|
270 | def show_detail(detail, no_html=false, options={}) | |
271 | multiple = false |
|
271 | multiple = false | |
272 | case detail.property |
|
272 | case detail.property | |
273 | when 'attr' |
|
273 | when 'attr' | |
274 | field = detail.prop_key.to_s.gsub(/\_id$/, "") |
|
274 | field = detail.prop_key.to_s.gsub(/\_id$/, "") | |
275 | label = l(("field_" + field).to_sym) |
|
275 | label = l(("field_" + field).to_sym) | |
276 | case detail.prop_key |
|
276 | case detail.prop_key | |
277 | when 'due_date', 'start_date' |
|
277 | when 'due_date', 'start_date' | |
278 | value = format_date(detail.value.to_date) if detail.value |
|
278 | value = format_date(detail.value.to_date) if detail.value | |
279 | old_value = format_date(detail.old_value.to_date) if detail.old_value |
|
279 | old_value = format_date(detail.old_value.to_date) if detail.old_value | |
280 |
|
280 | |||
281 | when 'project_id', 'status_id', 'tracker_id', 'assigned_to_id', |
|
281 | when 'project_id', 'status_id', 'tracker_id', 'assigned_to_id', | |
282 | 'priority_id', 'category_id', 'fixed_version_id' |
|
282 | 'priority_id', 'category_id', 'fixed_version_id' | |
283 | value = find_name_by_reflection(field, detail.value) |
|
283 | value = find_name_by_reflection(field, detail.value) | |
284 | old_value = find_name_by_reflection(field, detail.old_value) |
|
284 | old_value = find_name_by_reflection(field, detail.old_value) | |
285 |
|
285 | |||
286 | when 'estimated_hours' |
|
286 | when 'estimated_hours' | |
287 | value = "%0.02f" % detail.value.to_f unless detail.value.blank? |
|
287 | value = "%0.02f" % detail.value.to_f unless detail.value.blank? | |
288 | old_value = "%0.02f" % detail.old_value.to_f unless detail.old_value.blank? |
|
288 | old_value = "%0.02f" % detail.old_value.to_f unless detail.old_value.blank? | |
289 |
|
289 | |||
290 | when 'parent_id' |
|
290 | when 'parent_id' | |
291 | label = l(:field_parent_issue) |
|
291 | label = l(:field_parent_issue) | |
292 | value = "##{detail.value}" unless detail.value.blank? |
|
292 | value = "##{detail.value}" unless detail.value.blank? | |
293 | old_value = "##{detail.old_value}" unless detail.old_value.blank? |
|
293 | old_value = "##{detail.old_value}" unless detail.old_value.blank? | |
294 |
|
294 | |||
295 | when 'is_private' |
|
295 | when 'is_private' | |
296 | value = l(detail.value == "0" ? :general_text_No : :general_text_Yes) unless detail.value.blank? |
|
296 | value = l(detail.value == "0" ? :general_text_No : :general_text_Yes) unless detail.value.blank? | |
297 | old_value = l(detail.old_value == "0" ? :general_text_No : :general_text_Yes) unless detail.old_value.blank? |
|
297 | old_value = l(detail.old_value == "0" ? :general_text_No : :general_text_Yes) unless detail.old_value.blank? | |
298 | end |
|
298 | end | |
299 | when 'cf' |
|
299 | when 'cf' | |
300 | custom_field = CustomField.find_by_id(detail.prop_key) |
|
300 | custom_field = CustomField.find_by_id(detail.prop_key) | |
301 | if custom_field |
|
301 | if custom_field | |
302 | multiple = custom_field.multiple? |
|
302 | multiple = custom_field.multiple? | |
303 | label = custom_field.name |
|
303 | label = custom_field.name | |
304 | value = format_value(detail.value, custom_field.field_format) if detail.value |
|
304 | value = format_value(detail.value, custom_field.field_format) if detail.value | |
305 | old_value = format_value(detail.old_value, custom_field.field_format) if detail.old_value |
|
305 | old_value = format_value(detail.old_value, custom_field.field_format) if detail.old_value | |
306 | end |
|
306 | end | |
307 | when 'attachment' |
|
307 | when 'attachment' | |
308 | label = l(:label_attachment) |
|
308 | label = l(:label_attachment) | |
|
309 | when 'relation' | |||
|
310 | if detail.value && !detail.old_value | |||
|
311 | rel_issue = Issue.find_by_id(detail.value) | |||
|
312 | value = rel_issue.nil? ? "#{l(:label_issue)} #{detail.value}" : | |||
|
313 | (no_html ? rel_issue : link_to_issue(rel_issue)) | |||
|
314 | elsif detail.old_value && !detail.value | |||
|
315 | rel_issue = Issue.find_by_id(detail.old_value) | |||
|
316 | old_value = rel_issue.nil? ? "#{l(:label_issue)} #{detail.old_value}" : | |||
|
317 | (no_html ? rel_issue : link_to_issue(rel_issue)) | |||
|
318 | end | |||
|
319 | label = l(detail.prop_key.to_sym) | |||
309 | end |
|
320 | end | |
310 | call_hook(:helper_issues_show_detail_after_setting, |
|
321 | call_hook(:helper_issues_show_detail_after_setting, | |
311 | {:detail => detail, :label => label, :value => value, :old_value => old_value }) |
|
322 | {:detail => detail, :label => label, :value => value, :old_value => old_value }) | |
312 |
|
323 | |||
313 | label ||= detail.prop_key |
|
324 | label ||= detail.prop_key | |
314 | value ||= detail.value |
|
325 | value ||= detail.value | |
315 | old_value ||= detail.old_value |
|
326 | old_value ||= detail.old_value | |
316 |
|
327 | |||
317 | unless no_html |
|
328 | unless no_html | |
318 | label = content_tag('strong', label) |
|
329 | label = content_tag('strong', label) | |
319 | old_value = content_tag("i", h(old_value)) if detail.old_value |
|
330 | old_value = content_tag("i", h(old_value)) if detail.old_value | |
320 | old_value = content_tag("del", old_value) if detail.old_value and detail.value.blank? |
|
331 | old_value = content_tag("del", old_value) if detail.old_value and detail.value.blank? | |
321 | if detail.property == 'attachment' && !value.blank? && atta = Attachment.find_by_id(detail.prop_key) |
|
332 | if detail.property == 'attachment' && !value.blank? && atta = Attachment.find_by_id(detail.prop_key) | |
322 | # Link to the attachment if it has not been removed |
|
333 | # Link to the attachment if it has not been removed | |
323 | value = link_to_attachment(atta, :download => true, :only_path => options[:only_path]) |
|
334 | value = link_to_attachment(atta, :download => true, :only_path => options[:only_path]) | |
324 | if options[:only_path] != false && atta.is_text? |
|
335 | if options[:only_path] != false && atta.is_text? | |
325 | value += link_to( |
|
336 | value += link_to( | |
326 | image_tag('magnifier.png'), |
|
337 | image_tag('magnifier.png'), | |
327 | :controller => 'attachments', :action => 'show', |
|
338 | :controller => 'attachments', :action => 'show', | |
328 | :id => atta, :filename => atta.filename |
|
339 | :id => atta, :filename => atta.filename | |
329 | ) |
|
340 | ) | |
330 | end |
|
341 | end | |
331 | else |
|
342 | else | |
332 | value = content_tag("i", h(value)) if value |
|
343 | value = content_tag("i", h(value)) if value | |
333 | end |
|
344 | end | |
334 | end |
|
345 | end | |
335 |
|
346 | |||
336 | if detail.property == 'attr' && detail.prop_key == 'description' |
|
347 | if detail.property == 'attr' && detail.prop_key == 'description' | |
337 | s = l(:text_journal_changed_no_detail, :label => label) |
|
348 | s = l(:text_journal_changed_no_detail, :label => label) | |
338 | unless no_html |
|
349 | unless no_html | |
339 | diff_link = link_to 'diff', |
|
350 | diff_link = link_to 'diff', | |
340 | {:controller => 'journals', :action => 'diff', :id => detail.journal_id, |
|
351 | {:controller => 'journals', :action => 'diff', :id => detail.journal_id, | |
341 | :detail_id => detail.id, :only_path => options[:only_path]}, |
|
352 | :detail_id => detail.id, :only_path => options[:only_path]}, | |
342 | :title => l(:label_view_diff) |
|
353 | :title => l(:label_view_diff) | |
343 | s << " (#{ diff_link })" |
|
354 | s << " (#{ diff_link })" | |
344 | end |
|
355 | end | |
345 | s.html_safe |
|
356 | s.html_safe | |
346 | elsif detail.value.present? |
|
357 | elsif detail.value.present? | |
347 | case detail.property |
|
358 | case detail.property | |
348 | when 'attr', 'cf' |
|
359 | when 'attr', 'cf' | |
349 | if detail.old_value.present? |
|
360 | if detail.old_value.present? | |
350 | l(:text_journal_changed, :label => label, :old => old_value, :new => value).html_safe |
|
361 | l(:text_journal_changed, :label => label, :old => old_value, :new => value).html_safe | |
351 | elsif multiple |
|
362 | elsif multiple | |
352 | l(:text_journal_added, :label => label, :value => value).html_safe |
|
363 | l(:text_journal_added, :label => label, :value => value).html_safe | |
353 | else |
|
364 | else | |
354 | l(:text_journal_set_to, :label => label, :value => value).html_safe |
|
365 | l(:text_journal_set_to, :label => label, :value => value).html_safe | |
355 | end |
|
366 | end | |
356 | when 'attachment' |
|
367 | when 'attachment', 'relation' | |
357 | l(:text_journal_added, :label => label, :value => value).html_safe |
|
368 | l(:text_journal_added, :label => label, :value => value).html_safe | |
358 | end |
|
369 | end | |
359 | else |
|
370 | else | |
360 | l(:text_journal_deleted, :label => label, :old => old_value).html_safe |
|
371 | l(:text_journal_deleted, :label => label, :old => old_value).html_safe | |
361 | end |
|
372 | end | |
362 | end |
|
373 | end | |
363 |
|
374 | |||
364 | # Find the name of an associated record stored in the field attribute |
|
375 | # Find the name of an associated record stored in the field attribute | |
365 | def find_name_by_reflection(field, id) |
|
376 | def find_name_by_reflection(field, id) | |
366 | unless id.present? |
|
377 | unless id.present? | |
367 | return nil |
|
378 | return nil | |
368 | end |
|
379 | end | |
369 | association = Issue.reflect_on_association(field.to_sym) |
|
380 | association = Issue.reflect_on_association(field.to_sym) | |
370 | if association |
|
381 | if association | |
371 | record = association.class_name.constantize.find_by_id(id) |
|
382 | record = association.class_name.constantize.find_by_id(id) | |
372 | if record |
|
383 | if record | |
373 | record.name.force_encoding('UTF-8') if record.name.respond_to?(:force_encoding) |
|
384 | record.name.force_encoding('UTF-8') if record.name.respond_to?(:force_encoding) | |
374 | return record.name |
|
385 | return record.name | |
375 | end |
|
386 | end | |
376 | end |
|
387 | end | |
377 | end |
|
388 | end | |
378 |
|
389 | |||
379 | # Renders issue children recursively |
|
390 | # Renders issue children recursively | |
380 | def render_api_issue_children(issue, api) |
|
391 | def render_api_issue_children(issue, api) | |
381 | return if issue.leaf? |
|
392 | return if issue.leaf? | |
382 | api.array :children do |
|
393 | api.array :children do | |
383 | issue.children.each do |child| |
|
394 | issue.children.each do |child| | |
384 | api.issue(:id => child.id) do |
|
395 | api.issue(:id => child.id) do | |
385 | api.tracker(:id => child.tracker_id, :name => child.tracker.name) unless child.tracker.nil? |
|
396 | api.tracker(:id => child.tracker_id, :name => child.tracker.name) unless child.tracker.nil? | |
386 | api.subject child.subject |
|
397 | api.subject child.subject | |
387 | render_api_issue_children(child, api) |
|
398 | render_api_issue_children(child, api) | |
388 | end |
|
399 | end | |
389 | end |
|
400 | end | |
390 | end |
|
401 | end | |
391 | end |
|
402 | end | |
392 | end |
|
403 | end |
@@ -1,182 +1,210 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2013 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2013 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | class IssueRelation < ActiveRecord::Base |
|
18 | class IssueRelation < ActiveRecord::Base | |
19 | # Class used to represent the relations of an issue |
|
19 | # Class used to represent the relations of an issue | |
20 | class Relations < Array |
|
20 | class Relations < Array | |
21 | include Redmine::I18n |
|
21 | include Redmine::I18n | |
22 |
|
22 | |||
23 | def initialize(issue, *args) |
|
23 | def initialize(issue, *args) | |
24 | @issue = issue |
|
24 | @issue = issue | |
25 | super(*args) |
|
25 | super(*args) | |
26 | end |
|
26 | end | |
27 |
|
27 | |||
28 | def to_s(*args) |
|
28 | def to_s(*args) | |
29 | map {|relation| "#{l(relation.label_for(@issue))} ##{relation.other_issue(@issue).id}"}.join(', ') |
|
29 | map {|relation| "#{l(relation.label_for(@issue))} ##{relation.other_issue(@issue).id}"}.join(', ') | |
30 | end |
|
30 | end | |
31 | end |
|
31 | end | |
32 |
|
32 | |||
33 | belongs_to :issue_from, :class_name => 'Issue', :foreign_key => 'issue_from_id' |
|
33 | belongs_to :issue_from, :class_name => 'Issue', :foreign_key => 'issue_from_id' | |
34 | belongs_to :issue_to, :class_name => 'Issue', :foreign_key => 'issue_to_id' |
|
34 | belongs_to :issue_to, :class_name => 'Issue', :foreign_key => 'issue_to_id' | |
35 |
|
35 | |||
36 | TYPE_RELATES = "relates" |
|
36 | TYPE_RELATES = "relates" | |
37 | TYPE_DUPLICATES = "duplicates" |
|
37 | TYPE_DUPLICATES = "duplicates" | |
38 | TYPE_DUPLICATED = "duplicated" |
|
38 | TYPE_DUPLICATED = "duplicated" | |
39 | TYPE_BLOCKS = "blocks" |
|
39 | TYPE_BLOCKS = "blocks" | |
40 | TYPE_BLOCKED = "blocked" |
|
40 | TYPE_BLOCKED = "blocked" | |
41 | TYPE_PRECEDES = "precedes" |
|
41 | TYPE_PRECEDES = "precedes" | |
42 | TYPE_FOLLOWS = "follows" |
|
42 | TYPE_FOLLOWS = "follows" | |
43 | TYPE_COPIED_TO = "copied_to" |
|
43 | TYPE_COPIED_TO = "copied_to" | |
44 | TYPE_COPIED_FROM = "copied_from" |
|
44 | TYPE_COPIED_FROM = "copied_from" | |
45 |
|
45 | |||
46 | TYPES = { |
|
46 | TYPES = { | |
47 | TYPE_RELATES => { :name => :label_relates_to, :sym_name => :label_relates_to, |
|
47 | TYPE_RELATES => { :name => :label_relates_to, :sym_name => :label_relates_to, | |
48 | :order => 1, :sym => TYPE_RELATES }, |
|
48 | :order => 1, :sym => TYPE_RELATES }, | |
49 | TYPE_DUPLICATES => { :name => :label_duplicates, :sym_name => :label_duplicated_by, |
|
49 | TYPE_DUPLICATES => { :name => :label_duplicates, :sym_name => :label_duplicated_by, | |
50 | :order => 2, :sym => TYPE_DUPLICATED }, |
|
50 | :order => 2, :sym => TYPE_DUPLICATED }, | |
51 | TYPE_DUPLICATED => { :name => :label_duplicated_by, :sym_name => :label_duplicates, |
|
51 | TYPE_DUPLICATED => { :name => :label_duplicated_by, :sym_name => :label_duplicates, | |
52 | :order => 3, :sym => TYPE_DUPLICATES, :reverse => TYPE_DUPLICATES }, |
|
52 | :order => 3, :sym => TYPE_DUPLICATES, :reverse => TYPE_DUPLICATES }, | |
53 | TYPE_BLOCKS => { :name => :label_blocks, :sym_name => :label_blocked_by, |
|
53 | TYPE_BLOCKS => { :name => :label_blocks, :sym_name => :label_blocked_by, | |
54 | :order => 4, :sym => TYPE_BLOCKED }, |
|
54 | :order => 4, :sym => TYPE_BLOCKED }, | |
55 | TYPE_BLOCKED => { :name => :label_blocked_by, :sym_name => :label_blocks, |
|
55 | TYPE_BLOCKED => { :name => :label_blocked_by, :sym_name => :label_blocks, | |
56 | :order => 5, :sym => TYPE_BLOCKS, :reverse => TYPE_BLOCKS }, |
|
56 | :order => 5, :sym => TYPE_BLOCKS, :reverse => TYPE_BLOCKS }, | |
57 | TYPE_PRECEDES => { :name => :label_precedes, :sym_name => :label_follows, |
|
57 | TYPE_PRECEDES => { :name => :label_precedes, :sym_name => :label_follows, | |
58 | :order => 6, :sym => TYPE_FOLLOWS }, |
|
58 | :order => 6, :sym => TYPE_FOLLOWS }, | |
59 | TYPE_FOLLOWS => { :name => :label_follows, :sym_name => :label_precedes, |
|
59 | TYPE_FOLLOWS => { :name => :label_follows, :sym_name => :label_precedes, | |
60 | :order => 7, :sym => TYPE_PRECEDES, :reverse => TYPE_PRECEDES }, |
|
60 | :order => 7, :sym => TYPE_PRECEDES, :reverse => TYPE_PRECEDES }, | |
61 | TYPE_COPIED_TO => { :name => :label_copied_to, :sym_name => :label_copied_from, |
|
61 | TYPE_COPIED_TO => { :name => :label_copied_to, :sym_name => :label_copied_from, | |
62 | :order => 8, :sym => TYPE_COPIED_FROM }, |
|
62 | :order => 8, :sym => TYPE_COPIED_FROM }, | |
63 | TYPE_COPIED_FROM => { :name => :label_copied_from, :sym_name => :label_copied_to, |
|
63 | TYPE_COPIED_FROM => { :name => :label_copied_from, :sym_name => :label_copied_to, | |
64 | :order => 9, :sym => TYPE_COPIED_TO, :reverse => TYPE_COPIED_TO } |
|
64 | :order => 9, :sym => TYPE_COPIED_TO, :reverse => TYPE_COPIED_TO } | |
65 | }.freeze |
|
65 | }.freeze | |
66 |
|
66 | |||
67 | validates_presence_of :issue_from, :issue_to, :relation_type |
|
67 | validates_presence_of :issue_from, :issue_to, :relation_type | |
68 | validates_inclusion_of :relation_type, :in => TYPES.keys |
|
68 | validates_inclusion_of :relation_type, :in => TYPES.keys | |
69 | validates_numericality_of :delay, :allow_nil => true |
|
69 | validates_numericality_of :delay, :allow_nil => true | |
70 | validates_uniqueness_of :issue_to_id, :scope => :issue_from_id |
|
70 | validates_uniqueness_of :issue_to_id, :scope => :issue_from_id | |
71 | validate :validate_issue_relation |
|
71 | validate :validate_issue_relation | |
72 |
|
72 | |||
73 | attr_protected :issue_from_id, :issue_to_id |
|
73 | attr_protected :issue_from_id, :issue_to_id | |
74 | before_save :handle_issue_order |
|
74 | before_save :handle_issue_order | |
|
75 | after_create :create_journal_after_create | |||
|
76 | after_destroy :create_journal_after_delete | |||
75 |
|
77 | |||
76 | def visible?(user=User.current) |
|
78 | def visible?(user=User.current) | |
77 | (issue_from.nil? || issue_from.visible?(user)) && (issue_to.nil? || issue_to.visible?(user)) |
|
79 | (issue_from.nil? || issue_from.visible?(user)) && (issue_to.nil? || issue_to.visible?(user)) | |
78 | end |
|
80 | end | |
79 |
|
81 | |||
80 | def deletable?(user=User.current) |
|
82 | def deletable?(user=User.current) | |
81 | visible?(user) && |
|
83 | visible?(user) && | |
82 | ((issue_from.nil? || user.allowed_to?(:manage_issue_relations, issue_from.project)) || |
|
84 | ((issue_from.nil? || user.allowed_to?(:manage_issue_relations, issue_from.project)) || | |
83 | (issue_to.nil? || user.allowed_to?(:manage_issue_relations, issue_to.project))) |
|
85 | (issue_to.nil? || user.allowed_to?(:manage_issue_relations, issue_to.project))) | |
84 | end |
|
86 | end | |
85 |
|
87 | |||
86 | def initialize(attributes=nil, *args) |
|
88 | def initialize(attributes=nil, *args) | |
87 | super |
|
89 | super | |
88 | if new_record? |
|
90 | if new_record? | |
89 | if relation_type.blank? |
|
91 | if relation_type.blank? | |
90 | self.relation_type = IssueRelation::TYPE_RELATES |
|
92 | self.relation_type = IssueRelation::TYPE_RELATES | |
91 | end |
|
93 | end | |
92 | end |
|
94 | end | |
93 | end |
|
95 | end | |
94 |
|
96 | |||
95 | def validate_issue_relation |
|
97 | def validate_issue_relation | |
96 | if issue_from && issue_to |
|
98 | if issue_from && issue_to | |
97 | errors.add :issue_to_id, :invalid if issue_from_id == issue_to_id |
|
99 | errors.add :issue_to_id, :invalid if issue_from_id == issue_to_id | |
98 | unless issue_from.project_id == issue_to.project_id || |
|
100 | unless issue_from.project_id == issue_to.project_id || | |
99 | Setting.cross_project_issue_relations? |
|
101 | Setting.cross_project_issue_relations? | |
100 | errors.add :issue_to_id, :not_same_project |
|
102 | errors.add :issue_to_id, :not_same_project | |
101 | end |
|
103 | end | |
102 | # detect circular dependencies depending wether the relation should be reversed |
|
104 | # detect circular dependencies depending wether the relation should be reversed | |
103 | if TYPES.has_key?(relation_type) && TYPES[relation_type][:reverse] |
|
105 | if TYPES.has_key?(relation_type) && TYPES[relation_type][:reverse] | |
104 | errors.add :base, :circular_dependency if issue_from.all_dependent_issues.include? issue_to |
|
106 | errors.add :base, :circular_dependency if issue_from.all_dependent_issues.include? issue_to | |
105 | else |
|
107 | else | |
106 | errors.add :base, :circular_dependency if issue_to.all_dependent_issues.include? issue_from |
|
108 | errors.add :base, :circular_dependency if issue_to.all_dependent_issues.include? issue_from | |
107 | end |
|
109 | end | |
108 | if issue_from.is_descendant_of?(issue_to) || issue_from.is_ancestor_of?(issue_to) |
|
110 | if issue_from.is_descendant_of?(issue_to) || issue_from.is_ancestor_of?(issue_to) | |
109 | errors.add :base, :cant_link_an_issue_with_a_descendant |
|
111 | errors.add :base, :cant_link_an_issue_with_a_descendant | |
110 | end |
|
112 | end | |
111 | end |
|
113 | end | |
112 | end |
|
114 | end | |
113 |
|
115 | |||
114 | def other_issue(issue) |
|
116 | def other_issue(issue) | |
115 | (self.issue_from_id == issue.id) ? issue_to : issue_from |
|
117 | (self.issue_from_id == issue.id) ? issue_to : issue_from | |
116 | end |
|
118 | end | |
117 |
|
119 | |||
118 | # Returns the relation type for +issue+ |
|
120 | # Returns the relation type for +issue+ | |
119 | def relation_type_for(issue) |
|
121 | def relation_type_for(issue) | |
120 | if TYPES[relation_type] |
|
122 | if TYPES[relation_type] | |
121 | if self.issue_from_id == issue.id |
|
123 | if self.issue_from_id == issue.id | |
122 | relation_type |
|
124 | relation_type | |
123 | else |
|
125 | else | |
124 | TYPES[relation_type][:sym] |
|
126 | TYPES[relation_type][:sym] | |
125 | end |
|
127 | end | |
126 | end |
|
128 | end | |
127 | end |
|
129 | end | |
128 |
|
130 | |||
129 | def label_for(issue) |
|
131 | def label_for(issue) | |
130 | TYPES[relation_type] ? |
|
132 | TYPES[relation_type] ? | |
131 | TYPES[relation_type][(self.issue_from_id == issue.id) ? :name : :sym_name] : |
|
133 | TYPES[relation_type][(self.issue_from_id == issue.id) ? :name : :sym_name] : | |
132 | :unknow |
|
134 | :unknow | |
133 | end |
|
135 | end | |
134 |
|
136 | |||
135 | def css_classes_for(issue) |
|
137 | def css_classes_for(issue) | |
136 | "rel-#{relation_type_for(issue)}" |
|
138 | "rel-#{relation_type_for(issue)}" | |
137 | end |
|
139 | end | |
138 |
|
140 | |||
139 | def handle_issue_order |
|
141 | def handle_issue_order | |
140 | reverse_if_needed |
|
142 | reverse_if_needed | |
141 |
|
143 | |||
142 | if TYPE_PRECEDES == relation_type |
|
144 | if TYPE_PRECEDES == relation_type | |
143 | self.delay ||= 0 |
|
145 | self.delay ||= 0 | |
144 | else |
|
146 | else | |
145 | self.delay = nil |
|
147 | self.delay = nil | |
146 | end |
|
148 | end | |
147 | set_issue_to_dates |
|
149 | set_issue_to_dates | |
148 | end |
|
150 | end | |
149 |
|
151 | |||
150 | def set_issue_to_dates |
|
152 | def set_issue_to_dates | |
151 | soonest_start = self.successor_soonest_start |
|
153 | soonest_start = self.successor_soonest_start | |
152 | if soonest_start && issue_to |
|
154 | if soonest_start && issue_to | |
153 | issue_to.reschedule_on!(soonest_start) |
|
155 | issue_to.reschedule_on!(soonest_start) | |
154 | end |
|
156 | end | |
155 | end |
|
157 | end | |
156 |
|
158 | |||
157 | def successor_soonest_start |
|
159 | def successor_soonest_start | |
158 | if (TYPE_PRECEDES == self.relation_type) && delay && issue_from && |
|
160 | if (TYPE_PRECEDES == self.relation_type) && delay && issue_from && | |
159 | (issue_from.start_date || issue_from.due_date) |
|
161 | (issue_from.start_date || issue_from.due_date) | |
160 | (issue_from.due_date || issue_from.start_date) + 1 + delay |
|
162 | (issue_from.due_date || issue_from.start_date) + 1 + delay | |
161 | end |
|
163 | end | |
162 | end |
|
164 | end | |
163 |
|
165 | |||
164 | def <=>(relation) |
|
166 | def <=>(relation) | |
165 | r = TYPES[self.relation_type][:order] <=> TYPES[relation.relation_type][:order] |
|
167 | r = TYPES[self.relation_type][:order] <=> TYPES[relation.relation_type][:order] | |
166 | r == 0 ? id <=> relation.id : r |
|
168 | r == 0 ? id <=> relation.id : r | |
167 | end |
|
169 | end | |
168 |
|
170 | |||
169 | private |
|
171 | private | |
170 |
|
172 | |||
171 | # Reverses the relation if needed so that it gets stored in the proper way |
|
173 | # Reverses the relation if needed so that it gets stored in the proper way | |
172 | # Should not be reversed before validation so that it can be displayed back |
|
174 | # Should not be reversed before validation so that it can be displayed back | |
173 | # as entered on new relation form |
|
175 | # as entered on new relation form | |
174 | def reverse_if_needed |
|
176 | def reverse_if_needed | |
175 | if TYPES.has_key?(relation_type) && TYPES[relation_type][:reverse] |
|
177 | if TYPES.has_key?(relation_type) && TYPES[relation_type][:reverse] | |
176 | issue_tmp = issue_to |
|
178 | issue_tmp = issue_to | |
177 | self.issue_to = issue_from |
|
179 | self.issue_to = issue_from | |
178 | self.issue_from = issue_tmp |
|
180 | self.issue_from = issue_tmp | |
179 | self.relation_type = TYPES[relation_type][:reverse] |
|
181 | self.relation_type = TYPES[relation_type][:reverse] | |
180 | end |
|
182 | end | |
181 | end |
|
183 | end | |
|
184 | ||||
|
185 | def create_journal_after_create | |||
|
186 | journal = issue_from.init_journal(User.current) | |||
|
187 | journal.details << JournalDetail.new(:property => 'relation', | |||
|
188 | :prop_key => label_for(issue_from).to_s, | |||
|
189 | :value => issue_to.id) | |||
|
190 | journal.save | |||
|
191 | journal = issue_to.init_journal(User.current) | |||
|
192 | journal.details << JournalDetail.new(:property => 'relation', | |||
|
193 | :prop_key => label_for(issue_to).to_s, | |||
|
194 | :value => issue_from.id) | |||
|
195 | journal.save | |||
|
196 | end | |||
|
197 | ||||
|
198 | def create_journal_after_delete | |||
|
199 | journal = issue_from.init_journal(User.current) | |||
|
200 | journal.details << JournalDetail.new(:property => 'relation', | |||
|
201 | :prop_key => label_for(issue_from).to_s, | |||
|
202 | :old_value => issue_to.id) | |||
|
203 | journal.save | |||
|
204 | journal = issue_to.init_journal(User.current) | |||
|
205 | journal.details << JournalDetail.new(:property => 'relation', | |||
|
206 | :prop_key => label_for(issue_to).to_s, | |||
|
207 | :old_value => issue_from.id) | |||
|
208 | journal.save | |||
|
209 | end | |||
182 | end |
|
210 | end |
@@ -1,213 +1,245 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2013 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2013 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | require File.expand_path('../../../test_helper', __FILE__) |
|
18 | require File.expand_path('../../../test_helper', __FILE__) | |
19 |
|
19 | |||
20 | class IssuesHelperTest < ActionView::TestCase |
|
20 | class IssuesHelperTest < ActionView::TestCase | |
21 | include ApplicationHelper |
|
21 | include ApplicationHelper | |
22 | include Redmine::I18n |
|
22 | include Redmine::I18n | |
23 | include IssuesHelper |
|
23 | include IssuesHelper | |
24 | include CustomFieldsHelper |
|
24 | include CustomFieldsHelper | |
25 | include ERB::Util |
|
25 | include ERB::Util | |
26 |
|
26 | |||
27 | fixtures :projects, :trackers, :issue_statuses, :issues, |
|
27 | fixtures :projects, :trackers, :issue_statuses, :issues, | |
28 | :enumerations, :users, :issue_categories, |
|
28 | :enumerations, :users, :issue_categories, | |
29 | :projects_trackers, |
|
29 | :projects_trackers, | |
30 | :roles, |
|
30 | :roles, | |
31 | :member_roles, |
|
31 | :member_roles, | |
32 | :members, |
|
32 | :members, | |
33 | :enabled_modules, |
|
33 | :enabled_modules, | |
34 | :custom_fields, |
|
34 | :custom_fields, | |
35 | :attachments, |
|
35 | :attachments, | |
36 | :versions |
|
36 | :versions | |
37 |
|
37 | |||
38 | def setup |
|
38 | def setup | |
39 | super |
|
39 | super | |
40 | set_language_if_valid('en') |
|
40 | set_language_if_valid('en') | |
41 | User.current = nil |
|
41 | User.current = nil | |
42 | end |
|
42 | end | |
43 |
|
43 | |||
44 | def test_issue_heading |
|
44 | def test_issue_heading | |
45 | assert_equal "Bug #1", issue_heading(Issue.find(1)) |
|
45 | assert_equal "Bug #1", issue_heading(Issue.find(1)) | |
46 | end |
|
46 | end | |
47 |
|
47 | |||
48 | def test_issues_destroy_confirmation_message_with_one_root_issue |
|
48 | def test_issues_destroy_confirmation_message_with_one_root_issue | |
49 | assert_equal l(:text_issues_destroy_confirmation), |
|
49 | assert_equal l(:text_issues_destroy_confirmation), | |
50 | issues_destroy_confirmation_message(Issue.find(1)) |
|
50 | issues_destroy_confirmation_message(Issue.find(1)) | |
51 | end |
|
51 | end | |
52 |
|
52 | |||
53 | def test_issues_destroy_confirmation_message_with_an_arrayt_of_root_issues |
|
53 | def test_issues_destroy_confirmation_message_with_an_arrayt_of_root_issues | |
54 | assert_equal l(:text_issues_destroy_confirmation), |
|
54 | assert_equal l(:text_issues_destroy_confirmation), | |
55 | issues_destroy_confirmation_message(Issue.find([1, 2])) |
|
55 | issues_destroy_confirmation_message(Issue.find([1, 2])) | |
56 | end |
|
56 | end | |
57 |
|
57 | |||
58 | def test_issues_destroy_confirmation_message_with_one_parent_issue |
|
58 | def test_issues_destroy_confirmation_message_with_one_parent_issue | |
59 | Issue.find(2).update_attribute :parent_issue_id, 1 |
|
59 | Issue.find(2).update_attribute :parent_issue_id, 1 | |
60 | assert_equal l(:text_issues_destroy_confirmation) + "\n" + |
|
60 | assert_equal l(:text_issues_destroy_confirmation) + "\n" + | |
61 | l(:text_issues_destroy_descendants_confirmation, :count => 1), |
|
61 | l(:text_issues_destroy_descendants_confirmation, :count => 1), | |
62 | issues_destroy_confirmation_message(Issue.find(1)) |
|
62 | issues_destroy_confirmation_message(Issue.find(1)) | |
63 | end |
|
63 | end | |
64 |
|
64 | |||
65 | def test_issues_destroy_confirmation_message_with_one_parent_issue_and_its_child |
|
65 | def test_issues_destroy_confirmation_message_with_one_parent_issue_and_its_child | |
66 | Issue.find(2).update_attribute :parent_issue_id, 1 |
|
66 | Issue.find(2).update_attribute :parent_issue_id, 1 | |
67 | assert_equal l(:text_issues_destroy_confirmation), |
|
67 | assert_equal l(:text_issues_destroy_confirmation), | |
68 | issues_destroy_confirmation_message(Issue.find([1, 2])) |
|
68 | issues_destroy_confirmation_message(Issue.find([1, 2])) | |
69 | end |
|
69 | end | |
70 |
|
70 | |||
71 | test 'show_detail with no_html should show a changing attribute' do |
|
71 | test 'show_detail with no_html should show a changing attribute' do | |
72 | detail = JournalDetail.new(:property => 'attr', :old_value => '40', |
|
72 | detail = JournalDetail.new(:property => 'attr', :old_value => '40', | |
73 | :value => '100', :prop_key => 'done_ratio') |
|
73 | :value => '100', :prop_key => 'done_ratio') | |
74 | assert_equal "% Done changed from 40 to 100", show_detail(detail, true) |
|
74 | assert_equal "% Done changed from 40 to 100", show_detail(detail, true) | |
75 | end |
|
75 | end | |
76 |
|
76 | |||
77 | test 'show_detail with no_html should show a new attribute' do |
|
77 | test 'show_detail with no_html should show a new attribute' do | |
78 | detail = JournalDetail.new(:property => 'attr', :old_value => nil, |
|
78 | detail = JournalDetail.new(:property => 'attr', :old_value => nil, | |
79 | :value => '100', :prop_key => 'done_ratio') |
|
79 | :value => '100', :prop_key => 'done_ratio') | |
80 | assert_equal "% Done set to 100", show_detail(detail, true) |
|
80 | assert_equal "% Done set to 100", show_detail(detail, true) | |
81 | end |
|
81 | end | |
82 |
|
82 | |||
83 | test 'show_detail with no_html should show a deleted attribute' do |
|
83 | test 'show_detail with no_html should show a deleted attribute' do | |
84 | detail = JournalDetail.new(:property => 'attr', :old_value => '50', |
|
84 | detail = JournalDetail.new(:property => 'attr', :old_value => '50', | |
85 | :value => nil, :prop_key => 'done_ratio') |
|
85 | :value => nil, :prop_key => 'done_ratio') | |
86 | assert_equal "% Done deleted (50)", show_detail(detail, true) |
|
86 | assert_equal "% Done deleted (50)", show_detail(detail, true) | |
87 | end |
|
87 | end | |
88 |
|
88 | |||
89 | test 'show_detail with html should show a changing attribute with HTML highlights' do |
|
89 | test 'show_detail with html should show a changing attribute with HTML highlights' do | |
90 | detail = JournalDetail.new(:property => 'attr', :old_value => '40', |
|
90 | detail = JournalDetail.new(:property => 'attr', :old_value => '40', | |
91 | :value => '100', :prop_key => 'done_ratio') |
|
91 | :value => '100', :prop_key => 'done_ratio') | |
92 | html = show_detail(detail, false) |
|
92 | html = show_detail(detail, false) | |
93 | assert_include '<strong>% Done</strong>', html |
|
93 | assert_include '<strong>% Done</strong>', html | |
94 | assert_include '<i>40</i>', html |
|
94 | assert_include '<i>40</i>', html | |
95 | assert_include '<i>100</i>', html |
|
95 | assert_include '<i>100</i>', html | |
96 | end |
|
96 | end | |
97 |
|
97 | |||
98 | test 'show_detail with html should show a new attribute with HTML highlights' do |
|
98 | test 'show_detail with html should show a new attribute with HTML highlights' do | |
99 | detail = JournalDetail.new(:property => 'attr', :old_value => nil, |
|
99 | detail = JournalDetail.new(:property => 'attr', :old_value => nil, | |
100 | :value => '100', :prop_key => 'done_ratio') |
|
100 | :value => '100', :prop_key => 'done_ratio') | |
101 | html = show_detail(detail, false) |
|
101 | html = show_detail(detail, false) | |
102 | assert_include '<strong>% Done</strong>', html |
|
102 | assert_include '<strong>% Done</strong>', html | |
103 | assert_include '<i>100</i>', html |
|
103 | assert_include '<i>100</i>', html | |
104 | end |
|
104 | end | |
105 |
|
105 | |||
106 | test 'show_detail with html should show a deleted attribute with HTML highlights' do |
|
106 | test 'show_detail with html should show a deleted attribute with HTML highlights' do | |
107 | detail = JournalDetail.new(:property => 'attr', :old_value => '50', |
|
107 | detail = JournalDetail.new(:property => 'attr', :old_value => '50', | |
108 | :value => nil, :prop_key => 'done_ratio') |
|
108 | :value => nil, :prop_key => 'done_ratio') | |
109 | html = show_detail(detail, false) |
|
109 | html = show_detail(detail, false) | |
110 | assert_include '<strong>% Done</strong>', html |
|
110 | assert_include '<strong>% Done</strong>', html | |
111 | assert_include '<del><i>50</i></del>', html |
|
111 | assert_include '<del><i>50</i></del>', html | |
112 | end |
|
112 | end | |
113 |
|
113 | |||
114 | test 'show_detail with a start_date attribute should format the dates' do |
|
114 | test 'show_detail with a start_date attribute should format the dates' do | |
115 | detail = JournalDetail.new( |
|
115 | detail = JournalDetail.new( | |
116 | :property => 'attr', |
|
116 | :property => 'attr', | |
117 | :old_value => '2010-01-01', |
|
117 | :old_value => '2010-01-01', | |
118 | :value => '2010-01-31', |
|
118 | :value => '2010-01-31', | |
119 | :prop_key => 'start_date' |
|
119 | :prop_key => 'start_date' | |
120 | ) |
|
120 | ) | |
121 | with_settings :date_format => '%m/%d/%Y' do |
|
121 | with_settings :date_format => '%m/%d/%Y' do | |
122 | assert_match "01/31/2010", show_detail(detail, true) |
|
122 | assert_match "01/31/2010", show_detail(detail, true) | |
123 | assert_match "01/01/2010", show_detail(detail, true) |
|
123 | assert_match "01/01/2010", show_detail(detail, true) | |
124 | end |
|
124 | end | |
125 | end |
|
125 | end | |
126 |
|
126 | |||
127 | test 'show_detail with a due_date attribute should format the dates' do |
|
127 | test 'show_detail with a due_date attribute should format the dates' do | |
128 | detail = JournalDetail.new( |
|
128 | detail = JournalDetail.new( | |
129 | :property => 'attr', |
|
129 | :property => 'attr', | |
130 | :old_value => '2010-01-01', |
|
130 | :old_value => '2010-01-01', | |
131 | :value => '2010-01-31', |
|
131 | :value => '2010-01-31', | |
132 | :prop_key => 'due_date' |
|
132 | :prop_key => 'due_date' | |
133 | ) |
|
133 | ) | |
134 | with_settings :date_format => '%m/%d/%Y' do |
|
134 | with_settings :date_format => '%m/%d/%Y' do | |
135 | assert_match "01/31/2010", show_detail(detail, true) |
|
135 | assert_match "01/31/2010", show_detail(detail, true) | |
136 | assert_match "01/01/2010", show_detail(detail, true) |
|
136 | assert_match "01/01/2010", show_detail(detail, true) | |
137 | end |
|
137 | end | |
138 | end |
|
138 | end | |
139 |
|
139 | |||
140 | test 'show_detail should show old and new values with a project attribute' do |
|
140 | test 'show_detail should show old and new values with a project attribute' do | |
141 | detail = JournalDetail.new(:property => 'attr', :prop_key => 'project_id', |
|
141 | detail = JournalDetail.new(:property => 'attr', :prop_key => 'project_id', | |
142 | :old_value => 1, :value => 2) |
|
142 | :old_value => 1, :value => 2) | |
143 | assert_match 'eCookbook', show_detail(detail, true) |
|
143 | assert_match 'eCookbook', show_detail(detail, true) | |
144 | assert_match 'OnlineStore', show_detail(detail, true) |
|
144 | assert_match 'OnlineStore', show_detail(detail, true) | |
145 | end |
|
145 | end | |
146 |
|
146 | |||
147 | test 'show_detail should show old and new values with a issue status attribute' do |
|
147 | test 'show_detail should show old and new values with a issue status attribute' do | |
148 | detail = JournalDetail.new(:property => 'attr', :prop_key => 'status_id', |
|
148 | detail = JournalDetail.new(:property => 'attr', :prop_key => 'status_id', | |
149 | :old_value => 1, :value => 2) |
|
149 | :old_value => 1, :value => 2) | |
150 | assert_match 'New', show_detail(detail, true) |
|
150 | assert_match 'New', show_detail(detail, true) | |
151 | assert_match 'Assigned', show_detail(detail, true) |
|
151 | assert_match 'Assigned', show_detail(detail, true) | |
152 | end |
|
152 | end | |
153 |
|
153 | |||
154 | test 'show_detail should show old and new values with a tracker attribute' do |
|
154 | test 'show_detail should show old and new values with a tracker attribute' do | |
155 | detail = JournalDetail.new(:property => 'attr', :prop_key => 'tracker_id', |
|
155 | detail = JournalDetail.new(:property => 'attr', :prop_key => 'tracker_id', | |
156 | :old_value => 1, :value => 2) |
|
156 | :old_value => 1, :value => 2) | |
157 | assert_match 'Bug', show_detail(detail, true) |
|
157 | assert_match 'Bug', show_detail(detail, true) | |
158 | assert_match 'Feature request', show_detail(detail, true) |
|
158 | assert_match 'Feature request', show_detail(detail, true) | |
159 | end |
|
159 | end | |
160 |
|
160 | |||
161 | test 'show_detail should show old and new values with a assigned to attribute' do |
|
161 | test 'show_detail should show old and new values with a assigned to attribute' do | |
162 | detail = JournalDetail.new(:property => 'attr', :prop_key => 'assigned_to_id', |
|
162 | detail = JournalDetail.new(:property => 'attr', :prop_key => 'assigned_to_id', | |
163 | :old_value => 1, :value => 2) |
|
163 | :old_value => 1, :value => 2) | |
164 | assert_match 'Redmine Admin', show_detail(detail, true) |
|
164 | assert_match 'Redmine Admin', show_detail(detail, true) | |
165 | assert_match 'John Smith', show_detail(detail, true) |
|
165 | assert_match 'John Smith', show_detail(detail, true) | |
166 | end |
|
166 | end | |
167 |
|
167 | |||
168 | test 'show_detail should show old and new values with a priority attribute' do |
|
168 | test 'show_detail should show old and new values with a priority attribute' do | |
169 | detail = JournalDetail.new(:property => 'attr', :prop_key => 'priority_id', |
|
169 | detail = JournalDetail.new(:property => 'attr', :prop_key => 'priority_id', | |
170 | :old_value => 4, :value => 5) |
|
170 | :old_value => 4, :value => 5) | |
171 | assert_match 'Low', show_detail(detail, true) |
|
171 | assert_match 'Low', show_detail(detail, true) | |
172 | assert_match 'Normal', show_detail(detail, true) |
|
172 | assert_match 'Normal', show_detail(detail, true) | |
173 | end |
|
173 | end | |
174 |
|
174 | |||
175 | test 'show_detail should show old and new values with a category attribute' do |
|
175 | test 'show_detail should show old and new values with a category attribute' do | |
176 | detail = JournalDetail.new(:property => 'attr', :prop_key => 'category_id', |
|
176 | detail = JournalDetail.new(:property => 'attr', :prop_key => 'category_id', | |
177 | :old_value => 1, :value => 2) |
|
177 | :old_value => 1, :value => 2) | |
178 | assert_match 'Printing', show_detail(detail, true) |
|
178 | assert_match 'Printing', show_detail(detail, true) | |
179 | assert_match 'Recipes', show_detail(detail, true) |
|
179 | assert_match 'Recipes', show_detail(detail, true) | |
180 | end |
|
180 | end | |
181 |
|
181 | |||
182 | test 'show_detail should show old and new values with a fixed version attribute' do |
|
182 | test 'show_detail should show old and new values with a fixed version attribute' do | |
183 | detail = JournalDetail.new(:property => 'attr', :prop_key => 'fixed_version_id', |
|
183 | detail = JournalDetail.new(:property => 'attr', :prop_key => 'fixed_version_id', | |
184 | :old_value => 1, :value => 2) |
|
184 | :old_value => 1, :value => 2) | |
185 | assert_match '0.1', show_detail(detail, true) |
|
185 | assert_match '0.1', show_detail(detail, true) | |
186 | assert_match '1.0', show_detail(detail, true) |
|
186 | assert_match '1.0', show_detail(detail, true) | |
187 | end |
|
187 | end | |
188 |
|
188 | |||
189 | test 'show_detail should show old and new values with a estimated hours attribute' do |
|
189 | test 'show_detail should show old and new values with a estimated hours attribute' do | |
190 | detail = JournalDetail.new(:property => 'attr', :prop_key => 'estimated_hours', |
|
190 | detail = JournalDetail.new(:property => 'attr', :prop_key => 'estimated_hours', | |
191 | :old_value => '5', :value => '6.3') |
|
191 | :old_value => '5', :value => '6.3') | |
192 | assert_match '5.00', show_detail(detail, true) |
|
192 | assert_match '5.00', show_detail(detail, true) | |
193 | assert_match '6.30', show_detail(detail, true) |
|
193 | assert_match '6.30', show_detail(detail, true) | |
194 | end |
|
194 | end | |
195 |
|
195 | |||
196 | test 'show_detail should show old and new values with a custom field' do |
|
196 | test 'show_detail should show old and new values with a custom field' do | |
197 | detail = JournalDetail.new(:property => 'cf', :prop_key => '1', |
|
197 | detail = JournalDetail.new(:property => 'cf', :prop_key => '1', | |
198 | :old_value => 'MySQL', :value => 'PostgreSQL') |
|
198 | :old_value => 'MySQL', :value => 'PostgreSQL') | |
199 | assert_equal 'Database changed from MySQL to PostgreSQL', show_detail(detail, true) |
|
199 | assert_equal 'Database changed from MySQL to PostgreSQL', show_detail(detail, true) | |
200 | end |
|
200 | end | |
201 |
|
201 | |||
202 | test 'show_detail should show added file' do |
|
202 | test 'show_detail should show added file' do | |
203 | detail = JournalDetail.new(:property => 'attachment', :prop_key => '1', |
|
203 | detail = JournalDetail.new(:property => 'attachment', :prop_key => '1', | |
204 | :old_value => nil, :value => 'error281.txt') |
|
204 | :old_value => nil, :value => 'error281.txt') | |
205 | assert_match 'error281.txt', show_detail(detail, true) |
|
205 | assert_match 'error281.txt', show_detail(detail, true) | |
206 | end |
|
206 | end | |
207 |
|
207 | |||
208 | test 'show_detail should show removed file' do |
|
208 | test 'show_detail should show removed file' do | |
209 | detail = JournalDetail.new(:property => 'attachment', :prop_key => '1', |
|
209 | detail = JournalDetail.new(:property => 'attachment', :prop_key => '1', | |
210 | :old_value => 'error281.txt', :value => nil) |
|
210 | :old_value => 'error281.txt', :value => nil) | |
211 | assert_match 'error281.txt', show_detail(detail, true) |
|
211 | assert_match 'error281.txt', show_detail(detail, true) | |
212 | end |
|
212 | end | |
|
213 | ||||
|
214 | def test_show_detail_create_relation | |||
|
215 | detail = JournalDetail.new(:property => 'relation', | |||
|
216 | :prop_key => 'label_precedes', | |||
|
217 | :value => 1) | |||
|
218 | assert_equal "Precedes Bug #1: Can't print recipes added", show_detail(detail, true) | |||
|
219 | assert_match %r{<strong>Precedes</strong> <i><a href="/issues/1" class=".+">Bug #1</a>: Can't print recipes</i> added}, | |||
|
220 | show_detail(detail, false) | |||
|
221 | non_existed_issue_number = 9999 | |||
|
222 | assert_nil Issue.find_by_id(non_existed_issue_number) | |||
|
223 | detail = JournalDetail.new(:property => 'relation', | |||
|
224 | :prop_key => 'label_precedes', | |||
|
225 | :value => non_existed_issue_number) | |||
|
226 | assert_equal "Precedes Issue #{non_existed_issue_number} added", show_detail(detail, true) | |||
|
227 | assert_equal "<strong>Precedes</strong> <i>Issue #{non_existed_issue_number}</i> added", show_detail(detail, false) | |||
|
228 | end | |||
|
229 | ||||
|
230 | def test_show_detail_delete_relation | |||
|
231 | detail = JournalDetail.new(:property => 'relation', | |||
|
232 | :prop_key => 'label_precedes', | |||
|
233 | :old_value => 1) | |||
|
234 | assert_equal "Precedes deleted (Bug #1: Can't print recipes)", show_detail(detail, true) | |||
|
235 | assert_match %r{<strong>Precedes</strong> deleted \(<del><i><a href="/issues/1" class=".+">Bug #1</a>: Can't print recipes</i></del>\)}, | |||
|
236 | show_detail(detail, false) | |||
|
237 | non_existed_issue_number = 9999 | |||
|
238 | assert_nil Issue.find_by_id(non_existed_issue_number) | |||
|
239 | detail = JournalDetail.new(:property => 'relation', | |||
|
240 | :prop_key => 'label_precedes', | |||
|
241 | :old_value => non_existed_issue_number) | |||
|
242 | assert_equal "Precedes deleted (Issue 9999)", show_detail(detail, true) | |||
|
243 | assert_equal "<strong>Precedes</strong> deleted (<del><i>Issue 9999</i></del>)", show_detail(detail, false) | |||
|
244 | end | |||
213 | end |
|
245 | end |
@@ -1,170 +1,215 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2013 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2013 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | require File.expand_path('../../test_helper', __FILE__) |
|
18 | require File.expand_path('../../test_helper', __FILE__) | |
19 |
|
19 | |||
20 | class IssueRelationTest < ActiveSupport::TestCase |
|
20 | class IssueRelationTest < ActiveSupport::TestCase | |
21 | fixtures :projects, |
|
21 | fixtures :projects, | |
22 | :users, |
|
22 | :users, | |
23 | :roles, |
|
23 | :roles, | |
24 | :members, |
|
24 | :members, | |
25 | :member_roles, |
|
25 | :member_roles, | |
26 | :issues, |
|
26 | :issues, | |
27 | :issue_statuses, |
|
27 | :issue_statuses, | |
28 | :issue_relations, |
|
28 | :issue_relations, | |
29 | :enabled_modules, |
|
29 | :enabled_modules, | |
30 | :enumerations, |
|
30 | :enumerations, | |
31 | :trackers |
|
31 | :trackers | |
32 |
|
32 | |||
33 | include Redmine::I18n |
|
33 | include Redmine::I18n | |
34 |
|
34 | |||
35 | def test_create |
|
35 | def test_create | |
36 | from = Issue.find(1) |
|
36 | from = Issue.find(1) | |
37 | to = Issue.find(2) |
|
37 | to = Issue.find(2) | |
38 |
|
38 | |||
39 | relation = IssueRelation.new :issue_from => from, :issue_to => to, |
|
39 | relation = IssueRelation.new :issue_from => from, :issue_to => to, | |
40 | :relation_type => IssueRelation::TYPE_PRECEDES |
|
40 | :relation_type => IssueRelation::TYPE_PRECEDES | |
41 | assert relation.save |
|
41 | assert relation.save | |
42 | relation.reload |
|
42 | relation.reload | |
43 | assert_equal IssueRelation::TYPE_PRECEDES, relation.relation_type |
|
43 | assert_equal IssueRelation::TYPE_PRECEDES, relation.relation_type | |
44 | assert_equal from, relation.issue_from |
|
44 | assert_equal from, relation.issue_from | |
45 | assert_equal to, relation.issue_to |
|
45 | assert_equal to, relation.issue_to | |
46 | end |
|
46 | end | |
47 |
|
47 | |||
48 | def test_create_minimum |
|
48 | def test_create_minimum | |
49 | relation = IssueRelation.new :issue_from => Issue.find(1), :issue_to => Issue.find(2) |
|
49 | relation = IssueRelation.new :issue_from => Issue.find(1), :issue_to => Issue.find(2) | |
50 | assert relation.save |
|
50 | assert relation.save | |
51 | assert_equal IssueRelation::TYPE_RELATES, relation.relation_type |
|
51 | assert_equal IssueRelation::TYPE_RELATES, relation.relation_type | |
52 | end |
|
52 | end | |
53 |
|
53 | |||
54 | def test_follows_relation_should_be_reversed |
|
54 | def test_follows_relation_should_be_reversed | |
55 | from = Issue.find(1) |
|
55 | from = Issue.find(1) | |
56 | to = Issue.find(2) |
|
56 | to = Issue.find(2) | |
57 |
|
57 | |||
58 | relation = IssueRelation.new :issue_from => from, :issue_to => to, |
|
58 | relation = IssueRelation.new :issue_from => from, :issue_to => to, | |
59 | :relation_type => IssueRelation::TYPE_FOLLOWS |
|
59 | :relation_type => IssueRelation::TYPE_FOLLOWS | |
60 | assert relation.save |
|
60 | assert relation.save | |
61 | relation.reload |
|
61 | relation.reload | |
62 | assert_equal IssueRelation::TYPE_PRECEDES, relation.relation_type |
|
62 | assert_equal IssueRelation::TYPE_PRECEDES, relation.relation_type | |
63 | assert_equal to, relation.issue_from |
|
63 | assert_equal to, relation.issue_from | |
64 | assert_equal from, relation.issue_to |
|
64 | assert_equal from, relation.issue_to | |
65 | end |
|
65 | end | |
66 |
|
66 | |||
67 | def test_follows_relation_should_not_be_reversed_if_validation_fails |
|
67 | def test_follows_relation_should_not_be_reversed_if_validation_fails | |
68 | from = Issue.find(1) |
|
68 | from = Issue.find(1) | |
69 | to = Issue.find(2) |
|
69 | to = Issue.find(2) | |
70 |
|
70 | |||
71 | relation = IssueRelation.new :issue_from => from, :issue_to => to, |
|
71 | relation = IssueRelation.new :issue_from => from, :issue_to => to, | |
72 | :relation_type => IssueRelation::TYPE_FOLLOWS, |
|
72 | :relation_type => IssueRelation::TYPE_FOLLOWS, | |
73 | :delay => 'xx' |
|
73 | :delay => 'xx' | |
74 | assert !relation.save |
|
74 | assert !relation.save | |
75 | assert_equal IssueRelation::TYPE_FOLLOWS, relation.relation_type |
|
75 | assert_equal IssueRelation::TYPE_FOLLOWS, relation.relation_type | |
76 | assert_equal from, relation.issue_from |
|
76 | assert_equal from, relation.issue_from | |
77 | assert_equal to, relation.issue_to |
|
77 | assert_equal to, relation.issue_to | |
78 | end |
|
78 | end | |
79 |
|
79 | |||
80 | def test_relation_type_for |
|
80 | def test_relation_type_for | |
81 | from = Issue.find(1) |
|
81 | from = Issue.find(1) | |
82 | to = Issue.find(2) |
|
82 | to = Issue.find(2) | |
83 |
|
83 | |||
84 | relation = IssueRelation.new :issue_from => from, :issue_to => to, |
|
84 | relation = IssueRelation.new :issue_from => from, :issue_to => to, | |
85 | :relation_type => IssueRelation::TYPE_PRECEDES |
|
85 | :relation_type => IssueRelation::TYPE_PRECEDES | |
86 | assert_equal IssueRelation::TYPE_PRECEDES, relation.relation_type_for(from) |
|
86 | assert_equal IssueRelation::TYPE_PRECEDES, relation.relation_type_for(from) | |
87 | assert_equal IssueRelation::TYPE_FOLLOWS, relation.relation_type_for(to) |
|
87 | assert_equal IssueRelation::TYPE_FOLLOWS, relation.relation_type_for(to) | |
88 | end |
|
88 | end | |
89 |
|
89 | |||
90 | def test_set_issue_to_dates_without_issue_to |
|
90 | def test_set_issue_to_dates_without_issue_to | |
91 | r = IssueRelation.new(:issue_from => Issue.new(:start_date => Date.today), |
|
91 | r = IssueRelation.new(:issue_from => Issue.new(:start_date => Date.today), | |
92 | :relation_type => IssueRelation::TYPE_PRECEDES, |
|
92 | :relation_type => IssueRelation::TYPE_PRECEDES, | |
93 | :delay => 1) |
|
93 | :delay => 1) | |
94 | assert_nil r.set_issue_to_dates |
|
94 | assert_nil r.set_issue_to_dates | |
95 | end |
|
95 | end | |
96 |
|
96 | |||
97 | def test_set_issue_to_dates_without_issues |
|
97 | def test_set_issue_to_dates_without_issues | |
98 | r = IssueRelation.new(:relation_type => IssueRelation::TYPE_PRECEDES, :delay => 1) |
|
98 | r = IssueRelation.new(:relation_type => IssueRelation::TYPE_PRECEDES, :delay => 1) | |
99 | assert_nil r.set_issue_to_dates |
|
99 | assert_nil r.set_issue_to_dates | |
100 | end |
|
100 | end | |
101 |
|
101 | |||
102 | def test_validates_circular_dependency |
|
102 | def test_validates_circular_dependency | |
103 | IssueRelation.delete_all |
|
103 | IssueRelation.delete_all | |
104 | assert IssueRelation.create!( |
|
104 | assert IssueRelation.create!( | |
105 | :issue_from => Issue.find(1), :issue_to => Issue.find(2), |
|
105 | :issue_from => Issue.find(1), :issue_to => Issue.find(2), | |
106 | :relation_type => IssueRelation::TYPE_PRECEDES |
|
106 | :relation_type => IssueRelation::TYPE_PRECEDES | |
107 | ) |
|
107 | ) | |
108 | assert IssueRelation.create!( |
|
108 | assert IssueRelation.create!( | |
109 | :issue_from => Issue.find(2), :issue_to => Issue.find(3), |
|
109 | :issue_from => Issue.find(2), :issue_to => Issue.find(3), | |
110 | :relation_type => IssueRelation::TYPE_PRECEDES |
|
110 | :relation_type => IssueRelation::TYPE_PRECEDES | |
111 | ) |
|
111 | ) | |
112 | r = IssueRelation.new( |
|
112 | r = IssueRelation.new( | |
113 | :issue_from => Issue.find(3), :issue_to => Issue.find(1), |
|
113 | :issue_from => Issue.find(3), :issue_to => Issue.find(1), | |
114 | :relation_type => IssueRelation::TYPE_PRECEDES |
|
114 | :relation_type => IssueRelation::TYPE_PRECEDES | |
115 | ) |
|
115 | ) | |
116 | assert !r.save |
|
116 | assert !r.save | |
117 | assert_not_nil r.errors[:base] |
|
117 | assert_not_nil r.errors[:base] | |
118 | end |
|
118 | end | |
119 |
|
119 | |||
120 | def test_validates_circular_dependency_of_subtask |
|
120 | def test_validates_circular_dependency_of_subtask | |
121 | set_language_if_valid 'en' |
|
121 | set_language_if_valid 'en' | |
122 | issue1 = Issue.generate! |
|
122 | issue1 = Issue.generate! | |
123 | issue2 = Issue.generate! |
|
123 | issue2 = Issue.generate! | |
124 | IssueRelation.create!( |
|
124 | IssueRelation.create!( | |
125 | :issue_from => issue1, :issue_to => issue2, |
|
125 | :issue_from => issue1, :issue_to => issue2, | |
126 | :relation_type => IssueRelation::TYPE_PRECEDES |
|
126 | :relation_type => IssueRelation::TYPE_PRECEDES | |
127 | ) |
|
127 | ) | |
128 | child = Issue.generate!(:parent_issue_id => issue2.id) |
|
128 | child = Issue.generate!(:parent_issue_id => issue2.id) | |
129 | issue1.reload |
|
129 | issue1.reload | |
130 | child.reload |
|
130 | child.reload | |
131 |
|
131 | |||
132 | r = IssueRelation.new( |
|
132 | r = IssueRelation.new( | |
133 | :issue_from => child, :issue_to => issue1, |
|
133 | :issue_from => child, :issue_to => issue1, | |
134 | :relation_type => IssueRelation::TYPE_PRECEDES |
|
134 | :relation_type => IssueRelation::TYPE_PRECEDES | |
135 | ) |
|
135 | ) | |
136 | assert !r.save |
|
136 | assert !r.save | |
137 | assert_include 'This relation would create a circular dependency', r.errors.full_messages |
|
137 | assert_include 'This relation would create a circular dependency', r.errors.full_messages | |
138 | end |
|
138 | end | |
139 |
|
139 | |||
140 | def test_subtasks_should_allow_precedes_relation |
|
140 | def test_subtasks_should_allow_precedes_relation | |
141 | parent = Issue.generate! |
|
141 | parent = Issue.generate! | |
142 | child1 = Issue.generate!(:parent_issue_id => parent.id) |
|
142 | child1 = Issue.generate!(:parent_issue_id => parent.id) | |
143 | child2 = Issue.generate!(:parent_issue_id => parent.id) |
|
143 | child2 = Issue.generate!(:parent_issue_id => parent.id) | |
144 |
|
144 | |||
145 | r = IssueRelation.new( |
|
145 | r = IssueRelation.new( | |
146 | :issue_from => child1, :issue_to => child2, |
|
146 | :issue_from => child1, :issue_to => child2, | |
147 | :relation_type => IssueRelation::TYPE_PRECEDES |
|
147 | :relation_type => IssueRelation::TYPE_PRECEDES | |
148 | ) |
|
148 | ) | |
149 | assert r.valid? |
|
149 | assert r.valid? | |
150 | assert r.save |
|
150 | assert r.save | |
151 | end |
|
151 | end | |
152 |
|
152 | |||
153 | def test_validates_circular_dependency_on_reverse_relations |
|
153 | def test_validates_circular_dependency_on_reverse_relations | |
154 | IssueRelation.delete_all |
|
154 | IssueRelation.delete_all | |
155 | assert IssueRelation.create!( |
|
155 | assert IssueRelation.create!( | |
156 | :issue_from => Issue.find(1), :issue_to => Issue.find(3), |
|
156 | :issue_from => Issue.find(1), :issue_to => Issue.find(3), | |
157 | :relation_type => IssueRelation::TYPE_BLOCKS |
|
157 | :relation_type => IssueRelation::TYPE_BLOCKS | |
158 | ) |
|
158 | ) | |
159 | assert IssueRelation.create!( |
|
159 | assert IssueRelation.create!( | |
160 | :issue_from => Issue.find(1), :issue_to => Issue.find(2), |
|
160 | :issue_from => Issue.find(1), :issue_to => Issue.find(2), | |
161 | :relation_type => IssueRelation::TYPE_BLOCKED |
|
161 | :relation_type => IssueRelation::TYPE_BLOCKED | |
162 | ) |
|
162 | ) | |
163 | r = IssueRelation.new( |
|
163 | r = IssueRelation.new( | |
164 | :issue_from => Issue.find(2), :issue_to => Issue.find(1), |
|
164 | :issue_from => Issue.find(2), :issue_to => Issue.find(1), | |
165 | :relation_type => IssueRelation::TYPE_BLOCKED |
|
165 | :relation_type => IssueRelation::TYPE_BLOCKED | |
166 | ) |
|
166 | ) | |
167 | assert !r.save |
|
167 | assert !r.save | |
168 | assert_not_nil r.errors[:base] |
|
168 | assert_not_nil r.errors[:base] | |
169 | end |
|
169 | end | |
|
170 | ||||
|
171 | def test_create_should_make_journal_entry | |||
|
172 | from = Issue.find(1) | |||
|
173 | to = Issue.find(2) | |||
|
174 | from_journals = from.journals.size | |||
|
175 | to_journals = to.journals.size | |||
|
176 | relation = IssueRelation.new(:issue_from => from, :issue_to => to, | |||
|
177 | :relation_type => IssueRelation::TYPE_PRECEDES) | |||
|
178 | assert relation.save | |||
|
179 | from.reload | |||
|
180 | to.reload | |||
|
181 | relation.reload | |||
|
182 | assert_equal from.journals.size, (from_journals + 1) | |||
|
183 | assert_equal to.journals.size, (to_journals + 1) | |||
|
184 | assert_equal 'relation', from.journals.last.details.last.property | |||
|
185 | assert_equal 'label_precedes', from.journals.last.details.last.prop_key | |||
|
186 | assert_equal '2', from.journals.last.details.last.value | |||
|
187 | assert_nil from.journals.last.details.last.old_value | |||
|
188 | assert_equal 'relation', to.journals.last.details.last.property | |||
|
189 | assert_equal 'label_follows', to.journals.last.details.last.prop_key | |||
|
190 | assert_equal '1', to.journals.last.details.last.value | |||
|
191 | assert_nil to.journals.last.details.last.old_value | |||
|
192 | end | |||
|
193 | ||||
|
194 | def test_delete_should_make_journal_entry | |||
|
195 | relation = IssueRelation.find(1) | |||
|
196 | id = relation.id | |||
|
197 | from = relation.issue_from | |||
|
198 | to = relation.issue_to | |||
|
199 | from_journals = from.journals.size | |||
|
200 | to_journals = to.journals.size | |||
|
201 | assert relation.destroy | |||
|
202 | from.reload | |||
|
203 | to.reload | |||
|
204 | assert_equal from.journals.size, (from_journals + 1) | |||
|
205 | assert_equal to.journals.size, (to_journals + 1) | |||
|
206 | assert_equal 'relation', from.journals.last.details.last.property | |||
|
207 | assert_equal 'label_blocks', from.journals.last.details.last.prop_key | |||
|
208 | assert_equal '9', from.journals.last.details.last.old_value | |||
|
209 | assert_nil from.journals.last.details.last.value | |||
|
210 | assert_equal 'relation', to.journals.last.details.last.property | |||
|
211 | assert_equal 'label_blocked_by', to.journals.last.details.last.prop_key | |||
|
212 | assert_equal '10', to.journals.last.details.last.old_value | |||
|
213 | assert_nil to.journals.last.details.last.value | |||
|
214 | end | |||
170 | end |
|
215 | end |
General Comments 0
You need to be logged in to leave comments.
Login now