diff 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
line wrap: on
line diff
--- a/app/models/.svn/text-base/project.rb.svn-base	Wed Aug 25 16:30:24 2010 +0100
+++ b/app/models/.svn/text-base/project.rb.svn-base	Fri Sep 24 14:06:04 2010 +0100
@@ -412,6 +412,58 @@
   def short_description(length = 255)
     description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description
   end
+
+  def css_classes
+    s = 'project'
+    s << ' root' if root?
+    s << ' child' if child?
+    s << (leaf? ? ' leaf' : ' parent')
+    s
+  end
+
+  # The earliest start date of a project, based on it's issues and versions
+  def start_date
+    if module_enabled?(:issue_tracking)
+      [
+       issues.minimum('start_date'),
+       shared_versions.collect(&:effective_date),
+       shared_versions.collect {|v| v.fixed_issues.minimum('start_date')}
+      ].flatten.compact.min
+    end
+  end
+
+  # The latest due date of an issue or version
+  def due_date
+    if module_enabled?(:issue_tracking)
+      [
+       issues.maximum('due_date'),
+       shared_versions.collect(&:effective_date),
+       shared_versions.collect {|v| v.fixed_issues.maximum('due_date')}
+      ].flatten.compact.max
+    end
+  end
+
+  def overdue?
+    active? && !due_date.nil? && (due_date < Date.today)
+  end
+
+  # Returns the percent completed for this project, based on the
+  # progress on it's versions.
+  def completed_percent(options={:include_subprojects => false})
+    if options.delete(:include_subprojects)
+      total = self_and_descendants.collect(&:completed_percent).sum
+
+      total / self_and_descendants.count
+    else
+      if versions.count > 0
+        total = versions.collect(&:completed_pourcent).sum
+
+        total / versions.count
+      else
+        100
+      end
+    end
+  end
   
   # Return true if this project is allowed to do the specified action.
   # action can be:
@@ -441,6 +493,15 @@
       enabled_modules.clear
     end
   end
+
+  # Returns an array of projects that are in this project's hierarchy
+  #
+  # Example: parents, children, siblings
+  def hierarchy
+    parents = project.self_and_ancestors || []
+    descendants = project.descendants || []
+    project_hierarchy = parents | descendants # Set union
+  end
   
   # Returns an auto-generated project identifier based on the last identifier used
   def self.next_identifier