[ARVADOS] updated: 0454d8c5f091e598e705ed8ddd7f658b4eff7989

Git user git at public.curoverse.com
Mon Jun 19 11:57:54 EDT 2017


Summary of changes:
 .../app/assets/javascripts/edit_collection.js      | 40 -----------------
 .../app/assets/javascripts/edit_collection_tags.js | 52 ++++++++++++++++++++++
 .../app/controllers/collections_controller.rb      |  9 ++++
 .../app/views/collections/_show_tag_rows.html.erb  | 26 +++++++++++
 .../app/views/collections/_show_tags.html.erb      | 38 +++++-----------
 .../app/views/collections/save_tags.js.erb         |  0
 apps/workbench/config/routes.rb                    |  1 +
 7 files changed, 98 insertions(+), 68 deletions(-)
 create mode 100644 apps/workbench/app/assets/javascripts/edit_collection_tags.js
 create mode 100644 apps/workbench/app/views/collections/_show_tag_rows.html.erb
 copy tools/crunchstat-summary/tests/__init__.py => apps/workbench/app/views/collections/save_tags.js.erb (100%)

       via  0454d8c5f091e598e705ed8ddd7f658b4eff7989 (commit)
      from  d92e6647371dc3894555043d630fb5c297ef5d6c (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 0454d8c5f091e598e705ed8ddd7f658b4eff7989
Author: radhika <radhika at curoverse.com>
Date:   Mon Jun 19 11:57:36 2017 -0400

    9426: edit collection tags
    
    Arvados-DCO-1.1-Signed-off-by: Radhika Chippada <radhika at curoverse.com>

diff --git a/apps/workbench/app/assets/javascripts/edit_collection.js b/apps/workbench/app/assets/javascripts/edit_collection.js
index 14240d2..5f0c3b4 100644
--- a/apps/workbench/app/assets/javascripts/edit_collection.js
+++ b/apps/workbench/app/assets/javascripts/edit_collection.js
@@ -26,9 +26,6 @@ $(document).
                 $(".tab-pane-Upload").removeClass("disabled");
                 $(".tab-pane-Upload").attr("data-original-title", "");
                 $("#Upload-tab").attr("data-toggle", "tab");
-
-                $('.edit-collection-tags').removeClass('disabled');
-                $('#edit-collection-tags').attr('title', '');
             } else {
                 // User clicked "no" and so do not unlock
             }
@@ -44,42 +41,5 @@ $(document).
             $(".tab-pane-Upload").addClass("disabled");
             $(".tab-pane-Upload").attr("data-original-title", "Unlock collection to upload files");
             $("#Upload-tab").attr("data-toggle", "disabled");
-
-            $('.edit-collection-tags').removeClass('hide');
-            $('.edit-collection-tags').addClass('disabled');
-            $('#edit-collection-tags').attr('title', 'Unlock collection to edit tags');
-            $('.collection-tag-add').addClass('hide');
-            $('.collection-tag-remove').addClass('hide');
-            $('.collection-tag-save').addClass('hide');
-            $('.collection-tag-cancel').addClass('hide');
-            $('.collection-tag-field').prop("contenteditable", false);
         }
-    }).
-    on('click', '.collection-tag-save, .collection-tag-cancel', function(event) {
-        $('.edit-collection-tags').removeClass('hide');
-        $('.collection-tag-add').addClass('hide');
-        $('.collection-tag-remove').addClass('hide');
-        $('.collection-tag-save').addClass('hide');
-        $('.collection-tag-cancel').addClass('hide');
-        $('.collection-tag-field').prop("contenteditable", false);
-    }).
-    on('click', '.edit-collection-tags', function(event) {
-        $('.edit-collection-tags').addClass('hide');
-        $('.collection-tag-add').removeClass('hide');
-        $('.collection-tag-remove').removeClass('hide');
-        $('.collection-tag-save').removeClass('hide');
-        $('.collection-tag-cancel').removeClass('hide');
-        $('.collection-tag-field').prop("contenteditable", true);
     });
-
-jQuery(function($){
-  $(document).on('click', '.collection-tag-remove', function(e) {
-    $(this).parents('tr').detach();
-  });
-
-  $(document).on('click', '.collection-tag-add', function(e) {
-    var $collection_tags = $(this).closest('.collection-tags-container');
-    var $clone = $collection_tags.find('tr.hide').clone(true).removeClass('hide');
-    $collection_tags.find('table').append($clone);
-  });
-});
diff --git a/apps/workbench/app/assets/javascripts/edit_collection_tags.js b/apps/workbench/app/assets/javascripts/edit_collection_tags.js
new file mode 100644
index 0000000..26b0ba7
--- /dev/null
+++ b/apps/workbench/app/assets/javascripts/edit_collection_tags.js
@@ -0,0 +1,52 @@
+// On loading of a collection, enable the "lock" button and
+// disable all file modification controls (upload, rename, delete)
+$(document).
+    on('click', '.collection-tag-save, .collection-tag-cancel', function(event) {
+        $('.edit-collection-tags').removeClass('disabled');
+        $('.collection-tag-add').addClass('hide');
+        $('.collection-tag-remove').addClass('hide');
+        $('.collection-tag-save').addClass('hide');
+        $('.collection-tag-cancel').addClass('hide');
+        $('.collection-tag-field').prop("contenteditable", false);
+    }).
+    on('click', '.edit-collection-tags', function(event) {
+        $('.edit-collection-tags').addClass('disabled');
+        $('.collection-tag-add').removeClass('hide');
+        $('.collection-tag-remove').removeClass('hide');
+        $('.collection-tag-save').removeClass('hide');
+        $('.collection-tag-cancel').removeClass('hide');
+        $('.collection-tag-field').prop("contenteditable", true);
+        $('div').remove('.collection-tags-status-label');
+    }).
+    on('click', '.collection-tag-save', function(e){
+      var tag_data = {};
+      var $tags = $(".collection-tags-table");
+      $tags.find('tr').each(function (i, el) {
+        var $tds = $(this).find('td');
+        var $key = $tds.eq(1).text();
+        if ($key && $key.trim().length > 0) {
+          tag_data[$key.trim()] = $tds.eq(2).text().trim();
+        }
+      });
+
+      $.ajax($(location).attr('pathname')+'/save_tags', {
+          type: 'POST',
+          data: {tag_data}
+      }).success(function(data, status, jqxhr) {
+        $('.collection-tags-status').append('<div class="collection-tags-status-label alert alert-success"><p class="contain-align-left">Saved successfully.</p></div>');
+      }).fail(function(jqxhr, status, error) {
+        $('.collection-tags-status').append('<div class="collection-tags-status-label alert alert-danger"><p class="contain-align-left">We are sorry. There was an error saving tags. Please try again.</p></div>');
+      });
+    });
+
+jQuery(function($){
+  $(document).on('click', '.collection-tag-remove', function(e) {
+    $(this).parents('tr').detach();
+  });
+
+  $(document).on('click', '.collection-tag-add', function(e) {
+    var $collection_tags = $(this).closest('.collection-tags-container');
+    var $clone = $collection_tags.find('tr.hide').clone(true).removeClass('hide');
+    $collection_tags.find('table').append($clone);
+  });
+});
diff --git a/apps/workbench/app/controllers/collections_controller.rb b/apps/workbench/app/controllers/collections_controller.rb
index 48b9826..8b3cc2f 100644
--- a/apps/workbench/app/controllers/collections_controller.rb
+++ b/apps/workbench/app/controllers/collections_controller.rb
@@ -345,6 +345,15 @@ class CollectionsController < ApplicationController
     end
   end
 
+  def save_tags
+    props = @object.properties
+    props[:tags] = params['tag_data']
+    if @object.update_attributes properties: props
+    else
+      self.render_error status: 422
+    end
+  end
+
   protected
 
   def find_usable_token(token_list)
diff --git a/apps/workbench/app/views/collections/_show_tag_rows.html.erb b/apps/workbench/app/views/collections/_show_tag_rows.html.erb
new file mode 100644
index 0000000..da69925
--- /dev/null
+++ b/apps/workbench/app/views/collections/_show_tag_rows.html.erb
@@ -0,0 +1,26 @@
+<%
+  tags = object.properties[:tags]
+%>
+
+        <% tags.andand.each do |k, v| %>
+          <tr class="collection-tag-<%=k%>">
+            <td>
+              <i class="glyphicon glyphicon-remove collection-tag-remove hide" style="cursor: pointer;"></i>
+            </td>
+            <td class="collection-tag-field">
+              <%= k %>
+            </td>
+            <td class="collection-tag-field">
+              <%= v %>
+            </td>
+          </tr>
+        <% end %>
+
+        <!-- A hidden row to add new tag -->
+        <tr class="collection-tag-hidden hide">
+          <td>
+            <i class="glyphicon glyphicon-remove collection-tag-remove hide" style="cursor: pointer"></i>
+          </td>
+          <td class="collection-tag-field"></td>
+          <td class="collection-tag-field"></td>
+        </tr>
diff --git a/apps/workbench/app/views/collections/_show_tags.html.erb b/apps/workbench/app/views/collections/_show_tags.html.erb
index ed40873..e1b0de7 100644
--- a/apps/workbench/app/views/collections/_show_tags.html.erb
+++ b/apps/workbench/app/views/collections/_show_tags.html.erb
@@ -1,12 +1,11 @@
 <%
   object = @object unless object
-  tags = object.properties[:tags]
 %>
 
   <div class="collection-tags-container" style="padding-left:2em;padding-right:2em;">
     <% if object.editable? %>
-      <p title="Unlock collection to edit tags" id="edit-collection-tags">
-        <button type="button" class="btn btn-primary edit-collection-tags disabled">Edit</button>
+      <p title="Edit tags" id="edit-collection-tags">
+        <button type="button" class="btn btn-primary edit-collection-tags">Edit</button>
       </p>
     <% end %>
 
@@ -25,29 +24,8 @@
         </tr>
       </thead>
 
-      <tbody>
-        <% tags.andand.each do |k, v| %>
-          <tr class="collection-tag-<%=k%>">
-            <td>
-              <i class="glyphicon glyphicon-remove collection-tag-remove hide" style="cursor: pointer;"></i>
-            </td>
-            <td class="collection-tag-field">
-              <%= k %>
-            </td>
-            <td class="collection-tag-field">
-              <%= v %>
-            </td>
-          </tr>
-        <% end %>
-
-        <!-- A hidden row to add new tag -->
-        <tr class="collection-tag-hidden hide">
-          <td>
-            <i class="glyphicon glyphicon-remove collection-tag-remove hide" style="cursor: pointer"></i>
-          </td>
-          <td class="collection-tag-field"></td>
-          <td class="collection-tag-field"></td>
-        </tr>
+      <tbody class="collection-tag-rows">
+        <%= render partial: 'show_tag_rows', locals: {object: object} %>
       </tbody>
     </table>
     <div>
@@ -56,9 +34,13 @@
           <button class="btn btn-primary btn-sm collection-tag-add hide"><i class="glyphicon glyphicon-plus"></i> Add new tag </button>
         </div>
         <div class="pull-right">
-          <button type="button" class="btn btn-primary collection-tag-save hide">Save</button>
-          <button type="button" class="btn btn-primary collection-tag-cancel hide">Cancel</button>
+          <%= link_to(save_tags_collection_path, {class: 'btn btn-primary collection-tag-save hide', :remote => true, method: 'post', return_to: request.url}) do %>
+            Save
+          <% end %>
+          <button type="button" class="btn btn-sm btn-primary collection-tag-cancel hide">Cancel</button>
         </div>
+
+        <div><div class="collection-tags-status"/></div></div>
       <% end %>
     </div>
   </div>
diff --git a/apps/workbench/app/views/collections/save_tags.js.erb b/apps/workbench/app/views/collections/save_tags.js.erb
new file mode 100644
index 0000000..e69de29
diff --git a/apps/workbench/config/routes.rb b/apps/workbench/config/routes.rb
index badb471..880cc15 100644
--- a/apps/workbench/config/routes.rb
+++ b/apps/workbench/config/routes.rb
@@ -88,6 +88,7 @@ ArvadosWorkbench::Application.routes.draw do
     post 'unshare', :on => :member
     get 'choose', on: :collection
     post 'remove_selected_files', on: :member
+    post 'save_tags', on: :member
   end
   get('/collections/download/:uuid/:reader_token/*file' => 'collections#show_file',
       format: false)

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


hooks/post-receive
-- 




More information about the arvados-commits mailing list