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