[ARVADOS] updated: 98f0657745f2f38c19047ef9039c52c1b0fe0659

git at public.curoverse.com git at public.curoverse.com
Mon Feb 24 14:28:51 EST 2014


Summary of changes:
 .../app/assets/javascripts/application.js          |   70 +--------------
 apps/workbench/app/assets/javascripts/selection.js |  100 ++++++++++++++++++++
 .../app/assets/stylesheets/application.css.scss    |   18 ++++-
 apps/workbench/app/models/arvados_base.rb          |    4 +
 apps/workbench/app/models/collection.rb            |   19 ++++
 .../views/application/_selection_checkbox.html.erb |    6 +
 .../app/views/application/_show_recent.html.erb    |    2 +-
 .../app/views/collections/_index_tbody.html.erb    |    2 +-
 .../app/views/collections/_show_files.html.erb     |   11 ++
 .../app/views/layouts/application.html.erb         |   16 ++--
 10 files changed, 167 insertions(+), 81 deletions(-)
 create mode 100644 apps/workbench/app/assets/javascripts/selection.js
 create mode 100644 apps/workbench/app/views/application/_selection_checkbox.html.erb

       via  98f0657745f2f38c19047ef9039c52c1b0fe0659 (commit)
      from  e2bee889bc406f30b66337d823242869abe7e98d (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit 98f0657745f2f38c19047ef9039c52c1b0fe0659
Author: Peter Amstutz <peter.amstutz at curoverse.com>
Date:   Mon Feb 24 14:30:02 2014 -0500

    Frontend feature to add items to locally-stored selection list that is session-persistent.

diff --git a/apps/workbench/app/assets/javascripts/application.js b/apps/workbench/app/assets/javascripts/application.js
index fb6fe9a..0535ba1 100644
--- a/apps/workbench/app/assets/javascripts/application.js
+++ b/apps/workbench/app/assets/javascripts/application.js
@@ -21,7 +21,7 @@
 //= require bootstrap3-editable/bootstrap-editable
 //= require_tree .
 
-jQuery(function($){
+(function($){
     $.ajaxSetup({
         headers: {
             'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')
@@ -42,82 +42,14 @@ jQuery(function($){
         targets.fadeToggle(200);
     });
 
-    var add_selection = function(v) {
-        var lst = JSON.parse(localStorage.persistentSelection);
-        lst.push(v);
-        localStorage.persistentSelection = JSON.stringify(lst);
-        update_count();
-    };
-
-    var remove_selection = function(v) {
-        var lst = JSON.parse(localStorage.persistentSelection);
-        var i = jQuery.inArray(v, lst);
-        if (i > -1) {
-            lst.splice(i, 1);
-        }
-        localStorage.persistentSelection = JSON.stringify(lst);
-        update_count();
-    };
-
-    var remove_selection_click = function(e) {
-        remove_selection($(this).attr('name'));
-    };
-
-    var update_count = function(e) {
-        var lst = JSON.parse(localStorage.persistentSelection);
-        $("#persistent-selection-count").text(lst.length);
-
-        if (lst.length > 0) {
-            $('#persistent-selection-list').empty();
-            for (var i = 0; i < lst.length; i++) {
-                $('#persistent-selection-list').append("<li role=\"presentation\"><span><a href=\"#\">" + lst[i] + "</a>"
-                                                       + "<a href=\"#\" class=\"remove-selection\" name=\"" + lst[i] + "\">" 
-                                                       + "<span class=\"glyphicon glyphicon-trash pull-right\"></span>"
-                                                       + "</a></span></li>");
-            }
-        } else {
-            $('#persistent-selection-list').html("<li role=\"presentation\">No selections.</li>");
-        }
-
-        var checkboxes = $('.persistent-selection:checkbox');
-        for (i = 0; i < checkboxes.length; i++) {
-            if (jQuery.inArray($(checkboxes[i]).val(), lst) > -1) {
-                checkboxes[i].checked = true;
-            }
-            else {
-                checkboxes[i].checked = false;
-            }
-        }
-        
-        $('.remove-selection').on('click', remove_selection_click);
-    };
-
     $(document).
         on('ajax:send', function(e, xhr) {
             $('.loading').fadeTo('fast', 1);
         }).
         on('ajax:complete', function(e, status) {
             $('.loading').fadeOut('fast', 0);
-        }).
-        on('change', '.persistent-selection:checkbox', function(e) {
-            //console.log($(this));
-            //console.log($(this).val());
-
-            if (!localStorage.persistentSelection) {
-                localStorage.persistentSelection = JSON.stringify([]);
-            }
-            
-            var inc = 0;
-            if ($(this).is(":checked")) {
-                add_selection($(this).val());
-            }
-            else {
-                remove_selection($(this).val());
-            }
         });
 
-    $(window).on('load storage', update_count);
-
     HeaderRowFixer = function(selector) {
         this.duplicateTheadTr = function() {
             $(selector).each(function() {
diff --git a/apps/workbench/app/assets/javascripts/selection.js b/apps/workbench/app/assets/javascripts/selection.js
new file mode 100644
index 0000000..5d0900a
--- /dev/null
+++ b/apps/workbench/app/assets/javascripts/selection.js
@@ -0,0 +1,100 @@
+//= require jquery
+//= require jquery_ujs
+
+/** Javascript for local persistent selection. */
+
+(function($){
+    var get_storage = function() {
+        if (!sessionStorage.persistentSelection) {
+            sessionStorage.persistentSelection = JSON.stringify([]);
+        }
+        return JSON.parse(sessionStorage.persistentSelection);
+    }
+
+    var put_storage = function(lst) {
+        sessionStorage.persistentSelection = JSON.stringify(lst);
+    }
+
+    var add_selection = function(uuid, name, href, type) {
+        var lst = get_storage();
+        lst.push({"uuid": uuid, "name": name, "href": href, "type": type});
+        put_storage(lst);
+        update_count();
+    };
+
+    var remove_selection = function(uuid) {
+        var lst = get_storage();
+        for (var i = 0; i < lst.length; i++) {
+            if (lst[i].uuid == uuid) {
+                lst.splice(i, 1);
+                i--;
+            }
+        }
+        put_storage(lst);
+        update_count();
+    };
+
+    var remove_selection_click = function(e) {
+        remove_selection($(this).attr('name'));
+    };
+
+    var update_count = function(e) {
+        var lst = get_storage();
+        $("#persistent-selection-count").text(lst.length);
+
+        $('#persistent-selection-list > li > table').empty();
+        if (lst.length > 0) {
+            for (var i = 0; i < lst.length; i++) {
+                $('#persistent-selection-list > li > table').append("<tr>"
+                                                       + "<td style=\"vertical-align: top\">"
+                                                       + "<span style=\"padding-right: 1em\">" + lst[i].type + "</span>"
+                                                       + "</td>"
+
+                                                       + "<td>"
+                                                       + "<span><a href=\"" + lst[i].href + "\">" + lst[i].name + "</a></span>"
+                                                       + "</td>"
+
+                                                       + "<td>"
+                                                       + "<a href=\"#\" class=\"remove-selection\" name=\"" + lst[i].uuid + "\">" 
+                                                       + "<span class=\"glyphicon glyphicon-trash pull-right\"></span>"
+                                                       + "</a></span>"
+                                                       + "</td>"
+                                                       + "</tr>");
+            }
+        } else {
+            $('#persistent-selection-list > li > table').html("<tr><td>No selections.</td></tr>");
+        }
+
+        var checkboxes = $('.persistent-selection:checkbox');
+        for (i = 0; i < checkboxes.length; i++) {
+            for (var j = 0; j < lst.length; j++) {
+                if (lst[j].uuid == $(checkboxes[i]).val()) {
+                    checkboxes[i].checked = true;
+                    break;
+                }
+            }
+            if (j == lst.length) {
+                checkboxes[i].checked = false;
+            }
+        }
+        
+        $('.remove-selection').on('click', remove_selection_click);
+    };
+
+    $(document).
+        on('change', '.persistent-selection:checkbox', function(e) {
+            //console.log($(this));
+            //console.log($(this).val());
+            
+            var inc = 0;
+            if ($(this).is(":checked")) {
+                add_selection($(this).val(), $(this).attr('friendly_name'), $(this).attr('href'), $(this).attr('friendly_type'));
+            }
+            else {
+                remove_selection($(this).val());
+            }
+        });
+
+
+    $(window).on('load storage', update_count);
+})(jQuery);
\ No newline at end of file
diff --git a/apps/workbench/app/assets/stylesheets/application.css.scss b/apps/workbench/app/assets/stylesheets/application.css.scss
index dbaa063..c4a94ab 100644
--- a/apps/workbench/app/assets/stylesheets/application.css.scss
+++ b/apps/workbench/app/assets/stylesheets/application.css.scss
@@ -159,11 +159,27 @@ table.table-fixed-header-row tbody {
     top:1.5em;
 }
 
+/* Setting the height needs to be fixed with javascript. */
+.dropdown-menu {
+    padding-right: 20px;
+    max-height: 440px;
+    width: 400px;
+    overflow-y: auto;
+}
+
+#persistent-selection-list {
+    width: 500px;
+}
+
 #persistent-selection-list li {
     margin-left: 1em;
     padding: 3px 20px;
     font-weight: normal;
     line-height: 1.42857;
     color: rgb(51, 51, 51);
-    border-bottom: 1px solid rgb(221, 221, 221)
+    
+}
+
+#persistent-selection-list li table tr {
+  border-bottom: 1px solid rgb(221, 221, 221);
 }
diff --git a/apps/workbench/app/models/arvados_base.rb b/apps/workbench/app/models/arvados_base.rb
index 72b76a5..f1d4294 100644
--- a/apps/workbench/app/models/arvados_base.rb
+++ b/apps/workbench/app/models/arvados_base.rb
@@ -275,6 +275,10 @@ class ArvadosBase < ActiveRecord::Base
     (name if self.respond_to? :name) || uuid
   end
 
+  def selection_label
+    friendly_link_name
+  end
+
   protected
 
   def forget_uuid!
diff --git a/apps/workbench/app/models/collection.rb b/apps/workbench/app/models/collection.rb
index bda5523..e22a5f7 100644
--- a/apps/workbench/app/models/collection.rb
+++ b/apps/workbench/app/models/collection.rb
@@ -24,4 +24,23 @@ class Collection < ArvadosBase
   def used_by
     $arvados_api_client.api "collections/#{self.uuid}/", "used_by"
   end
+
+  # def selection_label
+  #   name = ''
+  #   i = 0 
+  #   if self.files.length > 3
+  #     m = 3
+  #   else
+  #     m = self.files.length 
+  #   end
+  #   while i < m
+  #     name += "#{self.files[i][1]}"
+  #     i += 1
+  #     name += ", " if i < m
+  #   end
+  #   if i < self.files.length
+  #     name += "&ellip;"
+  #   end
+  #   name
+  # end
 end
diff --git a/apps/workbench/app/views/application/_selection_checkbox.html.erb b/apps/workbench/app/views/application/_selection_checkbox.html.erb
new file mode 100644
index 0000000..cb0ec82
--- /dev/null
+++ b/apps/workbench/app/views/application/_selection_checkbox.html.erb
@@ -0,0 +1,6 @@
+<%= check_box_tag 'uuids[]', object.uuid, false, {
+  :class => 'persistent-selection', 
+  :friendly_type => object.class.name,
+  :friendly_name => object.selection_label,
+  :href => "#{url_for controller: object.class.name.tableize, action: 'show', id: object.uuid }" 
+} %>
diff --git a/apps/workbench/app/views/application/_show_recent.html.erb b/apps/workbench/app/views/application/_show_recent.html.erb
index 0008d09..ef4a8d1 100644
--- a/apps/workbench/app/views/application/_show_recent.html.erb
+++ b/apps/workbench/app/views/application/_show_recent.html.erb
@@ -30,7 +30,7 @@
     <% @objects.each do |object| %>
     <tr data-object-uuid="<%= object.uuid %>">
       <td>
-        <%= check_box_tag 'uuids[]', object.uuid, false, :class => 'persistent-selection' %>
+        <%= render :partial => "selection_checkbox", :locals => {:object => object} %>
       </td>
 
       <% object.attributes_for_display.each do |attr, attrvalue| %>
diff --git a/apps/workbench/app/views/collections/_index_tbody.html.erb b/apps/workbench/app/views/collections/_index_tbody.html.erb
index 0a3732a..57f6eeb 100644
--- a/apps/workbench/app/views/collections/_index_tbody.html.erb
+++ b/apps/workbench/app/views/collections/_index_tbody.html.erb
@@ -2,7 +2,7 @@
 
 <tr class="collection">
   <td>
-    <%= check_box_tag 'uuids[]', c.uuid, false, :class => 'persistent-selection' %>
+    <%= render :partial => "selection_checkbox", :locals => {:object => c} %>
   </td>
   <td>
     <%= link_to_if_arvados_object c.uuid %>
diff --git a/apps/workbench/app/views/collections/_show_files.html.erb b/apps/workbench/app/views/collections/_show_files.html.erb
index 385af8a..53fbad8 100644
--- a/apps/workbench/app/views/collections/_show_files.html.erb
+++ b/apps/workbench/app/views/collections/_show_files.html.erb
@@ -1,5 +1,6 @@
 <table class="table table-condensed table-fixedlayout">
   <colgroup>
+    <col width="4%" />
     <col width="35%" />
     <col width="40%" />
     <col width="15%" />
@@ -17,6 +18,16 @@
     <% 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}" 
+      } %>
+      </td>
+      <td>
         <%= file[0] %>
       </td>
 
diff --git a/apps/workbench/app/views/layouts/application.html.erb b/apps/workbench/app/views/layouts/application.html.erb
index ecbe3db..1d6a468 100644
--- a/apps/workbench/app/views/layouts/application.html.erb
+++ b/apps/workbench/app/views/layouts/application.html.erb
@@ -42,14 +42,6 @@
     padding-top: 1.25em;
     }
 
-    /* Setting the height needs to be fixed with javascript. */
-    .dropdown-menu {
-    padding-right: 20px;
-    max-height: 440px;
-    width: 400px;
-    overflow-y: auto;
-    }
-
     @media (min-width: 768px) {
     .left-nav {
     position: fixed;
@@ -93,7 +85,12 @@
               <span class="glyphicon glyphicon-arrow-right"></span>
             </li>
             <li>
-<%= link_to controller.breadcrumb_page_name, request.fullpath %>
+              <%= link_to controller.breadcrumb_page_name, request.fullpath %>
+            </li>
+            <li style="padding: 14px 0 14px">
+              <%= form_tag do |f| %>
+                <%= render :partial => "selection_checkbox", :locals => {:object => @object} %>
+              <% end %>
             </li>
           <% end %>
         <% end %>
@@ -125,6 +122,7 @@
             <span class="caret"></span>
           </a>
           <ul class="dropdown-menu" role="menu" id="persistent-selection-list">
+            <li><table style="width:100%"></table></li>
           </ul>
         </li>
 

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list