##// END OF EJS Templates
Ported r1009 from 0.6-stable branch....
Jean-Philippe Lang -
r1000:4a2efa9252ba
parent child
Show More
@@ -1,520 +1,520
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 class ProjectsController < ApplicationController
19 19 layout 'base'
20 20 before_filter :find_project, :except => [ :index, :list, :add ]
21 21 before_filter :authorize, :except => [ :index, :list, :add, :archive, :unarchive, :destroy ]
22 22 before_filter :require_admin, :only => [ :add, :archive, :unarchive, :destroy ]
23 23 accept_key_auth :activity, :calendar
24 24
25 25 cache_sweeper :project_sweeper, :only => [ :add, :edit, :archive, :unarchive, :destroy ]
26 26 cache_sweeper :issue_sweeper, :only => [ :add_issue ]
27 27 cache_sweeper :version_sweeper, :only => [ :add_version ]
28 28
29 29 helper :sort
30 30 include SortHelper
31 31 helper :custom_fields
32 32 include CustomFieldsHelper
33 33 helper :ifpdf
34 34 include IfpdfHelper
35 35 helper :issues
36 36 helper IssuesHelper
37 37 helper :queries
38 38 include QueriesHelper
39 39 helper :repositories
40 40 include RepositoriesHelper
41 41 include ProjectsHelper
42 42
43 43 def index
44 44 list
45 45 render :action => 'list' unless request.xhr?
46 46 end
47 47
48 48 # Lists visible projects
49 49 def list
50 50 projects = Project.find :all,
51 51 :conditions => Project.visible_by(User.current),
52 52 :include => :parent
53 53 @project_tree = projects.group_by {|p| p.parent || p}
54 54 @project_tree.each_key {|p| @project_tree[p] -= [p]}
55 55 end
56 56
57 57 # Add a new project
58 58 def add
59 59 @custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
60 60 @trackers = Tracker.all
61 61 @root_projects = Project.find(:all,
62 62 :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}",
63 63 :order => 'name')
64 64 @project = Project.new(params[:project])
65 65 @project.enabled_module_names = Redmine::AccessControl.available_project_modules
66 66 if request.get?
67 67 @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project) }
68 68 @project.trackers = Tracker.all
69 69 else
70 70 @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
71 71 @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => (params[:custom_fields] ? params["custom_fields"][x.id.to_s] : nil)) }
72 72 @project.custom_values = @custom_values
73 73 if @project.save
74 74 @project.enabled_module_names = params[:enabled_modules]
75 75 flash[:notice] = l(:notice_successful_create)
76 76 redirect_to :controller => 'admin', :action => 'projects'
77 77 end
78 78 end
79 79 end
80 80
81 81 # Show @project
82 82 def show
83 83 @custom_values = @project.custom_values.find(:all, :include => :custom_field, :order => "#{CustomField.table_name}.position")
84 84 @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role}
85 85 @subprojects = @project.active_children
86 86 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
87 87 @trackers = @project.trackers
88 88 @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])
89 89 @total_issues_by_tracker = Issue.count(:group => :tracker, :conditions => ["project_id=?", @project.id])
90 90 @total_hours = @project.time_entries.sum(:hours)
91 91 @key = User.current.rss_key
92 92 end
93 93
94 94 def settings
95 95 @root_projects = Project.find(:all,
96 96 :conditions => ["parent_id IS NULL AND status = #{Project::STATUS_ACTIVE} AND id <> ?", @project.id],
97 97 :order => 'name')
98 98 @custom_fields = IssueCustomField.find(:all)
99 99 @issue_category ||= IssueCategory.new
100 100 @member ||= @project.members.new
101 101 @trackers = Tracker.all
102 102 @custom_values ||= ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
103 103 @repository ||= @project.repository
104 104 @wiki ||= @project.wiki
105 105 end
106 106
107 107 # Edit @project
108 108 def edit
109 109 if request.post?
110 110 @project.custom_fields = IssueCustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
111 111 if params[:custom_fields]
112 112 @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
113 113 @project.custom_values = @custom_values
114 114 end
115 115 @project.attributes = params[:project]
116 116 if @project.save
117 117 flash[:notice] = l(:notice_successful_update)
118 118 redirect_to :action => 'settings', :id => @project
119 119 else
120 120 settings
121 121 render :action => 'settings'
122 122 end
123 123 end
124 124 end
125 125
126 126 def modules
127 127 @project.enabled_module_names = params[:enabled_modules]
128 128 redirect_to :action => 'settings', :id => @project, :tab => 'modules'
129 129 end
130 130
131 131 def archive
132 132 @project.archive if request.post? && @project.active?
133 133 redirect_to :controller => 'admin', :action => 'projects'
134 134 end
135 135
136 136 def unarchive
137 137 @project.unarchive if request.post? && !@project.active?
138 138 redirect_to :controller => 'admin', :action => 'projects'
139 139 end
140 140
141 141 # Delete @project
142 142 def destroy
143 143 @project_to_destroy = @project
144 144 if request.post? and params[:confirm]
145 145 @project_to_destroy.destroy
146 146 redirect_to :controller => 'admin', :action => 'projects'
147 147 end
148 148 # hide project in layout
149 149 @project = nil
150 150 end
151 151
152 152 # Add a new issue category to @project
153 153 def add_issue_category
154 154 @category = @project.issue_categories.build(params[:category])
155 155 if request.post? and @category.save
156 156 respond_to do |format|
157 157 format.html do
158 158 flash[:notice] = l(:notice_successful_create)
159 159 redirect_to :action => 'settings', :tab => 'categories', :id => @project
160 160 end
161 161 format.js do
162 162 # IE doesn't support the replace_html rjs method for select box options
163 163 render(:update) {|page| page.replace "issue_category_id",
164 164 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]')
165 165 }
166 166 end
167 167 end
168 168 end
169 169 end
170 170
171 171 # Add a new version to @project
172 172 def add_version
173 173 @version = @project.versions.build(params[:version])
174 174 if request.post? and @version.save
175 175 flash[:notice] = l(:notice_successful_create)
176 176 redirect_to :action => 'settings', :tab => 'versions', :id => @project
177 177 end
178 178 end
179 179
180 180 # Add a new issue to @project
181 181 # The new issue will be created from an existing one if copy_from parameter is given
182 182 def add_issue
183 183 @issue = params[:copy_from] ? Issue.new.copy_from(params[:copy_from]) : Issue.new(params[:issue])
184 184 @issue.project = @project
185 185 @issue.author = User.current
186 186 @issue.tracker ||= @project.trackers.find(params[:tracker_id])
187 187
188 188 default_status = IssueStatus.default
189 189 unless default_status
190 190 flash.now[:error] = 'No default issue status is defined. Please check your configuration (Go to "Administration -> Issue statuses").'
191 191 render :nothing => true, :layout => true
192 192 return
193 193 end
194 194 @issue.status = default_status
195 195 @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(User.current.role_for_project(@project), @issue.tracker))
196 196
197 197 if request.get?
198 198 @issue.start_date ||= Date.today
199 199 @custom_values = @issue.custom_values.empty? ?
200 200 @project.custom_fields_for_issues(@issue.tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) } :
201 201 @issue.custom_values
202 202 else
203 203 requested_status = IssueStatus.find_by_id(params[:issue][:status_id])
204 204 # Check that the user is allowed to apply the requested status
205 205 @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status
206 206 @custom_values = @project.custom_fields_for_issues(@issue.tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue, :value => params["custom_fields"][x.id.to_s]) }
207 207 @issue.custom_values = @custom_values
208 208 if @issue.save
209 209 attach_files(@issue, params[:attachments])
210 210 flash[:notice] = l(:notice_successful_create)
211 211 Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added')
212 212 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
213 213 return
214 214 end
215 215 end
216 216 @priorities = Enumeration::get_values('IPRI')
217 217 end
218 218
219 219 # Bulk edit issues
220 220 def bulk_edit_issues
221 221 if request.post?
222 222 status = params[:status_id].blank? ? nil : IssueStatus.find_by_id(params[:status_id])
223 223 priority = params[:priority_id].blank? ? nil : Enumeration.find_by_id(params[:priority_id])
224 224 assigned_to = params[:assigned_to_id].blank? ? nil : User.find_by_id(params[:assigned_to_id])
225 225 category = params[:category_id].blank? ? nil : @project.issue_categories.find_by_id(params[:category_id])
226 226 fixed_version = params[:fixed_version_id].blank? ? nil : @project.versions.find_by_id(params[:fixed_version_id])
227 227 issues = @project.issues.find_all_by_id(params[:issue_ids])
228 228 unsaved_issue_ids = []
229 229 issues.each do |issue|
230 230 journal = issue.init_journal(User.current, params[:notes])
231 231 issue.priority = priority if priority
232 232 issue.assigned_to = assigned_to if assigned_to || params[:assigned_to_id] == 'none'
233 233 issue.category = category if category
234 234 issue.fixed_version = fixed_version if fixed_version
235 235 issue.start_date = params[:start_date] unless params[:start_date].blank?
236 236 issue.due_date = params[:due_date] unless params[:due_date].blank?
237 237 issue.done_ratio = params[:done_ratio] unless params[:done_ratio].blank?
238 238 # Don't save any change to the issue if the user is not authorized to apply the requested status
239 239 if (status.nil? || (issue.status.new_status_allowed_to?(status, current_role, issue.tracker) && issue.status = status)) && issue.save
240 240 # Send notification for each issue (if changed)
241 241 Mailer.deliver_issue_edit(journal) if journal.details.any? && Setting.notified_events.include?('issue_updated')
242 242 else
243 243 # Keep unsaved issue ids to display them in flash error
244 244 unsaved_issue_ids << issue.id
245 245 end
246 246 end
247 247 if unsaved_issue_ids.empty?
248 248 flash[:notice] = l(:notice_successful_update) unless issues.empty?
249 249 else
250 250 flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, issues.size, '#' + unsaved_issue_ids.join(', #'))
251 251 end
252 252 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
253 253 return
254 254 end
255 255 if current_role && User.current.allowed_to?(:change_issue_status, @project)
256 256 # Find potential statuses the user could be allowed to switch issues to
257 257 @available_statuses = Workflow.find(:all, :include => :new_status,
258 258 :conditions => {:role_id => current_role.id}).collect(&:new_status).compact.uniq
259 259 end
260 260 render :update do |page|
261 261 page.hide 'query_form'
262 262 page.replace_html 'bulk-edit', :partial => 'issues/bulk_edit_form'
263 263 end
264 264 end
265 265
266 266 def move_issues
267 267 @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids]
268 268 redirect_to :controller => 'issues', :action => 'index', :project_id => @project and return unless @issues
269 269
270 270 @projects = []
271 271 # find projects to which the user is allowed to move the issue
272 272 if User.current.admin?
273 273 # admin is allowed to move issues to any active (visible) project
274 274 @projects = Project.find(:all, :conditions => Project.visible_by(User.current), :order => 'name')
275 275 else
276 276 User.current.memberships.each {|m| @projects << m.project if m.role.allowed_to?(:move_issues)}
277 277 end
278 278 @target_project = @projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id]
279 279 @target_project ||= @project
280 280 @trackers = @target_project.trackers
281 281 if request.post?
282 282 new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id])
283 283 unsaved_issue_ids = []
284 284 @issues.each do |issue|
285 285 unsaved_issue_ids << issue.id unless issue.move_to(@target_project, new_tracker)
286 286 end
287 287 if unsaved_issue_ids.empty?
288 288 flash[:notice] = l(:notice_successful_update) unless @issues.empty?
289 289 else
290 290 flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, @issues.size, '#' + unsaved_issue_ids.join(', #'))
291 291 end
292 292 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
293 293 return
294 294 end
295 295 render :layout => false if request.xhr?
296 296 end
297 297
298 298 # Add a news to @project
299 299 def add_news
300 300 @news = News.new(:project => @project, :author => User.current)
301 301 if request.post?
302 302 @news.attributes = params[:news]
303 303 if @news.save
304 304 flash[:notice] = l(:notice_successful_create)
305 305 Mailer.deliver_news_added(@news) if Setting.notified_events.include?('news_added')
306 306 redirect_to :controller => 'news', :action => 'index', :project_id => @project
307 307 end
308 308 end
309 309 end
310 310
311 311 def add_file
312 312 if request.post?
313 313 @version = @project.versions.find_by_id(params[:version_id])
314 attachments = attach_files(@issue, params[:attachments])
314 attachments = attach_files(@version, params[:attachments])
315 315 Mailer.deliver_attachments_added(attachments) if !attachments.empty? && Setting.notified_events.include?('file_added')
316 316 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
317 317 end
318 318 @versions = @project.versions.sort
319 319 end
320 320
321 321 def list_files
322 322 @versions = @project.versions.sort
323 323 end
324 324
325 325 # Show changelog for @project
326 326 def changelog
327 327 @trackers = @project.trackers.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position')
328 328 retrieve_selected_tracker_ids(@trackers)
329 329 @versions = @project.versions.sort
330 330 end
331 331
332 332 def roadmap
333 333 @trackers = @project.trackers.find(:all, :conditions => ["is_in_roadmap=?", true])
334 334 retrieve_selected_tracker_ids(@trackers)
335 335 @versions = @project.versions.sort
336 336 @versions = @versions.select {|v| !v.completed? } unless params[:completed]
337 337 end
338 338
339 339 def activity
340 340 if params[:year] and params[:year].to_i > 1900
341 341 @year = params[:year].to_i
342 342 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
343 343 @month = params[:month].to_i
344 344 end
345 345 end
346 346 @year ||= Date.today.year
347 347 @month ||= Date.today.month
348 348
349 349 case params[:format]
350 350 when 'atom'
351 351 # 30 last days
352 352 @date_from = Date.today - 30
353 353 @date_to = Date.today + 1
354 354 else
355 355 # current month
356 356 @date_from = Date.civil(@year, @month, 1)
357 357 @date_to = @date_from >> 1
358 358 end
359 359
360 360 @event_types = %w(issues news files documents changesets wiki_pages messages)
361 361 @event_types.delete('wiki_pages') unless @project.wiki
362 362 @event_types.delete('changesets') unless @project.repository
363 363 @event_types.delete('messages') unless @project.boards.any?
364 364 # only show what the user is allowed to view
365 365 @event_types = @event_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, @project)}
366 366
367 367 @scope = @event_types.select {|t| params["show_#{t}"]}
368 368 # default events if none is specified in parameters
369 369 @scope = (@event_types - %w(wiki_pages messages))if @scope.empty?
370 370
371 371 @events = []
372 372
373 373 if @scope.include?('issues')
374 374 @events += @project.issues.find(:all, :include => [:author, :tracker], :conditions => ["#{Issue.table_name}.created_on>=? and #{Issue.table_name}.created_on<=?", @date_from, @date_to] )
375 375 @events += @project.issues_status_changes(@date_from, @date_to)
376 376 end
377 377
378 378 if @scope.include?('news')
379 379 @events += @project.news.find(:all, :conditions => ["#{News.table_name}.created_on>=? and #{News.table_name}.created_on<=?", @date_from, @date_to], :include => :author )
380 380 end
381 381
382 382 if @scope.include?('files')
383 383 @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 )
384 384 end
385 385
386 386 if @scope.include?('documents')
387 387 @events += @project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on>=? and #{Document.table_name}.created_on<=?", @date_from, @date_to] )
388 388 @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 )
389 389 end
390 390
391 391 if @scope.include?('wiki_pages')
392 392 select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " +
393 393 "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title, " +
394 394 "#{WikiContent.versioned_table_name}.page_id, #{WikiContent.versioned_table_name}.author_id, " +
395 395 "#{WikiContent.versioned_table_name}.id"
396 396 joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " +
397 397 "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id "
398 398 conditions = ["#{Wiki.table_name}.project_id = ? AND #{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?",
399 399 @project.id, @date_from, @date_to]
400 400
401 401 @events += WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => conditions)
402 402 end
403 403
404 404 if @scope.include?('changesets')
405 405 @events += Changeset.find(:all, :include => :repository, :conditions => ["#{Repository.table_name}.project_id = ? AND #{Changeset.table_name}.committed_on BETWEEN ? AND ?", @project.id, @date_from, @date_to])
406 406 end
407 407
408 408 if @scope.include?('messages')
409 409 @events += Message.find(:all,
410 410 :include => [:board, :author],
411 411 :conditions => ["#{Board.table_name}.project_id=? AND #{Message.table_name}.parent_id IS NULL AND #{Message.table_name}.created_on BETWEEN ? AND ?", @project.id, @date_from, @date_to])
412 412 end
413 413
414 414 @events_by_day = @events.group_by(&:event_date)
415 415
416 416 respond_to do |format|
417 417 format.html { render :layout => false if request.xhr? }
418 418 format.atom { render_feed(@events, :title => "#{@project.name}: #{l(:label_activity)}") }
419 419 end
420 420 end
421 421
422 422 def calendar
423 423 @trackers = Tracker.find(:all, :order => 'position')
424 424 retrieve_selected_tracker_ids(@trackers)
425 425
426 426 if params[:year] and params[:year].to_i > 1900
427 427 @year = params[:year].to_i
428 428 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
429 429 @month = params[:month].to_i
430 430 end
431 431 end
432 432 @year ||= Date.today.year
433 433 @month ||= Date.today.month
434 434 @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month)
435 435
436 436 events = []
437 437 @project.issues_with_subprojects(params[:with_subprojects]) do
438 438 events += Issue.find(:all,
439 439 :include => [:tracker, :status, :assigned_to, :priority, :project],
440 440 :conditions => ["((start_date BETWEEN ? AND ?) OR (due_date BETWEEN ? AND ?)) AND #{Issue.table_name}.tracker_id IN (#{@selected_tracker_ids.join(',')})", @calendar.startdt, @calendar.enddt, @calendar.startdt, @calendar.enddt]
441 441 ) unless @selected_tracker_ids.empty?
442 442 end
443 443 events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt])
444 444 @calendar.events = events
445 445
446 446 render :layout => false if request.xhr?
447 447 end
448 448
449 449 def gantt
450 450 @trackers = Tracker.find(:all, :order => 'position')
451 451 retrieve_selected_tracker_ids(@trackers)
452 452
453 453 if params[:year] and params[:year].to_i >0
454 454 @year_from = params[:year].to_i
455 455 if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12
456 456 @month_from = params[:month].to_i
457 457 else
458 458 @month_from = 1
459 459 end
460 460 else
461 461 @month_from ||= Date.today.month
462 462 @year_from ||= Date.today.year
463 463 end
464 464
465 465 zoom = (params[:zoom] || User.current.pref[:gantt_zoom]).to_i
466 466 @zoom = (zoom > 0 && zoom < 5) ? zoom : 2
467 467 months = (params[:months] || User.current.pref[:gantt_months]).to_i
468 468 @months = (months > 0 && months < 25) ? months : 6
469 469
470 470 # Save gantt paramters as user preference (zoom and months count)
471 471 if (User.current.logged? && (@zoom != User.current.pref[:gantt_zoom] || @months != User.current.pref[:gantt_months]))
472 472 User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months
473 473 User.current.preference.save
474 474 end
475 475
476 476 @date_from = Date.civil(@year_from, @month_from, 1)
477 477 @date_to = (@date_from >> @months) - 1
478 478
479 479 @events = []
480 480 @project.issues_with_subprojects(params[:with_subprojects]) do
481 481 @events += Issue.find(:all,
482 482 :order => "start_date, due_date",
483 483 :include => [:tracker, :status, :assigned_to, :priority, :project],
484 484 :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]
485 485 ) unless @selected_tracker_ids.empty?
486 486 end
487 487 @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to])
488 488 @events.sort! {|x,y| x.start_date <=> y.start_date }
489 489
490 490 if params[:format]=='pdf'
491 491 @options_for_rfpdf ||= {}
492 492 @options_for_rfpdf[:file_name] = "#{@project.identifier}-gantt.pdf"
493 493 render :template => "projects/gantt.rfpdf", :layout => false
494 494 elsif params[:format]=='png' && respond_to?('gantt_image')
495 495 image = gantt_image(@events, @date_from, @months, @zoom)
496 496 image.format = 'PNG'
497 497 send_data(image.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "#{@project.identifier}-gantt.png")
498 498 else
499 499 render :template => "projects/gantt.rhtml"
500 500 end
501 501 end
502 502
503 503 private
504 504 # Find project of id params[:id]
505 505 # if not found, redirect to project list
506 506 # Used as a before_filter
507 507 def find_project
508 508 @project = Project.find(params[:id])
509 509 rescue ActiveRecord::RecordNotFound
510 510 render_404
511 511 end
512 512
513 513 def retrieve_selected_tracker_ids(selectable_trackers)
514 514 if ids = params[:tracker_ids]
515 515 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
516 516 else
517 517 @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s }
518 518 end
519 519 end
520 520 end
General Comments 0
You need to be logged in to leave comments. Login now