3654: add selection dropdown to collections pages
[arvados.git] / apps / workbench / app / controllers / actions_controller.rb
index 5c3d82749b2c6cff3d723fda6acdcd3de0e8a4fb..7c68ce9f7bfa37c8a6eca526774dfa6b3b6dc9ff 100644 (file)
@@ -45,7 +45,48 @@ class ActionsController < ApplicationController
 
   def move_or_copy action
     uuids_to_add = params["selection"]
-    move_or_copy_items action, uuids_to_add, @object.uuid
+    uuids_to_add = [ uuids_to_add ] unless uuids_to_add.is_a? Array
+    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 |src|
+        if resource_class == Collection and not Collection.attribute_info.include?(:name)
+          dst = Link.new(owner_uuid: @object.uuid,
+                         tail_uuid: @object.uuid,
+                         head_uuid: src.uuid,
+                         link_class: 'name',
+                         name: src.uuid)
+        else
+          case action
+          when :copy
+            dst = src.dup
+            if dst.respond_to? :'name='
+              if dst.name
+                dst.name = "Copy of #{dst.name}"
+              else
+                dst.name = "Copy of unnamed #{dst.class_for_display.downcase}"
+              end
+            end
+            if resource_class == Collection
+              dst.manifest_text = Collection.select([:manifest_text]).where(uuid: src.uuid).first.manifest_text
+            end
+          when :move
+            dst = src
+          else
+            raise ArgumentError.new "Unsupported action #{action}"
+          end
+          dst.owner_uuid = @object.uuid
+          dst.tail_uuid = @object.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
     redirect_to @object
   end
 
@@ -123,7 +164,13 @@ class ActionsController < ApplicationController
       l.save!
     end
 
-    redirect_to controller: 'collections', action: :show, id: newc.uuid
+    if params["show_project"]
+      respond_to do |format|
+        format.js {render inline: "location.reload();" }
+      end
+    else
+      redirect_to controller: 'collections', action: :show, id: newc.uuid
+    end
   end
 
   def report_issue_popup