From 4a9e31ed3066461a95bb5e3669bbe0f7ec0bf858 Mon Sep 17 00:00:00 2001 From: Nathan Daly Date: Thu, 7 Jan 2016 23:13:35 -0800 Subject: [PATCH 1/5] Adds a Move button to the notebooklist interface next to Rename. With this button, you can now move files or directories to any path in the notebook, including creating new directories (like 'mv -p'). To move a file, you specify the new destination directory's path. This achieves the same effect as renaming a file with a new relative path, but is more clear to users unfamiliar with unix commands -- especially with regard to moving to a parent directory. Can only move one file at a time currently. --- notebook/static/tree/js/notebooklist.js | 77 +++++++++++++++++++++++++ notebook/static/tree/less/tree.less | 4 ++ notebook/templates/tree.html | 1 + 3 files changed, 82 insertions(+) diff --git a/notebook/static/tree/js/notebooklist.js b/notebook/static/tree/js/notebooklist.js index 79e2b822c..b2e0099b8 100644 --- a/notebook/static/tree/js/notebooklist.js +++ b/notebook/static/tree/js/notebooklist.js @@ -129,6 +129,7 @@ define([ // Bind events for action buttons. $('.rename-button').click($.proxy(this.rename_selected, this)); + $('.move-button').click($.proxy(this.move_selected, this)); $('.shutdown-button').click($.proxy(this.shutdown_selected, this)); $('.duplicate-button').click($.proxy(this.duplicate_selected, this)); $('.delete-button').click($.proxy(this.delete_selected, this)); @@ -550,6 +551,15 @@ 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-button').css('display', 'inline-block'); + } else { + $('.move-button').css('display', 'none'); + } + // Shutdown is only visible when one or more notebooks running notebooks // are selected and no non-notebook items are selected. if (has_running_notebook && !(has_file || has_directory)) { @@ -774,6 +784,73 @@ define([ }); }; + NotebookList.prototype.move_selected = function() { + // TODO(nhdaly): Support moving multiple items at once. + if (this.selected.length !== 1){ + return; + } + + var that = this; + var item_path = this.selected[0].path; + var item_name = this.selected[0].name; + var item_type = this.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 + ':') + ).append( + $("
") + ).append(input); + var d = dialog.modal({ + title : "Move "+ item_type, + body : dialog_body, + buttons : { + OK : { + 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'} + } + }); + console.warn('Error durring moving :', e); + }); + } + }, + Cancel : {} + }, + open : function () { + // Upon ENTER, click the OK button. + input.keydown(function (event) { + if (event.which === keyboard.keycodes.enter) { + d.find('.btn-primary').first().click(); + return false; + } + }); + input.focus(); + if (input.val().indexOf(".") > 0) { + input[0].setSelectionRange(0,input.val().indexOf(".")); + } else { + input.select(); + } + } + }); + }; + NotebookList.prototype.delete_selected = function() { var message; if (this.selected.length === 1) { diff --git a/notebook/static/tree/less/tree.less b/notebook/static/tree/less/tree.less index ef733a540..d19dedd91 100644 --- a/notebook/static/tree/less/tree.less +++ b/notebook/static/tree/less/tree.less @@ -327,6 +327,10 @@ ul#new-menu { display: none; } +.move-button { + display: none; +} + .shutdown-button { display: none; } diff --git a/notebook/templates/tree.html b/notebook/templates/tree.html index 966242b14..acdf97141 100644 --- a/notebook/templates/tree.html +++ b/notebook/templates/tree.html @@ -31,6 +31,7 @@ data-terminals-available="{{terminals_available}}"
+
From a05b947f8d88acc56c630f8d082c1536575e8ac5 Mon Sep 17 00:00:00 2001 From: Nathan Daly Date: Mon, 18 Jan 2016 22:45:28 -0800 Subject: [PATCH 2/5] Switched "Move Items" Cancel/Okay button orders + variable clean-up. Part of addressing Issue #941. --- notebook/static/tree/js/notebooklist.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/notebook/static/tree/js/notebooklist.js b/notebook/static/tree/js/notebooklist.js index b2e0099b8..8f280634d 100644 --- a/notebook/static/tree/js/notebooklist.js +++ b/notebook/static/tree/js/notebooklist.js @@ -785,15 +785,16 @@ define([ }; NotebookList.prototype.move_selected = function() { + var that = this; + // TODO(nhdaly): Support moving multiple items at once. - if (this.selected.length !== 1){ + if (that.selected.length !== 1){ return; } - var that = this; - var item_path = this.selected[0].path; - var item_name = this.selected[0].name; - var item_type = this.selected[0].type; + 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') @@ -808,6 +809,7 @@ define([ title : "Move "+ item_type, body : dialog_body, buttons : { + Cancel : {}, OK : { class: "btn-primary", click: function() { @@ -830,8 +832,7 @@ define([ console.warn('Error durring moving :', e); }); } - }, - Cancel : {} + } }, open : function () { // Upon ENTER, click the OK button. From ec47775d5044b4f62dbc792049fecac24ed604bc Mon Sep 17 00:00:00 2001 From: Nathan Daly Date: Mon, 18 Jan 2016 23:17:16 -0800 Subject: [PATCH 3/5] Removed code unnecessary for Move to select the file name up to a period. The Move button expects a file path, which shouldn't include a file extension suffix. --- notebook/static/tree/js/notebooklist.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/notebook/static/tree/js/notebooklist.js b/notebook/static/tree/js/notebooklist.js index 8f280634d..91e9ecdec 100644 --- a/notebook/static/tree/js/notebooklist.js +++ b/notebook/static/tree/js/notebooklist.js @@ -843,11 +843,8 @@ define([ } }); input.focus(); - if (input.val().indexOf(".") > 0) { - input[0].setSelectionRange(0,input.val().indexOf(".")); - } else { - input.select(); - } + // Highlight the current path in the input box. + input.select(); } }); }; From ac9b107e2b219b8cbd4a326366dd8a829c852846 Mon Sep 17 00:00:00 2001 From: Nathan Daly Date: Wed, 3 Feb 2016 22:33:54 -0600 Subject: [PATCH 4/5] changed initial input focus behavior --- notebook/static/tree/js/notebooklist.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/notebook/static/tree/js/notebooklist.js b/notebook/static/tree/js/notebooklist.js index 91e9ecdec..319e65568 100644 --- a/notebook/static/tree/js/notebooklist.js +++ b/notebook/static/tree/js/notebooklist.js @@ -775,6 +775,7 @@ define([ } }); input.focus(); + // Highlight the filename (up to the filetype suffix) in the input field. if (input.val().indexOf(".") > 0) { input[0].setSelectionRange(0,input.val().indexOf(".")); } else { @@ -842,9 +843,8 @@ define([ return false; } }); + // Put the cursor at the end of the input. input.focus(); - // Highlight the current path in the input box. - input.select(); } }); }; From ecbeb59f1826f8fe62fb4a74560bb616e5a0504f Mon Sep 17 00:00:00 2001 From: Nathan Daly Date: Wed, 3 Feb 2016 23:17:46 -0600 Subject: [PATCH 5/5] adds TODO regarding the fancier UI --- notebook/static/tree/js/notebooklist.js | 1 + 1 file changed, 1 insertion(+) diff --git a/notebook/static/tree/js/notebooklist.js b/notebook/static/tree/js/notebooklist.js index 319e65568..995b8fb13 100644 --- a/notebook/static/tree/js/notebooklist.js +++ b/notebook/static/tree/js/notebooklist.js @@ -835,6 +835,7 @@ define([ } } }, + // TODO: Consider adding fancier UI per Issue #941. open : function () { // Upon ENTER, click the OK button. input.keydown(function (event) {