[ARVADOS] updated: a4127e018442e1b8053307f376c2d8c66b3279fc

Git user git at public.curoverse.com
Fri Jun 23 14:29:12 EDT 2017


Summary of changes:
 .../app/assets/javascripts/edit_collection_tags.js | 68 +++++++++++++++++
 .../app/assets/stylesheets/collections.css.scss    |  4 +
 .../app/controllers/collections_controller.rb      | 29 ++++++-
 .../app/views/collections/_show_tag_rows.html.erb  | 31 ++++++++
 .../app/views/collections/_show_tags.html.erb      | 48 ++++++++++++
 .../app/views/collections/save_tags.js.erb         |  3 +
 apps/workbench/app/views/collections/tags.js.erb   |  1 +
 apps/workbench/config/routes.rb                    |  2 +
 .../controllers/collections_controller_test.rb     | 63 ++++++++++++++++
 .../workbench/test/integration/collections_test.rb | 88 ++++++++++++++++++++++
 services/api/test/fixtures/collections.yml         | 17 +++++
 services/api/test/fixtures/links.yml               | 14 ++++
 .../arvados/v1/groups_controller_test.rb           |  1 +
 13 files changed, 368 insertions(+), 1 deletion(-)
 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
 create mode 100644 apps/workbench/app/views/collections/_show_tags.html.erb
 create mode 100644 apps/workbench/app/views/collections/save_tags.js.erb
 create mode 100644 apps/workbench/app/views/collections/tags.js.erb

       via  a4127e018442e1b8053307f376c2d8c66b3279fc (commit)
       via  b6244435a4470fbddc9f13edb4329d563e579e50 (commit)
       via  cffa37b8680c2730934b7f474836312bb7a1fe73 (commit)
       via  aee74220328be12113ea597e593b4ab6f120aeac (commit)
       via  55bdcab45a5e059ecc218099a30ff5ad231a627f (commit)
      from  ecc8ee4e5edabaf7d888f55a99184b1efe4a9060 (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 a4127e018442e1b8053307f376c2d8c66b3279fc
Merge: ecc8ee4 b624443
Author: radhika <radhika at curoverse.com>
Date:   Fri Jun 23 14:26:37 2017 -0400

    closes #9426
    
    Merge branch '9426-collection-tags'
    
    Arvados-DCO-1.1-Signed-off-by: Radhika Chippada <radhika at curoverse.com>


commit b6244435a4470fbddc9f13edb4329d563e579e50
Author: radhika <radhika at curoverse.com>
Date:   Tue Jun 20 19:00:32 2017 -0400

    9426: test Tags tab
    
    Arvados-DCO-1.1-Signed-off-by: Radhika Chippada <radhika at curoverse.com>

diff --git a/apps/workbench/app/assets/javascripts/edit_collection_tags.js b/apps/workbench/app/assets/javascripts/edit_collection_tags.js
index 06cd64b..dc8c033 100644
--- a/apps/workbench/app/assets/javascripts/edit_collection_tags.js
+++ b/apps/workbench/app/assets/javascripts/edit_collection_tags.js
@@ -1,6 +1,5 @@
-// On loading of a collection, enable the "lock" button and
-// disable all file modification controls (upload, rename, delete)
-$(document).
+jQuery(function($){
+  $(document).
     on('click', '.collection-tag-save, .collection-tag-cancel', function(event) {
         $('.edit-collection-tags').removeClass('disabled');
         $('#edit-collection-tags').attr("title", "Edit tags");
@@ -20,46 +19,50 @@ $(document).
         $('.collection-tag-field').prop("contenteditable", true);
         $('div').remove('.collection-tags-status-label');
     }).
-    on('click', '.collection-tag-save', function(e){
+    on('click', '.collection-tag-save', function(event) {
       var tag_data = {};
+      var has_tags = false;
+
       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) {
+          has_tags = true;
           tag_data[$key.trim()] = $tds.eq(2).text().trim();
         }
       });
 
-      if(jQuery.isEmptyObject(tag_data)){
-        tag_data["empty"]=true
+      var to_send;
+      if (has_tags == false) {
+        to_send = {tag_data: "empty"}
       } else {
-        tag_data = {tag_data}
+        to_send = {tag_data: tag_data}
       }
 
       $.ajax($(location).attr('pathname')+'/save_tags', {
           type: 'POST',
-          data: tag_data
+          data: to_send
       }).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>');
       });
     }).
-    on('click', '.collection-tag-cancel', function(e){
+    on('click', '.collection-tag-cancel', function(event) {
       $.ajax($(location).attr('pathname')+'/tags', {
           type: 'GET'
       });
+    }).
+    on('click', '.collection-tag-remove', function(event) {
+      $(this).parents('tr').detach();
+    }).
+    on('click', '.collection-tag-add', function(event) {
+      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);
+    }).
+    on('keypress', '.collection-tag-field', function(event){
+      return event.which != 13;
     });
-
-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/stylesheets/collections.css.scss b/apps/workbench/app/assets/stylesheets/collections.css.scss
index 2d2d0f2..dadf4ea 100644
--- a/apps/workbench/app/assets/stylesheets/collections.css.scss
+++ b/apps/workbench/app/assets/stylesheets/collections.css.scss
@@ -70,3 +70,7 @@ $active-bg: #39b3d7;
     padding: .5em 2em;
     margin: 0 1em;
 }
+
+.collection-tag-field * {
+  display: inline-block;
+}
diff --git a/apps/workbench/app/controllers/collections_controller.rb b/apps/workbench/app/controllers/collections_controller.rb
index bfba2f5..99399bc 100644
--- a/apps/workbench/app/controllers/collections_controller.rb
+++ b/apps/workbench/app/controllers/collections_controller.rb
@@ -350,11 +350,13 @@ class CollectionsController < ApplicationController
   end
 
   def save_tags
-    tags = nil
-    if params['tag_data']
-      tags = params['tag_data']
-    elsif params['empty']
-      tags = {}
+    tags_param = params['tag_data']
+    if tags_param
+      if tags_param.is_a?(String) && tags_param == "empty"
+        tags = {}
+      else
+        tags = tags_param
+      end
     end
 
     if tags
@@ -362,6 +364,8 @@ class CollectionsController < ApplicationController
       props[:tags] = tags
 
       if @object.update_attributes properties: props
+        @saved_tags = true
+        render
       else
         self.render_error status: 422
       end
diff --git a/apps/workbench/app/views/collections/_show_tag_rows.html.erb b/apps/workbench/app/views/collections/_show_tag_rows.html.erb
index da69925..eceec10 100644
--- a/apps/workbench/app/views/collections/_show_tag_rows.html.erb
+++ b/apps/workbench/app/views/collections/_show_tag_rows.html.erb
@@ -1,26 +1,31 @@
 <%
   tags = object.properties[:tags]
 %>
-
-        <% tags.andand.each do |k, v| %>
+      <% if tags.andand.is_a?(Hash) %>
+        <% tags.each do |k, v| %>
           <tr class="collection-tag-<%=k%>">
             <td>
-              <i class="glyphicon glyphicon-remove collection-tag-remove hide" style="cursor: pointer;"></i>
+              <% if object.editable? %>
+                <i class="glyphicon glyphicon-remove collection-tag-remove hide" style="cursor: pointer;"></i>
+              <% end %>
             </td>
-            <td class="collection-tag-field">
+            <td class="collection-tag-field collection-tag-field-key">
               <%= k %>
             </td>
-            <td class="collection-tag-field">
+            <td class="collection-tag-field collection-tag-field-value">
               <%= v %>
             </td>
           </tr>
         <% end %>
+      <% end %>
 
+      <% if @object.editable? %>
         <!-- 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>
+          <td class="collection-tag-field collection-tag-field-key"></td>
+          <td class="collection-tag-field collection-tag-field-value"></td>
         </tr>
+      <% end %>
diff --git a/apps/workbench/app/views/collections/_show_tags.html.erb b/apps/workbench/app/views/collections/_show_tags.html.erb
index 4ffe7ff..a1f58ae 100644
--- a/apps/workbench/app/views/collections/_show_tags.html.erb
+++ b/apps/workbench/app/views/collections/_show_tags.html.erb
@@ -5,7 +5,7 @@
   <div class="collection-tags-container" style="padding-left:2em;padding-right:2em;">
     <% if object.editable? %>
       <p title="Edit tags" id="edit-collection-tags">
-        <button type="button" class="btn btn-primary edit-collection-tags">Edit</button>
+        <a type="button" class="btn btn-primary edit-collection-tags">Edit</a>
       </p>
     <% end %>
 
@@ -31,7 +31,7 @@
     <div>
       <% if object.editable? %>
         <div class="pull-left">
-          <button class="btn btn-primary btn-sm collection-tag-add hide"><i class="glyphicon glyphicon-plus"></i> Add new tag </button>
+          <a class="btn btn-primary btn-sm collection-tag-add hide"><i class="glyphicon glyphicon-plus"></i> Add new tag </a>
         </div>
         <div class="pull-right">
           <%= link_to(save_tags_collection_path, {class: 'btn btn-sm btn-primary collection-tag-save hide', :remote => true, method: 'post', return_to: request.url}) do %>
diff --git a/apps/workbench/app/views/collections/save_tags.js.erb b/apps/workbench/app/views/collections/save_tags.js.erb
index e2faff1..5fc84d7 100644
--- a/apps/workbench/app/views/collections/save_tags.js.erb
+++ b/apps/workbench/app/views/collections/save_tags.js.erb
@@ -1 +1,3 @@
+<% if @saved_tags %>
 $(".collection-tag-rows").html("<%= escape_javascript(render partial: 'show_tag_rows', locals: {object: @object}) %>");
+<% end %>
diff --git a/apps/workbench/test/controllers/collections_controller_test.rb b/apps/workbench/test/controllers/collections_controller_test.rb
index 7ff123c..63e1ae3 100644
--- a/apps/workbench/test/controllers/collections_controller_test.rb
+++ b/apps/workbench/test/controllers/collections_controller_test.rb
@@ -776,4 +776,67 @@ class CollectionsControllerTest < ActionController::TestCase
     assert_response 422
     assert_includes json_response['errors'], 'Duplicate file path'
   end
+
+  [
+    [:active, true],
+    [:spectator, false],
+  ].each do |user, editable|
+    test "tags tab #{editable ? 'shows' : 'does not show'} edit button to #{user}" do
+      use_token user
+
+      get :tags, {
+        id: api_fixture('collections')['collection_with_tags_owned_by_active']['uuid'],
+        format: :js,
+      }, session_for(user)
+
+      assert_response :success
+
+      found = 0
+      response.body.scan /<i[^>]+>/ do |remove_icon|
+        remove_icon.scan(/\ collection-tag-remove(.*?)\"/).each do |i,|
+          found += 1
+        end
+      end
+
+      if editable
+        assert_equal(3, found)  # two from the tags + 1 from the hidden "add tag" row
+      else
+        assert_equal(0, found)
+      end
+    end
+  end
+
+  test "save_tags and verify that 'other' properties are retained" do
+    use_token :active
+
+    collection = api_fixture('collections')['collection_with_tags_owned_by_active']
+
+    new_tags = {"new_tag1" => "new_tag1_value",
+                "new_tag2" => "new_tag2_value"}
+
+    post :save_tags, {
+      id: collection['uuid'],
+      tag_data: new_tags,
+      format: :js,
+    }, session_for(:active)
+
+    assert_response :success
+    assert_equal true, response.body.include?("new_tag1")
+    assert_equal true, response.body.include?("new_tag1_value")
+    assert_equal true, response.body.include?("new_tag2")
+    assert_equal true, response.body.include?("new_tag2_value")
+    assert_equal false, response.body.include?("existing tag 1")
+    assert_equal false, response.body.include?("value for existing tag 1")
+
+    updated_properties = Collection.find(collection['uuid']).properties
+    updated_tags = updated_properties[:tags]
+    assert_equal true, updated_tags.keys.include?(:'new_tag1')
+    assert_equal new_tags['new_tag1'], updated_tags[:'new_tag1']
+    assert_equal true, updated_tags.keys.include?(:'new_tag2')
+    assert_equal new_tags['new_tag2'], updated_tags[:'new_tag2']
+    assert_equal false, updated_tags.keys.include?(:'existing tag 1')
+    assert_equal false, updated_tags.keys.include?(:'existing tag 2')
+    assert_equal true, updated_properties.keys.include?(:'some other property')
+    assert_equal 'value for the other property', updated_properties[:'some other property']
+  end
 end
diff --git a/apps/workbench/test/integration/collections_test.rb b/apps/workbench/test/integration/collections_test.rb
index 8b43e5d..dbdcef8 100644
--- a/apps/workbench/test/integration/collections_test.rb
+++ b/apps/workbench/test/integration/collections_test.rb
@@ -420,4 +420,92 @@ class CollectionsTest < ActionDispatch::IntegrationTest
     first('.lock-collection-btn').click
     accept_alert
   end
+
+  test "collection tags tab" do
+    need_selenium
+
+    visit page_with_token('active', '/collections/zzzzz-4zz18-bv31uwvy3neko21')
+
+    click_link 'Tags'
+    wait_for_ajax
+
+    # verify initial state
+    assert_selector 'a', text: 'Edit'
+    assert_no_selector 'a', text: 'Add new tag'
+    assert_no_selector 'a', text: 'Save'
+    assert_no_selector 'a', text: 'Cancel'
+
+    # Verify controls in edit mode
+    first('.edit-collection-tags').click
+    assert_selector 'a.disabled', text: 'Edit'
+    assert_selector 'a', text: 'Add new tag'
+    assert_selector 'a', text: 'Save'
+    assert_selector 'a', text: 'Cancel'
+
+    # add two tags
+    first('.edit-collection-tags').click
+
+    first('.glyphicon-plus').click
+    first('.collection-tag-field-key').click
+    first('.collection-tag-field-key').set('key 1')
+    first('.collection-tag-field-value').click
+    first('.collection-tag-field-value').set('value 1')
+
+    first('.glyphicon-plus').click
+    editable_key_fields = page.all('.collection-tag-field-key')
+    editable_key_fields[1].click
+    editable_key_fields[1].set('key 2')
+    editable_val_fields = page.all('.collection-tag-field-value')
+    editable_val_fields[1].click
+    editable_val_fields[1].set('value 2')
+
+    click_on 'Save'
+    wait_for_ajax
+
+    # added tags; verify
+    assert_text 'key 1'
+    assert_text 'value 1'
+    assert_text 'key 2'
+    assert_text 'value 2'
+    assert_selector 'a', text: 'Edit'
+    assert_no_selector 'a', text: 'Save'
+
+    # remove first tag
+    first('.edit-collection-tags').click
+    assert_not_nil first('.glyphicon-remove')
+    first('.glyphicon-remove').click
+    click_on 'Save'
+    wait_for_ajax
+
+    assert_text 'key 2'
+    assert_text 'value 2'
+    assert_no_text 'key 1'
+    assert_no_text 'value 1'
+    assert_selector 'a', text: 'Edit'
+
+    # Click on cancel and verify
+    first('.edit-collection-tags').click
+    first('.collection-tag-field-key').click
+    first('.collection-tag-field-key').set('this key wont stick')
+    first('.collection-tag-field-value').click
+    first('.collection-tag-field-value').set('this value wont stick')
+
+    click_on 'Cancel'
+    wait_for_ajax
+
+    assert_text 'key 2'
+    assert_text 'value 2'
+    assert_no_text 'this key wont stick'
+    assert_no_text 'this value wont stick'
+
+    # remove all tags
+    first('.edit-collection-tags').click
+    first('.glyphicon-remove').click
+    click_on 'Save'
+    wait_for_ajax
+
+    assert_selector 'a', text: 'Edit'
+    assert_no_text 'key 2'
+    assert_no_text 'value 2'
+  end
 end
diff --git a/services/api/test/fixtures/collections.yml b/services/api/test/fixtures/collections.yml
index 8aedbdc..6543f54 100644
--- a/services/api/test/fixtures/collections.yml
+++ b/services/api/test/fixtures/collections.yml
@@ -657,6 +657,23 @@ collection_to_remove_and_rename_files:
   manifest_text: ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:file1 0:0:file2\n"
   name: collection to remove and rename files
 
+collection_with_tags_owned_by_active:
+  uuid: zzzzz-4zz18-taggedcolletion
+  portable_data_hash: fa7aeb5140e2848d39b416daeef4ffc5+45
+  owner_uuid: zzzzz-tpzed-xurymjxw79nv3jz
+  created_at: 2014-02-03T17:22:54Z
+  modified_by_client_uuid: zzzzz-ozdt8-brczlopd8u8d0jr
+  modified_by_user_uuid: zzzzz-tpzed-d9tiejq69daie8f
+  modified_at: 2014-02-03T17:22:54Z
+  updated_at: 2014-02-03T17:22:54Z
+  manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
+  name: collection with tags
+  properties:
+    tags:
+      existing tag 1: value for existing tag 1
+      existing tag 2: value for existing tag 2
+    some other property: value for the other property
+
 
 # Test Helper trims the rest of the file
 
diff --git a/services/api/test/fixtures/links.yml b/services/api/test/fixtures/links.yml
index ac579f7..2c65483 100644
--- a/services/api/test/fixtures/links.yml
+++ b/services/api/test/fixtures/links.yml
@@ -1056,3 +1056,17 @@ star_shared_project_for_project_viewer:
   name: zzzzz-j7d0g-starredshared01
   head_uuid: zzzzz-j7d0g-starredshared01
   properties: {}
+
+tagged_collection_readable_by_spectator:
+  uuid: zzzzz-o0j2j-readacl4tagcoll
+  owner_uuid: zzzzz-tpzed-000000000000000
+  created_at: 2014-01-24 20:42:26 -0800
+  modified_by_client_uuid: zzzzz-ozdt8-brczlopd8u8d0jr
+  modified_by_user_uuid: zzzzz-tpzed-000000000000000
+  modified_at: 2014-01-24 20:42:26 -0800
+  updated_at: 2014-01-24 20:42:26 -0800
+  tail_uuid: zzzzz-tpzed-l1s2piq4t4mps8r
+  link_class: permission
+  name: can_read
+  head_uuid: zzzzz-4zz18-taggedcolletion
+  properties: {}
diff --git a/services/api/test/functional/arvados/v1/groups_controller_test.rb b/services/api/test/functional/arvados/v1/groups_controller_test.rb
index 3beec35..7e3cad7 100644
--- a/services/api/test/functional/arvados/v1/groups_controller_test.rb
+++ b/services/api/test/functional/arvados/v1/groups_controller_test.rb
@@ -116,6 +116,7 @@ class Arvados::V1::GroupsControllerTest < ActionController::TestCase
     authorize_with :active
     get :contents, {
       format: :json,
+      limit: 200,
       id: users(:active).uuid
     }
     assert_response :success

commit cffa37b8680c2730934b7f474836312bb7a1fe73
Author: radhika <radhika at curoverse.com>
Date:   Tue Jun 20 13:54:03 2017 -0400

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

diff --git a/apps/workbench/app/assets/javascripts/edit_collection_tags.js b/apps/workbench/app/assets/javascripts/edit_collection_tags.js
index 8dc9d61..06cd64b 100644
--- a/apps/workbench/app/assets/javascripts/edit_collection_tags.js
+++ b/apps/workbench/app/assets/javascripts/edit_collection_tags.js
@@ -31,9 +31,15 @@ $(document).
         }
       });
 
+      if(jQuery.isEmptyObject(tag_data)){
+        tag_data["empty"]=true
+      } else {
+        tag_data = {tag_data}
+      }
+
       $.ajax($(location).attr('pathname')+'/save_tags', {
           type: 'POST',
-          data: {tag_data}
+          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) {
@@ -42,7 +48,7 @@ $(document).
     }).
     on('click', '.collection-tag-cancel', function(e){
       $.ajax($(location).attr('pathname')+'/tags', {
-          type: 'POST'
+          type: 'GET'
       });
     });
 
diff --git a/apps/workbench/app/controllers/collections_controller.rb b/apps/workbench/app/controllers/collections_controller.rb
index 8e1e8a5..bfba2f5 100644
--- a/apps/workbench/app/controllers/collections_controller.rb
+++ b/apps/workbench/app/controllers/collections_controller.rb
@@ -350,9 +350,16 @@ class CollectionsController < ApplicationController
   end
 
   def save_tags
+    tags = nil
     if params['tag_data']
+      tags = params['tag_data']
+    elsif params['empty']
+      tags = {}
+    end
+
+    if tags
       props = @object.properties
-      props[:tags] = params['tag_data']
+      props[:tags] = tags
 
       if @object.update_attributes properties: props
       else
diff --git a/apps/workbench/app/views/collections/_show_tags.html.erb b/apps/workbench/app/views/collections/_show_tags.html.erb
index 54c9c5c..4ffe7ff 100644
--- a/apps/workbench/app/views/collections/_show_tags.html.erb
+++ b/apps/workbench/app/views/collections/_show_tags.html.erb
@@ -37,7 +37,7 @@
           <%= link_to(save_tags_collection_path, {class: 'btn btn-sm btn-primary collection-tag-save hide', :remote => true, method: 'post', return_to: request.url}) do %>
             Save
           <% end %>
-          <%= link_to(tags_collection_path, {class: 'btn btn-sm btn-primary collection-tag-cancel hide', :remote => true, method: 'post', return_to: request.url}) do %>
+          <%= link_to(tags_collection_path, {class: 'btn btn-sm btn-primary collection-tag-cancel hide', :remote => true, method: 'get', return_to: request.url}) do %>
             Cancel
           <% end %>
         </div>
diff --git a/apps/workbench/config/routes.rb b/apps/workbench/config/routes.rb
index 5bd4849..bf7118f 100644
--- a/apps/workbench/config/routes.rb
+++ b/apps/workbench/config/routes.rb
@@ -88,7 +88,7 @@ ArvadosWorkbench::Application.routes.draw do
     post 'unshare', :on => :member
     get 'choose', on: :collection
     post 'remove_selected_files', on: :member
-    post 'tags', on: :member
+    get 'tags', on: :member
     post 'save_tags', on: :member
   end
   get('/collections/download/:uuid/:reader_token/*file' => 'collections#show_file',

commit aee74220328be12113ea597e593b4ab6f120aeac
Author: radhika <radhika at curoverse.com>
Date:   Mon Jun 19 14:11:48 2017 -0400

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

diff --git a/apps/workbench/app/assets/javascripts/edit_collection_tags.js b/apps/workbench/app/assets/javascripts/edit_collection_tags.js
index 26b0ba7..8dc9d61 100644
--- a/apps/workbench/app/assets/javascripts/edit_collection_tags.js
+++ b/apps/workbench/app/assets/javascripts/edit_collection_tags.js
@@ -3,6 +3,7 @@
 $(document).
     on('click', '.collection-tag-save, .collection-tag-cancel', function(event) {
         $('.edit-collection-tags').removeClass('disabled');
+        $('#edit-collection-tags').attr("title", "Edit tags");
         $('.collection-tag-add').addClass('hide');
         $('.collection-tag-remove').addClass('hide');
         $('.collection-tag-save').addClass('hide');
@@ -11,6 +12,7 @@ $(document).
     }).
     on('click', '.edit-collection-tags', function(event) {
         $('.edit-collection-tags').addClass('disabled');
+        $('#edit-collection-tags').attr("title", "");
         $('.collection-tag-add').removeClass('hide');
         $('.collection-tag-remove').removeClass('hide');
         $('.collection-tag-save').removeClass('hide');
@@ -37,6 +39,11 @@ $(document).
       }).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>');
       });
+    }).
+    on('click', '.collection-tag-cancel', function(e){
+      $.ajax($(location).attr('pathname')+'/tags', {
+          type: 'POST'
+      });
     });
 
 jQuery(function($){
diff --git a/apps/workbench/app/controllers/collections_controller.rb b/apps/workbench/app/controllers/collections_controller.rb
index 8b3cc2f..8e1e8a5 100644
--- a/apps/workbench/app/controllers/collections_controller.rb
+++ b/apps/workbench/app/controllers/collections_controller.rb
@@ -345,12 +345,19 @@ class CollectionsController < ApplicationController
     end
   end
 
+  def tags
+    render
+  end
+
   def save_tags
-    props = @object.properties
-    props[:tags] = params['tag_data']
-    if @object.update_attributes properties: props
-    else
-      self.render_error status: 422
+    if params['tag_data']
+      props = @object.properties
+      props[:tags] = params['tag_data']
+
+      if @object.update_attributes properties: props
+      else
+        self.render_error status: 422
+      end
     end
   end
 
diff --git a/apps/workbench/app/views/collections/_show_tags.html.erb b/apps/workbench/app/views/collections/_show_tags.html.erb
index e1b0de7..54c9c5c 100644
--- a/apps/workbench/app/views/collections/_show_tags.html.erb
+++ b/apps/workbench/app/views/collections/_show_tags.html.erb
@@ -34,10 +34,12 @@
           <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">
-          <%= link_to(save_tags_collection_path, {class: 'btn btn-primary collection-tag-save hide', :remote => true, method: 'post', return_to: request.url}) do %>
+          <%= link_to(save_tags_collection_path, {class: 'btn btn-sm 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>
+          <%= link_to(tags_collection_path, {class: 'btn btn-sm btn-primary collection-tag-cancel hide', :remote => true, method: 'post', return_to: request.url}) do %>
+            Cancel
+          <% end %>
         </div>
 
         <div><div class="collection-tags-status"/></div></div>
diff --git a/apps/workbench/app/views/collections/save_tags.js.erb b/apps/workbench/app/views/collections/save_tags.js.erb
index e69de29..e2faff1 100644
--- a/apps/workbench/app/views/collections/save_tags.js.erb
+++ b/apps/workbench/app/views/collections/save_tags.js.erb
@@ -0,0 +1 @@
+$(".collection-tag-rows").html("<%= escape_javascript(render partial: 'show_tag_rows', locals: {object: @object}) %>");
diff --git a/apps/workbench/app/views/collections/tags.js.erb b/apps/workbench/app/views/collections/tags.js.erb
new file mode 100644
index 0000000..e2faff1
--- /dev/null
+++ b/apps/workbench/app/views/collections/tags.js.erb
@@ -0,0 +1 @@
+$(".collection-tag-rows").html("<%= escape_javascript(render partial: 'show_tag_rows', locals: {object: @object}) %>");
diff --git a/apps/workbench/config/routes.rb b/apps/workbench/config/routes.rb
index 880cc15..5bd4849 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 'tags', on: :member
     post 'save_tags', on: :member
   end
   get('/collections/download/:uuid/:reader_token/*file' => 'collections#show_file',

commit 55bdcab45a5e059ecc218099a30ff5ad231a627f
Author: radhika <radhika at curoverse.com>
Date:   Thu Jun 15 23:06:13 2017 -0400

    9426: collection Tags tab (in progress)
    
    Arvados-DCO-1.1-Signed-off-by: Radhika Chippada <radhika at curoverse.com>

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 dc9ed43..8b3cc2f 100644
--- a/apps/workbench/app/controllers/collections_controller.rb
+++ b/apps/workbench/app/controllers/collections_controller.rb
@@ -20,7 +20,7 @@ class CollectionsController < ApplicationController
   RELATION_LIMIT = 5
 
   def show_pane_list
-    panes = %w(Files Upload Provenance_graph Used_by Advanced)
+    panes = %w(Files Upload Tags Provenance_graph Used_by Advanced)
     panes = panes - %w(Upload) unless (@object.editable? rescue false)
     panes
   end
@@ -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
new file mode 100644
index 0000000..e1b0de7
--- /dev/null
+++ b/apps/workbench/app/views/collections/_show_tags.html.erb
@@ -0,0 +1,46 @@
+<%
+  object = @object unless object
+%>
+
+  <div class="collection-tags-container" style="padding-left:2em;padding-right:2em;">
+    <% if object.editable? %>
+      <p title="Edit tags" id="edit-collection-tags">
+        <button type="button" class="btn btn-primary edit-collection-tags">Edit</button>
+      </p>
+    <% end %>
+
+    <table class="table table-condensed table-fixedlayout collection-tags-table" border="1">
+      <colgroup>
+        <col width="5%" />
+        <col width="25%" />
+        <col width="70%" />
+      </colgroup>
+
+      <thead>
+        <tr>
+          <th></th>
+          <th>Key</th>
+          <th>Value</th>
+        </tr>
+      </thead>
+
+      <tbody class="collection-tag-rows">
+        <%= render partial: 'show_tag_rows', locals: {object: object} %>
+      </tbody>
+    </table>
+    <div>
+      <% if object.editable? %>
+        <div class="pull-left">
+          <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">
+          <%= 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