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