##// END OF EJS Templates
replaced deprecated find_all calls...
Jean-Philippe Lang -
r123:b3a3d3e2fab5
parent child
Show More
@@ -1,535 +1,535
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 ProjectsController < ApplicationController
18 class ProjectsController < ApplicationController
19 layout 'base'
19 layout 'base'
20 before_filter :find_project, :authorize, :except => [ :index, :list, :add ]
20 before_filter :find_project, :authorize, :except => [ :index, :list, :add ]
21 before_filter :require_admin, :only => [ :add, :destroy ]
21 before_filter :require_admin, :only => [ :add, :destroy ]
22
22
23 helper :sort
23 helper :sort
24 include SortHelper
24 include SortHelper
25 helper :custom_fields
25 helper :custom_fields
26 include CustomFieldsHelper
26 include CustomFieldsHelper
27 helper :ifpdf
27 helper :ifpdf
28 include IfpdfHelper
28 include IfpdfHelper
29 helper IssuesHelper
29 helper IssuesHelper
30 helper :queries
30 helper :queries
31 include QueriesHelper
31 include QueriesHelper
32
32
33 def index
33 def index
34 list
34 list
35 render :action => 'list' unless request.xhr?
35 render :action => 'list' unless request.xhr?
36 end
36 end
37
37
38 # Lists public projects
38 # Lists public projects
39 def list
39 def list
40 sort_init 'name', 'asc'
40 sort_init 'name', 'asc'
41 sort_update
41 sort_update
42 @project_count = Project.count(["is_public=?", true])
42 @project_count = Project.count(["is_public=?", true])
43 @project_pages = Paginator.new self, @project_count,
43 @project_pages = Paginator.new self, @project_count,
44 15,
44 15,
45 @params['page']
45 @params['page']
46 @projects = Project.find :all, :order => sort_clause,
46 @projects = Project.find :all, :order => sort_clause,
47 :conditions => ["is_public=?", true],
47 :conditions => ["is_public=?", true],
48 :limit => @project_pages.items_per_page,
48 :limit => @project_pages.items_per_page,
49 :offset => @project_pages.current.offset
49 :offset => @project_pages.current.offset
50
50
51 render :action => "list", :layout => false if request.xhr?
51 render :action => "list", :layout => false if request.xhr?
52 end
52 end
53
53
54 # Add a new project
54 # Add a new project
55 def add
55 def add
56 @custom_fields = IssueCustomField.find(:all)
56 @custom_fields = IssueCustomField.find(:all)
57 @root_projects = Project.find(:all, :conditions => "parent_id is null")
57 @root_projects = Project.find(:all, :conditions => "parent_id is null")
58 @project = Project.new(params[:project])
58 @project = Project.new(params[:project])
59 if request.get?
59 if request.get?
60 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project) }
60 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project) }
61 else
61 else
62 @project.custom_fields = CustomField.find(@params[:custom_field_ids]) if @params[:custom_field_ids]
62 @project.custom_fields = CustomField.find(@params[:custom_field_ids]) if @params[:custom_field_ids]
63 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
63 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
64 @project.custom_values = @custom_values
64 @project.custom_values = @custom_values
65 if params[:repository_enabled] && params[:repository_enabled] == "1"
65 if params[:repository_enabled] && params[:repository_enabled] == "1"
66 @project.repository = Repository.new
66 @project.repository = Repository.new
67 @project.repository.attributes = params[:repository]
67 @project.repository.attributes = params[:repository]
68 end
68 end
69 if @project.save
69 if @project.save
70 flash[:notice] = l(:notice_successful_create)
70 flash[:notice] = l(:notice_successful_create)
71 redirect_to :controller => 'admin', :action => 'projects'
71 redirect_to :controller => 'admin', :action => 'projects'
72 end
72 end
73 end
73 end
74 end
74 end
75
75
76 # Show @project
76 # Show @project
77 def show
77 def show
78 @custom_values = @project.custom_values.find(:all, :include => :custom_field)
78 @custom_values = @project.custom_values.find(:all, :include => :custom_field)
79 @members = @project.members.find(:all, :include => [:user, :role])
79 @members = @project.members.find(:all, :include => [:user, :role])
80 @subprojects = @project.children if @project.children_count > 0
80 @subprojects = @project.children if @project.children_count > 0
81 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "news.created_on DESC")
81 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "news.created_on DESC")
82 @trackers = Tracker.find(:all)
82 @trackers = Tracker.find(:all)
83 end
83 end
84
84
85 def settings
85 def settings
86 @root_projects = Project::find(:all, :conditions => ["parent_id is null and id <> ?", @project.id])
86 @root_projects = Project::find(:all, :conditions => ["parent_id is null and id <> ?", @project.id])
87 @custom_fields = IssueCustomField::find_all
87 @custom_fields = IssueCustomField.find(:all)
88 @issue_category ||= IssueCategory.new
88 @issue_category ||= IssueCategory.new
89 @member ||= @project.members.new
89 @member ||= @project.members.new
90 @roles = Role.find_all
90 @roles = Role.find(:all)
91 @users = User.find_all - @project.members.find(:all, :include => :user).collect{|m| m.user }
91 @users = User.find(:all) - @project.members.find(:all, :include => :user).collect{|m| m.user }
92 @custom_values ||= ProjectCustomField.find(:all).collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
92 @custom_values ||= ProjectCustomField.find(:all).collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
93 end
93 end
94
94
95 # Edit @project
95 # Edit @project
96 def edit
96 def edit
97 if request.post?
97 if request.post?
98 @project.custom_fields = IssueCustomField.find(@params[:custom_field_ids]) if @params[:custom_field_ids]
98 @project.custom_fields = IssueCustomField.find(@params[:custom_field_ids]) if @params[:custom_field_ids]
99 if params[:custom_fields]
99 if params[:custom_fields]
100 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
100 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
101 @project.custom_values = @custom_values
101 @project.custom_values = @custom_values
102 end
102 end
103 if params[:repository_enabled]
103 if params[:repository_enabled]
104 case params[:repository_enabled]
104 case params[:repository_enabled]
105 when "0"
105 when "0"
106 @project.repository = nil
106 @project.repository = nil
107 when "1"
107 when "1"
108 @project.repository ||= Repository.new
108 @project.repository ||= Repository.new
109 @project.repository.attributes = params[:repository]
109 @project.repository.attributes = params[:repository]
110 end
110 end
111 end
111 end
112 @project.attributes = params[:project]
112 @project.attributes = params[:project]
113 if @project.save
113 if @project.save
114 flash[:notice] = l(:notice_successful_update)
114 flash[:notice] = l(:notice_successful_update)
115 redirect_to :action => 'settings', :id => @project
115 redirect_to :action => 'settings', :id => @project
116 else
116 else
117 settings
117 settings
118 render :action => 'settings'
118 render :action => 'settings'
119 end
119 end
120 end
120 end
121 end
121 end
122
122
123 # Delete @project
123 # Delete @project
124 def destroy
124 def destroy
125 if request.post? and params[:confirm]
125 if request.post? and params[:confirm]
126 @project.destroy
126 @project.destroy
127 redirect_to :controller => 'admin', :action => 'projects'
127 redirect_to :controller => 'admin', :action => 'projects'
128 end
128 end
129 end
129 end
130
130
131 # Add a new issue category to @project
131 # Add a new issue category to @project
132 def add_issue_category
132 def add_issue_category
133 if request.post?
133 if request.post?
134 @issue_category = @project.issue_categories.build(params[:issue_category])
134 @issue_category = @project.issue_categories.build(params[:issue_category])
135 if @issue_category.save
135 if @issue_category.save
136 flash[:notice] = l(:notice_successful_create)
136 flash[:notice] = l(:notice_successful_create)
137 redirect_to :action => 'settings', :id => @project
137 redirect_to :action => 'settings', :id => @project
138 else
138 else
139 settings
139 settings
140 render :action => 'settings'
140 render :action => 'settings'
141 end
141 end
142 end
142 end
143 end
143 end
144
144
145 # Add a new version to @project
145 # Add a new version to @project
146 def add_version
146 def add_version
147 @version = @project.versions.build(params[:version])
147 @version = @project.versions.build(params[:version])
148 if request.post? and @version.save
148 if request.post? and @version.save
149 flash[:notice] = l(:notice_successful_create)
149 flash[:notice] = l(:notice_successful_create)
150 redirect_to :action => 'settings', :id => @project
150 redirect_to :action => 'settings', :id => @project
151 end
151 end
152 end
152 end
153
153
154 # Add a new member to @project
154 # Add a new member to @project
155 def add_member
155 def add_member
156 @member = @project.members.build(params[:member])
156 @member = @project.members.build(params[:member])
157 if request.post?
157 if request.post?
158 if @member.save
158 if @member.save
159 flash[:notice] = l(:notice_successful_create)
159 flash[:notice] = l(:notice_successful_create)
160 redirect_to :action => 'settings', :id => @project
160 redirect_to :action => 'settings', :id => @project
161 else
161 else
162 settings
162 settings
163 render :action => 'settings'
163 render :action => 'settings'
164 end
164 end
165 end
165 end
166 end
166 end
167
167
168 # Show members list of @project
168 # Show members list of @project
169 def list_members
169 def list_members
170 @members = @project.members
170 @members = @project.members
171 end
171 end
172
172
173 # Add a new document to @project
173 # Add a new document to @project
174 def add_document
174 def add_document
175 @categories = Enumeration::get_values('DCAT')
175 @categories = Enumeration::get_values('DCAT')
176 @document = @project.documents.build(params[:document])
176 @document = @project.documents.build(params[:document])
177 if request.post?
177 if request.post?
178 # Save the attachment
178 # Save the attachment
179 if params[:attachment][:file].size > 0
179 if params[:attachment][:file].size > 0
180 @attachment = @document.attachments.build(params[:attachment])
180 @attachment = @document.attachments.build(params[:attachment])
181 @attachment.author_id = self.logged_in_user.id if self.logged_in_user
181 @attachment.author_id = self.logged_in_user.id if self.logged_in_user
182 end
182 end
183 if @document.save
183 if @document.save
184 flash[:notice] = l(:notice_successful_create)
184 flash[:notice] = l(:notice_successful_create)
185 redirect_to :action => 'list_documents', :id => @project
185 redirect_to :action => 'list_documents', :id => @project
186 end
186 end
187 end
187 end
188 end
188 end
189
189
190 # Show documents list of @project
190 # Show documents list of @project
191 def list_documents
191 def list_documents
192 @documents = @project.documents.find :all, :include => :category
192 @documents = @project.documents.find :all, :include => :category
193 end
193 end
194
194
195 # Add a new issue to @project
195 # Add a new issue to @project
196 def add_issue
196 def add_issue
197 @tracker = Tracker.find(params[:tracker_id])
197 @tracker = Tracker.find(params[:tracker_id])
198 @priorities = Enumeration::get_values('IPRI')
198 @priorities = Enumeration::get_values('IPRI')
199 @issue = Issue.new(:project => @project, :tracker => @tracker)
199 @issue = Issue.new(:project => @project, :tracker => @tracker)
200 if request.get?
200 if request.get?
201 @issue.start_date = Date.today
201 @issue.start_date = Date.today
202 @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) }
202 @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) }
203 else
203 else
204 @issue.attributes = params[:issue]
204 @issue.attributes = params[:issue]
205 @issue.author_id = self.logged_in_user.id if self.logged_in_user
205 @issue.author_id = self.logged_in_user.id if self.logged_in_user
206 # Multiple file upload
206 # Multiple file upload
207 @attachments = []
207 @attachments = []
208 params[:attachments].each { |a|
208 params[:attachments].each { |a|
209 @attachments << Attachment.new(:container => @issue, :file => a, :author => logged_in_user) unless a.size == 0
209 @attachments << Attachment.new(:container => @issue, :file => a, :author => logged_in_user) unless a.size == 0
210 } if params[:attachments] and params[:attachments].is_a? Array
210 } if params[:attachments] and params[:attachments].is_a? Array
211 @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue, :value => params["custom_fields"][x.id.to_s]) }
211 @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue, :value => params["custom_fields"][x.id.to_s]) }
212 @issue.custom_values = @custom_values
212 @issue.custom_values = @custom_values
213 if @issue.save
213 if @issue.save
214 @attachments.each(&:save)
214 @attachments.each(&:save)
215 flash[:notice] = l(:notice_successful_create)
215 flash[:notice] = l(:notice_successful_create)
216 Mailer.deliver_issue_add(@issue) if Permission.find_by_controller_and_action(@params[:controller], @params[:action]).mail_enabled?
216 Mailer.deliver_issue_add(@issue) if Permission.find_by_controller_and_action(@params[:controller], @params[:action]).mail_enabled?
217 redirect_to :action => 'list_issues', :id => @project
217 redirect_to :action => 'list_issues', :id => @project
218 end
218 end
219 end
219 end
220 end
220 end
221
221
222 # Show filtered/sorted issues list of @project
222 # Show filtered/sorted issues list of @project
223 def list_issues
223 def list_issues
224 sort_init 'issues.id', 'desc'
224 sort_init 'issues.id', 'desc'
225 sort_update
225 sort_update
226
226
227 retrieve_query
227 retrieve_query
228
228
229 @results_per_page_options = [ 15, 25, 50, 100 ]
229 @results_per_page_options = [ 15, 25, 50, 100 ]
230 if params[:per_page] and @results_per_page_options.include? params[:per_page].to_i
230 if params[:per_page] and @results_per_page_options.include? params[:per_page].to_i
231 @results_per_page = params[:per_page].to_i
231 @results_per_page = params[:per_page].to_i
232 session[:results_per_page] = @results_per_page
232 session[:results_per_page] = @results_per_page
233 else
233 else
234 @results_per_page = session[:results_per_page] || 25
234 @results_per_page = session[:results_per_page] || 25
235 end
235 end
236
236
237 if @query.valid?
237 if @query.valid?
238 @issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement)
238 @issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement)
239 @issue_pages = Paginator.new self, @issue_count, @results_per_page, @params['page']
239 @issue_pages = Paginator.new self, @issue_count, @results_per_page, @params['page']
240 @issues = Issue.find :all, :order => sort_clause,
240 @issues = Issue.find :all, :order => sort_clause,
241 :include => [ :author, :status, :tracker, :project ],
241 :include => [ :author, :status, :tracker, :project ],
242 :conditions => @query.statement,
242 :conditions => @query.statement,
243 :limit => @issue_pages.items_per_page,
243 :limit => @issue_pages.items_per_page,
244 :offset => @issue_pages.current.offset
244 :offset => @issue_pages.current.offset
245 end
245 end
246 render :layout => false if request.xhr?
246 render :layout => false if request.xhr?
247 end
247 end
248
248
249 # Export filtered/sorted issues list to CSV
249 # Export filtered/sorted issues list to CSV
250 def export_issues_csv
250 def export_issues_csv
251 sort_init 'issues.id', 'desc'
251 sort_init 'issues.id', 'desc'
252 sort_update
252 sort_update
253
253
254 retrieve_query
254 retrieve_query
255 render :action => 'list_issues' and return unless @query.valid?
255 render :action => 'list_issues' and return unless @query.valid?
256
256
257 @issues = Issue.find :all, :order => sort_clause,
257 @issues = Issue.find :all, :order => sort_clause,
258 :include => [ :author, :status, :tracker, :project, :custom_values ],
258 :include => [ :author, :status, :tracker, :project, :custom_values ],
259 :conditions => @query.statement
259 :conditions => @query.statement
260
260
261 ic = Iconv.new('ISO-8859-1', 'UTF-8')
261 ic = Iconv.new('ISO-8859-1', 'UTF-8')
262 export = StringIO.new
262 export = StringIO.new
263 CSV::Writer.generate(export, l(:general_csv_separator)) do |csv|
263 CSV::Writer.generate(export, l(:general_csv_separator)) do |csv|
264 # csv header fields
264 # csv header fields
265 headers = [ "#", l(:field_status), l(:field_tracker), l(:field_subject), l(:field_author), l(:field_created_on), l(:field_updated_on) ]
265 headers = [ "#", l(:field_status), l(:field_tracker), l(:field_subject), l(:field_author), l(:field_created_on), l(:field_updated_on) ]
266 for custom_field in @project.all_custom_fields
266 for custom_field in @project.all_custom_fields
267 headers << custom_field.name
267 headers << custom_field.name
268 end
268 end
269 csv << headers.collect {|c| ic.iconv(c) }
269 csv << headers.collect {|c| ic.iconv(c) }
270 # csv lines
270 # csv lines
271 @issues.each do |issue|
271 @issues.each do |issue|
272 fields = [issue.id, issue.status.name, issue.tracker.name, issue.subject, issue.author.display_name, l_datetime(issue.created_on), l_datetime(issue.updated_on)]
272 fields = [issue.id, issue.status.name, issue.tracker.name, issue.subject, issue.author.display_name, l_datetime(issue.created_on), l_datetime(issue.updated_on)]
273 for custom_field in @project.all_custom_fields
273 for custom_field in @project.all_custom_fields
274 fields << (show_value issue.custom_value_for(custom_field))
274 fields << (show_value issue.custom_value_for(custom_field))
275 end
275 end
276 csv << fields.collect {|c| ic.iconv(c.to_s) }
276 csv << fields.collect {|c| ic.iconv(c.to_s) }
277 end
277 end
278 end
278 end
279 export.rewind
279 export.rewind
280 send_data(export.read, :type => 'text/csv; header=present', :filename => 'export.csv')
280 send_data(export.read, :type => 'text/csv; header=present', :filename => 'export.csv')
281 end
281 end
282
282
283 # Export filtered/sorted issues to PDF
283 # Export filtered/sorted issues to PDF
284 def export_issues_pdf
284 def export_issues_pdf
285 sort_init 'issues.id', 'desc'
285 sort_init 'issues.id', 'desc'
286 sort_update
286 sort_update
287
287
288 retrieve_query
288 retrieve_query
289 render :action => 'list_issues' and return unless @query.valid?
289 render :action => 'list_issues' and return unless @query.valid?
290
290
291 @issues = Issue.find :all, :order => sort_clause,
291 @issues = Issue.find :all, :order => sort_clause,
292 :include => [ :author, :status, :tracker, :project, :custom_values ],
292 :include => [ :author, :status, :tracker, :project, :custom_values ],
293 :conditions => @query.statement
293 :conditions => @query.statement
294
294
295 @options_for_rfpdf ||= {}
295 @options_for_rfpdf ||= {}
296 @options_for_rfpdf[:file_name] = "export.pdf"
296 @options_for_rfpdf[:file_name] = "export.pdf"
297 render :layout => false
297 render :layout => false
298 end
298 end
299
299
300 def move_issues
300 def move_issues
301 @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids]
301 @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids]
302 redirect_to :action => 'list_issues', :id => @project and return unless @issues
302 redirect_to :action => 'list_issues', :id => @project and return unless @issues
303 @projects = []
303 @projects = []
304 # find projects to which the user is allowed to move the issue
304 # find projects to which the user is allowed to move the issue
305 @logged_in_user.memberships.each {|m| @projects << m.project if Permission.allowed_to_role("projects/move_issues", m.role_id)}
305 @logged_in_user.memberships.each {|m| @projects << m.project if Permission.allowed_to_role("projects/move_issues", m.role_id)}
306 # issue can be moved to any tracker
306 # issue can be moved to any tracker
307 @trackers = Tracker.find(:all)
307 @trackers = Tracker.find(:all)
308 if request.post? and params[:new_project_id] and params[:new_tracker_id]
308 if request.post? and params[:new_project_id] and params[:new_tracker_id]
309 new_project = Project.find(params[:new_project_id])
309 new_project = Project.find(params[:new_project_id])
310 new_tracker = Tracker.find(params[:new_tracker_id])
310 new_tracker = Tracker.find(params[:new_tracker_id])
311 @issues.each { |i|
311 @issues.each { |i|
312 # project dependent properties
312 # project dependent properties
313 unless i.project_id == new_project.id
313 unless i.project_id == new_project.id
314 i.category = nil
314 i.category = nil
315 i.fixed_version = nil
315 i.fixed_version = nil
316 end
316 end
317 # move the issue
317 # move the issue
318 i.project = new_project
318 i.project = new_project
319 i.tracker = new_tracker
319 i.tracker = new_tracker
320 i.save
320 i.save
321 }
321 }
322 flash[:notice] = l(:notice_successful_update)
322 flash[:notice] = l(:notice_successful_update)
323 redirect_to :action => 'list_issues', :id => @project
323 redirect_to :action => 'list_issues', :id => @project
324 end
324 end
325 end
325 end
326
326
327 def add_query
327 def add_query
328 @query = Query.new(params[:query])
328 @query = Query.new(params[:query])
329 @query.project = @project
329 @query.project = @project
330 @query.user = logged_in_user
330 @query.user = logged_in_user
331
331
332 params[:fields].each do |field|
332 params[:fields].each do |field|
333 @query.add_filter(field, params[:operators][field], params[:values][field])
333 @query.add_filter(field, params[:operators][field], params[:values][field])
334 end if params[:fields]
334 end if params[:fields]
335
335
336 if request.post? and @query.save
336 if request.post? and @query.save
337 flash[:notice] = l(:notice_successful_create)
337 flash[:notice] = l(:notice_successful_create)
338 redirect_to :controller => 'reports', :action => 'issue_report', :id => @project
338 redirect_to :controller => 'reports', :action => 'issue_report', :id => @project
339 end
339 end
340 render :layout => false if request.xhr?
340 render :layout => false if request.xhr?
341 end
341 end
342
342
343 # Add a news to @project
343 # Add a news to @project
344 def add_news
344 def add_news
345 @news = News.new(:project => @project)
345 @news = News.new(:project => @project)
346 if request.post?
346 if request.post?
347 @news.attributes = params[:news]
347 @news.attributes = params[:news]
348 @news.author_id = self.logged_in_user.id if self.logged_in_user
348 @news.author_id = self.logged_in_user.id if self.logged_in_user
349 if @news.save
349 if @news.save
350 flash[:notice] = l(:notice_successful_create)
350 flash[:notice] = l(:notice_successful_create)
351 redirect_to :action => 'list_news', :id => @project
351 redirect_to :action => 'list_news', :id => @project
352 end
352 end
353 end
353 end
354 end
354 end
355
355
356 # Show news list of @project
356 # Show news list of @project
357 def list_news
357 def list_news
358 @news_pages, @news = paginate :news, :per_page => 10, :conditions => ["project_id=?", @project.id], :include => :author, :order => "news.created_on DESC"
358 @news_pages, @news = paginate :news, :per_page => 10, :conditions => ["project_id=?", @project.id], :include => :author, :order => "news.created_on DESC"
359 render :action => "list_news", :layout => false if request.xhr?
359 render :action => "list_news", :layout => false if request.xhr?
360 end
360 end
361
361
362 def add_file
362 def add_file
363 @attachment = Attachment.new(params[:attachment])
363 @attachment = Attachment.new(params[:attachment])
364 if request.post? and params[:attachment][:file].size > 0
364 if request.post? and params[:attachment][:file].size > 0
365 @attachment.container = @project.versions.find_by_id(params[:version_id])
365 @attachment.container = @project.versions.find_by_id(params[:version_id])
366 @attachment.author = logged_in_user
366 @attachment.author = logged_in_user
367 if @attachment.save
367 if @attachment.save
368 flash[:notice] = l(:notice_successful_create)
368 flash[:notice] = l(:notice_successful_create)
369 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
369 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
370 end
370 end
371 end
371 end
372 @versions = @project.versions
372 @versions = @project.versions
373 end
373 end
374
374
375 def list_files
375 def list_files
376 @versions = @project.versions
376 @versions = @project.versions
377 end
377 end
378
378
379 # Show changelog for @project
379 # Show changelog for @project
380 def changelog
380 def changelog
381 @trackers = Tracker.find(:all, :conditions => ["is_in_chlog=?", true])
381 @trackers = Tracker.find(:all, :conditions => ["is_in_chlog=?", true])
382 if request.get?
382 if request.get?
383 @selected_tracker_ids = @trackers.collect {|t| t.id.to_s }
383 @selected_tracker_ids = @trackers.collect {|t| t.id.to_s }
384 else
384 else
385 @selected_tracker_ids = params[:tracker_ids].collect { |id| id.to_i.to_s } if params[:tracker_ids] and params[:tracker_ids].is_a? Array
385 @selected_tracker_ids = params[:tracker_ids].collect { |id| id.to_i.to_s } if params[:tracker_ids] and params[:tracker_ids].is_a? Array
386 end
386 end
387 @selected_tracker_ids ||= []
387 @selected_tracker_ids ||= []
388 @fixed_issues = @project.issues.find(:all,
388 @fixed_issues = @project.issues.find(:all,
389 :include => [ :fixed_version, :status, :tracker ],
389 :include => [ :fixed_version, :status, :tracker ],
390 :conditions => [ "issue_statuses.is_closed=? and issues.tracker_id in (#{@selected_tracker_ids.join(',')}) and issues.fixed_version_id is not null", true],
390 :conditions => [ "issue_statuses.is_closed=? and issues.tracker_id in (#{@selected_tracker_ids.join(',')}) and issues.fixed_version_id is not null", true],
391 :order => "versions.effective_date DESC, issues.id DESC"
391 :order => "versions.effective_date DESC, issues.id DESC"
392 ) unless @selected_tracker_ids.empty?
392 ) unless @selected_tracker_ids.empty?
393 @fixed_issues ||= []
393 @fixed_issues ||= []
394 end
394 end
395
395
396 def activity
396 def activity
397 if params[:year] and params[:year].to_i > 1900
397 if params[:year] and params[:year].to_i > 1900
398 @year = params[:year].to_i
398 @year = params[:year].to_i
399 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
399 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
400 @month = params[:month].to_i
400 @month = params[:month].to_i
401 end
401 end
402 end
402 end
403 @year ||= Date.today.year
403 @year ||= Date.today.year
404 @month ||= Date.today.month
404 @month ||= Date.today.month
405
405
406 @date_from = Date.civil(@year, @month, 1)
406 @date_from = Date.civil(@year, @month, 1)
407 @date_to = (@date_from >> 1)-1
407 @date_to = (@date_from >> 1)-1
408
408
409 @events_by_day = {}
409 @events_by_day = {}
410
410
411 unless params[:show_issues] == "0"
411 unless params[:show_issues] == "0"
412 @project.issues.find(:all, :include => [:author, :status], :conditions => ["issues.created_on>=? and issues.created_on<=?", @date_from, @date_to] ).each { |i|
412 @project.issues.find(:all, :include => [:author, :status], :conditions => ["issues.created_on>=? and issues.created_on<=?", @date_from, @date_to] ).each { |i|
413 @events_by_day[i.created_on.to_date] ||= []
413 @events_by_day[i.created_on.to_date] ||= []
414 @events_by_day[i.created_on.to_date] << i
414 @events_by_day[i.created_on.to_date] << i
415 }
415 }
416 @show_issues = 1
416 @show_issues = 1
417 end
417 end
418
418
419 unless params[:show_news] == "0"
419 unless params[:show_news] == "0"
420 @project.news.find(:all, :conditions => ["news.created_on>=? and news.created_on<=?", @date_from, @date_to], :include => :author ).each { |i|
420 @project.news.find(:all, :conditions => ["news.created_on>=? and news.created_on<=?", @date_from, @date_to], :include => :author ).each { |i|
421 @events_by_day[i.created_on.to_date] ||= []
421 @events_by_day[i.created_on.to_date] ||= []
422 @events_by_day[i.created_on.to_date] << i
422 @events_by_day[i.created_on.to_date] << i
423 }
423 }
424 @show_news = 1
424 @show_news = 1
425 end
425 end
426
426
427 unless params[:show_files] == "0"
427 unless params[:show_files] == "0"
428 Attachment.find(:all, :select => "attachments.*", :joins => "LEFT JOIN versions ON versions.id = attachments.container_id", :conditions => ["attachments.container_type='Version' and versions.project_id=? and attachments.created_on>=? and attachments.created_on<=?", @project.id, @date_from, @date_to], :include => :author ).each { |i|
428 Attachment.find(:all, :select => "attachments.*", :joins => "LEFT JOIN versions ON versions.id = attachments.container_id", :conditions => ["attachments.container_type='Version' and versions.project_id=? and attachments.created_on>=? and attachments.created_on<=?", @project.id, @date_from, @date_to], :include => :author ).each { |i|
429 @events_by_day[i.created_on.to_date] ||= []
429 @events_by_day[i.created_on.to_date] ||= []
430 @events_by_day[i.created_on.to_date] << i
430 @events_by_day[i.created_on.to_date] << i
431 }
431 }
432 @show_files = 1
432 @show_files = 1
433 end
433 end
434
434
435 unless params[:show_documents] == "0"
435 unless params[:show_documents] == "0"
436 @project.documents.find(:all, :conditions => ["documents.created_on>=? and documents.created_on<=?", @date_from, @date_to] ).each { |i|
436 @project.documents.find(:all, :conditions => ["documents.created_on>=? and documents.created_on<=?", @date_from, @date_to] ).each { |i|
437 @events_by_day[i.created_on.to_date] ||= []
437 @events_by_day[i.created_on.to_date] ||= []
438 @events_by_day[i.created_on.to_date] << i
438 @events_by_day[i.created_on.to_date] << i
439 }
439 }
440 Attachment.find(:all, :select => "attachments.*", :joins => "LEFT JOIN documents ON documents.id = attachments.container_id", :conditions => ["attachments.container_type='Document' and documents.project_id=? and attachments.created_on>=? and attachments.created_on<=?", @project.id, @date_from, @date_to], :include => :author ).each { |i|
440 Attachment.find(:all, :select => "attachments.*", :joins => "LEFT JOIN documents ON documents.id = attachments.container_id", :conditions => ["attachments.container_type='Document' and documents.project_id=? and attachments.created_on>=? and attachments.created_on<=?", @project.id, @date_from, @date_to], :include => :author ).each { |i|
441 @events_by_day[i.created_on.to_date] ||= []
441 @events_by_day[i.created_on.to_date] ||= []
442 @events_by_day[i.created_on.to_date] << i
442 @events_by_day[i.created_on.to_date] << i
443 }
443 }
444 @show_documents = 1
444 @show_documents = 1
445 end
445 end
446
446
447 render :layout => false if request.xhr?
447 render :layout => false if request.xhr?
448 end
448 end
449
449
450 def calendar
450 def calendar
451 if params[:year] and params[:year].to_i > 1900
451 if params[:year] and params[:year].to_i > 1900
452 @year = params[:year].to_i
452 @year = params[:year].to_i
453 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
453 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
454 @month = params[:month].to_i
454 @month = params[:month].to_i
455 end
455 end
456 end
456 end
457 @year ||= Date.today.year
457 @year ||= Date.today.year
458 @month ||= Date.today.month
458 @month ||= Date.today.month
459
459
460 @date_from = Date.civil(@year, @month, 1)
460 @date_from = Date.civil(@year, @month, 1)
461 @date_to = (@date_from >> 1)-1
461 @date_to = (@date_from >> 1)-1
462 # start on monday
462 # start on monday
463 @date_from = @date_from - (@date_from.cwday-1)
463 @date_from = @date_from - (@date_from.cwday-1)
464 # finish on sunday
464 # finish on sunday
465 @date_to = @date_to + (7-@date_to.cwday)
465 @date_to = @date_to + (7-@date_to.cwday)
466
466
467 @issues = @project.issues.find(:all, :include => :tracker, :conditions => ["((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?))", @date_from, @date_to, @date_from, @date_to])
467 @issues = @project.issues.find(:all, :include => :tracker, :conditions => ["((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?))", @date_from, @date_to, @date_from, @date_to])
468 render :layout => false if request.xhr?
468 render :layout => false if request.xhr?
469 end
469 end
470
470
471 def gantt
471 def gantt
472 if params[:year] and params[:year].to_i >0
472 if params[:year] and params[:year].to_i >0
473 @year_from = params[:year].to_i
473 @year_from = params[:year].to_i
474 if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12
474 if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12
475 @month_from = params[:month].to_i
475 @month_from = params[:month].to_i
476 else
476 else
477 @month_from = 1
477 @month_from = 1
478 end
478 end
479 else
479 else
480 @month_from ||= (Date.today << 1).month
480 @month_from ||= (Date.today << 1).month
481 @year_from ||= (Date.today << 1).year
481 @year_from ||= (Date.today << 1).year
482 end
482 end
483
483
484 @zoom = (params[:zoom].to_i > 0 and params[:zoom].to_i < 5) ? params[:zoom].to_i : 2
484 @zoom = (params[:zoom].to_i > 0 and params[:zoom].to_i < 5) ? params[:zoom].to_i : 2
485 @months = (params[:months].to_i > 0 and params[:months].to_i < 25) ? params[:months].to_i : 6
485 @months = (params[:months].to_i > 0 and params[:months].to_i < 25) ? params[:months].to_i : 6
486
486
487 @date_from = Date.civil(@year_from, @month_from, 1)
487 @date_from = Date.civil(@year_from, @month_from, 1)
488 @date_to = (@date_from >> @months) - 1
488 @date_to = (@date_from >> @months) - 1
489 @issues = @project.issues.find(:all, :order => "start_date, due_date", :conditions => ["(((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?) or (start_date<? and due_date>?)) and start_date is not null and due_date is not null)", @date_from, @date_to, @date_from, @date_to, @date_from, @date_to])
489 @issues = @project.issues.find(:all, :order => "start_date, due_date", :conditions => ["(((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?) or (start_date<? and due_date>?)) and start_date is not null and due_date is not null)", @date_from, @date_to, @date_from, @date_to, @date_from, @date_to])
490
490
491 if params[:output]=='pdf'
491 if params[:output]=='pdf'
492 @options_for_rfpdf ||= {}
492 @options_for_rfpdf ||= {}
493 @options_for_rfpdf[:file_name] = "gantt.pdf"
493 @options_for_rfpdf[:file_name] = "gantt.pdf"
494 render :template => "projects/gantt.rfpdf", :layout => false
494 render :template => "projects/gantt.rfpdf", :layout => false
495 else
495 else
496 render :template => "projects/gantt.rhtml"
496 render :template => "projects/gantt.rhtml"
497 end
497 end
498 end
498 end
499
499
500 private
500 private
501 # Find project of id params[:id]
501 # Find project of id params[:id]
502 # if not found, redirect to project list
502 # if not found, redirect to project list
503 # Used as a before_filter
503 # Used as a before_filter
504 def find_project
504 def find_project
505 @project = Project.find(params[:id])
505 @project = Project.find(params[:id])
506 @html_title = @project.name
506 @html_title = @project.name
507 rescue
507 rescue
508 redirect_to :action => 'list'
508 redirect_to :action => 'list'
509 end
509 end
510
510
511 # Retrieve query from session or build a new query
511 # Retrieve query from session or build a new query
512 def retrieve_query
512 def retrieve_query
513 if params[:query_id]
513 if params[:query_id]
514 @query = @project.queries.find(params[:query_id])
514 @query = @project.queries.find(params[:query_id])
515 else
515 else
516 if params[:set_filter] or !session[:query] or session[:query].project_id != @project.id
516 if params[:set_filter] or !session[:query] or session[:query].project_id != @project.id
517 # Give it a name, required to be valid
517 # Give it a name, required to be valid
518 @query = Query.new(:name => "_")
518 @query = Query.new(:name => "_")
519 @query.project = @project
519 @query.project = @project
520 if params[:fields] and params[:fields].is_a? Array
520 if params[:fields] and params[:fields].is_a? Array
521 params[:fields].each do |field|
521 params[:fields].each do |field|
522 @query.add_filter(field, params[:operators][field], params[:values][field])
522 @query.add_filter(field, params[:operators][field], params[:values][field])
523 end
523 end
524 else
524 else
525 @query.available_filters.keys.each do |field|
525 @query.available_filters.keys.each do |field|
526 @query.add_short_filter(field, params[field]) if params[field]
526 @query.add_short_filter(field, params[field]) if params[field]
527 end
527 end
528 end
528 end
529 session[:query] = @query
529 session[:query] = @query
530 else
530 else
531 @query = session[:query]
531 @query = session[:query]
532 end
532 end
533 end
533 end
534 end
534 end
535 end
535 end
@@ -1,165 +1,165
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 ReportsController < ApplicationController
18 class ReportsController < ApplicationController
19 layout 'base'
19 layout 'base'
20 before_filter :find_project, :authorize
20 before_filter :find_project, :authorize
21
21
22 def issue_report
22 def issue_report
23 @statuses = IssueStatus.find_all
23 @statuses = IssueStatus.find :all
24
24
25 case params[:detail]
25 case params[:detail]
26 when "tracker"
26 when "tracker"
27 @field = "tracker_id"
27 @field = "tracker_id"
28 @rows = Tracker.find_all
28 @rows = Tracker.find :all
29 @data = issues_by_tracker
29 @data = issues_by_tracker
30 @report_title = l(:field_tracker)
30 @report_title = l(:field_tracker)
31 render :template => "reports/issue_report_details"
31 render :template => "reports/issue_report_details"
32 when "priority"
32 when "priority"
33 @field = "priority_id"
33 @field = "priority_id"
34 @rows = Enumeration::get_values('IPRI')
34 @rows = Enumeration::get_values('IPRI')
35 @data = issues_by_priority
35 @data = issues_by_priority
36 @report_title = l(:field_priority)
36 @report_title = l(:field_priority)
37 render :template => "reports/issue_report_details"
37 render :template => "reports/issue_report_details"
38 when "category"
38 when "category"
39 @field = "category_id"
39 @field = "category_id"
40 @rows = @project.issue_categories
40 @rows = @project.issue_categories
41 @data = issues_by_category
41 @data = issues_by_category
42 @report_title = l(:field_category)
42 @report_title = l(:field_category)
43 render :template => "reports/issue_report_details"
43 render :template => "reports/issue_report_details"
44 when "author"
44 when "author"
45 @field = "author_id"
45 @field = "author_id"
46 @rows = @project.members.collect { |m| m.user }
46 @rows = @project.members.collect { |m| m.user }
47 @data = issues_by_author
47 @data = issues_by_author
48 @report_title = l(:field_author)
48 @report_title = l(:field_author)
49 render :template => "reports/issue_report_details"
49 render :template => "reports/issue_report_details"
50 else
50 else
51 @queries = @project.queries.find :all, :conditions => ["is_public=? or user_id=?", true, (logged_in_user ? logged_in_user.id : 0)]
51 @queries = @project.queries.find :all, :conditions => ["is_public=? or user_id=?", true, (logged_in_user ? logged_in_user.id : 0)]
52 @trackers = Tracker.find(:all)
52 @trackers = Tracker.find(:all)
53 @priorities = Enumeration::get_values('IPRI')
53 @priorities = Enumeration::get_values('IPRI')
54 @categories = @project.issue_categories
54 @categories = @project.issue_categories
55 @authors = @project.members.collect { |m| m.user }
55 @authors = @project.members.collect { |m| m.user }
56 issues_by_tracker
56 issues_by_tracker
57 issues_by_priority
57 issues_by_priority
58 issues_by_category
58 issues_by_category
59 issues_by_author
59 issues_by_author
60 render :template => "reports/issue_report"
60 render :template => "reports/issue_report"
61 end
61 end
62 end
62 end
63
63
64 def delays
64 def delays
65 @trackers = Tracker.find(:all)
65 @trackers = Tracker.find(:all)
66 if request.get?
66 if request.get?
67 @selected_tracker_ids = @trackers.collect {|t| t.id.to_s }
67 @selected_tracker_ids = @trackers.collect {|t| t.id.to_s }
68 else
68 else
69 @selected_tracker_ids = params[:tracker_ids].collect { |id| id.to_i.to_s } if params[:tracker_ids] and params[:tracker_ids].is_a? Array
69 @selected_tracker_ids = params[:tracker_ids].collect { |id| id.to_i.to_s } if params[:tracker_ids] and params[:tracker_ids].is_a? Array
70 end
70 end
71 @selected_tracker_ids ||= []
71 @selected_tracker_ids ||= []
72 @raw =
72 @raw =
73 ActiveRecord::Base.connection.select_all("SELECT datediff( a.created_on, b.created_on ) as delay, count(a.id) as total
73 ActiveRecord::Base.connection.select_all("SELECT datediff( a.created_on, b.created_on ) as delay, count(a.id) as total
74 FROM issue_histories a, issue_histories b, issues i
74 FROM issue_histories a, issue_histories b, issues i
75 WHERE a.status_id =5
75 WHERE a.status_id =5
76 AND a.issue_id = b.issue_id
76 AND a.issue_id = b.issue_id
77 AND a.issue_id = i.id
77 AND a.issue_id = i.id
78 AND i.tracker_id in (#{@selected_tracker_ids.join(',')})
78 AND i.tracker_id in (#{@selected_tracker_ids.join(',')})
79 AND b.id = (
79 AND b.id = (
80 SELECT min( c.id )
80 SELECT min( c.id )
81 FROM issue_histories c
81 FROM issue_histories c
82 WHERE b.issue_id = c.issue_id )
82 WHERE b.issue_id = c.issue_id )
83 GROUP BY delay") unless @selected_tracker_ids.empty?
83 GROUP BY delay") unless @selected_tracker_ids.empty?
84 @raw ||=[]
84 @raw ||=[]
85
85
86 @x_from = 0
86 @x_from = 0
87 @x_to = 0
87 @x_to = 0
88 @y_from = 0
88 @y_from = 0
89 @y_to = 0
89 @y_to = 0
90 @sum_total = 0
90 @sum_total = 0
91 @sum_delay = 0
91 @sum_delay = 0
92 @raw.each do |r|
92 @raw.each do |r|
93 @x_to = [r['delay'].to_i, @x_to].max
93 @x_to = [r['delay'].to_i, @x_to].max
94 @y_to = [r['total'].to_i, @y_to].max
94 @y_to = [r['total'].to_i, @y_to].max
95 @sum_total = @sum_total + r['total'].to_i
95 @sum_total = @sum_total + r['total'].to_i
96 @sum_delay = @sum_delay + r['total'].to_i * r['delay'].to_i
96 @sum_delay = @sum_delay + r['total'].to_i * r['delay'].to_i
97 end
97 end
98 end
98 end
99
99
100 private
100 private
101 # Find project of id params[:id]
101 # Find project of id params[:id]
102 def find_project
102 def find_project
103 @project = Project.find(params[:id])
103 @project = Project.find(params[:id])
104 end
104 end
105
105
106 def issues_by_tracker
106 def issues_by_tracker
107 @issues_by_tracker ||=
107 @issues_by_tracker ||=
108 ActiveRecord::Base.connection.select_all("select s.id as status_id,
108 ActiveRecord::Base.connection.select_all("select s.id as status_id,
109 s.is_closed as closed,
109 s.is_closed as closed,
110 t.id as tracker_id,
110 t.id as tracker_id,
111 count(i.id) as total
111 count(i.id) as total
112 from
112 from
113 issues i, issue_statuses s, trackers t
113 issues i, issue_statuses s, trackers t
114 where
114 where
115 i.status_id=s.id
115 i.status_id=s.id
116 and i.tracker_id=t.id
116 and i.tracker_id=t.id
117 and i.project_id=#{@project.id}
117 and i.project_id=#{@project.id}
118 group by s.id, s.is_closed, t.id")
118 group by s.id, s.is_closed, t.id")
119 end
119 end
120
120
121 def issues_by_priority
121 def issues_by_priority
122 @issues_by_priority ||=
122 @issues_by_priority ||=
123 ActiveRecord::Base.connection.select_all("select s.id as status_id,
123 ActiveRecord::Base.connection.select_all("select s.id as status_id,
124 s.is_closed as closed,
124 s.is_closed as closed,
125 p.id as priority_id,
125 p.id as priority_id,
126 count(i.id) as total
126 count(i.id) as total
127 from
127 from
128 issues i, issue_statuses s, enumerations p
128 issues i, issue_statuses s, enumerations p
129 where
129 where
130 i.status_id=s.id
130 i.status_id=s.id
131 and i.priority_id=p.id
131 and i.priority_id=p.id
132 and i.project_id=#{@project.id}
132 and i.project_id=#{@project.id}
133 group by s.id, s.is_closed, p.id")
133 group by s.id, s.is_closed, p.id")
134 end
134 end
135
135
136 def issues_by_category
136 def issues_by_category
137 @issues_by_category ||=
137 @issues_by_category ||=
138 ActiveRecord::Base.connection.select_all("select s.id as status_id,
138 ActiveRecord::Base.connection.select_all("select s.id as status_id,
139 s.is_closed as closed,
139 s.is_closed as closed,
140 c.id as category_id,
140 c.id as category_id,
141 count(i.id) as total
141 count(i.id) as total
142 from
142 from
143 issues i, issue_statuses s, issue_categories c
143 issues i, issue_statuses s, issue_categories c
144 where
144 where
145 i.status_id=s.id
145 i.status_id=s.id
146 and i.category_id=c.id
146 and i.category_id=c.id
147 and i.project_id=#{@project.id}
147 and i.project_id=#{@project.id}
148 group by s.id, s.is_closed, c.id")
148 group by s.id, s.is_closed, c.id")
149 end
149 end
150
150
151 def issues_by_author
151 def issues_by_author
152 @issues_by_author ||=
152 @issues_by_author ||=
153 ActiveRecord::Base.connection.select_all("select s.id as status_id,
153 ActiveRecord::Base.connection.select_all("select s.id as status_id,
154 s.is_closed as closed,
154 s.is_closed as closed,
155 a.id as author_id,
155 a.id as author_id,
156 count(i.id) as total
156 count(i.id) as total
157 from
157 from
158 issues i, issue_statuses s, users a
158 issues i, issue_statuses s, users a
159 where
159 where
160 i.status_id=s.id
160 i.status_id=s.id
161 and i.author_id=a.id
161 and i.author_id=a.id
162 and i.project_id=#{@project.id}
162 and i.project_id=#{@project.id}
163 group by s.id, s.is_closed, a.id")
163 group by s.id, s.is_closed, a.id")
164 end
164 end
165 end
165 end
@@ -1,84 +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 RolesController < ApplicationController
18 class RolesController < 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 def list
27 def list
28 @role_pages, @roles = paginate :roles, :per_page => 10
28 @role_pages, @roles = paginate :roles, :per_page => 10
29 render :action => "list", :layout => false if request.xhr?
29 render :action => "list", :layout => false if request.xhr?
30 end
30 end
31
31
32 def new
32 def new
33 @role = Role.new(params[:role])
33 @role = Role.new(params[:role])
34 if request.post?
34 if request.post?
35 @role.permissions = Permission.find(@params[:permission_ids]) if @params[:permission_ids]
35 @role.permissions = Permission.find(@params[:permission_ids]) if @params[:permission_ids]
36 if @role.save
36 if @role.save
37 flash[:notice] = l(:notice_successful_create)
37 flash[:notice] = l(:notice_successful_create)
38 redirect_to :action => 'list'
38 redirect_to :action => 'list'
39 end
39 end
40 end
40 end
41 @permissions = Permission.find(:all, :conditions => ["is_public=?", false], :order => 'sort ASC')
41 @permissions = Permission.find(:all, :conditions => ["is_public=?", false], :order => 'sort ASC')
42 end
42 end
43
43
44 def edit
44 def edit
45 @role = Role.find(params[:id])
45 @role = Role.find(params[:id])
46 if request.post? and @role.update_attributes(params[:role])
46 if request.post? and @role.update_attributes(params[:role])
47 @role.permissions = Permission.find(@params[:permission_ids] || [])
47 @role.permissions = Permission.find(@params[:permission_ids] || [])
48 Permission.allowed_to_role_expired
48 Permission.allowed_to_role_expired
49 flash[:notice] = l(:notice_successful_update)
49 flash[:notice] = l(:notice_successful_update)
50 redirect_to :action => 'list'
50 redirect_to :action => 'list'
51 end
51 end
52 @permissions = Permission.find(:all, :conditions => ["is_public=?", false], :order => 'sort ASC')
52 @permissions = Permission.find(:all, :conditions => ["is_public=?", false], :order => 'sort ASC')
53 end
53 end
54
54
55 def destroy
55 def destroy
56 @role = Role.find(params[:id])
56 @role = Role.find(params[:id])
57 unless @role.members.empty?
57 unless @role.members.empty?
58 flash[:notice] = 'Some members have this role. Can\'t delete it.'
58 flash[:notice] = 'Some members have this role. Can\'t delete it.'
59 else
59 else
60 @role.destroy
60 @role.destroy
61 end
61 end
62 redirect_to :action => 'list'
62 redirect_to :action => 'list'
63 end
63 end
64
64
65 def workflow
65 def workflow
66 @role = Role.find_by_id(params[:role_id])
66 @role = Role.find_by_id(params[:role_id])
67 @tracker = Tracker.find_by_id(params[:tracker_id])
67 @tracker = Tracker.find_by_id(params[:tracker_id])
68
68
69 if request.post?
69 if request.post?
70 Workflow.destroy_all( ["role_id=? and tracker_id=?", @role.id, @tracker.id])
70 Workflow.destroy_all( ["role_id=? and tracker_id=?", @role.id, @tracker.id])
71 (params[:issue_status] || []).each { |old, news|
71 (params[:issue_status] || []).each { |old, news|
72 news.each { |new|
72 news.each { |new|
73 @role.workflows.build(:tracker_id => @tracker.id, :old_status_id => old, :new_status_id => new)
73 @role.workflows.build(:tracker_id => @tracker.id, :old_status_id => old, :new_status_id => new)
74 }
74 }
75 }
75 }
76 if @role.save
76 if @role.save
77 flash[:notice] = l(:notice_successful_update)
77 flash[:notice] = l(:notice_successful_update)
78 end
78 end
79 end
79 end
80 @roles = Role.find_all
80 @roles = Role.find :all
81 @trackers = Tracker.find_all
81 @trackers = Tracker.find :all
82 @statuses = IssueStatus.find(:all, :include => :workflows)
82 @statuses = IssueStatus.find(:all, :include => :workflows)
83 end
83 end
84 end
84 end
General Comments 0
You need to be logged in to leave comments. Login now