Enhanced the Issue Bulk Copy feature:
* Add a Copy option to the Context menu for multiple issues. * Added assigned to, status, start and due date options to the move/copy form. * Allow Issue#move_to to change attributes on the moved/copied issue. #4117 git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3122 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -271,13 +271,12 @@ class IssuesController < ApplicationController
|
||||
redirect_to(params[:back_to] || {:controller => 'issues', :action => 'index', :project_id => @project})
|
||||
return
|
||||
end
|
||||
# Find potential statuses the user could be allowed to switch issues to
|
||||
@available_statuses = Workflow.find(:all, :include => :new_status,
|
||||
:conditions => {:role_id => User.current.roles_for_project(@project).collect(&:id)}).collect(&:new_status).compact.uniq.sort
|
||||
@available_statuses = Workflow.available_statuses(@project)
|
||||
@custom_fields = @project.issue_custom_fields.select {|f| f.field_format == 'list'}
|
||||
end
|
||||
|
||||
def move
|
||||
@copy = params[:copy_options] && params[:copy_options][:copy]
|
||||
@allowed_projects = []
|
||||
# find projects to which the user is allowed to move the issue
|
||||
if User.current.admin?
|
||||
@@ -289,13 +288,18 @@ class IssuesController < ApplicationController
|
||||
@target_project = @allowed_projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id]
|
||||
@target_project ||= @project
|
||||
@trackers = @target_project.trackers
|
||||
@available_statuses = Workflow.available_statuses(@project)
|
||||
if request.post?
|
||||
new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id])
|
||||
unsaved_issue_ids = []
|
||||
moved_issues = []
|
||||
@issues.each do |issue|
|
||||
changed_attributes = {}
|
||||
[:assigned_to_id, :status_id, :start_date, :due_date].each do |valid_attribute|
|
||||
changed_attributes[valid_attribute] = params[valid_attribute] if params[valid_attribute]
|
||||
end
|
||||
issue.init_journal(User.current)
|
||||
if r = issue.move_to(@target_project, new_tracker, params[:copy_options])
|
||||
if r = issue.move_to(@target_project, new_tracker, {:copy => @copy, :attributes => changed_attributes})
|
||||
moved_issues << r
|
||||
else
|
||||
unsaved_issue_ids << issue.id
|
||||
|
||||
+9
-1
@@ -108,7 +108,15 @@ class Issue < ActiveRecord::Base
|
||||
end
|
||||
if options[:copy]
|
||||
issue.custom_field_values = self.custom_field_values.inject({}) {|h,v| h[v.custom_field_id] = v.value; h}
|
||||
issue.status = self.status
|
||||
issue.status = if options[:attributes] && options[:attributes][:status_id]
|
||||
IssueStatus.find_by_id(options[:attributes][:status_id])
|
||||
else
|
||||
self.status
|
||||
end
|
||||
end
|
||||
# Allow bulk setting of attributes on the issue
|
||||
if options[:attributes]
|
||||
issue.attributes = options[:attributes]
|
||||
end
|
||||
if issue.save
|
||||
unless options[:copy]
|
||||
|
||||
@@ -40,4 +40,15 @@ class Workflow < ActiveRecord::Base
|
||||
|
||||
result
|
||||
end
|
||||
|
||||
# Find potential statuses the user could be allowed to switch issues to
|
||||
def self.available_statuses(project, user=User.current)
|
||||
Workflow.find(:all,
|
||||
:include => :new_status,
|
||||
:conditions => {:role_id => user.roles_for_project(project).collect(&:id)}).
|
||||
collect(&:new_status).
|
||||
compact.
|
||||
uniq.
|
||||
sort
|
||||
end
|
||||
end
|
||||
|
||||
@@ -88,8 +88,6 @@
|
||||
</li>
|
||||
|
||||
<% if !@issue.nil? %>
|
||||
<li><%= context_menu_link l(:button_copy), {:controller => 'issues', :action => 'new', :project_id => @project, :copy_from => @issue},
|
||||
:class => 'icon-copy', :disabled => !@can[:copy] %></li>
|
||||
<% if @can[:log_time] -%>
|
||||
<li><%= context_menu_link l(:button_log_time), {:controller => 'timelog', :action => 'edit', :issue_id => @issue},
|
||||
:class => 'icon-time-add' %></li>
|
||||
@@ -99,6 +97,14 @@
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<% if @issue.present? %>
|
||||
<li><%= context_menu_link l(:button_copy), {:controller => 'issues', :action => 'new', :project_id => @project, :copy_from => @issue},
|
||||
:class => 'icon-copy', :disabled => !@can[:copy] %></li>
|
||||
<% else %>
|
||||
<li><%= context_menu_link l(:button_copy), {:controller => 'issues', :action => 'move', :ids => @issues.collect(&:id), :copy_options => {:copy => 't'}},
|
||||
:class => 'icon-copy', :disabled => !@can[:move] %></li>
|
||||
<% end %>
|
||||
|
||||
<li><%= context_menu_link l(:button_move), {:controller => 'issues', :action => 'move', :ids => @issues.collect(&:id)},
|
||||
:class => 'icon-move', :disabled => !@can[:move] %></li>
|
||||
<li><%= context_menu_link l(:button_delete), {:controller => 'issues', :action => 'destroy', :ids => @issues.collect(&:id)},
|
||||
|
||||
@@ -21,8 +21,30 @@
|
||||
<p><label for="new_tracker_id"><%=l(:field_tracker)%>:</label>
|
||||
<%= select_tag "new_tracker_id", "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(@trackers, "id", "name") %></p>
|
||||
|
||||
<p>
|
||||
<label><%= l(:field_assigned_to) %></label>
|
||||
<%= select_tag('assigned_to_id', content_tag('option', l(:label_no_change_option), :value => '') +
|
||||
content_tag('option', l(:label_nobody), :value => 'none') +
|
||||
options_from_collection_for_select(@target_project.assignable_users, :id, :name)) %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label><%= l(:field_status) %></label>
|
||||
<%= select_tag('status_id', "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(@available_statuses, :id, :name)) %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label><%= l(:field_start_date) %></label>
|
||||
<%= text_field_tag 'start_date', '', :size => 10 %><%= calendar_for('start_date') %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label><%= l(:field_due_date) %></label>
|
||||
<%= text_field_tag 'due_date', '', :size => 10 %><%= calendar_for('due_date') %>
|
||||
</p>
|
||||
|
||||
<p><label for="copy_options_copy"><%= l(:button_copy)%></label>
|
||||
<%= check_box_tag "copy_options[copy]", "1" %></p>
|
||||
<%= check_box_tag "copy_options[copy]", "1", @copy %></p>
|
||||
</div>
|
||||
|
||||
<%= submit_tag l(:button_move) %>
|
||||
|
||||
Reference in New Issue
Block a user