From 50c388ae5a08d6b2b15da4ace341a88fe9783650 Mon Sep 17 00:00:00 2001 From: Nathan Daly Date: Mon, 18 Jan 2016 22:56:58 -0800 Subject: [PATCH 1/2] Expands "Move" button to support moving multiple files together. "Move" button now displays for 1 or more selected items, and attempts to move all of them to the entered destination. For each move that fails, an error is displayed, but the other items are still moved. Addresses Issue #942. --- notebook/static/tree/js/notebooklist.js | 61 +++++++++++++------------ 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/notebook/static/tree/js/notebooklist.js b/notebook/static/tree/js/notebooklist.js index 7050517221..0823200085 100644 --- a/notebook/static/tree/js/notebooklist.js +++ b/notebook/static/tree/js/notebooklist.js @@ -551,10 +551,9 @@ define([ $('.rename-button').css('display', 'none'); } - // Move is only visible when one item is selected, and it is not a - // running notebook. - // TODO(nhdaly): Add support for moving multiple items at once. - if (selected.length === 1 && !has_running_notebook) { + // Move is visible iff at least one item is selected, and none of them + // are a running notebook. + if (selected.length >= 1 && !has_running_notebook) { $('.move-button').css('display', 'inline-block'); } else { $('.move-button').css('display', 'none'); @@ -792,27 +791,24 @@ define([ NotebookList.prototype.move_selected = function() { var that = this; + var num_items = that.selected.length; - // TODO(nhdaly): Support moving multiple items at once. - if (that.selected.length !== 1){ + // Can move one or more selected items. + if (!(num_items >= 1)) { return; } - var item_path = that.selected[0].path; - var item_name = that.selected[0].name; - var item_type = that.selected[0].type; - // Open a dialog to enter the new path, with current path as default. var input = $('').attr('type','text').attr('size','25').addClass('form-control') .val(utils.url_path_join('/', that.notebook_path)); var dialog_body = $('
').append( $("

").addClass("rename-message") - .text('Enter new destination directory path for '+ item_type + ':') + .text('Enter new destination directory path for '+ num_items + ' items:') ).append( $("
") ).append(input); var d = dialog.modal({ - title : "Move "+ item_type, + title : "Move "+ num_items + " Items", body : dialog_body, default_button: "Cancel", buttons : { @@ -820,24 +816,31 @@ define([ Move : { class: "btn-primary", click: function() { - // Construct the new path using the user input and its name. - var new_path = utils.url_path_join(input.val(), item_name) - that.contents.rename(item_path, new_path).then(function() { - that.load_list(); - }).catch(function(e) { - dialog.modal({ - title: "Move Failed", - body: $('

') - .text("An error occurred while moving \"" + item_name + "\" from \"" + item_path + "\" to \"" + new_path + "\".") - .append($('
') - .addClass('alert alert-danger') - .text(e.message || e)), - buttons: { - OK: {'class': 'btn-primary'} - } + // Move all the items. + that.selected.forEach(function(item) { + var item_path = item.path; + var item_name = item.name; + // Construct the new path using the user input and the item's name. + var new_path = utils.url_path_join(input.val(), item_name); + that.contents.rename(item_path, new_path).then(function() { + // After each move finishes, reload the list. + that.load_list(); + }).catch(function(e) { + // If any of the moves fails, show this dialog for that move. + dialog.modal({ + title: "Move Failed", + body: $('
') + .text("An error occurred while moving \"" + item_name + "\" from \"" + item_path + "\" to \"" + new_path + "\".") + .append($('
') + .addClass('alert alert-danger') + .text(e.message || e)), + buttons: { + OK: {'class': 'btn-primary'} + } + }); + console.warn('Error durring moving :', e); }); - console.warn('Error durring moving :', e); - }); + }); // End of forEach. } } }, From a595e4338b2c7502f5d069017944609122bcdc2f Mon Sep 17 00:00:00 2001 From: Nathan Daly Date: Mon, 15 Feb 2016 12:51:58 -0800 Subject: [PATCH 2/2] fixed typo: s/durring/during/g in notebooklist.js --- notebook/static/tree/js/notebooklist.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/notebook/static/tree/js/notebooklist.js b/notebook/static/tree/js/notebooklist.js index 0823200085..cabff155dc 100644 --- a/notebook/static/tree/js/notebooklist.js +++ b/notebook/static/tree/js/notebooklist.js @@ -102,7 +102,7 @@ define([ OK: {'class': 'btn-primary'} } }); - console.warn('Error durring New file creation', e); + console.warn('Error during New file creation', e); }); that.load_sessions(); }); @@ -122,7 +122,7 @@ define([ OK: {'class': 'btn-primary'} } }); - console.warn('Error durring New directory creation', e); + console.warn('Error during New directory creation', e); }); that.load_sessions(); }); @@ -765,7 +765,7 @@ define([ OK: {'class': 'btn-primary'} } }); - console.warn('Error durring renaming :', e); + console.warn('Error during renaming :', e); }); } } @@ -838,7 +838,7 @@ define([ OK: {'class': 'btn-primary'} } }); - console.warn('Error durring moving :', e); + console.warn('Error during moving :', e); }); }); // End of forEach. } @@ -896,7 +896,7 @@ define([ OK: {'class': 'btn-primary'} } }); - console.warn('Error durring content deletion:', e); + console.warn('Error during content deletion:', e); }); }); } @@ -939,7 +939,7 @@ define([ OK: {'class': 'btn-primary'} } }); - console.warn('Error durring content duplication', e); + console.warn('Error during content duplication', e); }); }); } @@ -1013,7 +1013,7 @@ define([ } }} }); - console.warn('Error durring notebook uploading', e); + console.warn('Error during notebook uploading', e); return false; } content_type = 'application/json';