2985: move selection items to the chosen project
authorradhika <radhika@curoverse.com>
Mon, 28 Jul 2014 01:46:44 +0000 (21:46 -0400)
committerradhika <radhika@curoverse.com>
Mon, 28 Jul 2014 01:46:44 +0000 (21:46 -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..785773688d0f0de3d121b9b3cd73722015f66e3d 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_object.uuid,
+                         tail_uuid: target_object.uuid,
+                         head_uuid: target_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 controller: 'projects', action: :show, id: target_uuid
+  end
+
   def destroy
     while (objects = Link.filter([['owner_uuid','=',@object.uuid],
                                   ['tail_uuid','=',@object.uuid]])).any?
index b033c9bf2fedf170c765b178bb510494707888ca..f1abd34d7a793aca5e0af462f27c17e7d96969ce 100644 (file)
@@ -1,3 +1,4 @@
+<% session[:selected_move_items] = 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 0f2ad6f4988f7f51b41aa3c27124b400b5de4e64..df37d3e1c7051ad6b1da1fcb0af7fb77d6aecc91 100644 (file)
                   'data-remote' => true,
                   'method' => 'delete'
             %></li>
-         <li><%= link_to "Move selected", '#',
-                 'data-href' => choose_projects_path(
+                 <li><%= link_to "Move selected", '#',
+                         'data-href' => choose_projects_path(
                                    title: 'Move to...',
                                    editable: true,
                                    action_name: 'Move',
-                                   action_href: url_for(action: :move_selections_into_project,
-                                                        controller: 'actions'),
-                                   action_method: 'patch',
-                                   action_data: {selection_param: 'selection[]',
+                                   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' => 'selection[]',
-                 'data-selection-action' => 'move'
+                  'data-selection-param-name' => 'move_items[]',
+                             'data-selection-action' => 'move'
             %></li>
         </ul>
       </div>
index 15cd178d14a02f65f6a53d5a9ce222de229197b2..565553692d16e6127a22ac7f1042721ee8f57b41 100644 (file)
@@ -63,10 +63,10 @@ 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
-  match '/move_selections_into_project' => 'actions#move_selections_into_project', via: :patch
   post 'actions' => 'actions#post'
   get 'websockets' => 'websocket#index'