Class: Version
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Version
- Defined in:
- app/models/version.rb
Overview
redMine - project management software Copyright (C) 2006 Jean-Philippe Lang
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Constant Summary
- VERSION_STATUSES =
%w(open locked closed)
- VERSION_SHARINGS =
%w(none descendants hierarchy tree system)
Instance Method Summary
-
- (Object) <=>(version)
Versions are sorted by effective_date and name Those with no effective_date are at the end, sorted by name.
-
- (Object) allowed_sharings(user = User.current)
Returns the sharings that user can set the version to.
- - (Boolean) closed?
-
- (Object) closed_issues_count
Returns the total amount of closed issues for this version.
-
- (Object) closed_pourcent
Returns the percentage of issues that have been marked as ‘closed’.
-
- (Boolean) completed?
Returns true if the version is completed: due date reached and no open issues.
-
- (Object) completed_pourcent
Returns the completion percentage of this version based on the amount of open/closed issues and the time spent on the open issues.
- - (Object) due_date
-
- (Object) estimated_hours
Returns the total estimated time for this version.
-
- (Object) issues_count
Returns assigned issues count.
- - (Boolean) open?
-
- (Object) open_issues_count
Returns the total amount of open issues for this version.
-
- (Boolean) overdue?
Returns true if the version is overdue: due date reached and some open issues.
-
- (Object) spent_hours
Returns the total reported time for this version.
- - (Object) start_date
- - (Object) to_s
-
- (Boolean) visible?(user = User.current)
Returns true if user or current user is allowed to view the version.
- - (Object) wiki_page
Methods inherited from ActiveRecord::Base
Instance Method Details
- (Object) <=>(version)
Versions are sorted by effective_date and name Those with no effective_date are at the end, sorted by name
129 130 131 132 133 134 135 |
# File 'app/models/version.rb', line 129 def <=>(version) if self.effective_date version.effective_date ? (self.effective_date == version.effective_date ? self.name <=> version.name : self.effective_date <=> version.effective_date) : -1 else version.effective_date ? 1 : (self.name <=> version.name) end end |
- (Object) allowed_sharings(user = User.current)
Returns the sharings that user can set the version to
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'app/models/version.rb', line 138 def allowed_sharings(user = User.current) VERSION_SHARINGS.select do |s| if == s true else case s when 'system' # Only admin users can set a systemwide sharing user.admin? when 'hierarchy', 'tree' # Only users allowed to manage versions of the root project can # set sharing to hierarchy or tree project.nil? || user.allowed_to?(:manage_versions, project.root) else true end end end end |
- (Boolean) closed?
64 65 66 |
# File 'app/models/version.rb', line 64 def closed? status == 'closed' end |
- (Object) closed_issues_count
Returns the total amount of closed issues for this version.
114 115 116 |
# File 'app/models/version.rb', line 114 def closed_issues_count @closed_issues_count ||= Issue.count(:all, :conditions => ["fixed_version_id = ? AND is_closed = ?", self.id, true], :include => :status) end |
- (Object) closed_pourcent
Returns the percentage of issues that have been marked as ‘closed’.
90 91 92 93 94 95 96 |
# File 'app/models/version.rb', line 90 def closed_pourcent if issues_count == 0 0 else issues_progress(false) end end |
- (Boolean) completed?
Returns true if the version is completed: due date reached and no open issues
73 74 75 |
# File 'app/models/version.rb', line 73 def completed? effective_date && (effective_date <= Date.today) && (open_issues_count == 0) end |
- (Object) completed_pourcent
Returns the completion percentage of this version based on the amount of open/closed issues and the time spent on the open issues.
79 80 81 82 83 84 85 86 87 |
# File 'app/models/version.rb', line 79 def completed_pourcent if issues_count == 0 0 elsif open_issues_count == 0 100 else issues_progress(false) + issues_progress(true) end end |
- (Object) due_date
50 51 52 |
# File 'app/models/version.rb', line 50 def due_date effective_date end |
- (Object) estimated_hours
Returns the total estimated time for this version
55 56 57 |
# File 'app/models/version.rb', line 55 def estimated_hours @estimated_hours ||= fixed_issues.sum(:estimated_hours).to_f end |
- (Object) issues_count
Returns assigned issues count
104 105 106 |
# File 'app/models/version.rb', line 104 def issues_count @issue_count ||= fixed_issues.count end |
- (Boolean) open?
68 69 70 |
# File 'app/models/version.rb', line 68 def open? status == 'open' end |
- (Object) open_issues_count
Returns the total amount of open issues for this version.
109 110 111 |
# File 'app/models/version.rb', line 109 def open_issues_count @open_issues_count ||= Issue.count(:all, :conditions => ["fixed_version_id = ? AND is_closed = ?", self.id, false], :include => :status) end |
- (Boolean) overdue?
Returns true if the version is overdue: due date reached and some open issues
99 100 101 |
# File 'app/models/version.rb', line 99 def overdue? effective_date && (effective_date < Date.today) && (open_issues_count > 0) end |
- (Object) spent_hours
Returns the total reported time for this version
60 61 62 |
# File 'app/models/version.rb', line 60 def spent_hours @spent_hours ||= TimeEntry.sum(:hours, :include => :issue, :conditions => ["#{Issue.table_name}.fixed_version_id = ?", id]).to_f end |
- (Object) start_date
46 47 48 |
# File 'app/models/version.rb', line 46 def start_date effective_date end |
- (Object) to_s
125 |
# File 'app/models/version.rb', line 125 def to_s; name end |
- (Boolean) visible?(user = User.current)
Returns true if user or current user is allowed to view the version
42 43 44 |
# File 'app/models/version.rb', line 42 def visible?(user=User.current) user.allowed_to?(:view_issues, self.project) end |
- (Object) wiki_page
118 119 120 121 122 123 |
# File 'app/models/version.rb', line 118 def wiki_page if project.wiki && !wiki_page_title.blank? @wiki_page ||= project.wiki.find_page(wiki_page_title) end @wiki_page end |