From: radhika Date: Tue, 20 Jun 2017 21:25:25 +0000 (-0400) Subject: Merge branch 'master' into 9426-collection-tags X-Git-Url: https://git.arvados.org/arvados.git/commitdiff_plain/ef15d01d2cb3c988185edd2b891d2b227fb33f3b?hp=8c2b89cb6a34b2f1a4ed672e8a883c680ffca80a Merge branch 'master' into 9426-collection-tags --- 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..06cd64b00a --- /dev/null +++ b/apps/workbench/app/assets/javascripts/edit_collection_tags.js @@ -0,0 +1,65 @@ +// 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'); + $('#edit-collection-tags').attr("title", "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', '.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'); + $('.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(); + } + }); + + 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 + }).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.

'); + }); + }). + on('click', '.collection-tag-cancel', function(e){ + $.ajax($(location).attr('pathname')+'/tags', { + type: 'GET' + }); + }); + +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..bfba2f57f8 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,29 @@ class CollectionsController < ApplicationController end end + def tags + render + 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] = tags + + if @object.update_attributes properties: props + else + self.render_error status: 422 + end + 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..4ffe7ff5f9 --- /dev/null +++ b/apps/workbench/app/views/collections/_show_tags.html.erb @@ -0,0 +1,48 @@ +<% + 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-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: 'get', return_to: request.url}) do %> + Cancel + <% 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..e2faff169a --- /dev/null +++ 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 0000000000..e2faff169a --- /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 badb471d64..bf7118f701 100644 --- a/apps/workbench/config/routes.rb +++ b/apps/workbench/config/routes.rb @@ -88,6 +88,8 @@ ArvadosWorkbench::Application.routes.draw do post 'unshare', :on => :member get 'choose', on: :collection post 'remove_selected_files', on: :member + get 'tags', on: :member + post 'save_tags', on: :member end get('/collections/download/:uuid/:reader_token/*file' => 'collections#show_file', format: false)