From: Peter Amstutz Date: Wed, 12 Apr 2017 20:10:13 +0000 (-0400) Subject: Merge branch '8567-moar-docker' refs #8567 X-Git-Tag: 1.1.0~309 X-Git-Url: https://git.arvados.org/arvados.git/commitdiff_plain/0035033f6bf6db955b116e2e0cc052bc5c79d80e?hp=bafff6941293d4cc12cda4209f1d7a2b10274ea3 Merge branch '8567-moar-docker' refs #8567 --- diff --git a/apps/workbench/app/assets/javascripts/edit_collection.js b/apps/workbench/app/assets/javascripts/edit_collection.js new file mode 100644 index 0000000000..7da3e95c06 --- /dev/null +++ b/apps/workbench/app/assets/javascripts/edit_collection.js @@ -0,0 +1,33 @@ +// On loading of a collection, enable the "lock" button and +// disable all file modification controls (upload, rename, delete) +$(document). + ready(function(event) { + $(".btn-collection-file-control").addClass("disabled"); + $(".tab-pane-Upload").addClass("disabled"); + $("#Upload-tab").attr("data-toggle", "disabled"); + }). + on('click', '.lock-collection-btn', function(event) { + classes = $(event.target).attr('class') + + if (classes.indexOf("fa-lock") != -1) { + // About to unlock; warn and get confirmation from user + if (confirm("Adding, renaming, and deleting files changes the portable data hash. Are you sure you want to unlock the collection?")) { + $(".lock-collection-btn").removeClass("fa-lock"); + $(".lock-collection-btn").addClass("fa-unlock"); + $(".lock-collection-btn").attr("title", "Lock collection to prevent editing files"); + $(".btn-collection-file-control").removeClass("disabled"); + $(".tab-pane-Upload").removeClass("disabled"); + $("#Upload-tab").attr("data-toggle", "tab"); + } else { + // User clicked "no" and so do not unlock + } + } else { + // Lock it back + $(".lock-collection-btn").removeClass("fa-unlock"); + $(".lock-collection-btn").addClass("fa-lock"); + $(".lock-collection-btn").attr("title", "Unlock collection to edit files"); + $(".btn-collection-file-control").addClass("disabled"); + $(".tab-pane-Upload").addClass("disabled"); + $("#Upload-tab").attr("data-toggle", "disabled"); + } + }); diff --git a/apps/workbench/app/assets/javascripts/selection.js.erb b/apps/workbench/app/assets/javascripts/selection.js.erb index 5c69c50c11..f60bef7ddb 100644 --- a/apps/workbench/app/assets/javascripts/selection.js.erb +++ b/apps/workbench/app/assets/javascripts/selection.js.erb @@ -53,6 +53,8 @@ function dispatch_selection_action() { function enable_disable_selection_actions() { var $container = $(this); var $checked = $('.persistent-selection:checkbox:checked', $container); + var collection_lock_classes = $('.lock-collection-btn').attr('class') + $('[data-selection-action]', $container). closest('div.btn-group-sm'). find('ul li'). @@ -74,6 +76,11 @@ function enable_disable_selection_actions() { toggleClass('disabled', ($checked.filter('[value*=-4zz18-]').length < 1) || ($checked.length != $checked.filter('[value*=-4zz18-]').length)); + $('[data-selection-action=remove-selected-files]', $container). + closest('li'). + toggleClass('disabled', + ($checked.length < 0) || + !($checked.length > 0 && collection_lock_classes && collection_lock_classes.indexOf("fa-unlock") !=-1)); } $(document). diff --git a/apps/workbench/app/assets/stylesheets/collections.css.scss b/apps/workbench/app/assets/stylesheets/collections.css.scss index 35c2249ecf..2d2d0f25d1 100644 --- a/apps/workbench/app/assets/stylesheets/collections.css.scss +++ b/apps/workbench/app/assets/stylesheets/collections.css.scss @@ -64,3 +64,9 @@ $active-bg: #39b3d7; .btn-group.toggle-persist .btn-info.active { background-color: $active-bg; } + +.lock-collection-btn { + display: inline-block; + padding: .5em 2em; + margin: 0 1em; +} diff --git a/apps/workbench/app/controllers/collections_controller.rb b/apps/workbench/app/controllers/collections_controller.rb index 02b204f18c..dc9ed43c40 100644 --- a/apps/workbench/app/controllers/collections_controller.rb +++ b/apps/workbench/app/controllers/collections_controller.rb @@ -326,12 +326,18 @@ class CollectionsController < ApplicationController end arv_coll = Arv::Collection.new(@object.manifest_text) - arv_coll.rename "./"+file_path, new_file_path - if @object.update_attributes manifest_text: arv_coll.manifest_text - show - else + if arv_coll.exist?(new_file_path) + @errors = 'Duplicate file path. Please use a different name.' self.render_error status: 422 + else + arv_coll.rename "./"+file_path, new_file_path + + if @object.update_attributes manifest_text: arv_coll.manifest_text + show + else + self.render_error status: 422 + end end else # Not a file rename; use default diff --git a/apps/workbench/app/views/application/_content.html.erb b/apps/workbench/app/views/application/_content.html.erb index 9441a46c26..a22608d3c9 100644 --- a/apps/workbench/app/views/application/_content.html.erb +++ b/apps/workbench/app/views/application/_content.html.erb @@ -29,7 +29,7 @@ end %> -