##// END OF EJS Templates
Transaction and performance improvement on workflow copy when creating a new tracker....
Jean-Philippe Lang -
r945:a7c2b63fb610
parent child
Show More
@@ -1,82 +1,84
1 1 # redMine - project management software
2 2 # Copyright (C) 2006 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 class TrackersController < ApplicationController
19 19 layout 'base'
20 20 before_filter :require_admin
21 21
22 22 def index
23 23 list
24 24 render :action => 'list' unless request.xhr?
25 25 end
26 26
27 27 # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
28 28 verify :method => :post, :only => [ :destroy, :move ], :redirect_to => { :action => :list }
29 29
30 30 def list
31 31 @tracker_pages, @trackers = paginate :trackers, :per_page => 10, :order => 'position'
32 32 render :action => "list", :layout => false if request.xhr?
33 33 end
34 34
35 35 def new
36 36 @tracker = Tracker.new(params[:tracker])
37 37 if request.post? and @tracker.save
38 38 # workflow copy
39 39 if !params[:copy_workflow_from].blank? && (copy_from = Tracker.find_by_id(params[:copy_workflow_from]))
40 copy_from.workflows.each do |w|
41 @tracker.workflows << w.clone
40 Workflow.transaction do
41 copy_from.workflows.find(:all, :include => [:role, :old_status, :new_status]).each do |w|
42 Workflow.create(:tracker_id => @tracker.id, :role => w.role, :old_status => w.old_status, :new_status => w.new_status)
43 end
42 44 end
43 45 end
44 46 flash[:notice] = l(:notice_successful_create)
45 47 redirect_to :action => 'list'
46 48 end
47 49 @trackers = Tracker.find :all
48 50 end
49 51
50 52 def edit
51 53 @tracker = Tracker.find(params[:id])
52 54 if request.post? and @tracker.update_attributes(params[:tracker])
53 55 flash[:notice] = l(:notice_successful_update)
54 56 redirect_to :action => 'list'
55 57 end
56 58 end
57 59
58 60 def move
59 61 @tracker = Tracker.find(params[:id])
60 62 case params[:position]
61 63 when 'highest'
62 64 @tracker.move_to_top
63 65 when 'higher'
64 66 @tracker.move_higher
65 67 when 'lower'
66 68 @tracker.move_lower
67 69 when 'lowest'
68 70 @tracker.move_to_bottom
69 71 end if params[:position]
70 72 redirect_to :action => 'list'
71 73 end
72 74
73 75 def destroy
74 76 @tracker = Tracker.find(params[:id])
75 77 unless @tracker.issues.empty?
76 78 flash[:error] = "This tracker contains issues and can\'t be deleted."
77 79 else
78 80 @tracker.destroy
79 81 end
80 82 redirect_to :action => 'list'
81 83 end
82 84 end
General Comments 0
You need to be logged in to leave comments. Login now