Chris@0: # Redmine - project management software Chris@909: # Copyright (C) 2006-2011 Jean-Philippe Lang Chris@0: # Chris@0: # This program is free software; you can redistribute it and/or Chris@0: # modify it under the terms of the GNU General Public License Chris@0: # as published by the Free Software Foundation; either version 2 Chris@0: # of the License, or (at your option) any later version. Chris@909: # Chris@0: # This program is distributed in the hope that it will be useful, Chris@0: # but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@0: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@0: # GNU General Public License for more details. Chris@909: # Chris@0: # You should have received a copy of the GNU General Public License Chris@0: # along with this program; if not, write to the Free Software Chris@0: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Chris@0: Chris@0: class WorkflowsController < ApplicationController Chris@0: layout 'admin' Chris@909: Chris@0: before_filter :require_admin Chris@0: before_filter :find_roles Chris@0: before_filter :find_trackers Chris@909: Chris@0: def index Chris@0: @workflow_counts = Workflow.count_by_tracker_and_role Chris@0: end Chris@909: Chris@0: def edit Chris@0: @role = Role.find_by_id(params[:role_id]) Chris@909: @tracker = Tracker.find_by_id(params[:tracker_id]) Chris@909: Chris@0: if request.post? Chris@0: Workflow.destroy_all( ["role_id=? and tracker_id=?", @role.id, @tracker.id]) Chris@245: (params[:issue_status] || []).each { |status_id, transitions| Chris@245: transitions.each { |new_status_id, options| Chris@245: author = options.is_a?(Array) && options.include?('author') && !options.include?('always') Chris@245: assignee = options.is_a?(Array) && options.include?('assignee') && !options.include?('always') Chris@909: @role.workflows.build(:tracker_id => @tracker.id, :old_status_id => status_id, :new_status_id => new_status_id, :author => author, :assignee => assignee) Chris@0: } Chris@0: } Chris@0: if @role.save Chris@0: flash[:notice] = l(:notice_successful_update) Chris@0: redirect_to :action => 'edit', :role_id => @role, :tracker_id => @tracker Chris@245: return Chris@0: end Chris@0: end Chris@909: Chris@0: @used_statuses_only = (params[:used_statuses_only] == '0' ? false : true) Chris@0: if @tracker && @used_statuses_only && @tracker.issue_statuses.any? Chris@0: @statuses = @tracker.issue_statuses Chris@0: end Chris@0: @statuses ||= IssueStatus.find(:all, :order => 'position') Chris@909: Chris@245: if @tracker && @role && @statuses.any? Chris@245: workflows = Workflow.all(:conditions => {:role_id => @role.id, :tracker_id => @tracker.id}) Chris@245: @workflows = {} Chris@245: @workflows['always'] = workflows.select {|w| !w.author && !w.assignee} Chris@245: @workflows['author'] = workflows.select {|w| w.author} Chris@245: @workflows['assignee'] = workflows.select {|w| w.assignee} Chris@245: end Chris@0: end Chris@909: Chris@0: def copy Chris@909: Chris@0: if params[:source_tracker_id].blank? || params[:source_tracker_id] == 'any' Chris@0: @source_tracker = nil Chris@0: else Chris@0: @source_tracker = Tracker.find_by_id(params[:source_tracker_id].to_i) Chris@0: end Chris@0: if params[:source_role_id].blank? || params[:source_role_id] == 'any' Chris@0: @source_role = nil Chris@0: else Chris@0: @source_role = Role.find_by_id(params[:source_role_id].to_i) Chris@0: end Chris@909: Chris@0: @target_trackers = params[:target_tracker_ids].blank? ? nil : Tracker.find_all_by_id(params[:target_tracker_ids]) Chris@0: @target_roles = params[:target_role_ids].blank? ? nil : Role.find_all_by_id(params[:target_role_ids]) Chris@909: Chris@0: if request.post? Chris@0: if params[:source_tracker_id].blank? || params[:source_role_id].blank? || (@source_tracker.nil? && @source_role.nil?) Chris@0: flash.now[:error] = l(:error_workflow_copy_source) Chris@0: elsif @target_trackers.nil? || @target_roles.nil? Chris@0: flash.now[:error] = l(:error_workflow_copy_target) Chris@0: else Chris@0: Workflow.copy(@source_tracker, @source_role, @target_trackers, @target_roles) Chris@0: flash[:notice] = l(:notice_successful_update) Chris@0: redirect_to :action => 'copy', :source_tracker_id => @source_tracker, :source_role_id => @source_role Chris@0: end Chris@0: end Chris@0: end Chris@0: Chris@0: private Chris@0: Chris@0: def find_roles Chris@0: @roles = Role.find(:all, :order => 'builtin, position') Chris@0: end Chris@909: Chris@0: def find_trackers Chris@0: @trackers = Tracker.find(:all, :order => 'position') Chris@0: end Chris@0: end