##// END OF EJS Templates
Renaming fixed
Zachary Sailer -
Show More
@@ -81,19 +81,6 b' class NamedNotebookHandler(IPythonHandler):'
81 81 self.finish(jsonapi.dumps({"name": notebook_name}))
82 82
83 83
84 class NotebookCopyHandler(IPythonHandler):
85
86 @web.authenticated
87 def get(self, notebook_path=None):
88 nbm = self.notebook_manager
89 name, path = nbm.named_notebook_path(notebook_path)
90 notebook_name = self.notebook_manager.copy_notebook(name, path)
91 if path==None:
92 self.redirect(url_path_join(self.base_project_url, "notebooks", notebook_name))
93 else:
94 self.redirect(url_path_join(self.base_project_url, "notebooks", path, notebook_name))
95
96
97 84 #-----------------------------------------------------------------------------
98 85 # URL to handler mappings
99 86 #-----------------------------------------------------------------------------
@@ -102,7 +89,6 b' class NotebookCopyHandler(IPythonHandler):'
102 89 _notebook_path_regex = r"(?P<notebook_path>.+)"
103 90
104 91 default_handlers = [
105 (r"/notebooks/%s/copy" % _notebook_path_regex, NotebookCopyHandler),
106 92 (r"/notebooks/%s" % _notebook_path_regex, NamedNotebookHandler),
107 93 (r"/notebooks/", NotebookHandler)
108 94 ]
@@ -96,20 +96,25 b' class FileNotebookManager(NotebookManager):'
96 96 def change_notebook(self, data, notebook_name, notebook_path=None):
97 97 """Changes notebook"""
98 98 changes = data.keys()
99 response = 200
99 100 for change in changes:
100 101 full_path = self.get_path(notebook_name, notebook_path)
101 if change == "notebook_name":
102 os.rename(full_path,
103 self.get_path(data['notebook_name'], notebook_path))
104 notebook_name = data['notebook_name']
105 if change == "notebook_path":
106 new_path = self.get_path(data['notebook_name'], data['notebook_path'])
102 if change == "name":
103 new_path = self.get_path(data['name'], notebook_path)
104 if os.path.isfile(new_path) == False:
105 os.rename(full_path,
106 self.get_path(data['name'], notebook_path))
107 notebook_name = data['name']
108 else:
109 response = 409
110 if change == "path":
111 new_path = self.get_path(data['name'], data['path'])
107 112 stutil.move(full_path, new_path)
108 notebook_path = data['notebook_path']
113 notebook_path = data['path']
109 114 if change == "content":
110 115 self.save_notebook(data, notebook_name, notebook_path)
111 116 model = self.notebook_model(notebook_name, notebook_path)
112 return model
117 return model, response
113 118
114 119 def notebook_exists(self, notebook_path):
115 120 """Does a notebook exist?"""
@@ -90,7 +90,8 b' class NotebookHandler(IPythonHandler):'
90 90 nbm = self.notebook_manager
91 91 notebook_name, notebook_path = nbm.named_notebook_path(notebook_path)
92 92 data = jsonapi.loads(self.request.body)
93 model = nbm.change_notebook(data, notebook_name, notebook_path)
93 model, response = nbm.change_notebook(data, notebook_name, notebook_path)
94 self.set_status(response)
94 95 self.finish(jsonapi.dumps(model))
95 96
96 97 @web.authenticated
@@ -1789,7 +1789,8 b' var IPython = (function (IPython) {'
1789 1789 data : JSON.stringify(name),
1790 1790 dataType: "json",
1791 1791 headers : {'Content-Type': 'application/json'},
1792 success : $.proxy(that.rename_success, this)
1792 success : $.proxy(that.rename_success, this),
1793 error : $.proxy(that.rename_error, this)
1793 1794 };
1794 1795 $([IPython.events]).trigger('notebook_rename.Notebook');
1795 1796 var url = this.baseProjectUrl() + 'api/notebooks/' + this.notebookPath()+ this.notebook_name;
@@ -1803,7 +1804,37 b' var IPython = (function (IPython) {'
1803 1804 this.session.notebook_rename(notebook_path);
1804 1805 $([IPython.events]).trigger('notebook_renamed.Notebook');
1805 1806 }
1806
1807
1808 Notebook.prototype.rename_error = function (json, status, xhr) {
1809 var that = this;
1810 var dialog = $('<div/>').append(
1811 $("<p/>").addClass("rename-message")
1812 .html('This notebook name already exists.')
1813 )
1814 IPython.dialog.modal({
1815 title: "Notebook Rename Error!",
1816 body: dialog,
1817 buttons : {
1818 "Cancel": {},
1819 "OK": {
1820 class: "btn-primary",
1821 click: function () {
1822 IPython.save_widget.rename_notebook();
1823 }}
1824 },
1825 open : function (event, ui) {
1826 var that = $(this);
1827 // Upon ENTER, click the OK button.
1828 that.find('input[type="text"]').keydown(function (event, ui) {
1829 if (event.which === utils.keycodes.ENTER) {
1830 that.find('.btn-primary').first().click();
1831 }
1832 });
1833 that.find('input[type="text"]').focus();
1834 }
1835 });
1836 }
1837
1807 1838 /**
1808 1839 * Request a notebook's data from the server.
1809 1840 *
@@ -129,7 +129,7 b' var IPython = (function (IPython) {'
129 129 var nbname = IPython.notebook.notebook_name;
130 130 var path = IPython.notebook.notebookPath();
131 131 var state = {"path": path+nbname}
132 window.history.pushState(state, "", "/notebook/" + path+nbname);
132 window.history.replaceState(state, "", "/notebooks/" + path+nbname);
133 133 }
134 134
135 135
@@ -75,16 +75,6 b' class ProjectRedirectHandler(IPythonHandler):'
75 75 url = self.base_project_url + 'tree'
76 76 self.redirect(url)
77 77
78 class NewFolderHandler(IPythonHandler):
79
80 @web.authenticated
81 def get(self, notebook_path):
82 nbm = self.notebook_manager
83 name, path = nbm.named_notebook_path(notebook_path)
84 nbm.add_new_folder(path)
85 url = self.base_project_url + 'tree/' + notebook_path
86 self.redirect(url)
87
88 78
89 79 #-----------------------------------------------------------------------------
90 80 # URL to handler mappings
@@ -94,7 +84,6 b' class NewFolderHandler(IPythonHandler):'
94 84 _notebook_path_regex = r"(?P<notebook_path>.+)"
95 85
96 86 default_handlers = [
97 (r"/tree/%s/-new" %_notebook_path_regex, NewFolderHandler),
98 87 (r"/tree/%s/" % _notebook_path_regex, TreePathRedirectHandler),
99 88 (r"/tree/%s" % _notebook_path_regex, ProjectPathDashboardHandler),
100 89 (r"/tree", ProjectDashboardHandler),
General Comments 0
You need to be logged in to leave comments. Login now