various unicode fixes

- remove notebookPath, notebookName, and baseProjectUrl methods everywhere
- use base_project_url *attributes* instead
- we should never use escaped URLs except when making an actual request

Should fix issues with double-escaping
This commit is contained in:
MinRK 2014-02-05 15:18:21 -08:00
parent beaa75b416
commit 13fc9022d9
9 changed files with 118 additions and 149 deletions

View File

@ -10,10 +10,11 @@
//============================================================================ //============================================================================
var IPython = (function (IPython) { var IPython = (function (IPython) {
"use strict";
var LoginWidget = function (selector, options) { var LoginWidget = function (selector, options) {
var options = options || {}; options = options || {};
this.base_url = options.baseProjectUrl || $('body').data('baseProjectUrl') ; this.base_project_url = options.base_project_url || IPython.utils.get_data("baseProjectUrl");
this.selector = selector; this.selector = selector;
if (this.selector !== undefined) { if (this.selector !== undefined) {
this.element = $(selector); this.element = $(selector);
@ -30,10 +31,16 @@ var IPython = (function (IPython) {
LoginWidget.prototype.bind_events = function () { LoginWidget.prototype.bind_events = function () {
var that = this; var that = this;
this.element.find("button#logout").click(function () { this.element.find("button#logout").click(function () {
window.location = that.base_url+"logout"; window.location = IPythin.utils.url_join_encode(
that.base_project_url,
"logout"
);
}); });
this.element.find("button#login").click(function () { this.element.find("button#login").click(function () {
window.location = that.base_url+"login"; window.location = IPythin.utils.url_join_encode(
that.base_project_url,
"login"
);
}); });
}; };

View File

@ -8,7 +8,6 @@
//============================================================================ //============================================================================
// On document ready // On document ready
//============================================================================ //============================================================================
"use strict";
// for the time beeing, we have to pass marked as a parameter here, // for the time beeing, we have to pass marked as a parameter here,
// as injecting require.js make marked not to put itself in the globals, // as injecting require.js make marked not to put itself in the globals,
@ -18,28 +17,28 @@ require(['components/marked/lib/marked',
'notebook/js/widgets/init'], 'notebook/js/widgets/init'],
function (marked) { function (marked) {
"use strict";
window.marked = marked window.marked = marked;
// monkey patch CM to be able to syntax highlight cell magics // monkey patch CM to be able to syntax highlight cell magics
// bug reported upstream, // bug reported upstream,
// see https://github.com/marijnh/CodeMirror2/issues/670 // see https://github.com/marijnh/CodeMirror2/issues/670
if(CodeMirror.getMode(1,'text/plain').indent == undefined ){ if(CodeMirror.getMode(1,'text/plain').indent === undefined ){
console.log('patching CM for undefined indent'); console.log('patching CM for undefined indent');
CodeMirror.modes.null = function() { CodeMirror.modes.null = function() {
return {token: function(stream) {stream.skipToEnd();},indent : function(){return 0}} return {token: function(stream) {stream.skipToEnd();},indent : function(){return 0;}};
} };
} }
CodeMirror.patchedGetMode = function(config, mode){ CodeMirror.patchedGetMode = function(config, mode){
var cmmode = CodeMirror.getMode(config, mode); var cmmode = CodeMirror.getMode(config, mode);
if(cmmode.indent == null) if(cmmode.indent === null) {
{
console.log('patch mode "' , mode, '" on the fly'); console.log('patch mode "' , mode, '" on the fly');
cmmode.indent = function(){return 0}; cmmode.indent = function(){return 0;};
} }
return cmmode; return cmmode;
} };
// end monkey patching CodeMirror // end monkey patching CodeMirror
IPython.mathjaxutils.init(); IPython.mathjaxutils.init();
@ -47,35 +46,32 @@ function (marked) {
$('#ipython-main-app').addClass('border-box-sizing'); $('#ipython-main-app').addClass('border-box-sizing');
$('div#notebook_panel').addClass('border-box-sizing'); $('div#notebook_panel').addClass('border-box-sizing');
var baseProjectUrl = $('body').data('baseProjectUrl'); var opts = {
var notebookPath = $('body').data('notebookPath'); base_project_url : IPython.utils.get_data("baseProjectUrl"),
var notebookName = $('body').data('notebookName'); base_kernel_url : IPython.utils.get_data("baseKernelUrl"),
notebookName = decodeURIComponent(notebookName); notebook_path : IPython.utils.get_data("notebookPath"),
notebookPath = decodeURIComponent(notebookPath); notebook_name : IPython.utils.get_data('notebookName')
console.log(notebookName); };
if (notebookPath == 'None'){
notebookPath = "";
}
IPython.page = new IPython.Page(); IPython.page = new IPython.Page();
IPython.layout_manager = new IPython.LayoutManager(); IPython.layout_manager = new IPython.LayoutManager();
IPython.pager = new IPython.Pager('div#pager', 'div#pager_splitter'); IPython.pager = new IPython.Pager('div#pager', 'div#pager_splitter');
IPython.quick_help = new IPython.QuickHelp(); IPython.quick_help = new IPython.QuickHelp();
IPython.login_widget = new IPython.LoginWidget('span#login_widget',{baseProjectUrl:baseProjectUrl}); IPython.login_widget = new IPython.LoginWidget('span#login_widget', opts);
IPython.notebook = new IPython.Notebook('div#notebook',{baseProjectUrl:baseProjectUrl, notebookPath:notebookPath, notebookName:notebookName}); IPython.notebook = new IPython.Notebook('div#notebook', opts);
IPython.keyboard_manager = new IPython.KeyboardManager(); IPython.keyboard_manager = new IPython.KeyboardManager();
IPython.save_widget = new IPython.SaveWidget('span#save_widget'); IPython.save_widget = new IPython.SaveWidget('span#save_widget');
IPython.menubar = new IPython.MenuBar('#menubar',{baseProjectUrl:baseProjectUrl, notebookPath: notebookPath}) IPython.menubar = new IPython.MenuBar('#menubar', opts);
IPython.toolbar = new IPython.MainToolBar('#maintoolbar-container') IPython.toolbar = new IPython.MainToolBar('#maintoolbar-container');
IPython.tooltip = new IPython.Tooltip() IPython.tooltip = new IPython.Tooltip();
IPython.notification_area = new IPython.NotificationArea('#notification_area') IPython.notification_area = new IPython.NotificationArea('#notification_area');
IPython.notification_area.init_notification_widgets(); IPython.notification_area.init_notification_widgets();
IPython.layout_manager.do_resize(); IPython.layout_manager.do_resize();
$('body').append('<div id="fonttest"><pre><span id="test1">x</span>'+ $('body').append('<div id="fonttest"><pre><span id="test1">x</span>'+
'<span id="test2" style="font-weight: bold;">x</span>'+ '<span id="test2" style="font-weight: bold;">x</span>'+
'<span id="test3" style="font-style: italic;">x</span></pre></div>') '<span id="test3" style="font-style: italic;">x</span></pre></div>');
var nh = $('#test1').innerHeight(); var nh = $('#test1').innerHeight();
var bh = $('#test2').innerHeight(); var bh = $('#test2').innerHeight();
var ih = $('#test3').innerHeight(); var ih = $('#test3').innerHeight();
@ -101,7 +97,7 @@ function (marked) {
$([IPython.events]).on('notebook_loaded.Notebook', first_load); $([IPython.events]).on('notebook_loaded.Notebook', first_load);
$([IPython.events]).trigger('app_initialized.NotebookApp'); $([IPython.events]).trigger('app_initialized.NotebookApp');
IPython.notebook.load_notebook(notebookName, notebookPath); IPython.notebook.load_notebook(opts.notebook_name, opts.notebook_path);
if (marked) { if (marked) {
marked.setOptions({ marked.setOptions({
@ -121,8 +117,6 @@ function (marked) {
} }
return highlighted.value; return highlighted.value;
} }
}) });
} }
} });
);

View File

@ -30,16 +30,14 @@ var IPython = (function (IPython) {
* *
* @param selector {string} selector for the menubar element in DOM * @param selector {string} selector for the menubar element in DOM
* @param {object} [options] * @param {object} [options]
* @param [options.baseProjectUrl] {String} String to use for the * @param [options.base_project_url] {String} String to use for the
* Base Project url, default would be to inspect * base project url. Default is to inspect
* $('body').data('baseProjectUrl'); * $('body').data('baseProjectUrl');
* does not support change for now is set through this option * does not support change for now is set through this option
*/ */
var MenuBar = function (selector, options) { var MenuBar = function (selector, options) {
options = options || {}; options = options || {};
if (options.baseProjectUrl !== undefined) { this.base_project_url = options.base_project_url || IPython.utils.get_data("baseProjectUrl");
this._baseProjectUrl = options.baseProjectUrl;
}
this.selector = selector; this.selector = selector;
if (this.selector !== undefined) { if (this.selector !== undefined) {
this.element = $(selector); this.element = $(selector);
@ -48,16 +46,6 @@ var IPython = (function (IPython) {
} }
}; };
MenuBar.prototype.baseProjectUrl = function(){
return this._baseProjectUrl || $('body').data('baseProjectUrl');
};
MenuBar.prototype.notebookPath = function() {
var path = $('body').data('notebookPath');
path = decodeURIComponent(path);
return path;
};
MenuBar.prototype.style = function () { MenuBar.prototype.style = function () {
this.element.addClass('border-box-sizing'); this.element.addClass('border-box-sizing');
this.element.find("li").click(function (event, ui) { this.element.find("li").click(function (event, ui) {
@ -75,16 +63,16 @@ var IPython = (function (IPython) {
if (IPython.notebook.dirty) { if (IPython.notebook.dirty) {
IPython.notebook.save_notebook({async : false}); IPython.notebook.save_notebook({async : false});
} }
var url = utils.url_path_join( var url = utils.url_join_encode(
this.baseProjectUrl(), this.base_project_url,
'nbconvert', 'nbconvert',
format, format,
this.notebookPath(), this.notebook_path,
notebook_name + '.ipynb' notebook_name + '.ipynb'
) + "?download=" + download.toString(); ) + "?download=" + download.toString();
window.open(url); window.open(url);
} };
MenuBar.prototype.bind_events = function () { MenuBar.prototype.bind_events = function () {
// File // File
@ -94,9 +82,9 @@ var IPython = (function (IPython) {
}); });
this.element.find('#open_notebook').click(function () { this.element.find('#open_notebook').click(function () {
window.open(utils.url_join_encode( window.open(utils.url_join_encode(
that.baseProjectUrl(), IPython.notebook.base_url,
'tree', 'tree',
that.notebookPath() IPython.notebook.notebook_path
)); ));
}); });
this.element.find('#copy_notebook').click(function () { this.element.find('#copy_notebook').click(function () {
@ -104,15 +92,17 @@ var IPython = (function (IPython) {
return false; return false;
}); });
this.element.find('#download_ipynb').click(function () { this.element.find('#download_ipynb').click(function () {
var notebook_name = IPython.notebook.get_notebook_name(); var base_url = IPython.notebook.base_url;
var notebook_path = IPython.notebook.notebook_path;
var notebook_name = IPython.notebook.notebook_name;
if (IPython.notebook.dirty) { if (IPython.notebook.dirty) {
IPython.notebook.save_notebook({async : false}); IPython.notebook.save_notebook({async : false});
} }
var url = utils.url_join_encode( var url = utils.url_join_encode(
that.baseProjectUrl(), base_url,
'files', 'files',
that.notebookPath(), notebook_path,
notebook_name + '.ipynb' notebook_name + '.ipynb'
); );
window.location.assign(url); window.location.assign(url);

View File

@ -23,10 +23,10 @@ var IPython = (function (IPython) {
* @param {Object} [options] A config object * @param {Object} [options] A config object
*/ */
var Notebook = function (selector, options) { var Notebook = function (selector, options) {
var options = options || {}; this.options = options = options || {};
this._baseProjectUrl = options.baseProjectUrl; this.base_project_url = options.base_project_url;
this.notebook_path = options.notebookPath; this.notebook_path = options.notebook_path;
this.notebook_name = options.notebookName; this.notebook_name = options.notebook_name;
this.element = $(selector); this.element = $(selector);
this.element.scroll(); this.element.scroll();
this.element.data("notebook", this); this.element.data("notebook", this);
@ -53,8 +53,8 @@ var IPython = (function (IPython) {
// single worksheet for now // single worksheet for now
this.worksheet_metadata = {}; this.worksheet_metadata = {};
this.notebook_name_blacklist_re = /[\/\\:]/; this.notebook_name_blacklist_re = /[\/\\:]/;
this.nbformat = 3 // Increment this when changing the nbformat this.nbformat = 3; // Increment this when changing the nbformat
this.nbformat_minor = 0 // Increment this when changing the nbformat this.nbformat_minor = 0; // Increment this when changing the nbformat
this.style(); this.style();
this.create_elements(); this.create_elements();
this.bind_events(); this.bind_events();
@ -69,24 +69,6 @@ var IPython = (function (IPython) {
$('div#notebook').addClass('border-box-sizing'); $('div#notebook').addClass('border-box-sizing');
}; };
/**
* Get the root URL of the notebook server.
*
* @method baseProjectUrl
* @return {String} The base project URL
*/
Notebook.prototype.baseProjectUrl = function() {
return this._baseProjectUrl || $('body').data('baseProjectUrl');
};
Notebook.prototype.notebookName = function() {
return $('body').data('notebookName');
};
Notebook.prototype.notebookPath = function() {
return $('body').data('notebookPath');
};
/** /**
* Create an HTML and CSS representation of the notebook. * Create an HTML and CSS representation of the notebook.
* *
@ -1365,7 +1347,7 @@ var IPython = (function (IPython) {
* @method start_session * @method start_session
*/ */
Notebook.prototype.start_session = function () { Notebook.prototype.start_session = function () {
this.session = new IPython.Session(this.notebook_name, this.notebook_path, this); this.session = new IPython.Session(this, this.options);
this.session.start($.proxy(this._session_started, this)); this.session.start($.proxy(this._session_started, this));
}; };
@ -1529,7 +1511,7 @@ var IPython = (function (IPython) {
* Getter method for this notebook's name. * Getter method for this notebook's name.
* *
* @method get_notebook_name * @method get_notebook_name
* @return {String} This notebook's name * @return {String} This notebook's name (excluding file extension)
*/ */
Notebook.prototype.get_notebook_name = function () { Notebook.prototype.get_notebook_name = function () {
var nbname = this.notebook_name.substring(0,this.notebook_name.length-6); var nbname = this.notebook_name.substring(0,this.notebook_name.length-6);
@ -1701,7 +1683,7 @@ var IPython = (function (IPython) {
} }
$([IPython.events]).trigger('notebook_saving.Notebook'); $([IPython.events]).trigger('notebook_saving.Notebook');
var url = utils.url_join_encode( var url = utils.url_join_encode(
this._baseProjectUrl, this.base_project_url,
'api/notebooks', 'api/notebooks',
this.notebook_path, this.notebook_path,
this.notebook_name this.notebook_name
@ -1762,7 +1744,7 @@ var IPython = (function (IPython) {
Notebook.prototype.new_notebook = function(){ Notebook.prototype.new_notebook = function(){
var path = this.notebook_path; var path = this.notebook_path;
var base_project_url = this._baseProjectUrl; var base_project_url = this.base_project_url;
var settings = { var settings = {
processData : false, processData : false,
cache : false, cache : false,
@ -1793,7 +1775,7 @@ var IPython = (function (IPython) {
Notebook.prototype.copy_notebook = function(){ Notebook.prototype.copy_notebook = function(){
var path = this.notebook_path; var path = this.notebook_path;
var base_project_url = this._baseProjectUrl; var base_project_url = this.base_project_url;
var settings = { var settings = {
processData : false, processData : false,
cache : false, cache : false,
@ -1833,7 +1815,7 @@ var IPython = (function (IPython) {
}; };
$([IPython.events]).trigger('rename_notebook.Notebook', data); $([IPython.events]).trigger('rename_notebook.Notebook', data);
var url = utils.url_join_encode( var url = utils.url_join_encode(
this._baseProjectUrl, this.base_project_url,
'api/notebooks', 'api/notebooks',
this.notebook_path, this.notebook_path,
this.notebook_name this.notebook_name
@ -1850,7 +1832,7 @@ var IPython = (function (IPython) {
dataType: "json", dataType: "json",
}; };
var url = utils.url_join_encode( var url = utils.url_join_encode(
this._baseProjectUrl, this.base_project_url,
'api/notebooks', 'api/notebooks',
this.notebook_path, this.notebook_path,
this.notebook_name this.notebook_name
@ -1919,7 +1901,7 @@ var IPython = (function (IPython) {
}; };
$([IPython.events]).trigger('notebook_loading.Notebook'); $([IPython.events]).trigger('notebook_loading.Notebook');
var url = utils.url_join_encode( var url = utils.url_join_encode(
this._baseProjectUrl, this.base_project_url,
'api/notebooks', 'api/notebooks',
this.notebook_path, this.notebook_path,
this.notebook_name this.notebook_name
@ -2069,7 +2051,7 @@ var IPython = (function (IPython) {
*/ */
Notebook.prototype.list_checkpoints = function () { Notebook.prototype.list_checkpoints = function () {
var url = utils.url_join_encode( var url = utils.url_join_encode(
this._baseProjectUrl, this.base_project_url,
'api/notebooks', 'api/notebooks',
this.notebook_path, this.notebook_path,
this.notebook_name, this.notebook_name,
@ -2120,9 +2102,9 @@ var IPython = (function (IPython) {
*/ */
Notebook.prototype.create_checkpoint = function () { Notebook.prototype.create_checkpoint = function () {
var url = utils.url_join_encode( var url = utils.url_join_encode(
this._baseProjectUrl, this.base_project_url,
'api/notebooks', 'api/notebooks',
this.notebookPath(), this.notebook_path,
this.notebook_name, this.notebook_name,
'checkpoints' 'checkpoints'
); );
@ -2207,9 +2189,9 @@ var IPython = (function (IPython) {
Notebook.prototype.restore_checkpoint = function (checkpoint) { Notebook.prototype.restore_checkpoint = function (checkpoint) {
$([IPython.events]).trigger('notebook_restoring.Notebook', checkpoint); $([IPython.events]).trigger('notebook_restoring.Notebook', checkpoint);
var url = utils.url_join_encode( var url = utils.url_join_encode(
this._baseProjectUrl, this.base_project_url,
'api/notebooks', 'api/notebooks',
this.notebookPath(), this.notebook_path,
this.notebook_name, this.notebook_name,
'checkpoints', 'checkpoints',
checkpoint checkpoint
@ -2255,9 +2237,9 @@ var IPython = (function (IPython) {
Notebook.prototype.delete_checkpoint = function (checkpoint) { Notebook.prototype.delete_checkpoint = function (checkpoint) {
$([IPython.events]).trigger('notebook_restoring.Notebook', checkpoint); $([IPython.events]).trigger('notebook_restoring.Notebook', checkpoint);
var url = utils.url_join_encode( var url = utils.url_join_encode(
this._baseProjectUrl, this.base_project_url,
'api/notebooks', 'api/notebooks',
this.notebookPath(), this.notebook_path,
this.notebook_name, this.notebook_name,
'checkpoints', 'checkpoints',
checkpoint checkpoint

View File

@ -127,7 +127,7 @@ var IPython = (function (IPython) {
SaveWidget.prototype.update_address_bar = function(){ SaveWidget.prototype.update_address_bar = function(){
var nbname = IPython.notebook.notebook_name; var nbname = IPython.notebook.notebook_name;
var path = IPython.notebook.notebookPath(); var path = IPython.notebook.notebook_path;
var state = {path : utils.url_join_encode(path, nbname)}; var state = {path : utils.url_join_encode(path, nbname)};
window.history.replaceState(state, "", utils.url_join_encode( window.history.replaceState(state, "", utils.url_join_encode(
"/notebooks", "/notebooks",

View File

@ -14,13 +14,14 @@ var IPython = (function (IPython) {
var utils = IPython.utils; var utils = IPython.utils;
var Session = function(notebook_name, notebook_path, notebook){ var Session = function(notebook, options){
this.kernel = null; this.kernel = null;
this.id = null; this.id = null;
this.name = notebook_name;
this.path = notebook_path;
this.notebook = notebook; this.notebook = notebook;
this._baseProjectUrl = notebook.baseProjectUrl(); this.name = notebook.notebook_name;
this.path = notebook.notebook_path;
this.base_project_url = notebook.base_project_url;
this.base_kernel_url = options.base_kernel_url || utils.get_data("baseKernelUrl");
}; };
Session.prototype.start = function(callback) { Session.prototype.start = function(callback) {
@ -44,7 +45,7 @@ var IPython = (function (IPython) {
} }
}, },
}; };
var url = utils.url_join_encode(this._baseProjectUrl, 'api/sessions'); var url = utils.url_join_encode(this.base_project_url, 'api/sessions');
$.ajax(url, settings); $.ajax(url, settings);
}; };
@ -64,7 +65,7 @@ var IPython = (function (IPython) {
data: JSON.stringify(model), data: JSON.stringify(model),
dataType : "json", dataType : "json",
}; };
var url = utils.url_join_encode(this._baseProjectUrl, 'api/sessions', this.id); var url = utils.url_join_encode(this.base_project_url, 'api/sessions', this.id);
$.ajax(url, settings); $.ajax(url, settings);
}; };
@ -76,7 +77,7 @@ var IPython = (function (IPython) {
dataType : "json", dataType : "json",
}; };
this.kernel.running = false; this.kernel.running = false;
var url = utils.url_join_encode(this._baseProjectUrl, 'api/sessions', this.id); var url = utils.url_join_encode(this.base_project_url, 'api/sessions', this.id);
$.ajax(url, settings); $.ajax(url, settings);
}; };
@ -88,7 +89,7 @@ var IPython = (function (IPython) {
*/ */
Session.prototype._handle_start_success = function (data, status, xhr) { Session.prototype._handle_start_success = function (data, status, xhr) {
this.id = data.id; this.id = data.id;
var base_url = utils.url_path_join($('body').data('baseKernelUrl'), "api/kernels"); var base_url = utils.url_join_encode(this.base_kernel_url, "api/kernels");
this.kernel = new IPython.Kernel(base_url); this.kernel = new IPython.Kernel(base_url);
this.kernel._kernel_started(data.kernel); this.kernel._kernel_started(data.kernel);
}; };

View File

@ -14,17 +14,17 @@ var IPython = (function (IPython) {
var utils = IPython.utils; var utils = IPython.utils;
var ClusterList = function (selector) { var ClusterList = function (selector, options) {
this.selector = selector; this.selector = selector;
if (this.selector !== undefined) { if (this.selector !== undefined) {
this.element = $(selector); this.element = $(selector);
this.style(); this.style();
this.bind_events(); this.bind_events();
} }
}; options = options || {};
this.options = options;
ClusterList.prototype.baseProjectUrl = function(){ this.base_project_url = options.base_project_url || utils.get_data("baseProjectUrl");
return this._baseProjectUrl || $('body').data('baseProjectUrl'); this.notebook_path = options.notebook_path || utils.get_data("notebookPath");
}; };
ClusterList.prototype.style = function () { ClusterList.prototype.style = function () {
@ -51,7 +51,7 @@ var IPython = (function (IPython) {
dataType : "json", dataType : "json",
success : $.proxy(this.load_list_success, this) success : $.proxy(this.load_list_success, this)
}; };
var url = utils.url_join_encode(this.baseProjectUrl(), 'clusters'); var url = utils.url_join_encode(this.base_project_url, 'clusters');
$.ajax(url, settings); $.ajax(url, settings);
}; };
@ -65,7 +65,7 @@ var IPython = (function (IPython) {
var len = data.length; var len = data.length;
for (var i=0; i<len; i++) { for (var i=0; i<len; i++) {
var element = $('<div/>'); var element = $('<div/>');
var item = new ClusterItem(element); var item = new ClusterItem(element, this.options);
item.update_state(data[i]); item.update_state(data[i]);
element.data('item', item); element.data('item', item);
this.element.append(element); this.element.append(element);
@ -73,17 +73,14 @@ var IPython = (function (IPython) {
}; };
var ClusterItem = function (element) { var ClusterItem = function (element, options) {
this.element = $(element); this.element = $(element);
this.base_project_url = options.base_project_url || utils.get_data("baseProjectUrl");
this.notebook_path = options.notebook_path || utils.get_data("notebookPath");
this.data = null; this.data = null;
this.style(); this.style();
}; };
ClusterItem.prototype.baseProjectUrl = function(){
return this._baseProjectUrl || $('body').data('baseProjectUrl');
};
ClusterItem.prototype.style = function () { ClusterItem.prototype.style = function () {
this.element.addClass('list_item').addClass("row-fluid"); this.element.addClass('list_item').addClass("row-fluid");
}; };
@ -138,7 +135,7 @@ var IPython = (function (IPython) {
}; };
status_col.text('starting'); status_col.text('starting');
var url = utils.url_join_encode( var url = utils.url_join_encode(
that.baseProjectUrl(), that.base_project_url,
'clusters', 'clusters',
that.data.profile, that.data.profile,
'start' 'start'
@ -180,7 +177,7 @@ var IPython = (function (IPython) {
}; };
status_col.text('stopping'); status_col.text('stopping');
var url = utils.url_join_encode( var url = utils.url_join_encode(
that.baseProjectUrl(), that.base_project_url,
'clusters', 'clusters',
that.data.profile, that.data.profile,
'stop' 'stop'

View File

@ -15,12 +15,16 @@ $(document).ready(function () {
IPython.page = new IPython.Page(); IPython.page = new IPython.Page();
$('#new_notebook').button().click(function (e) { $('#new_notebook').button().click(function (e) {
IPython.notebook_list.new_notebook($('body').data('baseProjectUrl')) IPython.notebook_list.new_notebook()
}); });
IPython.notebook_list = new IPython.NotebookList('#notebook_list'); var opts = {
IPython.cluster_list = new IPython.ClusterList('#cluster_list'); base_project_url : IPython.utils.get_data("baseProjectUrl"),
IPython.login_widget = new IPython.LoginWidget('#login_widget'); notebook_path : IPython.utils.get_data("notebookPath"),
};
IPython.notebook_list = new IPython.NotebookList('#notebook_list', opts);
IPython.cluster_list = new IPython.ClusterList('#cluster_list', opts);
IPython.login_widget = new IPython.LoginWidget('#login_widget', opts);
var interval_id=0; var interval_id=0;
// auto refresh every xx secondes, no need to be fast, // auto refresh every xx secondes, no need to be fast,

View File

@ -14,7 +14,7 @@ var IPython = (function (IPython) {
var utils = IPython.utils; var utils = IPython.utils;
var NotebookList = function (selector) { var NotebookList = function (selector, options) {
this.selector = selector; this.selector = selector;
if (this.selector !== undefined) { if (this.selector !== undefined) {
this.element = $(selector); this.element = $(selector);
@ -23,16 +23,10 @@ var IPython = (function (IPython) {
} }
this.notebooks_list = []; this.notebooks_list = [];
this.sessions = {}; this.sessions = {};
this.base_project_url = options.base_project_url || utils.get_data("baseProjectUrl");
this.notebook_path = options.notebook_path || utils.get_data("notebookPath");
}; };
NotebookList.prototype.baseProjectUrl = function () {
return $('body').data('baseProjectUrl');
};
NotebookList.prototype.notebookPath = function() {
return $('body').data('notebookPath');
};
NotebookList.prototype.style = function () { NotebookList.prototype.style = function () {
$('#notebook_toolbar').addClass('list_toolbar'); $('#notebook_toolbar').addClass('list_toolbar');
$('#drag_info').addClass('toolbar_info'); $('#drag_info').addClass('toolbar_info');
@ -112,7 +106,7 @@ var IPython = (function (IPython) {
dataType : "json", dataType : "json",
success : $.proxy(that.sessions_loaded, this) success : $.proxy(that.sessions_loaded, this)
}; };
var url = this.baseProjectUrl() + 'api/sessions'; var url = utils.url_join_encode(this.base_project_url, 'api/sessions');
$.ajax(url,settings); $.ajax(url,settings);
}; };
@ -152,10 +146,10 @@ var IPython = (function (IPython) {
}; };
var url = utils.url_join_encode( var url = utils.url_join_encode(
this.baseProjectUrl(), this.base_project_url,
'api', 'api',
'notebooks', 'notebooks',
this.notebookPath() this.notebook_path
); );
$.ajax(url, settings); $.ajax(url, settings);
}; };
@ -175,7 +169,7 @@ var IPython = (function (IPython) {
span12.empty(); span12.empty();
span12.append($('<div style="margin:auto;text-align:center;color:grey"/>').text(message)); span12.append($('<div style="margin:auto;text-align:center;color:grey"/>').text(message));
} }
var path = this.notebookPath(); var path = this.notebook_path;
var offset = 0; var offset = 0;
if (path !== '') { if (path !== '') {
item = this.new_notebook_item(0); item = this.new_notebook_item(0);
@ -233,7 +227,7 @@ var IPython = (function (IPython) {
item.find("a.item_link") item.find("a.item_link")
.attr('href', .attr('href',
utils.url_join_encode( utils.url_join_encode(
this.baseProjectUrl(), this.base_project_url,
"tree", "tree",
path, path,
name name
@ -250,7 +244,7 @@ var IPython = (function (IPython) {
item.find("a.item_link") item.find("a.item_link")
.attr('href', .attr('href',
utils.url_join_encode( utils.url_join_encode(
this.baseProjectUrl(), this.base_project_url,
"notebooks", "notebooks",
path, path,
nbname nbname
@ -291,7 +285,7 @@ var IPython = (function (IPython) {
} }
}; };
var url = utils.url_join_encode( var url = utils.url_join_encode(
that.baseProjectUrl(), that.base_project_url,
'api/sessions', 'api/sessions',
session session
); );
@ -331,9 +325,9 @@ var IPython = (function (IPython) {
} }
}; };
var url = utils.url_join_encode( var url = utils.url_join_encode(
notebooklist.baseProjectUrl(), notebooklist.base_project_url,
'api/notebooks', 'api/notebooks',
notebooklist.notebookPath(), notebooklist.notebook_path,
nbname nbname
); );
$.ajax(url, settings); $.ajax(url, settings);
@ -357,7 +351,7 @@ var IPython = (function (IPython) {
if (nbname.slice(nbname.length-6, nbname.length) != ".ipynb") { if (nbname.slice(nbname.length-6, nbname.length) != ".ipynb") {
nbname = nbname + ".ipynb"; nbname = nbname + ".ipynb";
} }
var path = that.notebookPath(); var path = that.notebook_path;
var nbdata = item.data('nbdata'); var nbdata = item.data('nbdata');
var content_type = 'application/json'; var content_type = 'application/json';
var model = { var model = {
@ -380,9 +374,9 @@ var IPython = (function (IPython) {
}; };
var url = utils.url_join_encode( var url = utils.url_join_encode(
that.baseProjectUrl(), that.base_project_url,
'api/notebooks', 'api/notebooks',
that.notebookPath(), that.notebook_path,
nbname nbname
); );
$.ajax(url, settings); $.ajax(url, settings);
@ -402,8 +396,8 @@ var IPython = (function (IPython) {
NotebookList.prototype.new_notebook = function(){ NotebookList.prototype.new_notebook = function(){
var path = this.notebookPath(); var path = this.notebook_path;
var base_project_url = this.baseProjectUrl(); var base_project_url = this.base_project_url;
var settings = { var settings = {
processData : false, processData : false,
cache : false, cache : false,