3821: added 'Remove selected files' to collection#show page.
authorradhika <radhika@curoverse.com>
Fri, 24 Mar 2017 14:26:56 +0000 (10:26 -0400)
committerradhika <radhika@curoverse.com>
Fri, 24 Mar 2017 14:26:56 +0000 (10:26 -0400)
apps/workbench/app/controllers/actions_controller.rb
apps/workbench/app/controllers/application_controller.rb
apps/workbench/app/controllers/collections_controller.rb
apps/workbench/app/views/collections/_show_files.html.erb
apps/workbench/config/routes.rb

index 28680df33f3cf4f5902d5abdc278c305011018f2..55e4e9aa4a0227ac4b68e064451e9d51ebcfd834 100644 (file)
@@ -114,42 +114,7 @@ class ActionsController < ApplicationController
   end
 
   expose_action :combine_selected_files_into_collection do
-    link_uuids, coll_ids = params["selection"].partition do |sel_s|
-      ArvadosBase::resource_class_for_uuid(sel_s) == Link
-    end
-
-    unless link_uuids.empty?
-      Link.select([:head_uuid]).where(uuid: link_uuids).each do |link|
-        if ArvadosBase::resource_class_for_uuid(link.head_uuid) == Collection
-          coll_ids << link.head_uuid
-        end
-      end
-    end
-
-    uuids = []
-    pdhs = []
-    source_paths = Hash.new { |hash, key| hash[key] = [] }
-    coll_ids.each do |coll_id|
-      if m = CollectionsHelper.match(coll_id)
-        key = m[1] + m[2]
-        pdhs << key
-        source_paths[key] << m[4]
-      elsif m = CollectionsHelper.match_uuid_with_optional_filepath(coll_id)
-        key = m[1]
-        uuids << key
-        source_paths[key] << m[4]
-      end
-    end
-
-    unless pdhs.empty?
-      Collection.where(portable_data_hash: pdhs.uniq).
-          select([:uuid, :portable_data_hash]).each do |coll|
-        unless source_paths[coll.portable_data_hash].empty?
-          uuids << coll.uuid
-          source_paths[coll.uuid] = source_paths.delete(coll.portable_data_hash)
-        end
-      end
-    end
+    uuids, source_paths = selected_collection_files params
 
     new_coll = Arv::Collection.new
     Collection.where(uuid: uuids.uniq).
index 23b8788bcb17520b4e8ca71f493b514c0fcda9f3..a63fe6e21f1311a353392a2bc2f27f656147bee5 100644 (file)
@@ -1250,6 +1250,49 @@ class ApplicationController < ActionController::Base
     end
   end
 
+  # helper method to get the names of collection files selected
+  helper_method :selected_collection_files
+  def selected_collection_files params
+    link_uuids, coll_ids = params["selection"].partition do |sel_s|
+      ArvadosBase::resource_class_for_uuid(sel_s) == Link
+    end
+
+    unless link_uuids.empty?
+      Link.select([:head_uuid]).where(uuid: link_uuids).each do |link|
+        if ArvadosBase::resource_class_for_uuid(link.head_uuid) == Collection
+          coll_ids << link.head_uuid
+        end
+      end
+    end
+
+    uuids = []
+    pdhs = []
+    source_paths = Hash.new { |hash, key| hash[key] = [] }
+    coll_ids.each do |coll_id|
+      if m = CollectionsHelper.match(coll_id)
+        key = m[1] + m[2]
+        pdhs << key
+        source_paths[key] << m[4]
+      elsif m = CollectionsHelper.match_uuid_with_optional_filepath(coll_id)
+        key = m[1]
+        uuids << key
+        source_paths[key] << m[4]
+      end
+    end
+
+    unless pdhs.empty?
+      Collection.where(portable_data_hash: pdhs.uniq).
+          select([:uuid, :portable_data_hash]).each do |coll|
+        unless source_paths[coll.portable_data_hash].empty?
+          uuids << coll.uuid
+          source_paths[coll.uuid] = source_paths.delete(coll.portable_data_hash)
+        end
+      end
+    end
+
+    [uuids, source_paths]
+  end
+
   def wiselinks_layout
     'body'
   end
index be58b91871f1a7a51fdeb28dc854425af9d8e68a..fc7fd885c8bd1f01aab73d650caf777fc082685e 100644 (file)
@@ -293,6 +293,21 @@ class CollectionsController < ApplicationController
     sharing_popup
   end
 
+  def remove_selected_files
+    uuids, source_paths = selected_collection_files params
+
+    arv_coll = Arv::Collection.new(@object.manifest_text)
+    source_paths[uuids[0]].each do |p|
+      arv_coll.rm "."+p
+    end
+
+    if @object.update_attributes manifest_text: arv_coll.manifest_text
+      show
+    else
+      self.render_error status: 422
+    end
+  end
+
   protected
 
   def find_usable_token(token_list)
index a21a514c47de1c51ec184dbe1531d5785c2b68d9..a363bae00125748dc0f8d7ed53de9ecf225bd337 100644 (file)
                     'data-selection-action' => 'combine-collections',
                     'data-toggle' => 'dropdown'
               %></li>
+            <li><%= link_to "Remove selected files", '#',
+                    method: :post,
+                    'data-href' => url_for(action: :remove_selected_files),
+                    'data-selection-param-name' => 'selection[]',
+                    'data-selection-action' => 'remove-selected-files',
+                    'data-toggle' => 'dropdown'
+              %></li>
           </ul>
         </div>
         <div class="btn-group btn-group-sm">
index 0d5b8fca83a3a789776baa48b9ea0556767df210..0eef73f8ae3d0116ba96ccf8f93f6663fc4204e8 100644 (file)
@@ -87,6 +87,7 @@ ArvadosWorkbench::Application.routes.draw do
     post 'share', :on => :member
     post 'unshare', :on => :member
     get 'choose', on: :collection
+    post 'remove_selected_files', on: :member
   end
   get('/collections/download/:uuid/:reader_token/*file' => 'collections#show_file',
       format: false)