var Dashboard = { datasourceUpdatingIntervallInSeconds : 5*60, preferredLang : null, widgetFileToLoadList : ['tablechart', 'overviewpanel', 'overviewtable', 'overviewtabledetailed', 'imageMap', 'cartesianCharts'], setLang : function(lang){ switch(lang){ case 'en': this.preferredLang = 'en'; break; case 'de': this.preferredLang = 'de'; break; case 'es': this.preferredLang = 'es'; break; case 'pl': this.preferredLang = 'pl'; break; default : this.preferredLang = 'en'; break; } }, hideHeaderMenu : function(){ $('#mainPanel').removeClass('panel-primary'); $('#mainPanelHeader').hide(); }, addWidget : function(widget){ if (typeof widget !== 'object') throw 'the widget is not a valid object'; if(typeof widget.getId !== 'function') throw 'function getId not present'; if(typeof widget.getName !== 'function') throw 'function getName not present'; if(typeof widget.getDescription !== 'function') throw 'function getDescription not present'; if(typeof widget.getIconClass !== 'function') throw 'function getIconClass not present'; if(typeof widget.createContent !== 'function') throw 'function createContent not present'; if(typeof widget.getConfiguration !== 'function') throw 'function getConfiguration not present'; if(typeof widget.getPreferredSize !== 'function') throw 'function preferredSize not present'; if(typeof widget.createConfiguration !== 'function' && widget.createConfiguration != null) throw 'createConfiguration, when specified, must be a function'; widget = Object.assign(widget, { getDescriptionInLang : function(){ if(Dashboard.preferredLang === null) throw 'preferredLang is null'; return this.getDescription()[Dashboard.preferredLang]; } }); this._internals._widgetSystem._widgetList.push(widget); }, evaluateKpi : function(widgetInstanceId, modelId, kpiId){ var currentWidgetInstanceId = widgetInstanceId; this._internals._filterSystem._updateWidgetInstanceFilterInfos(currentWidgetInstanceId, modelId, false, kpiId, null); var _calculateKpiRec = function(kpiInfoObj){ var kpiMeasure = null; var dataSourceOutput = null; if(kpiInfoObj.connectedDataSource != null){ this._internals._datasourceCacheSystem._updateCachedDatasourceList(currentWidgetInstanceId, kpiInfoObj.connectedDataSource); var cachedDatasource = this._internals._datasourceCacheSystem._getCachedDatasource(currentWidgetInstanceId, kpiInfoObj.connectedDataSource.id); dataSourceOutput = Utils.clone(cachedDatasource.lastObtainedValue); if(dataSourceOutput == null) throw 'Update the widget content'; if(dataSourceOutput.error != null){ throw 'Error occurred in the data source: '+dataSourceOutput.error; } } if(kpiInfoObj.connectedAlgorithm != null){ if(kpiInfoObj.connectedAlgorithm.code == null || kpiInfoObj.connectedAlgorithm.code == '' || kpiInfoObj.connectedAlgorithm.code.indexOf('return ') === -1) throw 'The algorithm with id ' + kpiInfoObj.connectedAlgorithm.id + ' must provide a javascript code with a return statement in the end'; var requiredKpiValueList = []; kpiInfoObj.requiredKpiList.forEach(function(requiredKpiInfo){ requiredKpiValueList.push({ id : requiredKpiInfo.id, name : requiredKpiInfo.name, description : requiredKpiInfo.description, fields : requiredKpiInfo.fields, value : _calculateKpiRec(requiredKpiInfo) }); }.bind(this)); try{ var fnInitCode = "function combine(fieldAggList=[]){var combineMethods={sum:function(field,rowNum){var sum=0;requiredKpiValueList.forEach(function(requiredKpiValue){sum+=requiredKpiValue.value.data.length>rowNum?Number(requiredKpiValue.value.data[rowNum][field]):0;});return sum;},avg:function(field,rowNum){var avg=0;requiredKpiValueList.forEach(function(requiredKpiValue){avg+=requiredKpiValue.value.data.length>rowNum?Number(requiredKpiValue.value.data[rowNum][field]):0;});return(avg/requiredKpiValueList.length);},min:function(field,rowNum){var min=null;requiredKpiValueList.forEach(function(requiredKpiValue){var val=requiredKpiValue.value.data.length>rowNum?Number(requiredKpiValue.value.data[rowNum][field]):null;min=min==null?val:val!=null&&valrowNum?Number(requiredKpiValue.value.data[rowNum][field]):null;max=max==null?val:val!=null&&val>max?val:max;});return max;}};var ret={columns:[],data:[],moreInfo:{}};var maxRow=requiredKpiValueList[0]?requiredKpiValueList[0].value.data.length:0;for(var rowNum=0;rowNum') .append($('
', {text : widgetSelected.getDescriptionInLang()}) .addClass('panel panel-primary panel-body')) .append(conf.nodeElement); return conf; }, _autoCreateConfigurationFor : function(widgetSelected, presetConfig){ //TODO return { nodeElement : null, okHandler : function(){} }; }, _initWidgetContent : function(widgetInstance){ var widget = this._findWidget(widgetInstance.widgetId); var widgetIntancePanel = this._initWidgetIntancePanel(widgetInstance); try{ widget.createContent(widgetInstance.widgetConfig, widgetInstance.id); }catch(e){ console.log('Widget "' + widget.getName() + '" content pre-creation returned an error: ' + e); } widgetIntancePanel.refresh(false); }, _findWidget : function(widgetId){ var widget = null; for(var i=0;i'), node : $('
'), setDisabled : function(isDisabled){ if(isDisabled === true) this.node.addClass('disabled'); else this.node.removeClass('disabled'); }, initPanel : function(){ if(widgetInstance.userInputList == null) widgetInstance.userInputList = {}; var _userInputMenu = function(){ var requiredCachedDatasourceWithInputList = []; Dashboard._internals._datasourceCacheSystem._datasourceDataCacheList.forEach(function(datasourceCached){ if(datasourceCached.usedByWidgetList.indexOf(widgetInstance.id) != -1) if(datasourceCached.userRequiredInputFieldList.length > 0) requiredCachedDatasourceWithInputList.push(datasourceCached); }); if(requiredCachedDatasourceWithInputList.length == 0) return null; var ulNode = $('