Blame view

js/app/views/VisuUI.js 10.6 KB
5cfea1f2   elena   vizu draft
1
2
3
4
5
6
/**
 * Project       AMDA-NG
 * Name          VisuUI.js
 * @class 	   amdaUI.visuUI
 * @extends      Ext.container.Container
 * @brief	   Visualization Module UI definition (View)
9d412dda   elena   catalog tmp and r...
7
 * @author 	  elena
5cfea1f2   elena   vizu draft
8
9
10
11
 */

Ext.define('amdaUI.VisuUI', {
	extend: 'Ext.container.Container',
8be9a1a8   Benjamin Renard   Fix catalog visu
12
13
	alias: 'widget.panelVisu',

33705dc4   Benjamin Renard   Catalog visu rework
14
15
16
17
18
19
20
21
22
  requires: [
    'amdaUI.CatalogVisuScatter',
    'amdaUI.CatalogVisuHistogram'
  ],

  visuTabContents: [],

  parametersStore: null,

e1fd05b4   Elena.Budnik   visu from cacheCat
23
	constructor: function(config) {
5cfea1f2   elena   vizu draft
24
		this.init(config);
8be9a1a8   Benjamin Renard   Fix catalog visu
25
		this.callParent(arguments);
9d412dda   elena   catalog tmp and r...
26
		if (this.object) this.reformObject();
5cfea1f2   elena   vizu draft
27
	},
8be9a1a8   Benjamin Renard   Fix catalog visu
28
29

	setObject : function (obj) {
9d412dda   elena   catalog tmp and r...
30
31
32
		this.object = obj;
		this.reformObject();
	},
8be9a1a8   Benjamin Renard   Fix catalog visu
33
34

	updateObject : function () {
9d412dda   elena   catalog tmp and r...
35
36
		 return true;
	},
8be9a1a8   Benjamin Renard   Fix catalog visu
37

e1fd05b4   Elena.Budnik   visu from cacheCat
38
	reformObject : function () {
8be9a1a8   Benjamin Renard   Fix catalog visu
39
40
		this.fromPlugin = this.object.get('fromPlugin');

9d412dda   elena   catalog tmp and r...
41
		if (this.fromPlugin) {
e1fd05b4   Elena.Budnik   visu from cacheCat
42
43
44
45
			if (this.object.get('folderId') == '')
				this.object.set('id','cacheCat');
			else
				this.object.set('id',this.object.get('folderId'));
8be9a1a8   Benjamin Renard   Fix catalog visu
46

9d412dda   elena   catalog tmp and r...
47
48
49
50
51
52
			this.object.set('objName',this.object.get('objName'));
		}
		else {
			this.object.set('id',this.object.get('id'));
			this.object.set('name',this.object.get('name'));
		}
5cfea1f2   elena   vizu draft
53
		// load object into view
e1fd05b4   Elena.Budnik   visu from cacheCat
54
		if (this.object.get('id') != '')
f8448f55   elena   tooltip
55
				this.loadObject();
5cfea1f2   elena   vizu draft
56
	},
8be9a1a8   Benjamin Renard   Fix catalog visu
57

fded4fcb   elena   reload corrected
58
	reset : function() {
ccb80610   elena   added options
59
60
61
62
63
64
65
66
		//reset all fieldsets except the first one (name, intervals)
		var form = this.items.items[0].items.items[0];
		for (var i = 1;  i < 4; i++) {
			var fieldset = form.items.items[i];
			Ext.each(fieldset.query('field'), function(field) {
				field.reset();
			});
		}
8be9a1a8   Benjamin Renard   Fix catalog visu
67
		this.resetChart();
fded4fcb   elena   reload corrected
68
	},
8be9a1a8   Benjamin Renard   Fix catalog visu
69

5cfea1f2   elena   vizu draft
70
71
72
73
	/**
	 * load object catalog into this view
	 */
	loadObject : function()
8be9a1a8   Benjamin Renard   Fix catalog visu
74
	{
5cfea1f2   elena   vizu draft
75
		var me = this;
8be9a1a8   Benjamin Renard   Fix catalog visu
76
77

		var onAfterInit = function(result, e)
e1fd05b4   Elena.Budnik   visu from cacheCat
78
		{
33705dc4   Benjamin Renard   Catalog visu rework
79
			/*if (!result) {
e1fd05b4   Elena.Budnik   visu from cacheCat
80
81
				myDesktopApp.errorMsg(e.message);
				Ext.defer(function(){Ext.Msg.toFront()},10);
8be9a1a8   Benjamin Renard   Fix catalog visu
82

e1fd05b4   Elena.Budnik   visu from cacheCat
83
84
85
				return;
			}
			else if (!result.success)
5cfea1f2   elena   vizu draft
86
87
88
89
90
			{
				if (result.message)
					myDesktopApp.errorMsg(result.message);
				else
					myDesktopApp.errorMsg('Unknown error during catalog cache initialisation');
e1fd05b4   Elena.Budnik   visu from cacheCat
91
92

				Ext.defer(function(){Ext.Msg.toFront()},10);
8be9a1a8   Benjamin Renard   Fix catalog visu
93

5cfea1f2   elena   vizu draft
94
95
				return;
			}
8be9a1a8   Benjamin Renard   Fix catalog visu
96

5cfea1f2   elena   vizu draft
97
			var fields = [], i = 0, index;
e1fd05b4   Elena.Budnik   visu from cacheCat
98
99
100
101

			if (!result.cache) {
				me.object.set('name', result.name);
				me.object.set('nbIntervals', result.totalCount);
8be9a1a8   Benjamin Renard   Fix catalog visu
102

e1fd05b4   Elena.Budnik   visu from cacheCat
103
104
				var params = [];
				Ext.Array.each(result.parameters, function(item, index) {
8be9a1a8   Benjamin Renard   Fix catalog visu
105
					params[index] = item;
e1fd05b4   Elena.Budnik   visu from cacheCat
106
				}, this);
8be9a1a8   Benjamin Renard   Fix catalog visu
107
108

				me.object.set('parameters', params);
e1fd05b4   Elena.Budnik   visu from cacheCat
109
110
111
112
113
			}
			else {
				fields[0] = Ext.create('Ext.data.Field', { name : 'start', id: 'start', text : 'start: date' });
				fields[1] = Ext.create('Ext.data.Field', { name : 'stop',  id: 'stop',  text : 'stop: date' });
				i = 2;
8be9a1a8   Benjamin Renard   Fix catalog visu
114
115
			}

e1fd05b4   Elena.Budnik   visu from cacheCat
116
117
			Ext.Array.each(me.object.get('parameters'), function(obj) {
				index = 'param'+i.toString();
7d14e196   Elena.Budnik   type definition f...
118
119
				if (obj.type == 2) {
					fields[i] = Ext.create('Ext.data.Field', { name : index, id: index, text : obj.name + ': string' });
8be9a1a8   Benjamin Renard   Fix catalog visu
120

e1fd05b4   Elena.Budnik   visu from cacheCat
121
122
123
124
125
				}
				else if (obj.type == 1){
					fields[i] = Ext.create('Ext.data.Field', { name : index, id: index, text : obj.name + ': date' });
				}
				else {
7d14e196   Elena.Budnik   type definition f...
126
					fields[i] = Ext.create('Ext.data.Field', { name : index, id: index, text : obj.name,
8be9a1a8   Benjamin Renard   Fix catalog visu
127
						convert: function(value, record) {
7d14e196   Elena.Budnik   type definition f...
128
129
130
							return parseFloat(value);
						}
					});
5cfea1f2   elena   vizu draft
131
				}
5cfea1f2   elena   vizu draft
132
133
				i++;
			});
8be9a1a8   Benjamin Renard   Fix catalog visu
134
135

			if (me.chartStore) {
fded4fcb   elena   reload corrected
136
137
138
139
				me.parList.removeAll();
				me.reset();
				me.chartStore = null;
			}
8be9a1a8   Benjamin Renard   Fix catalog visu
140

e1fd05b4   Elena.Budnik   visu from cacheCat
141
			me.parList.add(fields);
8be9a1a8   Benjamin Renard   Fix catalog visu
142

5cfea1f2   elena   vizu draft
143
			me.chartStore = Ext.create('Ext.data.Store', {
8be9a1a8   Benjamin Renard   Fix catalog visu
144
				fields : fields,
fded4fcb   elena   reload corrected
145
		//		autoDestroy: false,
e1fd05b4   Elena.Budnik   visu from cacheCat
146
		//		pageSize : 200,
8be9a1a8   Benjamin Renard   Fix catalog visu
147
		//		buffered : true,
e1fd05b4   Elena.Budnik   visu from cacheCat
148
149
		//		purgePageCount: 0,
		//		remoteSort: true,
5cfea1f2   elena   vizu draft
150
151
152
153
154
				autoload: false,
				proxy: {
					type: 'direct',
					api :
					{
86263051   elena   visu second draft
155
						read   :  AmdaAction.readIntervalsForChart
5cfea1f2   elena   vizu draft
156
157
					},
					// remplir automatiquement tt, sharedtt , catalog, shared catalog
8be9a1a8   Benjamin Renard   Fix catalog visu
158
					extraParams : {'typeTT' : 'catalog', 'id' : me.object.get('id'),
9d412dda   elena   catalog tmp and r...
159
						         'name' : me.object.get('objName'), 'fromPlugin' : me.fromPlugin},
5cfea1f2   elena   vizu draft
160
161
162
163
164
165
166
167
168
					reader:
					{
						type: 'json',
						root: 'intervals',
						totalProperty : 'totalCount'
					}
				},
				listeners: {
					scope : me,
8be9a1a8   Benjamin Renard   Fix catalog visu
169
					load: function(store,records) {
5cfea1f2   elena   vizu draft
170
						//TODO enable plot button
9d412dda   elena   catalog tmp and r...
171
172
						// me.object.set('nbIntervals',me.chartStore.getTotalCount());

fded4fcb   elena   reload corrected
173
						// load object into form
33705dc4   Benjamin Renard   Catalog visu rework
174
175
						//BRE - var formPanel =  me.items.items[0].items.items[0];
						//formPanel.getForm().loadRecord(me.object);
5cfea1f2   elena   vizu draft
176
177
178
					}
				}
			});
8be9a1a8   Benjamin Renard   Fix catalog visu
179

33705dc4   Benjamin Renard   Catalog visu rework
180
			me.chartStore.load();*/
5cfea1f2   elena   vizu draft
181
		}
e1fd05b4   Elena.Budnik   visu from cacheCat
182

33705dc4   Benjamin Renard   Catalog visu rework
183
184
185
186
187
188
189
190
191
192
193
194
195
		//AmdaAction.initForChart(this.object.get('id'), this.object.get('folderId'), this.object.get('objName'), this.fromPlugin, 'catalog', onAfterInit);
    this.formPanel.getForm().loadRecord(this.object);

    this.parametersStore.removeAll();
    Ext.Array.each(this.object.get('parameters'), function(param) {
			for (index = 0; index < param.size; ++index) {
				me.parametersStore.add({'paramId': param.id+'_'+index, 'name' : param.name, 'index': index, 'size': param.size});
			}
		});

    Ext.Array.each(this.visuTabContents, function(content) {
      content.initVisu();
    });
5cfea1f2   elena   vizu draft
196
	},
8be9a1a8   Benjamin Renard   Fix catalog visu
197
198


5cfea1f2   elena   vizu draft
199
	/**
8be9a1a8   Benjamin Renard   Fix catalog visu
200
	 * Check if changes were made before closing window
5cfea1f2   elena   vizu draft
201
	 * @return true if changes
8be9a1a8   Benjamin Renard   Fix catalog visu
202
203
204
	 */
	fclose : function()
	{
e1fd05b4   Elena.Budnik   visu from cacheCat
205
		return false;
fded4fcb   elena   reload corrected
206
207
208
	},

	resetChart : function () {
8be9a1a8   Benjamin Renard   Fix catalog visu
209

ccb80610   elena   added options
210
211
212
213
		var emptyAxesConfig =   [{
			type: 'Numeric',
			position: 'bottom',
			fields: [],
a442d142   Elena.Budnik   redmine #5382
214
			title: 'X axis',
ccb80610   elena   added options
215
			grid : true
e1fd05b4   Elena.Budnik   visu from cacheCat
216
		}, {
ccb80610   elena   added options
217
218
219
			type: 'Numeric',
			position: 'left',
			fields: [],
a442d142   Elena.Budnik   redmine #5382
220
			title: 'Y axis',
ccb80610   elena   added options
221
222
			grid: true
		}];
8be9a1a8   Benjamin Renard   Fix catalog visu
223

fded4fcb   elena   reload corrected
224
225
		this.chartConfig.series[0].xField = '';
		this.chartConfig.series[0].yField = '';
8be9a1a8   Benjamin Renard   Fix catalog visu
226

ccb80610   elena   added options
227
		this.chartConfig.theme = 'Blue';
8be9a1a8   Benjamin Renard   Fix catalog visu
228
229
230
231

		this.chartConfig.axes = emptyAxesConfig;

		var chart =  Ext.create('Ext.chart.Chart', this.chartConfig);
fded4fcb   elena   reload corrected
232
		this.replaceChart(chart);
8be9a1a8   Benjamin Renard   Fix catalog visu
233

fded4fcb   elena   reload corrected
234
	},
8be9a1a8   Benjamin Renard   Fix catalog visu
235

5cfea1f2   elena   vizu draft
236
	plotChart : function () {
8be9a1a8   Benjamin Renard   Fix catalog visu
237

33705dc4   Benjamin Renard   Catalog visu rework
238
		/*this.chartConfig.store = this.chartStore;
8be9a1a8   Benjamin Renard   Fix catalog visu
239
240
241
242

		var xTitle = this.items.items[0].items.items[0].items.items[1].items.items[2].getValue();
		var yTitle = this.items.items[0].items.items[0].items.items[2].items.items[2].getValue();

ccb80610   elena   added options
243
244
		if (xTitle) this.chartConfig.axes[0].title = xTitle;
		if (xTitle) this.chartConfig.axes[1].title = yTitle;
8be9a1a8   Benjamin Renard   Fix catalog visu
245

ccb80610   elena   added options
246
247
		// axis modifs
		if (this.comboXrange.getValue() == 'manual') {
8be9a1a8   Benjamin Renard   Fix catalog visu
248
			var minX = this.comboXrange.next().next().getValue();
ccb80610   elena   added options
249
250
251
252
253
254
255
256
257
258
259
260
261
262
			var maxX = this.comboXrange.next().next().next().next().getValue();
			this.chartConfig.axes[0].minimum = minX;
			this.chartConfig.axes[0].maximum = maxX ;
		} else {
			// unset min/max in config
			delete this.chartConfig.axes[0].minimum;
			delete this.chartConfig.axes[0].maximum;
		}
		if (this.comboYrange.getValue() == 'manual') {
			var minX = this.comboYrange.next().next().getValue();
			var maxX = this.comboYrange.next().next().next().next().getValue();
		//	if (minX && maxX) {
			this.chartConfig.axes[1].minimum = minX;
			this.chartConfig.axes[1].maximum = maxX;
8be9a1a8   Benjamin Renard   Fix catalog visu
263
		//	}
ccb80610   elena   added options
264
265
266
267
268
		} else {
			// unset min/max in config
			delete this.chartConfig.axes[1].minimum;
			delete this.chartConfig.axes[1].maximum;
		}
8be9a1a8   Benjamin Renard   Fix catalog visu
269
270
271

		var chart =  Ext.create('Ext.chart.Chart', this.chartConfig);

33705dc4   Benjamin Renard   Catalog visu rework
272
273
274
275
276
277
278
		this.replaceChart(chart);*/
    var chart = Ext.getCmp('visu-chart');
    var tabPanel = Ext.getCmp('visu-tabpanel');

    var chartPanel = chart.up();
    chartPanel.remove(chart);
    chartPanel.insert(tabPanel.activeTab.items.items[0].getChart());
fded4fcb   elena   reload corrected
279
	},
8be9a1a8   Benjamin Renard   Fix catalog visu
280
281

	replaceChart: function(chart) {
5cfea1f2   elena   vizu draft
282
283
284
285
		var chartPanel =  this.items.items[0].items.items[1];
		var oldChart = chartPanel.down('chart');
		oldIndex = chartPanel.items.indexOf(oldChart);
		chartPanel.remove(oldChart);
8be9a1a8   Benjamin Renard   Fix catalog visu
286
		chartPanel.insert(oldIndex, chart);
5cfea1f2   elena   vizu draft
287
	},
8be9a1a8   Benjamin Renard   Fix catalog visu
288

33705dc4   Benjamin Renard   Catalog visu rework
289
290
291
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
  initChartTypes: function() {
    var me = this;

    var tabPanel = Ext.getCmp('visu-tabpanel');
    if (!tabPanel)
      return;

    var chartTypes = [
      {
        title: 'Scatter',
        widget: 'widget.panelCatalogVisuScatter'
      },
      {
        title: 'Histogram',
        widget: 'widget.panelCatalogVisuHistogram'
      }
    ];

    var isFirst = true;
    Ext.Array.each(chartTypes, function(chartType) {
      var tabContent = Ext.create(chartType.widget, {parametersStore : me.parametersStore});
      var tab = tabPanel.add({
        title: chartType.title,
        items: [
          tabContent
        ],
        layout: 'fit'
      });
      me.visuTabContents.push(tabContent);
      if (isFirst) {
        tabPanel.setActiveTab(tab);
        isFirst = false;
      }
    });
  },

8be9a1a8   Benjamin Renard   Fix catalog visu
325
326
	init : function (config)
	{
33705dc4   Benjamin Renard   Catalog visu rework
327
328
329
330
331
332
333
334
    this.parametersStore =  Ext.create('Ext.data.Store', {
			fields: [
				{name: 'paramId', type: 'string'},
				{name: 'name',  type: 'string'},
				{name: 'index',  type: 'int'},
				{name: 'size', type: 'int'}
			],
			data: []
5cfea1f2   elena   vizu draft
335
		});
8be9a1a8   Benjamin Renard   Fix catalog visu
336

33705dc4   Benjamin Renard   Catalog visu rework
337
		var store = Ext.create('Ext.data.Store', {
8be9a1a8   Benjamin Renard   Fix catalog visu
338
			fields      :  [],
ccb80610   elena   added options
339
340
			autoload    : false
		});
8be9a1a8   Benjamin Renard   Fix catalog visu
341

33705dc4   Benjamin Renard   Catalog visu rework
342
343
344
		this.formPanel = Ext.create('Ext.form.Panel', {
      region: 'center',
			layout:  'border',
5cfea1f2   elena   vizu draft
345
346
			bodyStyle: {background : '#dfe8f6'},
			defaults: { border : false, align: 'stretch',  padding: '3'},
33705dc4   Benjamin Renard   Catalog visu rework
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
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
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
			items: [
        {
          xtype : 'fieldset',
          region: 'north',
  				items : [
            {
              xtype: 'fieldcontainer',
              layout: 'hbox',
              fieldDefaults: { labelWidth: 80, labelAlign : 'right' },
              items: [
                { xtype:'textfield', fieldLabel: 'Catalog Name', name: 'name', readOnly: true},
                { xtype: 'splitter' },
                { xtype:'textfield', fieldLabel: 'Intervals', name: 'nbIntervals', readOnly: true}
              ]
            }
          ],
        },
        {
          xtype: 'container',
          region: 'center',
          layout: 'border',
          items: [
            {
              xtype: 'tabpanel',
              region: 'west',
              width: 250,
//              height: 400,
              id: 'visu-tabpanel'
            },
            {
              xtype: 'chart',
              region: 'center',
              store: store,
              id: 'visu-chart',
              animate: false,
        			mask: false,
        			shadow: false,
        			theme:'Blue',
        			background: { fill : "#fff" }
            }
          ]
        }
      ],
      fbar:[
        {
          type: 'button',
          text: 'Plot',
          scope : this,
          handler: this.plotChart
        },
        {
          type: 'button',
          text: 'Reset',
          scope : this,
          handler: this.reset
      },
      {
        type: 'button',
        text: 'Save Chart',
        scope : this,
        handler: this.saveChart
      }
    ]
    });

    var myConf = {
5cfea1f2   elena   vizu draft
413
			layout: 'border',
8be9a1a8   Benjamin Renard   Fix catalog visu
414
			items: [
33705dc4   Benjamin Renard   Catalog visu rework
415
        this.formPanel,
5cfea1f2   elena   vizu draft
416
				{
8be9a1a8   Benjamin Renard   Fix catalog visu
417
					xtype: 'panel',
e1fd05b4   Elena.Budnik   visu from cacheCat
418
419
420
					region: 'south',
					title: 'Information',
					collapsible: true,
42863f42   Elena.Budnik   collapseMode: "he...
421
					collapseMode: 'header',
e1fd05b4   Elena.Budnik   visu from cacheCat
422
423
424
425
426
427
428
					height: 100,
					autoHide: false,
					bodyStyle: 'padding:5px',
					iconCls:  'icon-information',
					loader: {
						autoLoad: true,
						url: helpDir+'visuHOWTO'
8be9a1a8   Benjamin Renard   Fix catalog visu
429
					}
5cfea1f2   elena   vizu draft
430
				}
8be9a1a8   Benjamin Renard   Fix catalog visu
431
			]
5cfea1f2   elena   vizu draft
432
		};
8be9a1a8   Benjamin Renard   Fix catalog visu
433

33705dc4   Benjamin Renard   Catalog visu rework
434
435
    this.initChartTypes();

8be9a1a8   Benjamin Renard   Fix catalog visu
436
437
438
		Ext.apply (this, Ext.apply(arguments, myConf));
    }
});