removed '/new' URL and added POST notebook request

This commit is contained in:
Zachary Sailer 2013-07-25 17:45:27 -07:00 committed by MinRK
parent 8261ac2cb9
commit a74b9a018b
5 changed files with 35 additions and 31 deletions

View File

@ -19,6 +19,8 @@ Authors:
import os
from tornado import web
HTTPError = web.HTTPError
from zmq.utils import jsonapi
from ..base.handlers import IPythonHandler
from ..utils import url_path_join
@ -29,20 +31,12 @@ from urllib import quote
#-----------------------------------------------------------------------------
class NewPathHandler(IPythonHandler):
@web.authenticated
def get(self, notebook_path):
notebook_name = self.notebook_manager.new_notebook(notebook_path)
self.redirect(url_path_join(self.base_project_url,"notebooks", notebook_path, notebook_name))
class NewHandler(IPythonHandler):
class NotebookHandler(IPythonHandler):
@web.authenticated
def get(self):
def post(self):
notebook_name = self.notebook_manager.new_notebook()
self.redirect(url_path_join(self.base_project_url, "notebooks", notebook_name))
self.finish(jsonapi.dumps({"name": notebook_name}))
class NamedNotebookHandler(IPythonHandler):
@ -68,11 +62,11 @@ class NamedNotebookHandler(IPythonHandler):
mathjax_url=self.mathjax_url,
)
)
@web.authenticated
def post(self, notebook_path):
nbm =self.notebook_manager
notebook_name = nbm.new_notebook()
notebook_name = self.notebook_manager.new_notebook(notebook_path)
self.finish(jsonapi.dumps({"name": notebook_name}))
class NotebookCopyHandler(IPythonHandler):
@ -96,8 +90,7 @@ class NotebookCopyHandler(IPythonHandler):
_notebook_path_regex = r"(?P<notebook_path>.+)"
default_handlers = [
(r"/notebooks/%s/new" % _notebook_path_regex, NewPathHandler),
(r"/notebooks/new", NewHandler),
(r"/notebooks/%s/copy" % _notebook_path_regex, NotebookCopyHandler),
(r"/notebooks/%s" % _notebook_path_regex, NamedNotebookHandler)
(r"/notebooks/%s" % _notebook_path_regex, NamedNotebookHandler),
(r"/notebooks/", NotebookHandler)
]

View File

@ -78,7 +78,7 @@ var IPython = (function (IPython) {
// File
var that = this;
this.element.find('#new_notebook').click(function () {
window.open(that.baseProjectUrl() + 'notebooks/' + that.notebookPath() +'new');
IPython.notebook.new_notebook();
});
this.element.find('#open_notebook').click(function () {
window.open(that.baseProjectUrl() + 'tree/' + that.notebookPath());

View File

@ -89,7 +89,7 @@ var IPython = (function (IPython) {
if (path != 'None') {
if (path[path.length-1] != '/') {
path = path.substring(0,path.length);
};
};
return path;
} else {
return '';
@ -1743,6 +1743,22 @@ var IPython = (function (IPython) {
$([IPython.events]).trigger('notebook_save_failed.Notebook');
};
Notebook.prototype.new_notebook = function(){
var path = this.notebookPath();
var settings = {
processData : false,
cache : false,
type : "POST",
dataType : "json",
success:$.proxy(function (data, status, xhr){
notebook_name = data.name;
window.open(this._baseProjectUrl +'notebooks/' + this.notebookPath()+ notebook_name);
}, this)
};
var url = this._baseProjectUrl + 'notebooks/' + path;
$.ajax(url,settings);
};
Notebook.prototype.notebook_rename = function (nbname) {
var that = this;

View File

@ -13,18 +13,11 @@
$(document).ready(function () {
IPython.page = new IPython.Page();
if ($('body').data('notebookPath') == "") {
$('#new_notebook').button().click(function (e) {
window.open($('body').data('baseProjectUrl')+'notebooks/'+'new');
});
}
else {
$('#new_notebook').button().click(function (e) {
window.open($('body').data('baseProjectUrl')+'notebooks/'+$('body').data('notebookPath') + '/new');
});
}
$('#new_notebook').button().click(function (e) {
IPython.notebook_list.new_notebook($('body').data('baseProjectUrl'))
});
IPython.notebook_list = new IPython.NotebookList('#notebook_list');
IPython.cluster_list = new IPython.ClusterList('#cluster_list');
IPython.login_widget = new IPython.LoginWidget('#login_widget');

View File

@ -338,6 +338,8 @@ var IPython = (function (IPython) {
};
IPython.NotebookList = NotebookList;
return IPython;