Class: Version
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Version
- Includes:
- Redmine::SafeAttributes
- Defined in:
- app/models/version.rb
Overview
Redmine - project management software Copyright (C) 2006-2016 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 collapse
- VERSION_STATUSES =
%w(open locked closed)
- VERSION_SHARINGS =
%w(none descendants hierarchy tree system)
Class Method Summary collapse
Instance Method Summary collapse
-
#<=>(version) ⇒ Object
Versions are sorted by effective_date and name Those with no effective_date are at the end, sorted by name.
-
#allowed_sharings(user = User.current) ⇒ Object
Returns the sharings that
user
can set the version to. - #attachments_deletable?(usr = User.current) ⇒ Boolean
-
#attachments_visible?(*args) ⇒ Boolean
Version files have same visibility as project files.
- #behind_schedule? ⇒ Boolean
- #closed? ⇒ Boolean
-
#closed_issues_count ⇒ Object
Returns the total amount of closed issues for this version.
-
#closed_percent ⇒ Object
Returns the percentage of issues that have been marked as 'closed'.
-
#completed? ⇒ Boolean
Returns true if the version is completed: closed or due date reached and no open issues.
-
#completed_percent ⇒ Object
Returns the completion percentage of this version based on the amount of open/closed issues and the time spent on the open issues.
- #css_classes ⇒ Object
- #deletable? ⇒ Boolean
- #due_date ⇒ Object
- #due_date=(arg) ⇒ Object
-
#estimated_hours ⇒ Object
Returns the total estimated time for this version (sum of leaves estimated_hours).
-
#issues_count ⇒ Object
Returns assigned issues count.
- #open? ⇒ Boolean
-
#open_issues_count ⇒ Object
Returns the total amount of open issues for this version.
-
#overdue? ⇒ Boolean
Returns true if the version is overdue: due date reached and some open issues.
-
#shared? ⇒ Boolean
Returns true if the version is shared, otherwise false.
-
#spent_hours ⇒ Object
Returns the total reported time for this version.
- #start_date ⇒ Object
- #to_s ⇒ Object
- #to_s_with_project ⇒ Object
-
#visible?(user = User.current) ⇒ Boolean
Returns true if
user
or current user is allowed to view the version. - #wiki_page ⇒ Object
Methods included from Redmine::SafeAttributes
#delete_unsafe_attributes, #safe_attribute?, #safe_attribute_names, #safe_attributes=
Class Method Details
.fields_for_order_statement(table = nil) ⇒ Object
207 208 209 210 |
# File 'app/models/version.rb', line 207 def self.fields_for_order_statement(table=nil) table ||= table_name ["(CASE WHEN #{table}.effective_date IS NULL THEN 1 ELSE 0 END)", "#{table}.effective_date", "#{table}.name", "#{table}.id"] end |
Instance Method Details
#<=>(version) ⇒ Object
Versions are sorted by effective_date and name Those with no effective_date are at the end, sorted by name
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'app/models/version.rb', line 180 def <=>(version) if self.effective_date if version.effective_date if self.effective_date == version.effective_date name == version.name ? id <=> version.id : name <=> version.name else self.effective_date <=> version.effective_date end else -1 end else if version.effective_date 1 else name == version.name ? id <=> version.id : name <=> version.name end end end |
#allowed_sharings(user = User.current) ⇒ Object
Returns the sharings that user
can set the version to
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'app/models/version.rb', line 215 def allowed_sharings(user = User.current) VERSION_SHARINGS.select do |s| if sharing == 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 |
#attachments_deletable?(usr = User.current) ⇒ Boolean
70 71 72 |
# File 'app/models/version.rb', line 70 def (usr=User.current) project.present? && project.(usr) end |
#attachments_visible?(*args) ⇒ Boolean
Version files have same visibility as project files
66 67 68 |
# File 'app/models/version.rb', line 66 def (*args) project.present? && project.(*args) end |
#behind_schedule? ⇒ Boolean
110 111 112 113 114 115 116 117 118 119 |
# File 'app/models/version.rb', line 110 def behind_schedule? if completed_percent == 100 return false elsif due_date && start_date done_date = start_date + ((due_date - start_date+1)* completed_percent/100).floor return done_date <= User.current.today else false # No issues so it's not late end end |
#closed? ⇒ Boolean
97 98 99 |
# File 'app/models/version.rb', line 97 def closed? status == 'closed' end |
#closed_issues_count ⇒ Object
Returns the total amount of closed issues for this version.
160 161 162 163 |
# File 'app/models/version.rb', line 160 def closed_issues_count load_issue_counts @closed_issues_count end |
#closed_percent ⇒ Object
Returns the percentage of issues that have been marked as 'closed'.
134 135 136 137 138 139 140 |
# File 'app/models/version.rb', line 134 def closed_percent if issues_count == 0 0 else issues_progress(false) end end |
#completed? ⇒ Boolean
Returns true if the version is completed: closed or due date reached and no open issues
106 107 108 |
# File 'app/models/version.rb', line 106 def completed? closed? || (effective_date && (effective_date < User.current.today) && (open_issues_count == 0)) end |
#completed_percent ⇒ Object
Returns the completion percentage of this version based on the amount of open/closed issues and the time spent on the open issues.
123 124 125 126 127 128 129 130 131 |
# File 'app/models/version.rb', line 123 def completed_percent if issues_count == 0 0 elsif open_issues_count == 0 100 else issues_progress(false) + issues_progress(true) end end |
#css_classes ⇒ Object
200 201 202 203 204 205 |
# File 'app/models/version.rb', line 200 def css_classes [ completed? ? 'version-completed' : 'version-incompleted', "version-#{status}" ].join(' ') end |
#deletable? ⇒ Boolean
240 241 242 |
# File 'app/models/version.rb', line 240 def deletable? fixed_issues.empty? && !referenced_by_a_custom_field? end |
#due_date ⇒ Object
78 79 80 |
# File 'app/models/version.rb', line 78 def due_date effective_date end |
#due_date=(arg) ⇒ Object
82 83 84 |
# File 'app/models/version.rb', line 82 def due_date=(arg) self.effective_date=(arg) end |
#estimated_hours ⇒ Object
Returns the total estimated time for this version (sum of leaves estimated_hours)
88 89 90 |
# File 'app/models/version.rb', line 88 def estimated_hours @estimated_hours ||= fixed_issues.sum(:estimated_hours).to_f end |
#issues_count ⇒ Object
Returns assigned issues count
148 149 150 151 |
# File 'app/models/version.rb', line 148 def issues_count load_issue_counts @issue_count end |
#open? ⇒ Boolean
101 102 103 |
# File 'app/models/version.rb', line 101 def open? status == 'open' end |
#open_issues_count ⇒ Object
Returns the total amount of open issues for this version.
154 155 156 157 |
# File 'app/models/version.rb', line 154 def open_issues_count load_issue_counts @open_issues_count end |
#overdue? ⇒ Boolean
Returns true if the version is overdue: due date reached and some open issues
143 144 145 |
# File 'app/models/version.rb', line 143 def overdue? effective_date && (effective_date < User.current.today) && (open_issues_count > 0) end |
#shared? ⇒ Boolean
Returns true if the version is shared, otherwise false
236 237 238 |
# File 'app/models/version.rb', line 236 def shared? sharing != 'none' end |
#spent_hours ⇒ Object
Returns the total reported time for this version
93 94 95 |
# File 'app/models/version.rb', line 93 def spent_hours @spent_hours ||= TimeEntry.joins(:issue).where("#{Issue.table_name}.fixed_version_id = ?", id).sum(:hours).to_f end |
#start_date ⇒ Object
74 75 76 |
# File 'app/models/version.rb', line 74 def start_date @start_date ||= fixed_issues.minimum('start_date') end |
#to_s ⇒ Object
172 |
# File 'app/models/version.rb', line 172 def to_s; name end |
#to_s_with_project ⇒ Object
174 175 176 |
# File 'app/models/version.rb', line 174 def to_s_with_project "#{project} - #{name}" end |
#visible?(user = User.current) ⇒ Boolean
Returns true if user
or current user is allowed to view the
version
61 62 63 |
# File 'app/models/version.rb', line 61 def visible?(user=User.current) user.allowed_to?(:view_issues, self.project) end |
#wiki_page ⇒ Object
165 166 167 168 169 170 |
# File 'app/models/version.rb', line 165 def wiki_page if project.wiki && !wiki_page_title.blank? @wiki_page ||= project.wiki.find_page(wiki_page_title) end @wiki_page end |