|
@@
-1,677
+1,678
|
|
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, :authorize, :except => [ :index, :list, :add ]
|
|
23
|
23
|
before_filter :require_admin, :only => [ :add, :destroy ]
|
|
24
|
24
|
|
|
25
|
25
|
helper :sort
|
|
26
|
26
|
include SortHelper
|
|
27
|
27
|
helper :custom_fields
|
|
28
|
28
|
include CustomFieldsHelper
|
|
29
|
29
|
helper :ifpdf
|
|
30
|
30
|
include IfpdfHelper
|
|
31
|
31
|
helper IssuesHelper
|
|
32
|
32
|
helper :queries
|
|
33
|
33
|
include QueriesHelper
|
|
34
|
34
|
|
|
35
|
35
|
def index
|
|
36
|
36
|
list
|
|
37
|
37
|
render :action => 'list' unless request.xhr?
|
|
38
|
38
|
end
|
|
39
|
39
|
|
|
40
|
40
|
# Lists public projects
|
|
41
|
41
|
def list
|
|
42
|
|
sort_init 'name', 'asc'
|
|
|
42
|
sort_init "#{Project.table_name}.name", "asc"
|
|
43
|
43
|
sort_update
|
|
44
|
44
|
@project_count = Project.count(:all, :conditions => ["is_public=?", true])
|
|
45
|
45
|
@project_pages = Paginator.new self, @project_count,
|
|
46
|
46
|
15,
|
|
47
|
47
|
params['page']
|
|
48
|
48
|
@projects = Project.find :all, :order => sort_clause,
|
|
49
|
|
:conditions => ["is_public=?", true],
|
|
|
49
|
:conditions => ["#{Project.table_name}.is_public=?", true],
|
|
|
50
|
:include => :parent,
|
|
50
|
51
|
:limit => @project_pages.items_per_page,
|
|
51
|
52
|
:offset => @project_pages.current.offset
|
|
52
|
53
|
|
|
53
|
54
|
render :action => "list", :layout => false if request.xhr?
|
|
54
|
55
|
end
|
|
55
|
56
|
|
|
56
|
57
|
# Add a new project
|
|
57
|
58
|
def add
|
|
58
|
59
|
@custom_fields = IssueCustomField.find(:all)
|
|
59
|
60
|
@root_projects = Project.find(:all, :conditions => "parent_id is null")
|
|
60
|
61
|
@project = Project.new(params[:project])
|
|
61
|
62
|
if request.get?
|
|
62
|
63
|
@custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project) }
|
|
63
|
64
|
else
|
|
64
|
65
|
@project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
|
|
65
|
66
|
@custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
|
|
66
|
67
|
@project.custom_values = @custom_values
|
|
67
|
68
|
if params[:repository_enabled] && params[:repository_enabled] == "1"
|
|
68
|
69
|
@project.repository = Repository.new
|
|
69
|
70
|
@project.repository.attributes = params[:repository]
|
|
70
|
71
|
end
|
|
71
|
72
|
if "1" == params[:wiki_enabled]
|
|
72
|
73
|
@project.wiki = Wiki.new
|
|
73
|
74
|
@project.wiki.attributes = params[:wiki]
|
|
74
|
75
|
end
|
|
75
|
76
|
if @project.save
|
|
76
|
77
|
flash[:notice] = l(:notice_successful_create)
|
|
77
|
78
|
redirect_to :controller => 'admin', :action => 'projects'
|
|
78
|
79
|
end
|
|
79
|
80
|
end
|
|
80
|
81
|
end
|
|
81
|
82
|
|
|
82
|
83
|
# Show @project
|
|
83
|
84
|
def show
|
|
84
|
85
|
@custom_values = @project.custom_values.find(:all, :include => :custom_field)
|
|
85
|
86
|
@members = @project.members.find(:all, :include => [:user, :role], :order => 'position')
|
|
86
|
87
|
@subprojects = @project.children if @project.children.size > 0
|
|
87
|
88
|
@news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
|
|
88
|
89
|
@trackers = Tracker.find(:all, :order => 'position')
|
|
89
|
90
|
@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])
|
|
90
|
91
|
@total_issues_by_tracker = Issue.count(:group => :tracker, :conditions => ["project_id=?", @project.id])
|
|
91
|
92
|
end
|
|
92
|
93
|
|
|
93
|
94
|
def settings
|
|
94
|
95
|
@root_projects = Project::find(:all, :conditions => ["parent_id is null and id <> ?", @project.id])
|
|
95
|
96
|
@custom_fields = IssueCustomField.find(:all)
|
|
96
|
97
|
@issue_category ||= IssueCategory.new
|
|
97
|
98
|
@member ||= @project.members.new
|
|
98
|
99
|
@roles = Role.find(:all, :order => 'position')
|
|
99
|
100
|
@users = User.find_active(:all) - @project.users
|
|
100
|
101
|
@custom_values ||= ProjectCustomField.find(:all).collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
|
|
101
|
102
|
end
|
|
102
|
103
|
|
|
103
|
104
|
# Edit @project
|
|
104
|
105
|
def edit
|
|
105
|
106
|
if request.post?
|
|
106
|
107
|
@project.custom_fields = IssueCustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
|
|
107
|
108
|
if params[:custom_fields]
|
|
108
|
109
|
@custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
|
|
109
|
110
|
@project.custom_values = @custom_values
|
|
110
|
111
|
end
|
|
111
|
112
|
if params[:repository_enabled]
|
|
112
|
113
|
case params[:repository_enabled]
|
|
113
|
114
|
when "0"
|
|
114
|
115
|
@project.repository = nil
|
|
115
|
116
|
when "1"
|
|
116
|
117
|
@project.repository ||= Repository.new
|
|
117
|
118
|
@project.repository.update_attributes params[:repository]
|
|
118
|
119
|
end
|
|
119
|
120
|
end
|
|
120
|
121
|
if params[:wiki_enabled]
|
|
121
|
122
|
case params[:wiki_enabled]
|
|
122
|
123
|
when "0"
|
|
123
|
124
|
@project.wiki.destroy if @project.wiki
|
|
124
|
125
|
when "1"
|
|
125
|
126
|
@project.wiki ||= Wiki.new
|
|
126
|
127
|
@project.wiki.update_attributes params[:wiki]
|
|
127
|
128
|
end
|
|
128
|
129
|
end
|
|
129
|
130
|
@project.attributes = params[:project]
|
|
130
|
131
|
if @project.save
|
|
131
|
132
|
flash[:notice] = l(:notice_successful_update)
|
|
132
|
133
|
redirect_to :action => 'settings', :id => @project
|
|
133
|
134
|
else
|
|
134
|
135
|
settings
|
|
135
|
136
|
render :action => 'settings'
|
|
136
|
137
|
end
|
|
137
|
138
|
end
|
|
138
|
139
|
end
|
|
139
|
140
|
|
|
140
|
141
|
# Delete @project
|
|
141
|
142
|
def destroy
|
|
142
|
143
|
if request.post? and params[:confirm]
|
|
143
|
144
|
@project.destroy
|
|
144
|
145
|
redirect_to :controller => 'admin', :action => 'projects'
|
|
145
|
146
|
end
|
|
146
|
147
|
end
|
|
147
|
148
|
|
|
148
|
149
|
# Add a new issue category to @project
|
|
149
|
150
|
def add_issue_category
|
|
150
|
151
|
if request.post?
|
|
151
|
152
|
@issue_category = @project.issue_categories.build(params[:issue_category])
|
|
152
|
153
|
if @issue_category.save
|
|
153
|
154
|
flash[:notice] = l(:notice_successful_create)
|
|
154
|
155
|
redirect_to :action => 'settings', :tab => 'categories', :id => @project
|
|
155
|
156
|
else
|
|
156
|
157
|
settings
|
|
157
|
158
|
render :action => 'settings'
|
|
158
|
159
|
end
|
|
159
|
160
|
end
|
|
160
|
161
|
end
|
|
161
|
162
|
|
|
162
|
163
|
# Add a new version to @project
|
|
163
|
164
|
def add_version
|
|
164
|
165
|
@version = @project.versions.build(params[:version])
|
|
165
|
166
|
if request.post? and @version.save
|
|
166
|
167
|
flash[:notice] = l(:notice_successful_create)
|
|
167
|
168
|
redirect_to :action => 'settings', :tab => 'versions', :id => @project
|
|
168
|
169
|
end
|
|
169
|
170
|
end
|
|
170
|
171
|
|
|
171
|
172
|
# Add a new member to @project
|
|
172
|
173
|
def add_member
|
|
173
|
174
|
@member = @project.members.build(params[:member])
|
|
174
|
175
|
if request.post?
|
|
175
|
176
|
if @member.save
|
|
176
|
177
|
flash[:notice] = l(:notice_successful_create)
|
|
177
|
178
|
redirect_to :action => 'settings', :tab => 'members', :id => @project
|
|
178
|
179
|
else
|
|
179
|
180
|
settings
|
|
180
|
181
|
render :action => 'settings'
|
|
181
|
182
|
end
|
|
182
|
183
|
end
|
|
183
|
184
|
end
|
|
184
|
185
|
|
|
185
|
186
|
# Show members list of @project
|
|
186
|
187
|
def list_members
|
|
187
|
188
|
@members = @project.members.find(:all)
|
|
188
|
189
|
end
|
|
189
|
190
|
|
|
190
|
191
|
# Add a new document to @project
|
|
191
|
192
|
def add_document
|
|
192
|
193
|
@categories = Enumeration::get_values('DCAT')
|
|
193
|
194
|
@document = @project.documents.build(params[:document])
|
|
194
|
195
|
if request.post? and @document.save
|
|
195
|
196
|
# Save the attachments
|
|
196
|
197
|
params[:attachments].each { |a|
|
|
197
|
198
|
Attachment.create(:container => @document, :file => a, :author => logged_in_user) unless a.size == 0
|
|
198
|
199
|
} if params[:attachments] and params[:attachments].is_a? Array
|
|
199
|
200
|
flash[:notice] = l(:notice_successful_create)
|
|
200
|
201
|
Mailer.deliver_document_add(@document) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
|
|
201
|
202
|
redirect_to :action => 'list_documents', :id => @project
|
|
202
|
203
|
end
|
|
203
|
204
|
end
|
|
204
|
205
|
|
|
205
|
206
|
# Show documents list of @project
|
|
206
|
207
|
def list_documents
|
|
207
|
208
|
@documents = @project.documents.find :all, :include => :category
|
|
208
|
209
|
end
|
|
209
|
210
|
|
|
210
|
211
|
# Add a new issue to @project
|
|
211
|
212
|
def add_issue
|
|
212
|
213
|
@tracker = Tracker.find(params[:tracker_id])
|
|
213
|
214
|
@priorities = Enumeration::get_values('IPRI')
|
|
214
|
215
|
@issue = Issue.new(:project => @project, :tracker => @tracker)
|
|
215
|
216
|
if request.get?
|
|
216
|
217
|
@issue.start_date = Date.today
|
|
217
|
218
|
@custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) }
|
|
218
|
219
|
else
|
|
219
|
220
|
@issue.attributes = params[:issue]
|
|
220
|
221
|
@issue.author_id = self.logged_in_user.id if self.logged_in_user
|
|
221
|
222
|
# Multiple file upload
|
|
222
|
223
|
@attachments = []
|
|
223
|
224
|
params[:attachments].each { |a|
|
|
224
|
225
|
@attachments << Attachment.new(:container => @issue, :file => a, :author => logged_in_user) unless a.size == 0
|
|
225
|
226
|
} if params[:attachments] and params[:attachments].is_a? Array
|
|
226
|
227
|
@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]) }
|
|
227
|
228
|
@issue.custom_values = @custom_values
|
|
228
|
229
|
if @issue.save
|
|
229
|
230
|
@attachments.each(&:save)
|
|
230
|
231
|
flash[:notice] = l(:notice_successful_create)
|
|
231
|
232
|
Mailer.deliver_issue_add(@issue) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
|
|
232
|
233
|
redirect_to :action => 'list_issues', :id => @project
|
|
233
|
234
|
end
|
|
234
|
235
|
end
|
|
235
|
236
|
end
|
|
236
|
237
|
|
|
237
|
238
|
# Show filtered/sorted issues list of @project
|
|
238
|
239
|
def list_issues
|
|
239
|
240
|
sort_init "#{Issue.table_name}.id", "desc"
|
|
240
|
241
|
sort_update
|
|
241
|
242
|
|
|
242
|
243
|
retrieve_query
|
|
243
|
244
|
|
|
244
|
245
|
@results_per_page_options = [ 15, 25, 50, 100 ]
|
|
245
|
246
|
if params[:per_page] and @results_per_page_options.include? params[:per_page].to_i
|
|
246
|
247
|
@results_per_page = params[:per_page].to_i
|
|
247
|
248
|
session[:results_per_page] = @results_per_page
|
|
248
|
249
|
else
|
|
249
|
250
|
@results_per_page = session[:results_per_page] || 25
|
|
250
|
251
|
end
|
|
251
|
252
|
|
|
252
|
253
|
if @query.valid?
|
|
253
|
254
|
@issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement)
|
|
254
|
255
|
@issue_pages = Paginator.new self, @issue_count, @results_per_page, params['page']
|
|
255
|
256
|
@issues = Issue.find :all, :order => sort_clause,
|
|
256
|
257
|
:include => [ :author, :status, :tracker, :project, :priority ],
|
|
257
|
258
|
:conditions => @query.statement,
|
|
258
|
259
|
:limit => @issue_pages.items_per_page,
|
|
259
|
260
|
:offset => @issue_pages.current.offset
|
|
260
|
261
|
end
|
|
261
|
262
|
@trackers = Tracker.find :all, :order => 'position'
|
|
262
|
263
|
render :layout => false if request.xhr?
|
|
263
|
264
|
end
|
|
264
|
265
|
|
|
265
|
266
|
# Export filtered/sorted issues list to CSV
|
|
266
|
267
|
def export_issues_csv
|
|
267
|
268
|
sort_init "#{Issue.table_name}.id", "desc"
|
|
268
|
269
|
sort_update
|
|
269
|
270
|
|
|
270
|
271
|
retrieve_query
|
|
271
|
272
|
render :action => 'list_issues' and return unless @query.valid?
|
|
272
|
273
|
|
|
273
|
274
|
@issues = Issue.find :all, :order => sort_clause,
|
|
274
|
275
|
:include => [ :author, :status, :tracker, :priority, {:custom_values => :custom_field} ],
|
|
275
|
276
|
:conditions => @query.statement,
|
|
276
|
277
|
:limit => Setting.issues_export_limit
|
|
277
|
278
|
|
|
278
|
279
|
ic = Iconv.new(l(:general_csv_encoding), 'UTF-8')
|
|
279
|
280
|
export = StringIO.new
|
|
280
|
281
|
CSV::Writer.generate(export, l(:general_csv_separator)) do |csv|
|
|
281
|
282
|
# csv header fields
|
|
282
|
283
|
headers = [ "#", l(:field_status),
|
|
283
|
284
|
l(:field_tracker),
|
|
284
|
285
|
l(:field_priority),
|
|
285
|
286
|
l(:field_subject),
|
|
286
|
287
|
l(:field_author),
|
|
287
|
288
|
l(:field_start_date),
|
|
288
|
289
|
l(:field_due_date),
|
|
289
|
290
|
l(:field_done_ratio),
|
|
290
|
291
|
l(:field_created_on),
|
|
291
|
292
|
l(:field_updated_on)
|
|
292
|
293
|
]
|
|
293
|
294
|
for custom_field in @project.all_custom_fields
|
|
294
|
295
|
headers << custom_field.name
|
|
295
|
296
|
end
|
|
296
|
297
|
csv << headers.collect {|c| ic.iconv(c) }
|
|
297
|
298
|
# csv lines
|
|
298
|
299
|
@issues.each do |issue|
|
|
299
|
300
|
fields = [issue.id, issue.status.name,
|
|
300
|
301
|
issue.tracker.name,
|
|
301
|
302
|
issue.priority.name,
|
|
302
|
303
|
issue.subject,
|
|
303
|
304
|
issue.author.display_name,
|
|
304
|
305
|
issue.start_date ? l_date(issue.start_date) : nil,
|
|
305
|
306
|
issue.due_date ? l_date(issue.due_date) : nil,
|
|
306
|
307
|
issue.done_ratio,
|
|
307
|
308
|
l_datetime(issue.created_on),
|
|
308
|
309
|
l_datetime(issue.updated_on)
|
|
309
|
310
|
]
|
|
310
|
311
|
for custom_field in @project.all_custom_fields
|
|
311
|
312
|
fields << (show_value issue.custom_value_for(custom_field))
|
|
312
|
313
|
end
|
|
313
|
314
|
csv << fields.collect {|c| ic.iconv(c.to_s) }
|
|
314
|
315
|
end
|
|
315
|
316
|
end
|
|
316
|
317
|
export.rewind
|
|
317
|
318
|
send_data(export.read, :type => 'text/csv; header=present', :filename => 'export.csv')
|
|
318
|
319
|
end
|
|
319
|
320
|
|
|
320
|
321
|
# Export filtered/sorted issues to PDF
|
|
321
|
322
|
def export_issues_pdf
|
|
322
|
323
|
sort_init "#{Issue.table_name}.id", "desc"
|
|
323
|
324
|
sort_update
|
|
324
|
325
|
|
|
325
|
326
|
retrieve_query
|
|
326
|
327
|
render :action => 'list_issues' and return unless @query.valid?
|
|
327
|
328
|
|
|
328
|
329
|
@issues = Issue.find :all, :order => sort_clause,
|
|
329
|
330
|
:include => [ :author, :status, :tracker, :priority ],
|
|
330
|
331
|
:conditions => @query.statement,
|
|
331
|
332
|
:limit => Setting.issues_export_limit
|
|
332
|
333
|
|
|
333
|
334
|
@options_for_rfpdf ||= {}
|
|
334
|
335
|
@options_for_rfpdf[:file_name] = "export.pdf"
|
|
335
|
336
|
render :layout => false
|
|
336
|
337
|
end
|
|
337
|
338
|
|
|
338
|
339
|
def move_issues
|
|
339
|
340
|
@issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids]
|
|
340
|
341
|
redirect_to :action => 'list_issues', :id => @project and return unless @issues
|
|
341
|
342
|
@projects = []
|
|
342
|
343
|
# find projects to which the user is allowed to move the issue
|
|
343
|
344
|
@logged_in_user.memberships.each {|m| @projects << m.project if Permission.allowed_to_role("projects/move_issues", m.role_id)}
|
|
344
|
345
|
# issue can be moved to any tracker
|
|
345
|
346
|
@trackers = Tracker.find(:all)
|
|
346
|
347
|
if request.post? and params[:new_project_id] and params[:new_tracker_id]
|
|
347
|
348
|
new_project = Project.find(params[:new_project_id])
|
|
348
|
349
|
new_tracker = Tracker.find(params[:new_tracker_id])
|
|
349
|
350
|
@issues.each { |i|
|
|
350
|
351
|
# project dependent properties
|
|
351
|
352
|
unless i.project_id == new_project.id
|
|
352
|
353
|
i.category = nil
|
|
353
|
354
|
i.fixed_version = nil
|
|
354
|
355
|
end
|
|
355
|
356
|
# move the issue
|
|
356
|
357
|
i.project = new_project
|
|
357
|
358
|
i.tracker = new_tracker
|
|
358
|
359
|
i.save
|
|
359
|
360
|
}
|
|
360
|
361
|
flash[:notice] = l(:notice_successful_update)
|
|
361
|
362
|
redirect_to :action => 'list_issues', :id => @project
|
|
362
|
363
|
end
|
|
363
|
364
|
end
|
|
364
|
365
|
|
|
365
|
366
|
def add_query
|
|
366
|
367
|
@query = Query.new(params[:query])
|
|
367
|
368
|
@query.project = @project
|
|
368
|
369
|
@query.user = logged_in_user
|
|
369
|
370
|
|
|
370
|
371
|
params[:fields].each do |field|
|
|
371
|
372
|
@query.add_filter(field, params[:operators][field], params[:values][field])
|
|
372
|
373
|
end if params[:fields]
|
|
373
|
374
|
|
|
374
|
375
|
if request.post? and @query.save
|
|
375
|
376
|
flash[:notice] = l(:notice_successful_create)
|
|
376
|
377
|
redirect_to :controller => 'reports', :action => 'issue_report', :id => @project
|
|
377
|
378
|
end
|
|
378
|
379
|
render :layout => false if request.xhr?
|
|
379
|
380
|
end
|
|
380
|
381
|
|
|
381
|
382
|
# Add a news to @project
|
|
382
|
383
|
def add_news
|
|
383
|
384
|
@news = News.new(:project => @project)
|
|
384
|
385
|
if request.post?
|
|
385
|
386
|
@news.attributes = params[:news]
|
|
386
|
387
|
@news.author_id = self.logged_in_user.id if self.logged_in_user
|
|
387
|
388
|
if @news.save
|
|
388
|
389
|
flash[:notice] = l(:notice_successful_create)
|
|
389
|
390
|
redirect_to :action => 'list_news', :id => @project
|
|
390
|
391
|
end
|
|
391
|
392
|
end
|
|
392
|
393
|
end
|
|
393
|
394
|
|
|
394
|
395
|
# Show news list of @project
|
|
395
|
396
|
def list_news
|
|
396
|
397
|
@news_pages, @news = paginate :news, :per_page => 10, :conditions => ["project_id=?", @project.id], :include => :author, :order => "#{News.table_name}.created_on DESC"
|
|
397
|
398
|
render :action => "list_news", :layout => false if request.xhr?
|
|
398
|
399
|
end
|
|
399
|
400
|
|
|
400
|
401
|
def add_file
|
|
401
|
402
|
if request.post?
|
|
402
|
403
|
@version = @project.versions.find_by_id(params[:version_id])
|
|
403
|
404
|
# Save the attachments
|
|
404
|
405
|
@attachments = []
|
|
405
|
406
|
params[:attachments].each { |file|
|
|
406
|
407
|
next unless file.size > 0
|
|
407
|
408
|
a = Attachment.create(:container => @version, :file => file, :author => logged_in_user)
|
|
408
|
409
|
@attachments << a unless a.new_record?
|
|
409
|
410
|
} if params[:attachments] and params[:attachments].is_a? Array
|
|
410
|
411
|
Mailer.deliver_attachments_add(@attachments) if !@attachments.empty? and Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
|
|
411
|
412
|
redirect_to :controller => 'projects', :action => 'list_files', :id => @project
|
|
412
|
413
|
end
|
|
413
|
414
|
@versions = @project.versions
|
|
414
|
415
|
end
|
|
415
|
416
|
|
|
416
|
417
|
def list_files
|
|
417
|
418
|
@versions = @project.versions
|
|
418
|
419
|
end
|
|
419
|
420
|
|
|
420
|
421
|
# Show changelog for @project
|
|
421
|
422
|
def changelog
|
|
422
|
423
|
@trackers = Tracker.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position')
|
|
423
|
424
|
retrieve_selected_tracker_ids(@trackers)
|
|
424
|
425
|
|
|
425
|
426
|
@fixed_issues = @project.issues.find(:all,
|
|
426
|
427
|
:include => [ :fixed_version, :status, :tracker ],
|
|
427
|
428
|
:conditions => [ "#{IssueStatus.table_name}.is_closed=? and #{Issue.table_name}.tracker_id in (#{@selected_tracker_ids.join(',')}) and #{Issue.table_name}.fixed_version_id is not null", true],
|
|
428
|
429
|
:order => "#{Version.table_name}.effective_date DESC, #{Issue.table_name}.id DESC"
|
|
429
|
430
|
) unless @selected_tracker_ids.empty?
|
|
430
|
431
|
@fixed_issues ||= []
|
|
431
|
432
|
end
|
|
432
|
433
|
|
|
433
|
434
|
def roadmap
|
|
434
|
435
|
@trackers = Tracker.find(:all, :conditions => ["is_in_roadmap=?", true], :order => 'position')
|
|
435
|
436
|
retrieve_selected_tracker_ids(@trackers)
|
|
436
|
437
|
|
|
437
|
438
|
@versions = @project.versions.find(:all,
|
|
438
|
439
|
:conditions => [ "#{Version.table_name}.effective_date>?", Date.today],
|
|
439
|
440
|
:order => "#{Version.table_name}.effective_date ASC"
|
|
440
|
441
|
)
|
|
441
|
442
|
end
|
|
442
|
443
|
|
|
443
|
444
|
def activity
|
|
444
|
445
|
if params[:year] and params[:year].to_i > 1900
|
|
445
|
446
|
@year = params[:year].to_i
|
|
446
|
447
|
if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
|
|
447
|
448
|
@month = params[:month].to_i
|
|
448
|
449
|
end
|
|
449
|
450
|
end
|
|
450
|
451
|
@year ||= Date.today.year
|
|
451
|
452
|
@month ||= Date.today.month
|
|
452
|
453
|
|
|
453
|
454
|
@date_from = Date.civil(@year, @month, 1)
|
|
454
|
455
|
@date_to = (@date_from >> 1)-1
|
|
455
|
456
|
|
|
456
|
457
|
@events_by_day = {}
|
|
457
|
458
|
|
|
458
|
459
|
unless params[:show_issues] == "0"
|
|
459
|
460
|
@project.issues.find(:all, :include => [:author, :status], :conditions => ["#{Issue.table_name}.created_on>=? and #{Issue.table_name}.created_on<=?", @date_from, @date_to] ).each { |i|
|
|
460
|
461
|
@events_by_day[i.created_on.to_date] ||= []
|
|
461
|
462
|
@events_by_day[i.created_on.to_date] << i
|
|
462
|
463
|
}
|
|
463
|
464
|
@show_issues = 1
|
|
464
|
465
|
end
|
|
465
|
466
|
|
|
466
|
467
|
unless params[:show_news] == "0"
|
|
467
|
468
|
@project.news.find(:all, :conditions => ["#{News.table_name}.created_on>=? and #{News.table_name}.created_on<=?", @date_from, @date_to], :include => :author ).each { |i|
|
|
468
|
469
|
@events_by_day[i.created_on.to_date] ||= []
|
|
469
|
470
|
@events_by_day[i.created_on.to_date] << i
|
|
470
|
471
|
}
|
|
471
|
472
|
@show_news = 1
|
|
472
|
473
|
end
|
|
473
|
474
|
|
|
474
|
475
|
unless params[:show_files] == "0"
|
|
475
|
476
|
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 ).each { |i|
|
|
476
|
477
|
@events_by_day[i.created_on.to_date] ||= []
|
|
477
|
478
|
@events_by_day[i.created_on.to_date] << i
|
|
478
|
479
|
}
|
|
479
|
480
|
@show_files = 1
|
|
480
|
481
|
end
|
|
481
|
482
|
|
|
482
|
483
|
unless params[:show_documents] == "0"
|
|
483
|
484
|
@project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on>=? and #{Document.table_name}.created_on<=?", @date_from, @date_to] ).each { |i|
|
|
484
|
485
|
@events_by_day[i.created_on.to_date] ||= []
|
|
485
|
486
|
@events_by_day[i.created_on.to_date] << i
|
|
486
|
487
|
}
|
|
487
|
488
|
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 ).each { |i|
|
|
488
|
489
|
@events_by_day[i.created_on.to_date] ||= []
|
|
489
|
490
|
@events_by_day[i.created_on.to_date] << i
|
|
490
|
491
|
}
|
|
491
|
492
|
@show_documents = 1
|
|
492
|
493
|
end
|
|
493
|
494
|
|
|
494
|
495
|
unless params[:show_wiki_edits] == "0"
|
|
495
|
496
|
select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comment, " +
|
|
496
|
497
|
"#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title"
|
|
497
|
498
|
joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " +
|
|
498
|
499
|
"LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id "
|
|
499
|
500
|
conditions = ["#{Wiki.table_name}.project_id = ? AND #{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?",
|
|
500
|
501
|
@project.id, @date_from, @date_to]
|
|
501
|
502
|
|
|
502
|
503
|
WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => conditions).each { |i|
|
|
503
|
504
|
# We provide this alias so all events can be treated in the same manner
|
|
504
|
505
|
def i.created_on
|
|
505
|
506
|
self.updated_on
|
|
506
|
507
|
end
|
|
507
|
508
|
|
|
508
|
509
|
@events_by_day[i.created_on.to_date] ||= []
|
|
509
|
510
|
@events_by_day[i.created_on.to_date] << i
|
|
510
|
511
|
}
|
|
511
|
512
|
@show_wiki_edits = 1
|
|
512
|
513
|
end
|
|
513
|
514
|
|
|
514
|
515
|
unless @project.repository.nil? || params[:show_changesets] == "0"
|
|
515
|
516
|
@project.repository.changesets.find(:all, :conditions => ["#{Changeset.table_name}.committed_on BETWEEN ? AND ?", @date_from, @date_to]).each { |i|
|
|
516
|
517
|
def i.created_on
|
|
517
|
518
|
self.committed_on
|
|
518
|
519
|
end
|
|
519
|
520
|
@events_by_day[i.created_on.to_date] ||= []
|
|
520
|
521
|
@events_by_day[i.created_on.to_date] << i
|
|
521
|
522
|
}
|
|
522
|
523
|
@show_changesets = 1
|
|
523
|
524
|
end
|
|
524
|
525
|
|
|
525
|
526
|
render :layout => false if request.xhr?
|
|
526
|
527
|
end
|
|
527
|
528
|
|
|
528
|
529
|
def calendar
|
|
529
|
530
|
@trackers = Tracker.find(:all, :order => 'position')
|
|
530
|
531
|
retrieve_selected_tracker_ids(@trackers)
|
|
531
|
532
|
|
|
532
|
533
|
if params[:year] and params[:year].to_i > 1900
|
|
533
|
534
|
@year = params[:year].to_i
|
|
534
|
535
|
if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
|
|
535
|
536
|
@month = params[:month].to_i
|
|
536
|
537
|
end
|
|
537
|
538
|
end
|
|
538
|
539
|
@year ||= Date.today.year
|
|
539
|
540
|
@month ||= Date.today.month
|
|
540
|
541
|
|
|
541
|
542
|
@date_from = Date.civil(@year, @month, 1)
|
|
542
|
543
|
@date_to = (@date_from >> 1)-1
|
|
543
|
544
|
# start on monday
|
|
544
|
545
|
@date_from = @date_from - (@date_from.cwday-1)
|
|
545
|
546
|
# finish on sunday
|
|
546
|
547
|
@date_to = @date_to + (7-@date_to.cwday)
|
|
547
|
548
|
|
|
548
|
549
|
@project.issues_with_subprojects(params[:with_subprojects]) do
|
|
549
|
550
|
@issues = Issue.find(:all,
|
|
550
|
551
|
:include => [:tracker, :status, :assigned_to, :priority],
|
|
551
|
552
|
:conditions => ["((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?)) and #{Issue.table_name}.tracker_id in (#{@selected_tracker_ids.join(',')})", @date_from, @date_to, @date_from, @date_to]
|
|
552
|
553
|
) unless @selected_tracker_ids.empty?
|
|
553
|
554
|
end
|
|
554
|
555
|
@issues ||=[]
|
|
555
|
556
|
|
|
556
|
557
|
@ending_issues_by_days = @issues.group_by {|issue| issue.due_date}
|
|
557
|
558
|
@starting_issues_by_days = @issues.group_by {|issue| issue.start_date}
|
|
558
|
559
|
|
|
559
|
560
|
render :layout => false if request.xhr?
|
|
560
|
561
|
end
|
|
561
|
562
|
|
|
562
|
563
|
def gantt
|
|
563
|
564
|
@trackers = Tracker.find(:all, :order => 'position')
|
|
564
|
565
|
retrieve_selected_tracker_ids(@trackers)
|
|
565
|
566
|
|
|
566
|
567
|
if params[:year] and params[:year].to_i >0
|
|
567
|
568
|
@year_from = params[:year].to_i
|
|
568
|
569
|
if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12
|
|
569
|
570
|
@month_from = params[:month].to_i
|
|
570
|
571
|
else
|
|
571
|
572
|
@month_from = 1
|
|
572
|
573
|
end
|
|
573
|
574
|
else
|
|
574
|
575
|
@month_from ||= (Date.today << 1).month
|
|
575
|
576
|
@year_from ||= (Date.today << 1).year
|
|
576
|
577
|
end
|
|
577
|
578
|
|
|
578
|
579
|
@zoom = (params[:zoom].to_i > 0 and params[:zoom].to_i < 5) ? params[:zoom].to_i : 2
|
|
579
|
580
|
@months = (params[:months].to_i > 0 and params[:months].to_i < 25) ? params[:months].to_i : 6
|
|
580
|
581
|
|
|
581
|
582
|
@date_from = Date.civil(@year_from, @month_from, 1)
|
|
582
|
583
|
@date_to = (@date_from >> @months) - 1
|
|
583
|
584
|
|
|
584
|
585
|
@project.issues_with_subprojects(params[:with_subprojects]) do
|
|
585
|
586
|
@issues = Issue.find(:all,
|
|
586
|
587
|
:order => "start_date, due_date",
|
|
587
|
588
|
:include => [:tracker, :status, :assigned_to, :priority],
|
|
588
|
589
|
: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]
|
|
589
|
590
|
) unless @selected_tracker_ids.empty?
|
|
590
|
591
|
end
|
|
591
|
592
|
@issues ||=[]
|
|
592
|
593
|
|
|
593
|
594
|
if params[:output]=='pdf'
|
|
594
|
595
|
@options_for_rfpdf ||= {}
|
|
595
|
596
|
@options_for_rfpdf[:file_name] = "gantt.pdf"
|
|
596
|
597
|
render :template => "projects/gantt.rfpdf", :layout => false
|
|
597
|
598
|
else
|
|
598
|
599
|
render :template => "projects/gantt.rhtml"
|
|
599
|
600
|
end
|
|
600
|
601
|
end
|
|
601
|
602
|
|
|
602
|
603
|
def search
|
|
603
|
604
|
@question = params[:q] || ""
|
|
604
|
605
|
@question.strip!
|
|
605
|
606
|
@all_words = params[:all_words] || (params[:submit] ? false : true)
|
|
606
|
607
|
@scope = params[:scope] || (params[:submit] ? [] : %w(issues changesets news documents wiki) )
|
|
607
|
608
|
# tokens must be at least 3 character long
|
|
608
|
609
|
@tokens = @question.split.uniq.select {|w| w.length > 2 }
|
|
609
|
610
|
if !@tokens.empty?
|
|
610
|
611
|
# no more than 5 tokens to search for
|
|
611
|
612
|
@tokens.slice! 5..-1 if @tokens.size > 5
|
|
612
|
613
|
# strings used in sql like statement
|
|
613
|
614
|
like_tokens = @tokens.collect {|w| "%#{w}%"}
|
|
614
|
615
|
operator = @all_words ? " AND " : " OR "
|
|
615
|
616
|
limit = 10
|
|
616
|
617
|
@results = []
|
|
617
|
618
|
@results += @project.issues.find(:all, :limit => limit, :include => :author, :conditions => [ (["(LOWER(subject) like ? OR LOWER(description) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort] ) if @scope.include? 'issues'
|
|
618
|
619
|
@results += @project.news.find(:all, :limit => limit, :conditions => [ (["(LOWER(title) like ? OR LOWER(description) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort], :include => :author ) if @scope.include? 'news'
|
|
619
|
620
|
@results += @project.documents.find(:all, :limit => limit, :conditions => [ (["(LOWER(title) like ? OR LOWER(description) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort] ) if @scope.include? 'documents'
|
|
620
|
621
|
@results += @project.wiki.pages.find(:all, :limit => limit, :include => :content, :conditions => [ (["(LOWER(title) like ? OR LOWER(text) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort] ) if @project.wiki && @scope.include?('wiki')
|
|
621
|
622
|
@results += @project.repository.changesets.find(:all, :limit => limit, :conditions => [ (["(LOWER(comment) like ?)"] * like_tokens.size).join(operator), * (like_tokens).sort] ) if @project.repository && @scope.include?('changesets')
|
|
622
|
623
|
@question = @tokens.join(" ")
|
|
623
|
624
|
else
|
|
624
|
625
|
@question = ""
|
|
625
|
626
|
end
|
|
626
|
627
|
end
|
|
627
|
628
|
|
|
628
|
629
|
def feeds
|
|
629
|
630
|
@queries = @project.queries.find :all, :conditions => ["is_public=? or user_id=?", true, (logged_in_user ? logged_in_user.id : 0)]
|
|
630
|
631
|
@key = logged_in_user.get_or_create_rss_key.value if logged_in_user
|
|
631
|
632
|
end
|
|
632
|
633
|
|
|
633
|
634
|
private
|
|
634
|
635
|
# Find project of id params[:id]
|
|
635
|
636
|
# if not found, redirect to project list
|
|
636
|
637
|
# Used as a before_filter
|
|
637
|
638
|
def find_project
|
|
638
|
639
|
@project = Project.find(params[:id])
|
|
639
|
640
|
@html_title = @project.name
|
|
640
|
641
|
rescue ActiveRecord::RecordNotFound
|
|
641
|
642
|
render_404
|
|
642
|
643
|
end
|
|
643
|
644
|
|
|
644
|
645
|
def retrieve_selected_tracker_ids(selectable_trackers)
|
|
645
|
646
|
if ids = params[:tracker_ids]
|
|
646
|
647
|
@selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
|
|
647
|
648
|
else
|
|
648
|
649
|
@selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s }
|
|
649
|
650
|
end
|
|
650
|
651
|
end
|
|
651
|
652
|
|
|
652
|
653
|
# Retrieve query from session or build a new query
|
|
653
|
654
|
def retrieve_query
|
|
654
|
655
|
if params[:query_id]
|
|
655
|
656
|
@query = @project.queries.find(params[:query_id])
|
|
656
|
657
|
session[:query] = @query
|
|
657
|
658
|
else
|
|
658
|
659
|
if params[:set_filter] or !session[:query] or session[:query].project_id != @project.id
|
|
659
|
660
|
# Give it a name, required to be valid
|
|
660
|
661
|
@query = Query.new(:name => "_")
|
|
661
|
662
|
@query.project = @project
|
|
662
|
663
|
if params[:fields] and params[:fields].is_a? Array
|
|
663
|
664
|
params[:fields].each do |field|
|
|
664
|
665
|
@query.add_filter(field, params[:operators][field], params[:values][field])
|
|
665
|
666
|
end
|
|
666
|
667
|
else
|
|
667
|
668
|
@query.available_filters.keys.each do |field|
|
|
668
|
669
|
@query.add_short_filter(field, params[field]) if params[field]
|
|
669
|
670
|
end
|
|
670
|
671
|
end
|
|
671
|
672
|
session[:query] = @query
|
|
672
|
673
|
else
|
|
673
|
674
|
@query = session[:query]
|
|
674
|
675
|
end
|
|
675
|
676
|
end
|
|
676
|
677
|
end
|
|
677
|
678
|
end
|