##// END OF EJS Templates
Fixed: upload doesn't work in "Files" section....
Jean-Philippe Lang -
r996:fc26668cd98c
parent child
Show More
@@ -1,548 +1,548
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 document to @project
181 181 def add_document
182 182 @document = @project.documents.build(params[:document])
183 183 if request.post? and @document.save
184 184 attach_files(@document, params[:attachments])
185 185 flash[:notice] = l(:notice_successful_create)
186 186 Mailer.deliver_document_added(@document) if Setting.notified_events.include?('document_added')
187 187 redirect_to :action => 'list_documents', :id => @project
188 188 end
189 189 end
190 190
191 191 # Show documents list of @project
192 192 def list_documents
193 193 @sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category'
194 194 documents = @project.documents.find :all, :include => [:attachments, :category]
195 195 case @sort_by
196 196 when 'date'
197 197 @grouped = documents.group_by {|d| d.created_on.to_date }
198 198 when 'title'
199 199 @grouped = documents.group_by {|d| d.title.first.upcase}
200 200 when 'author'
201 201 @grouped = documents.select{|d| d.attachments.any?}.group_by {|d| d.attachments.last.author}
202 202 else
203 203 @grouped = documents.group_by(&:category)
204 204 end
205 205 render :layout => false if request.xhr?
206 206 end
207 207
208 208 # Add a new issue to @project
209 209 # The new issue will be created from an existing one if copy_from parameter is given
210 210 def add_issue
211 211 @issue = params[:copy_from] ? Issue.new.copy_from(params[:copy_from]) : Issue.new(params[:issue])
212 212 @issue.project = @project
213 213 @issue.author = User.current
214 214 @issue.tracker ||= @project.trackers.find(params[:tracker_id])
215 215
216 216 default_status = IssueStatus.default
217 217 unless default_status
218 218 flash.now[:error] = 'No default issue status is defined. Please check your configuration (Go to "Administration -> Issue statuses").'
219 219 render :nothing => true, :layout => true
220 220 return
221 221 end
222 222 @issue.status = default_status
223 223 @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(User.current.role_for_project(@project), @issue.tracker))
224 224
225 225 if request.get?
226 226 @issue.start_date ||= Date.today
227 227 @custom_values = @issue.custom_values.empty? ?
228 228 @project.custom_fields_for_issues(@issue.tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) } :
229 229 @issue.custom_values
230 230 else
231 231 requested_status = IssueStatus.find_by_id(params[:issue][:status_id])
232 232 # Check that the user is allowed to apply the requested status
233 233 @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status
234 234 @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]) }
235 235 @issue.custom_values = @custom_values
236 236 if @issue.save
237 237 attach_files(@issue, params[:attachments])
238 238 flash[:notice] = l(:notice_successful_create)
239 239 Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added')
240 240 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
241 241 return
242 242 end
243 243 end
244 244 @priorities = Enumeration::get_values('IPRI')
245 245 end
246 246
247 247 # Bulk edit issues
248 248 def bulk_edit_issues
249 249 if request.post?
250 250 status = params[:status_id].blank? ? nil : IssueStatus.find_by_id(params[:status_id])
251 251 priority = params[:priority_id].blank? ? nil : Enumeration.find_by_id(params[:priority_id])
252 252 assigned_to = params[:assigned_to_id].blank? ? nil : User.find_by_id(params[:assigned_to_id])
253 253 category = params[:category_id].blank? ? nil : @project.issue_categories.find_by_id(params[:category_id])
254 254 fixed_version = params[:fixed_version_id].blank? ? nil : @project.versions.find_by_id(params[:fixed_version_id])
255 255 issues = @project.issues.find_all_by_id(params[:issue_ids])
256 256 unsaved_issue_ids = []
257 257 issues.each do |issue|
258 258 journal = issue.init_journal(User.current, params[:notes])
259 259 issue.priority = priority if priority
260 260 issue.assigned_to = assigned_to if assigned_to || params[:assigned_to_id] == 'none'
261 261 issue.category = category if category
262 262 issue.fixed_version = fixed_version if fixed_version
263 263 issue.start_date = params[:start_date] unless params[:start_date].blank?
264 264 issue.due_date = params[:due_date] unless params[:due_date].blank?
265 265 issue.done_ratio = params[:done_ratio] unless params[:done_ratio].blank?
266 266 # Don't save any change to the issue if the user is not authorized to apply the requested status
267 267 if (status.nil? || (issue.status.new_status_allowed_to?(status, current_role, issue.tracker) && issue.status = status)) && issue.save
268 268 # Send notification for each issue (if changed)
269 269 Mailer.deliver_issue_edit(journal) if journal.details.any? && Setting.notified_events.include?('issue_updated')
270 270 else
271 271 # Keep unsaved issue ids to display them in flash error
272 272 unsaved_issue_ids << issue.id
273 273 end
274 274 end
275 275 if unsaved_issue_ids.empty?
276 276 flash[:notice] = l(:notice_successful_update) unless issues.empty?
277 277 else
278 278 flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, issues.size, '#' + unsaved_issue_ids.join(', #'))
279 279 end
280 280 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
281 281 return
282 282 end
283 283 if current_role && User.current.allowed_to?(:change_issue_status, @project)
284 284 # Find potential statuses the user could be allowed to switch issues to
285 285 @available_statuses = Workflow.find(:all, :include => :new_status,
286 286 :conditions => {:role_id => current_role.id}).collect(&:new_status).compact.uniq
287 287 end
288 288 render :update do |page|
289 289 page.hide 'query_form'
290 290 page.replace_html 'bulk-edit', :partial => 'issues/bulk_edit_form'
291 291 end
292 292 end
293 293
294 294 def move_issues
295 295 @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids]
296 296 redirect_to :controller => 'issues', :action => 'index', :project_id => @project and return unless @issues
297 297
298 298 @projects = []
299 299 # find projects to which the user is allowed to move the issue
300 300 if User.current.admin?
301 301 # admin is allowed to move issues to any active (visible) project
302 302 @projects = Project.find(:all, :conditions => Project.visible_by(User.current), :order => 'name')
303 303 else
304 304 User.current.memberships.each {|m| @projects << m.project if m.role.allowed_to?(:move_issues)}
305 305 end
306 306 @target_project = @projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id]
307 307 @target_project ||= @project
308 308 @trackers = @target_project.trackers
309 309 if request.post?
310 310 new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id])
311 311 unsaved_issue_ids = []
312 312 @issues.each do |issue|
313 313 unsaved_issue_ids << issue.id unless issue.move_to(@target_project, new_tracker)
314 314 end
315 315 if unsaved_issue_ids.empty?
316 316 flash[:notice] = l(:notice_successful_update) unless @issues.empty?
317 317 else
318 318 flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, @issues.size, '#' + unsaved_issue_ids.join(', #'))
319 319 end
320 320 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
321 321 return
322 322 end
323 323 render :layout => false if request.xhr?
324 324 end
325 325
326 326 # Add a news to @project
327 327 def add_news
328 328 @news = News.new(:project => @project, :author => User.current)
329 329 if request.post?
330 330 @news.attributes = params[:news]
331 331 if @news.save
332 332 flash[:notice] = l(:notice_successful_create)
333 333 Mailer.deliver_news_added(@news) if Setting.notified_events.include?('news_added')
334 334 redirect_to :controller => 'news', :action => 'index', :project_id => @project
335 335 end
336 336 end
337 337 end
338 338
339 339 def add_file
340 340 if request.post?
341 341 @version = @project.versions.find_by_id(params[:version_id])
342 attachments = attach_files(@issue, params[:attachments])
342 attachments = attach_files(@version, params[:attachments])
343 343 Mailer.deliver_attachments_added(attachments) if !attachments.empty? && Setting.notified_events.include?('file_added')
344 344 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
345 345 end
346 346 @versions = @project.versions.sort
347 347 end
348 348
349 349 def list_files
350 350 @versions = @project.versions.sort
351 351 end
352 352
353 353 # Show changelog for @project
354 354 def changelog
355 355 @trackers = @project.trackers.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position')
356 356 retrieve_selected_tracker_ids(@trackers)
357 357 @versions = @project.versions.sort
358 358 end
359 359
360 360 def roadmap
361 361 @trackers = @project.trackers.find(:all, :conditions => ["is_in_roadmap=?", true])
362 362 retrieve_selected_tracker_ids(@trackers)
363 363 @versions = @project.versions.sort
364 364 @versions = @versions.select {|v| !v.completed? } unless params[:completed]
365 365 end
366 366
367 367 def activity
368 368 if params[:year] and params[:year].to_i > 1900
369 369 @year = params[:year].to_i
370 370 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
371 371 @month = params[:month].to_i
372 372 end
373 373 end
374 374 @year ||= Date.today.year
375 375 @month ||= Date.today.month
376 376
377 377 case params[:format]
378 378 when 'atom'
379 379 # 30 last days
380 380 @date_from = Date.today - 30
381 381 @date_to = Date.today + 1
382 382 else
383 383 # current month
384 384 @date_from = Date.civil(@year, @month, 1)
385 385 @date_to = @date_from >> 1
386 386 end
387 387
388 388 @event_types = %w(issues news files documents changesets wiki_pages messages)
389 389 @event_types.delete('wiki_pages') unless @project.wiki
390 390 @event_types.delete('changesets') unless @project.repository
391 391 @event_types.delete('messages') unless @project.boards.any?
392 392 # only show what the user is allowed to view
393 393 @event_types = @event_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, @project)}
394 394
395 395 @scope = @event_types.select {|t| params["show_#{t}"]}
396 396 # default events if none is specified in parameters
397 397 @scope = (@event_types - %w(wiki_pages messages))if @scope.empty?
398 398
399 399 @events = []
400 400
401 401 if @scope.include?('issues')
402 402 @events += @project.issues.find(:all, :include => [:author, :tracker], :conditions => ["#{Issue.table_name}.created_on>=? and #{Issue.table_name}.created_on<=?", @date_from, @date_to] )
403 403 @events += @project.issues_status_changes(@date_from, @date_to)
404 404 end
405 405
406 406 if @scope.include?('news')
407 407 @events += @project.news.find(:all, :conditions => ["#{News.table_name}.created_on>=? and #{News.table_name}.created_on<=?", @date_from, @date_to], :include => :author )
408 408 end
409 409
410 410 if @scope.include?('files')
411 411 @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 )
412 412 end
413 413
414 414 if @scope.include?('documents')
415 415 @events += @project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on>=? and #{Document.table_name}.created_on<=?", @date_from, @date_to] )
416 416 @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 )
417 417 end
418 418
419 419 if @scope.include?('wiki_pages')
420 420 select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " +
421 421 "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title, " +
422 422 "#{WikiContent.versioned_table_name}.page_id, #{WikiContent.versioned_table_name}.author_id, " +
423 423 "#{WikiContent.versioned_table_name}.id"
424 424 joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " +
425 425 "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id "
426 426 conditions = ["#{Wiki.table_name}.project_id = ? AND #{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?",
427 427 @project.id, @date_from, @date_to]
428 428
429 429 @events += WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => conditions)
430 430 end
431 431
432 432 if @scope.include?('changesets')
433 433 @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])
434 434 end
435 435
436 436 if @scope.include?('messages')
437 437 @events += Message.find(:all,
438 438 :include => [:board, :author],
439 439 :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])
440 440 end
441 441
442 442 @events_by_day = @events.group_by(&:event_date)
443 443
444 444 respond_to do |format|
445 445 format.html { render :layout => false if request.xhr? }
446 446 format.atom { render_feed(@events, :title => "#{@project.name}: #{l(:label_activity)}") }
447 447 end
448 448 end
449 449
450 450 def calendar
451 451 @trackers = Tracker.find(:all, :order => 'position')
452 452 retrieve_selected_tracker_ids(@trackers)
453 453
454 454 if params[:year] and params[:year].to_i > 1900
455 455 @year = params[:year].to_i
456 456 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
457 457 @month = params[:month].to_i
458 458 end
459 459 end
460 460 @year ||= Date.today.year
461 461 @month ||= Date.today.month
462 462 @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month)
463 463
464 464 events = []
465 465 @project.issues_with_subprojects(params[:with_subprojects]) do
466 466 events += Issue.find(:all,
467 467 :include => [:tracker, :status, :assigned_to, :priority, :project],
468 468 :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]
469 469 ) unless @selected_tracker_ids.empty?
470 470 end
471 471 events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt])
472 472 @calendar.events = events
473 473
474 474 render :layout => false if request.xhr?
475 475 end
476 476
477 477 def gantt
478 478 @trackers = Tracker.find(:all, :order => 'position')
479 479 retrieve_selected_tracker_ids(@trackers)
480 480
481 481 if params[:year] and params[:year].to_i >0
482 482 @year_from = params[:year].to_i
483 483 if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12
484 484 @month_from = params[:month].to_i
485 485 else
486 486 @month_from = 1
487 487 end
488 488 else
489 489 @month_from ||= Date.today.month
490 490 @year_from ||= Date.today.year
491 491 end
492 492
493 493 zoom = (params[:zoom] || User.current.pref[:gantt_zoom]).to_i
494 494 @zoom = (zoom > 0 && zoom < 5) ? zoom : 2
495 495 months = (params[:months] || User.current.pref[:gantt_months]).to_i
496 496 @months = (months > 0 && months < 25) ? months : 6
497 497
498 498 # Save gantt paramters as user preference (zoom and months count)
499 499 if (User.current.logged? && (@zoom != User.current.pref[:gantt_zoom] || @months != User.current.pref[:gantt_months]))
500 500 User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months
501 501 User.current.preference.save
502 502 end
503 503
504 504 @date_from = Date.civil(@year_from, @month_from, 1)
505 505 @date_to = (@date_from >> @months) - 1
506 506
507 507 @events = []
508 508 @project.issues_with_subprojects(params[:with_subprojects]) do
509 509 @events += Issue.find(:all,
510 510 :order => "start_date, due_date",
511 511 :include => [:tracker, :status, :assigned_to, :priority, :project],
512 512 :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]
513 513 ) unless @selected_tracker_ids.empty?
514 514 end
515 515 @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to])
516 516 @events.sort! {|x,y| x.start_date <=> y.start_date }
517 517
518 518 if params[:format]=='pdf'
519 519 @options_for_rfpdf ||= {}
520 520 @options_for_rfpdf[:file_name] = "#{@project.identifier}-gantt.pdf"
521 521 render :template => "projects/gantt.rfpdf", :layout => false
522 522 elsif params[:format]=='png' && respond_to?('gantt_image')
523 523 image = gantt_image(@events, @date_from, @months, @zoom)
524 524 image.format = 'PNG'
525 525 send_data(image.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "#{@project.identifier}-gantt.png")
526 526 else
527 527 render :template => "projects/gantt.rhtml"
528 528 end
529 529 end
530 530
531 531 private
532 532 # Find project of id params[:id]
533 533 # if not found, redirect to project list
534 534 # Used as a before_filter
535 535 def find_project
536 536 @project = Project.find(params[:id])
537 537 rescue ActiveRecord::RecordNotFound
538 538 render_404
539 539 end
540 540
541 541 def retrieve_selected_tracker_ids(selectable_trackers)
542 542 if ids = params[:tracker_ids]
543 543 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
544 544 else
545 545 @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s }
546 546 end
547 547 end
548 548 end
General Comments 0
You need to be logged in to leave comments. Login now