Blame view

js/app/views/StatisticsUI.js 10.9 KB
d18b535d   elena   catalog draft + c...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/**
 * 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 : [	
d80af896   Elena.Budnik   args for Statistics
15
16
17
18
	//	  'amdaModel.Function'
			'amdaUI.TimeSelectorUI',
			'amdaUI.ParamArgumentsPlug',
			'amdaModel.DownloadParam'
d18b535d   elena   catalog draft + c...
19
20
21
	],
	
	statics : {	 
d80af896   Elena.Budnik   args for Statistics
22
	//	  functionStore : null
d18b535d   elena   catalog draft + c...
23
24
25
	},
		
	constructor: function(config) {
d80af896   Elena.Budnik   args for Statistics
26
		this.init(config); 
d18b535d   elena   catalog draft + c...
27
28
		this.callParent(arguments);
	//	if (this.object) this.loadObject();
d80af896   Elena.Budnik   args for Statistics
29
30
31
32
		//
		var paramArgsPlug = this.getPlugin('statistics-param-arguments-plugin');
		if (paramArgsPlug)
			paramArgsPlug.onApply = this.onApplyParameterArgs;
d18b535d   elena   catalog draft + c...
33
	},
d80af896   Elena.Budnik   args for Statistics
34
35
36
37
	 
	 onApplyParameterArgs : function(parentUI, paramObject) {
		parentUI.paramGrid.getView().refresh();
	}, 
d18b535d   elena   catalog draft + c...
38
	
d80af896   Elena.Budnik   args for Statistics
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
	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: {}
		};
        	
// 		if (components) {
// 			if (components['index1']) {
// 				paramObj['dim1-index'] = components['index1'];
// 				++paramObj['type'];
// 			}
// 			
// 			if (components['index2']) {
// 				paramObj['dim2-index'] = components['index2'];
// 				++paramObj['type'];
// 			}
// 		}
        	
		var r = Ext.create('amdaModel.DownloadParam', 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);
	},
d18b535d   elena   catalog draft + c...
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
	
	addTT : function(TTname,TTid)
	{ 
	    this.timeSelector.addTT(TTname, TTid); ; 
	 
	},
	 
	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 
d80af896   Elena.Budnik   args for Statistics
105
106
107
108
109
110
		var basicForm = this.formPanel.items.items[0].getForm();
		var updateStatus = true;
		
		var formValues = basicForm.getValues();
//    this.object.set('name',formValues.name);
//    this.object.set('description',formValues.description);
94a05aa2   Elena.Budnik   update object in ...
111
     	    	    
d80af896   Elena.Budnik   args for Statistics
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
		var recs = this.paramGrid.getStore().getNewRecords();
		var paramArr = new Array();
		
		Ext.Array.each(recs, function(rec, index,allItems)
		{
			var obj =  new Object();
			obj.param = rec.get('name');
			obj.function = rec.get('function');
			if (obj.function == null) 
			{				
				myDesktopApp.warningMsg('Please select function : `click to select`'); 
				updateStatus = false;
				return;                     
			}
			paramArr.push(obj);            	      
		});
94a05aa2   Elena.Budnik   update object in ...
128
	    
d80af896   Elena.Budnik   args for Statistics
129
		this.object.set('parameter', paramArr);
d18b535d   elena   catalog draft + c...
130
	    
d80af896   Elena.Budnik   args for Statistics
131
		var timeSource = this.timeSelector.getActiveTimeSource(); 
94a05aa2   Elena.Budnik   update object in ...
132
 
d80af896   Elena.Budnik   args for Statistics
133
134
135
136
137
138
139
		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...
140
             
d80af896   Elena.Budnik   args for Statistics
141
		basicForm.updateRecord(this.object);
94a05aa2   Elena.Budnik   update object in ...
142
	    
d80af896   Elena.Budnik   args for Statistics
143
144
145
146
		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);          
d18b535d   elena   catalog draft + c...
147
	  	      
d80af896   Elena.Budnik   args for Statistics
148
		return updateStatus;	    
d18b535d   elena   catalog draft + c...
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
	},
	
	/**
	 * 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) {
	  
// 	  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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
		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...
191
	  
d80af896   Elena.Budnik   args for Statistics
192
193
194
195
196
197
		var ttStore = Ext.create('Ext.data.Store', 
		{
			fields: [ 'name', 'hidden_id']	
		});
		
		this.timeSelector = new amdaUI.TimeSelectorUI({id: 'statisticsTimeSelector', height : 160}); 
d18b535d   elena   catalog draft + c...
198
	
d80af896   Elena.Budnik   args for Statistics
199
200
201
202
		var store = Ext.create('Ext.data.Store', 
			{
					fields: ['name', 'function'] 
			});
d18b535d   elena   catalog draft + c...
203
	
d80af896   Elena.Budnik   args for Statistics
204
		this.paramGrid = Ext.create('Ext.grid.Panel', { 
d18b535d   elena   catalog draft + c...
205
206
207
208
209
210
	      title: 'Select Parameter & Apply Function',
	      selType : 'rowmodel',
//	      flex: 2,
	      height :250,
	      store : store, 
	      columns: [
d80af896   Elena.Budnik   args for Statistics
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
			{ 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>';
				}
d18b535d   elena   catalog draft + c...
247
			}
d18b535d   elena   catalog draft + c...
248
	      ], 
d80af896   Elena.Budnik   args for Statistics
249
250
	      plugins: [ Ext.create('Ext.grid.plugin.CellEditing', { clicksToEdit: 1 })],
			listeners :
d18b535d   elena   catalog draft + c...
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
	      {
		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') || 
				      (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;
d80af896   Elena.Budnik   args for Statistics
284
285
				var nameToSent;
				var components = null;
d18b535d   elena   catalog draft + c...
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
			  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');
				  break;
			      case 'alias' :
				  nameToSent = "#"+data.records[0].get('text');
				  break;
			      case 'derivedParam' :
				  nameToSent = "ws_"+data.records[0].get('text');
				  break;
			      case 'myDataParam' :
				  nameToSent = "wsd_"+data.records[0].get('text');
				  break;
			      default :
				  return false;
			  }
		 	  var module = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.statistics.id);
			  if (module)
d80af896   Elena.Budnik   args for Statistics
309
310
			  {			     
					module.addParam(nameToSent, data.records[0].get('leaf'), data.records[0].get('needsArgs'), components);   			    				     
d18b535d   elena   catalog draft + c...
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
350
351
352
353
354
355
356
357
358
359
360
361
362
			  }
			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:  'hbox',
//	      bodyStyle: {background : '#dfe8f6'},
	      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,
		      this.timeSelector
		    ]
		},
		{            
		    xtype: 'form', 
		    title: 'Additional Information', 
		    flex : 1,
		    layout: {type: 'vbox', pack: 'start', align: 'stretch', padding : '3'},
		    items : [
		      this.fieldName,
		      {
			xtype: 'textarea',
			name: 'description',
			fieldLabel: 'Description', 			
			height: 200
		      }   
		    ],
		    fbar:
		        [
			{   
			    type: 'button',			   
			    text: 'Generate Catalog',
			    scope : this,
			    handler: function(){
                            // update object with user's values
                            // if the return is true (object had been updated)
880ea119   Elena.Budnik   check object
363
				if(this.updateObject()){ 
94a05aa2   Elena.Budnik   update object in ...
364
365
					this.updateObject();
					this.generateCatalog();			   			 
880ea119   Elena.Budnik   check object
366
				}
d18b535d   elena   catalog draft + c...
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
                        }
			},
			{   
			    type: 'button',
			    text: 'Reset',
			    scope : this,
			    handler: function() {
			    }
			} 
		      ]
		}
	    ]  
	  }); 
	 
	 
	
	var myConf = {
		    layout: 'border',
		    items: [		   
			  this.formPanel, 		     
			  {
			    xtype: 'panel', 
			    region: 'south',
			    title: 'Information',
			    collapsible: true,
			    height: 100,
			    autoHide: false,
			    bodyStyle: 'padding:5px',
			    iconCls: 'icon-information',
			      loader: {
				autoLoad: true,
38c35fa6   elena   catalog howto tbd
398
				url: helpDir+'statisticsHOWTO'
d18b535d   elena   catalog draft + c...
399
400
			      } 
			  }
d80af896   Elena.Budnik   args for Statistics
401
402
403
		    ],
			plugins: [ {ptype: 'paramArgumentsPlugin', pluginId: 'statistics-param-arguments-plugin'}]
		};
d18b535d   elena   catalog draft + c...
404
405
406
407
408
	    
	    Ext.apply (this, Ext.apply(arguments, myConf));	
    }
	 
});