Class: Version

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Redmine::SafeAttributes
Defined in:
app/models/version.rb

Overview

– copyright ChiliProject is a project management system.

Copyright (C) 2010-2013 the ChiliProject Team

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.

See doc/COPYRIGHT.rdoc for more details. ++

Constant Summary collapse

VERSION_STATUSES =
%w(open locked closed)
VERSION_SHARINGS =
%w(none descendants hierarchy tree system)

Instance Method Summary collapse

Methods included from Redmine::SafeAttributes

#delete_unsafe_attributes, included, #safe_attribute_names, #safe_attributes=

Instance Method Details

#<=>(version) ⇒ Object

Versions are sorted by effective_date and “Project Name - Version name” Those with no effective_date are at the end, sorted by “Project Name - Version name”


156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'app/models/version.rb', line 156

def <=>(version)
  if self.effective_date
    if version.effective_date
      if self.effective_date == version.effective_date
        "#{self.project.name} - #{self.name}" <=> "#{version.project.name} - #{version.name}"
      else
        self.effective_date <=> version.effective_date
      end
    else
      -1
    end
  else
    if version.effective_date
      1
    else
      "#{self.project.name} - #{self.name}" <=> "#{version.project.name} - #{version.name}"
    end
  end
end

#allowed_sharings(user = User.current) ⇒ Object

Returns the sharings that user can set the version to


177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'app/models/version.rb', line 177

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

#behind_schedule?Boolean

Returns:

  • (Boolean)

89
90
91
92
93
94
95
96
97
98
# File 'app/models/version.rb', line 89

def behind_schedule?
  if completed_pourcent == 100
    return false
  elsif due_date && start_date
    done_date = start_date + ((due_date - start_date+1)* completed_pourcent/100).floor
    return done_date <= Date.today
  else
    false # No issues so it's not late
  end
end

#closed?Boolean

Returns:

  • (Boolean)

76
77
78
# File 'app/models/version.rb', line 76

def closed?
  status == 'closed'
end

#closed_issues_countObject

Returns the total amount of closed issues for this version.


137
138
139
# File 'app/models/version.rb', line 137

def closed_issues_count
  @closed_issues_count ||= Issue.count(:all, :conditions => ["fixed_version_id = ? AND is_closed = ?", self.id, true], :include => :status)
end

#closed_pourcentObject

Returns the percentage of issues that have been marked as 'closed'.


113
114
115
116
117
118
119
# File 'app/models/version.rb', line 113

def closed_pourcent
  if issues_count == 0
    0
  else
    issues_progress(false)
  end
end

#completed?Boolean

Returns true if the version is completed: due date reached and no open issues

Returns:

  • (Boolean)

85
86
87
# File 'app/models/version.rb', line 85

def completed?
  effective_date && (effective_date <= Date.today) && (open_issues_count == 0)
end

#completed_pourcentObject

Returns the completion percentage of this version based on the amount of open/closed issues and the time spent on the open issues.


102
103
104
105
106
107
108
109
110
# File 'app/models/version.rb', line 102

def completed_pourcent
  if issues_count == 0
    0
  elsif open_issues_count == 0
    100
  else
    issues_progress(false) + issues_progress(true)
  end
end

#due_dateObject


61
62
63
# File 'app/models/version.rb', line 61

def due_date
  effective_date
end

#estimated_hoursObject

Returns the total estimated time for this version (sum of leaves estimated_hours)


67
68
69
# File 'app/models/version.rb', line 67

def estimated_hours
  @estimated_hours ||= fixed_issues.leaves.sum(:estimated_hours).to_f
end

#issues_countObject

Returns assigned issues count


127
128
129
# File 'app/models/version.rb', line 127

def issues_count
  @issue_count ||= fixed_issues.count
end

#open?Boolean

Returns:

  • (Boolean)

80
81
82
# File 'app/models/version.rb', line 80

def open?
  status == 'open'
end

#open_issues_countObject

Returns the total amount of open issues for this version.


132
133
134
# File 'app/models/version.rb', line 132

def open_issues_count
  @open_issues_count ||= Issue.count(:all, :conditions => ["fixed_version_id = ? AND is_closed = ?", self.id, false], :include => :status)
end

#overdue?Boolean

Returns true if the version is overdue: due date reached and some open issues

Returns:

  • (Boolean)

122
123
124
# File 'app/models/version.rb', line 122

def overdue?
  effective_date && (effective_date < Date.today) && (open_issues_count > 0)
end

#spent_hoursObject

Returns the total reported time for this version


72
73
74
# File 'app/models/version.rb', line 72

def spent_hours
  @spent_hours ||= TimeEntry.sum(:hours, :include => :issue, :conditions => ["#{Issue.table_name}.fixed_version_id = ?", id]).to_f
end

#start_dateObject

When a version started.

Can either be a set date stored in the database or a dynamic one based on the earlist start_date of the fixed_issues


57
58
59
# File 'app/models/version.rb', line 57

def start_date
  @start_date ||= (read_attribute(:start_date) || fixed_issues.minimum('start_date'))
end

#to_sObject


148
# File 'app/models/version.rb', line 148

def to_s; name end

#to_s_with_projectObject


150
151
152
# File 'app/models/version.rb', line 150

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

Returns:

  • (Boolean)

49
50
51
# File 'app/models/version.rb', line 49

def visible?(user=User.current)
  user.allowed_to?(:view_issues, self.project)
end

#wiki_pageObject


141
142
143
144
145
146
# File 'app/models/version.rb', line 141

def wiki_page
  if project.wiki && !wiki_page_title.blank?
    @wiki_page ||= project.wiki.find_page(wiki_page_title)
  end
  @wiki_page
end