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

Add getInitializationCode helper for interactive editors. Closes #1776 #1781

Merged
merged 1 commit into from
Jul 17, 2020
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
define([
'deepforge/viz/ConfigDialog',
'js/Constants',
'q',
], function (
ConfigDialog,
CONSTANTS,
Q,
) {

'use strict';
Expand All @@ -30,6 +32,42 @@ define([
widget.save = () => this.save();
}
widget.getConfigDialog = () => new ConfigDialog(this.client);
widget.getInitializationCode = () => this.getInitializationCode();
}

async getInitializationCode () {
const deferred = Q.defer();
const territory = {'': {children: 1}};
const territoryId = this.client.addUI(this, events => {
const codeType = this.getMetaNode('pipeline.Code');
const libraryCode = this.getMetaNode('LibraryCode');
if (!codeType || !libraryCode) {
this._logger.warn('Unsupported project. Could not find Code and LibraryCode meta node.');
return;
}

const nodeIds = events
.filter(event => event.etype === CONSTANTS.TERRITORY_EVENT_LOAD)
.map(event => event.eid);

const codeNodeIds = nodeIds
.filter(id => this.client.isTypeOf(id, codeType.getId()));

const initCode = codeNodeIds
.sort((n1, n2) => { // move library code to be in the front
const v1 = this.client.isTypeOf(n1, libraryCode.getId()) ? 1 : 0;
const v2 = this.client.isTypeOf(n2, libraryCode.getId()) ? 1 : 0;
return v2 - v1;
})
.map(nodeId => this.client.getNode(nodeId).getAttribute('code'))
.join('\n');

this.client.removeUI(territoryId);
deferred.resolve(initCode);
});
this.client.updateTerritory(territoryId, territory);

return deferred.promise;
}

selectedObjectChanged (nodeId) {
Expand Down