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

workflows_controller.rb 5.2 kB

13 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2013 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, :find_roles, :find_trackers
  20. def index
  21. @workflow_counts = WorkflowTransition.count_by_tracker_and_role
  22. end
  23. def edit
  24. @role = Role.find_by_id(params[:role_id]) if params[:role_id]
  25. @tracker = Tracker.find_by_id(params[:tracker_id]) if params[:tracker_id]
  26. if request.post?
  27. WorkflowTransition.destroy_all( ["role_id=? and tracker_id=?", @role.id, @tracker.id])
  28. (params[:issue_status] || []).each { |status_id, transitions|
  29. transitions.each { |new_status_id, options|
  30. author = options.is_a?(Array) && options.include?('author') && !options.include?('always')
  31. assignee = options.is_a?(Array) && options.include?('assignee') && !options.include?('always')
  32. WorkflowTransition.create(:role_id => @role.id, :tracker_id => @tracker.id, :old_status_id => status_id, :new_status_id => new_status_id, :author => author, :assignee => assignee)
  33. }
  34. }
  35. if @role.save
  36. redirect_to workflows_edit_path(:role_id => @role, :tracker_id => @tracker, :used_statuses_only => params[:used_statuses_only])
  37. return
  38. end
  39. end
  40. @used_statuses_only = (params[:used_statuses_only] == '0' ? false : true)
  41. if @tracker && @used_statuses_only && @tracker.issue_statuses.any?
  42. @statuses = @tracker.issue_statuses
  43. end
  44. @statuses ||= IssueStatus.sorted.all
  45. if @tracker && @role && @statuses.any?
  46. workflows = WorkflowTransition.where(:role_id => @role.id, :tracker_id => @tracker.id).all
  47. @workflows = {}
  48. @workflows['always'] = workflows.select {|w| !w.author && !w.assignee}
  49. @workflows['author'] = workflows.select {|w| w.author}
  50. @workflows['assignee'] = workflows.select {|w| w.assignee}
  51. end
  52. end
  53. def permissions
  54. @role = Role.find_by_id(params[:role_id]) if params[:role_id]
  55. @tracker = Tracker.find_by_id(params[:tracker_id]) if params[:tracker_id]
  56. if request.post? && @role && @tracker
  57. WorkflowPermission.replace_permissions(@tracker, @role, params[:permissions] || {})
  58. redirect_to workflows_permissions_path(:role_id => @role, :tracker_id => @tracker, :used_statuses_only => params[:used_statuses_only])
  59. return
  60. end
  61. @used_statuses_only = (params[:used_statuses_only] == '0' ? false : true)
  62. if @tracker && @used_statuses_only && @tracker.issue_statuses.any?
  63. @statuses = @tracker.issue_statuses
  64. end
  65. @statuses ||= IssueStatus.sorted.all
  66. if @role && @tracker
  67. @fields = (Tracker::CORE_FIELDS_ALL - @tracker.disabled_core_fields).map {|field| [field, l("field_"+field.sub(/_id$/, ''))]}
  68. @custom_fields = @tracker.custom_fields
  69. @permissions = WorkflowPermission.where(:tracker_id => @tracker.id, :role_id => @role.id).all.inject({}) do |h, w|
  70. h[w.old_status_id] ||= {}
  71. h[w.old_status_id][w.field_name] = w.rule
  72. h
  73. end
  74. @statuses.each {|status| @permissions[status.id] ||= {}}
  75. end
  76. end
  77. def copy
  78. if params[:source_tracker_id].blank? || params[:source_tracker_id] == 'any'
  79. @source_tracker = nil
  80. else
  81. @source_tracker = Tracker.find_by_id(params[:source_tracker_id].to_i)
  82. end
  83. if params[:source_role_id].blank? || params[:source_role_id] == 'any'
  84. @source_role = nil
  85. else
  86. @source_role = Role.find_by_id(params[:source_role_id].to_i)
  87. end
  88. @target_trackers = params[:target_tracker_ids].blank? ? nil : Tracker.find_all_by_id(params[:target_tracker_ids])
  89. @target_roles = params[:target_role_ids].blank? ? nil : Role.find_all_by_id(params[:target_role_ids])
  90. if request.post?
  91. if params[:source_tracker_id].blank? || params[:source_role_id].blank? || (@source_tracker.nil? && @source_role.nil?)
  92. flash.now[:error] = l(:error_workflow_copy_source)
  93. elsif @target_trackers.blank? || @target_roles.blank?
  94. flash.now[:error] = l(:error_workflow_copy_target)
  95. else
  96. WorkflowRule.copy(@source_tracker, @source_role, @target_trackers, @target_roles)
  97. flash[:notice] = l(:notice_successful_update)
  98. redirect_to workflows_copy_path(:source_tracker_id => @source_tracker, :source_role_id => @source_role)
  99. end
  100. end
  101. end
  102. private
  103. def find_roles
  104. @roles = Role.sorted.all
  105. end
  106. def find_trackers
  107. @trackers = Tracker.sorted.all
  108. end
  109. end

软件技术创新是当今国家整体创新能力的重要基础和发展引擎。近年来,大众参与的软件创新与创业活动已经成为网络时代软件开发和应用的新形态,正在快速改变着全球软件创新模式和软件产业格局。 ...