##// END OF EJS Templates
Project modules are checked (default) when creating a project....
Jean-Philippe Lang -
r719:4967f10356ea
parent child
Show More
@@ -1,628 +1,629
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 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 require 'csv'
19 19
20 20 class ProjectsController < ApplicationController
21 21 layout 'base'
22 22 before_filter :find_project, :except => [ :index, :list, :add ]
23 23 before_filter :authorize, :except => [ :index, :list, :add, :archive, :unarchive, :destroy ]
24 24 before_filter :require_admin, :only => [ :add, :archive, :unarchive, :destroy ]
25 25 accept_key_auth :activity, :calendar
26 26
27 27 cache_sweeper :project_sweeper, :only => [ :add, :edit, :archive, :unarchive, :destroy ]
28 28 cache_sweeper :issue_sweeper, :only => [ :add_issue ]
29 29 cache_sweeper :version_sweeper, :only => [ :add_version ]
30 30
31 31 helper :sort
32 32 include SortHelper
33 33 helper :custom_fields
34 34 include CustomFieldsHelper
35 35 helper :ifpdf
36 36 include IfpdfHelper
37 37 helper IssuesHelper
38 38 helper :queries
39 39 include QueriesHelper
40 40 helper :repositories
41 41 include RepositoriesHelper
42 42 include ProjectsHelper
43 43
44 44 def index
45 45 list
46 46 render :action => 'list' unless request.xhr?
47 47 end
48 48
49 49 # Lists visible projects
50 50 def list
51 51 projects = Project.find :all,
52 52 :conditions => Project.visible_by(logged_in_user),
53 53 :include => :parent
54 54 @project_tree = projects.group_by {|p| p.parent || p}
55 55 @project_tree.each_key {|p| @project_tree[p] -= [p]}
56 56 end
57 57
58 58 # Add a new project
59 59 def add
60 60 @custom_fields = IssueCustomField.find(:all)
61 61 @root_projects = Project.find(:all, :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}")
62 62 @project = Project.new(params[:project])
63 @project.enabled_module_names = Redmine::AccessControl.available_project_modules
63 64 if request.get?
64 65 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project) }
65 66 else
66 67 @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
67 68 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => (params[:custom_fields] ? params["custom_fields"][x.id.to_s] : nil)) }
68 69 @project.custom_values = @custom_values
69 70 if @project.save
70 71 @project.enabled_module_names = params[:enabled_modules]
71 72 flash[:notice] = l(:notice_successful_create)
72 73 redirect_to :controller => 'admin', :action => 'projects'
73 74 end
74 75 end
75 76 end
76 77
77 78 # Show @project
78 79 def show
79 80 @custom_values = @project.custom_values.find(:all, :include => :custom_field)
80 81 @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role}
81 82 @subprojects = @project.active_children
82 83 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
83 84 @trackers = Tracker.find(:all, :order => 'position')
84 85 @open_issues_by_tracker = Issue.count(:group => :tracker, :joins => "INNER JOIN #{IssueStatus.table_name} ON #{IssueStatus.table_name}.id = #{Issue.table_name}.status_id", :conditions => ["project_id=? and #{IssueStatus.table_name}.is_closed=?", @project.id, false])
85 86 @total_issues_by_tracker = Issue.count(:group => :tracker, :conditions => ["project_id=?", @project.id])
86 87 @key = User.current.rss_key
87 88 end
88 89
89 90 def settings
90 91 @root_projects = Project::find(:all, :conditions => ["parent_id IS NULL AND status = #{Project::STATUS_ACTIVE} AND id <> ?", @project.id])
91 92 @custom_fields = IssueCustomField.find(:all)
92 93 @issue_category ||= IssueCategory.new
93 94 @member ||= @project.members.new
94 95 @custom_values ||= ProjectCustomField.find(:all).collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
95 96 @repository ||= @project.repository
96 97 @wiki ||= @project.wiki
97 98 end
98 99
99 100 # Edit @project
100 101 def edit
101 102 if request.post?
102 103 @project.custom_fields = IssueCustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
103 104 if params[:custom_fields]
104 105 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
105 106 @project.custom_values = @custom_values
106 107 end
107 108 @project.attributes = params[:project]
108 109 if @project.save
109 110 flash[:notice] = l(:notice_successful_update)
110 111 redirect_to :action => 'settings', :id => @project
111 112 else
112 113 settings
113 114 render :action => 'settings'
114 115 end
115 116 end
116 117 end
117 118
118 119 def modules
119 120 @project.enabled_module_names = params[:enabled_modules]
120 121 redirect_to :action => 'settings', :id => @project, :tab => 'modules'
121 122 end
122 123
123 124 def archive
124 125 @project.archive if request.post? && @project.active?
125 126 redirect_to :controller => 'admin', :action => 'projects'
126 127 end
127 128
128 129 def unarchive
129 130 @project.unarchive if request.post? && !@project.active?
130 131 redirect_to :controller => 'admin', :action => 'projects'
131 132 end
132 133
133 134 # Delete @project
134 135 def destroy
135 136 @project_to_destroy = @project
136 137 if request.post? and params[:confirm]
137 138 @project_to_destroy.destroy
138 139 redirect_to :controller => 'admin', :action => 'projects'
139 140 end
140 141 # hide project in layout
141 142 @project = nil
142 143 end
143 144
144 145 # Add a new issue category to @project
145 146 def add_issue_category
146 147 @category = @project.issue_categories.build(params[:category])
147 148 if request.post? and @category.save
148 149 respond_to do |format|
149 150 format.html do
150 151 flash[:notice] = l(:notice_successful_create)
151 152 redirect_to :action => 'settings', :tab => 'categories', :id => @project
152 153 end
153 154 format.js do
154 155 # IE doesn't support the replace_html rjs method for select box options
155 156 render(:update) {|page| page.replace "issue_category_id",
156 157 content_tag('select', '<option></option>' + options_from_collection_for_select(@project.issue_categories, 'id', 'name', @category.id), :id => 'issue_category_id', :name => 'issue[category_id]')
157 158 }
158 159 end
159 160 end
160 161 end
161 162 end
162 163
163 164 # Add a new version to @project
164 165 def add_version
165 166 @version = @project.versions.build(params[:version])
166 167 if request.post? and @version.save
167 168 flash[:notice] = l(:notice_successful_create)
168 169 redirect_to :action => 'settings', :tab => 'versions', :id => @project
169 170 end
170 171 end
171 172
172 173 # Add a new document to @project
173 174 def add_document
174 175 @categories = Enumeration::get_values('DCAT')
175 176 @document = @project.documents.build(params[:document])
176 177 if request.post? and @document.save
177 178 # Save the attachments
178 179 params[:attachments].each { |a|
179 180 Attachment.create(:container => @document, :file => a, :author => logged_in_user) unless a.size == 0
180 181 } if params[:attachments] and params[:attachments].is_a? Array
181 182 flash[:notice] = l(:notice_successful_create)
182 183 Mailer.deliver_document_add(@document) if Setting.notified_events.include?('document_added')
183 184 redirect_to :action => 'list_documents', :id => @project
184 185 end
185 186 end
186 187
187 188 # Show documents list of @project
188 189 def list_documents
189 190 @documents = @project.documents.find :all, :include => :category
190 191 end
191 192
192 193 # Add a new issue to @project
193 194 def add_issue
194 195 @tracker = Tracker.find(params[:tracker_id])
195 196 @priorities = Enumeration::get_values('IPRI')
196 197
197 198 default_status = IssueStatus.default
198 199 unless default_status
199 200 flash.now[:error] = 'No default issue status defined. Please check your configuration.'
200 201 render :nothing => true, :layout => true
201 202 return
202 203 end
203 204 @issue = Issue.new(:project => @project, :tracker => @tracker)
204 205 @issue.status = default_status
205 206 @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(logged_in_user.role_for_project(@project), @issue.tracker))if logged_in_user
206 207 if request.get?
207 208 @issue.start_date = Date.today
208 209 @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) }
209 210 else
210 211 @issue.attributes = params[:issue]
211 212
212 213 requested_status = IssueStatus.find_by_id(params[:issue][:status_id])
213 214 @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status
214 215
215 216 @issue.author_id = self.logged_in_user.id if self.logged_in_user
216 217 # Multiple file upload
217 218 @attachments = []
218 219 params[:attachments].each { |a|
219 220 @attachments << Attachment.new(:container => @issue, :file => a, :author => logged_in_user) unless a.size == 0
220 221 } if params[:attachments] and params[:attachments].is_a? Array
221 222 @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]) }
222 223 @issue.custom_values = @custom_values
223 224 if @issue.save
224 225 @attachments.each(&:save)
225 226 flash[:notice] = l(:notice_successful_create)
226 227 Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added')
227 228 redirect_to :action => 'list_issues', :id => @project
228 229 end
229 230 end
230 231 end
231 232
232 233 # Show filtered/sorted issues list of @project
233 234 def list_issues
234 235 sort_init "#{Issue.table_name}.id", "desc"
235 236 sort_update
236 237
237 238 retrieve_query
238 239
239 240 @results_per_page_options = [ 15, 25, 50, 100 ]
240 241 if params[:per_page] and @results_per_page_options.include? params[:per_page].to_i
241 242 @results_per_page = params[:per_page].to_i
242 243 session[:results_per_page] = @results_per_page
243 244 else
244 245 @results_per_page = session[:results_per_page] || 25
245 246 end
246 247
247 248 if @query.valid?
248 249 @issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement)
249 250 @issue_pages = Paginator.new self, @issue_count, @results_per_page, params['page']
250 251 @issues = Issue.find :all, :order => sort_clause,
251 252 :include => [ :assigned_to, :status, :tracker, :project, :priority ],
252 253 :conditions => @query.statement,
253 254 :limit => @issue_pages.items_per_page,
254 255 :offset => @issue_pages.current.offset
255 256 end
256 257 render :layout => false if request.xhr?
257 258 end
258 259
259 260 # Export filtered/sorted issues list to CSV
260 261 def export_issues_csv
261 262 sort_init "#{Issue.table_name}.id", "desc"
262 263 sort_update
263 264
264 265 retrieve_query
265 266 render :action => 'list_issues' and return unless @query.valid?
266 267
267 268 @issues = Issue.find :all, :order => sort_clause,
268 269 :include => [ :assigned_to, :author, :status, :tracker, :priority, :project, {:custom_values => :custom_field} ],
269 270 :conditions => @query.statement,
270 271 :limit => Setting.issues_export_limit.to_i
271 272
272 273 ic = Iconv.new(l(:general_csv_encoding), 'UTF-8')
273 274 export = StringIO.new
274 275 CSV::Writer.generate(export, l(:general_csv_separator)) do |csv|
275 276 # csv header fields
276 277 headers = [ "#", l(:field_status),
277 278 l(:field_project),
278 279 l(:field_tracker),
279 280 l(:field_priority),
280 281 l(:field_subject),
281 282 l(:field_assigned_to),
282 283 l(:field_author),
283 284 l(:field_start_date),
284 285 l(:field_due_date),
285 286 l(:field_done_ratio),
286 287 l(:field_created_on),
287 288 l(:field_updated_on)
288 289 ]
289 290 for custom_field in @project.all_custom_fields
290 291 headers << custom_field.name
291 292 end
292 293 csv << headers.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
293 294 # csv lines
294 295 @issues.each do |issue|
295 296 fields = [issue.id, issue.status.name,
296 297 issue.project.name,
297 298 issue.tracker.name,
298 299 issue.priority.name,
299 300 issue.subject,
300 301 (issue.assigned_to ? issue.assigned_to.name : ""),
301 302 issue.author.name,
302 303 issue.start_date ? l_date(issue.start_date) : nil,
303 304 issue.due_date ? l_date(issue.due_date) : nil,
304 305 issue.done_ratio,
305 306 l_datetime(issue.created_on),
306 307 l_datetime(issue.updated_on)
307 308 ]
308 309 for custom_field in @project.all_custom_fields
309 310 fields << (show_value issue.custom_value_for(custom_field))
310 311 end
311 312 csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
312 313 end
313 314 end
314 315 export.rewind
315 316 send_data(export.read, :type => 'text/csv; header=present', :filename => 'export.csv')
316 317 end
317 318
318 319 # Export filtered/sorted issues to PDF
319 320 def export_issues_pdf
320 321 sort_init "#{Issue.table_name}.id", "desc"
321 322 sort_update
322 323
323 324 retrieve_query
324 325 render :action => 'list_issues' and return unless @query.valid?
325 326
326 327 @issues = Issue.find :all, :order => sort_clause,
327 328 :include => [ :author, :status, :tracker, :priority, :project ],
328 329 :conditions => @query.statement,
329 330 :limit => Setting.issues_export_limit.to_i
330 331
331 332 @options_for_rfpdf ||= {}
332 333 @options_for_rfpdf[:file_name] = "export.pdf"
333 334 render :layout => false
334 335 end
335 336
336 337 def move_issues
337 338 @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids]
338 339 redirect_to :action => 'list_issues', :id => @project and return unless @issues
339 340 @projects = []
340 341 # find projects to which the user is allowed to move the issue
341 342 User.current.memberships.each {|m| @projects << m.project if m.role.allowed_to?(:controller => 'projects', :action => 'move_issues')}
342 343 # issue can be moved to any tracker
343 344 @trackers = Tracker.find(:all)
344 345 if request.post? and params[:new_project_id] and params[:new_tracker_id]
345 346 new_project = Project.find_by_id(params[:new_project_id])
346 347 new_tracker = Tracker.find_by_id(params[:new_tracker_id])
347 348 @issues.each do |i|
348 349 if new_project && i.project_id != new_project.id
349 350 # issue is moved to another project
350 351 i.category = nil
351 352 i.fixed_version = nil
352 353 # delete issue relations
353 354 i.relations_from.clear
354 355 i.relations_to.clear
355 356 i.project = new_project
356 357 end
357 358 if new_tracker
358 359 i.tracker = new_tracker
359 360 end
360 361 i.save
361 362 end
362 363 flash[:notice] = l(:notice_successful_update)
363 364 redirect_to :action => 'list_issues', :id => @project
364 365 end
365 366 end
366 367
367 368 # Add a news to @project
368 369 def add_news
369 370 @news = News.new(:project => @project)
370 371 if request.post?
371 372 @news.attributes = params[:news]
372 373 @news.author_id = self.logged_in_user.id if self.logged_in_user
373 374 if @news.save
374 375 flash[:notice] = l(:notice_successful_create)
375 376 Mailer.deliver_news_added(@news) if Setting.notified_events.include?('news_added')
376 377 redirect_to :action => 'list_news', :id => @project
377 378 end
378 379 end
379 380 end
380 381
381 382 # Show news list of @project
382 383 def list_news
383 384 @news_pages, @news = paginate :news, :per_page => 10, :conditions => ["project_id=?", @project.id], :include => :author, :order => "#{News.table_name}.created_on DESC"
384 385
385 386 respond_to do |format|
386 387 format.html { render :layout => false if request.xhr? }
387 388 format.atom { render_feed(@news, :title => "#{@project.name}: #{l(:label_news_plural)}") }
388 389 end
389 390 end
390 391
391 392 def add_file
392 393 if request.post?
393 394 @version = @project.versions.find_by_id(params[:version_id])
394 395 # Save the attachments
395 396 @attachments = []
396 397 params[:attachments].each { |file|
397 398 next unless file.size > 0
398 399 a = Attachment.create(:container => @version, :file => file, :author => logged_in_user)
399 400 @attachments << a unless a.new_record?
400 401 } if params[:attachments] and params[:attachments].is_a? Array
401 402 Mailer.deliver_attachments_add(@attachments) if !@attachments.empty? && Setting.notified_events.include?('file_added')
402 403 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
403 404 end
404 405 @versions = @project.versions.sort
405 406 end
406 407
407 408 def list_files
408 409 @versions = @project.versions.sort
409 410 end
410 411
411 412 # Show changelog for @project
412 413 def changelog
413 414 @trackers = Tracker.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position')
414 415 retrieve_selected_tracker_ids(@trackers)
415 416 @versions = @project.versions.sort
416 417 end
417 418
418 419 def roadmap
419 420 @trackers = Tracker.find(:all, :conditions => ["is_in_roadmap=?", true], :order => 'position')
420 421 retrieve_selected_tracker_ids(@trackers)
421 422 @versions = @project.versions.sort
422 423 @versions = @versions.select {|v| !v.completed? } unless params[:completed]
423 424 end
424 425
425 426 def activity
426 427 if params[:year] and params[:year].to_i > 1900
427 428 @year = params[:year].to_i
428 429 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
429 430 @month = params[:month].to_i
430 431 end
431 432 end
432 433 @year ||= Date.today.year
433 434 @month ||= Date.today.month
434 435
435 436 case params[:format]
436 437 when 'rss'
437 438 # 30 last days
438 439 @date_from = Date.today - 30
439 440 @date_to = Date.today + 1
440 441 else
441 442 # current month
442 443 @date_from = Date.civil(@year, @month, 1)
443 444 @date_to = @date_from >> 1
444 445 end
445 446
446 447 @event_types = %w(issues news attachments documents wiki_edits revisions)
447 448 @event_types.delete('wiki_edits') unless @project.wiki
448 449 @event_types.delete('changesets') unless @project.repository
449 450
450 451 @scope = @event_types.select {|t| params["show_#{t}"]}
451 452 # default events if none is specified in parameters
452 453 @scope = (@event_types - %w(wiki_edits))if @scope.empty?
453 454
454 455 @events = []
455 456
456 457 if @scope.include?('issues')
457 458 @events += @project.issues.find(:all, :include => [:author, :tracker], :conditions => ["#{Issue.table_name}.created_on>=? and #{Issue.table_name}.created_on<=?", @date_from, @date_to] )
458 459 end
459 460
460 461 if @scope.include?('news')
461 462 @events += @project.news.find(:all, :conditions => ["#{News.table_name}.created_on>=? and #{News.table_name}.created_on<=?", @date_from, @date_to], :include => :author )
462 463 end
463 464
464 465 if @scope.include?('attachments')
465 466 @events += Attachment.find(:all, :select => "#{Attachment.table_name}.*", :joins => "LEFT JOIN #{Version.table_name} ON #{Version.table_name}.id = #{Attachment.table_name}.container_id", :conditions => ["#{Attachment.table_name}.container_type='Version' and #{Version.table_name}.project_id=? and #{Attachment.table_name}.created_on>=? and #{Attachment.table_name}.created_on<=?", @project.id, @date_from, @date_to], :include => :author )
466 467 end
467 468
468 469 if @scope.include?('documents')
469 470 @events += @project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on>=? and #{Document.table_name}.created_on<=?", @date_from, @date_to] )
470 471 @events += Attachment.find(:all, :select => "attachments.*", :joins => "LEFT JOIN #{Document.table_name} ON #{Document.table_name}.id = #{Attachment.table_name}.container_id", :conditions => ["#{Attachment.table_name}.container_type='Document' and #{Document.table_name}.project_id=? and #{Attachment.table_name}.created_on>=? and #{Attachment.table_name}.created_on<=?", @project.id, @date_from, @date_to], :include => :author )
471 472 end
472 473
473 474 if @scope.include?('wiki_edits') && @project.wiki
474 475 select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " +
475 476 "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title, " +
476 477 "#{WikiContent.versioned_table_name}.page_id, #{WikiContent.versioned_table_name}.author_id, " +
477 478 "#{WikiContent.versioned_table_name}.id"
478 479 joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " +
479 480 "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id "
480 481 conditions = ["#{Wiki.table_name}.project_id = ? AND #{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?",
481 482 @project.id, @date_from, @date_to]
482 483
483 484 @events += WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => conditions)
484 485 end
485 486
486 487 if @scope.include?('revisions') && @project.repository
487 488 @events += @project.repository.changesets.find(:all, :conditions => ["#{Changeset.table_name}.committed_on BETWEEN ? AND ?", @date_from, @date_to])
488 489 end
489 490
490 491 @events_by_day = @events.group_by(&:event_date)
491 492
492 493 respond_to do |format|
493 494 format.html { render :layout => false if request.xhr? }
494 495 format.atom { render_feed(@events, :title => "#{@project.name}: #{l(:label_activity)}") }
495 496 end
496 497 end
497 498
498 499 def calendar
499 500 @trackers = Tracker.find(:all, :order => 'position')
500 501 retrieve_selected_tracker_ids(@trackers)
501 502
502 503 if params[:year] and params[:year].to_i > 1900
503 504 @year = params[:year].to_i
504 505 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
505 506 @month = params[:month].to_i
506 507 end
507 508 end
508 509 @year ||= Date.today.year
509 510 @month ||= Date.today.month
510 511
511 512 @date_from = Date.civil(@year, @month, 1)
512 513 @date_to = (@date_from >> 1)-1
513 514 # start on monday
514 515 @date_from = @date_from - (@date_from.cwday-1)
515 516 # finish on sunday
516 517 @date_to = @date_to + (7-@date_to.cwday)
517 518
518 519 @events = []
519 520 @project.issues_with_subprojects(params[:with_subprojects]) do
520 521 @events += Issue.find(:all,
521 522 :include => [:tracker, :status, :assigned_to, :priority, :project],
522 523 :conditions => ["((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?)) and #{Issue.table_name}.tracker_id in (#{@selected_tracker_ids.join(',')})", @date_from, @date_to, @date_from, @date_to]
523 524 ) unless @selected_tracker_ids.empty?
524 525 end
525 526 @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to])
526 527
527 528 @ending_events_by_days = @events.group_by {|event| event.due_date}
528 529 @starting_events_by_days = @events.group_by {|event| event.start_date}
529 530
530 531 render :layout => false if request.xhr?
531 532 end
532 533
533 534 def gantt
534 535 @trackers = Tracker.find(:all, :order => 'position')
535 536 retrieve_selected_tracker_ids(@trackers)
536 537
537 538 if params[:year] and params[:year].to_i >0
538 539 @year_from = params[:year].to_i
539 540 if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12
540 541 @month_from = params[:month].to_i
541 542 else
542 543 @month_from = 1
543 544 end
544 545 else
545 546 @month_from ||= (Date.today << 1).month
546 547 @year_from ||= (Date.today << 1).year
547 548 end
548 549
549 550 @zoom = (params[:zoom].to_i > 0 and params[:zoom].to_i < 5) ? params[:zoom].to_i : 2
550 551 @months = (params[:months].to_i > 0 and params[:months].to_i < 25) ? params[:months].to_i : 6
551 552
552 553 @date_from = Date.civil(@year_from, @month_from, 1)
553 554 @date_to = (@date_from >> @months) - 1
554 555
555 556 @events = []
556 557 @project.issues_with_subprojects(params[:with_subprojects]) do
557 558 @events += Issue.find(:all,
558 559 :order => "start_date, due_date",
559 560 :include => [:tracker, :status, :assigned_to, :priority, :project],
560 561 :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 and #{Issue.table_name}.tracker_id in (#{@selected_tracker_ids.join(',')}))", @date_from, @date_to, @date_from, @date_to, @date_from, @date_to]
561 562 ) unless @selected_tracker_ids.empty?
562 563 end
563 564 @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to])
564 565 @events.sort! {|x,y| x.start_date <=> y.start_date }
565 566
566 567 if params[:format]=='pdf'
567 568 @options_for_rfpdf ||= {}
568 569 @options_for_rfpdf[:file_name] = "#{@project.identifier}-gantt.pdf"
569 570 render :template => "projects/gantt.rfpdf", :layout => false
570 571 elsif params[:format]=='png' && respond_to?('gantt_image')
571 572 image = gantt_image(@events, @date_from, @months, @zoom)
572 573 image.format = 'PNG'
573 574 send_data(image.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "#{@project.identifier}-gantt.png")
574 575 else
575 576 render :template => "projects/gantt.rhtml"
576 577 end
577 578 end
578 579
579 580 def feeds
580 581 @queries = @project.queries.find :all, :conditions => ["is_public=? or user_id=?", true, (logged_in_user ? logged_in_user.id : 0)]
581 582 @key = User.current.rss_key
582 583 end
583 584
584 585 private
585 586 # Find project of id params[:id]
586 587 # if not found, redirect to project list
587 588 # Used as a before_filter
588 589 def find_project
589 590 @project = Project.find(params[:id])
590 591 rescue ActiveRecord::RecordNotFound
591 592 render_404
592 593 end
593 594
594 595 def retrieve_selected_tracker_ids(selectable_trackers)
595 596 if ids = params[:tracker_ids]
596 597 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
597 598 else
598 599 @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s }
599 600 end
600 601 end
601 602
602 603 # Retrieve query from session or build a new query
603 604 def retrieve_query
604 605 if params[:query_id]
605 606 @query = @project.queries.find(params[:query_id])
606 607 @query.executed_by = logged_in_user
607 608 session[:query] = @query
608 609 else
609 610 if params[:set_filter] or !session[:query] or session[:query].project_id != @project.id
610 611 # Give it a name, required to be valid
611 612 @query = Query.new(:name => "_", :executed_by => logged_in_user)
612 613 @query.project = @project
613 614 if params[:fields] and params[:fields].is_a? Array
614 615 params[:fields].each do |field|
615 616 @query.add_filter(field, params[:operators][field], params[:values][field])
616 617 end
617 618 else
618 619 @query.available_filters.keys.each do |field|
619 620 @query.add_short_filter(field, params[field]) if params[field]
620 621 end
621 622 end
622 623 session[:query] = @query
623 624 else
624 625 @query = session[:query]
625 626 end
626 627 end
627 628 end
628 629 end
General Comments 0
You need to be logged in to leave comments. Login now