Created
December 1, 2019 17:07
-
-
Save echarles/89f799fd414d25234373f1c71da6922b to your computer and use it in GitHub Desktop.
Diff to resolve https://github.com/Zsailer/nbclassic/issues/2 Jupyter Kernel name is not displayed with Kernel Manager
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/notebook/static/notebook/js/kernelselector.js b/notebook/static/notebook/js/kernelselector.js | |
index 58f71d3233..aec4e08657 100644 | |
--- a/notebook/static/notebook/js/kernelselector.js | |
+++ b/notebook/static/notebook/js/kernelselector.js | |
@@ -74,18 +74,19 @@ define([ | |
.click( function () { | |
that.set_kernel(ks.name); | |
}) | |
- .text(ks.spec.display_name) | |
+ .text(ks.spec.display_name + " (" + ks.name + ")") | |
) | |
); | |
// Create the File > New Notebook submenu | |
new_notebook_submenu.append( | |
- $("<li>").attr("id", "new-notebook-submenu-"+ks.name).append( | |
+ $("<li>").addClass("new-notebook-kernel") | |
+ .attr("data-kernel-type", ks.name).append( | |
$('<a>') | |
.attr('href', '#') | |
.click( function () { | |
that.new_notebook(ks.name); | |
}) | |
- .text(ks.spec.display_name) | |
+ .text(ks.spec.display_name + " (" + ks.name + ")") | |
) | |
); | |
@@ -103,7 +104,7 @@ define([ | |
this.current_selection = ks.name; | |
// put the current kernel at the top of File > New Notebook | |
- var cur_kernel_entry = $("#new-notebook-submenu-" + ks.name); | |
+ var cur_kernel_entry = $('.new-notebook-kernel[data-kernel-type="' + ks.name + '"]'); | |
var parent = cur_kernel_entry.parent(); | |
// do something only if there is more than one kernel | |
if (parent.children().length > 1) { | |
@@ -261,13 +262,17 @@ define([ | |
} | |
names.map(function (name) { | |
var ks = that.kernelspecs[name]; | |
+ var display_txt = ks.name; | |
+ if (ks.spec.display_name) { | |
+ display_txt = ks.spec.display_name + " (" + ks.name + ")" | |
+ } | |
select.append( | |
- $('<option/>').attr('value', ks.name).text(ks.spec.display_name || ks.name) | |
+ $('<option/>').attr('value', ks.name).text(display_txt) | |
); | |
}); | |
var no_kernel_msg = i18n.msg.sprintf(i18n.msg._("Could not find a kernel matching %s. Please select a kernel:"), | |
- (data.selected.display_name || data.selected.name)) | |
+ (data.selected.display_name || data.selected.name)); | |
var body = $("<form>").addClass("form-inline").append( | |
$("<span>").text(no_kernel_msg) | |
).append(select); | |
diff --git a/notebook/static/services/sessions/session.js b/notebook/static/services/sessions/session.js | |
index 2243de6da9..d627b3854d 100644 | |
--- a/notebook/static/services/sessions/session.js | |
+++ b/notebook/static/services/sessions/session.js | |
@@ -40,6 +40,9 @@ define([ | |
this.ws_url = options.ws_url; | |
this.session_service_url = utils.url_path_join(this.base_url, 'api/sessions'); | |
this.session_url = null; | |
+ this._have_session_url = new Promise(function(resolve, reject){ | |
+ this._got_session_url = resolve; | |
+ }.bind(this)); | |
this.notebook = options.notebook; | |
this.kernel = null; | |
@@ -169,15 +172,18 @@ define([ | |
this.notebook_model.path = path; | |
} | |
- utils.ajax(this.session_url, { | |
- processData: false, | |
- cache: false, | |
- type: "PATCH", | |
- data: JSON.stringify(this._get_model()), | |
- contentType: 'application/json', | |
- dataType: "json", | |
- success: this._on_success(success), | |
- error: this._on_error(error) | |
+ var that = this; | |
+ this._have_session_url.then(function() { | |
+ utils.ajax(that.session_url, { | |
+ processData: false, | |
+ cache: false, | |
+ type: "PATCH", | |
+ data: JSON.stringify(that._get_model()), | |
+ contentType: 'application/json', | |
+ dataType: "json", | |
+ success: that._on_success(success), | |
+ error: that._on_error(error) | |
+ }); | |
}); | |
}; | |
@@ -196,13 +202,16 @@ define([ | |
this.kernel._kernel_dead(); | |
} | |
- utils.ajax(this.session_url, { | |
- processData: false, | |
- cache: false, | |
- type: "DELETE", | |
- dataType: "json", | |
- success: this._on_success(success), | |
- error: this._on_error(error) | |
+ var that = this; | |
+ this._have_session_url.then(function() { | |
+ utils.ajax(that.session_url, { | |
+ processData: false, | |
+ cache: false, | |
+ type: "DELETE", | |
+ dataType: "json", | |
+ success: that._on_success(success), | |
+ error: that._on_error(error) | |
+ }); | |
}); | |
}; | |
@@ -265,6 +274,7 @@ define([ | |
if (data && data.id) { | |
this.id = data.id; | |
this.session_url = utils.url_path_join(this.session_service_url, this.id); | |
+ this._got_session_url(); | |
} | |
if (data && data.notebook) { | |
this.notebook_model.path = data.path; | |
diff --git a/notebook/static/tree/js/newnotebook.js b/notebook/static/tree/js/newnotebook.js | |
index d0ea5d5c29..5f0ee8fc65 100644 | |
--- a/notebook/static/tree/js/newnotebook.js | |
+++ b/notebook/static/tree/js/newnotebook.js | |
@@ -60,12 +60,13 @@ define([ | |
for (var i = keys.length - 1; i >= 0; i--) { | |
var ks = this.kernelspecs[keys[i]]; | |
var li = $("<li>") | |
- .attr("id", "kernel-" +ks.name) | |
+ .addClass("new-notebook-kernel") | |
+ .attr("data-kernel-type", ks.name) | |
.data('kernelspec', ks).append( | |
$('<a>') | |
.attr('href', '#') | |
.click($.proxy(this.new_notebook, this, ks.name)) | |
- .text(ks.spec.display_name) | |
+ .text(ks.spec.display_name + " (" + ks.name + ")") | |
.attr('title', i18n.sprintf(i18n._('Create a new notebook with %s'), ks.spec.display_name)) | |
); | |
menu.after(li); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment