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