annotate app/controllers/workflows_controller.rb @ 888:96376d0a80bd feature_80

Close obsolete branch feature_80
author Chris Cannam
date Sat, 05 Mar 2011 16:02:23 +0000
parents 513646585e45
children 051f544170fe
rev   line source
Chris@0 1 # Redmine - project management software
Chris@0 2 # Copyright (C) 2006-2008 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@0 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@0 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@0 20
Chris@0 21 before_filter :require_admin
Chris@0 22 before_filter :find_roles
Chris@0 23 before_filter :find_trackers
Chris@0 24
Chris@0 25 def index
Chris@0 26 @workflow_counts = Workflow.count_by_tracker_and_role
Chris@0 27 end
Chris@0 28
Chris@0 29 def edit
Chris@0 30 @role = Role.find_by_id(params[:role_id])
Chris@0 31 @tracker = Tracker.find_by_id(params[:tracker_id])
Chris@0 32
Chris@0 33 if request.post?
Chris@0 34 Workflow.destroy_all( ["role_id=? and tracker_id=?", @role.id, @tracker.id])
Chris@0 35 (params[:issue_status] || []).each { |old, news|
Chris@0 36 news.each { |new|
Chris@0 37 @role.workflows.build(:tracker_id => @tracker.id, :old_status_id => old, :new_status_id => new)
Chris@0 38 }
Chris@0 39 }
Chris@0 40 if @role.save
Chris@0 41 flash[:notice] = l(:notice_successful_update)
Chris@0 42 redirect_to :action => 'edit', :role_id => @role, :tracker_id => @tracker
Chris@0 43 end
Chris@0 44 end
Chris@0 45
Chris@0 46 @used_statuses_only = (params[:used_statuses_only] == '0' ? false : true)
Chris@0 47 if @tracker && @used_statuses_only && @tracker.issue_statuses.any?
Chris@0 48 @statuses = @tracker.issue_statuses
Chris@0 49 end
Chris@0 50 @statuses ||= IssueStatus.find(:all, :order => 'position')
Chris@0 51 end
Chris@0 52
Chris@0 53 def copy
Chris@0 54
Chris@0 55 if params[:source_tracker_id].blank? || params[:source_tracker_id] == 'any'
Chris@0 56 @source_tracker = nil
Chris@0 57 else
Chris@0 58 @source_tracker = Tracker.find_by_id(params[:source_tracker_id].to_i)
Chris@0 59 end
Chris@0 60 if params[:source_role_id].blank? || params[:source_role_id] == 'any'
Chris@0 61 @source_role = nil
Chris@0 62 else
Chris@0 63 @source_role = Role.find_by_id(params[:source_role_id].to_i)
Chris@0 64 end
Chris@0 65
Chris@0 66 @target_trackers = params[:target_tracker_ids].blank? ? nil : Tracker.find_all_by_id(params[:target_tracker_ids])
Chris@0 67 @target_roles = params[:target_role_ids].blank? ? nil : Role.find_all_by_id(params[:target_role_ids])
Chris@0 68
Chris@0 69 if request.post?
Chris@0 70 if params[:source_tracker_id].blank? || params[:source_role_id].blank? || (@source_tracker.nil? && @source_role.nil?)
Chris@0 71 flash.now[:error] = l(:error_workflow_copy_source)
Chris@0 72 elsif @target_trackers.nil? || @target_roles.nil?
Chris@0 73 flash.now[:error] = l(:error_workflow_copy_target)
Chris@0 74 else
Chris@0 75 Workflow.copy(@source_tracker, @source_role, @target_trackers, @target_roles)
Chris@0 76 flash[:notice] = l(:notice_successful_update)
Chris@0 77 redirect_to :action => 'copy', :source_tracker_id => @source_tracker, :source_role_id => @source_role
Chris@0 78 end
Chris@0 79 end
Chris@0 80 end
Chris@0 81
Chris@0 82 private
Chris@0 83
Chris@0 84 def find_roles
Chris@0 85 @roles = Role.find(:all, :order => 'builtin, position')
Chris@0 86 end
Chris@0 87
Chris@0 88 def find_trackers
Chris@0 89 @trackers = Tracker.find(:all, :order => 'position')
Chris@0 90 end
Chris@0 91 end