825209970c
WIP #334 Fixed programmatic changes triggeringd save WIP #334 Added support for single panel WIP #334 Added ClassEditor WIP #334 Added boilerplate class code WIP #334 Updated creation buttons WIP #334 Updated pipeline execution for complex data types WIP #334 Fixed problem in default template WIP #334 Updated default code template WIP #334 Updated class name from src return value WIP #334 Removed Primitive, Complex data types from opint editor WIP #334 set isAbstract if needed on data type creation WIP #334 updated seeds WIP #334 Updated cifar example
72 linhas
2.1 KiB
JavaScript
72 linhas
2.1 KiB
JavaScript
/*globals define */
|
|
/*jshint browser: true*/
|
|
|
|
define([
|
|
'panels/TextEditor/TextEditorControl',
|
|
'underscore',
|
|
'text!./DefaultCodeTemplate.ejs'
|
|
], function (
|
|
TextEditorControl,
|
|
_,
|
|
CODE_TEMPLATE
|
|
) {
|
|
|
|
'use strict';
|
|
|
|
var ClassCodeEditorControl,
|
|
getBoilerplate = _.template(CODE_TEMPLATE);
|
|
|
|
ClassCodeEditorControl = function (options) {
|
|
options.attributeName = 'code';
|
|
TextEditorControl.call(this, options);
|
|
};
|
|
|
|
_.extend(
|
|
ClassCodeEditorControl.prototype,
|
|
TextEditorControl.prototype
|
|
);
|
|
|
|
// input/output updates are actually activeNode updates
|
|
ClassCodeEditorControl.prototype._onUpdate = function (id) {
|
|
if (id === this._currentNodeId) {
|
|
TextEditorControl.prototype._onUpdate.call(this, this._currentNodeId);
|
|
}
|
|
};
|
|
|
|
ClassCodeEditorControl.prototype._getObjectDescriptor = function (nodeId) {
|
|
var desc = TextEditorControl.prototype._getObjectDescriptor.call(this, nodeId),
|
|
node = this._client.getNode(nodeId),
|
|
ownCode = node.getOwnAttribute(this.ATTRIBUTE_NAME);
|
|
|
|
// If the 'text' attribute is not set, and it's not inheriting anything
|
|
if (!desc.text && ownCode === undefined) {
|
|
desc.text = getBoilerplate(desc);
|
|
}
|
|
return desc;
|
|
};
|
|
|
|
ClassCodeEditorControl.prototype.saveTextFor = function (id, text) {
|
|
// On save, update the node's name
|
|
// For now, simply use regex to grab the returned name
|
|
var i = text.lastIndexOf('return') + 7,
|
|
returned = text.substring(i),
|
|
match = returned.match(/[a-zA-Z0-9_]+/),
|
|
node = this._client.getNode(id),
|
|
nodeName = node.getAttribute('name'),
|
|
name;
|
|
|
|
if (match) {
|
|
name = match[0];
|
|
}
|
|
|
|
this._client.startTransaction(`Updating class "${name || nodeName}"`);
|
|
if (name) {
|
|
this._client.setAttributes(id, 'name', name);
|
|
}
|
|
TextEditorControl.prototype.saveTextFor.call(this, id, text);
|
|
this._client.completeTransaction();
|
|
};
|
|
|
|
return ClassCodeEditorControl;
|
|
});
|