comparison app/controllers/issues_controller.rb @ 1298:4f746d8966dd redmine_2.3_integration

Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author Chris Cannam
date Fri, 14 Jun 2013 09:28:30 +0100
parents 7c3de6c7b7f5 622f24f53b42
children
comparison
equal deleted inserted replaced
1297:0a574315af3e 1298:4f746d8966dd
1 # Redmine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang 2 # Copyright (C) 2006-2013 Jean-Philippe Lang
3 # 3 #
4 # This program is free software; you can redistribute it and/or 4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License 5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2 6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version. 7 # of the License, or (at your option) any later version.
19 menu_item :new_issue, :only => [:new, :create] 19 menu_item :new_issue, :only => [:new, :create]
20 default_search_scope :issues 20 default_search_scope :issues
21 21
22 before_filter :find_issue, :only => [:show, :edit, :update] 22 before_filter :find_issue, :only => [:show, :edit, :update]
23 before_filter :find_issues, :only => [:bulk_edit, :bulk_update, :destroy] 23 before_filter :find_issues, :only => [:bulk_edit, :bulk_update, :destroy]
24 before_filter :find_project, :only => [:new, :create] 24 before_filter :find_project, :only => [:new, :create, :update_form]
25 before_filter :authorize, :except => [:index] 25 before_filter :authorize, :except => [:index]
26 before_filter :find_optional_project, :only => [:index] 26 before_filter :find_optional_project, :only => [:index]
27 before_filter :check_for_default_issue_status, :only => [:new, :create] 27 before_filter :check_for_default_issue_status, :only => [:new, :create]
28 before_filter :build_new_issue_from_params, :only => [:new, :create] 28 before_filter :build_new_issue_from_params, :only => [:new, :create, :update_form]
29 accept_rss_auth :index, :show 29 accept_rss_auth :index, :show
30 accept_api_auth :index, :show, :create, :update, :destroy 30 accept_api_auth :index, :show, :create, :update, :destroy
31 31
32 rescue_from Query::StatementInvalid, :with => :query_statement_invalid 32 rescue_from Query::StatementInvalid, :with => :query_statement_invalid
33 33
69 else 69 else
70 @limit = per_page_option 70 @limit = per_page_option
71 end 71 end
72 72
73 @issue_count = @query.issue_count 73 @issue_count = @query.issue_count
74 @issue_pages = Paginator.new self, @issue_count, @limit, params['page'] 74 @issue_pages = Paginator.new @issue_count, @limit, params['page']
75 @offset ||= @issue_pages.current.offset 75 @offset ||= @issue_pages.offset
76 @issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version], 76 @issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version],
77 :order => sort_clause, 77 :order => sort_clause,
78 :offset => @offset, 78 :offset => @offset,
79 :limit => @limit) 79 :limit => @limit)
80 @issue_count_by_group = @query.issue_count_by_group 80 @issue_count_by_group = @query.issue_count_by_group
83 format.html { render :template => 'issues/index', :layout => !request.xhr? } 83 format.html { render :template => 'issues/index', :layout => !request.xhr? }
84 format.api { 84 format.api {
85 Issue.load_visible_relations(@issues) if include_in_api_response?('relations') 85 Issue.load_visible_relations(@issues) if include_in_api_response?('relations')
86 } 86 }
87 format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") } 87 format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") }
88 format.csv { send_data(issues_to_csv(@issues, @project, @query, params), :type => 'text/csv; header=present', :filename => 'export.csv') } 88 format.csv { send_data(query_to_csv(@issues, @query, params), :type => 'text/csv; header=present', :filename => 'issues.csv') }
89 format.pdf { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'export.pdf') } 89 format.pdf { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'issues.pdf') }
90 end 90 end
91 else 91 else
92 respond_to do |format| 92 respond_to do |format|
93 format.html { render(:template => 'issues/index', :layout => !request.xhr?) } 93 format.html { render(:template => 'issues/index', :layout => !request.xhr?) }
94 format.any(:atom, :csv, :pdf) { render(:nothing => true) } 94 format.any(:atom, :csv, :pdf) { render(:nothing => true) }
130 # Add a new issue 130 # Add a new issue
131 # The new issue will be created from an existing one if copy_from parameter is given 131 # The new issue will be created from an existing one if copy_from parameter is given
132 def new 132 def new
133 respond_to do |format| 133 respond_to do |format|
134 format.html { render :action => 'new', :layout => !request.xhr? } 134 format.html { render :action => 'new', :layout => !request.xhr? }
135 format.js { render :partial => 'update_form' }
136 end 135 end
137 end 136 end
138 137
139 def create 138 def create
140 call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue }) 139 call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue })
152 151
153 respond_to do |format| 152 respond_to do |format|
154 format.html { 153 format.html {
155 render_attachment_warning_if_needed(@issue) 154 render_attachment_warning_if_needed(@issue)
156 flash[:notice] = l(:notice_issue_successful_create, :id => view_context.link_to("##{@issue.id}", issue_path(@issue), :title => @issue.subject)) 155 flash[:notice] = l(:notice_issue_successful_create, :id => view_context.link_to("##{@issue.id}", issue_path(@issue), :title => @issue.subject))
157 redirect_to(params[:continue] ? { :action => 'new', :project_id => @issue.project, :issue => {:tracker_id => @issue.tracker, :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?} } : 156 if params[:continue]
158 { :action => 'show', :id => @issue }) 157 attrs = {:tracker_id => @issue.tracker, :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?}
158 redirect_to new_project_issue_path(@issue.project, :issue => attrs)
159 else
160 redirect_to issue_path(@issue)
161 end
159 } 162 }
160 format.api { render :action => 'show', :status => :created, :location => issue_url(@issue) } 163 format.api { render :action => 'show', :status => :created, :location => issue_url(@issue) }
161 end 164 end
162 return 165 return
163 else 166 else
194 if saved 197 if saved
195 render_attachment_warning_if_needed(@issue) 198 render_attachment_warning_if_needed(@issue)
196 flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record? 199 flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record?
197 200
198 respond_to do |format| 201 respond_to do |format|
199 format.html { redirect_back_or_default({:action => 'show', :id => @issue}) } 202 format.html { redirect_back_or_default issue_path(@issue) }
200 format.api { render_api_ok } 203 format.api { render_api_ok }
201 end 204 end
202 else 205 else
203 respond_to do |format| 206 respond_to do |format|
204 format.html { render :action => 'edit' } 207 format.html { render :action => 'edit' }
205 format.api { render_validation_errors(@issue) } 208 format.api { render_validation_errors(@issue) }
206 end 209 end
207 end 210 end
211 end
212
213 # Updates the issue form when changing the project, status or tracker
214 # on issue creation/update
215 def update_form
208 end 216 end
209 217
210 # Bulk edit/copy a set of issues 218 # Bulk edit/copy a set of issues
211 def bulk_edit 219 def bulk_edit
212 @issues.sort! 220 @issues.sort!
277 end 285 end
278 set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids) 286 set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids)
279 287
280 if params[:follow] 288 if params[:follow]
281 if @issues.size == 1 && moved_issues.size == 1 289 if @issues.size == 1 && moved_issues.size == 1
282 redirect_to :controller => 'issues', :action => 'show', :id => moved_issues.first 290 redirect_to issue_path(moved_issues.first)
283 elsif moved_issues.map(&:project).uniq.size == 1 291 elsif moved_issues.map(&:project).uniq.size == 1
284 redirect_to :controller => 'issues', :action => 'index', :project_id => moved_issues.map(&:project).first 292 redirect_to project_issues_path(moved_issues.map(&:project).first)
285 end 293 end
286 else 294 else
287 redirect_back_or_default({:controller => 'issues', :action => 'index', :project_id => @project}) 295 redirect_back_or_default _project_issues_path(@project)
288 end 296 end
289 end 297 end
290 298
291 def destroy 299 def destroy
292 @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f 300 @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f
315 rescue ::ActiveRecord::RecordNotFound # raised by #reload if issue no longer exists 323 rescue ::ActiveRecord::RecordNotFound # raised by #reload if issue no longer exists
316 # nothing to do, issue was already deleted (eg. by a parent) 324 # nothing to do, issue was already deleted (eg. by a parent)
317 end 325 end
318 end 326 end
319 respond_to do |format| 327 respond_to do |format|
320 format.html { redirect_back_or_default(:action => 'index', :project_id => @project) } 328 format.html { redirect_back_or_default _project_issues_path(@project) }
321 format.api { render_api_ok } 329 format.api { render_api_ok }
322 end 330 end
323 end 331 end
324 332
325 private 333 private