To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / app / controllers / workflows_controller.rb @ 912:5e80956cc792
History | View | Annotate | Download (3.91 KB)
| 1 | 0:513646585e45 | Chris | # Redmine - project management software
|
|---|---|---|---|
| 2 | 909:cbb26bc654de | Chris | # Copyright (C) 2006-2011 Jean-Philippe Lang
|
| 3 | 0:513646585e45 | Chris | #
|
| 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 | 909:cbb26bc654de | Chris | #
|
| 9 | 0:513646585e45 | Chris | # 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 | 909:cbb26bc654de | Chris | #
|
| 14 | 0:513646585e45 | Chris | # 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 | |||
| 18 | class WorkflowsController < ApplicationController |
||
| 19 | layout 'admin'
|
||
| 20 | 909:cbb26bc654de | Chris | |
| 21 | 0:513646585e45 | Chris | before_filter :require_admin
|
| 22 | before_filter :find_roles
|
||
| 23 | before_filter :find_trackers
|
||
| 24 | 909:cbb26bc654de | Chris | |
| 25 | 0:513646585e45 | Chris | def index |
| 26 | @workflow_counts = Workflow.count_by_tracker_and_role |
||
| 27 | end
|
||
| 28 | 909:cbb26bc654de | Chris | |
| 29 | 0:513646585e45 | Chris | def edit |
| 30 | @role = Role.find_by_id(params[:role_id]) |
||
| 31 | 909:cbb26bc654de | Chris | @tracker = Tracker.find_by_id(params[:tracker_id]) |
| 32 | |||
| 33 | 0:513646585e45 | Chris | if request.post?
|
| 34 | Workflow.destroy_all( ["role_id=? and tracker_id=?", @role.id, @tracker.id]) |
||
| 35 | 245:051f544170fe | Chris | (params[:issue_status] || []).each { |status_id, transitions|
|
| 36 | transitions.each { |new_status_id, options|
|
||
| 37 | author = options.is_a?(Array) && options.include?('author') && !options.include?('always') |
||
| 38 | assignee = options.is_a?(Array) && options.include?('assignee') && !options.include?('always') |
||
| 39 | 909:cbb26bc654de | Chris | @role.workflows.build(:tracker_id => @tracker.id, :old_status_id => status_id, :new_status_id => new_status_id, :author => author, :assignee => assignee) |
| 40 | 0:513646585e45 | Chris | } |
| 41 | } |
||
| 42 | if @role.save |
||
| 43 | flash[:notice] = l(:notice_successful_update) |
||
| 44 | redirect_to :action => 'edit', :role_id => @role, :tracker_id => @tracker |
||
| 45 | 245:051f544170fe | Chris | return
|
| 46 | 0:513646585e45 | Chris | end
|
| 47 | end
|
||
| 48 | 909:cbb26bc654de | Chris | |
| 49 | 0:513646585e45 | Chris | @used_statuses_only = (params[:used_statuses_only] == '0' ? false : true) |
| 50 | if @tracker && @used_statuses_only && @tracker.issue_statuses.any? |
||
| 51 | @statuses = @tracker.issue_statuses |
||
| 52 | end
|
||
| 53 | @statuses ||= IssueStatus.find(:all, :order => 'position') |
||
| 54 | 909:cbb26bc654de | Chris | |
| 55 | 245:051f544170fe | Chris | if @tracker && @role && @statuses.any? |
| 56 | workflows = Workflow.all(:conditions => {:role_id => @role.id, :tracker_id => @tracker.id}) |
||
| 57 | @workflows = {}
|
||
| 58 | @workflows['always'] = workflows.select {|w| !w.author && !w.assignee} |
||
| 59 | @workflows['author'] = workflows.select {|w| w.author} |
||
| 60 | @workflows['assignee'] = workflows.select {|w| w.assignee} |
||
| 61 | end
|
||
| 62 | 0:513646585e45 | Chris | end
|
| 63 | 909:cbb26bc654de | Chris | |
| 64 | 0:513646585e45 | Chris | def copy |
| 65 | 909:cbb26bc654de | Chris | |
| 66 | 0:513646585e45 | Chris | if params[:source_tracker_id].blank? || params[:source_tracker_id] == 'any' |
| 67 | @source_tracker = nil |
||
| 68 | else
|
||
| 69 | @source_tracker = Tracker.find_by_id(params[:source_tracker_id].to_i) |
||
| 70 | end
|
||
| 71 | if params[:source_role_id].blank? || params[:source_role_id] == 'any' |
||
| 72 | @source_role = nil |
||
| 73 | else
|
||
| 74 | @source_role = Role.find_by_id(params[:source_role_id].to_i) |
||
| 75 | end
|
||
| 76 | 909:cbb26bc654de | Chris | |
| 77 | 0:513646585e45 | Chris | @target_trackers = params[:target_tracker_ids].blank? ? nil : Tracker.find_all_by_id(params[:target_tracker_ids]) |
| 78 | @target_roles = params[:target_role_ids].blank? ? nil : Role.find_all_by_id(params[:target_role_ids]) |
||
| 79 | 909:cbb26bc654de | Chris | |
| 80 | 0:513646585e45 | Chris | if request.post?
|
| 81 | if params[:source_tracker_id].blank? || params[:source_role_id].blank? || (@source_tracker.nil? && @source_role.nil?) |
||
| 82 | flash.now[:error] = l(:error_workflow_copy_source) |
||
| 83 | elsif @target_trackers.nil? || @target_roles.nil? |
||
| 84 | flash.now[:error] = l(:error_workflow_copy_target) |
||
| 85 | else
|
||
| 86 | Workflow.copy(@source_tracker, @source_role, @target_trackers, @target_roles) |
||
| 87 | flash[:notice] = l(:notice_successful_update) |
||
| 88 | redirect_to :action => 'copy', :source_tracker_id => @source_tracker, :source_role_id => @source_role |
||
| 89 | end
|
||
| 90 | end
|
||
| 91 | end
|
||
| 92 | |||
| 93 | private |
||
| 94 | |||
| 95 | def find_roles |
||
| 96 | @roles = Role.find(:all, :order => 'builtin, position') |
||
| 97 | end
|
||
| 98 | 909:cbb26bc654de | Chris | |
| 99 | 0:513646585e45 | Chris | def find_trackers |
| 100 | @trackers = Tracker.find(:all, :order => 'position') |
||
| 101 | end
|
||
| 102 | end |