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