Commit c2dacf51 authored by damianofalcioni's avatar damianofalcioni

renamed modules and added widget manifest concept

parent 962096cd
......@@ -22,10 +22,12 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.46.0/mode/javascript/javascript.min.js" integrity="sha256-h2CaV12bheEEc7Ao3zF6MntAbDLJkPoFR+h+nHvQUqA=" crossorigin="anonymous"></script>
<script src="js/OliveUI.js"></script>
<script src="js/modules/newWidgetView.js"></script>
<script src="js/modules/newCodeEditor.js"></script>
<script src="js/modules/newMicroserviceCallConfigUI.js"></script>
<script src="js/modules/newMicroserviceCallViewUI.js"></script>
<script src="js/modules/newWidgetUI.js"></script>
<script src="js/modules/newCodeEditorUI.js"></script>
<script src="js/modules/newMicroserviceUI.js"></script>
<script src="js/modules/newMicroserviceUI_configUI.js"></script>
<script src="js/widgets/MicroserviceUI_manifest.js"></script>
<script src="js/main.js"></script>
</body>
......
......@@ -9,11 +9,65 @@
getState e setState che debbono ritornare ed impostare la configurazione totale del widget
*/
var _statics = {
createWidgetInstance: function (widgetName, _dom, _state) {
var widgetManifest = OliveUI.widgetsManifests[widgetName];
if (!widgetManifest) throw 'Impossible to find the manifest of the widget ' + widgetName;
if (!OliveUI.modules.newWidgetUI) throw 'Missing newWidgetUI module';
var widgetRootDiv = $('<div>');
var widget = OliveUI.modules.newWidgetUI({
initialView: 'render',
removeBtnClickFn: function () {
widgetRootDiv.remove();
//TODO: remove widget from instances
},
renderModule: widgetManifest.createUIFn(),
configModule: widgetManifest.createConfigurationUIFn ? widgetManifest.createConfigurationUIFn() : null,
mappingFn: widgetManifest.configurationMappingFn ? function(configOutput, renderInput) {
widgetManifest.configurationMappingFn(widget, configOutput, renderInput);
} : null
});
_dom.rootDiv.append(
widgetRootDiv.append(
widget.render()
)
);
//TODO: add widget to instances
}
};
var OliveUI = function (config = {}) {
var _state = {
widgetInstances: {}
};
var _dom = {
rootDiv: $('<div>')
};
return {
render: function () {
return _dom.rootDiv;
},
createWidgetInstance: function (widgetName) {
_statics.createWidgetInstance(widgetName, _dom, _state);
}
};
};
OliveUI.modules = {};
OliveUI.widgetsManifests = {};
OliveUI.addWidgetManifest = function (widgetManifest) {
if (!widgetManifest.name) throw 'name missing in widget manifest';
OliveUI.widgetsManifests[widgetManifest.name] = widgetManifest;
};
//------------------------------------------------------------------------
OliveUI.utils = (function () {
......@@ -206,10 +260,6 @@
return _utils;
}());
OliveUI.addWidget = function (widgetId, widget) {
};
return OliveUI;
}));
//Main entry point!
(function (OliveUI, newMicroserviceCallViewUI, newMicroserviceCallConfigUI) {
var mscEndpoint = 'https://www.adoxx.org/micro-service-controller-rest/rest/';
var microserviceId = '1738cb62-cc55-4abf-8560-feafdb83260c';
var operationId = 'default';
(function (OliveUI) {
var widgetRoot = $('<div>');
var widget = OliveUI.modules.newWidgetView({
initialView: 'render',
removeBtnClickFn: function () {
widgetRoot.empty();
},
mappingFn: function (configOutput, renderInput) {
if (!configOutput.microserviceInputs) throw 'Widget not configured';
Object.assign(renderInput, {
microserviceId: microserviceId,
operationId: operationId,
microserviceInputJSON: JSON.stringify(configOutput.microserviceInputs),
microserviceOutputAdaptAlg: configOutput.microserviceOutputAdaptAlg,
});
if (configOutput.serviceName)
widget.setWidgetTitle(configOutput.serviceName);
},
renderModule: newMicroserviceCallViewUI({
mscEndpoint: mscEndpoint
}),
configModule: newMicroserviceCallConfigUI({
mscEndpoint: mscEndpoint,
microserviceId: microserviceId,
operationId: operationId,
forceStartWhenStopped: true,
showServiceNameTxt: true
})
});
var oliveUI = OliveUI();
$('#main').append(widgetRoot.append(widget.render()));
$('#main').append(
oliveUI.render()
);
oliveUI.createWidgetInstance('Microservice UI');
oliveUI.createWidgetInstance('Microservice UI');
/*
widget.getConfig().configModule.refresh();
widget.setContent({
microserviceInputs: {
......@@ -45,5 +21,5 @@
microserviceOutputAdaptAlg: '',
serviceName: 'Test 1'
});
}(OliveUI, OliveUI.modules.newMicroserviceCallViewUI, OliveUI.modules.newMicroserviceCallConfigUI));
*/
}(OliveUI));
(function (OliveUI, CodeMirror) {
'use strict';
OliveUI.modules.newCodeEditor = function (config = {}) {
OliveUI.modules.newCodeEditorUI = function (config = {}) {
config.mode = config.mode || 'javascript';
config.tabSize = config.tabSize || 2;
config.lineNumbers = config.lineNumbers != null ? config.lineNumbers : true;
......
(function (OliveUI, newMicroserviceCallViewUI, newMicroserviceCallConfigUI) {
//DO NOT LOAD THIS FILE. OliveUI.createWidget not yet available
OliveUI.createWidget(function (widget) {
var config = {
mscEndpoint: '',
microserviceId: '',
operationId: ''
};
return {
mappingFn: function (configOutput, renderInput) {
if (!configOutput.microserviceInputs) throw 'Widget not configured';
Object.assign(renderInput, {
microserviceId: config.microserviceId,
operationId: config.operationId,
microserviceInputJSON: JSON.stringify(configOutput.microserviceInputs),
microserviceOutputAdaptAlg: configOutput.microserviceOutputAdaptAlg,
});
if (configOutput.serviceName)
widget.setWidgetTitle(configOutput.serviceName);
},
renderModule: newMicroserviceCallViewUI({
mscEndpoint: config.mscEndpoint
}),
configModule: newMicroserviceCallConfigUI({
mscEndpoint: config.mscEndpoint,
microserviceId: config.microserviceId,
operationId: config.operationId,
forceStartWhenStopped: true,
showServiceNameTxt: true
})
};
});
/*
var _static = {
init: function (_dom, _sub, config) {
_sub.widget = OliveUI.createWidget({
mappingFn: function (configOutput, renderInput) {
if (!configOutput.microserviceInputs) throw 'Widget not configured';
Object.assign(renderInput, {
microserviceId: config.microserviceId,
operationId: config.operationId,
microserviceInputJSON: JSON.stringify(configOutput.microserviceInputs),
microserviceOutputAdaptAlg: configOutput.microserviceOutputAdaptAlg,
});
if (configOutput.serviceName)
widget.setWidgetTitle(configOutput.serviceName);
},
renderModule: newMicroserviceCallViewUI({
mscEndpoint: config.mscEndpoint
}),
configModule: newMicroserviceCallConfigUI({
mscEndpoint: config.mscEndpoint,
microserviceId: config.microserviceId,
operationId: config.operationId,
forceStartWhenStopped: true,
showServiceNameTxt: true
})
});
}
};
var _newMicroserviceCallWidget = function (config = {}) {
config.mscEndpoint = config.mscEndpoint || '';
config.microserviceId = config.microserviceId || '';
config.operationId = config.operationId || '';
var _dom = {
root: $('<div>')
};
var _sub = {
widget: null
};
_static.init(_dom, _sub, config);
return {
render: function () {
return _dom.root.append(
_sub.widget.render()
);
}
};
};
OliveUI.modules.newMicroserviceCallWidget = _newMicroserviceCallWidget;
*/
}(OliveUI, OliveUI.modules.newMicroserviceCallViewUI, OliveUI.modules.newMicroserviceCallConfigUI));
......@@ -67,7 +67,7 @@
}
};
var _newMicroserviceCallViewUI = function (config = {}) {
var _newMicroserviceUI = function (config = {}) {
_statics.init.checkConfig(config);
var _dom = _statics.ui.newDom();
......@@ -82,6 +82,6 @@
};
};
OliveUI.modules.newMicroserviceCallViewUI = _newMicroserviceCallViewUI;
OliveUI.modules.newMicroserviceUI = _newMicroserviceUI;
}(OliveUI, OliveUI.utils));
(function (OliveUI, Utils, newCodeEditor) {
(function (OliveUI, Utils, newCodeEditorUI) {
'use strict';
/* newMSInputTable will be hided from outside */
var newMSInputTable = (function (Utils) {
/* newMSInputTableUI will be hided from outside */
var newMSInputTableUI = (function (Utils) {
var _statics = {
services: {
getMicroserviceIOInfo: function (restEndpoint, microserviceId, operationId, successCallback, failureCallback) {
......@@ -220,7 +220,7 @@
}
};
var _newMicroserviceCallConfigUI = function (config = {}) {
var _newMicroserviceUI_configUI = function (config = {}) {
config.mscEndpoint = config.mscEndpoint || '';
config.microserviceId = config.microserviceId || '';
config.operationId = config.operationId || '';
......@@ -242,8 +242,8 @@
};
var _sub = {
codeEditor: newCodeEditor({}),
inputTable: newMSInputTable({
codeEditor: newCodeEditorUI({}),
inputTable: newMSInputTableUI({
mscEndpoint: config.mscEndpoint,
microserviceId: config.microserviceId,
operationId: config.operationId,
......@@ -278,6 +278,6 @@
};
};
OliveUI.modules.newMicroserviceCallConfigUI = _newMicroserviceCallConfigUI;
OliveUI.modules.newMicroserviceUI_configUI = _newMicroserviceUI_configUI;
}(OliveUI, OliveUI.utils, OliveUI.modules.newCodeEditor));
}(OliveUI, OliveUI.utils, OliveUI.modules.newCodeEditorUI));
......@@ -96,7 +96,7 @@
}
};
var _newWidgetView = function (config = {}) {
var _newWidgetUI = function (config = {}) {
config.initialView = config.initialView || 'render'; //render or config
config.removeBtnClickFn = config.removeBtnClickFn || null;
config.refreshBtnVisible = config.refreshBtnVisible != null ? config.refreshBtnVisible : true;
......@@ -175,6 +175,6 @@
};
};
OliveUI.modules.newWidgetView = _newWidgetView;
OliveUI.modules.newWidgetUI = _newWidgetUI;
}(OliveUI, OliveUI.utils));
(function (OliveUI, newMicroserviceUI, newMicroserviceUI_configUI) {
'use strict';
var config = {
mscEndpoint: 'https://www.adoxx.org/micro-service-controller-rest/rest/',
microserviceId: '1738cb62-cc55-4abf-8560-feafdb83260c',
operationId: 'default'
};
OliveUI.addWidgetManifest({
name: 'Microservice UI',
description: '',
createUIFn: function () {
return newMicroserviceUI({
mscEndpoint: config.mscEndpoint
});
},
createConfigurationUIFn: function () {
return newMicroserviceUI_configUI({
mscEndpoint: config.mscEndpoint,
microserviceId: config.microserviceId,
operationId: config.operationId,
forceStartWhenStopped: true,
showServiceNameTxt: true
});
},
configurationMappingFn: function (widget, configurationUIOutputConfig, viewUIInputConfig) {
if (!configurationUIOutputConfig.microserviceInputs) throw 'Widget not configured';
Object.assign(viewUIInputConfig, {
microserviceId: config.microserviceId,
operationId: config.operationId,
microserviceInputJSON: JSON.stringify(configurationUIOutputConfig.microserviceInputs),
microserviceOutputAdaptAlg: configurationUIOutputConfig.microserviceOutputAdaptAlg,
});
if (configurationUIOutputConfig.serviceName)
widget.setWidgetTitle(configurationUIOutputConfig.serviceName);
}
});
}(OliveUI, OliveUI.modules.newMicroserviceUI, OliveUI.modules.newMicroserviceUI_configUI));
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