##// END OF EJS Templates
Added the ability to move issues (to another project) without changing their trackers....
Jean-Philippe Lang -
r676:1281d99f3057
parent child
Show More
@@ -1,672 +1,673
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 IssuesHelper
38 38 helper :queries
39 39 include QueriesHelper
40 40 helper :repositories
41 41 include RepositoriesHelper
42 42 include ProjectsHelper
43 43
44 44 def index
45 45 list
46 46 render :action => 'list' unless request.xhr?
47 47 end
48 48
49 49 # Lists public projects
50 50 def list
51 51 sort_init "#{Project.table_name}.name", "asc"
52 52 sort_update
53 53 @project_count = Project.count(:all, :conditions => Project.visible_by(logged_in_user))
54 54 @project_pages = Paginator.new self, @project_count,
55 55 15,
56 56 params['page']
57 57 @projects = Project.find :all, :order => sort_clause,
58 58 :conditions => Project.visible_by(logged_in_user),
59 59 :include => :parent,
60 60 :limit => @project_pages.items_per_page,
61 61 :offset => @project_pages.current.offset
62 62
63 63 render :action => "list", :layout => false if request.xhr?
64 64 end
65 65
66 66 # Add a new project
67 67 def add
68 68 @custom_fields = IssueCustomField.find(:all)
69 69 @root_projects = Project.find(:all, :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}")
70 70 @project = Project.new(params[:project])
71 71 if request.get?
72 72 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project) }
73 73 else
74 74 @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
75 75 @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)) }
76 76 @project.custom_values = @custom_values
77 77 if params[:repository_enabled] && params[:repository_enabled] == "1"
78 78 @project.repository = Repository.factory(params[:repository_scm])
79 79 @project.repository.attributes = params[:repository]
80 80 end
81 81 if "1" == params[:wiki_enabled]
82 82 @project.wiki = Wiki.new
83 83 @project.wiki.attributes = params[:wiki]
84 84 end
85 85 if @project.save
86 86 flash[:notice] = l(:notice_successful_create)
87 87 redirect_to :controller => 'admin', :action => 'projects'
88 88 end
89 89 end
90 90 end
91 91
92 92 # Show @project
93 93 def show
94 94 @custom_values = @project.custom_values.find(:all, :include => :custom_field)
95 95 @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role}
96 96 @subprojects = @project.active_children
97 97 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
98 98 @trackers = Tracker.find(:all, :order => 'position')
99 99 @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])
100 100 @total_issues_by_tracker = Issue.count(:group => :tracker, :conditions => ["project_id=?", @project.id])
101 101 @key = User.current.rss_key
102 102 end
103 103
104 104 def settings
105 105 @root_projects = Project::find(:all, :conditions => ["parent_id IS NULL AND status = #{Project::STATUS_ACTIVE} AND id <> ?", @project.id])
106 106 @custom_fields = IssueCustomField.find(:all)
107 107 @issue_category ||= IssueCategory.new
108 108 @member ||= @project.members.new
109 109 @custom_values ||= ProjectCustomField.find(:all).collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
110 110 end
111 111
112 112 # Edit @project
113 113 def edit
114 114 if request.post?
115 115 @project.custom_fields = IssueCustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
116 116 if params[:custom_fields]
117 117 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
118 118 @project.custom_values = @custom_values
119 119 end
120 120 if params[:repository_enabled]
121 121 case params[:repository_enabled]
122 122 when "0"
123 123 @project.repository = nil
124 124 when "1"
125 125 @project.repository ||= Repository.factory(params[:repository_scm])
126 126 @project.repository.update_attributes params[:repository] if @project.repository
127 127 end
128 128 end
129 129 if params[:wiki_enabled]
130 130 case params[:wiki_enabled]
131 131 when "0"
132 132 @project.wiki.destroy if @project.wiki
133 133 when "1"
134 134 @project.wiki ||= Wiki.new
135 135 @project.wiki.update_attributes params[:wiki]
136 136 end
137 137 end
138 138 @project.attributes = params[:project]
139 139 if @project.save
140 140 flash[:notice] = l(:notice_successful_update)
141 141 redirect_to :action => 'settings', :id => @project
142 142 else
143 143 settings
144 144 render :action => 'settings'
145 145 end
146 146 end
147 147 end
148 148
149 149 def archive
150 150 @project.archive if request.post? && @project.active?
151 151 redirect_to :controller => 'admin', :action => 'projects'
152 152 end
153 153
154 154 def unarchive
155 155 @project.unarchive if request.post? && !@project.active?
156 156 redirect_to :controller => 'admin', :action => 'projects'
157 157 end
158 158
159 159 # Delete @project
160 160 def destroy
161 161 @project_to_destroy = @project
162 162 if request.post? and params[:confirm]
163 163 @project_to_destroy.destroy
164 164 redirect_to :controller => 'admin', :action => 'projects'
165 165 end
166 166 # hide project in layout
167 167 @project = nil
168 168 end
169 169
170 170 # Add a new issue category to @project
171 171 def add_issue_category
172 172 @category = @project.issue_categories.build(params[:category])
173 173 if request.post? and @category.save
174 174 respond_to do |format|
175 175 format.html do
176 176 flash[:notice] = l(:notice_successful_create)
177 177 redirect_to :action => 'settings', :tab => 'categories', :id => @project
178 178 end
179 179 format.js do
180 180 # IE doesn't support the replace_html rjs method for select box options
181 181 render(:update) {|page| page.replace "issue_category_id",
182 182 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]')
183 183 }
184 184 end
185 185 end
186 186 end
187 187 end
188 188
189 189 # Add a new version to @project
190 190 def add_version
191 191 @version = @project.versions.build(params[:version])
192 192 if request.post? and @version.save
193 193 flash[:notice] = l(:notice_successful_create)
194 194 redirect_to :action => 'settings', :tab => 'versions', :id => @project
195 195 end
196 196 end
197 197
198 198 # Add a new member to @project
199 199 def add_member
200 200 @member = @project.members.build(params[:member])
201 201 if request.post? && @member.save
202 202 respond_to do |format|
203 203 format.html { redirect_to :action => 'settings', :tab => 'members', :id => @project }
204 204 format.js { render(:update) {|page| page.replace_html "tab-content-members", :partial => 'members'} }
205 205 end
206 206 else
207 207 settings
208 208 render :action => 'settings'
209 209 end
210 210 end
211 211
212 212 # Show members list of @project
213 213 def list_members
214 214 @members = @project.members.find(:all)
215 215 end
216 216
217 217 # Add a new document to @project
218 218 def add_document
219 219 @categories = Enumeration::get_values('DCAT')
220 220 @document = @project.documents.build(params[:document])
221 221 if request.post? and @document.save
222 222 # Save the attachments
223 223 params[:attachments].each { |a|
224 224 Attachment.create(:container => @document, :file => a, :author => logged_in_user) unless a.size == 0
225 225 } if params[:attachments] and params[:attachments].is_a? Array
226 226 flash[:notice] = l(:notice_successful_create)
227 227 Mailer.deliver_document_add(@document) #if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
228 228 redirect_to :action => 'list_documents', :id => @project
229 229 end
230 230 end
231 231
232 232 # Show documents list of @project
233 233 def list_documents
234 234 @documents = @project.documents.find :all, :include => :category
235 235 end
236 236
237 237 # Add a new issue to @project
238 238 def add_issue
239 239 @tracker = Tracker.find(params[:tracker_id])
240 240 @priorities = Enumeration::get_values('IPRI')
241 241
242 242 default_status = IssueStatus.default
243 243 unless default_status
244 244 flash.now[:error] = 'No default issue status defined. Please check your configuration.'
245 245 render :nothing => true, :layout => true
246 246 return
247 247 end
248 248 @issue = Issue.new(:project => @project, :tracker => @tracker)
249 249 @issue.status = default_status
250 250 @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(logged_in_user.role_for_project(@project), @issue.tracker))if logged_in_user
251 251 if request.get?
252 252 @issue.start_date = Date.today
253 253 @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) }
254 254 else
255 255 @issue.attributes = params[:issue]
256 256
257 257 requested_status = IssueStatus.find_by_id(params[:issue][:status_id])
258 258 @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status
259 259
260 260 @issue.author_id = self.logged_in_user.id if self.logged_in_user
261 261 # Multiple file upload
262 262 @attachments = []
263 263 params[:attachments].each { |a|
264 264 @attachments << Attachment.new(:container => @issue, :file => a, :author => logged_in_user) unless a.size == 0
265 265 } if params[:attachments] and params[:attachments].is_a? Array
266 266 @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]) }
267 267 @issue.custom_values = @custom_values
268 268 if @issue.save
269 269 @attachments.each(&:save)
270 270 flash[:notice] = l(:notice_successful_create)
271 271 Mailer.deliver_issue_add(@issue) #if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
272 272 redirect_to :action => 'list_issues', :id => @project
273 273 end
274 274 end
275 275 end
276 276
277 277 # Show filtered/sorted issues list of @project
278 278 def list_issues
279 279 sort_init "#{Issue.table_name}.id", "desc"
280 280 sort_update
281 281
282 282 retrieve_query
283 283
284 284 @results_per_page_options = [ 15, 25, 50, 100 ]
285 285 if params[:per_page] and @results_per_page_options.include? params[:per_page].to_i
286 286 @results_per_page = params[:per_page].to_i
287 287 session[:results_per_page] = @results_per_page
288 288 else
289 289 @results_per_page = session[:results_per_page] || 25
290 290 end
291 291
292 292 if @query.valid?
293 293 @issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement)
294 294 @issue_pages = Paginator.new self, @issue_count, @results_per_page, params['page']
295 295 @issues = Issue.find :all, :order => sort_clause,
296 296 :include => [ :assigned_to, :status, :tracker, :project, :priority ],
297 297 :conditions => @query.statement,
298 298 :limit => @issue_pages.items_per_page,
299 299 :offset => @issue_pages.current.offset
300 300 end
301 301 render :layout => false if request.xhr?
302 302 end
303 303
304 304 # Export filtered/sorted issues list to CSV
305 305 def export_issues_csv
306 306 sort_init "#{Issue.table_name}.id", "desc"
307 307 sort_update
308 308
309 309 retrieve_query
310 310 render :action => 'list_issues' and return unless @query.valid?
311 311
312 312 @issues = Issue.find :all, :order => sort_clause,
313 313 :include => [ :assigned_to, :author, :status, :tracker, :priority, :project, {:custom_values => :custom_field} ],
314 314 :conditions => @query.statement,
315 315 :limit => Setting.issues_export_limit.to_i
316 316
317 317 ic = Iconv.new(l(:general_csv_encoding), 'UTF-8')
318 318 export = StringIO.new
319 319 CSV::Writer.generate(export, l(:general_csv_separator)) do |csv|
320 320 # csv header fields
321 321 headers = [ "#", l(:field_status),
322 322 l(:field_project),
323 323 l(:field_tracker),
324 324 l(:field_priority),
325 325 l(:field_subject),
326 326 l(:field_assigned_to),
327 327 l(:field_author),
328 328 l(:field_start_date),
329 329 l(:field_due_date),
330 330 l(:field_done_ratio),
331 331 l(:field_created_on),
332 332 l(:field_updated_on)
333 333 ]
334 334 for custom_field in @project.all_custom_fields
335 335 headers << custom_field.name
336 336 end
337 337 csv << headers.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
338 338 # csv lines
339 339 @issues.each do |issue|
340 340 fields = [issue.id, issue.status.name,
341 341 issue.project.name,
342 342 issue.tracker.name,
343 343 issue.priority.name,
344 344 issue.subject,
345 345 (issue.assigned_to ? issue.assigned_to.name : ""),
346 346 issue.author.name,
347 347 issue.start_date ? l_date(issue.start_date) : nil,
348 348 issue.due_date ? l_date(issue.due_date) : nil,
349 349 issue.done_ratio,
350 350 l_datetime(issue.created_on),
351 351 l_datetime(issue.updated_on)
352 352 ]
353 353 for custom_field in @project.all_custom_fields
354 354 fields << (show_value issue.custom_value_for(custom_field))
355 355 end
356 356 csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
357 357 end
358 358 end
359 359 export.rewind
360 360 send_data(export.read, :type => 'text/csv; header=present', :filename => 'export.csv')
361 361 end
362 362
363 363 # Export filtered/sorted issues to PDF
364 364 def export_issues_pdf
365 365 sort_init "#{Issue.table_name}.id", "desc"
366 366 sort_update
367 367
368 368 retrieve_query
369 369 render :action => 'list_issues' and return unless @query.valid?
370 370
371 371 @issues = Issue.find :all, :order => sort_clause,
372 372 :include => [ :author, :status, :tracker, :priority, :project ],
373 373 :conditions => @query.statement,
374 374 :limit => Setting.issues_export_limit.to_i
375 375
376 376 @options_for_rfpdf ||= {}
377 377 @options_for_rfpdf[:file_name] = "export.pdf"
378 378 render :layout => false
379 379 end
380 380
381 381 def move_issues
382 382 @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids]
383 383 redirect_to :action => 'list_issues', :id => @project and return unless @issues
384 384 @projects = []
385 385 # find projects to which the user is allowed to move the issue
386 386 User.current.memberships.each {|m| @projects << m.project if m.role.allowed_to?(:controller => 'projects', :action => 'move_issues')}
387 387 # issue can be moved to any tracker
388 388 @trackers = Tracker.find(:all)
389 389 if request.post? and params[:new_project_id] and params[:new_tracker_id]
390 new_project = Project.find(params[:new_project_id])
391 new_tracker = Tracker.find(params[:new_tracker_id])
392 @issues.each { |i|
393 # project dependent properties
394 unless i.project_id == new_project.id
390 new_project = Project.find_by_id(params[:new_project_id])
391 new_tracker = Tracker.find_by_id(params[:new_tracker_id])
392 @issues.each do |i|
393 if new_project && i.project_id != new_project.id
394 # issue is moved to another project
395 395 i.category = nil
396 396 i.fixed_version = nil
397 397 # delete issue relations
398 398 i.relations_from.clear
399 399 i.relations_to.clear
400 end
401 # move the issue
402 400 i.project = new_project
401 end
402 if new_tracker
403 403 i.tracker = new_tracker
404 end
404 405 i.save
405 }
406 end
406 407 flash[:notice] = l(:notice_successful_update)
407 408 redirect_to :action => 'list_issues', :id => @project
408 409 end
409 410 end
410 411
411 412 # Add a news to @project
412 413 def add_news
413 414 @news = News.new(:project => @project)
414 415 if request.post?
415 416 @news.attributes = params[:news]
416 417 @news.author_id = self.logged_in_user.id if self.logged_in_user
417 418 if @news.save
418 419 flash[:notice] = l(:notice_successful_create)
419 420 redirect_to :action => 'list_news', :id => @project
420 421 end
421 422 end
422 423 end
423 424
424 425 # Show news list of @project
425 426 def list_news
426 427 @news_pages, @news = paginate :news, :per_page => 10, :conditions => ["project_id=?", @project.id], :include => :author, :order => "#{News.table_name}.created_on DESC"
427 428
428 429 respond_to do |format|
429 430 format.html { render :layout => false if request.xhr? }
430 431 format.atom { render_feed(@news, :title => "#{@project.name}: #{l(:label_news_plural)}") }
431 432 end
432 433 end
433 434
434 435 def add_file
435 436 if request.post?
436 437 @version = @project.versions.find_by_id(params[:version_id])
437 438 # Save the attachments
438 439 @attachments = []
439 440 params[:attachments].each { |file|
440 441 next unless file.size > 0
441 442 a = Attachment.create(:container => @version, :file => file, :author => logged_in_user)
442 443 @attachments << a unless a.new_record?
443 444 } if params[:attachments] and params[:attachments].is_a? Array
444 445 Mailer.deliver_attachments_add(@attachments) if !@attachments.empty? #and Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
445 446 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
446 447 end
447 448 @versions = @project.versions.sort
448 449 end
449 450
450 451 def list_files
451 452 @versions = @project.versions.sort
452 453 end
453 454
454 455 # Show changelog for @project
455 456 def changelog
456 457 @trackers = Tracker.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position')
457 458 retrieve_selected_tracker_ids(@trackers)
458 459 @versions = @project.versions.sort
459 460 end
460 461
461 462 def roadmap
462 463 @trackers = Tracker.find(:all, :conditions => ["is_in_roadmap=?", true], :order => 'position')
463 464 retrieve_selected_tracker_ids(@trackers)
464 465 @versions = @project.versions.sort
465 466 @versions = @versions.select {|v| !v.completed? } unless params[:completed]
466 467 end
467 468
468 469 def activity
469 470 if params[:year] and params[:year].to_i > 1900
470 471 @year = params[:year].to_i
471 472 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
472 473 @month = params[:month].to_i
473 474 end
474 475 end
475 476 @year ||= Date.today.year
476 477 @month ||= Date.today.month
477 478
478 479 case params[:format]
479 480 when 'rss'
480 481 # 30 last days
481 482 @date_from = Date.today - 30
482 483 @date_to = Date.today + 1
483 484 else
484 485 # current month
485 486 @date_from = Date.civil(@year, @month, 1)
486 487 @date_to = @date_from >> 1
487 488 end
488 489
489 490 @event_types = %w(issues news attachments documents wiki_edits revisions)
490 491 @event_types.delete('wiki_edits') unless @project.wiki
491 492 @event_types.delete('changesets') unless @project.repository
492 493
493 494 @scope = @event_types.select {|t| params["show_#{t}"]}
494 495 # default events if none is specified in parameters
495 496 @scope = (@event_types - %w(wiki_edits))if @scope.empty?
496 497
497 498 @events = []
498 499
499 500 if @scope.include?('issues')
500 501 @events += @project.issues.find(:all, :include => [:author, :tracker], :conditions => ["#{Issue.table_name}.created_on>=? and #{Issue.table_name}.created_on<=?", @date_from, @date_to] )
501 502 end
502 503
503 504 if @scope.include?('news')
504 505 @events += @project.news.find(:all, :conditions => ["#{News.table_name}.created_on>=? and #{News.table_name}.created_on<=?", @date_from, @date_to], :include => :author )
505 506 end
506 507
507 508 if @scope.include?('attachments')
508 509 @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 )
509 510 end
510 511
511 512 if @scope.include?('documents')
512 513 @events += @project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on>=? and #{Document.table_name}.created_on<=?", @date_from, @date_to] )
513 514 @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 )
514 515 end
515 516
516 517 if @scope.include?('wiki_edits') && @project.wiki
517 518 select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " +
518 519 "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title, " +
519 520 "#{WikiContent.versioned_table_name}.page_id, #{WikiContent.versioned_table_name}.author_id, " +
520 521 "#{WikiContent.versioned_table_name}.id"
521 522 joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " +
522 523 "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id "
523 524 conditions = ["#{Wiki.table_name}.project_id = ? AND #{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?",
524 525 @project.id, @date_from, @date_to]
525 526
526 527 @events += WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => conditions)
527 528 end
528 529
529 530 if @scope.include?('revisions') && @project.repository
530 531 @events += @project.repository.changesets.find(:all, :conditions => ["#{Changeset.table_name}.committed_on BETWEEN ? AND ?", @date_from, @date_to])
531 532 end
532 533
533 534 @events_by_day = @events.group_by(&:event_date)
534 535
535 536 respond_to do |format|
536 537 format.html { render :layout => false if request.xhr? }
537 538 format.atom { render_feed(@events, :title => "#{@project.name}: #{l(:label_activity)}") }
538 539 end
539 540 end
540 541
541 542 def calendar
542 543 @trackers = Tracker.find(:all, :order => 'position')
543 544 retrieve_selected_tracker_ids(@trackers)
544 545
545 546 if params[:year] and params[:year].to_i > 1900
546 547 @year = params[:year].to_i
547 548 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
548 549 @month = params[:month].to_i
549 550 end
550 551 end
551 552 @year ||= Date.today.year
552 553 @month ||= Date.today.month
553 554
554 555 @date_from = Date.civil(@year, @month, 1)
555 556 @date_to = (@date_from >> 1)-1
556 557 # start on monday
557 558 @date_from = @date_from - (@date_from.cwday-1)
558 559 # finish on sunday
559 560 @date_to = @date_to + (7-@date_to.cwday)
560 561
561 562 @events = []
562 563 @project.issues_with_subprojects(params[:with_subprojects]) do
563 564 @events += Issue.find(:all,
564 565 :include => [:tracker, :status, :assigned_to, :priority, :project],
565 566 :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]
566 567 ) unless @selected_tracker_ids.empty?
567 568 end
568 569 @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to])
569 570
570 571 @ending_events_by_days = @events.group_by {|event| event.due_date}
571 572 @starting_events_by_days = @events.group_by {|event| event.start_date}
572 573
573 574 render :layout => false if request.xhr?
574 575 end
575 576
576 577 def gantt
577 578 @trackers = Tracker.find(:all, :order => 'position')
578 579 retrieve_selected_tracker_ids(@trackers)
579 580
580 581 if params[:year] and params[:year].to_i >0
581 582 @year_from = params[:year].to_i
582 583 if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12
583 584 @month_from = params[:month].to_i
584 585 else
585 586 @month_from = 1
586 587 end
587 588 else
588 589 @month_from ||= (Date.today << 1).month
589 590 @year_from ||= (Date.today << 1).year
590 591 end
591 592
592 593 @zoom = (params[:zoom].to_i > 0 and params[:zoom].to_i < 5) ? params[:zoom].to_i : 2
593 594 @months = (params[:months].to_i > 0 and params[:months].to_i < 25) ? params[:months].to_i : 6
594 595
595 596 @date_from = Date.civil(@year_from, @month_from, 1)
596 597 @date_to = (@date_from >> @months) - 1
597 598
598 599 @events = []
599 600 @project.issues_with_subprojects(params[:with_subprojects]) do
600 601 @events += Issue.find(:all,
601 602 :order => "start_date, due_date",
602 603 :include => [:tracker, :status, :assigned_to, :priority, :project],
603 604 :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]
604 605 ) unless @selected_tracker_ids.empty?
605 606 end
606 607 @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to])
607 608 @events.sort! {|x,y| x.start_date <=> y.start_date }
608 609
609 610 if params[:format]=='pdf'
610 611 @options_for_rfpdf ||= {}
611 612 @options_for_rfpdf[:file_name] = "#{@project.identifier}-gantt.pdf"
612 613 render :template => "projects/gantt.rfpdf", :layout => false
613 614 elsif params[:format]=='png' && respond_to?('gantt_image')
614 615 image = gantt_image(@events, @date_from, @months, @zoom)
615 616 image.format = 'PNG'
616 617 send_data(image.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "#{@project.identifier}-gantt.png")
617 618 else
618 619 render :template => "projects/gantt.rhtml"
619 620 end
620 621 end
621 622
622 623 def feeds
623 624 @queries = @project.queries.find :all, :conditions => ["is_public=? or user_id=?", true, (logged_in_user ? logged_in_user.id : 0)]
624 625 @key = User.current.rss_key
625 626 end
626 627
627 628 private
628 629 # Find project of id params[:id]
629 630 # if not found, redirect to project list
630 631 # Used as a before_filter
631 632 def find_project
632 633 @project = Project.find(params[:id])
633 634 @html_title = @project.name
634 635 rescue ActiveRecord::RecordNotFound
635 636 render_404
636 637 end
637 638
638 639 def retrieve_selected_tracker_ids(selectable_trackers)
639 640 if ids = params[:tracker_ids]
640 641 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
641 642 else
642 643 @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s }
643 644 end
644 645 end
645 646
646 647 # Retrieve query from session or build a new query
647 648 def retrieve_query
648 649 if params[:query_id]
649 650 @query = @project.queries.find(params[:query_id])
650 651 @query.executed_by = logged_in_user
651 652 session[:query] = @query
652 653 else
653 654 if params[:set_filter] or !session[:query] or session[:query].project_id != @project.id
654 655 # Give it a name, required to be valid
655 656 @query = Query.new(:name => "_", :executed_by => logged_in_user)
656 657 @query.project = @project
657 658 if params[:fields] and params[:fields].is_a? Array
658 659 params[:fields].each do |field|
659 660 @query.add_filter(field, params[:operators][field], params[:values][field])
660 661 end
661 662 else
662 663 @query.available_filters.keys.each do |field|
663 664 @query.add_short_filter(field, params[field]) if params[field]
664 665 end
665 666 end
666 667 session[:query] = @query
667 668 else
668 669 @query = session[:query]
669 670 end
670 671 end
671 672 end
672 673 end
@@ -1,124 +1,125
1 1 # redMine - project management software
2 2 # Copyright (C) 2006 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 class Project < ActiveRecord::Base
19 19 # Project statuses
20 20 STATUS_ACTIVE = 1
21 21 STATUS_ARCHIVED = 9
22 22
23 23 has_many :members, :dependent => :delete_all, :include => :user, :conditions => "#{User.table_name}.status=#{User::STATUS_ACTIVE}"
24 24 has_many :users, :through => :members
25 25 has_many :custom_values, :dependent => :delete_all, :as => :customized
26 26 has_many :issues, :dependent => :destroy, :order => "#{Issue.table_name}.created_on DESC", :include => [:status, :tracker]
27 27 has_many :issue_changes, :through => :issues, :source => :journals
28 28 has_many :versions, :dependent => :destroy, :order => "#{Version.table_name}.effective_date DESC, #{Version.table_name}.name DESC"
29 29 has_many :time_entries, :dependent => :delete_all
30 30 has_many :queries, :dependent => :delete_all
31 31 has_many :documents, :dependent => :destroy
32 32 has_many :news, :dependent => :delete_all, :include => :author
33 33 has_many :issue_categories, :dependent => :delete_all, :order => "#{IssueCategory.table_name}.name"
34 34 has_many :boards, :order => "position ASC"
35 35 has_one :repository, :dependent => :destroy
36 36 has_one :wiki, :dependent => :destroy
37 37 has_and_belongs_to_many :custom_fields, :class_name => 'IssueCustomField', :join_table => "#{table_name_prefix}custom_fields_projects#{table_name_suffix}", :association_foreign_key => 'custom_field_id'
38 38 acts_as_tree :order => "name", :counter_cache => true
39 39
40 40 attr_protected :status
41 41
42 42 validates_presence_of :name, :description, :identifier
43 43 validates_uniqueness_of :name, :identifier
44 44 validates_associated :custom_values, :on => :update
45 45 validates_associated :repository, :wiki
46 46 validates_length_of :name, :maximum => 30
47 47 validates_format_of :name, :with => /^[\w\s\'\-]*$/i
48 48 validates_length_of :description, :maximum => 255
49 validates_length_of :homepage, :maximum => 30
49 50 validates_length_of :identifier, :in => 3..12
50 51 validates_format_of :identifier, :with => /^[a-z0-9\-]*$/
51 52
52 53 def identifier=(identifier)
53 54 super unless identifier_frozen?
54 55 end
55 56
56 57 def identifier_frozen?
57 58 errors[:identifier].nil? && !(new_record? || identifier.blank?)
58 59 end
59 60
60 61 def issues_with_subprojects(include_subprojects=false)
61 62 conditions = nil
62 63 if include_subprojects && !active_children.empty?
63 64 ids = [id] + active_children.collect {|c| c.id}
64 65 conditions = ["#{Issue.table_name}.project_id IN (#{ids.join(',')})"]
65 66 end
66 67 conditions ||= ["#{Issue.table_name}.project_id = ?", id]
67 68 Issue.with_scope :find => { :conditions => conditions } do
68 69 yield
69 70 end
70 71 end
71 72
72 73 # returns latest created projects
73 74 # non public projects will be returned only if user is a member of those
74 75 def self.latest(user=nil, count=5)
75 76 find(:all, :limit => count, :conditions => visible_by(user), :order => "created_on DESC")
76 77 end
77 78
78 79 def self.visible_by(user=nil)
79 80 if user && user.admin?
80 81 return "#{Project.table_name}.status=#{Project::STATUS_ACTIVE}"
81 82 elsif user && user.memberships.any?
82 83 return "#{Project.table_name}.status=#{Project::STATUS_ACTIVE} AND (#{Project.table_name}.is_public = #{connection.quoted_true} or #{Project.table_name}.id IN (#{user.memberships.collect{|m| m.project_id}.join(',')}))"
83 84 else
84 85 return "#{Project.table_name}.status=#{Project::STATUS_ACTIVE} AND #{Project.table_name}.is_public = #{connection.quoted_true}"
85 86 end
86 87 end
87 88
88 89 def active?
89 90 self.status == STATUS_ACTIVE
90 91 end
91 92
92 93 def archive
93 94 # Archive subprojects if any
94 95 children.each do |subproject|
95 96 subproject.archive
96 97 end
97 98 update_attribute :status, STATUS_ARCHIVED
98 99 end
99 100
100 101 def unarchive
101 102 return false if parent && !parent.active?
102 103 update_attribute :status, STATUS_ACTIVE
103 104 end
104 105
105 106 def active_children
106 107 children.select {|child| child.active?}
107 108 end
108 109
109 110 # Returns an array of all custom fields enabled for project issues
110 111 # (explictly associated custom fields and custom fields enabled for all projects)
111 112 def custom_fields_for_issues(tracker)
112 113 all_custom_fields.select {|c| tracker.custom_fields.include? c }
113 114 end
114 115
115 116 def all_custom_fields
116 117 @all_custom_fields ||= (IssueCustomField.for_all + custom_fields).uniq
117 118 end
118 119
119 120 protected
120 121 def validate
121 122 errors.add(parent_id, " must be a root project") if parent and parent.parent
122 123 errors.add_to_base("A project with subprojects can't be a subproject") if parent and children.size > 0
123 124 end
124 125 end
@@ -1,24 +1,24
1 1 <h2><%=l(:button_move)%></h2>
2 2
3 3
4 4 <% form_tag({:action => 'move_issues', :id => @project}, :class => "tabular") do %>
5 5
6 6 <div class="box">
7 7 <p><label><%= l(:label_issue_plural) %>:</label>
8 8 <% for issue in @issues %>
9 9 <%= link_to_issue issue %>: <%=h issue.subject %>
10 10 <%= hidden_field_tag "issue_ids[]", issue.id %><br />
11 11 <% end %>
12 12 <i>(<%= @issues.length%> <%= lwr(:label_issue, @issues.length)%>)</i></p>
13 13
14 14 &nbsp;
15 15
16 16 <!--[form:issue]-->
17 <p><label for="new_project_id"><%=l(:field_project)%></label>
17 <p><label for="new_project_id"><%=l(:field_project)%> :</label>
18 18 <%= select_tag "new_project_id", options_from_collection_for_select(@projects, "id", "name", @project.id) %></p>
19 19
20 <p><label for="new_tracker_id"><%=l(:field_tracker)%></label>
21 <%= select_tag "new_tracker_id", options_from_collection_for_select(@trackers, "id", "name") %></p>
20 <p><label for="new_tracker_id"><%=l(:field_tracker)%> :</label>
21 <%= select_tag "new_tracker_id", '<option></option>' + options_from_collection_for_select(@trackers, "id", "name") %></p>
22 22 </div>
23 23 <%= submit_tag l(:button_move) %>
24 24 <% end %>
General Comments 0
You need to be logged in to leave comments. Login now