|
@@
-1,668
+1,676
|
|
1
|
1
|
# redMine - project management software
|
|
2
|
2
|
# Copyright (C) 2006-2007 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
|
require 'csv'
|
|
19
|
19
|
|
|
20
|
20
|
class ProjectsController < ApplicationController
|
|
21
|
21
|
layout 'base'
|
|
22
|
22
|
before_filter :find_project, :except => [ :index, :list, :add ]
|
|
23
|
23
|
before_filter :authorize, :except => [ :index, :list, :add, :archive, :unarchive, :destroy ]
|
|
24
|
24
|
before_filter :require_admin, :only => [ :add, :archive, :unarchive, :destroy ]
|
|
25
|
25
|
accept_key_auth :activity, :calendar
|
|
26
|
26
|
|
|
27
|
27
|
cache_sweeper :project_sweeper, :only => [ :add, :edit, :archive, :unarchive, :destroy ]
|
|
28
|
28
|
cache_sweeper :issue_sweeper, :only => [ :add_issue ]
|
|
29
|
29
|
cache_sweeper :version_sweeper, :only => [ :add_version ]
|
|
30
|
30
|
|
|
31
|
31
|
helper :sort
|
|
32
|
32
|
include SortHelper
|
|
33
|
33
|
helper :custom_fields
|
|
34
|
34
|
include CustomFieldsHelper
|
|
35
|
35
|
helper :ifpdf
|
|
36
|
36
|
include IfpdfHelper
|
|
37
|
37
|
helper :issues
|
|
38
|
38
|
helper IssuesHelper
|
|
39
|
39
|
helper :queries
|
|
40
|
40
|
include QueriesHelper
|
|
41
|
41
|
helper :repositories
|
|
42
|
42
|
include RepositoriesHelper
|
|
43
|
43
|
include ProjectsHelper
|
|
44
|
44
|
|
|
45
|
45
|
def index
|
|
46
|
46
|
list
|
|
47
|
47
|
render :action => 'list' unless request.xhr?
|
|
48
|
48
|
end
|
|
49
|
49
|
|
|
50
|
50
|
# Lists visible projects
|
|
51
|
51
|
def list
|
|
52
|
52
|
projects = Project.find :all,
|
|
53
|
53
|
:conditions => Project.visible_by(logged_in_user),
|
|
54
|
54
|
:include => :parent
|
|
55
|
55
|
@project_tree = projects.group_by {|p| p.parent || p}
|
|
56
|
56
|
@project_tree.each_key {|p| @project_tree[p] -= [p]}
|
|
57
|
57
|
end
|
|
58
|
58
|
|
|
59
|
59
|
# Add a new project
|
|
60
|
60
|
def add
|
|
61
|
61
|
@custom_fields = IssueCustomField.find(:all)
|
|
62
|
62
|
@root_projects = Project.find(:all, :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}")
|
|
63
|
63
|
@project = Project.new(params[:project])
|
|
64
|
64
|
@project.enabled_module_names = Redmine::AccessControl.available_project_modules
|
|
65
|
65
|
if request.get?
|
|
66
|
66
|
@custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project) }
|
|
67
|
67
|
else
|
|
68
|
68
|
@project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
|
|
69
|
69
|
@custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => (params[:custom_fields] ? params["custom_fields"][x.id.to_s] : nil)) }
|
|
70
|
70
|
@project.custom_values = @custom_values
|
|
71
|
71
|
if @project.save
|
|
72
|
72
|
@project.enabled_module_names = params[:enabled_modules]
|
|
73
|
73
|
flash[:notice] = l(:notice_successful_create)
|
|
74
|
74
|
redirect_to :controller => 'admin', :action => 'projects'
|
|
75
|
75
|
end
|
|
76
|
76
|
end
|
|
77
|
77
|
end
|
|
78
|
78
|
|
|
79
|
79
|
# Show @project
|
|
80
|
80
|
def show
|
|
81
|
81
|
@custom_values = @project.custom_values.find(:all, :include => :custom_field)
|
|
82
|
82
|
@members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role}
|
|
83
|
83
|
@subprojects = @project.active_children
|
|
84
|
84
|
@news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
|
|
85
|
85
|
@trackers = Tracker.find(:all, :order => 'position')
|
|
86
|
86
|
@open_issues_by_tracker = Issue.count(:group => :tracker, :joins => "INNER JOIN #{IssueStatus.table_name} ON #{IssueStatus.table_name}.id = #{Issue.table_name}.status_id", :conditions => ["project_id=? and #{IssueStatus.table_name}.is_closed=?", @project.id, false])
|
|
87
|
87
|
@total_issues_by_tracker = Issue.count(:group => :tracker, :conditions => ["project_id=?", @project.id])
|
|
88
|
88
|
@total_hours = @project.time_entries.sum(:hours)
|
|
89
|
89
|
@key = User.current.rss_key
|
|
90
|
90
|
end
|
|
91
|
91
|
|
|
92
|
92
|
def settings
|
|
93
|
93
|
@root_projects = Project::find(:all, :conditions => ["parent_id IS NULL AND status = #{Project::STATUS_ACTIVE} AND id <> ?", @project.id])
|
|
94
|
94
|
@custom_fields = IssueCustomField.find(:all)
|
|
95
|
95
|
@issue_category ||= IssueCategory.new
|
|
96
|
96
|
@member ||= @project.members.new
|
|
97
|
97
|
@custom_values ||= ProjectCustomField.find(:all).collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
|
|
98
|
98
|
@repository ||= @project.repository
|
|
99
|
99
|
@wiki ||= @project.wiki
|
|
100
|
100
|
end
|
|
101
|
101
|
|
|
102
|
102
|
# Edit @project
|
|
103
|
103
|
def edit
|
|
104
|
104
|
if request.post?
|
|
105
|
105
|
@project.custom_fields = IssueCustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
|
|
106
|
106
|
if params[:custom_fields]
|
|
107
|
107
|
@custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
|
|
108
|
108
|
@project.custom_values = @custom_values
|
|
109
|
109
|
end
|
|
110
|
110
|
@project.attributes = params[:project]
|
|
111
|
111
|
if @project.save
|
|
112
|
112
|
flash[:notice] = l(:notice_successful_update)
|
|
113
|
113
|
redirect_to :action => 'settings', :id => @project
|
|
114
|
114
|
else
|
|
115
|
115
|
settings
|
|
116
|
116
|
render :action => 'settings'
|
|
117
|
117
|
end
|
|
118
|
118
|
end
|
|
119
|
119
|
end
|
|
120
|
120
|
|
|
121
|
121
|
def modules
|
|
122
|
122
|
@project.enabled_module_names = params[:enabled_modules]
|
|
123
|
123
|
redirect_to :action => 'settings', :id => @project, :tab => 'modules'
|
|
124
|
124
|
end
|
|
125
|
125
|
|
|
126
|
126
|
def archive
|
|
127
|
127
|
@project.archive if request.post? && @project.active?
|
|
128
|
128
|
redirect_to :controller => 'admin', :action => 'projects'
|
|
129
|
129
|
end
|
|
130
|
130
|
|
|
131
|
131
|
def unarchive
|
|
132
|
132
|
@project.unarchive if request.post? && !@project.active?
|
|
133
|
133
|
redirect_to :controller => 'admin', :action => 'projects'
|
|
134
|
134
|
end
|
|
135
|
135
|
|
|
136
|
136
|
# Delete @project
|
|
137
|
137
|
def destroy
|
|
138
|
138
|
@project_to_destroy = @project
|
|
139
|
139
|
if request.post? and params[:confirm]
|
|
140
|
140
|
@project_to_destroy.destroy
|
|
141
|
141
|
redirect_to :controller => 'admin', :action => 'projects'
|
|
142
|
142
|
end
|
|
143
|
143
|
# hide project in layout
|
|
144
|
144
|
@project = nil
|
|
145
|
145
|
end
|
|
146
|
146
|
|
|
147
|
147
|
# Add a new issue category to @project
|
|
148
|
148
|
def add_issue_category
|
|
149
|
149
|
@category = @project.issue_categories.build(params[:category])
|
|
150
|
150
|
if request.post? and @category.save
|
|
151
|
151
|
respond_to do |format|
|
|
152
|
152
|
format.html do
|
|
153
|
153
|
flash[:notice] = l(:notice_successful_create)
|
|
154
|
154
|
redirect_to :action => 'settings', :tab => 'categories', :id => @project
|
|
155
|
155
|
end
|
|
156
|
156
|
format.js do
|
|
157
|
157
|
# IE doesn't support the replace_html rjs method for select box options
|
|
158
|
158
|
render(:update) {|page| page.replace "issue_category_id",
|
|
159
|
159
|
content_tag('select', '<option></option>' + options_from_collection_for_select(@project.issue_categories, 'id', 'name', @category.id), :id => 'issue_category_id', :name => 'issue[category_id]')
|
|
160
|
160
|
}
|
|
161
|
161
|
end
|
|
162
|
162
|
end
|
|
163
|
163
|
end
|
|
164
|
164
|
end
|
|
165
|
165
|
|
|
166
|
166
|
# Add a new version to @project
|
|
167
|
167
|
def add_version
|
|
168
|
168
|
@version = @project.versions.build(params[:version])
|
|
169
|
169
|
if request.post? and @version.save
|
|
170
|
170
|
flash[:notice] = l(:notice_successful_create)
|
|
171
|
171
|
redirect_to :action => 'settings', :tab => 'versions', :id => @project
|
|
172
|
172
|
end
|
|
173
|
173
|
end
|
|
174
|
174
|
|
|
175
|
175
|
# Add a new document to @project
|
|
176
|
176
|
def add_document
|
|
177
|
177
|
@categories = Enumeration::get_values('DCAT')
|
|
178
|
178
|
@document = @project.documents.build(params[:document])
|
|
179
|
179
|
if request.post? and @document.save
|
|
180
|
180
|
# Save the attachments
|
|
181
|
181
|
params[:attachments].each { |a|
|
|
182
|
182
|
Attachment.create(:container => @document, :file => a, :author => logged_in_user) unless a.size == 0
|
|
183
|
183
|
} if params[:attachments] and params[:attachments].is_a? Array
|
|
184
|
184
|
flash[:notice] = l(:notice_successful_create)
|
|
185
|
185
|
Mailer.deliver_document_add(@document) if Setting.notified_events.include?('document_added')
|
|
186
|
186
|
redirect_to :action => 'list_documents', :id => @project
|
|
187
|
187
|
end
|
|
188
|
188
|
end
|
|
189
|
189
|
|
|
190
|
190
|
# Show documents list of @project
|
|
191
|
191
|
def list_documents
|
|
192
|
192
|
@documents = @project.documents.find :all, :include => :category
|
|
193
|
193
|
end
|
|
194
|
194
|
|
|
195
|
195
|
# Add a new issue to @project
|
|
196
|
196
|
def add_issue
|
|
197
|
197
|
@tracker = Tracker.find(params[:tracker_id])
|
|
198
|
198
|
@priorities = Enumeration::get_values('IPRI')
|
|
199
|
199
|
|
|
200
|
200
|
default_status = IssueStatus.default
|
|
201
|
201
|
unless default_status
|
|
202
|
202
|
flash.now[:error] = 'No default issue status defined. Please check your configuration.'
|
|
203
|
203
|
render :nothing => true, :layout => true
|
|
204
|
204
|
return
|
|
205
|
205
|
end
|
|
206
|
206
|
@issue = Issue.new(:project => @project, :tracker => @tracker)
|
|
207
|
207
|
@issue.status = default_status
|
|
208
|
208
|
@allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(logged_in_user.role_for_project(@project), @issue.tracker))if logged_in_user
|
|
209
|
209
|
if request.get?
|
|
210
|
210
|
@issue.start_date = Date.today
|
|
211
|
211
|
@custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) }
|
|
212
|
212
|
else
|
|
213
|
213
|
@issue.attributes = params[:issue]
|
|
214
|
214
|
|
|
215
|
215
|
requested_status = IssueStatus.find_by_id(params[:issue][:status_id])
|
|
216
|
216
|
@issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status
|
|
217
|
217
|
|
|
218
|
218
|
@issue.author_id = self.logged_in_user.id if self.logged_in_user
|
|
219
|
219
|
# Multiple file upload
|
|
220
|
220
|
@attachments = []
|
|
221
|
221
|
params[:attachments].each { |a|
|
|
222
|
222
|
@attachments << Attachment.new(:container => @issue, :file => a, :author => logged_in_user) unless a.size == 0
|
|
223
|
223
|
} if params[:attachments] and params[:attachments].is_a? Array
|
|
224
|
224
|
@custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue, :value => params["custom_fields"][x.id.to_s]) }
|
|
225
|
225
|
@issue.custom_values = @custom_values
|
|
226
|
226
|
if @issue.save
|
|
227
|
227
|
@attachments.each(&:save)
|
|
228
|
228
|
flash[:notice] = l(:notice_successful_create)
|
|
229
|
229
|
Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added')
|
|
230
|
230
|
redirect_to :action => 'list_issues', :id => @project
|
|
231
|
231
|
end
|
|
232
|
232
|
end
|
|
233
|
233
|
end
|
|
234
|
234
|
|
|
235
|
235
|
# Show filtered/sorted issues list of @project
|
|
236
|
236
|
def list_issues
|
|
237
|
237
|
sort_init "#{Issue.table_name}.id", "desc"
|
|
238
|
238
|
sort_update
|
|
239
|
239
|
|
|
240
|
240
|
retrieve_query
|
|
241
|
241
|
|
|
242
|
242
|
@results_per_page_options = [ 15, 25, 50, 100 ]
|
|
243
|
243
|
if params[:per_page] and @results_per_page_options.include? params[:per_page].to_i
|
|
244
|
244
|
@results_per_page = params[:per_page].to_i
|
|
245
|
245
|
session[:results_per_page] = @results_per_page
|
|
246
|
246
|
else
|
|
247
|
247
|
@results_per_page = session[:results_per_page] || 25
|
|
248
|
248
|
end
|
|
249
|
249
|
|
|
250
|
250
|
if @query.valid?
|
|
251
|
251
|
@issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement)
|
|
252
|
252
|
@issue_pages = Paginator.new self, @issue_count, @results_per_page, params['page']
|
|
253
|
253
|
@issues = Issue.find :all, :order => sort_clause,
|
|
254
|
254
|
:include => [ :assigned_to, :status, :tracker, :project, :priority, :category ],
|
|
255
|
255
|
:conditions => @query.statement,
|
|
256
|
256
|
:limit => @issue_pages.items_per_page,
|
|
257
|
257
|
:offset => @issue_pages.current.offset
|
|
258
|
258
|
end
|
|
259
|
259
|
|
|
260
|
260
|
render :layout => false if request.xhr?
|
|
261
|
261
|
end
|
|
262
|
262
|
|
|
263
|
263
|
# Export filtered/sorted issues list to CSV
|
|
264
|
264
|
def export_issues_csv
|
|
265
|
265
|
sort_init "#{Issue.table_name}.id", "desc"
|
|
266
|
266
|
sort_update
|
|
267
|
267
|
|
|
268
|
268
|
retrieve_query
|
|
269
|
269
|
render :action => 'list_issues' and return unless @query.valid?
|
|
270
|
270
|
|
|
271
|
271
|
@issues = Issue.find :all, :order => sort_clause,
|
|
272
|
272
|
:include => [ :assigned_to, :author, :status, :tracker, :priority, :project, {:custom_values => :custom_field} ],
|
|
273
|
273
|
:conditions => @query.statement,
|
|
274
|
274
|
:limit => Setting.issues_export_limit.to_i
|
|
275
|
275
|
|
|
276
|
276
|
ic = Iconv.new(l(:general_csv_encoding), 'UTF-8')
|
|
277
|
277
|
export = StringIO.new
|
|
278
|
278
|
CSV::Writer.generate(export, l(:general_csv_separator)) do |csv|
|
|
279
|
279
|
# csv header fields
|
|
280
|
280
|
headers = [ "#", l(:field_status),
|
|
281
|
281
|
l(:field_project),
|
|
282
|
282
|
l(:field_tracker),
|
|
283
|
283
|
l(:field_priority),
|
|
284
|
284
|
l(:field_subject),
|
|
285
|
285
|
l(:field_assigned_to),
|
|
286
|
286
|
l(:field_author),
|
|
287
|
287
|
l(:field_start_date),
|
|
288
|
288
|
l(:field_due_date),
|
|
289
|
289
|
l(:field_done_ratio),
|
|
290
|
290
|
l(:field_created_on),
|
|
291
|
291
|
l(:field_updated_on)
|
|
292
|
292
|
]
|
|
293
|
293
|
for custom_field in @project.all_custom_fields
|
|
294
|
294
|
headers << custom_field.name
|
|
295
|
295
|
end
|
|
296
|
296
|
csv << headers.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
|
|
297
|
297
|
# csv lines
|
|
298
|
298
|
@issues.each do |issue|
|
|
299
|
299
|
fields = [issue.id, issue.status.name,
|
|
300
|
300
|
issue.project.name,
|
|
301
|
301
|
issue.tracker.name,
|
|
302
|
302
|
issue.priority.name,
|
|
303
|
303
|
issue.subject,
|
|
304
|
304
|
(issue.assigned_to ? issue.assigned_to.name : ""),
|
|
305
|
305
|
issue.author.name,
|
|
306
|
306
|
issue.start_date ? l_date(issue.start_date) : nil,
|
|
307
|
307
|
issue.due_date ? l_date(issue.due_date) : nil,
|
|
308
|
308
|
issue.done_ratio,
|
|
309
|
309
|
l_datetime(issue.created_on),
|
|
310
|
310
|
l_datetime(issue.updated_on)
|
|
311
|
311
|
]
|
|
312
|
312
|
for custom_field in @project.all_custom_fields
|
|
313
|
313
|
fields << (show_value issue.custom_value_for(custom_field))
|
|
314
|
314
|
end
|
|
315
|
315
|
csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
|
|
316
|
316
|
end
|
|
317
|
317
|
end
|
|
318
|
318
|
export.rewind
|
|
319
|
319
|
send_data(export.read, :type => 'text/csv; header=present', :filename => 'export.csv')
|
|
320
|
320
|
end
|
|
321
|
321
|
|
|
322
|
322
|
# Export filtered/sorted issues to PDF
|
|
323
|
323
|
def export_issues_pdf
|
|
324
|
324
|
sort_init "#{Issue.table_name}.id", "desc"
|
|
325
|
325
|
sort_update
|
|
326
|
326
|
|
|
327
|
327
|
retrieve_query
|
|
328
|
328
|
render :action => 'list_issues' and return unless @query.valid?
|
|
329
|
329
|
|
|
330
|
330
|
@issues = Issue.find :all, :order => sort_clause,
|
|
331
|
331
|
:include => [ :author, :status, :tracker, :priority, :project ],
|
|
332
|
332
|
:conditions => @query.statement,
|
|
333
|
333
|
:limit => Setting.issues_export_limit.to_i
|
|
334
|
334
|
|
|
335
|
335
|
@options_for_rfpdf ||= {}
|
|
336
|
336
|
@options_for_rfpdf[:file_name] = "export.pdf"
|
|
337
|
337
|
render :layout => false
|
|
338
|
338
|
end
|
|
339
|
339
|
|
|
340
|
340
|
# Bulk edit issues
|
|
341
|
341
|
def bulk_edit_issues
|
|
342
|
342
|
if request.post?
|
|
|
343
|
status = IssueStatus.find_by_id(params[:status_id])
|
|
343
|
344
|
priority = Enumeration.find_by_id(params[:priority_id])
|
|
344
|
345
|
assigned_to = User.find_by_id(params[:assigned_to_id])
|
|
345
|
346
|
category = @project.issue_categories.find_by_id(params[:category_id])
|
|
346
|
347
|
fixed_version = @project.versions.find_by_id(params[:fixed_version_id])
|
|
347
|
348
|
issues = @project.issues.find_all_by_id(params[:issue_ids])
|
|
348
|
|
unsaved_issue_ids = []
|
|
|
349
|
unsaved_issue_ids = []
|
|
349
|
350
|
issues.each do |issue|
|
|
350
|
351
|
journal = issue.init_journal(User.current, params[:notes])
|
|
351
|
352
|
issue.priority = priority if priority
|
|
352
|
353
|
issue.assigned_to = assigned_to if assigned_to
|
|
353
|
354
|
issue.category = category if category
|
|
354
|
355
|
issue.fixed_version = fixed_version if fixed_version
|
|
355
|
356
|
issue.start_date = params[:start_date] unless params[:start_date].blank?
|
|
356
|
357
|
issue.due_date = params[:due_date] unless params[:due_date].blank?
|
|
357
|
358
|
issue.done_ratio = params[:done_ratio] unless params[:done_ratio].blank?
|
|
358
|
|
if issue.save
|
|
|
359
|
# Don't save any change to the issue if the user is not authorized to apply the requested status
|
|
|
360
|
if (status.nil? || (issue.status.new_status_allowed_to?(status, current_role, issue.tracker) && issue.status = status)) && issue.save
|
|
359
|
361
|
# Send notification for each issue (if changed)
|
|
360
|
362
|
Mailer.deliver_issue_edit(journal) if journal.details.any? && Setting.notified_events.include?('issue_updated')
|
|
361
|
363
|
else
|
|
|
364
|
# Keep unsaved issue ids to display them in flash error
|
|
362
|
365
|
unsaved_issue_ids << issue.id
|
|
363
|
366
|
end
|
|
364
|
367
|
end
|
|
365
|
368
|
if unsaved_issue_ids.empty?
|
|
366
|
369
|
flash[:notice] = l(:notice_successful_update) unless issues.empty?
|
|
367
|
370
|
else
|
|
368
|
371
|
flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, issues.size, '#' + unsaved_issue_ids.join(', #'))
|
|
369
|
372
|
end
|
|
370
|
373
|
redirect_to :action => 'list_issues', :id => @project
|
|
371
|
374
|
return
|
|
372
|
375
|
end
|
|
|
376
|
if current_role && User.current.allowed_to?(:change_issue_status, @project)
|
|
|
377
|
# Find potential statuses the user could be allowed to switch issues to
|
|
|
378
|
@available_statuses = Workflow.find(:all, :include => :new_status,
|
|
|
379
|
:conditions => {:role_id => current_role.id}).collect(&:new_status).compact.uniq
|
|
|
380
|
end
|
|
373
|
381
|
render :update do |page|
|
|
374
|
382
|
page.hide 'query_form'
|
|
375
|
383
|
page.replace_html 'bulk-edit', :partial => 'issues/bulk_edit_form'
|
|
376
|
384
|
end
|
|
377
|
385
|
end
|
|
378
|
386
|
|
|
379
|
387
|
def move_issues
|
|
380
|
388
|
@issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids]
|
|
381
|
389
|
redirect_to :action => 'list_issues', :id => @project and return unless @issues
|
|
382
|
390
|
@projects = []
|
|
383
|
391
|
# find projects to which the user is allowed to move the issue
|
|
384
|
392
|
User.current.memberships.each {|m| @projects << m.project if m.role.allowed_to?(:controller => 'projects', :action => 'move_issues')}
|
|
385
|
393
|
# issue can be moved to any tracker
|
|
386
|
394
|
@trackers = Tracker.find(:all)
|
|
387
|
395
|
if request.post? and params[:new_project_id] and params[:new_tracker_id]
|
|
388
|
396
|
new_project = Project.find_by_id(params[:new_project_id])
|
|
389
|
397
|
new_tracker = Tracker.find_by_id(params[:new_tracker_id])
|
|
390
|
398
|
@issues.each do |i|
|
|
391
|
399
|
if new_project && i.project_id != new_project.id
|
|
392
|
400
|
# issue is moved to another project
|
|
393
|
401
|
i.category = nil
|
|
394
|
402
|
i.fixed_version = nil
|
|
395
|
403
|
# delete issue relations
|
|
396
|
404
|
i.relations_from.clear
|
|
397
|
405
|
i.relations_to.clear
|
|
398
|
406
|
i.project = new_project
|
|
399
|
407
|
end
|
|
400
|
408
|
if new_tracker
|
|
401
|
409
|
i.tracker = new_tracker
|
|
402
|
410
|
end
|
|
403
|
411
|
i.save
|
|
404
|
412
|
end
|
|
405
|
413
|
flash[:notice] = l(:notice_successful_update)
|
|
406
|
414
|
redirect_to :action => 'list_issues', :id => @project
|
|
407
|
415
|
end
|
|
408
|
416
|
end
|
|
409
|
417
|
|
|
410
|
418
|
# Add a news to @project
|
|
411
|
419
|
def add_news
|
|
412
|
420
|
@news = News.new(:project => @project)
|
|
413
|
421
|
if request.post?
|
|
414
|
422
|
@news.attributes = params[:news]
|
|
415
|
423
|
@news.author_id = self.logged_in_user.id if self.logged_in_user
|
|
416
|
424
|
if @news.save
|
|
417
|
425
|
flash[:notice] = l(:notice_successful_create)
|
|
418
|
426
|
Mailer.deliver_news_added(@news) if Setting.notified_events.include?('news_added')
|
|
419
|
427
|
redirect_to :action => 'list_news', :id => @project
|
|
420
|
428
|
end
|
|
421
|
429
|
end
|
|
422
|
430
|
end
|
|
423
|
431
|
|
|
424
|
432
|
# Show news list of @project
|
|
425
|
433
|
def list_news
|
|
426
|
434
|
@news_pages, @newss = paginate :news, :per_page => 10, :conditions => ["project_id=?", @project.id], :include => :author, :order => "#{News.table_name}.created_on DESC"
|
|
427
|
435
|
|
|
428
|
436
|
respond_to do |format|
|
|
429
|
437
|
format.html { render :layout => false if request.xhr? }
|
|
430
|
438
|
format.atom { render_feed(@newss, :title => "#{@project.name}: #{l(:label_news_plural)}") }
|
|
431
|
439
|
end
|
|
432
|
440
|
end
|
|
433
|
441
|
|
|
434
|
442
|
def add_file
|
|
435
|
443
|
if request.post?
|
|
436
|
444
|
@version = @project.versions.find_by_id(params[:version_id])
|
|
437
|
445
|
# Save the attachments
|
|
438
|
446
|
@attachments = []
|
|
439
|
447
|
params[:attachments].each { |file|
|
|
440
|
448
|
next unless file.size > 0
|
|
441
|
449
|
a = Attachment.create(:container => @version, :file => file, :author => logged_in_user)
|
|
442
|
450
|
@attachments << a unless a.new_record?
|
|
443
|
451
|
} if params[:attachments] and params[:attachments].is_a? Array
|
|
444
|
452
|
Mailer.deliver_attachments_add(@attachments) if !@attachments.empty? && Setting.notified_events.include?('file_added')
|
|
445
|
453
|
redirect_to :controller => 'projects', :action => 'list_files', :id => @project
|
|
446
|
454
|
end
|
|
447
|
455
|
@versions = @project.versions.sort
|
|
448
|
456
|
end
|
|
449
|
457
|
|
|
450
|
458
|
def list_files
|
|
451
|
459
|
@versions = @project.versions.sort
|
|
452
|
460
|
end
|
|
453
|
461
|
|
|
454
|
462
|
# Show changelog for @project
|
|
455
|
463
|
def changelog
|
|
456
|
464
|
@trackers = Tracker.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position')
|
|
457
|
465
|
retrieve_selected_tracker_ids(@trackers)
|
|
458
|
466
|
@versions = @project.versions.sort
|
|
459
|
467
|
end
|
|
460
|
468
|
|
|
461
|
469
|
def roadmap
|
|
462
|
470
|
@trackers = Tracker.find(:all, :conditions => ["is_in_roadmap=?", true], :order => 'position')
|
|
463
|
471
|
retrieve_selected_tracker_ids(@trackers)
|
|
464
|
472
|
@versions = @project.versions.sort
|
|
465
|
473
|
@versions = @versions.select {|v| !v.completed? } unless params[:completed]
|
|
466
|
474
|
end
|
|
467
|
475
|
|
|
468
|
476
|
def activity
|
|
469
|
477
|
if params[:year] and params[:year].to_i > 1900
|
|
470
|
478
|
@year = params[:year].to_i
|
|
471
|
479
|
if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
|
|
472
|
480
|
@month = params[:month].to_i
|
|
473
|
481
|
end
|
|
474
|
482
|
end
|
|
475
|
483
|
@year ||= Date.today.year
|
|
476
|
484
|
@month ||= Date.today.month
|
|
477
|
485
|
|
|
478
|
486
|
case params[:format]
|
|
479
|
487
|
when 'atom'
|
|
480
|
488
|
# 30 last days
|
|
481
|
489
|
@date_from = Date.today - 30
|
|
482
|
490
|
@date_to = Date.today + 1
|
|
483
|
491
|
else
|
|
484
|
492
|
# current month
|
|
485
|
493
|
@date_from = Date.civil(@year, @month, 1)
|
|
486
|
494
|
@date_to = @date_from >> 1
|
|
487
|
495
|
end
|
|
488
|
496
|
|
|
489
|
497
|
@event_types = %w(issues news files documents wiki_pages changesets)
|
|
490
|
498
|
@event_types.delete('wiki_pages') unless @project.wiki
|
|
491
|
499
|
@event_types.delete('changesets') unless @project.repository
|
|
492
|
500
|
# only show what the user is allowed to view
|
|
493
|
501
|
@event_types = @event_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, @project)}
|
|
494
|
502
|
|
|
495
|
503
|
@scope = @event_types.select {|t| params["show_#{t}"]}
|
|
496
|
504
|
# default events if none is specified in parameters
|
|
497
|
505
|
@scope = (@event_types - %w(wiki_pages))if @scope.empty?
|
|
498
|
506
|
|
|
499
|
507
|
@events = []
|
|
500
|
508
|
|
|
501
|
509
|
if @scope.include?('issues')
|
|
502
|
510
|
@events += @project.issues.find(:all, :include => [:author, :tracker], :conditions => ["#{Issue.table_name}.created_on>=? and #{Issue.table_name}.created_on<=?", @date_from, @date_to] )
|
|
503
|
511
|
end
|
|
504
|
512
|
|
|
505
|
513
|
if @scope.include?('news')
|
|
506
|
514
|
@events += @project.news.find(:all, :conditions => ["#{News.table_name}.created_on>=? and #{News.table_name}.created_on<=?", @date_from, @date_to], :include => :author )
|
|
507
|
515
|
end
|
|
508
|
516
|
|
|
509
|
517
|
if @scope.include?('files')
|
|
510
|
518
|
@events += Attachment.find(:all, :select => "#{Attachment.table_name}.*", :joins => "LEFT JOIN #{Version.table_name} ON #{Version.table_name}.id = #{Attachment.table_name}.container_id", :conditions => ["#{Attachment.table_name}.container_type='Version' and #{Version.table_name}.project_id=? and #{Attachment.table_name}.created_on>=? and #{Attachment.table_name}.created_on<=?", @project.id, @date_from, @date_to], :include => :author )
|
|
511
|
519
|
end
|
|
512
|
520
|
|
|
513
|
521
|
if @scope.include?('documents')
|
|
514
|
522
|
@events += @project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on>=? and #{Document.table_name}.created_on<=?", @date_from, @date_to] )
|
|
515
|
523
|
@events += Attachment.find(:all, :select => "attachments.*", :joins => "LEFT JOIN #{Document.table_name} ON #{Document.table_name}.id = #{Attachment.table_name}.container_id", :conditions => ["#{Attachment.table_name}.container_type='Document' and #{Document.table_name}.project_id=? and #{Attachment.table_name}.created_on>=? and #{Attachment.table_name}.created_on<=?", @project.id, @date_from, @date_to], :include => :author )
|
|
516
|
524
|
end
|
|
517
|
525
|
|
|
518
|
526
|
if @scope.include?('wiki_pages')
|
|
519
|
527
|
select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " +
|
|
520
|
528
|
"#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title, " +
|
|
521
|
529
|
"#{WikiContent.versioned_table_name}.page_id, #{WikiContent.versioned_table_name}.author_id, " +
|
|
522
|
530
|
"#{WikiContent.versioned_table_name}.id"
|
|
523
|
531
|
joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " +
|
|
524
|
532
|
"LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id "
|
|
525
|
533
|
conditions = ["#{Wiki.table_name}.project_id = ? AND #{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?",
|
|
526
|
534
|
@project.id, @date_from, @date_to]
|
|
527
|
535
|
|
|
528
|
536
|
@events += WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => conditions)
|
|
529
|
537
|
end
|
|
530
|
538
|
|
|
531
|
539
|
if @scope.include?('changesets')
|
|
532
|
540
|
@events += @project.repository.changesets.find(:all, :conditions => ["#{Changeset.table_name}.committed_on BETWEEN ? AND ?", @date_from, @date_to])
|
|
533
|
541
|
end
|
|
534
|
542
|
|
|
535
|
543
|
@events_by_day = @events.group_by(&:event_date)
|
|
536
|
544
|
|
|
537
|
545
|
respond_to do |format|
|
|
538
|
546
|
format.html { render :layout => false if request.xhr? }
|
|
539
|
547
|
format.atom { render_feed(@events, :title => "#{@project.name}: #{l(:label_activity)}") }
|
|
540
|
548
|
end
|
|
541
|
549
|
end
|
|
542
|
550
|
|
|
543
|
551
|
def calendar
|
|
544
|
552
|
@trackers = Tracker.find(:all, :order => 'position')
|
|
545
|
553
|
retrieve_selected_tracker_ids(@trackers)
|
|
546
|
554
|
|
|
547
|
555
|
if params[:year] and params[:year].to_i > 1900
|
|
548
|
556
|
@year = params[:year].to_i
|
|
549
|
557
|
if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
|
|
550
|
558
|
@month = params[:month].to_i
|
|
551
|
559
|
end
|
|
552
|
560
|
end
|
|
553
|
561
|
@year ||= Date.today.year
|
|
554
|
562
|
@month ||= Date.today.month
|
|
555
|
563
|
@calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month)
|
|
556
|
564
|
|
|
557
|
565
|
events = []
|
|
558
|
566
|
@project.issues_with_subprojects(params[:with_subprojects]) do
|
|
559
|
567
|
events += Issue.find(:all,
|
|
560
|
568
|
:include => [:tracker, :status, :assigned_to, :priority, :project],
|
|
561
|
569
|
:conditions => ["((start_date BETWEEN ? AND ?) OR (due_date BETWEEN ? AND ?)) AND #{Issue.table_name}.tracker_id IN (#{@selected_tracker_ids.join(',')})", @calendar.startdt, @calendar.enddt, @calendar.startdt, @calendar.enddt]
|
|
562
|
570
|
) unless @selected_tracker_ids.empty?
|
|
563
|
571
|
end
|
|
564
|
572
|
events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt])
|
|
565
|
573
|
@calendar.events = events
|
|
566
|
574
|
|
|
567
|
575
|
render :layout => false if request.xhr?
|
|
568
|
576
|
end
|
|
569
|
577
|
|
|
570
|
578
|
def gantt
|
|
571
|
579
|
@trackers = Tracker.find(:all, :order => 'position')
|
|
572
|
580
|
retrieve_selected_tracker_ids(@trackers)
|
|
573
|
581
|
|
|
574
|
582
|
if params[:year] and params[:year].to_i >0
|
|
575
|
583
|
@year_from = params[:year].to_i
|
|
576
|
584
|
if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12
|
|
577
|
585
|
@month_from = params[:month].to_i
|
|
578
|
586
|
else
|
|
579
|
587
|
@month_from = 1
|
|
580
|
588
|
end
|
|
581
|
589
|
else
|
|
582
|
590
|
@month_from ||= Date.today.month
|
|
583
|
591
|
@year_from ||= Date.today.year
|
|
584
|
592
|
end
|
|
585
|
593
|
|
|
586
|
594
|
zoom = (params[:zoom] || User.current.pref[:gantt_zoom]).to_i
|
|
587
|
595
|
@zoom = (zoom > 0 && zoom < 5) ? zoom : 2
|
|
588
|
596
|
months = (params[:months] || User.current.pref[:gantt_months]).to_i
|
|
589
|
597
|
@months = (months > 0 && months < 25) ? months : 6
|
|
590
|
598
|
|
|
591
|
599
|
# Save gantt paramters as user preference (zoom and months count)
|
|
592
|
600
|
if (User.current.logged? && (@zoom != User.current.pref[:gantt_zoom] || @months != User.current.pref[:gantt_months]))
|
|
593
|
601
|
User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months
|
|
594
|
602
|
User.current.preference.save
|
|
595
|
603
|
end
|
|
596
|
604
|
|
|
597
|
605
|
@date_from = Date.civil(@year_from, @month_from, 1)
|
|
598
|
606
|
@date_to = (@date_from >> @months) - 1
|
|
599
|
607
|
|
|
600
|
608
|
@events = []
|
|
601
|
609
|
@project.issues_with_subprojects(params[:with_subprojects]) do
|
|
602
|
610
|
@events += Issue.find(:all,
|
|
603
|
611
|
:order => "start_date, due_date",
|
|
604
|
612
|
:include => [:tracker, :status, :assigned_to, :priority, :project],
|
|
605
|
613
|
:conditions => ["(((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?) or (start_date<? and due_date>?)) and start_date is not null and due_date is not null and #{Issue.table_name}.tracker_id in (#{@selected_tracker_ids.join(',')}))", @date_from, @date_to, @date_from, @date_to, @date_from, @date_to]
|
|
606
|
614
|
) unless @selected_tracker_ids.empty?
|
|
607
|
615
|
end
|
|
608
|
616
|
@events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to])
|
|
609
|
617
|
@events.sort! {|x,y| x.start_date <=> y.start_date }
|
|
610
|
618
|
|
|
611
|
619
|
if params[:format]=='pdf'
|
|
612
|
620
|
@options_for_rfpdf ||= {}
|
|
613
|
621
|
@options_for_rfpdf[:file_name] = "#{@project.identifier}-gantt.pdf"
|
|
614
|
622
|
render :template => "projects/gantt.rfpdf", :layout => false
|
|
615
|
623
|
elsif params[:format]=='png' && respond_to?('gantt_image')
|
|
616
|
624
|
image = gantt_image(@events, @date_from, @months, @zoom)
|
|
617
|
625
|
image.format = 'PNG'
|
|
618
|
626
|
send_data(image.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "#{@project.identifier}-gantt.png")
|
|
619
|
627
|
else
|
|
620
|
628
|
render :template => "projects/gantt.rhtml"
|
|
621
|
629
|
end
|
|
622
|
630
|
end
|
|
623
|
631
|
|
|
624
|
632
|
private
|
|
625
|
633
|
# Find project of id params[:id]
|
|
626
|
634
|
# if not found, redirect to project list
|
|
627
|
635
|
# Used as a before_filter
|
|
628
|
636
|
def find_project
|
|
629
|
637
|
@project = Project.find(params[:id])
|
|
630
|
638
|
rescue ActiveRecord::RecordNotFound
|
|
631
|
639
|
render_404
|
|
632
|
640
|
end
|
|
633
|
641
|
|
|
634
|
642
|
def retrieve_selected_tracker_ids(selectable_trackers)
|
|
635
|
643
|
if ids = params[:tracker_ids]
|
|
636
|
644
|
@selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
|
|
637
|
645
|
else
|
|
638
|
646
|
@selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s }
|
|
639
|
647
|
end
|
|
640
|
648
|
end
|
|
641
|
649
|
|
|
642
|
650
|
# Retrieve query from session or build a new query
|
|
643
|
651
|
def retrieve_query
|
|
644
|
652
|
if params[:query_id]
|
|
645
|
653
|
@query = @project.queries.find(params[:query_id])
|
|
646
|
654
|
@query.executed_by = logged_in_user
|
|
647
|
655
|
session[:query] = @query
|
|
648
|
656
|
else
|
|
649
|
657
|
if params[:set_filter] or !session[:query] or session[:query].project_id != @project.id
|
|
650
|
658
|
# Give it a name, required to be valid
|
|
651
|
659
|
@query = Query.new(:name => "_", :executed_by => logged_in_user)
|
|
652
|
660
|
@query.project = @project
|
|
653
|
661
|
if params[:fields] and params[:fields].is_a? Array
|
|
654
|
662
|
params[:fields].each do |field|
|
|
655
|
663
|
@query.add_filter(field, params[:operators][field], params[:values][field])
|
|
656
|
664
|
end
|
|
657
|
665
|
else
|
|
658
|
666
|
@query.available_filters.keys.each do |field|
|
|
659
|
667
|
@query.add_short_filter(field, params[field]) if params[field]
|
|
660
|
668
|
end
|
|
661
|
669
|
end
|
|
662
|
670
|
session[:query] = @query
|
|
663
|
671
|
else
|
|
664
|
672
|
@query = session[:query]
|
|
665
|
673
|
end
|
|
666
|
674
|
end
|
|
667
|
675
|
end
|
|
668
|
676
|
end
|