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