##// END OF EJS Templates
remove trailing white-spaces from app/models/version.rb....
Toshi MARUYAMA -
r6761:e9e47673fa63
parent child
Show More
@@ -1,16 +1,16
1 1 # Redmine - project management software
2 # Copyright (C) 2006-2010 Jean-Philippe Lang
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 #
8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 #
13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
@@ -25,7 +25,7 class Version < ActiveRecord::Base
25 25
26 26 VERSION_STATUSES = %w(open locked closed)
27 27 VERSION_SHARINGS = %w(none descendants hierarchy tree system)
28
28
29 29 validates_presence_of :name
30 30 validates_uniqueness_of :name, :scope => [:project_id]
31 31 validates_length_of :name, :maximum => 60
@@ -42,26 +42,26 class Version < ActiveRecord::Base
42 42 def visible?(user=User.current)
43 43 user.allowed_to?(:view_issues, self.project)
44 44 end
45
45
46 46 def start_date
47 47 @start_date ||= fixed_issues.minimum('start_date')
48 48 end
49
49
50 50 def due_date
51 51 effective_date
52 52 end
53
53
54 54 # Returns the total estimated time for this version
55 55 # (sum of leaves estimated_hours)
56 56 def estimated_hours
57 57 @estimated_hours ||= fixed_issues.leaves.sum(:estimated_hours).to_f
58 58 end
59
59
60 60 # Returns the total reported time for this version
61 61 def spent_hours
62 62 @spent_hours ||= TimeEntry.sum(:hours, :include => :issue, :conditions => ["#{Issue.table_name}.fixed_version_id = ?", id]).to_f
63 63 end
64
64
65 65 def closed?
66 66 status == 'closed'
67 67 end
@@ -69,7 +69,7 class Version < ActiveRecord::Base
69 69 def open?
70 70 status == 'open'
71 71 end
72
72
73 73 # Returns true if the version is completed: due date reached and no open issues
74 74 def completed?
75 75 effective_date && (effective_date <= Date.today) && (open_issues_count == 0)
@@ -85,7 +85,7 class Version < ActiveRecord::Base
85 85 false # No issues so it's not late
86 86 end
87 87 end
88
88
89 89 # Returns the completion percentage of this version based on the amount of open/closed issues
90 90 # and the time spent on the open issues.
91 91 def completed_pourcent
@@ -97,7 +97,7 class Version < ActiveRecord::Base
97 97 issues_progress(false) + issues_progress(true)
98 98 end
99 99 end
100
100
101 101 # Returns the percentage of issues that have been marked as 'closed'.
102 102 def closed_pourcent
103 103 if issues_count == 0
@@ -106,17 +106,17 class Version < ActiveRecord::Base
106 106 issues_progress(false)
107 107 end
108 108 end
109
109
110 110 # Returns true if the version is overdue: due date reached and some open issues
111 111 def overdue?
112 112 effective_date && (effective_date < Date.today) && (open_issues_count > 0)
113 113 end
114
114
115 115 # Returns assigned issues count
116 116 def issues_count
117 117 @issue_count ||= fixed_issues.count
118 118 end
119
119
120 120 # Returns the total amount of open issues for this version.
121 121 def open_issues_count
122 122 @open_issues_count ||= Issue.count(:all, :conditions => ["fixed_version_id = ? AND is_closed = ?", self.id, false], :include => :status)
@@ -126,20 +126,20 class Version < ActiveRecord::Base
126 126 def closed_issues_count
127 127 @closed_issues_count ||= Issue.count(:all, :conditions => ["fixed_version_id = ? AND is_closed = ?", self.id, true], :include => :status)
128 128 end
129
129
130 130 def wiki_page
131 131 if project.wiki && !wiki_page_title.blank?
132 132 @wiki_page ||= project.wiki.find_page(wiki_page_title)
133 133 end
134 134 @wiki_page
135 135 end
136
136
137 137 def to_s; name end
138 138
139 139 def to_s_with_project
140 140 "#{project} - #{name}"
141 141 end
142
142
143 143 # Versions are sorted by effective_date and "Project Name - Version name"
144 144 # Those with no effective_date are at the end, sorted by "Project Name - Version name"
145 145 def <=>(version)
@@ -161,7 +161,7 class Version < ActiveRecord::Base
161 161 end
162 162 end
163 163 end
164
164
165 165 # Returns the sharings that +user+ can set the version to
166 166 def allowed_sharings(user = User.current)
167 167 VERSION_SHARINGS.select do |s|
@@ -182,7 +182,7 class Version < ActiveRecord::Base
182 182 end
183 183 end
184 184 end
185
185
186 186 private
187 187
188 188 # Update the issue's fixed versions. Used if a version's sharing changes.
@@ -195,7 +195,7 class Version < ActiveRecord::Base
195 195 end
196 196 end
197 197 end
198
198
199 199 # Returns the average estimated time of assigned issues
200 200 # or 1 if no issue has an estimated time
201 201 # Used to weigth unestimated issues in progress calculation
@@ -209,7 +209,7 class Version < ActiveRecord::Base
209 209 end
210 210 @estimated_average
211 211 end
212
212
213 213 # Returns the total progress of open or closed issues. The returned percentage takes into account
214 214 # the amount of estimated time set for this version.
215 215 #
@@ -222,7 +222,7 class Version < ActiveRecord::Base
222 222 progress = 0
223 223 if issues_count > 0
224 224 ratio = open ? 'done_ratio' : 100
225
225
226 226 done = fixed_issues.sum("COALESCE(estimated_hours, #{estimated_average}) * #{ratio}",
227 227 :include => :status,
228 228 :conditions => ["is_closed = ?", !open]).to_f
General Comments 0
You need to be logged in to leave comments. Login now