diff --git a/IPython/html/static/base/js/utils.js b/IPython/html/static/base/js/utils.js index 16f9a70..a974166 100644 --- a/IPython/html/static/base/js/utils.js +++ b/IPython/html/static/base/js/utils.js @@ -272,11 +272,11 @@ define([ } else { line = "background-color: "; } - line = line + "rgb(" + r + "," + g + "," + b + ");" - if ( !attrs["style"] ) { - attrs["style"] = line; + line = line + "rgb(" + r + "," + g + "," + b + ");"; + if ( !attrs.style ) { + attrs.style = line; } else { - attrs["style"] += " " + line; + attrs.style += " " + line; } } } @@ -285,7 +285,7 @@ define([ function ansispan(str) { // ansispan function adapted from github.com/mmalecki/ansispan (MIT License) // regular ansi escapes (using the table above) - var is_open = false + var is_open = false; return str.replace(/\033\[(0?[01]|22|39)?([;\d]+)?m/g, function(match, prefix, pattern) { if (!pattern) { // [(01|22|39|)m close spans @@ -313,7 +313,7 @@ define([ return span + ">"; } }); - }; + } // Transform ANSI color escape codes into HTML tags with css // classes listed in the above ansi_colormap object. The actual color used @@ -392,6 +392,18 @@ define([ return url; }; + var url_path_split = function (path) { + // Like os.path.split for URLs. + // Always returns two strings, the directory path and the base filename + + var idx = path.lastIndexOf('/'); + if (idx === -1) { + return ['', path]; + } else { + return [ path.slice(0, idx), path.slice(idx + 1) ]; + } + }; + var parse_url = function (url) { // an `a` element with an href allows attr-access to the parsed segments of a URL // a = parse_url("http://localhost:8888/path/name#hash") @@ -577,7 +589,7 @@ define([ wrapped_error.xhr_status = status; wrapped_error.xhr_error = error; return wrapped_error; - } + }; var utils = { regex_split : regex_split, @@ -588,6 +600,7 @@ define([ points_to_pixels : points_to_pixels, get_body_data : get_body_data, parse_url : parse_url, + url_path_split : url_path_split, url_path_join : url_path_join, url_join_encode : url_join_encode, encode_uri_components : encode_uri_components, diff --git a/IPython/html/static/notebook/js/main.js b/IPython/html/static/notebook/js/main.js index 486267d..6c4a6a6 100644 --- a/IPython/html/static/notebook/js/main.js +++ b/IPython/html/static/notebook/js/main.js @@ -151,6 +151,6 @@ require([ IPython.tooltip = notebook.tooltip; events.trigger('app_initialized.NotebookApp'); - notebook.load_notebook(common_options.notebook_name, common_options.notebook_path); + notebook.load_notebook(common_options.notebook_path); }); diff --git a/IPython/html/static/notebook/js/menubar.js b/IPython/html/static/notebook/js/menubar.js index 04779b7..3c367a5 100644 --- a/IPython/html/static/notebook/js/menubar.js +++ b/IPython/html/static/notebook/js/menubar.js @@ -2,13 +2,14 @@ // Distributed under the terms of the Modified BSD License. define([ - 'base/js/namespace', 'jquery', + 'base/js/namespace', + 'base/js/dialog', 'base/js/utils', 'notebook/js/tour', 'bootstrap', 'moment', -], function(IPython, $, utils, tour, bootstrap, moment) { +], function($, IPython, dialog, utils, tour, bootstrap, moment) { "use strict"; var MenuBar = function (selector, options) { @@ -89,14 +90,14 @@ define([ this.element.find('#new_notebook').click(function () { // Create a new notebook in the same path as the current // notebook's path. - that.contents.new(that.notebook.notebook_path, null, { + var parent = utils.url_path_split(this.notebook_path)[0]; + that.contents.new(parent, { ext: ".ipynb", extra_settings: {async: false}, // So we can open a new window afterwards success: function (data) { window.open( utils.url_join_encode( - that.base_url, 'notebooks', - data.path, data.name + that.base_url, 'notebooks', data.path ), '_blank'); }, error: function(error) { diff --git a/IPython/html/static/notebook/js/notebook.js b/IPython/html/static/notebook/js/notebook.js index 9312a44..21bcba2 100644 --- a/IPython/html/static/notebook/js/notebook.js +++ b/IPython/html/static/notebook/js/notebook.js @@ -212,13 +212,13 @@ define([ }); this.events.on('kernel_ready.Kernel', function(event, data) { - var kinfo = data.kernel.info_reply + var kinfo = data.kernel.info_reply; var langinfo = kinfo.language_info || {}; if (!langinfo.name) langinfo.name = kinfo.language; that.metadata.language_info = langinfo; // Mode 'null' should be plain, unhighlighted text. - var cm_mode = langinfo.codemirror_mode || langinfo.language || 'null' + var cm_mode = langinfo.codemirror_mode || langinfo.language || 'null'; that.set_codemirror_mode(cm_mode); }); @@ -1029,7 +1029,7 @@ define([ text = ''; } // metadata - target_cell.metadata = source_cell.metadata + target_cell.metadata = source_cell.metadata; // We must show the editor before setting its contents target_cell.unrender(); target_cell.set_text(text); @@ -1231,8 +1231,6 @@ define([ * @method split_cell */ Notebook.prototype.split_cell = function () { - var mdc = textcell.MarkdownCell; - var rc = textcell.RawCell; var cell = this.get_selected_cell(); if (cell.is_splittable()) { var texta = cell.get_pre_cursor(); @@ -1251,8 +1249,6 @@ define([ * @method merge_cell_above */ Notebook.prototype.merge_cell_above = function () { - var mdc = textcell.MarkdownCell; - var rc = textcell.RawCell; var index = this.get_selected_index(); var cell = this.get_cell(index); var render = cell.rendered; @@ -1288,8 +1284,6 @@ define([ * @method merge_cell_below */ Notebook.prototype.merge_cell_below = function () { - var mdc = textcell.MarkdownCell; - var rc = textcell.RawCell; var index = this.get_selected_index(); var cell = this.get_cell(index); var render = cell.rendered; @@ -1523,9 +1517,9 @@ define([ } this.codemirror_mode = newmode; codecell.CodeCell.options_default.cm_config.mode = newmode; - modename = newmode.mode || newmode.name || newmode; + var modename = newmode.mode || newmode.name || newmode; - that = this; + var that = this; utils.requireCodeMirrorMode(modename, function () { $.map(that.get_cells(), function(cell, i) { if (cell.cell_type === 'code'){ @@ -1547,7 +1541,6 @@ define([ * @method start_session */ Notebook.prototype.start_session = function (kernel_name) { - var that = this; if (this._session_starting) { throw new session.SessionAlreadyStarting(); } @@ -1629,7 +1622,6 @@ define([ Notebook.prototype.execute_cell = function () { // mode = shift, ctrl, alt var cell = this.get_selected_cell(); - var cell_index = this.find_cell_index(cell); cell.execute(); this.command_mode(); @@ -1758,7 +1750,9 @@ define([ * @param {String} name A new name for this notebook */ Notebook.prototype.set_notebook_name = function (name) { + var parent = utils.url_path_split(this.notebook_path)[0]; this.notebook_name = name; + this.notebook_path = utils.url_path_join(parent, name); }; /** @@ -1795,6 +1789,7 @@ define([ // Save the metadata and name. this.metadata = content.metadata; this.notebook_name = data.name; + this.notebook_path = data.path; var trusted = true; // Trigger an event changing the kernel spec - this will set the default @@ -1807,7 +1802,7 @@ define([ if (this.metadata.language_info !== undefined) { var langinfo = this.metadata.language_info; // Mode 'null' should be plain, unhighlighted text. - var cm_mode = langinfo.codemirror_mode || langinfo.language || 'null' + var cm_mode = langinfo.codemirror_mode || langinfo.language || 'null'; this.set_codemirror_mode(cm_mode); } @@ -1900,8 +1895,6 @@ define([ Notebook.prototype.save_notebook = function (extra_settings) { // Create a JSON model to be sent to the server. var model = { - name : this.notebook_name, - path : this.notebook_path, type : "notebook", content : this.toJSON() }; @@ -1909,11 +1902,11 @@ define([ var start = new Date().getTime(); var that = this; - this.contents.save(this.notebook_path, this.notebook_name, model, { + this.contents.save(this.notebook_path, model, { extra_settings: extra_settings, success: $.proxy(this.save_notebook_success, this, start), error: function (error) { - that.events.trigger('notebook_save_failed.Notebook'); + that.events.trigger('notebook_save_failed.Notebook', error); } }); }; @@ -2031,15 +2024,15 @@ define([ Notebook.prototype.copy_notebook = function(){ var base_url = this.base_url; - this.contents.copy(this.notebook_path, null, this.notebook_name, { + var parent = utils.url_path_split(this.notebook_path)[0]; + this.contents.copy(this.notebook_path, parent, { // synchronous so we can open a new window on success extra_settings: {async: false}, success: function (data) { window.open(utils.url_join_encode( - base_url, 'notebooks', data.path, data.name + base_url, 'notebooks', data.path ), '_blank'); - }, - error : utils.log_ajax_error + } }); }; @@ -2049,11 +2042,13 @@ define([ } var that = this; - this.contents.rename(this.notebook_path, this.notebook_name, - this.notebook_path, new_name, { + var parent = utils.url_path_split(this.notebook_path)[0]; + var new_path = utils.url_path_join(parent, new_name); + this.contents.rename(this.notebook_path, new_path, { success: function (json) { - var name = that.notebook_name = json.name; - that.session.rename_notebook(name, json.path); + that.notebook_name = json.name; + that.notebook_path = json.path; + that.session.rename_notebook(json.path); that.events.trigger('notebook_renamed.Notebook', json); }, error: $.proxy(this.rename_error, this) @@ -2061,7 +2056,7 @@ define([ }; Notebook.prototype.delete = function () { - this.contents.delete(this.notebook_name, this.notebook_path); + this.contents.delete(this.notebook_path); }; Notebook.prototype.rename_error = function (error) { @@ -2100,13 +2095,13 @@ define([ * Request a notebook's data from the server. * * @method load_notebook - * @param {String} notebook_name and path A notebook to load + * @param {String} notebook_path A notebook to load */ - Notebook.prototype.load_notebook = function (notebook_name, notebook_path) { - this.notebook_name = notebook_name; + Notebook.prototype.load_notebook = function (notebook_path) { this.notebook_path = notebook_path; + this.notebook_name = utils.url_path_split(this.notebook_path)[1]; this.events.trigger('notebook_loading.Notebook'); - this.contents.load(notebook_path, notebook_name, { + this.contents.get(notebook_path, { success: $.proxy(this.load_notebook_success, this), error: $.proxy(this.load_notebook_error, this) }); @@ -2121,7 +2116,7 @@ define([ * @param {Object} data JSON representation of a notebook */ Notebook.prototype.load_notebook_success = function (data) { - var failed; + var failed, msg; try { this.fromJSON(data); } catch (e) { @@ -2146,12 +2141,11 @@ define([ } if (data.message) { - var msg; if (failed) { - msg = "The notebook also failed validation:" + msg = "The notebook also failed validation:"; } else { msg = "An invalid notebook may not function properly." + - " The validation error was:" + " The validation error was:"; } body.append($("

").text( msg @@ -2192,7 +2186,7 @@ define([ src = " a newer notebook format "; } - var msg = "This notebook has been converted from" + src + + msg = "This notebook has been converted from" + src + "(v"+orig_nbformat+") to the current notebook " + "format (v"+nbmodel.nbformat+"). The next time you save this notebook, the " + "current notebook format will be used."; @@ -2219,7 +2213,7 @@ define([ var that = this; var orig_vs = 'v' + nbmodel.nbformat + '.' + orig_nbformat_minor; var this_vs = 'v' + nbmodel.nbformat + '.' + this.nbformat_minor; - var msg = "This notebook is version " + orig_vs + ", but we only fully support up to " + + msg = "This notebook is version " + orig_vs + ", but we only fully support up to " + this_vs + ". You can still work with this notebook, but some features " + "introduced in later notebook versions may not be available."; @@ -2270,7 +2264,7 @@ define([ Notebook.prototype.load_notebook_error = function (error) { this.events.trigger('notebook_load_failed.Notebook', error); var msg; - if (error.name = utils.XHR_ERROR && error.xhr.status === 500) { + if (error.name === utils.XHR_ERROR && error.xhr.status === 500) { utils.log_ajax_error(error.xhr, error.xhr_status, error.xhr_error); msg = "An unknown error occurred while loading this notebook. " + "This version can load notebook formats " + @@ -2330,10 +2324,10 @@ define([ */ Notebook.prototype.list_checkpoints = function () { var that = this; - this.contents.list_checkpoints(this.notebook_path, this.notebook_name, { + this.contents.list_checkpoints(this.notebook_path, { success: $.proxy(this.list_checkpoints_success, this), error: function(error) { - that.events.trigger('list_checkpoints_failed.Notebook'); + that.events.trigger('list_checkpoints_failed.Notebook', error); } }); }; @@ -2362,10 +2356,10 @@ define([ */ Notebook.prototype.create_checkpoint = function () { var that = this; - this.contents.create_checkpoint(this.notebook_path, this.notebook_name, { + this.contents.create_checkpoint(this.notebook_path, { success: $.proxy(this.create_checkpoint_success, this), error: function (error) { - that.events.trigger('checkpoint_failed.Notebook'); + that.events.trigger('checkpoint_failed.Notebook', error); } }); }; @@ -2432,11 +2426,11 @@ define([ Notebook.prototype.restore_checkpoint = function (checkpoint) { this.events.trigger('notebook_restoring.Notebook', checkpoint); var that = this; - this.contents.restore_checkpoint(this.notebook_path, this.notebook_name, + this.contents.restore_checkpoint(this.notebook_path, checkpoint, { success: $.proxy(this.restore_checkpoint_success, this), error: function (error) { - that.events.trigger('checkpoint_restore_failed.Notebook'); + that.events.trigger('checkpoint_restore_failed.Notebook', error); } }); }; @@ -2448,7 +2442,7 @@ define([ */ Notebook.prototype.restore_checkpoint_success = function () { this.events.trigger('checkpoint_restored.Notebook'); - this.load_notebook(this.notebook_name, this.notebook_path); + this.load_notebook(this.notebook_path); }; /** @@ -2460,7 +2454,7 @@ define([ Notebook.prototype.delete_checkpoint = function (checkpoint) { this.events.trigger('notebook_restoring.Notebook', checkpoint); var that = this; - this.contents.delete_checkpoint(this.notebook_path, this.notebook_name, + this.contents.delete_checkpoint(this.notebook_path, checkpoint, { success: $.proxy(this.delete_checkpoint_success, this), error: function (error) { @@ -2476,7 +2470,7 @@ define([ */ Notebook.prototype.delete_checkpoint_success = function () { this.events.trigger('checkpoint_deleted.Notebook'); - this.load_notebook(this.notebook_name, this.notebook_path); + this.load_notebook(this.notebook_path); }; diff --git a/IPython/html/static/notebook/js/savewidget.js b/IPython/html/static/notebook/js/savewidget.js index 72cddf9..f2cfb5c 100644 --- a/IPython/html/static/notebook/js/savewidget.js +++ b/IPython/html/static/notebook/js/savewidget.js @@ -122,14 +122,12 @@ define([ SaveWidget.prototype.update_address_bar = function(){ var base_url = this.notebook.base_url; - var nbname = this.notebook.notebook_name; var path = this.notebook.notebook_path; - var state = {path : path, name: nbname}; + var state = {path : path}; window.history.replaceState(state, "", utils.url_join_encode( base_url, "notebooks", - path, - nbname) + path) ); }; @@ -199,7 +197,7 @@ define([ $.proxy(that._regularly_update_checkpoint_date, that), t + 1000 ); - } + }; var tdelta = Math.ceil(new Date()-this._checkpoint_date); // update regularly for the first 6hours and show diff --git a/IPython/html/static/services/contents.js b/IPython/html/static/services/contents.js index d229b0b..041a7af 100644 --- a/IPython/html/static/services/contents.js +++ b/IPython/html/static/services/contents.js @@ -29,8 +29,9 @@ define([ // An error representing the result of attempting to delete a non-empty // directory. this.message = 'A directory must be empty before being deleted.'; - } - Contents.DirectoryNotEmptyError.prototype = new Error; + }; + + Contents.DirectoryNotEmptyError.prototype = Object.create(Error.prototype); Contents.DirectoryNotEmptyError.prototype.name = Contents.DIRECTORY_NOT_EMPTY_ERROR; @@ -54,29 +55,28 @@ define([ */ Contents.prototype.create_basic_error_handler = function(callback) { if (!callback) { - return function(xhr, status, error) { }; + return utils.log_ajax_error; } return function(xhr, status, error) { callback(utils.wrap_ajax_error(xhr, status, error)); }; - } + }; /** * File Functions (including notebook operations) */ /** - * Load a file. + * Get a file. * * Calls success with file JSON model, or error with error. * - * @method load_notebook + * @method get * @param {String} path - * @param {String} name * @param {Function} success * @param {Function} error */ - Contents.prototype.load = function (path, name, options) { + Contents.prototype.get = function (path, options) { // We do the call with settings so we can set cache to false. var settings = { processData : false, @@ -86,32 +86,25 @@ define([ success : options.success, error : this.create_basic_error_handler(options.error) }; - var url = this.api_url(path, name); + var url = this.api_url(path); $.ajax(url, settings); }; /** - * Creates a new notebook file at the specified directory path. + * Creates a new file at the specified directory path. * - * @method scroll_to_cell + * @method new * @param {String} path The path to create the new notebook at - * @param {String} name Name for new file. Chosen by server if unspecified. * @param {Object} options: - * ext: file extension to use if name unspecified + * ext: file extension to use */ - Contents.prototype.new = function(path, name, options) { - var method, data; - if (name) { - method = "PUT"; - } else { - method = "POST"; - data = JSON.stringify({ext: options.ext || ".ipynb"}); - } + Contents.prototype.new = function(path, options) { + var data = JSON.stringify({ext: options.ext || ".ipynb"}); var settings = { processData : false, - type : method, + type : "POST", data: data, dataType : "json", success : options.success || function() {}, @@ -123,9 +116,8 @@ define([ $.ajax(this.api_url(path), settings); }; - Contents.prototype.delete = function(name, path, options) { + Contents.prototype.delete = function(path, options) { var error_callback = options.error || function() {}; - var that = this; var settings = { processData : false, type : "DELETE", @@ -140,12 +132,12 @@ define([ error_callback(utils.wrap_ajax_error(xhr, status, error)); } }; - var url = this.api_url(path, name); + var url = this.api_url(path); $.ajax(url, settings); }; - Contents.prototype.rename = function(path, name, new_path, new_name, options) { - var data = {name: new_name, path: new_path}; + Contents.prototype.rename = function(path, new_path, options) { + var data = {path: new_path}; var settings = { processData : false, type : "PATCH", @@ -155,11 +147,11 @@ define([ success : options.success || function() {}, error : this.create_basic_error_handler(options.error) }; - var url = this.api_url(path, name); + var url = this.api_url(path); $.ajax(url, settings); }; - Contents.prototype.save = function(path, name, model, options) { + Contents.prototype.save = function(path, model, options) { // We do the call with settings so we can set cache to false. var settings = { processData : false, @@ -172,24 +164,19 @@ define([ if (options.extra_settings) { $.extend(settings, options.extra_settings); } - var url = this.api_url(path, name); + var url = this.api_url(path); $.ajax(url, settings); }; - Contents.prototype.copy = function(to_path, to_name, from, options) { - var url, method; - if (to_name) { - url = this.api_url(to_path, to_name); - method = "PUT"; - } else { - url = this.api_url(to_path); - method = "POST"; - } + Contents.prototype.copy = function(from_file, to_dir, options) { + // Copy a file into a given directory via POST + // The server will select the name of the copied file + var url = this.api_url(to_dir); var settings = { processData : false, - type: method, - data: JSON.stringify({copy_from: from}), + type: "POST", + data: JSON.stringify({copy_from: from_file}), dataType : "json", success: options.success || function() {}, error: this.create_basic_error_handler(options.error) @@ -204,8 +191,8 @@ define([ * Checkpointing Functions */ - Contents.prototype.create_checkpoint = function(path, name, options) { - var url = this.api_url(path, name, 'checkpoints'); + Contents.prototype.create_checkpoint = function(path, options) { + var url = this.api_url(path, 'checkpoints'); var settings = { type : "POST", success: options.success || function() {}, @@ -214,8 +201,8 @@ define([ $.ajax(url, settings); }; - Contents.prototype.list_checkpoints = function(path, name, options) { - var url = this.api_url(path, name, 'checkpoints'); + Contents.prototype.list_checkpoints = function(path, options) { + var url = this.api_url(path, 'checkpoints'); var settings = { type : "GET", success: options.success, @@ -224,8 +211,8 @@ define([ $.ajax(url, settings); }; - Contents.prototype.restore_checkpoint = function(path, name, checkpoint_id, options) { - var url = this.api_url(path, name, 'checkpoints', checkpoint_id); + Contents.prototype.restore_checkpoint = function(path, checkpoint_id, options) { + var url = this.api_url(path, 'checkpoints', checkpoint_id); var settings = { type : "POST", success: options.success || function() {}, @@ -234,8 +221,8 @@ define([ $.ajax(url, settings); }; - Contents.prototype.delete_checkpoint = function(path, name, checkpoint_id, options) { - var url = this.api_url(path, name, 'checkpoints', checkpoint_id); + Contents.prototype.delete_checkpoint = function(path, checkpoint_id, options) { + var url = this.api_url(path, 'checkpoints', checkpoint_id); var settings = { type : "DELETE", success: options.success || function() {}, @@ -255,10 +242,8 @@ define([ * representing individual files or directories. Each dictionary has * the keys: * type: "notebook" or "directory" - * name: the name of the file or directory * created: created date * last_modified: last modified dat - * path: the path * @method list_notebooks * @param {String} path The path to list notebooks in * @param {Function} load_callback called with list of notebooks on success diff --git a/IPython/html/static/services/sessions/session.js b/IPython/html/static/services/sessions/session.js index 5b2316d..22ba9fc 100644 --- a/IPython/html/static/services/sessions/session.js +++ b/IPython/html/static/services/sessions/session.js @@ -15,7 +15,6 @@ define([ * all other operations, the kernel object should be used. * * Options should include: - * - notebook_name: the notebook name * - notebook_path: the path (not including name) to the notebook * - kernel_name: the type of kernel (e.g. python3) * - base_url: the root url of the notebook server @@ -28,7 +27,6 @@ define([ var Session = function (options) { this.id = null; this.notebook_model = { - name: options.notebook_name, path: options.notebook_path }; this.kernel_model = { @@ -154,15 +152,11 @@ define([ * undefined, then they will not be changed. * * @function rename_notebook - * @param {string} [name] - new notebook name - * @param {string} [path] - new path to notebook + * @param {string} [path] - new notebook path * @param {function} [success] - function executed on ajax success * @param {function} [error] - functon executed on ajax error */ - Session.prototype.rename_notebook = function (name, path, success, error) { - if (name !== undefined) { - this.notebook_model.name = name; - } + Session.prototype.rename_notebook = function (path, success, error) { if (path !== undefined) { this.notebook_model.path = path; } @@ -208,7 +202,6 @@ define([ * fresh. If options are given, they can include any of the * following: * - * - notebook_name - the name of the notebook * - notebook_path - the path to the notebook * - kernel_name - the name (type) of the kernel * @@ -220,9 +213,6 @@ define([ Session.prototype.restart = function (options, success, error) { var that = this; var start = function () { - if (options && options.notebook_name) { - that.notebook_model.name = options.notebook_name; - } if (options && options.notebook_path) { that.notebook_model.path = options.notebook_path; } @@ -238,8 +228,8 @@ define([ // Helper functions /** - * Get the data model for the session, which includes the notebook - * (name and path) and kernel (name and id). + * Get the data model for the session, which includes the notebook path + * and kernel (name and id). * * @function _get_model * @returns {Object} - the data model @@ -266,7 +256,6 @@ define([ this.session_url = utils.url_join_encode(this.session_service_url, this.id); } if (data && data.notebook) { - this.notebook_model.name = data.notebook.name; this.notebook_model.path = data.notebook.path; } if (data && data.kernel) { diff --git a/IPython/html/static/tree/js/main.js b/IPython/html/static/tree/js/main.js index 2396ad8..8d84917 100644 --- a/IPython/html/static/tree/js/main.js +++ b/IPython/html/static/tree/js/main.js @@ -2,8 +2,9 @@ // Distributed under the terms of the Modified BSD License. require([ - 'base/js/namespace', 'jquery', + 'base/js/namespace', + 'base/js/dialog', 'base/js/events', 'base/js/page', 'base/js/utils', @@ -19,18 +20,20 @@ require([ 'bootstrap', 'custom/custom', ], function( - IPython, - $, + $, + IPython, + dialog, events, - page, - utils, - contents, + page, + utils, + contents_service, notebooklist, clusterlist, sesssionlist, kernellist, terminallist, loginwidget){ + "use strict"; page = new page.Page(); @@ -38,36 +41,37 @@ require([ base_url: utils.get_body_data("baseUrl"), notebook_path: utils.get_body_data("notebookPath"), }; - session_list = new sesssionlist.SesssionList($.extend({ + var session_list = new sesssionlist.SesssionList($.extend({ events: events}, common_options)); - contents = new contents.Contents($.extend({ + var contents = new contents_service.Contents($.extend({ events: events}, common_options)); - notebook_list = new notebooklist.NotebookList('#notebook_list', $.extend({ + var notebook_list = new notebooklist.NotebookList('#notebook_list', $.extend({ contents: contents, session_list: session_list}, common_options)); - cluster_list = new clusterlist.ClusterList('#cluster_list', common_options); - kernel_list = new kernellist.KernelList('#running_list', $.extend({ + var cluster_list = new clusterlist.ClusterList('#cluster_list', common_options); + var kernel_list = new kernellist.KernelList('#running_list', $.extend({ session_list: session_list}, common_options)); + var terminal_list; if (utils.get_body_data("terminalsAvailable") === "True") { terminal_list = new terminallist.TerminalList('#terminal_list', common_options); } - login_widget = new loginwidget.LoginWidget('#login_widget', common_options); + var login_widget = new loginwidget.LoginWidget('#login_widget', common_options); $('#new_notebook').click(function (e) { - contents.new(common_options.notebook_path, null, { + contents.new(common_options.notebook_path, { ext: ".ipynb", extra_settings: {async: false}, // So we can open a new window afterwards success: function (data) { window.open( utils.url_join_encode( common_options.base_url, 'notebooks', - data.path, data.name + data.path ), '_blank'); }, error: function(error) { diff --git a/IPython/html/static/tree/js/notebooklist.js b/IPython/html/static/tree/js/notebooklist.js index b361167..678fceb 100644 --- a/IPython/html/static/tree/js/notebooklist.js +++ b/IPython/html/static/tree/js/notebooklist.js @@ -100,7 +100,7 @@ define([ }; reader.onerror = function (event) { var item = $(event.target).data('item'); - var name = item.data('name') + var name = item.data('name'); item.remove(); dialog.modal({ title : 'Failed to read file', @@ -141,7 +141,7 @@ define([ }; NotebookList.prototype.load_list = function () { - var that = this + var that = this; this.contents.list_contents(that.notebook_path, { success: $.proxy(this.draw_notebook_list, this), error: function(error) { @@ -177,7 +177,7 @@ define([ model = { type: 'directory', name: '..', - path: path, + path: utils.url_path_split(path)[0], }; this.add_link(model, item); offset += 1; @@ -240,8 +240,7 @@ define([ utils.url_join_encode( this.base_url, uri_prefix, - path, - name + path ) ); // directory nav doesn't open new tabs @@ -311,7 +310,6 @@ define([ }; NotebookList.prototype.add_delete_button = function (item) { - var new_buttons = $('').addClass("btn-group pull-right"); var notebooklist = this; var delete_button = $("