##// END OF EJS Templates
Added issue count details for versions on Reports view....
Jean-Philippe Lang -
r540:ef39db234b40
parent child
Show More
@@ -1,191 +1,214
1 1 # redMine - project management software
2 2 # Copyright (C) 2006 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.
17 17
18 18 class ReportsController < ApplicationController
19 19 layout 'base'
20 20 before_filter :find_project, :authorize
21 21
22 22 def issue_report
23 23 @statuses = IssueStatus.find(:all, :order => 'position')
24 24
25 25 case params[:detail]
26 26 when "tracker"
27 27 @field = "tracker_id"
28 28 @rows = Tracker.find :all, :order => 'position'
29 29 @data = issues_by_tracker
30 30 @report_title = l(:field_tracker)
31 31 render :template => "reports/issue_report_details"
32 when "version"
33 @field = "fixed_version_id"
34 @rows = @project.versions.sort
35 @data = issues_by_version
36 @report_title = l(:field_version)
37 render :template => "reports/issue_report_details"
32 38 when "priority"
33 39 @field = "priority_id"
34 40 @rows = Enumeration::get_values('IPRI')
35 41 @data = issues_by_priority
36 42 @report_title = l(:field_priority)
37 43 render :template => "reports/issue_report_details"
38 44 when "category"
39 45 @field = "category_id"
40 46 @rows = @project.issue_categories
41 47 @data = issues_by_category
42 48 @report_title = l(:field_category)
43 49 render :template => "reports/issue_report_details"
44 50 when "author"
45 51 @field = "author_id"
46 52 @rows = @project.members.collect { |m| m.user }
47 53 @data = issues_by_author
48 54 @report_title = l(:field_author)
49 55 render :template => "reports/issue_report_details"
50 56 when "subproject"
51 57 @field = "project_id"
52 58 @rows = @project.children
53 59 @data = issues_by_subproject
54 60 @report_title = l(:field_subproject)
55 61 render :template => "reports/issue_report_details"
56 62 else
57 63 @queries = @project.queries.find :all, :conditions => ["is_public=? or user_id=?", true, (logged_in_user ? logged_in_user.id : 0)]
58 64 @trackers = Tracker.find(:all, :order => 'position')
65 @versions = @project.versions.sort
59 66 @priorities = Enumeration::get_values('IPRI')
60 67 @categories = @project.issue_categories
61 68 @authors = @project.members.collect { |m| m.user }
62 69 @subprojects = @project.children
63 70 issues_by_tracker
71 issues_by_version
64 72 issues_by_priority
65 73 issues_by_category
66 74 issues_by_author
67 75 issues_by_subproject
68 76 @total_hours = @project.time_entries.sum(:hours)
69 77 render :template => "reports/issue_report"
70 78 end
71 79 end
72 80
73 81 def delays
74 82 @trackers = Tracker.find(:all)
75 83 if request.get?
76 84 @selected_tracker_ids = @trackers.collect {|t| t.id.to_s }
77 85 else
78 86 @selected_tracker_ids = params[:tracker_ids].collect { |id| id.to_i.to_s } if params[:tracker_ids] and params[:tracker_ids].is_a? Array
79 87 end
80 88 @selected_tracker_ids ||= []
81 89 @raw =
82 90 ActiveRecord::Base.connection.select_all("SELECT datediff( a.created_on, b.created_on ) as delay, count(a.id) as total
83 91 FROM issue_histories a, issue_histories b, issues i
84 92 WHERE a.status_id =5
85 93 AND a.issue_id = b.issue_id
86 94 AND a.issue_id = i.id
87 95 AND i.tracker_id in (#{@selected_tracker_ids.join(',')})
88 96 AND b.id = (
89 97 SELECT min( c.id )
90 98 FROM issue_histories c
91 99 WHERE b.issue_id = c.issue_id )
92 100 GROUP BY delay") unless @selected_tracker_ids.empty?
93 101 @raw ||=[]
94 102
95 103 @x_from = 0
96 104 @x_to = 0
97 105 @y_from = 0
98 106 @y_to = 0
99 107 @sum_total = 0
100 108 @sum_delay = 0
101 109 @raw.each do |r|
102 110 @x_to = [r['delay'].to_i, @x_to].max
103 111 @y_to = [r['total'].to_i, @y_to].max
104 112 @sum_total = @sum_total + r['total'].to_i
105 113 @sum_delay = @sum_delay + r['total'].to_i * r['delay'].to_i
106 114 end
107 115 end
108 116
109 117 private
110 118 # Find project of id params[:id]
111 119 def find_project
112 120 @project = Project.find(params[:id])
113 121 rescue ActiveRecord::RecordNotFound
114 122 render_404
115 123 end
116 124
117 125 def issues_by_tracker
118 126 @issues_by_tracker ||=
119 127 ActiveRecord::Base.connection.select_all("select s.id as status_id,
120 128 s.is_closed as closed,
121 129 t.id as tracker_id,
122 130 count(i.id) as total
123 131 from
124 132 #{Issue.table_name} i, #{IssueStatus.table_name} s, #{Tracker.table_name} t
125 133 where
126 134 i.status_id=s.id
127 135 and i.tracker_id=t.id
128 136 and i.project_id=#{@project.id}
129 137 group by s.id, s.is_closed, t.id")
130 138 end
131
139
140 def issues_by_version
141 @issues_by_version ||=
142 ActiveRecord::Base.connection.select_all("select s.id as status_id,
143 s.is_closed as closed,
144 v.id as fixed_version_id,
145 count(i.id) as total
146 from
147 #{Issue.table_name} i, #{IssueStatus.table_name} s, #{Version.table_name} v
148 where
149 i.status_id=s.id
150 and i.fixed_version_id=v.id
151 and i.project_id=#{@project.id}
152 group by s.id, s.is_closed, v.id")
153 end
154
132 155 def issues_by_priority
133 156 @issues_by_priority ||=
134 157 ActiveRecord::Base.connection.select_all("select s.id as status_id,
135 158 s.is_closed as closed,
136 159 p.id as priority_id,
137 160 count(i.id) as total
138 161 from
139 162 #{Issue.table_name} i, #{IssueStatus.table_name} s, #{Enumeration.table_name} p
140 163 where
141 164 i.status_id=s.id
142 165 and i.priority_id=p.id
143 166 and i.project_id=#{@project.id}
144 167 group by s.id, s.is_closed, p.id")
145 168 end
146 169
147 170 def issues_by_category
148 171 @issues_by_category ||=
149 172 ActiveRecord::Base.connection.select_all("select s.id as status_id,
150 173 s.is_closed as closed,
151 174 c.id as category_id,
152 175 count(i.id) as total
153 176 from
154 177 #{Issue.table_name} i, #{IssueStatus.table_name} s, #{IssueCategory.table_name} c
155 178 where
156 179 i.status_id=s.id
157 180 and i.category_id=c.id
158 181 and i.project_id=#{@project.id}
159 182 group by s.id, s.is_closed, c.id")
160 183 end
161 184
162 185 def issues_by_author
163 186 @issues_by_author ||=
164 187 ActiveRecord::Base.connection.select_all("select s.id as status_id,
165 188 s.is_closed as closed,
166 189 a.id as author_id,
167 190 count(i.id) as total
168 191 from
169 192 #{Issue.table_name} i, #{IssueStatus.table_name} s, #{User.table_name} a
170 193 where
171 194 i.status_id=s.id
172 195 and i.author_id=a.id
173 196 and i.project_id=#{@project.id}
174 197 group by s.id, s.is_closed, a.id")
175 198 end
176 199
177 200 def issues_by_subproject
178 201 @issues_by_subproject ||=
179 202 ActiveRecord::Base.connection.select_all("select s.id as status_id,
180 203 s.is_closed as closed,
181 204 i.project_id as project_id,
182 205 count(i.id) as total
183 206 from
184 207 #{Issue.table_name} i, #{IssueStatus.table_name} s
185 208 where
186 209 i.status_id=s.id
187 210 and i.project_id IN (#{@project.children.collect{|p| p.id}.join(',')})
188 211 group by s.id, s.is_closed, i.project_id") if @project.children.any?
189 212 @issues_by_subproject ||= []
190 213 end
191 214 end
@@ -1,48 +1,51
1 1 <h2><%=l(:label_report_plural)%></h2>
2 2
3 3 <div class="splitcontentleft">
4 4 <div class="contextual">
5 5 <%= link_to_if_authorized l(:label_query_new), {:controller => 'projects', :action => 'add_query', :id => @project}, :class => 'icon icon-add' %>
6 6 </div>
7 7 <h3><%= l(:label_query_plural) %></h3>
8 8
9 9 <% if @queries.empty? %><p><i><%=l(:label_no_data)%></i></p><% end %>
10 10 <ul>
11 11 <% @queries.each do |query| %>
12 12 <li><%= link_to query.name, :controller => 'projects', :action => 'list_issues', :id => @project, :query_id => query %></li>
13 13 <% end %>
14 14 </ul>
15 15 </div>
16 16 <div class="splitcontentright">
17 17 <% if @total_hours %>
18 18 <h3 class="textright"><%= l(:label_spent_time) %>:
19 19 <%= link_to(lwr(:label_f_hour, @total_hours), {:controller => 'timelog', :action => 'details', :project_id => @project}, :class => 'icon icon-time') %>
20 20 </h3>
21 21 <% end %>
22 22 </div>
23 23
24 24 <div class="clear"></div>
25 25
26 26 <div class="splitcontentleft">
27 27 <h3><%=l(:field_tracker)%>&nbsp;&nbsp;<%= link_to image_tag('zoom_in.png'), :detail => 'tracker' %></h3>
28 28 <%= render :partial => 'simple', :locals => { :data => @issues_by_tracker, :field_name => "tracker_id", :rows => @trackers } %>
29 29 <br />
30 <h3><%=l(:field_version)%>&nbsp;&nbsp;<%= link_to image_tag('zoom_in.png'), :detail => 'version' %></h3>
31 <%= render :partial => 'simple', :locals => { :data => @issues_by_version, :field_name => "fixed_version_id", :rows => @versions } %>
32 <br />
30 33 <h3><%=l(:field_author)%>&nbsp;&nbsp;<%= link_to image_tag('zoom_in.png'), :detail => 'author' %></h3>
31 34 <%= render :partial => 'simple', :locals => { :data => @issues_by_author, :field_name => "author_id", :rows => @authors } %>
32 35 <br />
33 36 </div>
34 37
35 38 <div class="splitcontentright">
36 39 <h3><%=l(:field_priority)%>&nbsp;&nbsp;<%= link_to image_tag('zoom_in.png'), :detail => 'priority' %></h3>
37 40 <%= render :partial => 'simple', :locals => { :data => @issues_by_priority, :field_name => "priority_id", :rows => @priorities } %>
38 41 <br />
39 42 <% if @project.children.any? %>
40 43 <h3><%=l(:field_subproject)%>&nbsp;&nbsp;<%= link_to image_tag('zoom_in.png'), :detail => 'subproject' %></h3>
41 44 <%= render :partial => 'simple', :locals => { :data => @issues_by_subproject, :field_name => "project_id", :rows => @subprojects } %>
42 45 <br />
43 46 <% end %>
44 47 <h3><%=l(:field_category)%>&nbsp;&nbsp;<%= link_to image_tag('zoom_in.png'), :detail => 'category' %></h3>
45 48 <%= render :partial => 'simple', :locals => { :data => @issues_by_category, :field_name => "category_id", :rows => @categories } %>
46 49 <br />
47 50 </div>
48 51
General Comments 0
You need to be logged in to leave comments. Login now