Blame view

js/app/views/StatisticsUI.js 16.3 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
 */

23769849   Elena.Budnik   LoadObject in Sta...
10
11
Ext.define('amdaUI.StatisticsUI', 
{
d18b535d   elena   catalog draft + c...
12
13
14
15
	extend: 'Ext.container.Container',
	alias: 'widget.panelStatistics',
	
	requires : [	
23769849   Elena.Budnik   LoadObject in Sta...
16
			//'amdaModel.Function'
d80af896   Elena.Budnik   args for Statistics
17
18
19
			'amdaUI.TimeSelectorUI',
			'amdaUI.ParamArgumentsPlug',
			'amdaModel.DownloadParam'
d18b535d   elena   catalog draft + c...
20
21
	],
	
23769849   Elena.Budnik   LoadObject in Sta...
22
23
	statics : 
	{	 
d80af896   Elena.Budnik   args for Statistics
24
	//	  functionStore : null
d18b535d   elena   catalog draft + c...
25
26
	},
		
3ab0bee9   Elena.Budnik   aprams with args ...
27
28
	constructor: function(config) 
	{
d80af896   Elena.Budnik   args for Statistics
29
		this.init(config); 
d18b535d   elena   catalog draft + c...
30
		this.callParent(arguments);
23769849   Elena.Budnik   LoadObject in Sta...
31
32
		this.loadObject();
				 
d80af896   Elena.Budnik   args for Statistics
33
34
35
		var paramArgsPlug = this.getPlugin('statistics-param-arguments-plugin');
		if (paramArgsPlug)
			paramArgsPlug.onApply = this.onApplyParameterArgs;
d18b535d   elena   catalog draft + c...
36
	},
23769849   Elena.Budnik   LoadObject in Sta...
37
38
39
40
	
	loadObject : function()
	{
		// load object into form	
7348b580   Elena.Budnik   redmine #6010 : S...
41
		var basicForm = this.formPanel.items.items[1].getForm();
23769849   Elena.Budnik   LoadObject in Sta...
42
43
44
45
		basicForm.loadRecord(this.object);
		
	},
	
3ab0bee9   Elena.Budnik   aprams with args ...
46
47
	onApplyParameterArgs : function(parentUI, paramObject) 
	{
d80af896   Elena.Budnik   args for Statistics
48
49
		parentUI.paramGrid.getView().refresh();
	}, 
d18b535d   elena   catalog draft + c...
50
	
d80af896   Elena.Budnik   args for Statistics
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
	addParam : function(paramId, isLeaf, needArgs, components) 
	{
		// adding the parameter to the  paramGrid	
		var paramObj = {
			paramid: paramId,
			type: 0,
			'dim1-is-range': false,
			'dim1-min-range': 0.,
			'dim1-max-range': 0.,
			'dim1-index': '*',
			'dim2-is-range': false,
			'dim2-min-range': 0.,
			'dim2-max-range': 0.,
			'dim2-index': '*',
			template_args: {}
		};
        	
96cdc664   Elena.Budnik   new record type i...
68
69
		if (components) {
			if (components['index1']) {
3ab0bee9   Elena.Budnik   aprams with args ...
70
				paramObj['dim1-index'] = components['index1'];
96cdc664   Elena.Budnik   new record type i...
71
72
73
74
				++paramObj['type'];
			}
			
			if (components['index2']) {
3ab0bee9   Elena.Budnik   aprams with args ...
75
				paramObj['dim2-index'] = components['index2'];
96cdc664   Elena.Budnik   new record type i...
76
77
78
				++paramObj['type'];
			}
		}
d80af896   Elena.Budnik   args for Statistics
79
        	
96cdc664   Elena.Budnik   new record type i...
80
		var r = Ext.create('amdaModel.DownloadParam', paramObj);		
d80af896   Elena.Budnik   args for Statistics
81
		this.paramGrid.getStore().add(r);
23769849   Elena.Budnik   LoadObject in Sta...
82
		this.paramGrid.getSelectionModel().select(this.paramGrid.getStore().getCount()-1);  
d80af896   Elena.Budnik   args for Statistics
83
84
85
86
87
88
89
90
	//	var pos = this.paramGrid.store.getCount();
	//	this.paramGrid.store.insert(pos,r); 
		this.paramGrid.getView().refresh();
		
		if (needArgs)
			this.editParameterArgs(r);
	},

23769849   Elena.Budnik   LoadObject in Sta...
91
92
	editParameterArgs: function(record) 
	{
d80af896   Elena.Budnik   args for Statistics
93
94
95
96
97
		var paramArgsPlug = this.getPlugin('statistics-param-arguments-plugin');
		
		if (paramArgsPlug)
			paramArgsPlug.show('statistics-param-arguments-plugin', record);
	},
d18b535d   elena   catalog draft + c...
98
99
100
	
	addTT : function(TTname,TTid)
	{ 
23769849   Elena.Budnik   LoadObject in Sta...
101
		this.timeSelector.addTT(TTname, TTid); ; 	 
d18b535d   elena   catalog draft + c...
102
	},
7348b580   Elena.Budnik   redmine #6010 : S...
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
	
	/**
	* 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();
	}, 
	
23769849   Elena.Budnik   LoadObject in Sta...
118
119
120
121
122
	generateCatalog : function()
	{	     
		var module = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.statistics.id);
		if (module) 
			module.linkedNode.execute();	     
d18b535d   elena   catalog draft + c...
123
124
	},
	
23769849   Elena.Budnik   LoadObject in Sta...
125
126
127
128
129
/*
* Update this.object from form
*/	
	updateObject : function()
	{    
96cdc664   Elena.Budnik   new record type i...
130
		// get the basic form of the left 
d80af896   Elena.Budnik   args for Statistics
131
132
133
134
		var basicForm = this.formPanel.items.items[0].getForm();
		var updateStatus = true;
		
		var formValues = basicForm.getValues();
804b5599   Elena.Budnik   catalog name
135
		this.object.set('name',this.fieldName.getValue());
23769849   Elena.Budnik   LoadObject in Sta...
136
		this.object.set('description',formValues.description);
94a05aa2   Elena.Budnik   update object in ...
137
     	    	    
d80af896   Elena.Budnik   args for Statistics
138
139
140
		var recs = this.paramGrid.getStore().getNewRecords();
		var paramArr = new Array();
		
96cdc664   Elena.Budnik   new record type i...
141
		Ext.Array.each(recs, function(rec, index, allItems)
3ab0bee9   Elena.Budnik   aprams with args ...
142
143
144
		{			 			
			var obj = Ext.clone(rec.data);
			 
d80af896   Elena.Budnik   args for Statistics
145
146
147
148
149
150
151
152
			if (obj.function == null) 
			{				
				myDesktopApp.warningMsg('Please select function : `click to select`'); 
				updateStatus = false;
				return;                     
			}
			paramArr.push(obj);            	      
		});
94a05aa2   Elena.Budnik   update object in ...
153
	    
d80af896   Elena.Budnik   args for Statistics
154
		this.object.set('parameter', paramArr);
d18b535d   elena   catalog draft + c...
155
	    
d80af896   Elena.Budnik   args for Statistics
156
		var timeSource = this.timeSelector.getActiveTimeSource(); 
94a05aa2   Elena.Budnik   update object in ...
157
 
d80af896   Elena.Budnik   args for Statistics
158
159
160
161
162
163
164
		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;    
		}
d18b535d   elena   catalog draft + c...
165
             
d80af896   Elena.Budnik   args for Statistics
166
		basicForm.updateRecord(this.object);
94a05aa2   Elena.Budnik   update object in ...
167
	    
d80af896   Elena.Budnik   args for Statistics
168
169
170
171
		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);          
96cdc664   Elena.Budnik   new record type i...
172
	 	      
d80af896   Elena.Budnik   args for Statistics
173
		return updateStatus;	    
d18b535d   elena   catalog draft + c...
174
175
176
177
178
179
	},
	
	/**
	 * Check if changes were made before closing window 
	 * @return true if changes
	 */	
23769849   Elena.Budnik   LoadObject in Sta...
180
181
	fclose : function() 
	{
d18b535d   elena   catalog draft + c...
182
183
184
185
186
187
188
189
190
191
		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
	 */
23769849   Elena.Budnik   LoadObject in Sta...
192
193
	init : function (config) 
	{	  
d18b535d   elena   catalog draft + c...
194
195
196
197
198
199
200
201
202
// 	  var functions = Ext.create('Ext.data.Store', {
// 	    fields: ['id', 'name'],
// 	    data : [
// 		{"id":"min", "name":"MIN"},
// 		{"id":"max", "name":"MAX"},
// 		{"id":"mean","name":"MEAN"}        
// 	    ]
// 	    });
	     
d80af896   Elena.Budnik   args for Statistics
203
204
205
206
207
208
209
210
211
212
213
214
215
216
		this.fieldName = new Ext.form.field.Text({
				fieldLabel: 'Catalog 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;
			}
		});
d18b535d   elena   catalog draft + c...
217
	  
d80af896   Elena.Budnik   args for Statistics
218
219
220
221
222
		var ttStore = Ext.create('Ext.data.Store', 
		{
			fields: [ 'name', 'hidden_id']	
		});
		
7348b580   Elena.Budnik   redmine #6010 : S...
223
		this.timeSelector = new amdaUI.TimeSelectorUI({id: 'statisticsTimeSelector', flex:1}); 
d18b535d   elena   catalog draft + c...
224
	
d80af896   Elena.Budnik   args for Statistics
225
226
227
228
		var store = Ext.create('Ext.data.Store', 
			{
					fields: ['name', 'function'] 
			});
d18b535d   elena   catalog draft + c...
229
	
23769849   Elena.Budnik   LoadObject in Sta...
230
		this.paramGrid = Ext.create('Ext.grid.Panel', 
d80af896   Elena.Budnik   args for Statistics
231
			{ 
23769849   Elena.Budnik   LoadObject in Sta...
232
233
				title: 'Select Parameter & Apply Function',
				selType : 'rowmodel',
7348b580   Elena.Budnik   redmine #6010 : S...
234
235
				flex: 2,
	//			height :250,
23769849   Elena.Budnik   LoadObject in Sta...
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
272
273
				store : store, 
				columns: [
					{ xtype: 'rownumberer' },
					{ 
						header: "Parameter Name", 
						dataIndex: 'name', 
						flex:1, 
						sortable: false, 
						menuDisabled : true ,
						renderer: function (val, meta, rec) {
							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' ],
							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>';
d80af896   Elena.Budnik   args for Statistics
274
275
						}
					}
23769849   Elena.Budnik   LoadObject in Sta...
276
277
278
				], 
				plugins: [ Ext.create('Ext.grid.plugin.CellEditing', { clicksToEdit: 1 })],
				listeners :
d80af896   Elena.Budnik   args for Statistics
279
				{
23769849   Elena.Budnik   LoadObject in Sta...
280
					render : function(o,op)
3ab0bee9   Elena.Budnik   aprams with args ...
281
					{
23769849   Elena.Budnik   LoadObject in Sta...
282
283
284
285
286
287
288
289
290
						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;   
3ab0bee9   Elena.Budnik   aprams with args ...
291
								}	
23769849   Elena.Budnik   LoadObject in Sta...
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
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
								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') || 
											(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;
						
								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' :
0cefcae2   Benjamin Renard   il reste click droit
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
                                                                                                                                                                        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;
23769849   Elena.Budnik   LoadObject in Sta...
368
369
370
371
372
373
374
375
376
377
378
379
									case 'myDataParam' :
										nameToSent = "wsd_"+data.records[0].get('text');
										break;
									default :
										return false;
								}
								var module = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.statistics.id);
								if (module)
								{			     
									module.addParam(nameToSent, data.records[0].get('leaf'), data.records[0].get('needsArgs'), components);   			    				     
								}
								return true;
3ab0bee9   Elena.Budnik   aprams with args ...
380
							}
23769849   Elena.Budnik   LoadObject in Sta...
381
382
383
384
385
						});
					},	
					cellclick : function(grid, cell, cellIndex, record){		     
							if (cellIndex == 3) 
							grid.getStore().remove(record);
3ab0bee9   Elena.Budnik   aprams with args ...
386
					}
23769849   Elena.Budnik   LoadObject in Sta...
387
388
				}    
			}); 
d18b535d   elena   catalog draft + c...
389
390
      	
 
23769849   Elena.Budnik   LoadObject in Sta...
391
392
393
		this.formPanel =  Ext.create('Ext.form.Panel', 
		{ 
			region: 'center',	     
7348b580   Elena.Budnik   redmine #6010 : S...
394
395
396
397
398
			layout: {
				type: 'hbox',
				pack: 'start',
				align: 'stretch'
			},
23769849   Elena.Budnik   LoadObject in Sta...
399
400
401
			//bodyStyle: {background : '#dfe8f6'},
			defaults: { bodyStyle: {background : '#dfe8f6'}, padding : '3'},
			fieldDefaults: { labelWidth: 80, labelAlign : 'top' },
7348b580   Elena.Budnik   redmine #6010 : S...
402
			items: [ {  
23769849   Elena.Budnik   LoadObject in Sta...
403
404
405
				xtype: 'form',
				flex : 1,			    
				layout: {type: 'vbox', pack: 'start', align: 'stretch'},
7348b580   Elena.Budnik   redmine #6010 : S...
406
407
				items : [ this.paramGrid ],
					fbar:[ {   
23769849   Elena.Budnik   LoadObject in Sta...
408
409
410
411
412
413
414
						type: 'button',			   
						text: 'Generate Catalog',
						scope : this,
						handler: function()
						{
							// update object with user's values
							// if the return is true (object had been updated)
804b5599   Elena.Budnik   catalog name
415
							if (this.updateObject()){ 
23769849   Elena.Budnik   LoadObject in Sta...
416
417
418
419
420
421
422
423
								this.generateCatalog();			   			 
							}
						}
					},
					{   
						type: 'button',
						text: 'Reset',
						scope : this,
7348b580   Elena.Budnik   redmine #6010 : S...
424
425
426
427
428
						handler: function() {
							this.formPanel.getForm().reset();
							this.paramGrid.store.removeAll();
							this.timeSelector.TTGrid.store.removeAll();
						}
23769849   Elena.Budnik   LoadObject in Sta...
429
					}]
7348b580   Elena.Budnik   redmine #6010 : S...
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
				},
				{            
					xtype: 'form', 
					title: 'Additional Information', 
					flex : 1,
					trackResetOnLoad: true,  
					layout: {type: 'vbox', pack: 'start', align: 'stretch', padding : '3'},
					items : [
						this.fieldName,
						{
							xtype: 'textarea',
							name: 'description',
							fieldLabel: 'Description', 			
							height: 125
						},
						this.timeSelector 
					]
				}
			]  
23769849   Elena.Budnik   LoadObject in Sta...
449
		}); 
d18b535d   elena   catalog draft + c...
450
	 
23769849   Elena.Budnik   LoadObject in Sta...
451
452
453
454
455
456
457
458
459
		var myConf = {
					layout: 'border',
					items: [		   
					this.formPanel, 		     
					{
						xtype: 'panel', 
						region: 'south',
						title: 'Information',
						collapsible: true,
42863f42   Elena.Budnik   collapseMode: "he...
460
						collapseMode: 'header',
23769849   Elena.Budnik   LoadObject in Sta...
461
462
463
464
465
466
467
468
469
470
471
						height: 100,
						autoHide: false,
						bodyStyle: 'padding:5px',
						iconCls: 'icon-information',
						loader: {
							autoLoad: true,
							url: helpDir+'statisticsHOWTO'
						} 
					}],
					plugins: [ {ptype: 'paramArgumentsPlugin', pluginId: 'statistics-param-arguments-plugin'}]
				};
d18b535d   elena   catalog draft + c...
472
	    
23769849   Elena.Budnik   LoadObject in Sta...
473
474
		Ext.apply (this, Ext.apply(arguments, myConf));	
	} 
d18b535d   elena   catalog draft + c...
475
});