You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

workflows_controller.rb 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2012 Jean-Philippe Lang
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; either version 2
  7. # of the License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  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
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. class WorkflowsController < ApplicationController
  18. layout 'admin'
  19. before_filter :require_admin
  20. before_filter :find_roles
  21. before_filter :find_trackers
  22. def index
  23. @workflow_counts = Workflow.count_by_tracker_and_role
  24. end
  25. def edit
  26. @role = Role.find_by_id(params[:role_id])
  27. @tracker = Tracker.find_by_id(params[:tracker_id])
  28. if request.post?
  29. Workflow.destroy_all( ["role_id=? and tracker_id=?", @role.id, @tracker.id])
  30. (params[:issue_status] || []).each { |status_id, transitions|
  31. transitions.each { |new_status_id, options|
  32. author = options.is_a?(Array) && options.include?('author') && !options.include?('always')
  33. assignee = options.is_a?(Array) && options.include?('assignee') && !options.include?('always')
  34. @role.workflows.build(:tracker_id => @tracker.id, :old_status_id => status_id, :new_status_id => new_status_id, :author => author, :assignee => assignee)
  35. }
  36. }
  37. if @role.save
  38. flash[:notice] = l(:notice_successful_update)
  39. redirect_to :action => 'edit', :role_id => @role, :tracker_id => @tracker
  40. return
  41. end
  42. end
  43. @used_statuses_only = (params[:used_statuses_only] == '0' ? false : true)
  44. if @tracker && @used_statuses_only && @tracker.issue_statuses.any?
  45. @statuses = @tracker.issue_statuses
  46. end
  47. @statuses ||= IssueStatus.find(:all, :order => 'position')
  48. if @tracker && @role && @statuses.any?
  49. workflows = Workflow.all(:conditions => {:role_id => @role.id, :tracker_id => @tracker.id})
  50. @workflows = {}
  51. @workflows['always'] = workflows.select {|w| !w.author && !w.assignee}
  52. @workflows['author'] = workflows.select {|w| w.author}
  53. @workflows['assignee'] = workflows.select {|w| w.assignee}
  54. end
  55. end
  56. def copy
  57. if params[:source_tracker_id].blank? || params[:source_tracker_id] == 'any'
  58. @source_tracker = nil
  59. else
  60. @source_tracker = Tracker.find_by_id(params[:source_tracker_id].to_i)
  61. end
  62. if params[:source_role_id].blank? || params[:source_role_id] == 'any'
  63. @source_role = nil
  64. else
  65. @source_role = Role.find_by_id(params[:source_role_id].to_i)
  66. end
  67. @target_trackers = params[:target_tracker_ids].blank? ? nil : Tracker.find_all_by_id(params[:target_tracker_ids])
  68. @target_roles = params[:target_role_ids].blank? ? nil : Role.find_all_by_id(params[:target_role_ids])
  69. if request.post?
  70. if params[:source_tracker_id].blank? || params[:source_role_id].blank? || (@source_tracker.nil? && @source_role.nil?)
  71. flash.now[:error] = l(:error_workflow_copy_source)
  72. elsif @target_trackers.nil? || @target_roles.nil?
  73. flash.now[:error] = l(:error_workflow_copy_target)
  74. else
  75. Workflow.copy(@source_tracker, @source_role, @target_trackers, @target_roles)
  76. flash[:notice] = l(:notice_successful_update)
  77. redirect_to :action => 'copy', :source_tracker_id => @source_tracker, :source_role_id => @source_role
  78. end
  79. end
  80. end
  81. private
  82. def find_roles
  83. @roles = Role.find(:all, :order => 'builtin, position')
  84. end
  85. def find_trackers
  86. @trackers = Tracker.find(:all, :order => 'position')
  87. end
  88. end