##// END OF EJS Templates
Eager load group projects to avoid N SQL queries....
Jean-Philippe Lang -
r3621:e417d755e94e
parent child
Show More
@@ -1,162 +1,162
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2009 Jean-Philippe Lang
2 # Copyright (C) 2006-2009 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 GroupsController < ApplicationController
18 class GroupsController < ApplicationController
19 layout 'admin'
19 layout 'admin'
20
20
21 before_filter :require_admin
21 before_filter :require_admin
22
22
23 helper :custom_fields
23 helper :custom_fields
24
24
25 # GET /groups
25 # GET /groups
26 # GET /groups.xml
26 # GET /groups.xml
27 def index
27 def index
28 @groups = Group.find(:all, :order => 'lastname')
28 @groups = Group.find(:all, :order => 'lastname')
29
29
30 respond_to do |format|
30 respond_to do |format|
31 format.html # index.html.erb
31 format.html # index.html.erb
32 format.xml { render :xml => @groups }
32 format.xml { render :xml => @groups }
33 end
33 end
34 end
34 end
35
35
36 # GET /groups/1
36 # GET /groups/1
37 # GET /groups/1.xml
37 # GET /groups/1.xml
38 def show
38 def show
39 @group = Group.find(params[:id])
39 @group = Group.find(params[:id])
40
40
41 respond_to do |format|
41 respond_to do |format|
42 format.html # show.html.erb
42 format.html # show.html.erb
43 format.xml { render :xml => @group }
43 format.xml { render :xml => @group }
44 end
44 end
45 end
45 end
46
46
47 # GET /groups/new
47 # GET /groups/new
48 # GET /groups/new.xml
48 # GET /groups/new.xml
49 def new
49 def new
50 @group = Group.new
50 @group = Group.new
51
51
52 respond_to do |format|
52 respond_to do |format|
53 format.html # new.html.erb
53 format.html # new.html.erb
54 format.xml { render :xml => @group }
54 format.xml { render :xml => @group }
55 end
55 end
56 end
56 end
57
57
58 # GET /groups/1/edit
58 # GET /groups/1/edit
59 def edit
59 def edit
60 @group = Group.find(params[:id])
60 @group = Group.find(params[:id], :include => :projects)
61 end
61 end
62
62
63 # POST /groups
63 # POST /groups
64 # POST /groups.xml
64 # POST /groups.xml
65 def create
65 def create
66 @group = Group.new(params[:group])
66 @group = Group.new(params[:group])
67
67
68 respond_to do |format|
68 respond_to do |format|
69 if @group.save
69 if @group.save
70 flash[:notice] = l(:notice_successful_create)
70 flash[:notice] = l(:notice_successful_create)
71 format.html { redirect_to(groups_path) }
71 format.html { redirect_to(groups_path) }
72 format.xml { render :xml => @group, :status => :created, :location => @group }
72 format.xml { render :xml => @group, :status => :created, :location => @group }
73 else
73 else
74 format.html { render :action => "new" }
74 format.html { render :action => "new" }
75 format.xml { render :xml => @group.errors, :status => :unprocessable_entity }
75 format.xml { render :xml => @group.errors, :status => :unprocessable_entity }
76 end
76 end
77 end
77 end
78 end
78 end
79
79
80 # PUT /groups/1
80 # PUT /groups/1
81 # PUT /groups/1.xml
81 # PUT /groups/1.xml
82 def update
82 def update
83 @group = Group.find(params[:id])
83 @group = Group.find(params[:id])
84
84
85 respond_to do |format|
85 respond_to do |format|
86 if @group.update_attributes(params[:group])
86 if @group.update_attributes(params[:group])
87 flash[:notice] = l(:notice_successful_update)
87 flash[:notice] = l(:notice_successful_update)
88 format.html { redirect_to(groups_path) }
88 format.html { redirect_to(groups_path) }
89 format.xml { head :ok }
89 format.xml { head :ok }
90 else
90 else
91 format.html { render :action => "edit" }
91 format.html { render :action => "edit" }
92 format.xml { render :xml => @group.errors, :status => :unprocessable_entity }
92 format.xml { render :xml => @group.errors, :status => :unprocessable_entity }
93 end
93 end
94 end
94 end
95 end
95 end
96
96
97 # DELETE /groups/1
97 # DELETE /groups/1
98 # DELETE /groups/1.xml
98 # DELETE /groups/1.xml
99 def destroy
99 def destroy
100 @group = Group.find(params[:id])
100 @group = Group.find(params[:id])
101 @group.destroy
101 @group.destroy
102
102
103 respond_to do |format|
103 respond_to do |format|
104 format.html { redirect_to(groups_url) }
104 format.html { redirect_to(groups_url) }
105 format.xml { head :ok }
105 format.xml { head :ok }
106 end
106 end
107 end
107 end
108
108
109 def add_users
109 def add_users
110 @group = Group.find(params[:id])
110 @group = Group.find(params[:id])
111 users = User.find_all_by_id(params[:user_ids])
111 users = User.find_all_by_id(params[:user_ids])
112 @group.users << users if request.post?
112 @group.users << users if request.post?
113 respond_to do |format|
113 respond_to do |format|
114 format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'users' }
114 format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'users' }
115 format.js {
115 format.js {
116 render(:update) {|page|
116 render(:update) {|page|
117 page.replace_html "tab-content-users", :partial => 'groups/users'
117 page.replace_html "tab-content-users", :partial => 'groups/users'
118 users.each {|user| page.visual_effect(:highlight, "user-#{user.id}") }
118 users.each {|user| page.visual_effect(:highlight, "user-#{user.id}") }
119 }
119 }
120 }
120 }
121 end
121 end
122 end
122 end
123
123
124 def remove_user
124 def remove_user
125 @group = Group.find(params[:id])
125 @group = Group.find(params[:id])
126 @group.users.delete(User.find(params[:user_id])) if request.post?
126 @group.users.delete(User.find(params[:user_id])) if request.post?
127 respond_to do |format|
127 respond_to do |format|
128 format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'users' }
128 format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'users' }
129 format.js { render(:update) {|page| page.replace_html "tab-content-users", :partial => 'groups/users'} }
129 format.js { render(:update) {|page| page.replace_html "tab-content-users", :partial => 'groups/users'} }
130 end
130 end
131 end
131 end
132
132
133 def autocomplete_for_user
133 def autocomplete_for_user
134 @group = Group.find(params[:id])
134 @group = Group.find(params[:id])
135 @users = User.active.like(params[:q]).find(:all, :limit => 100) - @group.users
135 @users = User.active.like(params[:q]).find(:all, :limit => 100) - @group.users
136 render :layout => false
136 render :layout => false
137 end
137 end
138
138
139 def edit_membership
139 def edit_membership
140 @group = Group.find(params[:id])
140 @group = Group.find(params[:id])
141 @membership = Member.edit_membership(params[:membership_id], params[:membership], @group)
141 @membership = Member.edit_membership(params[:membership_id], params[:membership], @group)
142 @membership.save if request.post?
142 @membership.save if request.post?
143 respond_to do |format|
143 respond_to do |format|
144 format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'memberships' }
144 format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'memberships' }
145 format.js {
145 format.js {
146 render(:update) {|page|
146 render(:update) {|page|
147 page.replace_html "tab-content-memberships", :partial => 'groups/memberships'
147 page.replace_html "tab-content-memberships", :partial => 'groups/memberships'
148 page.visual_effect(:highlight, "member-#{@membership.id}")
148 page.visual_effect(:highlight, "member-#{@membership.id}")
149 }
149 }
150 }
150 }
151 end
151 end
152 end
152 end
153
153
154 def destroy_membership
154 def destroy_membership
155 @group = Group.find(params[:id])
155 @group = Group.find(params[:id])
156 Member.find(params[:membership_id]).destroy if request.post?
156 Member.find(params[:membership_id]).destroy if request.post?
157 respond_to do |format|
157 respond_to do |format|
158 format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'memberships' }
158 format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'memberships' }
159 format.js { render(:update) {|page| page.replace_html "tab-content-memberships", :partial => 'groups/memberships'} }
159 format.js { render(:update) {|page| page.replace_html "tab-content-memberships", :partial => 'groups/memberships'} }
160 end
160 end
161 end
161 end
162 end
162 end
General Comments 0
You need to be logged in to leave comments. Login now