##// END OF EJS Templates
Use parent tracker as the default tracker when adding a subtask (#12113)....
Jean-Philippe Lang -
r10451:ef1f14905b71
parent child
Show More
@@ -1,403 +1,407
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, :project => (issue.project_id != ancestor.project_id)))
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 css = "issue issue-#{child.id} hascontextmenu"
84 84 css << " idnt idnt-#{level}" if level > 0
85 85 s << content_tag('tr',
86 86 content_tag('td', check_box_tag("ids[]", child.id, false, :id => nil), :class => 'checkbox') +
87 87 content_tag('td', link_to_issue(child, :truncate => 60, :project => (issue.project_id != child.project_id)), :class => 'subject') +
88 88 content_tag('td', h(child.status)) +
89 89 content_tag('td', link_to_user(child.assigned_to)) +
90 90 content_tag('td', progress_bar(child.done_ratio, :width => '80px')),
91 91 :class => css)
92 92 end
93 93 s << '</table></form>'
94 94 s.html_safe
95 95 end
96 96
97 97 # Returns a link for adding a new subtask to the given issue
98 98 def link_to_new_subtask(issue)
99 link_to(l(:button_add), {:controller => 'issues', :action => 'new', :project_id => issue.project, :issue => {:parent_issue_id => issue}})
99 attrs = {
100 :tracker_id => issue.tracker,
101 :parent_issue_id => issue
102 }
103 link_to(l(:button_add), {:controller => 'issues', :action => 'new', :project_id => issue.project, :issue => attrs})
100 104 end
101 105
102 106 class IssueFieldsRows
103 107 include ActionView::Helpers::TagHelper
104 108
105 109 def initialize
106 110 @left = []
107 111 @right = []
108 112 end
109 113
110 114 def left(*args)
111 115 args.any? ? @left << cells(*args) : @left
112 116 end
113 117
114 118 def right(*args)
115 119 args.any? ? @right << cells(*args) : @right
116 120 end
117 121
118 122 def size
119 123 @left.size > @right.size ? @left.size : @right.size
120 124 end
121 125
122 126 def to_html
123 127 html = ''.html_safe
124 128 blank = content_tag('th', '') + content_tag('td', '')
125 129 size.times do |i|
126 130 left = @left[i] || blank
127 131 right = @right[i] || blank
128 132 html << content_tag('tr', left + right)
129 133 end
130 134 html
131 135 end
132 136
133 137 def cells(label, text, options={})
134 138 content_tag('th', "#{label}:", options) + content_tag('td', text, options)
135 139 end
136 140 end
137 141
138 142 def issue_fields_rows
139 143 r = IssueFieldsRows.new
140 144 yield r
141 145 r.to_html
142 146 end
143 147
144 148 def render_custom_fields_rows(issue)
145 149 return if issue.custom_field_values.empty?
146 150 ordered_values = []
147 151 half = (issue.custom_field_values.size / 2.0).ceil
148 152 half.times do |i|
149 153 ordered_values << issue.custom_field_values[i]
150 154 ordered_values << issue.custom_field_values[i + half]
151 155 end
152 156 s = "<tr>\n"
153 157 n = 0
154 158 ordered_values.compact.each do |value|
155 159 s << "</tr>\n<tr>\n" if n > 0 && (n % 2) == 0
156 160 s << "\t<th>#{ h(value.custom_field.name) }:</th><td>#{ simple_format_without_paragraph(h(show_value(value))) }</td>\n"
157 161 n += 1
158 162 end
159 163 s << "</tr>\n"
160 164 s.html_safe
161 165 end
162 166
163 167 def issues_destroy_confirmation_message(issues)
164 168 issues = [issues] unless issues.is_a?(Array)
165 169 message = l(:text_issues_destroy_confirmation)
166 170 descendant_count = issues.inject(0) {|memo, i| memo += (i.right - i.left - 1)/2}
167 171 if descendant_count > 0
168 172 issues.each do |issue|
169 173 next if issue.root?
170 174 issues.each do |other_issue|
171 175 descendant_count -= 1 if issue.is_descendant_of?(other_issue)
172 176 end
173 177 end
174 178 if descendant_count > 0
175 179 message << "\n" + l(:text_issues_destroy_descendants_confirmation, :count => descendant_count)
176 180 end
177 181 end
178 182 message
179 183 end
180 184
181 185 def sidebar_queries
182 186 unless @sidebar_queries
183 187 @sidebar_queries = Query.visible.all(
184 188 :order => "#{Query.table_name}.name ASC",
185 189 # Project specific queries and global queries
186 190 :conditions => (@project.nil? ? ["project_id IS NULL"] : ["project_id IS NULL OR project_id = ?", @project.id])
187 191 )
188 192 end
189 193 @sidebar_queries
190 194 end
191 195
192 196 def query_links(title, queries)
193 197 # links to #index on issues/show
194 198 url_params = controller_name == 'issues' ? {:controller => 'issues', :action => 'index', :project_id => @project} : params
195 199
196 200 content_tag('h3', h(title)) +
197 201 queries.collect {|query|
198 202 css = 'query'
199 203 css << ' selected' if query == @query
200 204 link_to(h(query.name), url_params.merge(:query_id => query), :class => css)
201 205 }.join('<br />').html_safe
202 206 end
203 207
204 208 def render_sidebar_queries
205 209 out = ''.html_safe
206 210 queries = sidebar_queries.select {|q| !q.is_public?}
207 211 out << query_links(l(:label_my_queries), queries) if queries.any?
208 212 queries = sidebar_queries.select {|q| q.is_public?}
209 213 out << query_links(l(:label_query_plural), queries) if queries.any?
210 214 out
211 215 end
212 216
213 217 # Returns the textual representation of a journal details
214 218 # as an array of strings
215 219 def details_to_strings(details, no_html=false, options={})
216 220 options[:only_path] = (options[:only_path] == false ? false : true)
217 221 strings = []
218 222 values_by_field = {}
219 223 details.each do |detail|
220 224 if detail.property == 'cf'
221 225 field_id = detail.prop_key
222 226 field = CustomField.find_by_id(field_id)
223 227 if field && field.multiple?
224 228 values_by_field[field_id] ||= {:added => [], :deleted => []}
225 229 if detail.old_value
226 230 values_by_field[field_id][:deleted] << detail.old_value
227 231 end
228 232 if detail.value
229 233 values_by_field[field_id][:added] << detail.value
230 234 end
231 235 next
232 236 end
233 237 end
234 238 strings << show_detail(detail, no_html, options)
235 239 end
236 240 values_by_field.each do |field_id, changes|
237 241 detail = JournalDetail.new(:property => 'cf', :prop_key => field_id)
238 242 if changes[:added].any?
239 243 detail.value = changes[:added]
240 244 strings << show_detail(detail, no_html, options)
241 245 elsif changes[:deleted].any?
242 246 detail.old_value = changes[:deleted]
243 247 strings << show_detail(detail, no_html, options)
244 248 end
245 249 end
246 250 strings
247 251 end
248 252
249 253 # Returns the textual representation of a single journal detail
250 254 def show_detail(detail, no_html=false, options={})
251 255 multiple = false
252 256 case detail.property
253 257 when 'attr'
254 258 field = detail.prop_key.to_s.gsub(/\_id$/, "")
255 259 label = l(("field_" + field).to_sym)
256 260 case detail.prop_key
257 261 when 'due_date', 'start_date'
258 262 value = format_date(detail.value.to_date) if detail.value
259 263 old_value = format_date(detail.old_value.to_date) if detail.old_value
260 264
261 265 when 'project_id', 'status_id', 'tracker_id', 'assigned_to_id',
262 266 'priority_id', 'category_id', 'fixed_version_id'
263 267 value = find_name_by_reflection(field, detail.value)
264 268 old_value = find_name_by_reflection(field, detail.old_value)
265 269
266 270 when 'estimated_hours'
267 271 value = "%0.02f" % detail.value.to_f unless detail.value.blank?
268 272 old_value = "%0.02f" % detail.old_value.to_f unless detail.old_value.blank?
269 273
270 274 when 'parent_id'
271 275 label = l(:field_parent_issue)
272 276 value = "##{detail.value}" unless detail.value.blank?
273 277 old_value = "##{detail.old_value}" unless detail.old_value.blank?
274 278
275 279 when 'is_private'
276 280 value = l(detail.value == "0" ? :general_text_No : :general_text_Yes) unless detail.value.blank?
277 281 old_value = l(detail.old_value == "0" ? :general_text_No : :general_text_Yes) unless detail.old_value.blank?
278 282 end
279 283 when 'cf'
280 284 custom_field = CustomField.find_by_id(detail.prop_key)
281 285 if custom_field
282 286 multiple = custom_field.multiple?
283 287 label = custom_field.name
284 288 value = format_value(detail.value, custom_field.field_format) if detail.value
285 289 old_value = format_value(detail.old_value, custom_field.field_format) if detail.old_value
286 290 end
287 291 when 'attachment'
288 292 label = l(:label_attachment)
289 293 end
290 294 call_hook(:helper_issues_show_detail_after_setting,
291 295 {:detail => detail, :label => label, :value => value, :old_value => old_value })
292 296
293 297 label ||= detail.prop_key
294 298 value ||= detail.value
295 299 old_value ||= detail.old_value
296 300
297 301 unless no_html
298 302 label = content_tag('strong', label)
299 303 old_value = content_tag("i", h(old_value)) if detail.old_value
300 304 old_value = content_tag("del", old_value) if detail.old_value and detail.value.blank?
301 305 if detail.property == 'attachment' && !value.blank? && atta = Attachment.find_by_id(detail.prop_key)
302 306 # Link to the attachment if it has not been removed
303 307 value = link_to_attachment(atta, :download => true, :only_path => options[:only_path])
304 308 if options[:only_path] != false && atta.is_text?
305 309 value += link_to(
306 310 image_tag('magnifier.png'),
307 311 :controller => 'attachments', :action => 'show',
308 312 :id => atta, :filename => atta.filename
309 313 )
310 314 end
311 315 else
312 316 value = content_tag("i", h(value)) if value
313 317 end
314 318 end
315 319
316 320 if detail.property == 'attr' && detail.prop_key == 'description'
317 321 s = l(:text_journal_changed_no_detail, :label => label)
318 322 unless no_html
319 323 diff_link = link_to 'diff',
320 324 {:controller => 'journals', :action => 'diff', :id => detail.journal_id,
321 325 :detail_id => detail.id, :only_path => options[:only_path]},
322 326 :title => l(:label_view_diff)
323 327 s << " (#{ diff_link })"
324 328 end
325 329 s.html_safe
326 330 elsif detail.value.present?
327 331 case detail.property
328 332 when 'attr', 'cf'
329 333 if detail.old_value.present?
330 334 l(:text_journal_changed, :label => label, :old => old_value, :new => value).html_safe
331 335 elsif multiple
332 336 l(:text_journal_added, :label => label, :value => value).html_safe
333 337 else
334 338 l(:text_journal_set_to, :label => label, :value => value).html_safe
335 339 end
336 340 when 'attachment'
337 341 l(:text_journal_added, :label => label, :value => value).html_safe
338 342 end
339 343 else
340 344 l(:text_journal_deleted, :label => label, :old => old_value).html_safe
341 345 end
342 346 end
343 347
344 348 # Find the name of an associated record stored in the field attribute
345 349 def find_name_by_reflection(field, id)
346 350 association = Issue.reflect_on_association(field.to_sym)
347 351 if association
348 352 record = association.class_name.constantize.find_by_id(id)
349 353 return record.name if record
350 354 end
351 355 end
352 356
353 357 # Renders issue children recursively
354 358 def render_api_issue_children(issue, api)
355 359 return if issue.leaf?
356 360 api.array :children do
357 361 issue.children.each do |child|
358 362 api.issue(:id => child.id) do
359 363 api.tracker(:id => child.tracker_id, :name => child.tracker.name) unless child.tracker.nil?
360 364 api.subject child.subject
361 365 render_api_issue_children(child, api)
362 366 end
363 367 end
364 368 end
365 369 end
366 370
367 371 def issues_to_csv(issues, project, query, options={})
368 372 decimal_separator = l(:general_csv_decimal_separator)
369 373 encoding = l(:general_csv_encoding)
370 374 columns = (options[:columns] == 'all' ? query.available_columns : query.columns)
371 375
372 376 export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv|
373 377 # csv header fields
374 378 csv << [ "#" ] + columns.collect {|c| Redmine::CodesetUtil.from_utf8(c.caption.to_s, encoding) } +
375 379 (options[:description] ? [Redmine::CodesetUtil.from_utf8(l(:field_description), encoding)] : [])
376 380
377 381 # csv lines
378 382 issues.each do |issue|
379 383 col_values = columns.collect do |column|
380 384 s = if column.is_a?(QueryCustomFieldColumn)
381 385 cv = issue.custom_field_values.detect {|v| v.custom_field_id == column.custom_field.id}
382 386 show_value(cv)
383 387 else
384 388 value = column.value(issue)
385 389 if value.is_a?(Date)
386 390 format_date(value)
387 391 elsif value.is_a?(Time)
388 392 format_time(value)
389 393 elsif value.is_a?(Float)
390 394 ("%.2f" % value).gsub('.', decimal_separator)
391 395 else
392 396 value
393 397 end
394 398 end
395 399 s.to_s
396 400 end
397 401 csv << [ issue.id.to_s ] + col_values.collect {|c| Redmine::CodesetUtil.from_utf8(c.to_s, encoding) } +
398 402 (options[:description] ? [Redmine::CodesetUtil.from_utf8(issue.description, encoding)] : [])
399 403 end
400 404 end
401 405 export
402 406 end
403 407 end
General Comments 0
You need to be logged in to leave comments. Login now