1
|
# redMine - project management software
|
2
|
# Copyright (C) 2006 Jean-Philippe Lang
|
3
|
#
|
4
|
# This program is free software; you can redistribute it and/or
|
5
|
# modify it under the terms of the GNU General Public License
|
6
|
# as published by the Free Software Foundation; either version 2
|
7
|
# of the License, or (at your option) any later version.
|
8
|
#
|
9
|
# This program is distributed in the hope that it will be useful,
|
10
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
# GNU General Public License for more details.
|
13
|
#
|
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
|
16
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
17
|
|
18
|
class ReportsController < ApplicationController
|
19
|
menu_item :issues
|
20
|
before_filter :find_project, :authorize
|
21
|
|
22
|
def issue_report
|
23
|
@statuses = IssueStatus.find(:all, :order => 'position')
|
24
|
|
25
|
case params[:detail]
|
26
|
when "tracker"
|
27
|
@field = "tracker_id"
|
28
|
@rows = @project.trackers
|
29
|
@data = issues_by_tracker
|
30
|
@report_title = l(:field_tracker)
|
31
|
render :template => "reports/issue_report_details"
|
32
|
when "version"
|
33
|
@field = "fixed_version_id"
|
34
|
@rows = @project.shared_versions.sort
|
35
|
@data = issues_by_version
|
36
|
@report_title = l(:field_version)
|
37
|
render :template => "reports/issue_report_details"
|
38
|
when "priority"
|
39
|
@field = "priority_id"
|
40
|
@rows = IssuePriority.all
|
41
|
@data = issues_by_priority
|
42
|
@report_title = l(:field_priority)
|
43
|
render :template => "reports/issue_report_details"
|
44
|
when "category"
|
45
|
@field = "category_id"
|
46
|
@rows = @project.issue_categories
|
47
|
@data = issues_by_category
|
48
|
@report_title = l(:field_category)
|
49
|
render :template => "reports/issue_report_details"
|
50
|
when "assigned_to"
|
51
|
@field = "assigned_to_id"
|
52
|
@rows = @project.assignable_users
|
53
|
@data = issues_by_assigned_to
|
54
|
@report_title = l(:field_assigned_to)
|
55
|
render :template => "reports/issue_report_details"
|
56
|
when "author"
|
57
|
@field = "author_id"
|
58
|
@rows = @project.members.collect { |m| m.user }.sort
|
59
|
@data = issues_by_author
|
60
|
@report_title = l(:field_author)
|
61
|
render :template => "reports/issue_report_details"
|
62
|
when "subproject"
|
63
|
@field = "project_id"
|
64
|
@rows = @project.descendants.visible
|
65
|
@data = issues_by_subproject
|
66
|
@report_title = l(:field_subproject)
|
67
|
render :template => "reports/issue_report_details"
|
68
|
else
|
69
|
@trackers = @project.trackers
|
70
|
@versions = @project.shared_versions.sort
|
71
|
@priorities = IssuePriority.all
|
72
|
@categories = @project.issue_categories
|
73
|
@assignees = @project.members.select {|m| m.roles.detect {|role| role.assignable?}}.collect {|m| m.user}.sort
|
74
|
@authors = @project.members.collect { |m| m.user }.sort
|
75
|
@subprojects = @project.descendants.visible
|
76
|
issues_by_tracker
|
77
|
issues_by_version
|
78
|
issues_by_priority
|
79
|
issues_by_category
|
80
|
issues_by_assigned_to
|
81
|
issues_by_author
|
82
|
issues_by_subproject
|
83
|
|
84
|
render :template => "reports/issue_report"
|
85
|
end
|
86
|
end
|
87
|
|
88
|
private
|
89
|
# Find project of id params[:id]
|
90
|
def find_project
|
91
|
@project = Project.find(params[:id])
|
92
|
rescue ActiveRecord::RecordNotFound
|
93
|
render_404
|
94
|
end
|
95
|
|
96
|
def issues_by_tracker
|
97
|
@issues_by_tracker ||=
|
98
|
ActiveRecord::Base.connection.select_all("select s.id as status_id,
|
99
|
s.is_closed as closed,
|
100
|
t.id as tracker_id,
|
101
|
count(i.id) as total
|
102
|
from
|
103
|
#{Issue.table_name} i, #{IssueStatus.table_name} s, #{Tracker.table_name} t
|
104
|
where
|
105
|
i.status_id=s.id
|
106
|
and i.tracker_id=t.id
|
107
|
and i.project_id=#{@project.id}
|
108
|
group by s.id, s.is_closed, t.id")
|
109
|
end
|
110
|
|
111
|
def issues_by_version
|
112
|
@issues_by_version ||=
|
113
|
ActiveRecord::Base.connection.select_all("select s.id as status_id,
|
114
|
s.is_closed as closed,
|
115
|
v.id as fixed_version_id,
|
116
|
count(i.id) as total
|
117
|
from
|
118
|
#{Issue.table_name} i, #{IssueStatus.table_name} s, #{Version.table_name} v
|
119
|
where
|
120
|
i.status_id=s.id
|
121
|
and i.fixed_version_id=v.id
|
122
|
and i.project_id=#{@project.id}
|
123
|
group by s.id, s.is_closed, v.id")
|
124
|
end
|
125
|
|
126
|
def issues_by_priority
|
127
|
@issues_by_priority ||=
|
128
|
ActiveRecord::Base.connection.select_all("select s.id as status_id,
|
129
|
s.is_closed as closed,
|
130
|
p.id as priority_id,
|
131
|
count(i.id) as total
|
132
|
from
|
133
|
#{Issue.table_name} i, #{IssueStatus.table_name} s, #{IssuePriority.table_name} p
|
134
|
where
|
135
|
i.status_id=s.id
|
136
|
and i.priority_id=p.id
|
137
|
and i.project_id=#{@project.id}
|
138
|
group by s.id, s.is_closed, p.id")
|
139
|
end
|
140
|
|
141
|
def issues_by_category
|
142
|
@issues_by_category ||=
|
143
|
ActiveRecord::Base.connection.select_all("select s.id as status_id,
|
144
|
s.is_closed as closed,
|
145
|
c.id as category_id,
|
146
|
count(i.id) as total
|
147
|
from
|
148
|
#{Issue.table_name} i, #{IssueStatus.table_name} s, #{IssueCategory.table_name} c
|
149
|
where
|
150
|
i.status_id=s.id
|
151
|
and i.category_id=c.id
|
152
|
and i.project_id=#{@project.id}
|
153
|
group by s.id, s.is_closed, c.id")
|
154
|
end
|
155
|
|
156
|
def issues_by_assigned_to
|
157
|
@issues_by_assigned_to ||=
|
158
|
ActiveRecord::Base.connection.select_all("select s.id as status_id,
|
159
|
s.is_closed as closed,
|
160
|
a.id as assigned_to_id,
|
161
|
count(i.id) as total
|
162
|
from
|
163
|
#{Issue.table_name} i, #{IssueStatus.table_name} s, #{User.table_name} a
|
164
|
where
|
165
|
i.status_id=s.id
|
166
|
and i.assigned_to_id=a.id
|
167
|
and i.project_id=#{@project.id}
|
168
|
group by s.id, s.is_closed, a.id")
|
169
|
end
|
170
|
|
171
|
def issues_by_author
|
172
|
@issues_by_author ||=
|
173
|
ActiveRecord::Base.connection.select_all("select s.id as status_id,
|
174
|
s.is_closed as closed,
|
175
|
a.id as author_id,
|
176
|
count(i.id) as total
|
177
|
from
|
178
|
#{Issue.table_name} i, #{IssueStatus.table_name} s, #{User.table_name} a
|
179
|
where
|
180
|
i.status_id=s.id
|
181
|
and i.author_id=a.id
|
182
|
and i.project_id=#{@project.id}
|
183
|
group by s.id, s.is_closed, a.id")
|
184
|
end
|
185
|
|
186
|
def issues_by_subproject
|
187
|
@issues_by_subproject ||=
|
188
|
ActiveRecord::Base.connection.select_all("select s.id as status_id,
|
189
|
s.is_closed as closed,
|
190
|
i.project_id as project_id,
|
191
|
count(i.id) as total
|
192
|
from
|
193
|
#{Issue.table_name} i, #{IssueStatus.table_name} s
|
194
|
where
|
195
|
i.status_id=s.id
|
196
|
and i.project_id IN (#{@project.descendants.active.collect{|p| p.id}.join(',')})
|
197
|
group by s.id, s.is_closed, i.project_id") if @project.descendants.active.any?
|
198
|
@issues_by_subproject ||= []
|
199
|
end
|
200
|
end
|