Commit 4d51a021 authored by damianofalcioni's avatar damianofalcioni

improved OliveUI.js

parent c2dacf51
......@@ -3,12 +3,6 @@
}(typeof window !== "undefined" ? window : this, function ($) {
'use strict';
if (typeof $.fn.popover != 'function') throw 'Bootstrap Required';
/*
oltre al contenuto ogni widget ha una configurazione richiesta durante l'istanziazione. Come la gestisco?
- e se non metto il set content ma fo tutto tramite la configurazione iniziale?
getState e setState che debbono ritornare ed impostare la configurazione totale del widget
*/
var _statics = {
createWidgetInstance: function (widgetName, _dom, _state) {
......@@ -16,18 +10,20 @@
if (!widgetManifest) throw 'Impossible to find the manifest of the widget ' + widgetName;
if (!OliveUI.modules.newWidgetUI) throw 'Missing newWidgetUI module';
var uuid = OliveUI.utils.generateUUID();
var widgetRootDiv = $('<div>');
var widget = OliveUI.modules.newWidgetUI({
initialView: 'render',
removeBtnClickFn: function () {
widgetRootDiv.remove();
//TODO: remove widget from instances
delete _state.widgetInstances[uuid];
},
renderModule: widgetManifest.createUIFn(),
configModule: widgetManifest.createConfigurationUIFn ? widgetManifest.createConfigurationUIFn() : null,
mappingFn: widgetManifest.configurationMappingFn ? function(configOutput, renderInput) {
widgetManifest.configurationMappingFn(widget, configOutput, renderInput);
mappingFn: widgetManifest.configurationMappingFn ? function (configOutput, renderInput) {
widgetManifest.configurationMappingFn(widget, configOutput, renderInput);
} : null
});
......@@ -36,8 +32,28 @@
widget.render()
)
);
//TODO: add widget to instances
}
_state.widgetInstances[uuid] = {
widgetName: widgetName,
widget: widget,
widgetRootDiv: widgetRootDiv
};
return uuid;
},
getWidgetInstanceConfiguration: function (widgetUUID, _state) {
var widgetState = _state.widgetInstances[widgetUUID];
if (!widgetState) throw 'Impossible to find the widget instance ' + widgetUUID;
return widgetState.widget.getContent();
},
setWidgetInstanceConfiguration: function (widgetUUID, widgetContent, _state) {
var widgetState = _state.widgetInstances[widgetUUID];
if (!widgetState) throw 'Impossible to find the widget instance ' + widgetUUID;
widgetState.widget.setContent(widgetContent);
},
};
var OliveUI = function (config = {}) {
......@@ -55,7 +71,15 @@
return _dom.rootDiv;
},
createWidgetInstance: function (widgetName) {
_statics.createWidgetInstance(widgetName, _dom, _state);
return _statics.createWidgetInstance(widgetName, _dom, _state);
},
getWidgetInstanceConfiguration: function (widgetUUID) {
return _statics.getWidgetInstanceConfiguration(widgetUUID, _state);
},
setWidgetInstanceConfiguration: function (widgetUUID, widgetContent) {
_statics.setWidgetInstanceConfiguration(widgetUUID, widgetContent, _state);
}
};
};
......@@ -65,6 +89,7 @@
OliveUI.addWidgetManifest = function (widgetManifest) {
if (!widgetManifest.name) throw 'name missing in widget manifest';
//TODO: complete manifest check
OliveUI.widgetsManifests[widgetManifest.name] = widgetManifest;
};
......@@ -245,7 +270,7 @@
return JSON.parse(JSON.stringify(obj));
},
isStyled: function(className) {
isStyled: function (className) {
var re = new RegExp('(^|,)\\s*\\.' + className + '\\s*(\\,|$)');
var ret = false;
$.each(document.styleSheets, function () {
......@@ -262,4 +287,3 @@
return OliveUI;
}));
......@@ -8,11 +8,10 @@
oliveUI.render()
);
oliveUI.createWidgetInstance('Microservice UI');
oliveUI.createWidgetInstance('Microservice UI');
/*
widget.getConfig().configModule.refresh();
widget.setContent({
var widget1 = oliveUI.createWidgetInstance('Microservice UI');
var widget2 = oliveUI.createWidgetInstance('Microservice UI');
oliveUI.setWidgetInstanceConfiguration(widget1, {
microserviceInputs: {
'Append Text': {
value: 'World'
......@@ -21,5 +20,15 @@
microserviceOutputAdaptAlg: '',
serviceName: 'Test 1'
});
*/
oliveUI.setWidgetInstanceConfiguration(widget2, {
microserviceInputs: {
'Append Text': {
value: 'World'
}
},
microserviceOutputAdaptAlg: 'return output.dataText;',
serviceName: 'Test 2'
});
}(OliveUI));
......@@ -39,6 +39,7 @@
if (configurationUIOutputConfig.serviceName)
widget.setWidgetTitle(configurationUIOutputConfig.serviceName);
}
//TODO: add uiCustomRenderFn configUiCustomRenderFn uiCustomGetState...
});
}(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