Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SCT-401 - fix issue where losing connection results in user being unable to save #1571

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions kbase-extension/static/kbase/js/api/auth.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
define([
'bluebird',
'jquery',
'util/string',
'jqueryCookie'
], function(Promise, $, StringUtil) {
], function(Promise, $) {
'use strict';

function factory(config) {
var url = config.url;
var cookieName = 'kbase_session';
const url = config.url,
cookieName = 'kbase_session',
cookieRegex = new RegExp('(^| )' + cookieName + '=([^;]+)');

/**
* Does a GET request to get the profile of the currently logged in user.
Expand Down Expand Up @@ -42,14 +42,19 @@ define([
return null;
}

function getTokenCookie() {
let match = document.cookie.match(cookieRegex);
if (match) {
return match[2];
}
return null;
}

/* Returns the current auth token that's stuffed in a cookie.
* Returns null if not logged in.
*/
function getAuthToken() {
if (!$.cookie(cookieName)) {
return null;
}
return $.cookie(cookieName);
return getTokenCookie();
}

/* Sets the given auth token into the browser's cookie.
Expand Down
63 changes: 34 additions & 29 deletions kbase-extension/static/kbase/js/kbaseNarrative.js
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,9 @@ define([
} else {
errorText = 'An unknown error occurred!';
}
errorText += '<br>This may occur because you have recently lost a connection to the ' +
'Narrative server. Please try restarting the kernel by navigating to the Kernel ' +
'menu -> Restart. If this problem persists, contact KBase through the Help menu.';

Jupyter.dialog.modal({
title: 'Narrative save failed!',
Expand Down Expand Up @@ -715,17 +718,17 @@ define([
}
};

$([Jupyter.events]).on('notebook_loaded.Notebook', function () {
$([Jupyter.events]).on('notebook_loaded.Notebook', () => {
this.loadingWidget.updateProgress('narrative', true);
$('#notification_area').find('div#notification_trusted').hide();

$(document).one('dataUpdated.Narrative', function () {
$(document).one('dataUpdated.Narrative', () => {
this.loadingWidget.updateProgress('data', true);
}.bind(this));
});

$(document).one('appListUpdated.Narrative', function () {
$(document).one('appListUpdated.Narrative', () => {
this.loadingWidget.updateProgress('apps', true);
}.bind(this));
});

// Tricky with inter/intra-dependencies between kbaseNarrative and kbaseNarrativeWorkspace...
this.sidePanel = new KBaseNarrativeSidePanel($('#kb-side-panel'), { autorender: false });
Expand Down Expand Up @@ -753,34 +756,36 @@ define([
}
this.initSharePanel();
this.updateDocumentVersion()
.then(function() {
.then(() => {
// init the controller
return this.narrController.render();
}.bind(this))
.finally(function () {
})
.finally(() => {
this.sidePanel.render();
}.bind(this));
});

$([Jupyter.events]).trigger('loaded.Narrative');
$([Jupyter.events]).on('kernel_ready.Kernel',
function () {
console.log('Kernel Ready! Initializing Job Channel...');
this.loadingWidget.updateProgress('kernel', true);
// TODO: This should be an event "kernel-ready", perhaps broadcast
// on the default bus channel.
this.sidePanel.$jobsWidget.initCommChannel()
.then(function () {
this.loadingWidget.updateProgress('jobs', true);
}.bind(this))
.catch(function (err) {
// TODO: put the narrative into a terminal state
console.error('ERROR initializing kbase comm channel', err);
KBFatal('Narrative.ini', 'KBase communication channel could not be initiated with the back end. TODO');
// this.loadingWidget.remove();
}.bind(this));
}.bind(this)
);
}.bind(this));
$([Jupyter.events]).on('kernel_ready.Kernel', () => {
NarrativeLogin.restartSession();
Jupyter.notebook.kernel.execute(
'import os;' +
'os.environ["KB_AUTH_TOKEN"]="' + this.getAuthToken() + '";' +
'os.environ["KB_WORKSPACE_ID"]="' + Jupyter.notebook.metadata.ws_name + '"'
);

console.log('Kernel Ready! Initializing Job Channel...');
this.loadingWidget.updateProgress('kernel', true);
// TODO: This should be an event "kernel-ready", perhaps broadcast
// on the default bus channel.
this.sidePanel.$jobsWidget.initCommChannel()
.then(() => {
this.loadingWidget.updateProgress('jobs', true);
})
.catch((err) => {
console.error('ERROR initializing kbase comm channel', err);
KBFatal('Narrative.ini', 'KBase communication channel could not be initiated with the back end.');
});
});
});
};

/**
Expand Down
Loading