Allows project to be changed from the bulk edit form.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8536 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
dc8fcbaf03
commit
d29638845a
|
@ -209,10 +209,25 @@ class IssuesController < ApplicationController
|
||||||
# Bulk edit a set of issues
|
# Bulk edit a set of issues
|
||||||
def bulk_edit
|
def bulk_edit
|
||||||
@issues.sort!
|
@issues.sort!
|
||||||
@available_statuses = @projects.map{|p|Workflow.available_statuses(p)}.inject{|memo,w|memo & w}
|
|
||||||
@custom_fields = @projects.map{|p|p.all_issue_custom_fields}.inject{|memo,c|memo & c}
|
if User.current.allowed_to?(:move_issues, @projects)
|
||||||
@assignables = @projects.map(&:assignable_users).inject{|memo,a| memo & a}
|
@allowed_projects = Issue.allowed_target_projects_on_move
|
||||||
@trackers = @projects.map(&:trackers).inject{|memo,t| memo & t}
|
if params[:issue]
|
||||||
|
@target_project = @allowed_projects.detect {|p| p.id.to_s == params[:issue][:project_id]}
|
||||||
|
if @target_project
|
||||||
|
target_projects = [@target_project]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
target_projects ||= @projects
|
||||||
|
|
||||||
|
@available_statuses = target_projects.map{|p|Workflow.available_statuses(p)}.inject{|memo,w|memo & w}
|
||||||
|
@custom_fields = target_projects.map{|p|p.all_issue_custom_fields}.inject{|memo,c|memo & c}
|
||||||
|
@assignables = target_projects.map(&:assignable_users).inject{|memo,a| memo & a}
|
||||||
|
@trackers = target_projects.map(&:trackers).inject{|memo,t| memo & t}
|
||||||
|
|
||||||
|
@notes = params[:notes]
|
||||||
|
render :layout => false if request.xhr?
|
||||||
end
|
end
|
||||||
|
|
||||||
def bulk_update
|
def bulk_update
|
||||||
|
@ -220,18 +235,30 @@ class IssuesController < ApplicationController
|
||||||
attributes = parse_params_for_bulk_issue_attributes(params)
|
attributes = parse_params_for_bulk_issue_attributes(params)
|
||||||
|
|
||||||
unsaved_issue_ids = []
|
unsaved_issue_ids = []
|
||||||
|
moved_issues = []
|
||||||
@issues.each do |issue|
|
@issues.each do |issue|
|
||||||
issue.reload
|
issue.reload
|
||||||
journal = issue.init_journal(User.current, params[:notes])
|
journal = issue.init_journal(User.current, params[:notes])
|
||||||
issue.safe_attributes = attributes
|
issue.safe_attributes = attributes
|
||||||
call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue })
|
call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue })
|
||||||
unless issue.save
|
if issue.save
|
||||||
|
moved_issues << issue
|
||||||
|
else
|
||||||
# Keep unsaved issue ids to display them in flash error
|
# Keep unsaved issue ids to display them in flash error
|
||||||
unsaved_issue_ids << issue.id
|
unsaved_issue_ids << issue.id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids)
|
set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids)
|
||||||
redirect_back_or_default({:controller => 'issues', :action => 'index', :project_id => @project})
|
|
||||||
|
if params[:follow]
|
||||||
|
if @issues.size == 1 && moved_issues.size == 1
|
||||||
|
redirect_to :controller => 'issues', :action => 'show', :id => moved_issues.first
|
||||||
|
elsif moved_issues.map(&:project).uniq.size == 1
|
||||||
|
redirect_to :controller => 'issues', :action => 'index', :project_id => moved_issues.map(&:project).first
|
||||||
|
end
|
||||||
|
else
|
||||||
|
redirect_back_or_default({:controller => 'issues', :action => 'index', :project_id => @project})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
verify :method => :delete, :only => :destroy, :render => { :nothing => true, :status => :method_not_allowed }
|
verify :method => :delete, :only => :destroy, :render => { :nothing => true, :status => :method_not_allowed }
|
||||||
|
|
|
@ -7,13 +7,22 @@
|
||||||
) + h(": #{i.subject}"))
|
) + h(": #{i.subject}"))
|
||||||
}.join("\n").html_safe %></ul>
|
}.join("\n").html_safe %></ul>
|
||||||
|
|
||||||
<% form_tag(:action => 'bulk_update') do %>
|
<% form_tag({:action => 'bulk_update'}, :id => 'bulk_edit_form') do %>
|
||||||
<%= @issues.collect {|i| hidden_field_tag('ids[]', i.id)}.join("\n").html_safe %>
|
<%= @issues.collect {|i| hidden_field_tag('ids[]', i.id)}.join("\n").html_safe %>
|
||||||
<div class="box tabular">
|
<div class="box tabular">
|
||||||
<fieldset class="attributes">
|
<fieldset class="attributes">
|
||||||
<legend><%= l(:label_change_properties) %></legend>
|
<legend><%= l(:label_change_properties) %></legend>
|
||||||
|
|
||||||
<div class="splitcontentleft">
|
<div class="splitcontentleft">
|
||||||
|
<% if @allowed_projects.present? %>
|
||||||
|
<p>
|
||||||
|
<label for="issue_project_id"><%= l(:field_project) %></label>
|
||||||
|
<%= select_tag('issue[project_id]', "<option value=\"\">#{l(:label_no_change_option)}</option>" + project_tree_options_for_select(@allowed_projects, :selected => @target_project)) %>
|
||||||
|
</p>
|
||||||
|
<%= observe_field :issue_project_id, :url => {:action => 'bulk_edit'},
|
||||||
|
:update => 'content',
|
||||||
|
:with => "Form.serialize('bulk_edit_form')" %>
|
||||||
|
<% end %>
|
||||||
<p>
|
<p>
|
||||||
<label for="issue_tracker_id"><%= l(:field_tracker) %></label>
|
<label for="issue_tracker_id"><%= l(:field_tracker) %></label>
|
||||||
<%= select_tag('issue[tracker_id]', "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(@trackers, :id, :name)) %>
|
<%= select_tag('issue[tracker_id]', "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(@trackers, :id, :name)) %>
|
||||||
|
@ -92,5 +101,13 @@
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p><%= submit_tag l(:button_submit) %></p>
|
<p>
|
||||||
|
<% if @target_project %>
|
||||||
|
<%= submit_tag l(:button_move) %>
|
||||||
|
<%= submit_tag l(:button_move_and_follow), :name => 'follow' %>
|
||||||
|
<% else %>
|
||||||
|
<%= submit_tag l(:button_submit) %>
|
||||||
|
<% end %>
|
||||||
|
</p>
|
||||||
|
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -198,7 +198,7 @@ ActionController::Routing::Routes.draw do |map|
|
||||||
|
|
||||||
map.resources :queries, :except => [:show]
|
map.resources :queries, :except => [:show]
|
||||||
map.resources :issues,
|
map.resources :issues,
|
||||||
:collection => {:bulk_edit => :get, :bulk_update => :post} do |issues|
|
:collection => {:bulk_edit => [:get, :post], :bulk_update => :post} do |issues|
|
||||||
issues.resources :time_entries, :controller => 'timelog',
|
issues.resources :time_entries, :controller => 'timelog',
|
||||||
:collection => {:report => :get}
|
:collection => {:report => :get}
|
||||||
issues.resources :relations, :shallow => true,
|
issues.resources :relations, :shallow => true,
|
||||||
|
|
|
@ -2033,6 +2033,7 @@ class IssuesControllerTest < ActionController::TestCase
|
||||||
assert_response :success
|
assert_response :success
|
||||||
assert_template 'bulk_edit'
|
assert_template 'bulk_edit'
|
||||||
|
|
||||||
|
assert_tag :select, :attributes => {:name => 'issue[project_id]'}
|
||||||
assert_tag :input, :attributes => {:name => 'issue[parent_issue_id]'}
|
assert_tag :input, :attributes => {:name => 'issue[parent_issue_id]'}
|
||||||
|
|
||||||
# Project specific custom field, date type
|
# Project specific custom field, date type
|
||||||
|
@ -2185,6 +2186,38 @@ class IssuesControllerTest < ActionController::TestCase
|
||||||
assert_equal 2, ActionMailer::Base.deliveries.size
|
assert_equal 2, ActionMailer::Base.deliveries.size
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_bulk_update_project
|
||||||
|
@request.session[:user_id] = 2
|
||||||
|
post :bulk_update, :ids => [1, 2], :issue => {:project_id => '2'}
|
||||||
|
assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
|
||||||
|
# Issues moved to project 2
|
||||||
|
assert_equal 2, Issue.find(1).project_id
|
||||||
|
assert_equal 2, Issue.find(2).project_id
|
||||||
|
# No tracker change
|
||||||
|
assert_equal 1, Issue.find(1).tracker_id
|
||||||
|
assert_equal 2, Issue.find(2).tracker_id
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_bulk_update_project_on_single_issue_should_follow_when_needed
|
||||||
|
@request.session[:user_id] = 2
|
||||||
|
post :bulk_update, :id => 1, :issue => {:project_id => '2'}, :follow => '1'
|
||||||
|
assert_redirected_to '/issues/1'
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_bulk_update_project_on_multiple_issues_should_follow_when_needed
|
||||||
|
@request.session[:user_id] = 2
|
||||||
|
post :bulk_update, :id => [1, 2], :issue => {:project_id => '2'}, :follow => '1'
|
||||||
|
assert_redirected_to '/projects/onlinestore/issues'
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_bulk_update_tracker
|
||||||
|
@request.session[:user_id] = 2
|
||||||
|
post :bulk_update, :ids => [1, 2], :issue => {:tracker_id => '2'}
|
||||||
|
assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
|
||||||
|
assert_equal 2, Issue.find(1).tracker_id
|
||||||
|
assert_equal 2, Issue.find(2).tracker_id
|
||||||
|
end
|
||||||
|
|
||||||
def test_bulk_update_status
|
def test_bulk_update_status
|
||||||
@request.session[:user_id] = 2
|
@request.session[:user_id] = 2
|
||||||
# update issues priority
|
# update issues priority
|
||||||
|
@ -2198,6 +2231,24 @@ class IssuesControllerTest < ActionController::TestCase
|
||||||
assert issue.closed?
|
assert issue.closed?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_bulk_update_priority
|
||||||
|
@request.session[:user_id] = 2
|
||||||
|
post :bulk_update, :ids => [1, 2], :issue => {:priority_id => 6}
|
||||||
|
|
||||||
|
assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
|
||||||
|
assert_equal 6, Issue.find(1).priority_id
|
||||||
|
assert_equal 6, Issue.find(2).priority_id
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_bulk_update_with_notes
|
||||||
|
@request.session[:user_id] = 2
|
||||||
|
post :bulk_update, :ids => [1, 2], :notes => 'Moving two issues'
|
||||||
|
|
||||||
|
assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
|
||||||
|
assert_equal 'Moving two issues', Issue.find(1).journals.sort_by(&:id).last.notes
|
||||||
|
assert_equal 'Moving two issues', Issue.find(2).journals.sort_by(&:id).last.notes
|
||||||
|
end
|
||||||
|
|
||||||
def test_bulk_update_parent_id
|
def test_bulk_update_parent_id
|
||||||
@request.session[:user_id] = 2
|
@request.session[:user_id] = 2
|
||||||
post :bulk_update, :ids => [1, 3],
|
post :bulk_update, :ids => [1, 3],
|
||||||
|
|
|
@ -123,6 +123,11 @@ class RoutingIssuesTest < ActionController::IntegrationTest
|
||||||
{ :method => 'get', :path => "/issues/bulk_edit" },
|
{ :method => 'get', :path => "/issues/bulk_edit" },
|
||||||
{ :controller => 'issues', :action => 'bulk_edit' }
|
{ :controller => 'issues', :action => 'bulk_edit' }
|
||||||
)
|
)
|
||||||
|
# For updating the bulk edit form
|
||||||
|
assert_routing(
|
||||||
|
{ :method => 'post', :path => "/issues/bulk_edit" },
|
||||||
|
{ :controller => 'issues', :action => 'bulk_edit' }
|
||||||
|
)
|
||||||
assert_routing(
|
assert_routing(
|
||||||
{ :method => 'post', :path => "/issues/bulk_update" },
|
{ :method => 'post', :path => "/issues/bulk_update" },
|
||||||
{ :controller => 'issues', :action => 'bulk_update' }
|
{ :controller => 'issues', :action => 'bulk_update' }
|
||||||
|
|
Loading…
Reference in New Issue