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-2017 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
- .fields_for_order_statement(table = nil) ⇒ Object
-
.sort_by_status(versions) ⇒ Object
Sort versions by status (open, locked then closed versions).
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.
- #base_reload ⇒ Object
- #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
- #default_project_version ⇒ Object
- #default_project_version=(arg) ⇒ 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.
- #reload(*args) ⇒ Object
-
#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. - #visible_fixed_issues ⇒ Object
- #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
318 319 320 321 |
# File 'app/models/version.rb', line 318 def self.fields_for_order_statement(table=nil) table ||= table_name [Arel.sql("(CASE WHEN #{table}.effective_date IS NULL THEN 1 ELSE 0 END)"), "#{table}.effective_date", "#{table}.name", "#{table}.id"] end |
.sort_by_status(versions) ⇒ Object
Sort versions by status (open, locked then closed versions)
301 302 303 304 305 306 307 308 309 |
# File 'app/models/version.rb', line 301 def self.sort_by_status(versions) versions.sort do |a, b| if a.status == b.status a <=> b else b.status <=> a.status end end 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
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 |
# File 'app/models/version.rb', line 280 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
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 |
# File 'app/models/version.rb', line 326 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
172 173 174 |
# File 'app/models/version.rb', line 172 def (usr=User.current) project.present? && project.(usr) end |
#attachments_visible?(*args) ⇒ Boolean
Version files have same visibility as project files
168 169 170 |
# File 'app/models/version.rb', line 168 def (*args) project.present? && project.(*args) end |
#base_reload ⇒ Object
176 |
# File 'app/models/version.rb', line 176 alias :base_reload :reload |
#behind_schedule? ⇒ Boolean
219 220 221 222 223 224 225 226 227 228 |
# File 'app/models/version.rb', line 219 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
206 207 208 |
# File 'app/models/version.rb', line 206 def closed? status == 'closed' end |
#closed_issues_count ⇒ Object
Returns the total amount of closed issues for this version.
257 258 259 |
# File 'app/models/version.rb', line 257 def closed_issues_count fixed_issues.closed_count end |
#closed_percent ⇒ Object
Returns the percentage of issues that have been marked as 'closed'.
237 238 239 |
# File 'app/models/version.rb', line 237 def closed_percent fixed_issues.closed_percent end |
#completed? ⇒ Boolean
Returns true if the version is completed: closed or due date reached and no open issues
215 216 217 |
# File 'app/models/version.rb', line 215 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.
232 233 234 |
# File 'app/models/version.rb', line 232 def completed_percent fixed_issues.completed_percent end |
#css_classes ⇒ Object
311 312 313 314 315 316 |
# File 'app/models/version.rb', line 311 def css_classes [ completed? ? 'version-completed' : 'version-incompleted', "version-#{status}" ].join(' ') end |
#default_project_version ⇒ Object
355 356 357 358 359 360 361 |
# File 'app/models/version.rb', line 355 def default_project_version if @default_project_version.nil? project.present? && project.default_version == self else @default_project_version end end |
#default_project_version=(arg) ⇒ Object
363 364 365 |
# File 'app/models/version.rb', line 363 def default_project_version=(arg) @default_project_version = (arg == '1' || arg == true) end |
#deletable? ⇒ Boolean
351 352 353 |
# File 'app/models/version.rb', line 351 def deletable? fixed_issues.empty? && !referenced_by_a_custom_field? end |
#due_date ⇒ Object
187 188 189 |
# File 'app/models/version.rb', line 187 def due_date effective_date end |
#due_date=(arg) ⇒ Object
191 192 193 |
# File 'app/models/version.rb', line 191 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)
197 198 199 |
# File 'app/models/version.rb', line 197 def estimated_hours fixed_issues.estimated_hours end |
#issues_count ⇒ Object
Returns assigned issues count
247 248 249 |
# File 'app/models/version.rb', line 247 def issues_count fixed_issues.count end |
#open? ⇒ Boolean
210 211 212 |
# File 'app/models/version.rb', line 210 def open? status == 'open' end |
#open_issues_count ⇒ Object
Returns the total amount of open issues for this version.
252 253 254 |
# File 'app/models/version.rb', line 252 def open_issues_count fixed_issues.open_count end |
#overdue? ⇒ Boolean
Returns true if the version is overdue: due date reached and some open issues
242 243 244 |
# File 'app/models/version.rb', line 242 def overdue? effective_date && (effective_date < User.current.today) && (open_issues_count > 0) end |
#reload(*args) ⇒ Object
177 178 179 180 181 |
# File 'app/models/version.rb', line 177 def reload(*args) @default_project_version = nil @visible_fixed_issues = nil base_reload(*args) end |
#shared? ⇒ Boolean
Returns true if the version is shared, otherwise false
347 348 349 |
# File 'app/models/version.rb', line 347 def shared? sharing != 'none' end |
#spent_hours ⇒ Object
Returns the total reported time for this version
202 203 204 |
# File 'app/models/version.rb', line 202 def spent_hours @spent_hours ||= TimeEntry.joins(:issue).where("#{Issue.table_name}.fixed_version_id = ?", id).sum(:hours).to_f end |
#start_date ⇒ Object
183 184 185 |
# File 'app/models/version.rb', line 183 def start_date @start_date ||= fixed_issues.minimum('start_date') end |
#to_s ⇒ Object
272 |
# File 'app/models/version.rb', line 272 def to_s; name end |
#to_s_with_project ⇒ Object
274 275 276 |
# File 'app/models/version.rb', line 274 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
163 164 165 |
# File 'app/models/version.rb', line 163 def visible?(user=User.current) user.allowed_to?(:view_issues, self.project) end |
#visible_fixed_issues ⇒ Object
261 262 263 |
# File 'app/models/version.rb', line 261 def visible_fixed_issues @visible_fixed_issues ||= fixed_issues.visible end |
#wiki_page ⇒ Object
265 266 267 268 269 270 |
# File 'app/models/version.rb', line 265 def wiki_page if project.wiki && !wiki_page_title.blank? @wiki_page ||= project.wiki.find_page(wiki_page_title) end @wiki_page end |