mirror of
https://github.com/jupyter/notebook.git
synced 2024-12-27 04:20:22 +08:00
removed '/new' URL and added POST notebook request
This commit is contained in:
parent
8261ac2cb9
commit
a74b9a018b
@ -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)
|
||||
]
|
||||
|
@ -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());
|
||||
|
@ -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;
|
||||
|
@ -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');
|
||||
|
@ -338,6 +338,8 @@ var IPython = (function (IPython) {
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
IPython.NotebookList = NotebookList;
|
||||
|
||||
return IPython;
|
||||
|
Loading…
Reference in New Issue
Block a user