Ability to bulk edit custom fields of type 'list' (#461).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2316 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2009-01-25 16:04:28 +00:00
parent e944fc74df
commit bcc9007196
3 changed files with 37 additions and 2 deletions

View File

@ -232,6 +232,7 @@ class IssuesController < ApplicationController
assigned_to = (params[:assigned_to_id].blank? || params[:assigned_to_id] == 'none') ? nil : User.find_by_id(params[:assigned_to_id]) assigned_to = (params[:assigned_to_id].blank? || params[:assigned_to_id] == 'none') ? nil : User.find_by_id(params[:assigned_to_id])
category = (params[:category_id].blank? || params[:category_id] == 'none') ? nil : @project.issue_categories.find_by_id(params[:category_id]) category = (params[:category_id].blank? || params[:category_id] == 'none') ? nil : @project.issue_categories.find_by_id(params[:category_id])
fixed_version = (params[:fixed_version_id].blank? || params[:fixed_version_id] == 'none') ? nil : @project.versions.find_by_id(params[:fixed_version_id]) fixed_version = (params[:fixed_version_id].blank? || params[:fixed_version_id] == 'none') ? nil : @project.versions.find_by_id(params[:fixed_version_id])
custom_field_values = params[:custom_field_values] ? params[:custom_field_values].reject {|k,v| v.blank?} : nil
unsaved_issue_ids = [] unsaved_issue_ids = []
@issues.each do |issue| @issues.each do |issue|
@ -243,6 +244,7 @@ class IssuesController < ApplicationController
issue.start_date = params[:start_date] unless params[:start_date].blank? issue.start_date = params[:start_date] unless params[:start_date].blank?
issue.due_date = params[:due_date] unless params[:due_date].blank? issue.due_date = params[:due_date] unless params[:due_date].blank?
issue.done_ratio = params[:done_ratio] unless params[:done_ratio].blank? issue.done_ratio = params[:done_ratio] unless params[:done_ratio].blank?
issue.custom_field_values = custom_field_values if custom_field_values && !custom_field_values.empty?
call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue }) call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue })
# Don't save any change to the issue if the user is not authorized to apply the requested status # Don't save any change to the issue if the user is not authorized to apply the requested status
if (status.nil? || (issue.status.new_status_allowed_to?(status, current_role, issue.tracker) && issue.status = status)) && issue.save if (status.nil? || (issue.status.new_status_allowed_to?(status, current_role, issue.tracker) && issue.status = status)) && issue.save
@ -264,6 +266,7 @@ class IssuesController < ApplicationController
# Find potential statuses the user could be allowed to switch issues to # Find potential statuses the user could be allowed to switch issues to
@available_statuses = Workflow.find(:all, :include => :new_status, @available_statuses = Workflow.find(:all, :include => :new_status,
:conditions => {:role_id => current_role.id}).collect(&:new_status).compact.uniq.sort :conditions => {:role_id => current_role.id}).collect(&:new_status).compact.uniq.sort
@custom_fields = @project.issue_custom_fields.select {|f| f.field_format == 'list'}
end end
def move def move

View File

@ -38,6 +38,13 @@
<label><%= l(:field_done_ratio) %>: <label><%= l(:field_done_ratio) %>:
<%= select_tag 'done_ratio', options_for_select([[l(:label_no_change_option), '']] + (0..10).to_a.collect {|r| ["#{r*10} %", r*10] }) %></label> <%= select_tag 'done_ratio', options_for_select([[l(:label_no_change_option), '']] + (0..10).to_a.collect {|r| ["#{r*10} %", r*10] }) %></label>
</p> </p>
<% @custom_fields.each do |custom_field| %>
<p><label><%= h(custom_field.name) %></label>
<%= select_tag "custom_field_values[#{custom_field.id}]", options_for_select([[l(:label_no_change_option), '']] + custom_field.possible_values) %></label>
</p>
<% end %>
<%= call_hook(:view_issues_bulk_edit_details_bottom, { :issues => @issues }) %> <%= call_hook(:view_issues_bulk_edit_details_bottom, { :issues => @issues }) %>
</fieldset> </fieldset>

View File

@ -629,11 +629,36 @@ class IssuesControllerTest < Test::Unit::TestCase
def test_bulk_edit def test_bulk_edit
@request.session[:user_id] = 2 @request.session[:user_id] = 2
# update issues priority # update issues priority
post :bulk_edit, :ids => [1, 2], :priority_id => 7, :notes => 'Bulk editing', :assigned_to_id => '' post :bulk_edit, :ids => [1, 2], :priority_id => 7,
:assigned_to_id => '',
:custom_field_values => {'2' => ''},
:notes => 'Bulk editing'
assert_response 302 assert_response 302
# check that the issues were updated # check that the issues were updated
assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id} assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
assert_equal 'Bulk editing', Issue.find(1).journals.find(:first, :order => 'created_on DESC').notes
issue = Issue.find(1)
journal = issue.journals.find(:first, :order => 'created_on DESC')
assert_equal '125', issue.custom_value_for(2).value
assert_equal 'Bulk editing', journal.notes
assert_equal 1, journal.details.size
end
def test_bulk_edit_custom_field
@request.session[:user_id] = 2
# update issues priority
post :bulk_edit, :ids => [1, 2], :priority_id => '',
:assigned_to_id => '',
:custom_field_values => {'2' => '777'},
:notes => 'Bulk editing custom field'
assert_response 302
issue = Issue.find(1)
journal = issue.journals.find(:first, :order => 'created_on DESC')
assert_equal '777', issue.custom_value_for(2).value
assert_equal 1, journal.details.size
assert_equal '125', journal.details.first.old_value
assert_equal '777', journal.details.first.value
end end
def test_bulk_unassign def test_bulk_unassign