Commit e41ceee9 authored by damianofalcioni's avatar damianofalcioni

Javascript Render UI defined completely in the manifest

parent ad3fb0af
......@@ -29,12 +29,15 @@
refresh: function () {
_state.editor.refresh();
},
setContent: function (content = '') {
_state.editor.setValue(content);
setContent: function (content = {}) {
content.text = content.text || '';
_state.editor.setValue(content.text);
_state.editor.refresh();
},
getContent: function () {
return _state.editor.getValue();
return {
text: _state.editor.getValue()
};
}
};
};
......
(function (OliveUI, Utils) {
'use strict';
var _statics = {
init: {
loadJavascriptContent: function (_dom, content) {
var alg = content.javascriptAlg;
try {
var algF = new Function(alg + '\n//# sourceURL=' + Utils.generateUUID() + '.js');
var domOut = algF();
_dom.outputDiv.empty().append(domOut);
} catch (e) {
Utils.showError(e, _dom.messageDiv);
}
}
}
};
var _newJavascriptRenderUI = function (config = {}) {
var _dom = {
messageDiv: $('<div>'),
outputDiv: $('<div>')
};
return {
render: function () {
return $('<div>').append(
_dom.messageDiv,
_dom.outputDiv);
},
setContent: function (content = {}) {
content.javascriptAlg = content.javascriptAlg || '';
_statics.init.loadJavascriptContent(_dom, content);
}
};
};
OliveUI.modules.newJavascriptRenderUI = _newJavascriptRenderUI;
}(OliveUI, OliveUI.utils));
(function (OliveUI, newCodeEditorUI) {
'use strict';
var _newJavascriptRenderUI_configUI = function (config = {}) {
var _dom = {
rootNode: $('<div>')
};
var _sub = {
codeEditor: newCodeEditorUI({})
};
return {
getContent: function () {
return {
javascriptAlg: _sub.codeEditor.getContent()
};
},
setContent: function (content = {}) {
_sub.codeEditor.setContent(content.javascriptAlg || '/*Javascript algoritm that "return" a DOM object.*/\n');
},
render: function () {
return _dom.rootNode.empty().append(
_sub.codeEditor.render()
);
},
refresh: function () {
_sub.codeEditor.refresh();
}
};
};
OliveUI.modules.newJavascriptRenderUI_configUI = _newJavascriptRenderUI_configUI;
}(OliveUI, OliveUI.modules.newCodeEditorUI));
......@@ -122,7 +122,7 @@
},
view: {
showMSResult: function (output, _sub, _dom) {
var adaptationAlg = _sub.codeEditor.getContent();
var adaptationAlg = _sub.codeEditor.getContent().text;
_dom.resultTxt.val(JSON.stringify(output, null, 4));
if (adaptationAlg.indexOf('return ') === -1) {
......@@ -209,13 +209,15 @@
return {
microserviceInputs: _sub.inputTable.getContent(),
serviceName: _dom.serviceNameTxt.val(),
microserviceOutputAdaptAlg: _sub.codeEditor.getContent()
microserviceOutputAdaptAlg: _sub.codeEditor.getContent().text
};
},
setContent: function (_dom, _sub, content) {
_dom.serviceNameTxt.val(content.serviceName || '');
_sub.inputTable.setContent(content.microserviceInputs || {});
_sub.codeEditor.setContent(content.microserviceOutputAdaptAlg || '/*\n Javascript algoritm that "return" a DOM object.\n The algorithm can access the microservice output content\n using the variable "output"\n*/');
_sub.codeEditor.setContent({
text: content.microserviceOutputAdaptAlg || '/*\n Javascript algoritm that "return" a DOM object.\n The algorithm can access the microservice output content\n using the variable "output"\n*/'
});
}
}
};
......
(function (OliveUI, newJavascriptRenderUI, newJavascriptRenderUI_configUI) {
(function (OliveUI, newCodeEditorUI) {
'use strict';
OliveUI.addWidgetManifest({
......@@ -7,12 +7,74 @@
description: '',
createUIFn: function () {
return newJavascriptRenderUI({});
var _newJavascriptRenderUI = function (config = {}) {
var _dom = {
messageDiv: $('<div>'),
outputDiv: $('<div>')
};
return {
render: function () {
return $('<div>').append(
_dom.messageDiv,
_dom.outputDiv);
},
setContent: function (content = {}) {
content.javascriptAlg = content.javascriptAlg || '';
try {
var algF = new Function(content.javascriptAlg + '\n//# sourceURL=' + OliveUI.utils.generateUUID() + '.js');
var domOut = algF();
_dom.outputDiv.empty().append(domOut);
} catch (e) {
OliveUI.utils.showError(e, _dom.messageDiv);
}
}
};
};
return _newJavascriptRenderUI();
},
createConfigurationUIFn: function () {
return newJavascriptRenderUI_configUI({});
var _newJavascriptRenderUI_configUI = function (config = {}) {
var _dom = {
rootNode: $('<div>')
};
var _sub = {
codeEditor: newCodeEditorUI({})
};
return {
getContent: function () {
return {
javascriptAlg: _sub.codeEditor.getContent().text
};
},
setContent: function (content = {}) {
_sub.codeEditor.setContent({
text: content.javascriptAlg || '//Javascript algoritm that "return" a DOM object.\n'
});
},
render: function () {
return _dom.rootNode.empty().append(
_sub.codeEditor.render()
);
},
refresh: function () {
_sub.codeEditor.refresh();
}
};
};
return _newJavascriptRenderUI_configUI();
}
/* OR
createConfigurationUIFn: function () {
return newCodeEditorUI({});
},
configurationMappingFn: function (widget, configurationUIOutputConfig, viewUIInputConfig) {
Object.assign(viewUIInputConfig, {
javascriptAlg: configurationUIOutputConfig.text
});
}
*/
});
}(OliveUI, OliveUI.modules.newJavascriptRenderUI, OliveUI.modules.newJavascriptRenderUI_configUI));
}(OliveUI, OliveUI.modules.newCodeEditorUI));
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment