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