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