##// END OF EJS Templates
Code cleanup....
Jean-Philippe Lang -
r9810:5097f5178418
parent child
Show More
@@ -1,128 +1,126
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 class WorkflowsController < ApplicationController
19 19 layout 'admin'
20 20
21 before_filter :require_admin
22 before_filter :find_roles
23 before_filter :find_trackers
21 before_filter :require_admin, :find_roles, :find_trackers
24 22
25 23 def index
26 24 @workflow_counts = WorkflowTransition.count_by_tracker_and_role
27 25 end
28 26
29 27 def edit
30 28 @role = Role.find_by_id(params[:role_id])
31 29 @tracker = Tracker.find_by_id(params[:tracker_id])
32 30
33 31 if request.post?
34 32 WorkflowTransition.destroy_all( ["role_id=? and tracker_id=?", @role.id, @tracker.id])
35 33 (params[:issue_status] || []).each { |status_id, transitions|
36 34 transitions.each { |new_status_id, options|
37 35 author = options.is_a?(Array) && options.include?('author') && !options.include?('always')
38 36 assignee = options.is_a?(Array) && options.include?('assignee') && !options.include?('always')
39 37 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)
40 38 }
41 39 }
42 40 if @role.save
43 41 redirect_to :action => 'edit', :role_id => @role, :tracker_id => @tracker
44 42 return
45 43 end
46 44 end
47 45
48 46 @used_statuses_only = (params[:used_statuses_only] == '0' ? false : true)
49 47 if @tracker && @used_statuses_only && @tracker.issue_statuses.any?
50 48 @statuses = @tracker.issue_statuses
51 49 end
52 50 @statuses ||= IssueStatus.sorted.all
53 51
54 52 if @tracker && @role && @statuses.any?
55 53 workflows = WorkflowTransition.where(:role_id => @role.id, :tracker_id => @tracker.id).all
56 54 @workflows = {}
57 55 @workflows['always'] = workflows.select {|w| !w.author && !w.assignee}
58 56 @workflows['author'] = workflows.select {|w| w.author}
59 57 @workflows['assignee'] = workflows.select {|w| w.assignee}
60 58 end
61 59 end
62 60
63 61 def permissions
64 62 @role = Role.find_by_id(params[:role_id])
65 63 @tracker = Tracker.find_by_id(params[:tracker_id])
66 64
67 65 if @role && @tracker
68 66 if request.post?
69 67 WorkflowPermission.replace_permissions(@tracker, @role, params[:permissions] || {})
70 68 redirect_to :action => 'permissions', :role_id => @role, :tracker_id => @tracker
71 69 return
72 70 end
73 71
74 72 @statuses = @tracker.issue_statuses
75 73 if @statuses.empty?
76 74 @statuses = IssueStatus.sorted.all
77 75 end
78 76 @fields = (Tracker::CORE_FIELDS_ALL - @tracker.disabled_core_fields).map {|field| [field, l("field_"+field.sub(/_id$/, ''))]}
79 77 @custom_fields = @tracker.custom_fields
80 78
81 79 @permissions = WorkflowPermission.where(:tracker_id => @tracker.id, :role_id => @role.id).all.inject({}) do |h, w|
82 80 h[w.old_status_id] ||= {}
83 81 h[w.old_status_id][w.field_name] = w.rule
84 82 h
85 83 end
86 84 @statuses.each {|status| @permissions[status.id] ||= {}}
87 85 end
88 86 end
89 87
90 88 def copy
91 89
92 90 if params[:source_tracker_id].blank? || params[:source_tracker_id] == 'any'
93 91 @source_tracker = nil
94 92 else
95 93 @source_tracker = Tracker.find_by_id(params[:source_tracker_id].to_i)
96 94 end
97 95 if params[:source_role_id].blank? || params[:source_role_id] == 'any'
98 96 @source_role = nil
99 97 else
100 98 @source_role = Role.find_by_id(params[:source_role_id].to_i)
101 99 end
102 100
103 101 @target_trackers = params[:target_tracker_ids].blank? ? nil : Tracker.find_all_by_id(params[:target_tracker_ids])
104 102 @target_roles = params[:target_role_ids].blank? ? nil : Role.find_all_by_id(params[:target_role_ids])
105 103
106 104 if request.post?
107 105 if params[:source_tracker_id].blank? || params[:source_role_id].blank? || (@source_tracker.nil? && @source_role.nil?)
108 106 flash.now[:error] = l(:error_workflow_copy_source)
109 107 elsif @target_trackers.nil? || @target_roles.nil?
110 108 flash.now[:error] = l(:error_workflow_copy_target)
111 109 else
112 110 WorkflowRule.copy(@source_tracker, @source_role, @target_trackers, @target_roles)
113 111 flash[:notice] = l(:notice_successful_update)
114 112 redirect_to :action => 'copy', :source_tracker_id => @source_tracker, :source_role_id => @source_role
115 113 end
116 114 end
117 115 end
118 116
119 117 private
120 118
121 119 def find_roles
122 120 @roles = Role.sorted.all
123 121 end
124 122
125 123 def find_trackers
126 124 @trackers = Tracker.sorted.all
127 125 end
128 126 end
General Comments 0
You need to be logged in to leave comments. Login now