From 96956c190926b5be74189d92ca012ec0d3d23acd 2013-10-17 21:09:07 From: Zachary Sailer Date: 2013-10-17 21:09:07 Subject: [PATCH] Renaming fixed --- diff --git a/IPython/html/notebook/handlers.py b/IPython/html/notebook/handlers.py index 45f1e17..44663d8 100644 --- a/IPython/html/notebook/handlers.py +++ b/IPython/html/notebook/handlers.py @@ -81,19 +81,6 @@ class NamedNotebookHandler(IPythonHandler): self.finish(jsonapi.dumps({"name": notebook_name})) -class NotebookCopyHandler(IPythonHandler): - - @web.authenticated - def get(self, notebook_path=None): - nbm = self.notebook_manager - name, path = nbm.named_notebook_path(notebook_path) - notebook_name = self.notebook_manager.copy_notebook(name, path) - if path==None: - self.redirect(url_path_join(self.base_project_url, "notebooks", notebook_name)) - else: - self.redirect(url_path_join(self.base_project_url, "notebooks", path, notebook_name)) - - #----------------------------------------------------------------------------- # URL to handler mappings #----------------------------------------------------------------------------- @@ -102,7 +89,6 @@ class NotebookCopyHandler(IPythonHandler): _notebook_path_regex = r"(?P.+)" default_handlers = [ - (r"/notebooks/%s/copy" % _notebook_path_regex, NotebookCopyHandler), (r"/notebooks/%s" % _notebook_path_regex, NamedNotebookHandler), (r"/notebooks/", NotebookHandler) ] diff --git a/IPython/html/services/notebooks/filenbmanager.py b/IPython/html/services/notebooks/filenbmanager.py index 5743b88..59bbd73 100644 --- a/IPython/html/services/notebooks/filenbmanager.py +++ b/IPython/html/services/notebooks/filenbmanager.py @@ -96,20 +96,25 @@ class FileNotebookManager(NotebookManager): def change_notebook(self, data, notebook_name, notebook_path=None): """Changes notebook""" changes = data.keys() + response = 200 for change in changes: full_path = self.get_path(notebook_name, notebook_path) - if change == "notebook_name": - os.rename(full_path, - self.get_path(data['notebook_name'], notebook_path)) - notebook_name = data['notebook_name'] - if change == "notebook_path": - new_path = self.get_path(data['notebook_name'], data['notebook_path']) + if change == "name": + new_path = self.get_path(data['name'], notebook_path) + if os.path.isfile(new_path) == False: + os.rename(full_path, + self.get_path(data['name'], notebook_path)) + notebook_name = data['name'] + else: + response = 409 + if change == "path": + new_path = self.get_path(data['name'], data['path']) stutil.move(full_path, new_path) - notebook_path = data['notebook_path'] + notebook_path = data['path'] if change == "content": self.save_notebook(data, notebook_name, notebook_path) model = self.notebook_model(notebook_name, notebook_path) - return model + return model, response def notebook_exists(self, notebook_path): """Does a notebook exist?""" diff --git a/IPython/html/services/notebooks/handlers.py b/IPython/html/services/notebooks/handlers.py index 453c95c..09031b4 100644 --- a/IPython/html/services/notebooks/handlers.py +++ b/IPython/html/services/notebooks/handlers.py @@ -90,7 +90,8 @@ class NotebookHandler(IPythonHandler): nbm = self.notebook_manager notebook_name, notebook_path = nbm.named_notebook_path(notebook_path) data = jsonapi.loads(self.request.body) - model = nbm.change_notebook(data, notebook_name, notebook_path) + model, response = nbm.change_notebook(data, notebook_name, notebook_path) + self.set_status(response) self.finish(jsonapi.dumps(model)) @web.authenticated diff --git a/IPython/html/static/notebook/js/notebook.js b/IPython/html/static/notebook/js/notebook.js index fa65407..740c460 100644 --- a/IPython/html/static/notebook/js/notebook.js +++ b/IPython/html/static/notebook/js/notebook.js @@ -1789,7 +1789,8 @@ var IPython = (function (IPython) { data : JSON.stringify(name), dataType: "json", headers : {'Content-Type': 'application/json'}, - success : $.proxy(that.rename_success, this) + success : $.proxy(that.rename_success, this), + error : $.proxy(that.rename_error, this) }; $([IPython.events]).trigger('notebook_rename.Notebook'); var url = this.baseProjectUrl() + 'api/notebooks/' + this.notebookPath()+ this.notebook_name; @@ -1803,7 +1804,37 @@ var IPython = (function (IPython) { this.session.notebook_rename(notebook_path); $([IPython.events]).trigger('notebook_renamed.Notebook'); } - + + Notebook.prototype.rename_error = function (json, status, xhr) { + var that = this; + var dialog = $('
').append( + $("

").addClass("rename-message") + .html('This notebook name already exists.') + ) + IPython.dialog.modal({ + title: "Notebook Rename Error!", + body: dialog, + buttons : { + "Cancel": {}, + "OK": { + class: "btn-primary", + click: function () { + IPython.save_widget.rename_notebook(); + }} + }, + open : function (event, ui) { + var that = $(this); + // Upon ENTER, click the OK button. + that.find('input[type="text"]').keydown(function (event, ui) { + if (event.which === utils.keycodes.ENTER) { + that.find('.btn-primary').first().click(); + } + }); + that.find('input[type="text"]').focus(); + } + }); + } + /** * Request a notebook's data from the server. * diff --git a/IPython/html/static/notebook/js/savewidget.js b/IPython/html/static/notebook/js/savewidget.js index c421457..5505031 100644 --- a/IPython/html/static/notebook/js/savewidget.js +++ b/IPython/html/static/notebook/js/savewidget.js @@ -129,7 +129,7 @@ var IPython = (function (IPython) { var nbname = IPython.notebook.notebook_name; var path = IPython.notebook.notebookPath(); var state = {"path": path+nbname} - window.history.pushState(state, "", "/notebook/" + path+nbname); + window.history.replaceState(state, "", "/notebooks/" + path+nbname); } diff --git a/IPython/html/tree/handlers.py b/IPython/html/tree/handlers.py index a8882cb..e94f784 100644 --- a/IPython/html/tree/handlers.py +++ b/IPython/html/tree/handlers.py @@ -75,16 +75,6 @@ class ProjectRedirectHandler(IPythonHandler): url = self.base_project_url + 'tree' self.redirect(url) -class NewFolderHandler(IPythonHandler): - - @web.authenticated - def get(self, notebook_path): - nbm = self.notebook_manager - name, path = nbm.named_notebook_path(notebook_path) - nbm.add_new_folder(path) - url = self.base_project_url + 'tree/' + notebook_path - self.redirect(url) - #----------------------------------------------------------------------------- # URL to handler mappings @@ -94,7 +84,6 @@ class NewFolderHandler(IPythonHandler): _notebook_path_regex = r"(?P.+)" default_handlers = [ - (r"/tree/%s/-new" %_notebook_path_regex, NewFolderHandler), (r"/tree/%s/" % _notebook_path_regex, TreePathRedirectHandler), (r"/tree/%s" % _notebook_path_regex, ProjectPathDashboardHandler), (r"/tree", ProjectDashboardHandler),