POST works to actions controller, still need to implement the actual action to build...
authorPeter Amstutz <peter.amstutz@curoverse.com>
Fri, 28 Feb 2014 18:47:58 +0000 (13:47 -0500)
committerPeter Amstutz <peter.amstutz@curoverse.com>
Fri, 28 Feb 2014 18:47:58 +0000 (13:47 -0500)
apps/workbench/app/assets/javascripts/selection.js
apps/workbench/app/controllers/actions_controller.rb [new file with mode: 0644]
apps/workbench/app/controllers/application_controller.rb
apps/workbench/app/helpers/collections_helper.rb
apps/workbench/app/views/collections/_show_files.html.erb
apps/workbench/app/views/layouts/application.html.erb
apps/workbench/config/routes.rb

index c8ec8100ac90c7fdb2c559c9f73feac4603443a8..ef1c59230bf4ac8f2756d89446040da789fafba6 100644 (file)
@@ -40,7 +40,6 @@ jQuery(function($){
     };
 
     var remove_selection_click = function(e) {
-        //remove_selection($(this).attr('name'));
         remove_selection($(this).val());
     };
 
@@ -49,23 +48,26 @@ jQuery(function($){
         update_count();
     }
 
+    var combine_selected_files_into_collection = function () {
+        
+    }
+
     var update_count = function(e) {
         var lst = get_selection_list();
         $("#persistent-selection-count").text(lst.length);
 
         if (lst.length > 0) {
-            $('#persistent-selection-list').html('<li><a href="#" class="btn pull-right" id="clear_selections_button">Clear selections</a></li>'
-                                                 +'<li class="notification"><table style="width: 100%"></table></li>');
+            $('#selection-form-content').html('<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><a href="#" id="clear_selections_button">Clear selections</a></li>'
+                                                 + '<li class="notification"><table style="width: 100%"></table></li>');
             for (var i = 0; i < lst.length; i++) {
-                $('#persistent-selection-list > li > table').append("<tr>"
+                $('#selection-form-content > li > table').append("<tr>"
                                                        + "<td>"
-                                                       + "<form>"
-                                                       + "<input class='remove-selection' type='checkbox' value='" + lst[i].uuid + "' checked='true'></input>"
-                                                       + "</form>"
+                                                       + "<input class='remove-selection' name='selection[]' type='checkbox' value='" + lst[i].uuid + "' checked='true'></input>"
                                                        + "</td>"
 
                                                        + "<td>"
-                                                       + "<span style='padding-left: 1em'><a href=\"" + lst[i].href + "\">" + lst[i].name + "</a></span>"
+                                                       + "<div style='padding-left: 1em'><a href=\"" + lst[i].href + "\">" + lst[i].name + "</a></div>"
                                                        + "</td>"
 
                                                        + "<td style=\"vertical-align: top\">"
@@ -93,6 +95,7 @@ jQuery(function($){
         
         $('.remove-selection').on('click', remove_selection_click);
         $('#clear_selections_button').on('click', clear_selections);
+        $('#combine_selected_files_into_collection').on('click', combine_selected_files_into_collection);
     };
 
     $(document).
diff --git a/apps/workbench/app/controllers/actions_controller.rb b/apps/workbench/app/controllers/actions_controller.rb
new file mode 100644 (file)
index 0000000..94bfd1e
--- /dev/null
@@ -0,0 +1,27 @@
+class ActionsController < ApplicationController
+  def combine_selected_files_into_collection
+    lst = []
+    params["selection"].each do |s|
+      m = CollectionsHelper.match(s)
+      if m
+        lst.append(m[1] + m[2])
+      end
+    end
+
+    collections = Collection.where(uuid: lst)
+    
+    collections.each do |c| 
+      puts c.manifest_text
+    end
+
+    '/'
+  end
+
+  def post
+    if params["combine_selected_files_into_collection"]
+      redirect_to combine_selected_files_into_collection
+    else
+      redirect_to :back
+    end
+  end
+end
index 412f86ce07a6b874d05b7d5d796bb84a9017bf09..2790f96472f0cac1633340465bc8524bf20f6940 100644 (file)
@@ -4,7 +4,7 @@ class ApplicationController < ActionController::Base
   around_filter :thread_clear
   around_filter :thread_with_mandatory_api_token, :except => [:render_exception, :render_not_found]
   around_filter :thread_with_optional_api_token
-  before_filter :find_object_by_uuid, :except => [:index, :render_exception, :render_not_found]
+  before_filter :find_object_by_uuid, :except => [:index, :post, :render_exception, :render_not_found]
   before_filter :check_user_agreements, :except => [:render_exception, :render_not_found]
   before_filter :check_user_notifications, :except => [:render_exception, :render_not_found]
   theme :select_theme
index df0ba22eac92f411ed58a268ccfd5b6a4cb2af8d..7b548dfb84b4ae25a2bbe2e57ffa265d29118277 100644 (file)
@@ -6,6 +6,6 @@ module CollectionsHelper
   end
 
   def self.match(uuid)
-    /^([a-f0-9]{32}(\+[0-9]+)?)(\+.*)?$/.match(uuid.to_s)
+    /^([a-f0-9]{32})(\+[0-9]+)?(\+.*?)?(\/.*)?$/.match(uuid.to_s)
   end
 end
index 705ded388a28ba1837c07f84ef9c4324451dfe9e..a8535ab2595b75b7b33c7c3a5b3868b491cbdf18 100644 (file)
     <% file_path = "#{file[0]}/#{file[1]}" %>
     <tr>
       <td>
-        <% fp2 = file_path[2..-1] if file_path[0..1] == './' %>
-        <% fp2 ||= file_path %>
-<%= check_box_tag 'uuids[]', @object.uuid+file_path, false, {
-  :class => 'persistent-selection', 
-  :friendly_type => "File",
-  :friendly_name => "#{@object.uuid}/#{fp2}",
-  :href => "#{url_for controller: 'collections', action: 'show', id: @object.uuid }/#{file_path}" 
-      } %>
+        <% puts "#{file[0]} #{file[1]} #{file_path}" %>
+        <%= check_box_tag 'uuids[]', @object.uuid+file_path, false, {
+              :class => 'persistent-selection', 
+              :friendly_type => "File",
+              :friendly_name => "#{@object.uuid}/#{file_path}",
+              :href => "#{url_for controller: 'collections', action: 'show', id: @object.uuid }/#{file_path}" 
+            } %>
       </td>
       <td>
         <%= file[0] %>
index 68f0e109bd3a125a5087f808c93e701812785464..abef47136fd21dd90ae67cf246b51431344ef7b8 100644 (file)
             <span class="badge" id="persistent-selection-count"></span>
             <span class="caret"></span>
           </a>
-          <ul class="dropdown-menu" role="menu" id="persistent-selection-list">
+            <ul class="dropdown-menu" role="menu" id="persistent-selection-list">
+              <%= form_tag '/actions' do %>
+              <div id="selection-form-content"></div>
+              <% end %>
           </ul>
         </li>
 
index 5330a9148a2f8574c0d410e8ff83acb67eaa4911..51aa4e082a697fcb2d7eba7f9402cc0da8f3f49f 100644 (file)
@@ -33,6 +33,9 @@ ArvadosWorkbench::Application.routes.draw do
   match '/collections/graph' => 'collections#graph'
   resources :collections
   get '/collections/:uuid/*file' => 'collections#show_file', :format => false
+
+  post 'actions' => 'actions#post'
+
   root :to => 'users#welcome'
 
   # Send unroutable requests to an arbitrary controller