diff --git a/src/visualizers/panels/InteractiveEditor/InteractiveEditorControl.js b/src/visualizers/panels/InteractiveEditor/InteractiveEditorControl.js index 923a63bc3..49afd58e4 100644 --- a/src/visualizers/panels/InteractiveEditor/InteractiveEditorControl.js +++ b/src/visualizers/panels/InteractiveEditor/InteractiveEditorControl.js @@ -1,10 +1,12 @@ /*globals define, WebGMEGlobal*/ define([ + 'deepforge/compute/interactive/session-with-queue', 'deepforge/viz/ConfigDialog', 'js/Constants', 'q', ], function ( + Session, ConfigDialog, CONSTANTS, Q, @@ -16,23 +18,45 @@ define([ constructor(options) { this._logger = options.logger.fork('Control'); this.client = options.client; + this.session = options.session; this._embedded = options.embedded; this._widget = options.widget; this.initializeWidgetHandlers(this._widget); this.territoryEventFilters = []; - this._currentNodeId = null; - + if (this.session) { + this.onComputeInitialized(this.session); + } else { + this._widget.showComputeShield(); + } this._logger.debug('ctor finished'); } initializeWidgetHandlers (widget) { - const features = widget.getCapabilities(); - if (features.save) { - widget.save = () => this.save(); - } + const self = this; + widget.save = function() {return self.save(...arguments);}; widget.getConfigDialog = () => new ConfigDialog(this.client); widget.getInitializationCode = () => this.getInitializationCode(); + widget.createInteractiveSession = + (computeId, config) => this.createInteractiveSession(computeId, config); + } + + async createInteractiveSession(computeId, config) { + const createSession = Session.new(computeId, config); + this._widget.showComputeLoadingStatus(status); + this._widget.updateComputeLoadingStatus('Connecting'); + createSession.on( + 'update', + status => this._widget.updateComputeLoadingStatus(status) + ); + const session = await createSession; + this.onComputeInitialized(session); + } + + async onComputeInitialized(session) { + this.session = session; + this._widget.session = session; // HACK + this._widget.onComputeInitialized(session); // HACK } async getInitializationCode () { @@ -218,6 +242,9 @@ define([ destroy () { this._detachClientEventListeners(); this._widget.destroy(); + if (this.session) { + this.session.close(); + } } _attachClientEventListeners () { diff --git a/src/visualizers/panels/InteractiveEditor/InteractiveEditorPanel.js b/src/visualizers/panels/InteractiveEditor/InteractiveEditorPanel.js index b7b4d7e65..104529aef 100644 --- a/src/visualizers/panels/InteractiveEditor/InteractiveEditorPanel.js +++ b/src/visualizers/panels/InteractiveEditor/InteractiveEditorPanel.js @@ -3,29 +3,25 @@ define([ 'js/PanelBase/PanelBaseWithHeader', 'js/PanelManager/IActivePanel', - 'widgets/InteractiveEditor/InteractiveEditorWidget', - './InteractiveEditorControl' ], function ( PanelBaseWithHeader, IActivePanel, - InteractiveEditorWidget, - InteractiveEditorControl ) { 'use strict'; - function InteractiveEditorPanel(layoutManager, params) { - var options = {}; + function InteractiveEditorPanel(options, params) { + const panelOptions = {}; //set properties from options - options[PanelBaseWithHeader.OPTIONS.LOGGER_INSTANCE_NAME] = 'InteractiveEditorPanel'; - options[PanelBaseWithHeader.OPTIONS.FLOATING_TITLE] = true; + panelOptions[PanelBaseWithHeader.OPTIONS.LOGGER_INSTANCE_NAME] = name + 'Panel'; //call parent's constructor - PanelBaseWithHeader.apply(this, [options, layoutManager]); + PanelBaseWithHeader.call(this, panelOptions); this._client = params.client; this._embedded = params.embedded; + this.session = params.session; - this.initialize(); + this.initialize(options); this.logger.debug('ctor finished'); } @@ -34,23 +30,25 @@ define([ _.extend(InteractiveEditorPanel.prototype, PanelBaseWithHeader.prototype); _.extend(InteractiveEditorPanel.prototype, IActivePanel.prototype); - InteractiveEditorPanel.prototype.initialize = function () { + InteractiveEditorPanel.prototype.initialize = function (options) { + const {Control, Widget} = options; var self = this; //set Widget title this.setTitle(''); - this.widget = new InteractiveEditorWidget(this.logger, this.$el); + this.widget = new Widget(this.logger, this.$el); this.widget.setTitle = function (title) { self.setTitle(title); }; - this.control = new InteractiveEditorControl({ + this.control = new Control({ logger: this.logger, client: this._client, embedded: this._embedded, - widget: this.widget + widget: this.widget, + session: this.session, }); this.onActivate(); diff --git a/src/visualizers/widgets/InteractiveEditor/InteractiveEditorWidget.js b/src/visualizers/widgets/InteractiveEditor/InteractiveEditorWidget.js index ec8b6cb57..f162183d5 100644 --- a/src/visualizers/widgets/InteractiveEditor/InteractiveEditorWidget.js +++ b/src/visualizers/widgets/InteractiveEditor/InteractiveEditorWidget.js @@ -1,13 +1,11 @@ /* globals define, $ */ define([ - 'deepforge/compute/interactive/session-with-queue', 'deepforge/viz/ConfigDialog', 'deepforge/viz/InformDialog', 'deepforge/compute/index', 'deepforge/globals', 'css!./styles/InteractiveEditorWidget.css', ], function( - Session, ConfigDialog, InformDialog, Compute, @@ -18,12 +16,12 @@ define([ const LoaderHTML = '