Add "Copy selections to current folder" button to selection drop-down.
authorTom Clegg <tom@curoverse.com>
Fri, 2 May 2014 02:23:57 +0000 (22:23 -0400)
committerTom Clegg <tom@curoverse.com>
Fri, 2 May 2014 02:23:57 +0000 (22:23 -0400)
apps/workbench/app/assets/javascripts/selection.js
apps/workbench/app/assets/stylesheets/selection.css
apps/workbench/app/controllers/actions_controller.rb
apps/workbench/app/controllers/application_controller.rb
apps/workbench/app/controllers/folders_controller.rb
apps/workbench/app/models/arvados_resource_list.rb
apps/workbench/app/views/folders/show.html.erb
apps/workbench/app/views/layouts/application.html.erb

index d70794dc0a58f41ea71b59b2258934766a824cab..f8dbed59c4f0a2f072189670c5be84bac5fecab6 100644 (file)
@@ -49,15 +49,21 @@ jQuery(function($){
     }
 
     var update_count = function(e) {
+        var html;
+        var this_object_uuid = $('#selection-form-content').
+            closest('form').
+            find('input[name=uuid]').val();
         var lst = get_selection_list();
         $("#persistent-selection-count").text(lst.length);
         if (lst.length > 0) {
-            $('#selection-form-content').html(
-                '<li><a href="#" id="clear_selections_button">Clear selections</a></li>'
-                    + '<li><input type="submit" name="combine_selected_files_into_collection" '
-                    + ' id="combine_selected_files_into_collection" '
-                    + ' value="Combine selected collections and files into a new collection" /></li>'
-                    + '<li class="notification"><table style="width: 100%"></table></li>');
+            html = '<li><a href="#" class="btn btn-xs btn-info" id="clear_selections_button"><i class="fa fa-fw fa-ban"></i> Clear selections</a></li>';
+            if (this_object_uuid.match('-j7d0g-'))
+                html += '<li><button class="btn btn-xs btn-info" type="submit" name="copy_selections_into_folder" id="copy_selections_into_folder"><i class="fa fa-fw fa-folder-open"></i> Copy selections into this folder</button></li>';
+            html += '<li><button class="btn btn-xs btn-info" type="submit" name="combine_selected_files_into_collection" '
+                + ' id="combine_selected_files_into_collection">'
+                + '<i class="fa fa-fw fa-archive"></i> Combine selected collections and files into a new collection</button></li>'
+                + '<li class="notification"><table style="width: 100%"></table></li>';
+            $('#selection-form-content').html(html);
 
             for (var i = 0; i < lst.length; i++) {
                 $('#selection-form-content > li > table').append("<tr>"
index 147d6fe93b45a741e5ce41c2336fb59509d13cfa..5e0da41b7a676b92b61d0b7433142956c631e0cd 100644 (file)
@@ -2,18 +2,8 @@
     width: 500px;
 }
 
-#selection-form-content > li > a, #selection-form-content > li > input {
-    display: block;
-    padding: 3px 20px;
-    clear: both;
-    font-weight: normal;
-    line-height: 1.42857;
-    color: rgb(51, 51, 51);
-    white-space: nowrap;    
-    border: none;
-    background: transparent;
-    width: 100%;
-    text-align: left;
+#selection-form-content > li > a, #selection-form-content > li > button {
+    margin: 3px 20px;
 }
 
 #selection-form-content li table tr {
@@ -22,8 +12,6 @@
     border-top: 1px solid rgb(221, 221, 221);
 }
 
-#selection-form-content a:hover, #selection-form-content a:focus, #selection-form-content input:hover, #selection-form-content input:focus, #selection-form-content tr:hover {
-    text-decoration: none;
-    color: rgb(38, 38, 38);
-    background-color: whitesmoke;
-}
\ No newline at end of file
+#selection-form-content li table tr:last-child {
+    border-bottom: 1px solid rgb(221, 221, 221);
+}
index 8a817f03cd78e52dc61ab7c57bff4dc12ff3fe8a..87b14480a80f826a5a1ab59eb83b48f37c3d2595 100644 (file)
@@ -1,8 +1,39 @@
 class ActionsController < ApplicationController
 
-  skip_before_filter :find_object_by_uuid, only: :post
+  @@exposed_actions = {}
+  def self.expose_action method, &block
+    @@exposed_actions[method] = true
+    define_method method, block
+  end
+
+  def model_class
+    ArvadosBase::resource_class_for_uuid(params[:uuid])
+  end
+
+  def post
+    params.keys.collect(&:to_sym).each do |param|
+      if @@exposed_actions[param]
+        return self.send(param.to_s)
+      end
+    end
+    redirect_to :back
+  end
+
+  expose_action :copy_selections_into_folder do
+    already_named = Link.
+      filter([['tail_uuid','=',@object.uuid],
+              ['head_uuid','in',params["selection"]]]).
+      collect(&:head_uuid)
+    (params["selection"] - already_named).each do |s|
+      Link.create(tail_uuid: @object.uuid,
+                  head_uuid: s,
+                  link_class: 'name',
+                  name: "#{s} added #{Time.now}")
+    end
+    redirect_to @object
+  end
 
-  def combine_selected_files_into_collection
+  expose_action :combine_selected_files_into_collection do
     lst = []
     files = []
     params["selection"].each do |s|
@@ -87,11 +118,4 @@ class ActionsController < ApplicationController
     redirect_to controller: 'collections', action: :show, id: newc.uuid
   end
 
-  def post
-    if params["combine_selected_files_into_collection"]
-      combine_selected_files_into_collection
-    else
-      redirect_to :back
-    end
-  end
 end
index e9d4dd5a97fcaaf158161da9fa02147edfda267d..c7c3520b58e11dd1d599cd60849524ba3819b8e5 100644 (file)
@@ -200,8 +200,14 @@ class ApplicationController < ActionController::Base
     if params[:id] and params[:id].match /\D/
       params[:uuid] = params.delete :id
     end
-    if params[:uuid].is_a? String
-      @object = model_class.find(params[:uuid])
+    if not model_class
+      @object = nil
+    elsif params[:uuid].is_a? String
+      if params[:uuid].empty?
+        @object = nil
+      else
+        @object = model_class.find(params[:uuid])
+      end
     else
       @object = model_class.where(uuid: params[:uuid]).first
     end
index 43b6f407b877a3c583e2cf41781c6b23038aa7ef..0c9b963fa179d7b00c15a196ce92fe9fdcd1a8fa 100644 (file)
@@ -35,6 +35,7 @@ class FoldersController < ApplicationController
         @shared_with_me << folder
       end
     end
+    @object
   end
 
   def show
@@ -42,6 +43,22 @@ class FoldersController < ApplicationController
     @share_links = Link.filter([['head_uuid', '=', @object.uuid],
                                 ['link_class', '=', 'permission']])
     @logs = Log.limit(10).filter([['object_uuid', '=', @object.uuid]])
+
+    @objects_and_names = []
+    @objects.each do |object|
+      if !(name_links = @objects.links_for(object, 'name')).empty?
+        name_links.each do |name_link|
+          @objects_and_names << [object, name_link]
+        end
+      else
+        @objects_and_names << [object,
+                               Link.new(tail_uuid: @object.uuid,
+                                        head_uuid: object.uuid,
+                                        link_class: "name",
+                                        name: "")]
+      end
+    end
+
     super
   end
 
index f6bcaae9b126b357499e9f3d93ae402f3fe559a5..d585b3ca9df22afad4314c056341be9398e2cf8f 100644 (file)
@@ -164,7 +164,8 @@ class ArvadosResourceList
     end
   end
 
-  def name_for item_or_uuid
+  # Note: this arbitrarily chooses one of (possibly) multiple names.
+  def names_for item_or_uuid
     links_for(item_or_uuid, 'name').first.andand.name
   end
 
index 505a8c27b7b714815b9f18d1a0dd6aa3f83976bc..200b0f36e39bb1e562965c76287928bf813667dc 100644 (file)
               <col width="15%" />
               <col width="29%" />
             </colgroup>
-            <% @objects.each do |object| %>
+            <% @objects_and_names.each do |object, name_link| %>
             <tr>
               <td>
                 <%= render :partial => "selection_checkbox", :locals => {object: object} %>
                 <%= render :partial => "show_object_button", :locals => {object: object, size: 'xs'} %>
               </td>
               <td>
-                <% name_link = @objects.links_for(object, 'name').first || Link.new(link_class: "name", owner_uuid: @object.uuid, tail_uuid: @object.uuid, head_uuid: object.uuid, name: "") %>
                 <%= render_editable_attribute name_link, 'name', nil, { 'data-emptytext' => "Unnamed #{object.class}" } %>
               </td>
               <td>
index d87399110fbd86d347bfc2aa4d919661fca1643e..a7a9750a3ec84aff96eb752d4e7c1dd97e0af5d7 100644 (file)
             </a>
               <ul class="dropdown-menu" role="menu" id="persistent-selection-list">
                 <%= form_tag '/actions' do %>
+                <%= hidden_field_tag 'uuid', @object.andand.uuid %>
                 <div id="selection-form-content"></div>
                 <% end %>
             </ul>