This part of things is working.

This commit is contained in:
Brian E. Granger 2015-12-17 13:06:38 -08:00 committed by Jonathan Frederic
parent 142ae515bc
commit 49b7b8c071
8 changed files with 61 additions and 13 deletions

View File

@ -293,8 +293,12 @@ class IPythonHandler(AuthenticatedHandler):
#---------------------------------------------------------------
@property
def nbextensions(self):
return self.settings.get('nbextensions', [])
def nbextensions_tree(self):
return self.settings.get('nbextensions_tree', {})
@property
def nbextensions_notebook(self):
return self.settings.get('nbextensions_notebook', {})
def get_template(self, name):
"""Return the jinja template object for a given name"""

View File

@ -22,7 +22,7 @@ class NotebookHandler(IPythonHandler):
redirects to the '/files/' handler if the name is not given."""
path = path.strip('/')
cm = self.contents_manager
nbextensions = json.dumps(self.nbextensions)
nbextensions = json.dumps(self.nbextensions_notebook)
# will raise 404 on not found
try:

View File

@ -220,6 +220,8 @@ class NotebookWebApplication(web.Application):
rate_limit_window=ipython_app.rate_limit_window,
nbextensions=ipython_app.nbextensions,
nbextensions_tree=ipython_app.nbextensions_tree,
nbextensions_notebook=ipython_app.nbextensions_notebook,
# authentication
cookie_secret=ipython_app.cookie_secret,
@ -693,8 +695,11 @@ class NotebookApp(JupyterApp):
path.append(os.path.join(get_ipython_dir(), 'nbextensions'))
return path
nbextensions = List(Unicode(), config=True,
help="A list of nbextensions to enable.")
nbextensions_tree = Dict(config=True,
help="A list of nbextensions to enable for the tree/dashboard page.")
nbextensions_notebook = Dict(config=True,
help="A list of nbextensions to enable for the notebook page.")
websocket_url = Unicode("", config=True,
help="""The base URL for websockets,

View File

@ -45,11 +45,27 @@ define([
* @return {Promise} that resolves to a list of loaded module handles.
*/
var load_extensions = function () {
console.log('load_extensions', arguments);
return Promise.all(Array.prototype.map.call(arguments, load_extension)).catch(function(err) {
console.error("Failed to load extension" + (err.requireModules.length>1?'s':'') + ":", err.requireModules, err);
});
};
/**
* Return a list of extensions that should be active
* The config for nbextensions comes in as a dict where keys are
* nbextensions paths and the values are a bool indicating if it
* should be active. This returns a list of nbextension paths
* where the value is true
*/
function filter_extensions(nbext_config) {
var active = [];
Object.keys(nbext_config).forEach(function (nbext) {
if (nbext_config[nbext]) {active.push(nbext);}
});
return active;
}
/**
* Wait for a config section to load, and then load the extensions specified
* in a 'load_extensions' key inside it.
@ -57,9 +73,8 @@ define([
function load_extensions_from_config(section) {
section.loaded.then(function() {
if (section.data.load_extensions) {
var nbextension_paths = Object.getOwnPropertyNames(
section.data.load_extensions);
load_extensions.apply(this, nbextension_paths);
var active = filter_extensions(section.data.load_extensions);
load_extensions.apply(this, active);
}
});
}
@ -842,6 +857,7 @@ define([
var utils = {
load_extension: load_extension,
load_extensions: load_extensions,
filter_extensions: filter_extensions,
load_extensions_from_config: load_extensions_from_config,
regex_split : regex_split,
uuid : uuid,

View File

@ -66,6 +66,8 @@ require([
// compat with old IPython, remove for IPython > 3.0
window.CodeMirror = CodeMirror;
// Setup all of the config related things
var common_options = {
ws_url : utils.get_body_data("wsUrl"),
base_url : utils.get_body_data("baseUrl"),
@ -77,6 +79,11 @@ require([
config_section.load();
var common_config = new configmod.ConfigSection('common', common_options);
common_config.load();
var nbextensions = $('body').data('nbextensions');
// Instantiate the main objects
var page = new page.Page();
var pager = new pager.Pager('div#pager', {
events: events});
@ -179,7 +186,10 @@ require([
enumerable: true,
configurable: false
});
// Now actually load nbextensions
var active = utils.filter_extensions(nbextensions);
utils.load_extensions.apply(null, active);
utils.load_extensions_from_config(config_section);
utils.load_extensions_from_config(common_config);
notebook.load_notebook(common_options.notebook_path);

View File

@ -32,10 +32,8 @@ require([
"use strict";
requirejs(['custom/custom'], function() {});
IPython.NotebookList = notebooklist.NotebookList;
// Setup all of the config related things
page = new page.Page();
var common_options = {
base_url: utils.get_body_data("baseUrl"),
notebook_path: utils.get_body_data("notebookPath"),
@ -46,6 +44,12 @@ require([
var common_config = new config.ConfigSection('common', common_options);
common_config.load();
var nbextensions = $('body').data('nbextensions');
// Instantiate the main objects
page = new page.Page();
var session_list = new sesssionlist.SesssionList($.extend({
events: events},
common_options));
@ -53,6 +57,7 @@ require([
base_url: common_options.base_url,
common_config: common_config
});
IPython.NotebookList = notebooklist.NotebookList;
var notebook_list = new notebooklist.NotebookList('#notebook_list', $.extend({
contents: contents,
session_list: session_list},
@ -141,6 +146,10 @@ require([
IPython.new_notebook_widget = new_buttons;
events.trigger('app_initialized.DashboardApp');
// Now actually load nbextensions
var active = utils.filter_extensions(nbextensions);
utils.load_extensions.apply(null, active);
utils.load_extensions_from_config(cfg);
utils.load_extensions_from_config(common_config);

View File

@ -8,7 +8,7 @@
data-base-url="{{base_url | urlencode}}"
data-notebook-path="{{notebook_path | urlencode}}"
data-terminals-available="{{terminals_available}}"
data-nbextensions="{{nbextensions}}"
{% endblock %}

View File

@ -3,6 +3,7 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import json
from tornado import web
from ..base.handlers import IPythonHandler, path_regex
from ..utils import url_path_join, url_escape
@ -37,6 +38,8 @@ class TreeHandler(IPythonHandler):
def get(self, path=''):
path = path.strip('/')
cm = self.contents_manager
nbextensions = json.dumps(self.nbextensions_tree)
if cm.dir_exists(path=path):
if cm.is_hidden(path):
self.log.info("Refusing to serve hidden directory, via 404 Error")
@ -48,6 +51,7 @@ class TreeHandler(IPythonHandler):
notebook_path=path,
breadcrumbs=breadcrumbs,
terminals_available=self.settings['terminals_available'],
nbextensions=nbextensions
))
elif cm.file_exists(path):
# it's not a directory, we have redirecting to do