/**
* Project AMDA-NG
* Name StatisticsUI.js
* @class amdaUI.statisticsUI
* @extends Ext.container.Container
* @brief Statistics Module UI definition (View)
* @author elena
*/
Ext.define('amdaUI.StatisticsUI',
{
extend: 'Ext.container.Container',
alias: 'widget.panelStatistics',
requires: [
'amdaUI.TimeSelectorUI',
'amdaUI.ParamArgumentsPlug',
'amdaModel.StatisticParam'
],
constructor: function (config)
{
this.init(config);
this.callParent(arguments);
this.loadObject();
var paramArgsPlug = this.getPlugin('statistics-param-arguments-plugin');
if (paramArgsPlug)
paramArgsPlug.onApply = this.onApplyParameterArgs;
},
loadObject: function ()
{
// load object into form
var basicForm = this.formPanel.items.items[1].getForm();
basicForm.loadRecord(this.object);
// set object's TTs into the timeselector
this.timeSelector.setTTTab(this.object.get('timeTables'));
// set parameters
this.paramGrid.reconfigure(this.object.params());
},
setObject: function (obj) {
this.object = obj;
this.loadObject();
},
onApplyParameterArgs: function (parentUI, paramObject)
{
parentUI.paramGrid.getView().refresh();
},
addParam: function (paramId, isLeaf, needArgs, components, predefined_args,info)
{
// adding the parameter to the paramGrid
var paramObj = amdaModel.RequestParamObject.getEmptyObj();
paramObj.paramid = paramId;
if (components) {
if (components['index1']) {
paramObj['dim1-index'] = components['index1'];
++paramObj['type'];
}
if (components['index2']) {
paramObj['dim2-index'] = components['index2'];
++paramObj['type'];
}
}
if(info){
paramObj.qtip= info;
}
var r = Ext.create('amdaModel.StatisticParam', paramObj);
this.paramGrid.getStore().add(r);
this.paramGrid.getSelectionModel().select(this.paramGrid.getStore().getCount() - 1);
// var pos = this.paramGrid.store.getCount();
// this.paramGrid.store.insert(pos,r);
this.paramGrid.getView().refresh();
if (needArgs)
this.editParameterArgs(r);
},
editParameterArgs: function (record)
{
var paramArgsPlug = this.getPlugin('statistics-param-arguments-plugin');
if (paramArgsPlug)
paramArgsPlug.show('statistics-param-arguments-plugin', record);
},
saveRequest : function()
{
var me = this;
if (!this.updateObject()) {
return;
}
var statisticModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.statistics.id);
if ((this.object.get('id') != '') && (statisticModule.linkedNode.get('text') == this.object.get('name'))) {
this.saveProcess(false);
return;
}
statisticModule.linkedNode.isValidName(this.fieldName.getValue(), function (res) {
if (!res)
{
me.fieldName.validFlag = 'Error during object validation';
myDesktopApp.errorMsg(me.fieldName.validFlag);
me.fieldName.validate();
return;
}
if (!res.valid)
{
if (res.error)
{
if (res.error.search('subtree') != -1) {
Ext.MessageBox.show({title:'Warning',
msg: res.error+'
Do you want to overwrite it?',
width: 300,
buttons: Ext.MessageBox.OKCANCEL,
fn : function(btn) {
if (btn == 'cancel') return;
this.fieldName.clearInvalid();
this.saveProcess(true);
},
icon: Ext.MessageBox.WARNING,
scope : me
});
me.fieldName.validFlag = true;
}
else
me.fieldName.validFlag = res.error;
}
else
{
me.fieldName.validFlag = 'Invalid object name';
myDesktopApp.errorMsg(me.fieldName.validFlag);
}
me.fieldName.validate();
return;
}
me.fieldName.validFlag = true;
me.fieldName.validate();
me.saveProcess(false);
});
},
saveProcess: function(toRename) {
var statisticModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.statistics.id);
if (this.object.isModified('name')) {
if (this.object.get('id'))
{
var contextNode = statisticModule.linkedNode.parentNode;
statisticModule.createLinkedNode();
statisticModule.linkedNode.set('contextNode',contextNode);
statisticModule.createObject(this.object.getJsonValues());
var statisticObj = statisticModule.linkedNode.get('object');
this.object = statisticObj;
if (toRename) statisticModule.linkedNode.toRename = true;
}
statisticModule.linkedNode.create();
}
else {
statisticModule.linkedNode.set('contextNode',statisticModule.contextNode);
statisticModule.linkedNode.update();
}
},
addTT: function (TTname, TTid)
{
this.timeSelector.addTT(TTname, TTid);
;
},
/**
* Set Start-Stop from parameter info (Local & MyData)
setTimeFromData: function (obj) {
if (!obj.start || !obj.stop)
return;
//var dateStart = new Date(obj.start.replace(/[T|Z]/g, ' ').replace(/\-/g, '\/'));
//var dateStop = new Date(obj.stop.replace(/[T|Z]/g, ' ').replace(/\-/g, '\/'));
//this.formPanel.items.items[1].getForm().setValues({startDate: dateStart, stopDate: dateStop});
// this.timeSelector.intervalSel.updateDuration();
}, */
generateCatalog: function ()
{
var module = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.statistics.id);
if (module)
module.linkedNode.execute();
},
/*
* Update this.object from form
*/
updateObject: function ()
{
// get the basic form of the left
var basicForm = this.formPanel.items.items[1].getForm();
var updateStatus = true;
var formValues = basicForm.getValues();
this.object.set('name', this.fieldName.getValue());
this.object.set('description', formValues.description);
var recs = this.paramGrid.getStore().getNewRecords();
var paramArr = new Array();
Ext.Array.each(recs, function (rec, index, allItems)
{
var obj = Ext.clone(rec.data);
if (obj.function == null)
{
myDesktopApp.warningMsg('Please select function : `click to select`');
updateStatus = false;
return;
}
paramArr.push(obj);
});
this.object.set('parameter', paramArr);
var timeSource = this.timeSelector.getActiveTimeSource();
if (timeSource === amdaModel.AmdaTimeObject.inputTimeSrc[0] // timeSource 'TimeTable'
&& this.timeSelector.TTGrid.getStore().count() == 0)
{
myDesktopApp.warningMsg('You\'ve chosen Time Selection `by TimeTable` but no timeTable was added!'
+ '
You must add one or choose Time Selection `by Interval`');
return false;
}
basicForm.updateRecord(this.object);
this.object.set('timesrc', timeSource);
// set valid intervals into TimeTable object
if (timeSource === amdaModel.AmdaTimeObject.inputTimeSrc[0])
this.object.set('timeTables', this.timeSelector.TTGrid.getStore().data.items);
return updateStatus;
},
/**
* Check if changes were made before closing window
* @return true if changes
*/
fclose: function ()
{
if (this.status == null)
return false;
var isDirty = this.formPanel.getForm().isDirty() || (this.status.isModified) || (this.status.nbModified > 0) || (this.status.nbNew > 0);
return isDirty;
},
/**
* View configuration
*/
init: function (config)
{
this.fieldName = new Ext.form.field.Text({
fieldLabel: 'Request Name',
allowBlank: false,
stripCharsRe: /(^\s+|\s+$)/g,
emptyText: 'Please no spaces!',
name: 'name',
// anchor: '100%',
validateOnChange: false,
validateOnBlur: false,
validFlag: false,
validator: function () {
return this.validFlag;
}
});
this.timeSelector = new amdaUI.TimeSelectorUI({id: 'statisticsTimeSelector', flex: 1});
this.paramGrid = Ext.create('Ext.grid.Panel',
{
title: 'Select Parameter & Apply Function',
selType: 'rowmodel',
flex: 2,
// height :250,
store: Ext.create('Ext.data.Store', {model: 'amdaModel.StatisticParam'}),
columns: [
{xtype: 'rownumberer'},
{
header: "Parameter Name",
dataIndex: 'name',
flex: 1,
sortable: false,
menuDisabled: true,
renderer: function (val, meta, rec) {
meta.tdAttr = 'data-qtip="' + rec.data.qtip + '"';
return rec.getParamFullName();
}
},
// { header: 'parameter', dataIndex: 'name', menuDisabled : true, sortable : false },
{header: 'function', dataIndex: 'function', menuDisabled: true, sortable: false,
editor:
{
xtype: 'combo', queryMode: 'local',
//emptyText : 'please click to select function',
store: ['min', 'max', 'mean', 'RMS', 'median', 'variance', 'skewness', 'kurtosis',
'count', 'countNotNan', 'countTrue','firstValue','middleIntervalValue','lastValue'],
triggerAction: 'all',
//lazyInit: false,
listeners: {
focus: function (obj) {
obj.expand();
}
}
},
renderer: function (v)
{
if (v != null && v.length > 0)
return v;
else
return 'click to select';
}
},
{menuDisabled: true, width: 30, renderer: function () {
return '