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