##// END OF EJS Templates
Moved users list diplayed as available watchers on the new issue form to an helper....
Jean-Philippe Lang -
r13613:9548d39a15c1
parent child
Show More
@@ -1,523 +1,519
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2015 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 class IssuesController < ApplicationController
19 19 menu_item :new_issue, :only => [:new, :create]
20 20 default_search_scope :issues
21 21
22 22 before_filter :find_issue, :only => [:show, :edit, :update]
23 23 before_filter :find_issues, :only => [:bulk_edit, :bulk_update, :destroy]
24 24 before_filter :find_project, :only => [:new, :create, :update_form]
25 25 before_filter :authorize, :except => [:index]
26 26 before_filter :find_optional_project, :only => [:index]
27 27 before_filter :build_new_issue_from_params, :only => [:new, :create, :update_form]
28 28 accept_rss_auth :index, :show
29 29 accept_api_auth :index, :show, :create, :update, :destroy
30 30
31 31 rescue_from Query::StatementInvalid, :with => :query_statement_invalid
32 32
33 33 helper :journals
34 34 helper :projects
35 35 include ProjectsHelper
36 36 helper :custom_fields
37 37 include CustomFieldsHelper
38 38 helper :issue_relations
39 39 include IssueRelationsHelper
40 40 helper :watchers
41 41 include WatchersHelper
42 42 helper :attachments
43 43 include AttachmentsHelper
44 44 helper :queries
45 45 include QueriesHelper
46 46 helper :repositories
47 47 include RepositoriesHelper
48 48 helper :sort
49 49 include SortHelper
50 50 include IssuesHelper
51 51 helper :timelog
52 52
53 53 def index
54 54 retrieve_query
55 55 sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
56 56 sort_update(@query.sortable_columns)
57 57 @query.sort_criteria = sort_criteria.to_a
58 58
59 59 if @query.valid?
60 60 case params[:format]
61 61 when 'csv', 'pdf'
62 62 @limit = Setting.issues_export_limit.to_i
63 63 if params[:columns] == 'all'
64 64 @query.column_names = @query.available_inline_columns.map(&:name)
65 65 end
66 66 when 'atom'
67 67 @limit = Setting.feeds_limit.to_i
68 68 when 'xml', 'json'
69 69 @offset, @limit = api_offset_and_limit
70 70 @query.column_names = %w(author)
71 71 else
72 72 @limit = per_page_option
73 73 end
74 74
75 75 @issue_count = @query.issue_count
76 76 @issue_pages = Paginator.new @issue_count, @limit, params['page']
77 77 @offset ||= @issue_pages.offset
78 78 @issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version],
79 79 :order => sort_clause,
80 80 :offset => @offset,
81 81 :limit => @limit)
82 82 @issue_count_by_group = @query.issue_count_by_group
83 83
84 84 respond_to do |format|
85 85 format.html { render :template => 'issues/index', :layout => !request.xhr? }
86 86 format.api {
87 87 Issue.load_visible_relations(@issues) if include_in_api_response?('relations')
88 88 }
89 89 format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") }
90 90 format.csv { send_data(query_to_csv(@issues, @query, params), :type => 'text/csv; header=present', :filename => 'issues.csv') }
91 91 format.pdf { send_file_headers! :type => 'application/pdf', :filename => 'issues.pdf' }
92 92 end
93 93 else
94 94 respond_to do |format|
95 95 format.html { render(:template => 'issues/index', :layout => !request.xhr?) }
96 96 format.any(:atom, :csv, :pdf) { render(:nothing => true) }
97 97 format.api { render_validation_errors(@query) }
98 98 end
99 99 end
100 100 rescue ActiveRecord::RecordNotFound
101 101 render_404
102 102 end
103 103
104 104 def show
105 105 @journals = @issue.journals.includes(:user, :details).
106 106 references(:user, :details).
107 107 reorder("#{Journal.table_name}.id ASC").to_a
108 108 @journals.each_with_index {|j,i| j.indice = i+1}
109 109 @journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project)
110 110 Journal.preload_journals_details_custom_fields(@journals)
111 111 @journals.select! {|journal| journal.notes? || journal.visible_details.any?}
112 112 @journals.reverse! if User.current.wants_comments_in_reverse_order?
113 113
114 114 @changesets = @issue.changesets.visible.to_a
115 115 @changesets.reverse! if User.current.wants_comments_in_reverse_order?
116 116
117 117 @relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? }
118 118 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
119 119 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
120 120 @priorities = IssuePriority.active
121 121 @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
122 122 @relation = IssueRelation.new
123 123
124 124 respond_to do |format|
125 125 format.html {
126 126 retrieve_previous_and_next_issue_ids
127 127 render :template => 'issues/show'
128 128 }
129 129 format.api
130 130 format.atom { render :template => 'journals/index', :layout => false, :content_type => 'application/atom+xml' }
131 131 format.pdf {
132 132 send_file_headers! :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf"
133 133 }
134 134 end
135 135 end
136 136
137 137 # Add a new issue
138 138 # The new issue will be created from an existing one if copy_from parameter is given
139 139 def new
140 140 respond_to do |format|
141 141 format.html { render :action => 'new', :layout => !request.xhr? }
142 142 end
143 143 end
144 144
145 145 def create
146 146 unless User.current.allowed_to?(:add_issues, @issue.project)
147 147 raise ::Unauthorized
148 148 end
149 149 call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue })
150 150 @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))
151 151 if @issue.save
152 152 call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue})
153 153 respond_to do |format|
154 154 format.html {
155 155 render_attachment_warning_if_needed(@issue)
156 156 flash[:notice] = l(:notice_issue_successful_create, :id => view_context.link_to("##{@issue.id}", issue_path(@issue), :title => @issue.subject))
157 157 if params[:continue]
158 158 attrs = {:tracker_id => @issue.tracker, :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?}
159 159 redirect_to new_project_issue_path(@issue.project, :issue => attrs)
160 160 else
161 161 redirect_to issue_path(@issue)
162 162 end
163 163 }
164 164 format.api { render :action => 'show', :status => :created, :location => issue_url(@issue) }
165 165 end
166 166 return
167 167 else
168 168 respond_to do |format|
169 169 format.html { render :action => 'new' }
170 170 format.api { render_validation_errors(@issue) }
171 171 end
172 172 end
173 173 end
174 174
175 175 def edit
176 176 return unless update_issue_from_params
177 177
178 178 respond_to do |format|
179 179 format.html { }
180 180 format.xml { }
181 181 end
182 182 end
183 183
184 184 def update
185 185 return unless update_issue_from_params
186 186 @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))
187 187 saved = false
188 188 begin
189 189 saved = save_issue_with_child_records
190 190 rescue ActiveRecord::StaleObjectError
191 191 @conflict = true
192 192 if params[:last_journal_id]
193 193 @conflict_journals = @issue.journals_after(params[:last_journal_id]).to_a
194 194 @conflict_journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project)
195 195 end
196 196 end
197 197
198 198 if saved
199 199 render_attachment_warning_if_needed(@issue)
200 200 flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record?
201 201
202 202 respond_to do |format|
203 203 format.html { redirect_back_or_default issue_path(@issue) }
204 204 format.api { render_api_ok }
205 205 end
206 206 else
207 207 respond_to do |format|
208 208 format.html { render :action => 'edit' }
209 209 format.api { render_validation_errors(@issue) }
210 210 end
211 211 end
212 212 end
213 213
214 214 # Updates the issue form when changing the project, status or tracker
215 215 # on issue creation/update
216 216 def update_form
217 217 end
218 218
219 219 # Bulk edit/copy a set of issues
220 220 def bulk_edit
221 221 @issues.sort!
222 222 @copy = params[:copy].present?
223 223 @notes = params[:notes]
224 224
225 225 if @copy
226 226 unless User.current.allowed_to?(:copy_issues, @projects)
227 227 raise ::Unauthorized
228 228 end
229 229 end
230 230
231 231 @allowed_projects = Issue.allowed_target_projects
232 232 if params[:issue]
233 233 @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:issue][:project_id].to_s}
234 234 if @target_project
235 235 target_projects = [@target_project]
236 236 end
237 237 end
238 238 target_projects ||= @projects
239 239
240 240 if @copy
241 241 # Copied issues will get their default statuses
242 242 @available_statuses = []
243 243 else
244 244 @available_statuses = @issues.map(&:new_statuses_allowed_to).reduce(:&)
245 245 end
246 246 @custom_fields = target_projects.map{|p|p.all_issue_custom_fields.visible}.reduce(:&)
247 247 @assignables = target_projects.map(&:assignable_users).reduce(:&)
248 248 @trackers = target_projects.map(&:trackers).reduce(:&)
249 249 @versions = target_projects.map {|p| p.shared_versions.open}.reduce(:&)
250 250 @categories = target_projects.map {|p| p.issue_categories}.reduce(:&)
251 251 if @copy
252 252 @attachments_present = @issues.detect {|i| i.attachments.any?}.present?
253 253 @subtasks_present = @issues.detect {|i| !i.leaf?}.present?
254 254 end
255 255
256 256 @safe_attributes = @issues.map(&:safe_attribute_names).reduce(:&)
257 257
258 258 @issue_params = params[:issue] || {}
259 259 @issue_params[:custom_field_values] ||= {}
260 260 end
261 261
262 262 def bulk_update
263 263 @issues.sort!
264 264 @copy = params[:copy].present?
265 265 attributes = parse_params_for_bulk_issue_attributes(params)
266 266
267 267 if @copy
268 268 unless User.current.allowed_to?(:copy_issues, @projects)
269 269 raise ::Unauthorized
270 270 end
271 271 target_projects = @projects
272 272 if attributes['project_id'].present?
273 273 target_projects = Project.where(:id => attributes['project_id']).to_a
274 274 end
275 275 unless User.current.allowed_to?(:add_issues, target_projects)
276 276 raise ::Unauthorized
277 277 end
278 278 end
279 279
280 280 unsaved_issues = []
281 281 saved_issues = []
282 282
283 283 if @copy && params[:copy_subtasks].present?
284 284 # Descendant issues will be copied with the parent task
285 285 # Don't copy them twice
286 286 @issues.reject! {|issue| @issues.detect {|other| issue.is_descendant_of?(other)}}
287 287 end
288 288
289 289 @issues.each do |orig_issue|
290 290 orig_issue.reload
291 291 if @copy
292 292 issue = orig_issue.copy({},
293 293 :attachments => params[:copy_attachments].present?,
294 294 :subtasks => params[:copy_subtasks].present?,
295 295 :link => link_copy?(params[:link_copy])
296 296 )
297 297 else
298 298 issue = orig_issue
299 299 end
300 300 journal = issue.init_journal(User.current, params[:notes])
301 301 issue.safe_attributes = attributes
302 302 call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue })
303 303 if issue.save
304 304 saved_issues << issue
305 305 else
306 306 unsaved_issues << orig_issue
307 307 end
308 308 end
309 309
310 310 if unsaved_issues.empty?
311 311 flash[:notice] = l(:notice_successful_update) unless saved_issues.empty?
312 312 if params[:follow]
313 313 if @issues.size == 1 && saved_issues.size == 1
314 314 redirect_to issue_path(saved_issues.first)
315 315 elsif saved_issues.map(&:project).uniq.size == 1
316 316 redirect_to project_issues_path(saved_issues.map(&:project).first)
317 317 end
318 318 else
319 319 redirect_back_or_default _project_issues_path(@project)
320 320 end
321 321 else
322 322 @saved_issues = @issues
323 323 @unsaved_issues = unsaved_issues
324 324 @issues = Issue.visible.where(:id => @unsaved_issues.map(&:id)).to_a
325 325 bulk_edit
326 326 render :action => 'bulk_edit'
327 327 end
328 328 end
329 329
330 330 def destroy
331 331 @hours = TimeEntry.where(:issue_id => @issues.map(&:id)).sum(:hours).to_f
332 332 if @hours > 0
333 333 case params[:todo]
334 334 when 'destroy'
335 335 # nothing to do
336 336 when 'nullify'
337 337 TimeEntry.where(['issue_id IN (?)', @issues]).update_all('issue_id = NULL')
338 338 when 'reassign'
339 339 reassign_to = @project.issues.find_by_id(params[:reassign_to_id])
340 340 if reassign_to.nil?
341 341 flash.now[:error] = l(:error_issue_not_found_in_project)
342 342 return
343 343 else
344 344 TimeEntry.where(['issue_id IN (?)', @issues]).
345 345 update_all("issue_id = #{reassign_to.id}")
346 346 end
347 347 else
348 348 # display the destroy form if it's a user request
349 349 return unless api_request?
350 350 end
351 351 end
352 352 @issues.each do |issue|
353 353 begin
354 354 issue.reload.destroy
355 355 rescue ::ActiveRecord::RecordNotFound # raised by #reload if issue no longer exists
356 356 # nothing to do, issue was already deleted (eg. by a parent)
357 357 end
358 358 end
359 359 respond_to do |format|
360 360 format.html { redirect_back_or_default _project_issues_path(@project) }
361 361 format.api { render_api_ok }
362 362 end
363 363 end
364 364
365 365 private
366 366
367 367 def find_project
368 368 project_id = params[:project_id] || (params[:issue] && params[:issue][:project_id])
369 369 @project = Project.find(project_id)
370 370 rescue ActiveRecord::RecordNotFound
371 371 render_404
372 372 end
373 373
374 374 def retrieve_previous_and_next_issue_ids
375 375 retrieve_query_from_session
376 376 if @query
377 377 sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
378 378 sort_update(@query.sortable_columns, 'issues_index_sort')
379 379 limit = 500
380 380 issue_ids = @query.issue_ids(:order => sort_clause, :limit => (limit + 1), :include => [:assigned_to, :tracker, :priority, :category, :fixed_version])
381 381 if (idx = issue_ids.index(@issue.id)) && idx < limit
382 382 if issue_ids.size < 500
383 383 @issue_position = idx + 1
384 384 @issue_count = issue_ids.size
385 385 end
386 386 @prev_issue_id = issue_ids[idx - 1] if idx > 0
387 387 @next_issue_id = issue_ids[idx + 1] if idx < (issue_ids.size - 1)
388 388 end
389 389 end
390 390 end
391 391
392 392 # Used by #edit and #update to set some common instance variables
393 393 # from the params
394 394 # TODO: Refactor, not everything in here is needed by #edit
395 395 def update_issue_from_params
396 396 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
397 397 @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
398 398 if params[:time_entry]
399 399 @time_entry.attributes = params[:time_entry]
400 400 end
401 401
402 402 @issue.init_journal(User.current)
403 403
404 404 issue_attributes = params[:issue]
405 405 if issue_attributes && params[:conflict_resolution]
406 406 case params[:conflict_resolution]
407 407 when 'overwrite'
408 408 issue_attributes = issue_attributes.dup
409 409 issue_attributes.delete(:lock_version)
410 410 when 'add_notes'
411 411 issue_attributes = issue_attributes.slice(:notes)
412 412 when 'cancel'
413 413 redirect_to issue_path(@issue)
414 414 return false
415 415 end
416 416 end
417 417 @issue.safe_attributes = issue_attributes
418 418 @priorities = IssuePriority.active
419 419 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
420 420 true
421 421 end
422 422
423 423 # TODO: Refactor, lots of extra code in here
424 424 # TODO: Changing tracker on an existing issue should not trigger this
425 425 def build_new_issue_from_params
426 426 if params[:id].blank?
427 427 @issue = Issue.new
428 428 if params[:copy_from]
429 429 begin
430 430 @issue.init_journal(User.current)
431 431 @copy_from = Issue.visible.find(params[:copy_from])
432 432 unless User.current.allowed_to?(:copy_issues, @copy_from.project)
433 433 raise ::Unauthorized
434 434 end
435 435 @link_copy = link_copy?(params[:link_copy]) || request.get?
436 436 @copy_attachments = params[:copy_attachments].present? || request.get?
437 437 @copy_subtasks = params[:copy_subtasks].present? || request.get?
438 438 @issue.copy_from(@copy_from, :attachments => @copy_attachments, :subtasks => @copy_subtasks, :link => @link_copy)
439 439 rescue ActiveRecord::RecordNotFound
440 440 render_404
441 441 return
442 442 end
443 443 end
444 444 @issue.project = @project
445 445 @issue.author ||= User.current
446 446 @issue.start_date ||= Date.today if Setting.default_issue_start_date_to_creation_date?
447 447 else
448 448 @issue = @project.issues.visible.find(params[:id])
449 449 end
450 450
451 451 if attrs = params[:issue].deep_dup
452 452 if params[:was_default_status] == attrs[:status_id]
453 453 attrs.delete(:status_id)
454 454 end
455 455 @issue.safe_attributes = attrs
456 456 end
457 457 @issue.tracker ||= @project.trackers.first
458 458 if @issue.tracker.nil?
459 459 render_error l(:error_no_tracker_in_project)
460 460 return false
461 461 end
462 462 if @issue.status.nil?
463 463 render_error l(:error_no_default_issue_status)
464 464 return false
465 465 end
466 466
467 467 @priorities = IssuePriority.active
468 468 @allowed_statuses = @issue.new_statuses_allowed_to(User.current, @issue.new_record?)
469 @available_watchers = @issue.watcher_users
470 if @issue.project.users.count <= 20
471 @available_watchers = (@available_watchers + @issue.project.users.sort).uniq
472 end
473 469 end
474 470
475 471 def parse_params_for_bulk_issue_attributes(params)
476 472 attributes = (params[:issue] || {}).reject {|k,v| v.blank?}
477 473 attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'}
478 474 if custom = attributes[:custom_field_values]
479 475 custom.reject! {|k,v| v.blank?}
480 476 custom.keys.each do |k|
481 477 if custom[k].is_a?(Array)
482 478 custom[k] << '' if custom[k].delete('__none__')
483 479 else
484 480 custom[k] = '' if custom[k] == '__none__'
485 481 end
486 482 end
487 483 end
488 484 attributes
489 485 end
490 486
491 487 # Saves @issue and a time_entry from the parameters
492 488 def save_issue_with_child_records
493 489 Issue.transaction do
494 490 if params[:time_entry] && (params[:time_entry][:hours].present? || params[:time_entry][:comments].present?) && User.current.allowed_to?(:log_time, @issue.project)
495 491 time_entry = @time_entry || TimeEntry.new
496 492 time_entry.project = @issue.project
497 493 time_entry.issue = @issue
498 494 time_entry.user = User.current
499 495 time_entry.spent_on = User.current.today
500 496 time_entry.attributes = params[:time_entry]
501 497 @issue.time_entries << time_entry
502 498 end
503 499
504 500 call_hook(:controller_issues_edit_before_save, { :params => params, :issue => @issue, :time_entry => time_entry, :journal => @issue.current_journal})
505 501 if @issue.save
506 502 call_hook(:controller_issues_edit_after_save, { :params => params, :issue => @issue, :time_entry => time_entry, :journal => @issue.current_journal})
507 503 else
508 504 raise ActiveRecord::Rollback
509 505 end
510 506 end
511 507 end
512 508
513 509 def link_copy?(param)
514 510 case Setting.link_copied_issue
515 511 when 'yes'
516 512 true
517 513 when 'no'
518 514 false
519 515 when 'ask'
520 516 param == '1'
521 517 end
522 518 end
523 519 end
@@ -1,463 +1,473
1 1 # encoding: utf-8
2 2 #
3 3 # Redmine - project management software
4 4 # Copyright (C) 2006-2015 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 include Redmine::Export::PDF::IssuesPdfHelper
23 23
24 24 def issue_list(issues, &block)
25 25 ancestors = []
26 26 issues.each do |issue|
27 27 while (ancestors.any? && !issue.is_descendant_of?(ancestors.last))
28 28 ancestors.pop
29 29 end
30 30 yield issue, ancestors.size
31 31 ancestors << issue unless issue.leaf?
32 32 end
33 33 end
34 34
35 35 def grouped_issue_list(issues, query, issue_count_by_group, &block)
36 36 previous_group, first = false, true
37 37 issue_list(issues) do |issue, level|
38 38 group_name = group_count = nil
39 39 if query.grouped? && ((group = query.group_by_column.value(issue)) != previous_group || first)
40 40 if group.blank? && group != false
41 41 group_name = "(#{l(:label_blank_value)})"
42 42 else
43 43 group_name = column_content(query.group_by_column, issue)
44 44 end
45 45 group_name ||= ""
46 46 group_count = issue_count_by_group[group]
47 47 end
48 48 yield issue, level, group_name, group_count
49 49 previous_group, first = group, false
50 50 end
51 51 end
52 52
53 53 # Renders a HTML/CSS tooltip
54 54 #
55 55 # To use, a trigger div is needed. This is a div with the class of "tooltip"
56 56 # that contains this method wrapped in a span with the class of "tip"
57 57 #
58 58 # <div class="tooltip"><%= link_to_issue(issue) %>
59 59 # <span class="tip"><%= render_issue_tooltip(issue) %></span>
60 60 # </div>
61 61 #
62 62 def render_issue_tooltip(issue)
63 63 @cached_label_status ||= l(:field_status)
64 64 @cached_label_start_date ||= l(:field_start_date)
65 65 @cached_label_due_date ||= l(:field_due_date)
66 66 @cached_label_assigned_to ||= l(:field_assigned_to)
67 67 @cached_label_priority ||= l(:field_priority)
68 68 @cached_label_project ||= l(:field_project)
69 69
70 70 link_to_issue(issue) + "<br /><br />".html_safe +
71 71 "<strong>#{@cached_label_project}</strong>: #{link_to_project(issue.project)}<br />".html_safe +
72 72 "<strong>#{@cached_label_status}</strong>: #{h(issue.status.name)}<br />".html_safe +
73 73 "<strong>#{@cached_label_start_date}</strong>: #{format_date(issue.start_date)}<br />".html_safe +
74 74 "<strong>#{@cached_label_due_date}</strong>: #{format_date(issue.due_date)}<br />".html_safe +
75 75 "<strong>#{@cached_label_assigned_to}</strong>: #{h(issue.assigned_to)}<br />".html_safe +
76 76 "<strong>#{@cached_label_priority}</strong>: #{h(issue.priority.name)}".html_safe
77 77 end
78 78
79 79 def issue_heading(issue)
80 80 h("#{issue.tracker} ##{issue.id}")
81 81 end
82 82
83 83 def render_issue_subject_with_tree(issue)
84 84 s = ''
85 85 ancestors = issue.root? ? [] : issue.ancestors.visible.to_a
86 86 ancestors.each do |ancestor|
87 87 s << '<div>' + content_tag('p', link_to_issue(ancestor, :project => (issue.project_id != ancestor.project_id)))
88 88 end
89 89 s << '<div>'
90 90 subject = h(issue.subject)
91 91 if issue.is_private?
92 92 subject = content_tag('span', l(:field_is_private), :class => 'private') + ' ' + subject
93 93 end
94 94 s << content_tag('h3', subject)
95 95 s << '</div>' * (ancestors.size + 1)
96 96 s.html_safe
97 97 end
98 98
99 99 def render_descendants_tree(issue)
100 100 s = '<form><table class="list issues">'
101 101 issue_list(issue.descendants.visible.sort_by(&:lft)) do |child, level|
102 102 css = "issue issue-#{child.id} hascontextmenu"
103 103 css << " idnt idnt-#{level}" if level > 0
104 104 s << content_tag('tr',
105 105 content_tag('td', check_box_tag("ids[]", child.id, false, :id => nil), :class => 'checkbox') +
106 106 content_tag('td', link_to_issue(child, :project => (issue.project_id != child.project_id)), :class => 'subject', :style => 'width: 50%') +
107 107 content_tag('td', h(child.status)) +
108 108 content_tag('td', link_to_user(child.assigned_to)) +
109 109 content_tag('td', progress_bar(child.done_ratio, :width => '80px')),
110 110 :class => css)
111 111 end
112 112 s << '</table></form>'
113 113 s.html_safe
114 114 end
115 115
116 116 # Returns an array of error messages for bulk edited issues
117 117 def bulk_edit_error_messages(issues)
118 118 messages = {}
119 119 issues.each do |issue|
120 120 issue.errors.full_messages.each do |message|
121 121 messages[message] ||= []
122 122 messages[message] << issue
123 123 end
124 124 end
125 125 messages.map { |message, issues|
126 126 "#{message}: " + issues.map {|i| "##{i.id}"}.join(', ')
127 127 }
128 128 end
129 129
130 130 # Returns a link for adding a new subtask to the given issue
131 131 def link_to_new_subtask(issue)
132 132 attrs = {
133 133 :tracker_id => issue.tracker,
134 134 :parent_issue_id => issue
135 135 }
136 136 link_to(l(:button_add), new_project_issue_path(issue.project, :issue => attrs))
137 137 end
138 138
139 139 class IssueFieldsRows
140 140 include ActionView::Helpers::TagHelper
141 141
142 142 def initialize
143 143 @left = []
144 144 @right = []
145 145 end
146 146
147 147 def left(*args)
148 148 args.any? ? @left << cells(*args) : @left
149 149 end
150 150
151 151 def right(*args)
152 152 args.any? ? @right << cells(*args) : @right
153 153 end
154 154
155 155 def size
156 156 @left.size > @right.size ? @left.size : @right.size
157 157 end
158 158
159 159 def to_html
160 160 html = ''.html_safe
161 161 blank = content_tag('th', '') + content_tag('td', '')
162 162 size.times do |i|
163 163 left = @left[i] || blank
164 164 right = @right[i] || blank
165 165 html << content_tag('tr', left + right)
166 166 end
167 167 html
168 168 end
169 169
170 170 def cells(label, text, options={})
171 171 content_tag('th', "#{label}:", options) + content_tag('td', text, options)
172 172 end
173 173 end
174 174
175 175 def issue_fields_rows
176 176 r = IssueFieldsRows.new
177 177 yield r
178 178 r.to_html
179 179 end
180 180
181 181 def render_custom_fields_rows(issue)
182 182 values = issue.visible_custom_field_values
183 183 return if values.empty?
184 184 ordered_values = []
185 185 half = (values.size / 2.0).ceil
186 186 half.times do |i|
187 187 ordered_values << values[i]
188 188 ordered_values << values[i + half]
189 189 end
190 190 s = "<tr>\n"
191 191 n = 0
192 192 ordered_values.compact.each do |value|
193 193 css = "cf_#{value.custom_field.id}"
194 194 s << "</tr>\n<tr>\n" if n > 0 && (n % 2) == 0
195 195 s << "\t<th class=\"#{css}\">#{ h(value.custom_field.name) }:</th><td class=\"#{css}\">#{ h(show_value(value)) }</td>\n"
196 196 n += 1
197 197 end
198 198 s << "</tr>\n"
199 199 s.html_safe
200 200 end
201 201
202 202 # Returns the number of descendants for an array of issues
203 203 def issues_descendant_count(issues)
204 204 ids = issues.reject(&:leaf?).map {|issue| issue.descendants.ids}.flatten.uniq
205 205 ids -= issues.map(&:id)
206 206 ids.size
207 207 end
208 208
209 209 def issues_destroy_confirmation_message(issues)
210 210 issues = [issues] unless issues.is_a?(Array)
211 211 message = l(:text_issues_destroy_confirmation)
212 212
213 213 descendant_count = issues_descendant_count(issues)
214 214 if descendant_count > 0
215 215 message << "\n" + l(:text_issues_destroy_descendants_confirmation, :count => descendant_count)
216 216 end
217 217 message
218 218 end
219 219
220 # Returns an array of users that are proposed as watchers
221 # on the new issue form
222 def users_for_new_issue_watchers(issue)
223 users = issue.watcher_users
224 if issue.project.users.count <= 20
225 users = (users + issue.project.users.sort).uniq
226 end
227 users
228 end
229
220 230 def sidebar_queries
221 231 unless @sidebar_queries
222 232 @sidebar_queries = IssueQuery.visible.
223 233 order("#{Query.table_name}.name ASC").
224 234 # Project specific queries and global queries
225 235 where(@project.nil? ? ["project_id IS NULL"] : ["project_id IS NULL OR project_id = ?", @project.id]).
226 236 to_a
227 237 end
228 238 @sidebar_queries
229 239 end
230 240
231 241 def query_links(title, queries)
232 242 return '' if queries.empty?
233 243 # links to #index on issues/show
234 244 url_params = controller_name == 'issues' ? {:controller => 'issues', :action => 'index', :project_id => @project} : params
235 245
236 246 content_tag('h3', title) + "\n" +
237 247 content_tag('ul',
238 248 queries.collect {|query|
239 249 css = 'query'
240 250 css << ' selected' if query == @query
241 251 content_tag('li', link_to(query.name, url_params.merge(:query_id => query), :class => css))
242 252 }.join("\n").html_safe,
243 253 :class => 'queries'
244 254 ) + "\n"
245 255 end
246 256
247 257 def render_sidebar_queries
248 258 out = ''.html_safe
249 259 out << query_links(l(:label_my_queries), sidebar_queries.select(&:is_private?))
250 260 out << query_links(l(:label_query_plural), sidebar_queries.reject(&:is_private?))
251 261 out
252 262 end
253 263
254 264 def email_issue_attributes(issue, user)
255 265 items = []
256 266 %w(author status priority assigned_to category fixed_version).each do |attribute|
257 267 unless issue.disabled_core_fields.include?(attribute+"_id")
258 268 items << "#{l("field_#{attribute}")}: #{issue.send attribute}"
259 269 end
260 270 end
261 271 issue.visible_custom_field_values(user).each do |value|
262 272 items << "#{value.custom_field.name}: #{show_value(value, false)}"
263 273 end
264 274 items
265 275 end
266 276
267 277 def render_email_issue_attributes(issue, user, html=false)
268 278 items = email_issue_attributes(issue, user)
269 279 if html
270 280 content_tag('ul', items.map{|s| content_tag('li', s)}.join("\n").html_safe)
271 281 else
272 282 items.map{|s| "* #{s}"}.join("\n")
273 283 end
274 284 end
275 285
276 286 # Returns the textual representation of a journal details
277 287 # as an array of strings
278 288 def details_to_strings(details, no_html=false, options={})
279 289 options[:only_path] = (options[:only_path] == false ? false : true)
280 290 strings = []
281 291 values_by_field = {}
282 292 details.each do |detail|
283 293 if detail.property == 'cf'
284 294 field = detail.custom_field
285 295 if field && field.multiple?
286 296 values_by_field[field] ||= {:added => [], :deleted => []}
287 297 if detail.old_value
288 298 values_by_field[field][:deleted] << detail.old_value
289 299 end
290 300 if detail.value
291 301 values_by_field[field][:added] << detail.value
292 302 end
293 303 next
294 304 end
295 305 end
296 306 strings << show_detail(detail, no_html, options)
297 307 end
298 308 values_by_field.each do |field, changes|
299 309 detail = JournalDetail.new(:property => 'cf', :prop_key => field.id.to_s)
300 310 detail.instance_variable_set "@custom_field", field
301 311 if changes[:added].any?
302 312 detail.value = changes[:added]
303 313 strings << show_detail(detail, no_html, options)
304 314 elsif changes[:deleted].any?
305 315 detail.old_value = changes[:deleted]
306 316 strings << show_detail(detail, no_html, options)
307 317 end
308 318 end
309 319 strings
310 320 end
311 321
312 322 # Returns the textual representation of a single journal detail
313 323 def show_detail(detail, no_html=false, options={})
314 324 multiple = false
315 325 show_diff = false
316 326
317 327 case detail.property
318 328 when 'attr'
319 329 field = detail.prop_key.to_s.gsub(/\_id$/, "")
320 330 label = l(("field_" + field).to_sym)
321 331 case detail.prop_key
322 332 when 'due_date', 'start_date'
323 333 value = format_date(detail.value.to_date) if detail.value
324 334 old_value = format_date(detail.old_value.to_date) if detail.old_value
325 335
326 336 when 'project_id', 'status_id', 'tracker_id', 'assigned_to_id',
327 337 'priority_id', 'category_id', 'fixed_version_id'
328 338 value = find_name_by_reflection(field, detail.value)
329 339 old_value = find_name_by_reflection(field, detail.old_value)
330 340
331 341 when 'estimated_hours'
332 342 value = "%0.02f" % detail.value.to_f unless detail.value.blank?
333 343 old_value = "%0.02f" % detail.old_value.to_f unless detail.old_value.blank?
334 344
335 345 when 'parent_id'
336 346 label = l(:field_parent_issue)
337 347 value = "##{detail.value}" unless detail.value.blank?
338 348 old_value = "##{detail.old_value}" unless detail.old_value.blank?
339 349
340 350 when 'is_private'
341 351 value = l(detail.value == "0" ? :general_text_No : :general_text_Yes) unless detail.value.blank?
342 352 old_value = l(detail.old_value == "0" ? :general_text_No : :general_text_Yes) unless detail.old_value.blank?
343 353
344 354 when 'description'
345 355 show_diff = true
346 356 end
347 357 when 'cf'
348 358 custom_field = detail.custom_field
349 359 if custom_field
350 360 label = custom_field.name
351 361 if custom_field.format.class.change_as_diff
352 362 show_diff = true
353 363 else
354 364 multiple = custom_field.multiple?
355 365 value = format_value(detail.value, custom_field) if detail.value
356 366 old_value = format_value(detail.old_value, custom_field) if detail.old_value
357 367 end
358 368 end
359 369 when 'attachment'
360 370 label = l(:label_attachment)
361 371 when 'relation'
362 372 if detail.value && !detail.old_value
363 373 rel_issue = Issue.visible.find_by_id(detail.value)
364 374 value = rel_issue.nil? ? "#{l(:label_issue)} ##{detail.value}" :
365 375 (no_html ? rel_issue : link_to_issue(rel_issue, :only_path => options[:only_path]))
366 376 elsif detail.old_value && !detail.value
367 377 rel_issue = Issue.visible.find_by_id(detail.old_value)
368 378 old_value = rel_issue.nil? ? "#{l(:label_issue)} ##{detail.old_value}" :
369 379 (no_html ? rel_issue : link_to_issue(rel_issue, :only_path => options[:only_path]))
370 380 end
371 381 relation_type = IssueRelation::TYPES[detail.prop_key]
372 382 label = l(relation_type[:name]) if relation_type
373 383 end
374 384 call_hook(:helper_issues_show_detail_after_setting,
375 385 {:detail => detail, :label => label, :value => value, :old_value => old_value })
376 386
377 387 label ||= detail.prop_key
378 388 value ||= detail.value
379 389 old_value ||= detail.old_value
380 390
381 391 unless no_html
382 392 label = content_tag('strong', label)
383 393 old_value = content_tag("i", h(old_value)) if detail.old_value
384 394 if detail.old_value && detail.value.blank? && detail.property != 'relation'
385 395 old_value = content_tag("del", old_value)
386 396 end
387 397 if detail.property == 'attachment' && value.present? &&
388 398 atta = detail.journal.journalized.attachments.detect {|a| a.id == detail.prop_key.to_i}
389 399 # Link to the attachment if it has not been removed
390 400 value = link_to_attachment(atta, :download => true, :only_path => options[:only_path])
391 401 if options[:only_path] != false && atta.is_text?
392 402 value += link_to(
393 403 image_tag('magnifier.png'),
394 404 :controller => 'attachments', :action => 'show',
395 405 :id => atta, :filename => atta.filename
396 406 )
397 407 end
398 408 else
399 409 value = content_tag("i", h(value)) if value
400 410 end
401 411 end
402 412
403 413 if show_diff
404 414 s = l(:text_journal_changed_no_detail, :label => label)
405 415 unless no_html
406 416 diff_link = link_to 'diff',
407 417 {:controller => 'journals', :action => 'diff', :id => detail.journal_id,
408 418 :detail_id => detail.id, :only_path => options[:only_path]},
409 419 :title => l(:label_view_diff)
410 420 s << " (#{ diff_link })"
411 421 end
412 422 s.html_safe
413 423 elsif detail.value.present?
414 424 case detail.property
415 425 when 'attr', 'cf'
416 426 if detail.old_value.present?
417 427 l(:text_journal_changed, :label => label, :old => old_value, :new => value).html_safe
418 428 elsif multiple
419 429 l(:text_journal_added, :label => label, :value => value).html_safe
420 430 else
421 431 l(:text_journal_set_to, :label => label, :value => value).html_safe
422 432 end
423 433 when 'attachment', 'relation'
424 434 l(:text_journal_added, :label => label, :value => value).html_safe
425 435 end
426 436 else
427 437 l(:text_journal_deleted, :label => label, :old => old_value).html_safe
428 438 end
429 439 end
430 440
431 441 # Find the name of an associated record stored in the field attribute
432 442 def find_name_by_reflection(field, id)
433 443 unless id.present?
434 444 return nil
435 445 end
436 446 @detail_value_name_by_reflection ||= Hash.new do |hash, key|
437 447 association = Issue.reflect_on_association(key.first.to_sym)
438 448 if association
439 449 record = association.klass.find_by_id(key.last)
440 450 if record
441 451 record.name.force_encoding('UTF-8')
442 452 hash[key] = record.name
443 453 end
444 454 end
445 455 hash[key] ||= nil
446 456 end
447 457 @detail_value_name_by_reflection[[field, id]]
448 458 end
449 459
450 460 # Renders issue children recursively
451 461 def render_api_issue_children(issue, api)
452 462 return if issue.leaf?
453 463 api.array :children do
454 464 issue.children.each do |child|
455 465 api.issue(:id => child.id) do
456 466 api.tracker(:id => child.tracker_id, :name => child.tracker.name) unless child.tracker.nil?
457 467 api.subject child.subject
458 468 render_api_issue_children(child, api)
459 469 end
460 470 end
461 471 end
462 472 end
463 473 end
@@ -1,59 +1,59
1 1 <%= title l(:label_issue_new) %>
2 2
3 3 <%= call_hook(:view_issues_new_top, {:issue => @issue}) %>
4 4
5 5 <%= labelled_form_for @issue, :url => project_issues_path(@project),
6 6 :html => {:id => 'issue-form', :multipart => true} do |f| %>
7 7 <%= error_messages_for 'issue' %>
8 8 <%= hidden_field_tag 'copy_from', params[:copy_from] if params[:copy_from] %>
9 9 <div class="box tabular">
10 10 <div id="all_attributes">
11 11 <%= render :partial => 'issues/form', :locals => {:f => f} %>
12 12 </div>
13 13
14 14 <% if @copy_from && Setting.link_copied_issue == 'ask' %>
15 15 <p>
16 16 <label for="link_copy"><%= l(:label_link_copied_issue) %></label>
17 17 <%= check_box_tag 'link_copy', '1', @link_copy %>
18 18 </p>
19 19 <% end %>
20 20 <% if @copy_from && @copy_from.attachments.any? %>
21 21 <p>
22 22 <label for="copy_attachments"><%= l(:label_copy_attachments) %></label>
23 23 <%= check_box_tag 'copy_attachments', '1', @copy_attachments %>
24 24 </p>
25 25 <% end %>
26 26 <% if @copy_from && !@copy_from.leaf? %>
27 27 <p>
28 28 <label for="copy_subtasks"><%= l(:label_copy_subtasks) %></label>
29 29 <%= check_box_tag 'copy_subtasks', '1', @copy_subtasks %>
30 30 </p>
31 31 <% end %>
32 32
33 33 <p id="attachments_form"><label><%= l(:label_attachment_plural) %></label><%= render :partial => 'attachments/form', :locals => {:container => @issue} %></p>
34 34
35 35 <% if @issue.safe_attribute? 'watcher_user_ids' -%>
36 36 <p id="watchers_form"><label><%= l(:label_issue_watchers) %></label>
37 37 <span id="watchers_inputs">
38 <%= watchers_checkboxes(@issue, @available_watchers) %>
38 <%= watchers_checkboxes(@issue, users_for_new_issue_watchers(@issue)) %>
39 39 </span>
40 40 <span class="search_for_watchers">
41 41 <%= link_to l(:label_search_for_watchers),
42 42 {:controller => 'watchers', :action => 'new', :project_id => @issue.project},
43 43 :remote => true,
44 44 :method => 'get' %>
45 45 </span>
46 46 </p>
47 47 <% end %>
48 48 </div>
49 49
50 50 <%= submit_tag l(:button_create) %>
51 51 <%= submit_tag l(:button_create_and_continue), :name => 'continue' %>
52 52 <%= preview_link preview_new_issue_path(:project_id => @project), 'issue-form' %>
53 53 <% end %>
54 54
55 55 <div id="preview" class="wiki"></div>
56 56
57 57 <% content_for :header_tags do %>
58 58 <%= robot_exclusion_tag %>
59 59 <% end %>
General Comments 0
You need to be logged in to leave comments. Login now