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