Blame view

js/app/views/StatisticsUI.js 28.1 KB
d18b535d   elena   catalog draft + c...
1
2
3
4
5
6
7
8
9
/**
 * Project       AMDA-NG
 * Name          StatisticsUI.js
 * @class 	 amdaUI.statisticsUI
 * @extends      Ext.container.Container
 * @brief	 Statistics Module UI definition (View)
 * @author 	 elena
 */

4ca3eeff   Hacene SI HADJ MOHAND   il reste plot et ...
10
11
12
13
14
15
Ext.define('amdaUI.StatisticsUI',
        {
            extend: 'Ext.container.Container',
            alias: 'widget.panelStatistics',

            requires: [
4ca3eeff   Hacene SI HADJ MOHAND   il reste plot et ...
16
17
                'amdaUI.TimeSelectorUI',
                'amdaUI.ParamArgumentsPlug',
533ea933   Benjamin Renard   Show description ...
18
                'amdaUI.DescriptionField',
2e7079bb   Benjamin Renard   First implementat...
19
		'amdaModel.StatisticParam'
4ca3eeff   Hacene SI HADJ MOHAND   il reste plot et ...
20
21
            ],

4ca3eeff   Hacene SI HADJ MOHAND   il reste plot et ...
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
            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);
f43a0a5e   Benjamin Renard   Fix save statisti...
38
39
		// set object's TTs into the timeselector
		this.timeSelector.setTTTab(this.object.get('timeTables'));
2e7079bb   Benjamin Renard   First implementat...
40
41
42
		// set parameters
		this.paramGrid.reconfigure(this.object.params());
            },
4ca3eeff   Hacene SI HADJ MOHAND   il reste plot et ...
43

2e7079bb   Benjamin Renard   First implementat...
44
45
46
            setObject: function (obj) {
                this.object = obj;
                this.loadObject();
4ca3eeff   Hacene SI HADJ MOHAND   il reste plot et ...
47
48
49
50
51
52
53
            },

            onApplyParameterArgs: function (parentUI, paramObject)
            {
                parentUI.paramGrid.getView().refresh();
            },

7f23e0f7   Erdogan Furkan   #5119 -Done. Adde...
54
            addParam: function (paramId, isLeaf, needArgs, components, predefined_args,info)
4ca3eeff   Hacene SI HADJ MOHAND   il reste plot et ...
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
            {
                // 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'];
                    }
                }

7f23e0f7   Erdogan Furkan   #5119 -Done. Adde...
72
73
74
75
                if(info){
                    paramObj.qtip= info;
                }

2e7079bb   Benjamin Renard   First implementat...
76
                var r = Ext.create('amdaModel.StatisticParam', paramObj);
4ca3eeff   Hacene SI HADJ MOHAND   il reste plot et ...
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
                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);
            },

2e7079bb   Benjamin Renard   First implementat...
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
            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+'<br/>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();
		}
            },

4ca3eeff   Hacene SI HADJ MOHAND   il reste plot et ...
177
178
179
180
181
182
183
184
            addTT: function (TTname, TTid)
            {
                this.timeSelector.addTT(TTname, TTid);
                ;
            },

            /**
             * Set Start-Stop from parameter info (Local & MyData)
79a60955   Hacene SI HADJ MOHAND   ms ok affichage ko
185
          
4ca3eeff   Hacene SI HADJ MOHAND   il reste plot et ...
186
187
188
189
            setTimeFromData: function (obj) {
                if (!obj.start || !obj.stop)
                    return;

79a60955   Hacene SI HADJ MOHAND   ms ok affichage ko
190
191
                //var dateStart = new Date(obj.start.replace(/[T|Z]/g, ' ').replace(/\-/g, '\/'));
                //var dateStop = new Date(obj.stop.replace(/[T|Z]/g, ' ').replace(/\-/g, '\/'));
4ca3eeff   Hacene SI HADJ MOHAND   il reste plot et ...
192

79a60955   Hacene SI HADJ MOHAND   ms ok affichage ko
193
194
195
                //this.formPanel.items.items[1].getForm().setValues({startDate: dateStart, stopDate: dateStop});
               // this.timeSelector.intervalSel.updateDuration();
            },   */
4ca3eeff   Hacene SI HADJ MOHAND   il reste plot et ...
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271

            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!'
                            + '<br>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({
2e7079bb   Benjamin Renard   First implementat...
272
                    fieldLabel: 'Request Name',
4ca3eeff   Hacene SI HADJ MOHAND   il reste plot et ...
273
274
275
276
277
278
279
280
281
282
283
284
285
                    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;
                    }
                });

4ca3eeff   Hacene SI HADJ MOHAND   il reste plot et ...
286
287
                this.timeSelector = new amdaUI.TimeSelectorUI({id: 'statisticsTimeSelector', flex: 1});

4ca3eeff   Hacene SI HADJ MOHAND   il reste plot et ...
288
289
290
291
292
293
                this.paramGrid = Ext.create('Ext.grid.Panel',
                        {
                            title: 'Select Parameter & Apply Function',
                            selType: 'rowmodel',
                            flex: 2,
                            //			height :250,
2e7079bb   Benjamin Renard   First implementat...
294
                            store: Ext.create('Ext.data.Store', {model: 'amdaModel.StatisticParam'}),
4ca3eeff   Hacene SI HADJ MOHAND   il reste plot et ...
295
296
297
298
299
300
301
302
303
                            columns: [
                                {xtype: 'rownumberer'},
                                {
                                    header: "Parameter Name",
                                    dataIndex: 'name',
                                    flex: 1,
                                    sortable: false,
                                    menuDisabled: true,
                                    renderer: function (val, meta, rec) {
7f23e0f7   Erdogan Furkan   #5119 -Done. Adde...
304
                                        meta.tdAttr = 'data-qtip="' + rec.data.qtip + '"';
4ca3eeff   Hacene SI HADJ MOHAND   il reste plot et ...
305
306
307
308
309
310
311
312
313
                                        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',
26afa3fd   Hacene SI HADJ MOHAND   ihm ok
314
                                                store: ['min', 'max', 'mean', 'RMS', 'median', 'variance', 'skewness', 'kurtosis',
6e0fdbf9   Hacene SI HADJ MOHAND   correcting middel...
315
                                                    'count', 'countNotNan', 'countTrue','firstValue','middleIntervalValue','lastValue'],
4ca3eeff   Hacene SI HADJ MOHAND   il reste plot et ...
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
                                                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 '<div class="icon-remover" style="width: 15px; height: 15px;"></div>';
                                    }
                                }
                            ],
                            plugins: [Ext.create('Ext.grid.plugin.CellEditing', {clicksToEdit: 1})],
                            listeners:
                                    {
                                        render: function (o, op)
                                        {
                                            var me = this;
                                            var el = me.body.dom;
                                            var dropTarget = Ext.create('Ext.dd.DropTarget', el, {
                                                ddGroup: 'explorerTree',
                                                notifyOver: function (ddSource, e, data)
                                                {
                                                    if (data.records[0].data.nodeType == 'localParam' && data.records[0].get('notyet')) {
                                                        this.valid = false;
                                                        return this.dropNotAllowed;
                                                    }
                                                    if (((data.records[0].data.nodeType == 'localParam') ||
                                                            (data.records[0].data.nodeType == 'remoteParam') ||
                                                            (data.records[0].data.nodeType == 'remoteSimuParam') ||
                                                            (data.records[0].data.nodeType == 'derivedParam') ||
98c92bbf   Erdogan Furkan   #10557 - Done (Ma...
356
                                                            (data.records[0].data.nodeType == 'specialParam') ||
4ca3eeff   Hacene SI HADJ MOHAND   il reste plot et ...
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
                                                            (data.records[0].data.nodeType == 'myDataParam') ||
                                                            (data.records[0].data.nodeType == 'alias')) &&
                                                            (data.records[0].isLeaf() || data.records[0].data.isParameter) &&
                                                            !data.records[0].data.disable)
                                                    {
                                                        this.valid = true;
                                                        return this.dropAllowed;
                                                    }

                                                    this.valid = false;
                                                    return this.dropNotAllowed;
                                                },
                                                notifyDrop: function (ddSource, e, data)
                                                {
                                                    if (!this.valid)
                                                        return false;
                                                    var nameToSent;
                                                    var components = null;
7f23e0f7   Erdogan Furkan   #5119 -Done. Adde...
375
                                                    var info = data.records[0].get('info');
4ca3eeff   Hacene SI HADJ MOHAND   il reste plot et ...
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447

                                                    switch (data.records[0].data.nodeType)
                                                    {
                                                        case 'localParam' :
                                                        case 'remoteParam':
                                                        case 'remoteSimuParam':
                                                            nameToSent = data.records[0].get('id');
                                                            if (data.records[0].get('alias') != "")
                                                                var nameToSent = "#" + data.records[0].get('alias');
                                                            var component_info = data.records[0].get('component_info');
                                                            if (component_info && component_info.parentId)
                                                            {
                                                                if (component_info.index1 && component_info.index2)
                                                                {
                                                                    nameToSent = component_info.parentId;
                                                                    components = [];
                                                                    if (component_info.index1)
                                                                        components['index1'] = component_info.index1;
                                                                    if (component_info.index2)
                                                                        components['index2'] = component_info.index2;
                                                                }
                                                                if (data.records[0].get('needsArgs'))
                                                                {
                                                                    nameToSent = component_info.parentId;
                                                                    if (component_info.index1)
                                                                    {
                                                                        components = [];
                                                                        components['index1'] = component_info.index1;
                                                                    }
                                                                }
                                                            }
                                                            break;
                                                        case 'alias' :
                                                            nameToSent = "#" + data.records[0].get('text');
                                                            break;
                                                        case 'derivedParam' :
                                                            if (data.records[0].modelName == 'amdaModel.DerivedParamComponentNode')
                                                            {
                                                                paramId = data.records[0].get('text');
                                                                var parentId = paramId.substr(0, paramId.length - 3);
                                                                nameToSent = "ws_" + parentId;
                                                                var regExp = /\(([\d]+)\)/;
                                                                var component_index = regExp.exec(paramId);
                                                                if (component_index)
                                                                {
                                                                    components = [];
                                                                    components['index1'] = component_index[1];
                                                                }
                                                                break;
                                                            } else
                                                            {
                                                                nameToSent = "ws_" + data.records[0].get('text');
                                                            }
                                                            break;
                                                        case 'myDataParam' :
                                                              if (data.records[0].modelName == 'amdaModel.MyDataParamComponentNode')
                                                            {
                                                                paramId = data.records[0].get('text');
                                                                var parentId = paramId.substr(0, paramId.length - 3);
                                                                nameToSent = "wsd_" + parentId;
                                                                var regExp = /\(([\d]+)\)/;
                                                                var component_index = regExp.exec(paramId);
                                                                if (component_index)
                                                                {
                                                                    components = [];
                                                                    components['index1'] = component_index[1];
                                                                }
                                                                break;
                                                            } else{
                                                            nameToSent = "wsd_" + data.records[0].get('text');
                                                        }
                                                            break;
98c92bbf   Erdogan Furkan   #10557 - Done (Ma...
448
449
450
                                                        case 'specialParam':
                                                            nameToSent = data.records[0].get('id');
                                                            break;
4ca3eeff   Hacene SI HADJ MOHAND   il reste plot et ...
451
452
453
454
455
456
                                                        default :
                                                            return false;
                                                    }
                                                    var module = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.statistics.id);
                                                    if (module)
                                                    {
b1fab76f   Benjamin Renard   Give the possibil...
457
458
							if (data.records[0].get('predefinedArgs')) {
								module.parseTemplatedParam(nameToSent, function(param_info) {
7f23e0f7   Erdogan Furkan   #5119 -Done. Adde...
459
									module.addParam(param_info.paramid, data.records[0].get('leaf'), true, components, param_info.template_args, info);
b1fab76f   Benjamin Renard   Give the possibil...
460
461
462
								});
							}
							else {
7f23e0f7   Erdogan Furkan   #5119 -Done. Adde...
463
                                module.addParam(nameToSent, data.records[0].get('leaf'), data.records[0].get('needsArgs'), components,null,info);
b1fab76f   Benjamin Renard   Give the possibil...
464
							}
4ca3eeff   Hacene SI HADJ MOHAND   il reste plot et ...
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
                                                    }
                                                    return true;
                                                }
                                            });
                                        },
                                        cellclick: function (grid, cell, cellIndex, record) {
                                            if (cellIndex == 3)
                                                grid.getStore().remove(record);
                                        }
                                    }
                        });


                this.formPanel = Ext.create('Ext.form.Panel',
                        {
                            region: 'center',
                            layout: {
                                type: 'hbox',
                                pack: 'start',
                                align: 'stretch'
                            },
                            defaults: {bodyStyle: {background: '#dfe8f6'}, padding: '3'},
                            fieldDefaults: {labelWidth: 80, labelAlign: 'top'},
                            items: [{
                                    xtype: 'form',
                                    flex: 1,
                                    layout: {type: 'vbox', pack: 'start', align: 'stretch'},
                                    items: [this.paramGrid],
                                    fbar: [{
                                            type: 'button',
2e7079bb   Benjamin Renard   First implementat...
495
                                            text: 'Generate',
4ca3eeff   Hacene SI HADJ MOHAND   il reste plot et ...
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
                                            scope: this,
                                            handler: function ()
                                            {
                                                // update object with user's values
                                                // if the return is true (object had been updated)
                                                if (this.updateObject()) {
                                                    this.generateCatalog();
                                                }
                                            }
                                        },
                                        {
                                            type: 'button',
                                            text: 'Reset',
                                            scope: this,
                                            handler: function () {
                                                this.formPanel.getForm().reset();
                                                this.paramGrid.store.removeAll();
                                                this.timeSelector.TTGrid.store.removeAll();
                                            }
2e7079bb   Benjamin Renard   First implementat...
515
516
517
518
519
520
521
522
523
524
                                        },
                                        {
                                            text: 'Save',
                                            id: 'save-statistic',
                                            scope: this,
                                            handler: function () {
                                                this.saveRequest();
                                            }
                                        }
                                    ]
4ca3eeff   Hacene SI HADJ MOHAND   il reste plot et ...
525
526
527
528
529
530
531
532
533
534
                                },
                                {
                                    xtype: 'form',
                                    title: 'Additional Information',
                                    flex: 1,
                                    trackResetOnLoad: true,
                                    layout: {type: 'vbox', pack: 'start', align: 'stretch', padding: '3'},
                                    items: [
                                        this.fieldName,
                                        {
533ea933   Benjamin Renard   Show description ...
535
                                            xtype: 'descriptionfield',
4ca3eeff   Hacene SI HADJ MOHAND   il reste plot et ...
536
                                            name: 'description',
4ca3eeff   Hacene SI HADJ MOHAND   il reste plot et ...
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
                                            height: 125
                                        },
                                        this.timeSelector
                                    ]
                                }
                            ]
                        });

                var myConf = {
                    layout: 'border',
                    items: [
                        this.formPanel,
                        {
                            xtype: 'panel',
                            region: 'south',
                            title: 'Information',
                            collapsible: true,
                            collapseMode: 'header',
                            height: 160,
                            autoHide: false,
                            bodyStyle: 'padding:5px',
                            iconCls: 'icon-information',
                            loader: {
                                autoLoad: true,
                                url: helpDir + 'statisticsHOWTO'
                            }
                        }],
                    plugins: [{ptype: 'paramArgumentsPlugin', pluginId: 'statistics-param-arguments-plugin'}]
                };

                Ext.apply(this, Ext.apply(arguments, myConf));
            }
        });