##// END OF EJS Templates
Refactor: Extract method for setting the flash on bulk issue saves....
Eric Davis -
r3446:c7c3c0cc7c7d
parent child
Show More
@@ -1,571 +1,571
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2008 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 IssuesController < ApplicationController
19 19 menu_item :new_issue, :only => :new
20 20 default_search_scope :issues
21 21
22 22 before_filter :find_issue, :only => [:show, :edit, :update, :reply]
23 23 before_filter :find_issues, :only => [:bulk_edit, :move, :destroy]
24 24 before_filter :find_project, :only => [:new, :update_form, :preview]
25 25 before_filter :authorize, :except => [:index, :changes, :gantt, :calendar, :preview, :context_menu]
26 26 before_filter :find_optional_project, :only => [:index, :changes, :gantt, :calendar]
27 27 accept_key_auth :index, :show, :changes
28 28
29 29 rescue_from Query::StatementInvalid, :with => :query_statement_invalid
30 30
31 31 helper :journals
32 32 helper :projects
33 33 include ProjectsHelper
34 34 helper :custom_fields
35 35 include CustomFieldsHelper
36 36 helper :issue_relations
37 37 include IssueRelationsHelper
38 38 helper :watchers
39 39 include WatchersHelper
40 40 helper :attachments
41 41 include AttachmentsHelper
42 42 helper :queries
43 43 include QueriesHelper
44 44 helper :sort
45 45 include SortHelper
46 46 include IssuesHelper
47 47 helper :timelog
48 48 include Redmine::Export::PDF
49 49
50 50 verify :method => [:post, :delete],
51 51 :only => :destroy,
52 52 :render => { :nothing => true, :status => :method_not_allowed }
53 53
54 54 verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed }
55 55
56 56 def index
57 57 retrieve_query
58 58 sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
59 59 sort_update({'id' => "#{Issue.table_name}.id"}.merge(@query.available_columns.inject({}) {|h, c| h[c.name.to_s] = c.sortable; h}))
60 60
61 61 if @query.valid?
62 62 limit = case params[:format]
63 63 when 'csv', 'pdf'
64 64 Setting.issues_export_limit.to_i
65 65 when 'atom'
66 66 Setting.feeds_limit.to_i
67 67 else
68 68 per_page_option
69 69 end
70 70
71 71 @issue_count = @query.issue_count
72 72 @issue_pages = Paginator.new self, @issue_count, limit, params['page']
73 73 @issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version],
74 74 :order => sort_clause,
75 75 :offset => @issue_pages.current.offset,
76 76 :limit => limit)
77 77 @issue_count_by_group = @query.issue_count_by_group
78 78
79 79 respond_to do |format|
80 80 format.html { render :template => 'issues/index.rhtml', :layout => !request.xhr? }
81 81 format.xml { render :layout => false }
82 82 format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") }
83 83 format.csv { send_data(issues_to_csv(@issues, @project), :type => 'text/csv; header=present', :filename => 'export.csv') }
84 84 format.pdf { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'export.pdf') }
85 85 end
86 86 else
87 87 # Send html if the query is not valid
88 88 render(:template => 'issues/index.rhtml', :layout => !request.xhr?)
89 89 end
90 90 rescue ActiveRecord::RecordNotFound
91 91 render_404
92 92 end
93 93
94 94 def changes
95 95 retrieve_query
96 96 sort_init 'id', 'desc'
97 97 sort_update({'id' => "#{Issue.table_name}.id"}.merge(@query.available_columns.inject({}) {|h, c| h[c.name.to_s] = c.sortable; h}))
98 98
99 99 if @query.valid?
100 100 @journals = @query.journals(:order => "#{Journal.table_name}.created_on DESC",
101 101 :limit => 25)
102 102 end
103 103 @title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name)
104 104 render :layout => false, :content_type => 'application/atom+xml'
105 105 rescue ActiveRecord::RecordNotFound
106 106 render_404
107 107 end
108 108
109 109 def show
110 110 @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC")
111 111 @journals.each_with_index {|j,i| j.indice = i+1}
112 112 @journals.reverse! if User.current.wants_comments_in_reverse_order?
113 113 @changesets = @issue.changesets.visible.all
114 114 @changesets.reverse! if User.current.wants_comments_in_reverse_order?
115 115 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
116 116 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
117 117 @priorities = IssuePriority.all
118 118 @time_entry = TimeEntry.new
119 119 respond_to do |format|
120 120 format.html { render :template => 'issues/show.rhtml' }
121 121 format.xml { render :layout => false }
122 122 format.atom { render :action => 'changes', :layout => false, :content_type => 'application/atom+xml' }
123 123 format.pdf { send_data(issue_to_pdf(@issue), :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf") }
124 124 end
125 125 end
126 126
127 127 # Add a new issue
128 128 # The new issue will be created from an existing one if copy_from parameter is given
129 129 def new
130 130 @issue = Issue.new
131 131 @issue.copy_from(params[:copy_from]) if params[:copy_from]
132 132 @issue.project = @project
133 133 # Tracker must be set before custom field values
134 134 @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first)
135 135 if @issue.tracker.nil?
136 136 render_error l(:error_no_tracker_in_project)
137 137 return
138 138 end
139 139 if params[:issue].is_a?(Hash)
140 140 @issue.safe_attributes = params[:issue]
141 141 @issue.watcher_user_ids = params[:issue]['watcher_user_ids'] if User.current.allowed_to?(:add_issue_watchers, @project)
142 142 end
143 143 @issue.author = User.current
144 144
145 145 default_status = IssueStatus.default
146 146 unless default_status
147 147 render_error l(:error_no_default_issue_status)
148 148 return
149 149 end
150 150 @issue.status = default_status
151 151 @allowed_statuses = @issue.new_statuses_allowed_to(User.current, true)
152 152
153 153 if request.get? || request.xhr?
154 154 @issue.start_date ||= Date.today
155 155 else
156 156 requested_status = IssueStatus.find_by_id(params[:issue][:status_id])
157 157 # Check that the user is allowed to apply the requested status
158 158 @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status
159 159 call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue })
160 160 if @issue.save
161 161 attachments = Attachment.attach_files(@issue, params[:attachments])
162 162 render_attachment_warning_if_needed(@issue)
163 163 flash[:notice] = l(:notice_successful_create)
164 164 call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue})
165 165 respond_to do |format|
166 166 format.html {
167 167 redirect_to(params[:continue] ? { :action => 'new', :tracker_id => @issue.tracker } :
168 168 { :action => 'show', :id => @issue })
169 169 }
170 170 format.xml { render :action => 'show', :status => :created, :location => url_for(:controller => 'issues', :action => 'show', :id => @issue) }
171 171 end
172 172 return
173 173 else
174 174 respond_to do |format|
175 175 format.html { }
176 176 format.xml { render(:xml => @issue.errors, :status => :unprocessable_entity); return }
177 177 end
178 178 end
179 179 end
180 180 @priorities = IssuePriority.all
181 181 render :layout => !request.xhr?
182 182 end
183 183
184 184 # Attributes that can be updated on workflow transition (without :edit permission)
185 185 # TODO: make it configurable (at least per role)
186 186 UPDATABLE_ATTRS_ON_TRANSITION = %w(status_id assigned_to_id fixed_version_id done_ratio) unless const_defined?(:UPDATABLE_ATTRS_ON_TRANSITION)
187 187
188 188 def edit
189 189 update_issue_from_params
190 190
191 191 @journal = @issue.current_journal
192 192
193 193 respond_to do |format|
194 194 format.html { }
195 195 format.xml { }
196 196 end
197 197 end
198 198
199 199 def update
200 200 update_issue_from_params
201 201
202 202 if @issue.save_issue_with_child_records(params, @time_entry)
203 203 render_attachment_warning_if_needed(@issue)
204 204 flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record?
205 205
206 206 respond_to do |format|
207 207 format.html { redirect_back_or_default({:action => 'show', :id => @issue}) }
208 208 format.xml { head :ok }
209 209 end
210 210 else
211 211 render_attachment_warning_if_needed(@issue)
212 212 flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record?
213 213 @journal = @issue.current_journal
214 214
215 215 respond_to do |format|
216 216 format.html { render :action => 'edit' }
217 217 format.xml { render :xml => @issue.errors, :status => :unprocessable_entity }
218 218 end
219 219 end
220 220
221 221 rescue ActiveRecord::StaleObjectError
222 222 # Optimistic locking exception
223 223 flash.now[:error] = l(:notice_locking_conflict)
224 224 # Remove the previously added attachments if issue was not updated
225 225 attachments[:files].each(&:destroy) if attachments[:files]
226 226 end
227 227
228 228 def reply
229 229 journal = Journal.find(params[:journal_id]) if params[:journal_id]
230 230 if journal
231 231 user = journal.user
232 232 text = journal.notes
233 233 else
234 234 user = @issue.author
235 235 text = @issue.description
236 236 end
237 237 content = "#{ll(Setting.default_language, :text_user_wrote, user)}\\n> "
238 238 content << text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]').gsub('"', '\"').gsub(/(\r?\n|\r\n?)/, "\\n> ") + "\\n\\n"
239 239 render(:update) { |page|
240 240 page.<< "$('notes').value = \"#{content}\";"
241 241 page.show 'update'
242 242 page << "Form.Element.focus('notes');"
243 243 page << "Element.scrollTo('update');"
244 244 page << "$('notes').scrollTop = $('notes').scrollHeight - $('notes').clientHeight;"
245 245 }
246 246 end
247 247
248 248 # Bulk edit a set of issues
249 249 def bulk_edit
250 250 if request.post?
251 251 attributes = (params[:issue] || {}).reject {|k,v| v.blank?}
252 252 attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'}
253 253 attributes[:custom_field_values].reject! {|k,v| v.blank?} if attributes[:custom_field_values]
254 254
255 255 unsaved_issue_ids = []
256 256 @issues.each do |issue|
257 257 journal = issue.init_journal(User.current, params[:notes])
258 258 issue.safe_attributes = attributes
259 259 call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue })
260 260 unless issue.save
261 261 # Keep unsaved issue ids to display them in flash error
262 262 unsaved_issue_ids << issue.id
263 263 end
264 264 end
265 if unsaved_issue_ids.empty?
266 flash[:notice] = l(:notice_successful_update) unless @issues.empty?
267 else
268 flash[:error] = l(:notice_failed_to_save_issues, :count => unsaved_issue_ids.size,
269 :total => @issues.size,
270 :ids => '#' + unsaved_issue_ids.join(', #'))
271 end
265 set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids)
272 266 redirect_back_or_default({:controller => 'issues', :action => 'index', :project_id => @project})
273 267 return
274 268 end
275 269 @available_statuses = Workflow.available_statuses(@project)
276 270 @custom_fields = @project.all_issue_custom_fields
277 271 end
278 272
279 273 def move
280 274 @copy = params[:copy_options] && params[:copy_options][:copy]
281 275 @allowed_projects = []
282 276 # find projects to which the user is allowed to move the issue
283 277 if User.current.admin?
284 278 # admin is allowed to move issues to any active (visible) project
285 279 @allowed_projects = Project.find(:all, :conditions => Project.visible_by(User.current))
286 280 else
287 281 User.current.memberships.each {|m| @allowed_projects << m.project if m.roles.detect {|r| r.allowed_to?(:move_issues)}}
288 282 end
289 283 @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id]
290 284 @target_project ||= @project
291 285 @trackers = @target_project.trackers
292 286 @available_statuses = Workflow.available_statuses(@project)
293 287 if request.post?
294 288 new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id])
295 289 unsaved_issue_ids = []
296 290 moved_issues = []
297 291 @issues.each do |issue|
298 292 changed_attributes = {}
299 293 [:assigned_to_id, :status_id, :start_date, :due_date].each do |valid_attribute|
300 294 unless params[valid_attribute].blank?
301 295 changed_attributes[valid_attribute] = (params[valid_attribute] == 'none' ? nil : params[valid_attribute])
302 296 end
303 297 end
304 298 issue.init_journal(User.current)
305 299 call_hook(:controller_issues_move_before_save, { :params => params, :issue => issue, :target_project => @target_project, :copy => !!@copy })
306 300 if r = issue.move_to(@target_project, new_tracker, {:copy => @copy, :attributes => changed_attributes})
307 301 moved_issues << r
308 302 else
309 303 unsaved_issue_ids << issue.id
310 304 end
311 305 end
312 if unsaved_issue_ids.empty?
313 flash[:notice] = l(:notice_successful_update) unless @issues.empty?
314 else
315 flash[:error] = l(:notice_failed_to_save_issues, :count => unsaved_issue_ids.size,
316 :total => @issues.size,
317 :ids => '#' + unsaved_issue_ids.join(', #'))
318 end
306 set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids)
307
319 308 if params[:follow]
320 309 if @issues.size == 1 && moved_issues.size == 1
321 310 redirect_to :controller => 'issues', :action => 'show', :id => moved_issues.first
322 311 else
323 312 redirect_to :controller => 'issues', :action => 'index', :project_id => (@target_project || @project)
324 313 end
325 314 else
326 315 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
327 316 end
328 317 return
329 318 end
330 319 render :layout => false if request.xhr?
331 320 end
332 321
333 322 def destroy
334 323 @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f
335 324 if @hours > 0
336 325 case params[:todo]
337 326 when 'destroy'
338 327 # nothing to do
339 328 when 'nullify'
340 329 TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues])
341 330 when 'reassign'
342 331 reassign_to = @project.issues.find_by_id(params[:reassign_to_id])
343 332 if reassign_to.nil?
344 333 flash.now[:error] = l(:error_issue_not_found_in_project)
345 334 return
346 335 else
347 336 TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues])
348 337 end
349 338 else
350 339 unless params[:format] == 'xml'
351 340 # display the destroy form if it's a user request
352 341 return
353 342 end
354 343 end
355 344 end
356 345 @issues.each(&:destroy)
357 346 respond_to do |format|
358 347 format.html { redirect_to :action => 'index', :project_id => @project }
359 348 format.xml { head :ok }
360 349 end
361 350 end
362 351
363 352 def gantt
364 353 @gantt = Redmine::Helpers::Gantt.new(params)
365 354 retrieve_query
366 355 @query.group_by = nil
367 356 if @query.valid?
368 357 events = []
369 358 # Issues that have start and due dates
370 359 events += @query.issues(:include => [:tracker, :assigned_to, :priority],
371 360 :order => "start_date, due_date",
372 361 :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)", @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to]
373 362 )
374 363 # Issues that don't have a due date but that are assigned to a version with a date
375 364 events += @query.issues(:include => [:tracker, :assigned_to, :priority, :fixed_version],
376 365 :order => "start_date, effective_date",
377 366 :conditions => ["(((start_date>=? and start_date<=?) or (effective_date>=? and effective_date<=?) or (start_date<? and effective_date>?)) and start_date is not null and due_date is null and effective_date is not null)", @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to]
378 367 )
379 368 # Versions
380 369 events += @query.versions(:conditions => ["effective_date BETWEEN ? AND ?", @gantt.date_from, @gantt.date_to])
381 370
382 371 @gantt.events = events
383 372 end
384 373
385 374 basename = (@project ? "#{@project.identifier}-" : '') + 'gantt'
386 375
387 376 respond_to do |format|
388 377 format.html { render :template => "issues/gantt.rhtml", :layout => !request.xhr? }
389 378 format.png { send_data(@gantt.to_image, :disposition => 'inline', :type => 'image/png', :filename => "#{basename}.png") } if @gantt.respond_to?('to_image')
390 379 format.pdf { send_data(gantt_to_pdf(@gantt, @project), :type => 'application/pdf', :filename => "#{basename}.pdf") }
391 380 end
392 381 end
393 382
394 383 def calendar
395 384 if params[:year] and params[:year].to_i > 1900
396 385 @year = params[:year].to_i
397 386 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
398 387 @month = params[:month].to_i
399 388 end
400 389 end
401 390 @year ||= Date.today.year
402 391 @month ||= Date.today.month
403 392
404 393 @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month)
405 394 retrieve_query
406 395 @query.group_by = nil
407 396 if @query.valid?
408 397 events = []
409 398 events += @query.issues(:include => [:tracker, :assigned_to, :priority],
410 399 :conditions => ["((start_date BETWEEN ? AND ?) OR (due_date BETWEEN ? AND ?))", @calendar.startdt, @calendar.enddt, @calendar.startdt, @calendar.enddt]
411 400 )
412 401 events += @query.versions(:conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt])
413 402
414 403 @calendar.events = events
415 404 end
416 405
417 406 render :layout => false if request.xhr?
418 407 end
419 408
420 409 def context_menu
421 410 @issues = Issue.find_all_by_id(params[:ids], :include => :project)
422 411 if (@issues.size == 1)
423 412 @issue = @issues.first
424 413 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
425 414 end
426 415 projects = @issues.collect(&:project).compact.uniq
427 416 @project = projects.first if projects.size == 1
428 417
429 418 @can = {:edit => (@project && User.current.allowed_to?(:edit_issues, @project)),
430 419 :log_time => (@project && User.current.allowed_to?(:log_time, @project)),
431 420 :update => (@project && (User.current.allowed_to?(:edit_issues, @project) || (User.current.allowed_to?(:change_status, @project) && @allowed_statuses && !@allowed_statuses.empty?))),
432 421 :move => (@project && User.current.allowed_to?(:move_issues, @project)),
433 422 :copy => (@issue && @project.trackers.include?(@issue.tracker) && User.current.allowed_to?(:add_issues, @project)),
434 423 :delete => (@project && User.current.allowed_to?(:delete_issues, @project))
435 424 }
436 425 if @project
437 426 @assignables = @project.assignable_users
438 427 @assignables << @issue.assigned_to if @issue && @issue.assigned_to && !@assignables.include?(@issue.assigned_to)
439 428 @trackers = @project.trackers
440 429 end
441 430
442 431 @priorities = IssuePriority.all.reverse
443 432 @statuses = IssueStatus.find(:all, :order => 'position')
444 433 @back = params[:back_url] || request.env['HTTP_REFERER']
445 434
446 435 render :layout => false
447 436 end
448 437
449 438 def update_form
450 439 if params[:id].blank?
451 440 @issue = Issue.new
452 441 @issue.project = @project
453 442 else
454 443 @issue = @project.issues.visible.find(params[:id])
455 444 end
456 445 @issue.attributes = params[:issue]
457 446 @allowed_statuses = ([@issue.status] + @issue.status.find_new_statuses_allowed_to(User.current.roles_for_project(@project), @issue.tracker)).uniq
458 447 @priorities = IssuePriority.all
459 448
460 449 render :partial => 'attributes'
461 450 end
462 451
463 452 def preview
464 453 @issue = @project.issues.find_by_id(params[:id]) unless params[:id].blank?
465 454 @attachements = @issue.attachments if @issue
466 455 @text = params[:notes] || (params[:issue] ? params[:issue][:description] : nil)
467 456 render :partial => 'common/preview'
468 457 end
469 458
470 459 private
471 460 def find_issue
472 461 @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
473 462 @project = @issue.project
474 463 rescue ActiveRecord::RecordNotFound
475 464 render_404
476 465 end
477 466
478 467 # Filter for bulk operations
479 468 def find_issues
480 469 @issues = Issue.find_all_by_id(params[:id] || params[:ids])
481 470 raise ActiveRecord::RecordNotFound if @issues.empty?
482 471 projects = @issues.collect(&:project).compact.uniq
483 472 if projects.size == 1
484 473 @project = projects.first
485 474 else
486 475 # TODO: let users bulk edit/move/destroy issues from different projects
487 476 render_error 'Can not bulk edit/move/destroy issues from different projects'
488 477 return false
489 478 end
490 479 rescue ActiveRecord::RecordNotFound
491 480 render_404
492 481 end
493 482
494 483 def find_project
495 484 project_id = (params[:issue] && params[:issue][:project_id]) || params[:project_id]
496 485 @project = Project.find(project_id)
497 486 rescue ActiveRecord::RecordNotFound
498 487 render_404
499 488 end
500 489
501 490 def find_optional_project
502 491 @project = Project.find(params[:project_id]) unless params[:project_id].blank?
503 492 allowed = User.current.allowed_to?({:controller => params[:controller], :action => params[:action]}, @project, :global => true)
504 493 allowed ? true : deny_access
505 494 rescue ActiveRecord::RecordNotFound
506 495 render_404
507 496 end
508 497
509 498 # Retrieve query from session or build a new query
510 499 def retrieve_query
511 500 if !params[:query_id].blank?
512 501 cond = "project_id IS NULL"
513 502 cond << " OR project_id = #{@project.id}" if @project
514 503 @query = Query.find(params[:query_id], :conditions => cond)
515 504 @query.project = @project
516 505 session[:query] = {:id => @query.id, :project_id => @query.project_id}
517 506 sort_clear
518 507 else
519 508 if api_request? || params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil)
520 509 # Give it a name, required to be valid
521 510 @query = Query.new(:name => "_")
522 511 @query.project = @project
523 512 if params[:fields] and params[:fields].is_a? Array
524 513 params[:fields].each do |field|
525 514 @query.add_filter(field, params[:operators][field], params[:values][field])
526 515 end
527 516 else
528 517 @query.available_filters.keys.each do |field|
529 518 @query.add_short_filter(field, params[field]) if params[field]
530 519 end
531 520 end
532 521 @query.group_by = params[:group_by]
533 522 @query.column_names = params[:query] && params[:query][:column_names]
534 523 session[:query] = {:project_id => @query.project_id, :filters => @query.filters, :group_by => @query.group_by, :column_names => @query.column_names}
535 524 else
536 525 @query = Query.find_by_id(session[:query][:id]) if session[:query][:id]
537 526 @query ||= Query.new(:name => "_", :project => @project, :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names])
538 527 @query.project = @project
539 528 end
540 529 end
541 530 end
542 531
543 532 # Rescues an invalid query statement. Just in case...
544 533 def query_statement_invalid(exception)
545 534 logger.error "Query::StatementInvalid: #{exception.message}" if logger
546 535 session.delete(:query)
547 536 sort_clear
548 537 render_error "An error occurred while executing the query and has been logged. Please report this error to your Redmine administrator."
549 538 end
550 539
551 540 # Used by #edit and #update to set some common instance variables
552 541 # from the params
553 542 # TODO: Refactor, not everything in here is needed by #edit
554 543 def update_issue_from_params
555 544 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
556 545 @priorities = IssuePriority.all
557 546 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
558 547 @time_entry = TimeEntry.new
559 548
560 549 @notes = params[:notes]
561 550 @issue.init_journal(User.current, @notes)
562 551 # User can change issue attributes only if he has :edit permission or if a workflow transition is allowed
563 552 if (@edit_allowed || !@allowed_statuses.empty?) && params[:issue]
564 553 attrs = params[:issue].dup
565 554 attrs.delete_if {|k,v| !UPDATABLE_ATTRS_ON_TRANSITION.include?(k) } unless @edit_allowed
566 555 attrs.delete(:status_id) unless @allowed_statuses.detect {|s| s.id.to_s == attrs[:status_id].to_s}
567 556 @issue.safe_attributes = attrs
568 557 end
569 558
570 559 end
560
561 def set_flash_from_bulk_issue_save(issues, unsaved_issue_ids)
562 if unsaved_issue_ids.empty?
563 flash[:notice] = l(:notice_successful_update) unless issues.empty?
564 else
565 flash[:error] = l(:notice_failed_to_save_issues,
566 :count => unsaved_issue_ids.size,
567 :total => issues.size,
568 :ids => '#' + unsaved_issue_ids.join(', #'))
569 end
570 end
571 571 end
General Comments 0
You need to be logged in to leave comments. Login now