From 55bdcab45a5e059ecc218099a30ff5ad231a627f Mon Sep 17 00:00:00 2001 From: radhika Date: Thu, 15 Jun 2017 23:06:13 -0400 Subject: [PATCH] 9426: collection Tags tab (in progress) Arvados-DCO-1.1-Signed-off-by: Radhika Chippada --- .../javascripts/edit_collection_tags.js | 52 +++++++++++++++++++ .../app/controllers/collections_controller.rb | 11 +++- .../views/collections/_show_tag_rows.html.erb | 26 ++++++++++ .../app/views/collections/_show_tags.html.erb | 46 ++++++++++++++++ .../app/views/collections/save_tags.js.erb | 0 apps/workbench/config/routes.rb | 1 + 6 files changed, 135 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 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 0000000000..26b0ba7eb9 --- /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('

Saved successfully.

'); + }).fail(function(jqxhr, status, error) { + $('.collection-tags-status').append('

We are sorry. There was an error saving tags. Please try again.

'); + }); + }); + +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 dc9ed43c40..8b3cc2feb8 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 0000000000..da699256e9 --- /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| %> + + + + + + <%= k %> + + + <%= v %> + + + <% end %> + + + + + + + + + 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 0000000000..e1b0de7ae2 --- /dev/null +++ b/apps/workbench/app/views/collections/_show_tags.html.erb @@ -0,0 +1,46 @@ +<% + object = @object unless object +%> + +
+ <% if object.editable? %> +

+ +

+ <% end %> + + + + + + + + + + + + + + + + + + <%= render partial: 'show_tag_rows', locals: {object: object} %> + +
KeyValue
+
+ <% if object.editable? %> +
+ +
+
+ <%= 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 %> + +
+ +
+ <% end %> +
+
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 0000000000..e69de29bb2 diff --git a/apps/workbench/config/routes.rb b/apps/workbench/config/routes.rb index badb471d64..880cc15f6d 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) -- 2.30.2