Mercurial > hg > soundsoftware-site
comparison app/models/.svn/text-base/project.rb.svn-base @ 22:40f7cfd4df19
* Update to SVN trunk rev 4173
author | Chris Cannam <chris.cannam@soundsoftware.ac.uk> |
---|---|
date | Fri, 24 Sep 2010 14:06:04 +0100 |
parents | 513646585e45 |
children | 94944d00e43c |
comparison
equal
deleted
inserted
replaced
14:1d32c0a0efbf | 22:40f7cfd4df19 |
---|---|
410 | 410 |
411 # Returns a short description of the projects (first lines) | 411 # Returns a short description of the projects (first lines) |
412 def short_description(length = 255) | 412 def short_description(length = 255) |
413 description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description | 413 description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description |
414 end | 414 end |
415 | |
416 def css_classes | |
417 s = 'project' | |
418 s << ' root' if root? | |
419 s << ' child' if child? | |
420 s << (leaf? ? ' leaf' : ' parent') | |
421 s | |
422 end | |
423 | |
424 # The earliest start date of a project, based on it's issues and versions | |
425 def start_date | |
426 if module_enabled?(:issue_tracking) | |
427 [ | |
428 issues.minimum('start_date'), | |
429 shared_versions.collect(&:effective_date), | |
430 shared_versions.collect {|v| v.fixed_issues.minimum('start_date')} | |
431 ].flatten.compact.min | |
432 end | |
433 end | |
434 | |
435 # The latest due date of an issue or version | |
436 def due_date | |
437 if module_enabled?(:issue_tracking) | |
438 [ | |
439 issues.maximum('due_date'), | |
440 shared_versions.collect(&:effective_date), | |
441 shared_versions.collect {|v| v.fixed_issues.maximum('due_date')} | |
442 ].flatten.compact.max | |
443 end | |
444 end | |
445 | |
446 def overdue? | |
447 active? && !due_date.nil? && (due_date < Date.today) | |
448 end | |
449 | |
450 # Returns the percent completed for this project, based on the | |
451 # progress on it's versions. | |
452 def completed_percent(options={:include_subprojects => false}) | |
453 if options.delete(:include_subprojects) | |
454 total = self_and_descendants.collect(&:completed_percent).sum | |
455 | |
456 total / self_and_descendants.count | |
457 else | |
458 if versions.count > 0 | |
459 total = versions.collect(&:completed_pourcent).sum | |
460 | |
461 total / versions.count | |
462 else | |
463 100 | |
464 end | |
465 end | |
466 end | |
415 | 467 |
416 # Return true if this project is allowed to do the specified action. | 468 # Return true if this project is allowed to do the specified action. |
417 # action can be: | 469 # action can be: |
418 # * a parameter-like Hash (eg. :controller => 'projects', :action => 'edit') | 470 # * a parameter-like Hash (eg. :controller => 'projects', :action => 'edit') |
419 # * a permission Symbol (eg. :edit_project) | 471 # * a permission Symbol (eg. :edit_project) |
438 # add new modules | 490 # add new modules |
439 module_names.reject {|name| module_enabled?(name)}.each {|name| enabled_modules << EnabledModule.new(:name => name)} | 491 module_names.reject {|name| module_enabled?(name)}.each {|name| enabled_modules << EnabledModule.new(:name => name)} |
440 else | 492 else |
441 enabled_modules.clear | 493 enabled_modules.clear |
442 end | 494 end |
495 end | |
496 | |
497 # Returns an array of projects that are in this project's hierarchy | |
498 # | |
499 # Example: parents, children, siblings | |
500 def hierarchy | |
501 parents = project.self_and_ancestors || [] | |
502 descendants = project.descendants || [] | |
503 project_hierarchy = parents | descendants # Set union | |
443 end | 504 end |
444 | 505 |
445 # Returns an auto-generated project identifier based on the last identifier used | 506 # Returns an auto-generated project identifier based on the last identifier used |
446 def self.next_identifier | 507 def self.next_identifier |
447 p = Project.find(:first, :order => 'created_on DESC') | 508 p = Project.find(:first, :order => 'created_on DESC') |