##// END OF EJS Templates
Rename issues CSV and PDF exports....
Jean-Philippe Lang -
r11219:aca59db4cc5a
parent child
Show More
@@ -1,439 +1,439
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2013 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.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
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
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.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 class IssuesController < ApplicationController
18 class IssuesController < ApplicationController
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, :update_form]
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, :update_form]
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
34 helper :journals
34 helper :journals
35 helper :projects
35 helper :projects
36 include ProjectsHelper
36 include ProjectsHelper
37 helper :custom_fields
37 helper :custom_fields
38 include CustomFieldsHelper
38 include CustomFieldsHelper
39 helper :issue_relations
39 helper :issue_relations
40 include IssueRelationsHelper
40 include IssueRelationsHelper
41 helper :watchers
41 helper :watchers
42 include WatchersHelper
42 include WatchersHelper
43 helper :attachments
43 helper :attachments
44 include AttachmentsHelper
44 include AttachmentsHelper
45 helper :queries
45 helper :queries
46 include QueriesHelper
46 include QueriesHelper
47 helper :repositories
47 helper :repositories
48 include RepositoriesHelper
48 include RepositoriesHelper
49 helper :sort
49 helper :sort
50 include SortHelper
50 include SortHelper
51 include IssuesHelper
51 include IssuesHelper
52 helper :timelog
52 helper :timelog
53 include Redmine::Export::PDF
53 include Redmine::Export::PDF
54
54
55 def index
55 def index
56 retrieve_query
56 retrieve_query
57 sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
57 sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
58 sort_update(@query.sortable_columns)
58 sort_update(@query.sortable_columns)
59 @query.sort_criteria = sort_criteria.to_a
59 @query.sort_criteria = sort_criteria.to_a
60
60
61 if @query.valid?
61 if @query.valid?
62 case params[:format]
62 case params[:format]
63 when 'csv', 'pdf'
63 when 'csv', 'pdf'
64 @limit = Setting.issues_export_limit.to_i
64 @limit = Setting.issues_export_limit.to_i
65 when 'atom'
65 when 'atom'
66 @limit = Setting.feeds_limit.to_i
66 @limit = Setting.feeds_limit.to_i
67 when 'xml', 'json'
67 when 'xml', 'json'
68 @offset, @limit = api_offset_and_limit
68 @offset, @limit = api_offset_and_limit
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 @issue_count, @limit, params['page']
74 @issue_pages = Paginator.new @issue_count, @limit, params['page']
75 @offset ||= @issue_pages.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
81
81
82 respond_to do |format|
82 respond_to do |format|
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(query_to_csv(@issues, @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) }
95 format.api { render_validation_errors(@query) }
95 format.api { render_validation_errors(@query) }
96 end
96 end
97 end
97 end
98 rescue ActiveRecord::RecordNotFound
98 rescue ActiveRecord::RecordNotFound
99 render_404
99 render_404
100 end
100 end
101
101
102 def show
102 def show
103 @journals = @issue.journals.includes(:user, :details).reorder("#{Journal.table_name}.id ASC").all
103 @journals = @issue.journals.includes(:user, :details).reorder("#{Journal.table_name}.id ASC").all
104 @journals.each_with_index {|j,i| j.indice = i+1}
104 @journals.each_with_index {|j,i| j.indice = i+1}
105 @journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project)
105 @journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project)
106 @journals.reverse! if User.current.wants_comments_in_reverse_order?
106 @journals.reverse! if User.current.wants_comments_in_reverse_order?
107
107
108 @changesets = @issue.changesets.visible.all
108 @changesets = @issue.changesets.visible.all
109 @changesets.reverse! if User.current.wants_comments_in_reverse_order?
109 @changesets.reverse! if User.current.wants_comments_in_reverse_order?
110
110
111 @relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? }
111 @relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? }
112 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
112 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
113 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
113 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
114 @priorities = IssuePriority.active
114 @priorities = IssuePriority.active
115 @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
115 @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
116 respond_to do |format|
116 respond_to do |format|
117 format.html {
117 format.html {
118 retrieve_previous_and_next_issue_ids
118 retrieve_previous_and_next_issue_ids
119 render :template => 'issues/show'
119 render :template => 'issues/show'
120 }
120 }
121 format.api
121 format.api
122 format.atom { render :template => 'journals/index', :layout => false, :content_type => 'application/atom+xml' }
122 format.atom { render :template => 'journals/index', :layout => false, :content_type => 'application/atom+xml' }
123 format.pdf {
123 format.pdf {
124 pdf = issue_to_pdf(@issue, :journals => @journals)
124 pdf = issue_to_pdf(@issue, :journals => @journals)
125 send_data(pdf, :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf")
125 send_data(pdf, :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf")
126 }
126 }
127 end
127 end
128 end
128 end
129
129
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 end
135 end
136 end
136 end
137
137
138 def create
138 def create
139 call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue })
139 call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue })
140 @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))
140 @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))
141 if @issue.save
141 if @issue.save
142 call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue})
142 call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue})
143 respond_to do |format|
143 respond_to do |format|
144 format.html {
144 format.html {
145 render_attachment_warning_if_needed(@issue)
145 render_attachment_warning_if_needed(@issue)
146 flash[:notice] = l(:notice_issue_successful_create, :id => view_context.link_to("##{@issue.id}", issue_path(@issue), :title => @issue.subject))
146 flash[:notice] = l(:notice_issue_successful_create, :id => view_context.link_to("##{@issue.id}", issue_path(@issue), :title => @issue.subject))
147 if params[:continue]
147 if params[:continue]
148 attrs = {:tracker_id => @issue.tracker, :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?}
148 attrs = {:tracker_id => @issue.tracker, :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?}
149 redirect_to new_project_issue_path(@issue.project, :issue => attrs)
149 redirect_to new_project_issue_path(@issue.project, :issue => attrs)
150 else
150 else
151 redirect_to issue_path(@issue)
151 redirect_to issue_path(@issue)
152 end
152 end
153 }
153 }
154 format.api { render :action => 'show', :status => :created, :location => issue_url(@issue) }
154 format.api { render :action => 'show', :status => :created, :location => issue_url(@issue) }
155 end
155 end
156 return
156 return
157 else
157 else
158 respond_to do |format|
158 respond_to do |format|
159 format.html { render :action => 'new' }
159 format.html { render :action => 'new' }
160 format.api { render_validation_errors(@issue) }
160 format.api { render_validation_errors(@issue) }
161 end
161 end
162 end
162 end
163 end
163 end
164
164
165 def edit
165 def edit
166 return unless update_issue_from_params
166 return unless update_issue_from_params
167
167
168 respond_to do |format|
168 respond_to do |format|
169 format.html { }
169 format.html { }
170 format.xml { }
170 format.xml { }
171 end
171 end
172 end
172 end
173
173
174 def update
174 def update
175 return unless update_issue_from_params
175 return unless update_issue_from_params
176 @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))
176 @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))
177 saved = false
177 saved = false
178 begin
178 begin
179 saved = @issue.save_issue_with_child_records(params, @time_entry)
179 saved = @issue.save_issue_with_child_records(params, @time_entry)
180 rescue ActiveRecord::StaleObjectError
180 rescue ActiveRecord::StaleObjectError
181 @conflict = true
181 @conflict = true
182 if params[:last_journal_id]
182 if params[:last_journal_id]
183 @conflict_journals = @issue.journals_after(params[:last_journal_id]).all
183 @conflict_journals = @issue.journals_after(params[:last_journal_id]).all
184 @conflict_journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project)
184 @conflict_journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project)
185 end
185 end
186 end
186 end
187
187
188 if saved
188 if saved
189 render_attachment_warning_if_needed(@issue)
189 render_attachment_warning_if_needed(@issue)
190 flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record?
190 flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record?
191
191
192 respond_to do |format|
192 respond_to do |format|
193 format.html { redirect_back_or_default issue_path(@issue) }
193 format.html { redirect_back_or_default issue_path(@issue) }
194 format.api { render_api_ok }
194 format.api { render_api_ok }
195 end
195 end
196 else
196 else
197 respond_to do |format|
197 respond_to do |format|
198 format.html { render :action => 'edit' }
198 format.html { render :action => 'edit' }
199 format.api { render_validation_errors(@issue) }
199 format.api { render_validation_errors(@issue) }
200 end
200 end
201 end
201 end
202 end
202 end
203
203
204 # Updates the issue form when changing the project, status or tracker
204 # Updates the issue form when changing the project, status or tracker
205 # on issue creation/update
205 # on issue creation/update
206 def update_form
206 def update_form
207 end
207 end
208
208
209 # Bulk edit/copy a set of issues
209 # Bulk edit/copy a set of issues
210 def bulk_edit
210 def bulk_edit
211 @issues.sort!
211 @issues.sort!
212 @copy = params[:copy].present?
212 @copy = params[:copy].present?
213 @notes = params[:notes]
213 @notes = params[:notes]
214
214
215 if User.current.allowed_to?(:move_issues, @projects)
215 if User.current.allowed_to?(:move_issues, @projects)
216 @allowed_projects = Issue.allowed_target_projects_on_move
216 @allowed_projects = Issue.allowed_target_projects_on_move
217 if params[:issue]
217 if params[:issue]
218 @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:issue][:project_id].to_s}
218 @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:issue][:project_id].to_s}
219 if @target_project
219 if @target_project
220 target_projects = [@target_project]
220 target_projects = [@target_project]
221 end
221 end
222 end
222 end
223 end
223 end
224 target_projects ||= @projects
224 target_projects ||= @projects
225
225
226 if @copy
226 if @copy
227 @available_statuses = [IssueStatus.default]
227 @available_statuses = [IssueStatus.default]
228 else
228 else
229 @available_statuses = @issues.map(&:new_statuses_allowed_to).reduce(:&)
229 @available_statuses = @issues.map(&:new_statuses_allowed_to).reduce(:&)
230 end
230 end
231 @custom_fields = target_projects.map{|p|p.all_issue_custom_fields}.reduce(:&)
231 @custom_fields = target_projects.map{|p|p.all_issue_custom_fields}.reduce(:&)
232 @assignables = target_projects.map(&:assignable_users).reduce(:&)
232 @assignables = target_projects.map(&:assignable_users).reduce(:&)
233 @trackers = target_projects.map(&:trackers).reduce(:&)
233 @trackers = target_projects.map(&:trackers).reduce(:&)
234 @versions = target_projects.map {|p| p.shared_versions.open}.reduce(:&)
234 @versions = target_projects.map {|p| p.shared_versions.open}.reduce(:&)
235 @categories = target_projects.map {|p| p.issue_categories}.reduce(:&)
235 @categories = target_projects.map {|p| p.issue_categories}.reduce(:&)
236 if @copy
236 if @copy
237 @attachments_present = @issues.detect {|i| i.attachments.any?}.present?
237 @attachments_present = @issues.detect {|i| i.attachments.any?}.present?
238 @subtasks_present = @issues.detect {|i| !i.leaf?}.present?
238 @subtasks_present = @issues.detect {|i| !i.leaf?}.present?
239 end
239 end
240
240
241 @safe_attributes = @issues.map(&:safe_attribute_names).reduce(:&)
241 @safe_attributes = @issues.map(&:safe_attribute_names).reduce(:&)
242 render :layout => false if request.xhr?
242 render :layout => false if request.xhr?
243 end
243 end
244
244
245 def bulk_update
245 def bulk_update
246 @issues.sort!
246 @issues.sort!
247 @copy = params[:copy].present?
247 @copy = params[:copy].present?
248 attributes = parse_params_for_bulk_issue_attributes(params)
248 attributes = parse_params_for_bulk_issue_attributes(params)
249
249
250 unsaved_issue_ids = []
250 unsaved_issue_ids = []
251 moved_issues = []
251 moved_issues = []
252
252
253 if @copy && params[:copy_subtasks].present?
253 if @copy && params[:copy_subtasks].present?
254 # Descendant issues will be copied with the parent task
254 # Descendant issues will be copied with the parent task
255 # Don't copy them twice
255 # Don't copy them twice
256 @issues.reject! {|issue| @issues.detect {|other| issue.is_descendant_of?(other)}}
256 @issues.reject! {|issue| @issues.detect {|other| issue.is_descendant_of?(other)}}
257 end
257 end
258
258
259 @issues.each do |issue|
259 @issues.each do |issue|
260 issue.reload
260 issue.reload
261 if @copy
261 if @copy
262 issue = issue.copy({},
262 issue = issue.copy({},
263 :attachments => params[:copy_attachments].present?,
263 :attachments => params[:copy_attachments].present?,
264 :subtasks => params[:copy_subtasks].present?
264 :subtasks => params[:copy_subtasks].present?
265 )
265 )
266 end
266 end
267 journal = issue.init_journal(User.current, params[:notes])
267 journal = issue.init_journal(User.current, params[:notes])
268 issue.safe_attributes = attributes
268 issue.safe_attributes = attributes
269 call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue })
269 call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue })
270 if issue.save
270 if issue.save
271 moved_issues << issue
271 moved_issues << issue
272 else
272 else
273 # Keep unsaved issue ids to display them in flash error
273 # Keep unsaved issue ids to display them in flash error
274 unsaved_issue_ids << issue.id
274 unsaved_issue_ids << issue.id
275 end
275 end
276 end
276 end
277 set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids)
277 set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids)
278
278
279 if params[:follow]
279 if params[:follow]
280 if @issues.size == 1 && moved_issues.size == 1
280 if @issues.size == 1 && moved_issues.size == 1
281 redirect_to issue_path(moved_issues.first)
281 redirect_to issue_path(moved_issues.first)
282 elsif moved_issues.map(&:project).uniq.size == 1
282 elsif moved_issues.map(&:project).uniq.size == 1
283 redirect_to project_issues_path(moved_issues.map(&:project).first)
283 redirect_to project_issues_path(moved_issues.map(&:project).first)
284 end
284 end
285 else
285 else
286 redirect_back_or_default _project_issues_path(@project)
286 redirect_back_or_default _project_issues_path(@project)
287 end
287 end
288 end
288 end
289
289
290 def destroy
290 def destroy
291 @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f
291 @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f
292 if @hours > 0
292 if @hours > 0
293 case params[:todo]
293 case params[:todo]
294 when 'destroy'
294 when 'destroy'
295 # nothing to do
295 # nothing to do
296 when 'nullify'
296 when 'nullify'
297 TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues])
297 TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues])
298 when 'reassign'
298 when 'reassign'
299 reassign_to = @project.issues.find_by_id(params[:reassign_to_id])
299 reassign_to = @project.issues.find_by_id(params[:reassign_to_id])
300 if reassign_to.nil?
300 if reassign_to.nil?
301 flash.now[:error] = l(:error_issue_not_found_in_project)
301 flash.now[:error] = l(:error_issue_not_found_in_project)
302 return
302 return
303 else
303 else
304 TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues])
304 TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues])
305 end
305 end
306 else
306 else
307 # display the destroy form if it's a user request
307 # display the destroy form if it's a user request
308 return unless api_request?
308 return unless api_request?
309 end
309 end
310 end
310 end
311 @issues.each do |issue|
311 @issues.each do |issue|
312 begin
312 begin
313 issue.reload.destroy
313 issue.reload.destroy
314 rescue ::ActiveRecord::RecordNotFound # raised by #reload if issue no longer exists
314 rescue ::ActiveRecord::RecordNotFound # raised by #reload if issue no longer exists
315 # nothing to do, issue was already deleted (eg. by a parent)
315 # nothing to do, issue was already deleted (eg. by a parent)
316 end
316 end
317 end
317 end
318 respond_to do |format|
318 respond_to do |format|
319 format.html { redirect_back_or_default _project_issues_path(@project) }
319 format.html { redirect_back_or_default _project_issues_path(@project) }
320 format.api { render_api_ok }
320 format.api { render_api_ok }
321 end
321 end
322 end
322 end
323
323
324 private
324 private
325
325
326 def find_project
326 def find_project
327 project_id = params[:project_id] || (params[:issue] && params[:issue][:project_id])
327 project_id = params[:project_id] || (params[:issue] && params[:issue][:project_id])
328 @project = Project.find(project_id)
328 @project = Project.find(project_id)
329 rescue ActiveRecord::RecordNotFound
329 rescue ActiveRecord::RecordNotFound
330 render_404
330 render_404
331 end
331 end
332
332
333 def retrieve_previous_and_next_issue_ids
333 def retrieve_previous_and_next_issue_ids
334 retrieve_query_from_session
334 retrieve_query_from_session
335 if @query
335 if @query
336 sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
336 sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
337 sort_update(@query.sortable_columns, 'issues_index_sort')
337 sort_update(@query.sortable_columns, 'issues_index_sort')
338 limit = 500
338 limit = 500
339 issue_ids = @query.issue_ids(:order => sort_clause, :limit => (limit + 1), :include => [:assigned_to, :tracker, :priority, :category, :fixed_version])
339 issue_ids = @query.issue_ids(:order => sort_clause, :limit => (limit + 1), :include => [:assigned_to, :tracker, :priority, :category, :fixed_version])
340 if (idx = issue_ids.index(@issue.id)) && idx < limit
340 if (idx = issue_ids.index(@issue.id)) && idx < limit
341 if issue_ids.size < 500
341 if issue_ids.size < 500
342 @issue_position = idx + 1
342 @issue_position = idx + 1
343 @issue_count = issue_ids.size
343 @issue_count = issue_ids.size
344 end
344 end
345 @prev_issue_id = issue_ids[idx - 1] if idx > 0
345 @prev_issue_id = issue_ids[idx - 1] if idx > 0
346 @next_issue_id = issue_ids[idx + 1] if idx < (issue_ids.size - 1)
346 @next_issue_id = issue_ids[idx + 1] if idx < (issue_ids.size - 1)
347 end
347 end
348 end
348 end
349 end
349 end
350
350
351 # Used by #edit and #update to set some common instance variables
351 # Used by #edit and #update to set some common instance variables
352 # from the params
352 # from the params
353 # TODO: Refactor, not everything in here is needed by #edit
353 # TODO: Refactor, not everything in here is needed by #edit
354 def update_issue_from_params
354 def update_issue_from_params
355 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
355 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
356 @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
356 @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
357 @time_entry.attributes = params[:time_entry]
357 @time_entry.attributes = params[:time_entry]
358
358
359 @issue.init_journal(User.current)
359 @issue.init_journal(User.current)
360
360
361 issue_attributes = params[:issue]
361 issue_attributes = params[:issue]
362 if issue_attributes && params[:conflict_resolution]
362 if issue_attributes && params[:conflict_resolution]
363 case params[:conflict_resolution]
363 case params[:conflict_resolution]
364 when 'overwrite'
364 when 'overwrite'
365 issue_attributes = issue_attributes.dup
365 issue_attributes = issue_attributes.dup
366 issue_attributes.delete(:lock_version)
366 issue_attributes.delete(:lock_version)
367 when 'add_notes'
367 when 'add_notes'
368 issue_attributes = issue_attributes.slice(:notes)
368 issue_attributes = issue_attributes.slice(:notes)
369 when 'cancel'
369 when 'cancel'
370 redirect_to issue_path(@issue)
370 redirect_to issue_path(@issue)
371 return false
371 return false
372 end
372 end
373 end
373 end
374 @issue.safe_attributes = issue_attributes
374 @issue.safe_attributes = issue_attributes
375 @priorities = IssuePriority.active
375 @priorities = IssuePriority.active
376 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
376 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
377 true
377 true
378 end
378 end
379
379
380 # TODO: Refactor, lots of extra code in here
380 # TODO: Refactor, lots of extra code in here
381 # TODO: Changing tracker on an existing issue should not trigger this
381 # TODO: Changing tracker on an existing issue should not trigger this
382 def build_new_issue_from_params
382 def build_new_issue_from_params
383 if params[:id].blank?
383 if params[:id].blank?
384 @issue = Issue.new
384 @issue = Issue.new
385 if params[:copy_from]
385 if params[:copy_from]
386 begin
386 begin
387 @copy_from = Issue.visible.find(params[:copy_from])
387 @copy_from = Issue.visible.find(params[:copy_from])
388 @copy_attachments = params[:copy_attachments].present? || request.get?
388 @copy_attachments = params[:copy_attachments].present? || request.get?
389 @copy_subtasks = params[:copy_subtasks].present? || request.get?
389 @copy_subtasks = params[:copy_subtasks].present? || request.get?
390 @issue.copy_from(@copy_from, :attachments => @copy_attachments, :subtasks => @copy_subtasks)
390 @issue.copy_from(@copy_from, :attachments => @copy_attachments, :subtasks => @copy_subtasks)
391 rescue ActiveRecord::RecordNotFound
391 rescue ActiveRecord::RecordNotFound
392 render_404
392 render_404
393 return
393 return
394 end
394 end
395 end
395 end
396 @issue.project = @project
396 @issue.project = @project
397 else
397 else
398 @issue = @project.issues.visible.find(params[:id])
398 @issue = @project.issues.visible.find(params[:id])
399 end
399 end
400
400
401 @issue.project = @project
401 @issue.project = @project
402 @issue.author ||= User.current
402 @issue.author ||= User.current
403 # Tracker must be set before custom field values
403 # Tracker must be set before custom field values
404 @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first)
404 @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first)
405 if @issue.tracker.nil?
405 if @issue.tracker.nil?
406 render_error l(:error_no_tracker_in_project)
406 render_error l(:error_no_tracker_in_project)
407 return false
407 return false
408 end
408 end
409 @issue.start_date ||= Date.today if Setting.default_issue_start_date_to_creation_date?
409 @issue.start_date ||= Date.today if Setting.default_issue_start_date_to_creation_date?
410 @issue.safe_attributes = params[:issue]
410 @issue.safe_attributes = params[:issue]
411
411
412 @priorities = IssuePriority.active
412 @priorities = IssuePriority.active
413 @allowed_statuses = @issue.new_statuses_allowed_to(User.current, true)
413 @allowed_statuses = @issue.new_statuses_allowed_to(User.current, true)
414 @available_watchers = (@issue.project.users.sort + @issue.watcher_users).uniq
414 @available_watchers = (@issue.project.users.sort + @issue.watcher_users).uniq
415 end
415 end
416
416
417 def check_for_default_issue_status
417 def check_for_default_issue_status
418 if IssueStatus.default.nil?
418 if IssueStatus.default.nil?
419 render_error l(:error_no_default_issue_status)
419 render_error l(:error_no_default_issue_status)
420 return false
420 return false
421 end
421 end
422 end
422 end
423
423
424 def parse_params_for_bulk_issue_attributes(params)
424 def parse_params_for_bulk_issue_attributes(params)
425 attributes = (params[:issue] || {}).reject {|k,v| v.blank?}
425 attributes = (params[:issue] || {}).reject {|k,v| v.blank?}
426 attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'}
426 attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'}
427 if custom = attributes[:custom_field_values]
427 if custom = attributes[:custom_field_values]
428 custom.reject! {|k,v| v.blank?}
428 custom.reject! {|k,v| v.blank?}
429 custom.keys.each do |k|
429 custom.keys.each do |k|
430 if custom[k].is_a?(Array)
430 if custom[k].is_a?(Array)
431 custom[k] << '' if custom[k].delete('__none__')
431 custom[k] << '' if custom[k].delete('__none__')
432 else
432 else
433 custom[k] = '' if custom[k] == '__none__'
433 custom[k] = '' if custom[k] == '__none__'
434 end
434 end
435 end
435 end
436 end
436 end
437 attributes
437 attributes
438 end
438 end
439 end
439 end
General Comments 0
You need to be logged in to leave comments. Login now