##// END OF EJS Templates
Use scoped models for pagination....
Jean-Philippe Lang -
r10798:85fb937a4ef0
parent child
Show More
@@ -1,81 +1,81
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang
2 # Copyright (C) 2006-2012 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 IssueStatusesController < ApplicationController
18 class IssueStatusesController < ApplicationController
19 layout 'admin'
19 layout 'admin'
20
20
21 before_filter :require_admin, :except => :index
21 before_filter :require_admin, :except => :index
22 before_filter :require_admin_or_api_request, :only => :index
22 before_filter :require_admin_or_api_request, :only => :index
23 accept_api_auth :index
23 accept_api_auth :index
24
24
25 def index
25 def index
26 respond_to do |format|
26 respond_to do |format|
27 format.html {
27 format.html {
28 @issue_status_pages, @issue_statuses = paginate :issue_statuses, :per_page => 25, :order => "position"
28 @issue_status_pages, @issue_statuses = paginate IssueStatus.sorted, :per_page => 25
29 render :action => "index", :layout => false if request.xhr?
29 render :action => "index", :layout => false if request.xhr?
30 }
30 }
31 format.api {
31 format.api {
32 @issue_statuses = IssueStatus.all(:order => 'position')
32 @issue_statuses = IssueStatus.all(:order => 'position')
33 }
33 }
34 end
34 end
35 end
35 end
36
36
37 def new
37 def new
38 @issue_status = IssueStatus.new
38 @issue_status = IssueStatus.new
39 end
39 end
40
40
41 def create
41 def create
42 @issue_status = IssueStatus.new(params[:issue_status])
42 @issue_status = IssueStatus.new(params[:issue_status])
43 if request.post? && @issue_status.save
43 if request.post? && @issue_status.save
44 flash[:notice] = l(:notice_successful_create)
44 flash[:notice] = l(:notice_successful_create)
45 redirect_to issue_statuses_path
45 redirect_to issue_statuses_path
46 else
46 else
47 render :action => 'new'
47 render :action => 'new'
48 end
48 end
49 end
49 end
50
50
51 def edit
51 def edit
52 @issue_status = IssueStatus.find(params[:id])
52 @issue_status = IssueStatus.find(params[:id])
53 end
53 end
54
54
55 def update
55 def update
56 @issue_status = IssueStatus.find(params[:id])
56 @issue_status = IssueStatus.find(params[:id])
57 if request.put? && @issue_status.update_attributes(params[:issue_status])
57 if request.put? && @issue_status.update_attributes(params[:issue_status])
58 flash[:notice] = l(:notice_successful_update)
58 flash[:notice] = l(:notice_successful_update)
59 redirect_to issue_statuses_path
59 redirect_to issue_statuses_path
60 else
60 else
61 render :action => 'edit'
61 render :action => 'edit'
62 end
62 end
63 end
63 end
64
64
65 def destroy
65 def destroy
66 IssueStatus.find(params[:id]).destroy
66 IssueStatus.find(params[:id]).destroy
67 redirect_to issue_statuses_path
67 redirect_to issue_statuses_path
68 rescue
68 rescue
69 flash[:error] = l(:error_unable_delete_issue_status)
69 flash[:error] = l(:error_unable_delete_issue_status)
70 redirect_to issue_statuses_path
70 redirect_to issue_statuses_path
71 end
71 end
72
72
73 def update_issue_done_ratio
73 def update_issue_done_ratio
74 if request.post? && IssueStatus.update_issue_done_ratios
74 if request.post? && IssueStatus.update_issue_done_ratios
75 flash[:notice] = l(:notice_issue_done_ratios_updated)
75 flash[:notice] = l(:notice_issue_done_ratios_updated)
76 else
76 else
77 flash[:error] = l(:error_issue_done_ratios_not_updated)
77 flash[:error] = l(:error_issue_done_ratios_not_updated)
78 end
78 end
79 redirect_to issue_statuses_path
79 redirect_to issue_statuses_path
80 end
80 end
81 end
81 end
@@ -1,108 +1,108
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang
2 # Copyright (C) 2006-2012 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 RolesController < ApplicationController
18 class RolesController < ApplicationController
19 layout 'admin'
19 layout 'admin'
20
20
21 before_filter :require_admin, :except => [:index, :show]
21 before_filter :require_admin, :except => [:index, :show]
22 before_filter :require_admin_or_api_request, :only => [:index, :show]
22 before_filter :require_admin_or_api_request, :only => [:index, :show]
23 before_filter :find_role, :only => [:show, :edit, :update, :destroy]
23 before_filter :find_role, :only => [:show, :edit, :update, :destroy]
24 accept_api_auth :index, :show
24 accept_api_auth :index, :show
25
25
26 def index
26 def index
27 respond_to do |format|
27 respond_to do |format|
28 format.html {
28 format.html {
29 @role_pages, @roles = paginate :roles, :per_page => 25, :order => 'builtin, position'
29 @role_pages, @roles = paginate Role.sorted, :per_page => 25
30 render :action => "index", :layout => false if request.xhr?
30 render :action => "index", :layout => false if request.xhr?
31 }
31 }
32 format.api {
32 format.api {
33 @roles = Role.givable.all
33 @roles = Role.givable.all
34 }
34 }
35 end
35 end
36 end
36 end
37
37
38 def show
38 def show
39 respond_to do |format|
39 respond_to do |format|
40 format.api
40 format.api
41 end
41 end
42 end
42 end
43
43
44 def new
44 def new
45 # Prefills the form with 'Non member' role permissions by default
45 # Prefills the form with 'Non member' role permissions by default
46 @role = Role.new(params[:role] || {:permissions => Role.non_member.permissions})
46 @role = Role.new(params[:role] || {:permissions => Role.non_member.permissions})
47 if params[:copy].present? && @copy_from = Role.find_by_id(params[:copy])
47 if params[:copy].present? && @copy_from = Role.find_by_id(params[:copy])
48 @role.copy_from(@copy_from)
48 @role.copy_from(@copy_from)
49 end
49 end
50 @roles = Role.sorted.all
50 @roles = Role.sorted.all
51 end
51 end
52
52
53 def create
53 def create
54 @role = Role.new(params[:role])
54 @role = Role.new(params[:role])
55 if request.post? && @role.save
55 if request.post? && @role.save
56 # workflow copy
56 # workflow copy
57 if !params[:copy_workflow_from].blank? && (copy_from = Role.find_by_id(params[:copy_workflow_from]))
57 if !params[:copy_workflow_from].blank? && (copy_from = Role.find_by_id(params[:copy_workflow_from]))
58 @role.workflow_rules.copy(copy_from)
58 @role.workflow_rules.copy(copy_from)
59 end
59 end
60 flash[:notice] = l(:notice_successful_create)
60 flash[:notice] = l(:notice_successful_create)
61 redirect_to roles_path
61 redirect_to roles_path
62 else
62 else
63 @roles = Role.sorted.all
63 @roles = Role.sorted.all
64 render :action => 'new'
64 render :action => 'new'
65 end
65 end
66 end
66 end
67
67
68 def edit
68 def edit
69 end
69 end
70
70
71 def update
71 def update
72 if request.put? and @role.update_attributes(params[:role])
72 if request.put? and @role.update_attributes(params[:role])
73 flash[:notice] = l(:notice_successful_update)
73 flash[:notice] = l(:notice_successful_update)
74 redirect_to roles_path
74 redirect_to roles_path
75 else
75 else
76 render :action => 'edit'
76 render :action => 'edit'
77 end
77 end
78 end
78 end
79
79
80 def destroy
80 def destroy
81 @role.destroy
81 @role.destroy
82 redirect_to roles_path
82 redirect_to roles_path
83 rescue
83 rescue
84 flash[:error] = l(:error_can_not_remove_role)
84 flash[:error] = l(:error_can_not_remove_role)
85 redirect_to roles_path
85 redirect_to roles_path
86 end
86 end
87
87
88 def permissions
88 def permissions
89 @roles = Role.sorted.all
89 @roles = Role.sorted.all
90 @permissions = Redmine::AccessControl.permissions.select { |p| !p.public? }
90 @permissions = Redmine::AccessControl.permissions.select { |p| !p.public? }
91 if request.post?
91 if request.post?
92 @roles.each do |role|
92 @roles.each do |role|
93 role.permissions = params[:permissions][role.id.to_s]
93 role.permissions = params[:permissions][role.id.to_s]
94 role.save
94 role.save
95 end
95 end
96 flash[:notice] = l(:notice_successful_update)
96 flash[:notice] = l(:notice_successful_update)
97 redirect_to roles_path
97 redirect_to roles_path
98 end
98 end
99 end
99 end
100
100
101 private
101 private
102
102
103 def find_role
103 def find_role
104 @role = Role.find(params[:id])
104 @role = Role.find(params[:id])
105 rescue ActiveRecord::RecordNotFound
105 rescue ActiveRecord::RecordNotFound
106 render_404
106 render_404
107 end
107 end
108 end
108 end
@@ -1,101 +1,101
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang
2 # Copyright (C) 2006-2012 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 'admin'
19 layout 'admin'
20
20
21 before_filter :require_admin, :except => :index
21 before_filter :require_admin, :except => :index
22 before_filter :require_admin_or_api_request, :only => :index
22 before_filter :require_admin_or_api_request, :only => :index
23 accept_api_auth :index
23 accept_api_auth :index
24
24
25 def index
25 def index
26 respond_to do |format|
26 respond_to do |format|
27 format.html {
27 format.html {
28 @tracker_pages, @trackers = paginate :trackers, :per_page => 10, :order => 'position'
28 @tracker_pages, @trackers = paginate Tracker.sorted, :per_page => 10
29 render :action => "index", :layout => false if request.xhr?
29 render :action => "index", :layout => false if request.xhr?
30 }
30 }
31 format.api {
31 format.api {
32 @trackers = Tracker.sorted.all
32 @trackers = Tracker.sorted.all
33 }
33 }
34 end
34 end
35 end
35 end
36
36
37 def new
37 def new
38 @tracker ||= Tracker.new(params[:tracker])
38 @tracker ||= Tracker.new(params[:tracker])
39 @trackers = Tracker.sorted.all
39 @trackers = Tracker.sorted.all
40 @projects = Project.all
40 @projects = Project.all
41 end
41 end
42
42
43 def create
43 def create
44 @tracker = Tracker.new(params[:tracker])
44 @tracker = Tracker.new(params[:tracker])
45 if @tracker.save
45 if @tracker.save
46 # workflow copy
46 # workflow copy
47 if !params[:copy_workflow_from].blank? && (copy_from = Tracker.find_by_id(params[:copy_workflow_from]))
47 if !params[:copy_workflow_from].blank? && (copy_from = Tracker.find_by_id(params[:copy_workflow_from]))
48 @tracker.workflow_rules.copy(copy_from)
48 @tracker.workflow_rules.copy(copy_from)
49 end
49 end
50 flash[:notice] = l(:notice_successful_create)
50 flash[:notice] = l(:notice_successful_create)
51 redirect_to trackers_path
51 redirect_to trackers_path
52 return
52 return
53 end
53 end
54 new
54 new
55 render :action => 'new'
55 render :action => 'new'
56 end
56 end
57
57
58 def edit
58 def edit
59 @tracker ||= Tracker.find(params[:id])
59 @tracker ||= Tracker.find(params[:id])
60 @projects = Project.all
60 @projects = Project.all
61 end
61 end
62
62
63 def update
63 def update
64 @tracker = Tracker.find(params[:id])
64 @tracker = Tracker.find(params[:id])
65 if @tracker.update_attributes(params[:tracker])
65 if @tracker.update_attributes(params[:tracker])
66 flash[:notice] = l(:notice_successful_update)
66 flash[:notice] = l(:notice_successful_update)
67 redirect_to trackers_path
67 redirect_to trackers_path
68 return
68 return
69 end
69 end
70 edit
70 edit
71 render :action => 'edit'
71 render :action => 'edit'
72 end
72 end
73
73
74 def destroy
74 def destroy
75 @tracker = Tracker.find(params[:id])
75 @tracker = Tracker.find(params[:id])
76 unless @tracker.issues.empty?
76 unless @tracker.issues.empty?
77 flash[:error] = l(:error_can_not_delete_tracker)
77 flash[:error] = l(:error_can_not_delete_tracker)
78 else
78 else
79 @tracker.destroy
79 @tracker.destroy
80 end
80 end
81 redirect_to trackers_path
81 redirect_to trackers_path
82 end
82 end
83
83
84 def fields
84 def fields
85 if request.post? && params[:trackers]
85 if request.post? && params[:trackers]
86 params[:trackers].each do |tracker_id, tracker_params|
86 params[:trackers].each do |tracker_id, tracker_params|
87 tracker = Tracker.find_by_id(tracker_id)
87 tracker = Tracker.find_by_id(tracker_id)
88 if tracker
88 if tracker
89 tracker.core_fields = tracker_params[:core_fields]
89 tracker.core_fields = tracker_params[:core_fields]
90 tracker.custom_field_ids = tracker_params[:custom_field_ids]
90 tracker.custom_field_ids = tracker_params[:custom_field_ids]
91 tracker.save
91 tracker.save
92 end
92 end
93 end
93 end
94 flash[:notice] = l(:notice_successful_update)
94 flash[:notice] = l(:notice_successful_update)
95 redirect_to fields_trackers_path
95 redirect_to fields_trackers_path
96 return
96 return
97 end
97 end
98 @trackers = Tracker.sorted.all
98 @trackers = Tracker.sorted.all
99 @custom_fields = IssueCustomField.all.sort
99 @custom_fields = IssueCustomField.all.sort
100 end
100 end
101 end
101 end
General Comments 0
You need to be logged in to leave comments. Login now