forked from software-project/scrum-pm
/
sprints_helper.rb
executable file
·130 lines (115 loc) · 4.14 KB
/
sprints_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
module SprintsHelper
def classify( count )
return count == 0 ? 'even' : 'odd'
end
def sprint_end( sprint )
if sprint.start_date and sprint.duration
sprint.start_date.advance(:days => sprint.duration)
end
end
def done_user_stories( sprint )
done_counter = 0
for user_story in sprint.user_stories
done_counter += done_tasks_in_stories(user_story)
end
return done_counter
end
def done_tasks_in_stories( user_story )
done = 0
done = user_story.issues.find_all{|t| t.done_ratio == 100}.nitems
if done == 0
return 0
end
done == user_story.issues.nitems ? user_story.time_estimate.value : 0
end
def all_user_stories( sprint )
all_counter = 0
for user_story in sprint.user_stories
all_counter += user_story.time_estimate.value;
end
return all_counter == 0? 1: all_counter
end
def procent_of_sprint_done( sprint )
if sprint.user_stories.size > 0
((done_user_stories( sprint ).to_f / all_user_stories( sprint ).to_f)*100).to_i.to_s + "%"
else
0
end
end
def load_sprint_stats(sprint, data)
if data.size == 0
data = {:all_points => 0, :pending => 0, :in_progress => 0, :done => 0, :percent_done => 0 }
end
if sprint.user_stories.size > 0
sprint.user_stories.each{|u|
data[:all_points] += u.time_estimate.value
pending = 0
inprogress = 0
done = 0
u.issues.each { |i|
case i.done_ratio
when 0
pending += 1
when 100
done += 1
else
inprogress += 1
end
}
if done == u.issues.size && u.issues.size > 0
data[:done] += u.time_estimate.value
else
if done > 0 || inprogress > 0
data[:in_progress] += u.time_estimate.value
else
data[:pending] += u.time_estimate.value
end
end
}
data[:percent_done] = ((data[:done]/data[:all_points])*100).to_i.to_s + "%" if data[:all_points] > 0
end
data
end
def load_project_stats(project)
data = {:all_points => 0, :pending => 0, :in_progress => 0, :done => 0, :percent_done => 0, :un_assign => 0 }
UserStory.find(:all, :conditions => ["version_id is null AND project_id = ?",project.id]).each { |i|
data[:un_assign] += i.time_estimate.value
}
for sprint in Version.find(:all, :conditions => ["project_id = ?",project.id])
data = load_sprint_stats(sprint, data)
end
data[:all_points] += data[:un_assign]
data[:percent_done] = (data[:done]/(data[:all_points])) * 100 if data[:all_points] != 0
data
end
def link_to_object(object,action)
link_to_object(object,action,action)
end
def link_to_object(object,action,image)
options = {:controller => object.class.name.pluralize.underscore, :action => action, :project_id => @project}
if action == "destroy"
other = {:confirm => 'Are you sure?', :method => :post}
end
if action == "destroy" || action == "show" || action == "edit"
options = options.merge({:id => object.id})
end
link_to image_tag("/plugin_assets/redmine_sprints/images/#{image}.png",:title => l(action)), options, other
end
def link_to_new_object(object,parent,image)
options = {:controller => object.pluralize.underscore, :action => "new", :project_id => @project}
unless parent.nil?
options = options.merge({(parent.class.name.downcase + "_id").to_sym => parent.id})
end
link_to(image_tag("/plugin_assets/redmine_sprints/images/#{image}.png",:title => l("new")), options)
end
def labelled_tabular_form_for(name, object, options, &proc)
options[:html] ||= {}
options[:html][:class] = 'tabular' unless options[:html].has_key?(:class)
form_for(name, object, options.merge({ :builder => TabularFormBuilder, :lang => current_language}), &proc)
end
def labelled_tabular_remote_form_for(name, object, options, &proc)
options[:html] ||= {}
options[:html][:class] = 'tabular' unless options[:html].has_key?(:class)
remote_form_for(name, object, options.merge({ :builder => TabularFormBuilder, :lang => current_language}), &proc)
end
end