Project

General

Profile

Feature #4403 » implement_custom_copies.patch

implementation of custom copies (missing creation UI) - James Bernard, 2009-12-21 02:57

View differences:

app/controllers/issues_controller.rb (working copy)
111 111
    @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
112 112
    @priorities = IssuePriority.all
113 113
    @time_entry = TimeEntry.new
114
    @custom_copies = CustomCopy.find(:all,
115
      :conditions => "source_project_id=#{@issue.project.id} and source_tracker_id=#{@issue.tracker.id} and source_status_id=#{@issue.status.id}")
114 116
    respond_to do |format|
115 117
      format.html { render :template => 'issues/show.rhtml' }
116 118
      format.atom { render :action => 'changes', :layout => false, :content_type => 'application/atom+xml' }
......
276 278
  end
277 279

  
278 280
  def move
281
    if (params[:custom_copy])
282
       custom_copy = CustomCopy.find(params[:custom_copy])
283
       redirect_to :controller => 'issues', :action => 'move', :id => params[:id],
284
       :copy_options => {:copy => 't'},
285
       :new_project_id => custom_copy.target_project_id,
286
       :new_tracker_id => custom_copy.target_tracker_id,
287
       :status_id => custom_copy.target_status_id,
288
       :copied_status_id => custom_copy.source_post_status_id,
289
       :follow => '1'
290
    end
291
    is_custom_copy = params[:new_project_id]
292

  
279 293
    @copy = params[:copy_options] && params[:copy_options][:copy]
280 294
    @allowed_projects = []
281 295
    # find projects to which the user is allowed to move the issue
......
289 303
    @target_project ||= @project    
290 304
    @trackers = @target_project.trackers
291 305
    @available_statuses = Workflow.available_statuses(@project)
292
    if request.post?
306
    if request.post? || is_custom_copy
293 307
      new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id])
294 308
      unsaved_issue_ids = []
295 309
      moved_issues = []
......
303 317
        issue.init_journal(User.current)
304 318
        if r = issue.move_to(@target_project, new_tracker, {:copy => @copy, :attributes => changed_attributes})
305 319
          moved_issues << r
320
          if is_custom_copy && params[:copied_status_id]
321
            copied_status = IssueStatus.find(params[:copied_status_id])
322
            if copied_status && @available_statuses.include?(copied_status)
323
              issue.status = copied_status
324
              issue.save
325
              relation = IssueRelation.new(params[:relation])
326
              relation.issue_from    = issue
327
              relation.issue_to      = r
328
              relation.relation_type = IssueRelation::TYPE_RELATES
329
              relation.save
330
            end
331
          end
306 332
        else
307 333
          unsaved_issue_ids << issue.id
308 334
        end
app/models/custom_copy.rb (revision 3208)
1
# Redmine - project management software
2
# Copyright (C) 2006-2009  Jean-Philippe Lang
3
#
4
# This program is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU General Public License
6
# as published by the Free Software Foundation; either version 2
7
# of the License, or (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
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
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17

  
18
class CustomCopy < ActiveRecord::Base
19
   belongs_to :project, :foreign_key => 'source_project_id'
20
   belongs_to :tracker, :foreign_key => 'source_tracker_id'
21
   belongs_to :issue_status, :foreign_key => 'source_status_id'
22
   belongs_to :issue_status, :foreign_key => 'source_post_status_id'
23
   belongs_to :project, :foreign_key => 'target_project_id'
24
   belongs_to :tracker, :foreign_key => 'target_tracker_id'
25
   belongs_to :issue_status, :foreign_key => 'target_status_id'
26

  
27
end
app/views/issues/_action_menu.rhtml (working copy)
7 7
<%= link_to_if_authorized l(:button_copy), {:controller => 'issues', :action => 'move', :id => @issue, :copy_options => {:copy => 't'} }, :class => 'icon icon-copy' %>
8 8
<%= link_to_if_authorized l(:button_move), {:controller => 'issues', :action => 'move', :id => @issue }, :class => 'icon icon-move' %>
9 9
<%= link_to_if_authorized l(:button_delete), {:controller => 'issues', :action => 'destroy', :id => @issue}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %>
10

  
11
<% @custom_copies.each do |custom_copy| %>
12
	<%= link_to_if_authorized h(custom_copy.label), {:controller => 'issues', :action => 'move', :id => @issue, :custom_copy => custom_copy.id }, :class => 'icon icon-copy' %>
13
<% end %>
14

  
10 15
</div>
db/migrate/20091217215900_create_custom_copies.rb (revision 3208)
1
class CreateCustomCopies < ActiveRecord::Migration
2
  def self.up
3
    create_table :custom_copies do |t|
4
      t.column :label, :string, :limit => 40, :default => "", :null => false
5
      t.column :source_project_id, :integer, :null => false
6
      t.column :source_tracker_id, :integer, :null => false
7
      t.column :source_status_id,  :integer, :null => false
8
      t.column :source_post_status_id,  :integer, :null => false
9
      t.column :target_project_id, :integer, :null => false
10
      t.column :target_tracker_id, :integer, :null => false
11
      t.column :target_status_id,  :integer, :null => false
12
    end
13
  end
14

  
15
  def self.down
16
    drop_table :custom_copies
17
  end
18
end
(1-1/5)