##// 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 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006 Jean-Philippe Lang
2 # Copyright (C) 2006 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 TrackersController < ApplicationController
18 class TrackersController < ApplicationController
19 layout 'base'
19 layout 'base'
20 before_filter :require_admin
20 before_filter :require_admin
21
21
22 def index
22 def index
23 list
23 list
24 render :action => 'list' unless request.xhr?
24 render :action => 'list' unless request.xhr?
25 end
25 end
26
26
27 # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
27 # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
28 verify :method => :post, :only => [ :destroy, :move ], :redirect_to => { :action => :list }
28 verify :method => :post, :only => [ :destroy, :move ], :redirect_to => { :action => :list }
29
29
30 def list
30 def list
31 @tracker_pages, @trackers = paginate :trackers, :per_page => 10, :order => 'position'
31 @tracker_pages, @trackers = paginate :trackers, :per_page => 10, :order => 'position'
32 render :action => "list", :layout => false if request.xhr?
32 render :action => "list", :layout => false if request.xhr?
33 end
33 end
34
34
35 def new
35 def new
36 @tracker = Tracker.new(params[:tracker])
36 @tracker = Tracker.new(params[:tracker])
37 if request.post? and @tracker.save
37 if request.post? and @tracker.save
38 # workflow copy
38 # workflow copy
39 if !params[:copy_workflow_from].blank? && (copy_from = Tracker.find_by_id(params[:copy_workflow_from]))
39 if !params[:copy_workflow_from].blank? && (copy_from = Tracker.find_by_id(params[:copy_workflow_from]))
40 copy_from.workflows.each do |w|
40 Workflow.transaction do
41 @tracker.workflows << w.clone
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 end
44 end
43 end
45 end
44 flash[:notice] = l(:notice_successful_create)
46 flash[:notice] = l(:notice_successful_create)
45 redirect_to :action => 'list'
47 redirect_to :action => 'list'
46 end
48 end
47 @trackers = Tracker.find :all
49 @trackers = Tracker.find :all
48 end
50 end
49
51
50 def edit
52 def edit
51 @tracker = Tracker.find(params[:id])
53 @tracker = Tracker.find(params[:id])
52 if request.post? and @tracker.update_attributes(params[:tracker])
54 if request.post? and @tracker.update_attributes(params[:tracker])
53 flash[:notice] = l(:notice_successful_update)
55 flash[:notice] = l(:notice_successful_update)
54 redirect_to :action => 'list'
56 redirect_to :action => 'list'
55 end
57 end
56 end
58 end
57
59
58 def move
60 def move
59 @tracker = Tracker.find(params[:id])
61 @tracker = Tracker.find(params[:id])
60 case params[:position]
62 case params[:position]
61 when 'highest'
63 when 'highest'
62 @tracker.move_to_top
64 @tracker.move_to_top
63 when 'higher'
65 when 'higher'
64 @tracker.move_higher
66 @tracker.move_higher
65 when 'lower'
67 when 'lower'
66 @tracker.move_lower
68 @tracker.move_lower
67 when 'lowest'
69 when 'lowest'
68 @tracker.move_to_bottom
70 @tracker.move_to_bottom
69 end if params[:position]
71 end if params[:position]
70 redirect_to :action => 'list'
72 redirect_to :action => 'list'
71 end
73 end
72
74
73 def destroy
75 def destroy
74 @tracker = Tracker.find(params[:id])
76 @tracker = Tracker.find(params[:id])
75 unless @tracker.issues.empty?
77 unless @tracker.issues.empty?
76 flash[:error] = "This tracker contains issues and can\'t be deleted."
78 flash[:error] = "This tracker contains issues and can\'t be deleted."
77 else
79 else
78 @tracker.destroy
80 @tracker.destroy
79 end
81 end
80 redirect_to :action => 'list'
82 redirect_to :action => 'list'
81 end
83 end
82 end
84 end
General Comments 0
You need to be logged in to leave comments. Login now