Merge branch 'master' into 2985-selection-button-move-copy
authorradhika <radhika@curoverse.com>
Wed, 30 Jul 2014 19:01:07 +0000 (15:01 -0400)
committerradhika <radhika@curoverse.com>
Wed, 30 Jul 2014 19:01:07 +0000 (15:01 -0400)
apps/workbench/app/controllers/projects_controller.rb
apps/workbench/app/views/application/_choose.js.erb
apps/workbench/app/views/projects/_show_tab_contents.html.erb
apps/workbench/config/routes.rb

index f32f356d0ca88257adaa4ff5969cadcaef326659..d243ef426800b44fe5cd9b351be67bc33b8222d4 100644 (file)
@@ -52,6 +52,37 @@ class ProjectsController < ApplicationController
     end
   end
 
+  def move_items
+    target_uuid = params['target']
+    uuids_to_add = session[:selected_move_items]
+
+    uuids_to_add.
+      collect { |x| ArvadosBase::resource_class_for_uuid(x) }.
+      uniq.
+      each do |resource_class|
+      resource_class.filter([['uuid','in',uuids_to_add]]).each do |dst|
+        if resource_class == Collection
+          dst = Link.new(owner_uuid: target_uuid,
+                         tail_uuid: target_uuid,
+                         head_uuid: dst.uuid,
+                         link_class: 'name',
+                         name: target_uuid)
+        else
+          dst.owner_uuid = target_uuid
+          dst.tail_uuid = target_uuid if dst.class == Link
+        end
+        begin
+          dst.save!
+        rescue
+          dst.name += " (#{Time.now.localtime})" if dst.respond_to? :name=
+          dst.save!
+        end
+      end
+    end
+    session[:selected_move_items] = nil
+    redirect_to @object
+  end
+
   def destroy
     while (objects = Link.filter([['owner_uuid','=',@object.uuid],
                                   ['tail_uuid','=',@object.uuid]])).any?
index 2d189753ff2c96d9a0770f847d448055f9981f6d..58ebc6f57e9a58b250887088fe089007ef799573 100644 (file)
@@ -1,3 +1,4 @@
+<% session[:selected_move_items] = params['move_items'] if params['move_items'] %>
 $('body > .modal-container').html("<%= escape_javascript(render partial: 'choose.html', locals: {multiple: multiple}) %>");
 $('body > .modal-container .modal').modal('show');
 $('body > .modal-container .modal .modal-footer .btn-primary').
index 36f1907a3da8bf84a3fbba0bca92a8b37cd14146..df37d3e1c7051ad6b1da1fcb0af7fb77d6aecc91 100644 (file)
                   'data-selection-action' => 'remove',
                   'data-remote' => true,
                   'method' => 'delete'
+            %></li>
+                 <li><%= link_to "Move selected", '#',
+                         'data-href' => choose_projects_path(
+                                   title: 'Move to...',
+                                   editable: true,
+                                   action_name: 'Move',
+                                   action_href: move_items_project_path,
+                                   action_method: 'get',
+                                   action_data: {selection_param: 'target',
+                                                 success: 'page-refresh'}.to_json),
+                  'data-remote' => true,
+                  'data-selection-param-name' => 'move_items[]',
+                             'data-selection-action' => 'move'
             %></li>
         </ul>
       </div>
index fe6200bda8edb5e1ace1dab3551dcf13f04164f9..2b254eed091f411c27d14accdaa136b4676bb1e1 100644 (file)
@@ -63,6 +63,7 @@ ArvadosWorkbench::Application.routes.draw do
   resources :projects do
     match 'remove/:item_uuid', on: :member, via: :delete, action: :remove_item
     match 'remove_items', on: :member, via: :delete, action: :remove_items
+    get 'move_items', on: :member, action: :move_items
     get 'choose', on: :collection
     post 'share_with', on: :member
   end