@@ -1,396 +1,396 | |||
|
1 | 1 | # encoding: utf-8 |
|
2 | 2 | # |
|
3 | 3 | # Redmine - project management software |
|
4 | 4 | # Copyright (C) 2006-2012 Jean-Philippe Lang |
|
5 | 5 | # |
|
6 | 6 | # This program is free software; you can redistribute it and/or |
|
7 | 7 | # modify it under the terms of the GNU General Public License |
|
8 | 8 | # as published by the Free Software Foundation; either version 2 |
|
9 | 9 | # of the License, or (at your option) any later version. |
|
10 | 10 | # |
|
11 | 11 | # This program is distributed in the hope that it will be useful, |
|
12 | 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 | 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 | 14 | # GNU General Public License for more details. |
|
15 | 15 | # |
|
16 | 16 | # You should have received a copy of the GNU General Public License |
|
17 | 17 | # along with this program; if not, write to the Free Software |
|
18 | 18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
19 | 19 | |
|
20 | 20 | module IssuesHelper |
|
21 | 21 | include ApplicationHelper |
|
22 | 22 | |
|
23 | 23 | def issue_list(issues, &block) |
|
24 | 24 | ancestors = [] |
|
25 | 25 | issues.each do |issue| |
|
26 | 26 | while (ancestors.any? && !issue.is_descendant_of?(ancestors.last)) |
|
27 | 27 | ancestors.pop |
|
28 | 28 | end |
|
29 | 29 | yield issue, ancestors.size |
|
30 | 30 | ancestors << issue unless issue.leaf? |
|
31 | 31 | end |
|
32 | 32 | end |
|
33 | 33 | |
|
34 | 34 | # Renders a HTML/CSS tooltip |
|
35 | 35 | # |
|
36 | 36 | # To use, a trigger div is needed. This is a div with the class of "tooltip" |
|
37 | 37 | # that contains this method wrapped in a span with the class of "tip" |
|
38 | 38 | # |
|
39 | 39 | # <div class="tooltip"><%= link_to_issue(issue) %> |
|
40 | 40 | # <span class="tip"><%= render_issue_tooltip(issue) %></span> |
|
41 | 41 | # </div> |
|
42 | 42 | # |
|
43 | 43 | def render_issue_tooltip(issue) |
|
44 | 44 | @cached_label_status ||= l(:field_status) |
|
45 | 45 | @cached_label_start_date ||= l(:field_start_date) |
|
46 | 46 | @cached_label_due_date ||= l(:field_due_date) |
|
47 | 47 | @cached_label_assigned_to ||= l(:field_assigned_to) |
|
48 | 48 | @cached_label_priority ||= l(:field_priority) |
|
49 | 49 | @cached_label_project ||= l(:field_project) |
|
50 | 50 | |
|
51 | 51 | link_to_issue(issue) + "<br /><br />".html_safe + |
|
52 | 52 | "<strong>#{@cached_label_project}</strong>: #{link_to_project(issue.project)}<br />".html_safe + |
|
53 | 53 | "<strong>#{@cached_label_status}</strong>: #{h(issue.status.name)}<br />".html_safe + |
|
54 | 54 | "<strong>#{@cached_label_start_date}</strong>: #{format_date(issue.start_date)}<br />".html_safe + |
|
55 | 55 | "<strong>#{@cached_label_due_date}</strong>: #{format_date(issue.due_date)}<br />".html_safe + |
|
56 | 56 | "<strong>#{@cached_label_assigned_to}</strong>: #{h(issue.assigned_to)}<br />".html_safe + |
|
57 | 57 | "<strong>#{@cached_label_priority}</strong>: #{h(issue.priority.name)}".html_safe |
|
58 | 58 | end |
|
59 | 59 | |
|
60 | 60 | def issue_heading(issue) |
|
61 | 61 | h("#{issue.tracker} ##{issue.id}") |
|
62 | 62 | end |
|
63 | 63 | |
|
64 | 64 | def render_issue_subject_with_tree(issue) |
|
65 | 65 | s = '' |
|
66 | 66 | ancestors = issue.root? ? [] : issue.ancestors.visible.all |
|
67 | 67 | ancestors.each do |ancestor| |
|
68 | 68 | s << '<div>' + content_tag('p', link_to_issue(ancestor)) |
|
69 | 69 | end |
|
70 | 70 | s << '<div>' |
|
71 | 71 | subject = h(issue.subject) |
|
72 | 72 | if issue.is_private? |
|
73 | 73 | subject = content_tag('span', l(:field_is_private), :class => 'private') + ' ' + subject |
|
74 | 74 | end |
|
75 | 75 | s << content_tag('h3', subject) |
|
76 | 76 | s << '</div>' * (ancestors.size + 1) |
|
77 | 77 | s.html_safe |
|
78 | 78 | end |
|
79 | 79 | |
|
80 | 80 | def render_descendants_tree(issue) |
|
81 | 81 | s = '<form><table class="list issues">' |
|
82 | 82 | issue_list(issue.descendants.visible.sort_by(&:lft)) do |child, level| |
|
83 | 83 | s << content_tag('tr', |
|
84 | 84 | content_tag('td', check_box_tag("ids[]", child.id, false, :id => nil), :class => 'checkbox') + |
|
85 | 85 | content_tag('td', link_to_issue(child, :truncate => 60), :class => 'subject') + |
|
86 | 86 | content_tag('td', h(child.status)) + |
|
87 | 87 | content_tag('td', link_to_user(child.assigned_to)) + |
|
88 | 88 | content_tag('td', progress_bar(child.done_ratio, :width => '80px')), |
|
89 | 89 | :class => "issue issue-#{child.id} hascontextmenu #{level > 0 ? "idnt idnt-#{level}" : nil}") |
|
90 | 90 | end |
|
91 | 91 | s << '</table></form>' |
|
92 | 92 | s.html_safe |
|
93 | 93 | end |
|
94 | 94 | |
|
95 | 95 | class IssueFieldsRows |
|
96 | 96 | include ActionView::Helpers::TagHelper |
|
97 | 97 | |
|
98 | 98 | def initialize |
|
99 | 99 | @left = [] |
|
100 | 100 | @right = [] |
|
101 | 101 | end |
|
102 | 102 | |
|
103 | 103 | def left(*args) |
|
104 | 104 | args.any? ? @left << cells(*args) : @left |
|
105 | 105 | end |
|
106 | 106 | |
|
107 | 107 | def right(*args) |
|
108 | 108 | args.any? ? @right << cells(*args) : @right |
|
109 | 109 | end |
|
110 | 110 | |
|
111 | 111 | def size |
|
112 | 112 | @left.size > @right.size ? @left.size : @right.size |
|
113 | 113 | end |
|
114 | 114 | |
|
115 | 115 | def to_html |
|
116 | 116 | html = ''.html_safe |
|
117 | 117 | blank = content_tag('th', '') + content_tag('td', '') |
|
118 | 118 | size.times do |i| |
|
119 | 119 | left = @left[i] || blank |
|
120 | 120 | right = @right[i] || blank |
|
121 | 121 | html << content_tag('tr', left + right) |
|
122 | 122 | end |
|
123 | 123 | html |
|
124 | 124 | end |
|
125 | 125 | |
|
126 | 126 | def cells(label, text, options={}) |
|
127 | 127 | content_tag('th', "#{label}:", options) + content_tag('td', text, options) |
|
128 | 128 | end |
|
129 | 129 | end |
|
130 | 130 | |
|
131 | 131 | def issue_fields_rows |
|
132 | 132 | r = IssueFieldsRows.new |
|
133 | 133 | yield r |
|
134 | 134 | r.to_html |
|
135 | 135 | end |
|
136 | 136 | |
|
137 | 137 | def render_custom_fields_rows(issue) |
|
138 | 138 | return if issue.custom_field_values.empty? |
|
139 | 139 | ordered_values = [] |
|
140 | 140 | half = (issue.custom_field_values.size / 2.0).ceil |
|
141 | 141 | half.times do |i| |
|
142 | 142 | ordered_values << issue.custom_field_values[i] |
|
143 | 143 | ordered_values << issue.custom_field_values[i + half] |
|
144 | 144 | end |
|
145 | 145 | s = "<tr>\n" |
|
146 | 146 | n = 0 |
|
147 | 147 | ordered_values.compact.each do |value| |
|
148 | 148 | s << "</tr>\n<tr>\n" if n > 0 && (n % 2) == 0 |
|
149 | 149 | s << "\t<th>#{ h(value.custom_field.name) }:</th><td>#{ simple_format_without_paragraph(h(show_value(value))) }</td>\n" |
|
150 | 150 | n += 1 |
|
151 | 151 | end |
|
152 | 152 | s << "</tr>\n" |
|
153 | 153 | s.html_safe |
|
154 | 154 | end |
|
155 | 155 | |
|
156 | 156 | def issues_destroy_confirmation_message(issues) |
|
157 | 157 | issues = [issues] unless issues.is_a?(Array) |
|
158 | 158 | message = l(:text_issues_destroy_confirmation) |
|
159 | 159 | descendant_count = issues.inject(0) {|memo, i| memo += (i.right - i.left - 1)/2} |
|
160 | 160 | if descendant_count > 0 |
|
161 | 161 | issues.each do |issue| |
|
162 | 162 | next if issue.root? |
|
163 | 163 | issues.each do |other_issue| |
|
164 | 164 | descendant_count -= 1 if issue.is_descendant_of?(other_issue) |
|
165 | 165 | end |
|
166 | 166 | end |
|
167 | 167 | if descendant_count > 0 |
|
168 | 168 | message << "\n" + l(:text_issues_destroy_descendants_confirmation, :count => descendant_count) |
|
169 | 169 | end |
|
170 | 170 | end |
|
171 | 171 | message |
|
172 | 172 | end |
|
173 | 173 | |
|
174 | 174 | def sidebar_queries |
|
175 | 175 | unless @sidebar_queries |
|
176 | 176 | @sidebar_queries = Query.visible.all( |
|
177 | 177 | :order => "#{Query.table_name}.name ASC", |
|
178 | 178 | # Project specific queries and global queries |
|
179 | 179 | :conditions => (@project.nil? ? ["project_id IS NULL"] : ["project_id IS NULL OR project_id = ?", @project.id]) |
|
180 | 180 | ) |
|
181 | 181 | end |
|
182 | 182 | @sidebar_queries |
|
183 | 183 | end |
|
184 | 184 | |
|
185 | 185 | def query_links(title, queries) |
|
186 | 186 | # links to #index on issues/show |
|
187 | 187 | url_params = controller_name == 'issues' ? {:controller => 'issues', :action => 'index', :project_id => @project} : params |
|
188 | 188 | |
|
189 | 189 | content_tag('h3', h(title)) + |
|
190 | 190 | queries.collect {|query| |
|
191 | 191 | css = 'query' |
|
192 | 192 | css << ' selected' if query == @query |
|
193 | 193 | link_to(h(query.name), url_params.merge(:query_id => query), :class => css) |
|
194 | 194 | }.join('<br />').html_safe |
|
195 | 195 | end |
|
196 | 196 | |
|
197 | 197 | def render_sidebar_queries |
|
198 | 198 | out = ''.html_safe |
|
199 | 199 | queries = sidebar_queries.select {|q| !q.is_public?} |
|
200 | 200 | out << query_links(l(:label_my_queries), queries) if queries.any? |
|
201 | 201 | queries = sidebar_queries.select {|q| q.is_public?} |
|
202 | 202 | out << query_links(l(:label_query_plural), queries) if queries.any? |
|
203 | 203 | out |
|
204 | 204 | end |
|
205 | 205 | |
|
206 | 206 | # Returns the textual representation of a journal details |
|
207 | 207 | # as an array of strings |
|
208 | 208 | def details_to_strings(details, no_html=false, options={}) |
|
209 | 209 | options[:only_path] = (options[:only_path] == false ? false : true) |
|
210 | 210 | strings = [] |
|
211 | 211 | values_by_field = {} |
|
212 | 212 | details.each do |detail| |
|
213 | 213 | if detail.property == 'cf' |
|
214 | 214 | field_id = detail.prop_key |
|
215 | 215 | field = CustomField.find_by_id(field_id) |
|
216 | 216 | if field && field.multiple? |
|
217 | 217 | values_by_field[field_id] ||= {:added => [], :deleted => []} |
|
218 | 218 | if detail.old_value |
|
219 | 219 | values_by_field[field_id][:deleted] << detail.old_value |
|
220 | 220 | end |
|
221 | 221 | if detail.value |
|
222 | 222 | values_by_field[field_id][:added] << detail.value |
|
223 | 223 | end |
|
224 | 224 | next |
|
225 | 225 | end |
|
226 | 226 | end |
|
227 | 227 | strings << show_detail(detail, no_html, options) |
|
228 | 228 | end |
|
229 | 229 | values_by_field.each do |field_id, changes| |
|
230 | 230 | detail = JournalDetail.new(:property => 'cf', :prop_key => field_id) |
|
231 | 231 | if changes[:added].any? |
|
232 | 232 | detail.value = changes[:added] |
|
233 | 233 | strings << show_detail(detail, no_html, options) |
|
234 | 234 | elsif changes[:deleted].any? |
|
235 | 235 | detail.old_value = changes[:deleted] |
|
236 | 236 | strings << show_detail(detail, no_html, options) |
|
237 | 237 | end |
|
238 | 238 | end |
|
239 | 239 | strings |
|
240 | 240 | end |
|
241 | 241 | |
|
242 | 242 | # Returns the textual representation of a single journal detail |
|
243 | 243 | def show_detail(detail, no_html=false, options={}) |
|
244 | 244 | multiple = false |
|
245 | 245 | case detail.property |
|
246 | 246 | when 'attr' |
|
247 | 247 | field = detail.prop_key.to_s.gsub(/\_id$/, "") |
|
248 | 248 | label = l(("field_" + field).to_sym) |
|
249 | 249 | case detail.prop_key |
|
250 | 250 | when 'due_date', 'start_date' |
|
251 | 251 | value = format_date(detail.value.to_date) if detail.value |
|
252 | 252 | old_value = format_date(detail.old_value.to_date) if detail.old_value |
|
253 | 253 | |
|
254 | 254 | when 'project_id', 'status_id', 'tracker_id', 'assigned_to_id', |
|
255 | 255 | 'priority_id', 'category_id', 'fixed_version_id' |
|
256 | 256 | value = find_name_by_reflection(field, detail.value) |
|
257 | 257 | old_value = find_name_by_reflection(field, detail.old_value) |
|
258 | 258 | |
|
259 | 259 | when 'estimated_hours' |
|
260 | 260 | value = "%0.02f" % detail.value.to_f unless detail.value.blank? |
|
261 | 261 | old_value = "%0.02f" % detail.old_value.to_f unless detail.old_value.blank? |
|
262 | 262 | |
|
263 | 263 | when 'parent_id' |
|
264 | 264 | label = l(:field_parent_issue) |
|
265 | 265 | value = "##{detail.value}" unless detail.value.blank? |
|
266 | 266 | old_value = "##{detail.old_value}" unless detail.old_value.blank? |
|
267 | 267 | |
|
268 | 268 | when 'is_private' |
|
269 | 269 | value = l(detail.value == "0" ? :general_text_No : :general_text_Yes) unless detail.value.blank? |
|
270 | 270 | old_value = l(detail.old_value == "0" ? :general_text_No : :general_text_Yes) unless detail.old_value.blank? |
|
271 | 271 | end |
|
272 | 272 | when 'cf' |
|
273 | 273 | custom_field = CustomField.find_by_id(detail.prop_key) |
|
274 | 274 | if custom_field |
|
275 | 275 | multiple = custom_field.multiple? |
|
276 | 276 | label = custom_field.name |
|
277 | 277 | value = format_value(detail.value, custom_field.field_format) if detail.value |
|
278 | 278 | old_value = format_value(detail.old_value, custom_field.field_format) if detail.old_value |
|
279 | 279 | end |
|
280 | 280 | when 'attachment' |
|
281 | 281 | label = l(:label_attachment) |
|
282 | 282 | end |
|
283 | 283 | call_hook(:helper_issues_show_detail_after_setting, |
|
284 | 284 | {:detail => detail, :label => label, :value => value, :old_value => old_value }) |
|
285 | 285 | |
|
286 | 286 | label ||= detail.prop_key |
|
287 | 287 | value ||= detail.value |
|
288 | 288 | old_value ||= detail.old_value |
|
289 | 289 | |
|
290 | 290 | unless no_html |
|
291 | 291 | label = content_tag('strong', label) |
|
292 | 292 | old_value = content_tag("i", h(old_value)) if detail.old_value |
|
293 |
old_value = content_tag(" |
|
|
293 | old_value = content_tag("del", old_value) if detail.old_value and detail.value.blank? | |
|
294 | 294 | if detail.property == 'attachment' && !value.blank? && atta = Attachment.find_by_id(detail.prop_key) |
|
295 | 295 | # Link to the attachment if it has not been removed |
|
296 | 296 | value = link_to_attachment(atta, :download => true, :only_path => options[:only_path]) |
|
297 | 297 | if options[:only_path] != false && atta.is_text? |
|
298 | 298 | value += link_to( |
|
299 | 299 | image_tag('magnifier.png'), |
|
300 | 300 | :controller => 'attachments', :action => 'show', |
|
301 | 301 | :id => atta, :filename => atta.filename |
|
302 | 302 | ) |
|
303 | 303 | end |
|
304 | 304 | else |
|
305 | 305 | value = content_tag("i", h(value)) if value |
|
306 | 306 | end |
|
307 | 307 | end |
|
308 | 308 | |
|
309 | 309 | if detail.property == 'attr' && detail.prop_key == 'description' |
|
310 | 310 | s = l(:text_journal_changed_no_detail, :label => label) |
|
311 | 311 | unless no_html |
|
312 | 312 | diff_link = link_to 'diff', |
|
313 | 313 | {:controller => 'journals', :action => 'diff', :id => detail.journal_id, |
|
314 | 314 | :detail_id => detail.id, :only_path => options[:only_path]}, |
|
315 | 315 | :title => l(:label_view_diff) |
|
316 | 316 | s << " (#{ diff_link })" |
|
317 | 317 | end |
|
318 | 318 | s.html_safe |
|
319 | 319 | elsif detail.value.present? |
|
320 | 320 | case detail.property |
|
321 | 321 | when 'attr', 'cf' |
|
322 | 322 | if detail.old_value.present? |
|
323 | 323 | l(:text_journal_changed, :label => label, :old => old_value, :new => value).html_safe |
|
324 | 324 | elsif multiple |
|
325 | 325 | l(:text_journal_added, :label => label, :value => value).html_safe |
|
326 | 326 | else |
|
327 | 327 | l(:text_journal_set_to, :label => label, :value => value).html_safe |
|
328 | 328 | end |
|
329 | 329 | when 'attachment' |
|
330 | 330 | l(:text_journal_added, :label => label, :value => value).html_safe |
|
331 | 331 | end |
|
332 | 332 | else |
|
333 | 333 | l(:text_journal_deleted, :label => label, :old => old_value).html_safe |
|
334 | 334 | end |
|
335 | 335 | end |
|
336 | 336 | |
|
337 | 337 | # Find the name of an associated record stored in the field attribute |
|
338 | 338 | def find_name_by_reflection(field, id) |
|
339 | 339 | association = Issue.reflect_on_association(field.to_sym) |
|
340 | 340 | if association |
|
341 | 341 | record = association.class_name.constantize.find_by_id(id) |
|
342 | 342 | return record.name if record |
|
343 | 343 | end |
|
344 | 344 | end |
|
345 | 345 | |
|
346 | 346 | # Renders issue children recursively |
|
347 | 347 | def render_api_issue_children(issue, api) |
|
348 | 348 | return if issue.leaf? |
|
349 | 349 | api.array :children do |
|
350 | 350 | issue.children.each do |child| |
|
351 | 351 | api.issue(:id => child.id) do |
|
352 | 352 | api.tracker(:id => child.tracker_id, :name => child.tracker.name) unless child.tracker.nil? |
|
353 | 353 | api.subject child.subject |
|
354 | 354 | render_api_issue_children(child, api) |
|
355 | 355 | end |
|
356 | 356 | end |
|
357 | 357 | end |
|
358 | 358 | end |
|
359 | 359 | |
|
360 | 360 | def issues_to_csv(issues, project, query, options={}) |
|
361 | 361 | decimal_separator = l(:general_csv_decimal_separator) |
|
362 | 362 | encoding = l(:general_csv_encoding) |
|
363 | 363 | columns = (options[:columns] == 'all' ? query.available_columns : query.columns) |
|
364 | 364 | |
|
365 | 365 | export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv| |
|
366 | 366 | # csv header fields |
|
367 | 367 | csv << [ "#" ] + columns.collect {|c| Redmine::CodesetUtil.from_utf8(c.caption.to_s, encoding) } + |
|
368 | 368 | (options[:description] ? [Redmine::CodesetUtil.from_utf8(l(:field_description), encoding)] : []) |
|
369 | 369 | |
|
370 | 370 | # csv lines |
|
371 | 371 | issues.each do |issue| |
|
372 | 372 | col_values = columns.collect do |column| |
|
373 | 373 | s = if column.is_a?(QueryCustomFieldColumn) |
|
374 | 374 | cv = issue.custom_field_values.detect {|v| v.custom_field_id == column.custom_field.id} |
|
375 | 375 | show_value(cv) |
|
376 | 376 | else |
|
377 | 377 | value = column.value(issue) |
|
378 | 378 | if value.is_a?(Date) |
|
379 | 379 | format_date(value) |
|
380 | 380 | elsif value.is_a?(Time) |
|
381 | 381 | format_time(value) |
|
382 | 382 | elsif value.is_a?(Float) |
|
383 | 383 | ("%.2f" % value).gsub('.', decimal_separator) |
|
384 | 384 | else |
|
385 | 385 | value |
|
386 | 386 | end |
|
387 | 387 | end |
|
388 | 388 | s.to_s |
|
389 | 389 | end |
|
390 | 390 | csv << [ issue.id.to_s ] + col_values.collect {|c| Redmine::CodesetUtil.from_utf8(c.to_s, encoding) } + |
|
391 | 391 | (options[:description] ? [Redmine::CodesetUtil.from_utf8(issue.description, encoding)] : []) |
|
392 | 392 | end |
|
393 | 393 | end |
|
394 | 394 | export |
|
395 | 395 | end |
|
396 | 396 | end |
@@ -1,18 +1,18 | |||
|
1 | 1 | <% if defined?(container) && container && container.saved_attachments %> |
|
2 | 2 | <% container.saved_attachments.each_with_index do |attachment, i| %> |
|
3 | 3 | <span class="icon icon-attachment" style="display:block; line-height:1.5em;"> |
|
4 | 4 | <%= h(attachment.filename) %> (<%= number_to_human_size(attachment.filesize) %>) |
|
5 | 5 | <%= hidden_field_tag "attachments[p#{i}][token]", "#{attachment.id}.#{attachment.digest}" %> |
|
6 | 6 | </span> |
|
7 | 7 | <% end %> |
|
8 | 8 | <% end %> |
|
9 | 9 | <span id="attachments_fields"> |
|
10 | 10 | <span> |
|
11 |
<%= file_field_tag 'attachments[1][file]', : |
|
|
11 | <%= file_field_tag 'attachments[1][file]', :id => nil, :class => 'file', | |
|
12 | 12 | :onchange => "checkFileSize(this, #{Setting.attachment_max_size.to_i.kilobytes}, '#{escape_javascript(l(:error_attachment_too_big, :max_size => number_to_human_size(Setting.attachment_max_size.to_i.kilobytes)))}');" -%> |
|
13 | 13 | <%= text_field_tag 'attachments[1][description]', '', :id => nil, :class => 'description', :maxlength => 255, :placeholder => l(:label_optional_description) %> |
|
14 | 14 | <%= link_to_function(image_tag('delete.png'), 'removeFileField(this)', :title => (l(:button_delete))) %> |
|
15 | 15 | </span> |
|
16 | 16 | </span> |
|
17 | 17 | <span class="add_attachment"><%= link_to l(:label_add_another_file), '#', :onclick => 'addFileField(); return false;', :class => 'add_attachment' %> |
|
18 | 18 | (<%= l(:label_max_size) %>: <%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>)</span> |
@@ -1,198 +1,199 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2012 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.expand_path('../../../test_helper', __FILE__) |
|
19 | 19 | |
|
20 | 20 | class IssuesHelperTest < ActionView::TestCase |
|
21 | 21 | include ApplicationHelper |
|
22 | 22 | include IssuesHelper |
|
23 | 23 | include CustomFieldsHelper |
|
24 | 24 | include ERB::Util |
|
25 | 25 | |
|
26 | 26 | fixtures :projects, :trackers, :issue_statuses, :issues, |
|
27 | 27 | :enumerations, :users, :issue_categories, |
|
28 | 28 | :projects_trackers, |
|
29 | 29 | :roles, |
|
30 | 30 | :member_roles, |
|
31 | 31 | :members, |
|
32 | 32 | :enabled_modules, |
|
33 | 33 | :workflows, |
|
34 | 34 | :custom_fields, |
|
35 | :attachments | |
|
35 | :attachments, | |
|
36 | :versions | |
|
36 | 37 | |
|
37 | 38 | def setup |
|
38 | 39 | super |
|
39 | 40 | set_language_if_valid('en') |
|
40 | 41 | User.current = nil |
|
41 | 42 | end |
|
42 | 43 | |
|
43 | 44 | def test_issue_heading |
|
44 | 45 | assert_equal "Bug #1", issue_heading(Issue.find(1)) |
|
45 | 46 | end |
|
46 | 47 | |
|
47 | 48 | def test_issues_destroy_confirmation_message_with_one_root_issue |
|
48 | 49 | assert_equal l(:text_issues_destroy_confirmation), issues_destroy_confirmation_message(Issue.find(1)) |
|
49 | 50 | end |
|
50 | 51 | |
|
51 | 52 | def test_issues_destroy_confirmation_message_with_an_arrayt_of_root_issues |
|
52 | 53 | assert_equal l(:text_issues_destroy_confirmation), issues_destroy_confirmation_message(Issue.find([1, 2])) |
|
53 | 54 | end |
|
54 | 55 | |
|
55 | 56 | def test_issues_destroy_confirmation_message_with_one_parent_issue |
|
56 | 57 | Issue.find(2).update_attribute :parent_issue_id, 1 |
|
57 | 58 | assert_equal l(:text_issues_destroy_confirmation) + "\n" + l(:text_issues_destroy_descendants_confirmation, :count => 1), |
|
58 | 59 | issues_destroy_confirmation_message(Issue.find(1)) |
|
59 | 60 | end |
|
60 | 61 | |
|
61 | 62 | def test_issues_destroy_confirmation_message_with_one_parent_issue_and_its_child |
|
62 | 63 | Issue.find(2).update_attribute :parent_issue_id, 1 |
|
63 | 64 | assert_equal l(:text_issues_destroy_confirmation), issues_destroy_confirmation_message(Issue.find([1, 2])) |
|
64 | 65 | end |
|
65 | 66 | |
|
66 | 67 | context "IssuesHelper#show_detail" do |
|
67 | 68 | context "with no_html" do |
|
68 | 69 | should 'show a changing attribute' do |
|
69 | 70 | @detail = JournalDetail.new(:property => 'attr', :old_value => '40', :value => '100', :prop_key => 'done_ratio') |
|
70 | 71 | assert_equal "% Done changed from 40 to 100", show_detail(@detail, true) |
|
71 | 72 | end |
|
72 | 73 | |
|
73 | 74 | should 'show a new attribute' do |
|
74 | 75 | @detail = JournalDetail.new(:property => 'attr', :old_value => nil, :value => '100', :prop_key => 'done_ratio') |
|
75 | 76 | assert_equal "% Done set to 100", show_detail(@detail, true) |
|
76 | 77 | end |
|
77 | 78 | |
|
78 | 79 | should 'show a deleted attribute' do |
|
79 | 80 | @detail = JournalDetail.new(:property => 'attr', :old_value => '50', :value => nil, :prop_key => 'done_ratio') |
|
80 | 81 | assert_equal "% Done deleted (50)", show_detail(@detail, true) |
|
81 | 82 | end |
|
82 | 83 | end |
|
83 | 84 | |
|
84 | 85 | context "with html" do |
|
85 | 86 | should 'show a changing attribute with HTML highlights' do |
|
86 | 87 | @detail = JournalDetail.new(:property => 'attr', :old_value => '40', :value => '100', :prop_key => 'done_ratio') |
|
87 | 88 | html = show_detail(@detail, false) |
|
88 | 89 | |
|
89 | 90 | assert_include '<strong>% Done</strong>', html |
|
90 | 91 | assert_include '<i>40</i>', html |
|
91 | 92 | assert_include '<i>100</i>', html |
|
92 | 93 | end |
|
93 | 94 | |
|
94 | 95 | should 'show a new attribute with HTML highlights' do |
|
95 | 96 | @detail = JournalDetail.new(:property => 'attr', :old_value => nil, :value => '100', :prop_key => 'done_ratio') |
|
96 | 97 | html = show_detail(@detail, false) |
|
97 | 98 | |
|
98 | 99 | assert_include '<strong>% Done</strong>', html |
|
99 | 100 | assert_include '<i>100</i>', html |
|
100 | 101 | end |
|
101 | 102 | |
|
102 | 103 | should 'show a deleted attribute with HTML highlights' do |
|
103 | 104 | @detail = JournalDetail.new(:property => 'attr', :old_value => '50', :value => nil, :prop_key => 'done_ratio') |
|
104 | 105 | html = show_detail(@detail, false) |
|
105 | 106 | |
|
106 | 107 | assert_include '<strong>% Done</strong>', html |
|
107 |
assert_include '< |
|
|
108 | assert_include '<del><i>50</i></del>', html | |
|
108 | 109 | end |
|
109 | 110 | end |
|
110 | 111 | |
|
111 | 112 | context "with a start_date attribute" do |
|
112 | 113 | should "format the current date" do |
|
113 | 114 | @detail = JournalDetail.new(:property => 'attr', :old_value => '2010-01-01', :value => '2010-01-31', :prop_key => 'start_date') |
|
114 | 115 | assert_match "01/31/2010", show_detail(@detail, true) |
|
115 | 116 | end |
|
116 | 117 | |
|
117 | 118 | should "format the old date" do |
|
118 | 119 | @detail = JournalDetail.new(:property => 'attr', :old_value => '2010-01-01', :value => '2010-01-31', :prop_key => 'start_date') |
|
119 | 120 | assert_match "01/01/2010", show_detail(@detail, true) |
|
120 | 121 | end |
|
121 | 122 | end |
|
122 | 123 | |
|
123 | 124 | context "with a due_date attribute" do |
|
124 | 125 | should "format the current date" do |
|
125 | 126 | @detail = JournalDetail.new(:property => 'attr', :old_value => '2010-01-01', :value => '2010-01-31', :prop_key => 'due_date') |
|
126 | 127 | assert_match "01/31/2010", show_detail(@detail, true) |
|
127 | 128 | end |
|
128 | 129 | |
|
129 | 130 | should "format the old date" do |
|
130 | 131 | @detail = JournalDetail.new(:property => 'attr', :old_value => '2010-01-01', :value => '2010-01-31', :prop_key => 'due_date') |
|
131 | 132 | assert_match "01/01/2010", show_detail(@detail, true) |
|
132 | 133 | end |
|
133 | 134 | end |
|
134 | 135 | |
|
135 | 136 | should "show old and new values with a project attribute" do |
|
136 | 137 | detail = JournalDetail.new(:property => 'attr', :prop_key => 'project_id', :old_value => 1, :value => 2) |
|
137 | 138 | assert_match 'eCookbook', show_detail(detail, true) |
|
138 | 139 | assert_match 'OnlineStore', show_detail(detail, true) |
|
139 | 140 | end |
|
140 | 141 | |
|
141 | 142 | should "show old and new values with a issue status attribute" do |
|
142 | 143 | detail = JournalDetail.new(:property => 'attr', :prop_key => 'status_id', :old_value => 1, :value => 2) |
|
143 | 144 | assert_match 'New', show_detail(detail, true) |
|
144 | 145 | assert_match 'Assigned', show_detail(detail, true) |
|
145 | 146 | end |
|
146 | 147 | |
|
147 | 148 | should "show old and new values with a tracker attribute" do |
|
148 | 149 | detail = JournalDetail.new(:property => 'attr', :prop_key => 'tracker_id', :old_value => 1, :value => 2) |
|
149 | 150 | assert_match 'Bug', show_detail(detail, true) |
|
150 | 151 | assert_match 'Feature request', show_detail(detail, true) |
|
151 | 152 | end |
|
152 | 153 | |
|
153 | 154 | should "show old and new values with a assigned to attribute" do |
|
154 | 155 | detail = JournalDetail.new(:property => 'attr', :prop_key => 'assigned_to_id', :old_value => 1, :value => 2) |
|
155 | 156 | assert_match 'redMine Admin', show_detail(detail, true) |
|
156 | 157 | assert_match 'John Smith', show_detail(detail, true) |
|
157 | 158 | end |
|
158 | 159 | |
|
159 | 160 | should "show old and new values with a priority attribute" do |
|
160 | 161 | detail = JournalDetail.new(:property => 'attr', :prop_key => 'priority_id', :old_value => 4, :value => 5) |
|
161 | 162 | assert_match 'Low', show_detail(detail, true) |
|
162 | 163 | assert_match 'Normal', show_detail(detail, true) |
|
163 | 164 | end |
|
164 | 165 | |
|
165 | 166 | should "show old and new values with a category attribute" do |
|
166 | 167 | detail = JournalDetail.new(:property => 'attr', :prop_key => 'category_id', :old_value => 1, :value => 2) |
|
167 | 168 | assert_match 'Printing', show_detail(detail, true) |
|
168 | 169 | assert_match 'Recipes', show_detail(detail, true) |
|
169 | 170 | end |
|
170 | 171 | |
|
171 | 172 | should "show old and new values with a fixed version attribute" do |
|
172 | 173 | detail = JournalDetail.new(:property => 'attr', :prop_key => 'fixed_version_id', :old_value => 1, :value => 2) |
|
173 | 174 | assert_match '0.1', show_detail(detail, true) |
|
174 | 175 | assert_match '1.0', show_detail(detail, true) |
|
175 | 176 | end |
|
176 | 177 | |
|
177 | 178 | should "show old and new values with a estimated hours attribute" do |
|
178 | 179 | detail = JournalDetail.new(:property => 'attr', :prop_key => 'estimated_hours', :old_value => '5', :value => '6.3') |
|
179 | 180 | assert_match '5.00', show_detail(detail, true) |
|
180 | 181 | assert_match '6.30', show_detail(detail, true) |
|
181 | 182 | end |
|
182 | 183 | |
|
183 | 184 | should "show old and new values with a custom field" do |
|
184 | 185 | detail = JournalDetail.new(:property => 'cf', :prop_key => '1', :old_value => 'MySQL', :value => 'PostgreSQL') |
|
185 | 186 | assert_equal 'Database changed from MySQL to PostgreSQL', show_detail(detail, true) |
|
186 | 187 | end |
|
187 | 188 | |
|
188 | 189 | should "show added file" do |
|
189 | 190 | detail = JournalDetail.new(:property => 'attachment', :prop_key => '1', :old_value => nil, :value => 'error281.txt') |
|
190 | 191 | assert_match 'error281.txt', show_detail(detail, true) |
|
191 | 192 | end |
|
192 | 193 | |
|
193 | 194 | should "show removed file" do |
|
194 | 195 | detail = JournalDetail.new(:property => 'attachment', :prop_key => '1', :old_value => 'error281.txt', :value => nil) |
|
195 | 196 | assert_match 'error281.txt', show_detail(detail, true) |
|
196 | 197 | end |
|
197 | 198 | end |
|
198 | 199 | end |
General Comments 0
You need to be logged in to leave comments.
Login now