Blame view

js/app/views/VisuUI.js 7.47 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
  requires: [
    'amdaUI.CatalogVisuScatter',
    'amdaUI.CatalogVisuHistogram'
  ],

  visuTabContents: [],

  parametersStore: null,
1a0151a5   Benjamin Renard   wip
22
  catalogStore: null,
b0720b91   Benjamin Renard   Finalize catalog ...
23
  emptyChartConfig: null,
33705dc4   Benjamin Renard   Catalog visu rework
24

e1fd05b4   Elena.Budnik   visu from cacheCat
25
	constructor: function(config) {
5cfea1f2   elena   vizu draft
26
		this.init(config);
8be9a1a8   Benjamin Renard   Fix catalog visu
27
		this.callParent(arguments);
b0720b91   Benjamin Renard   Finalize catalog ...
28
29
    if (this.object)
        this.loadObject();
5cfea1f2   elena   vizu draft
30
	},
8be9a1a8   Benjamin Renard   Fix catalog visu
31
32

	setObject : function (obj) {
9d412dda   elena   catalog tmp and r...
33
		this.object = obj;
b0720b91   Benjamin Renard   Finalize catalog ...
34
		this.loadObject();
9d412dda   elena   catalog tmp and r...
35
	},
8be9a1a8   Benjamin Renard   Fix catalog visu
36
37

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

fded4fcb   elena   reload corrected
41
	reset : function() {
738e0997   Benjamin Renard   Draw histogram
42
    var tabPanel = Ext.getCmp('visu-tabpanel');
b0720b91   Benjamin Renard   Finalize catalog ...
43
44
45
46
47
48
    Ext.Array.each(tabPanel.items.items, function(item) {
      Ext.each(item.query('field'), function(field) {
          field.reset();
      });
    });
    this.replaceChart(null);
fded4fcb   elena   reload corrected
49
	},
8be9a1a8   Benjamin Renard   Fix catalog visu
50

5cfea1f2   elena   vizu draft
51
52
53
54
	/**
	 * load object catalog into this view
	 */
	loadObject : function()
8be9a1a8   Benjamin Renard   Fix catalog visu
55
	{
5cfea1f2   elena   vizu draft
56
		var me = this;
8be9a1a8   Benjamin Renard   Fix catalog visu
57

b0720b91   Benjamin Renard   Finalize catalog ...
58
    var onAfterInit = function(result, e)
e1fd05b4   Elena.Budnik   visu from cacheCat
59
		{
1a0151a5   Benjamin Renard   wip
60
      if (!result) {
e1fd05b4   Elena.Budnik   visu from cacheCat
61
62
				myDesktopApp.errorMsg(e.message);
				Ext.defer(function(){Ext.Msg.toFront()},10);
8be9a1a8   Benjamin Renard   Fix catalog visu
63

e1fd05b4   Elena.Budnik   visu from cacheCat
64
65
66
				return;
			}
			else if (!result.success)
5cfea1f2   elena   vizu draft
67
68
69
70
71
			{
				if (result.message)
					myDesktopApp.errorMsg(result.message);
				else
					myDesktopApp.errorMsg('Unknown error during catalog cache initialisation');
e1fd05b4   Elena.Budnik   visu from cacheCat
72
73

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

5cfea1f2   elena   vizu draft
75
76
				return;
			}
8be9a1a8   Benjamin Renard   Fix catalog visu
77

b0720b91   Benjamin Renard   Finalize catalog ...
78
79
80
81
82
83
84
      me.parametersStore.removeAll();
      Ext.Array.each(result.parameters, function(param) {
        if ((param.type == 0) || (param.type == 1) || (param.type == 3)) {
          me.parametersStore.add(param);
        }
      });

1a0151a5   Benjamin Renard   wip
85
86
87
      var dateConvert = function (value, rec) {
          if (!Ext.isDate(value)) {
              var valueString = new String(value);
b0720b91   Benjamin Renard   Finalize catalog ...
88
              return new Date(valueString+'Z');
1a0151a5   Benjamin Renard   wip
89
90
91
92
93
          }
          return value;
      };

      var fieldsConfig = [];
b0720b91   Benjamin Renard   Finalize catalog ...
94
95
      fieldsConfig.push({type: 'date', id: 'start', name : 'start',   dateFormat: 'Y-m-d\\TH:i:s', convert: dateConvert});
      fieldsConfig.push({type: 'date', id: 'stop', name : 'stop',  dateFormat: 'Y-m-d\\TH:i:s', convert: dateConvert});
1a0151a5   Benjamin Renard   wip
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
      me.parametersStore.each(function (param) {
        switch (param.get('type')) {
          case 0: //double
            fieldsConfig.push({
              type: 'float',
              id: param.get('id'),
              name: param.get('id')
            });
            break;
          case 1: //dateTime
            fieldsConfig.push({
              type: 'date',
              id: param.get('id'),
              name : param.get('id'),
              convert: dateConvert
            });
            break;
1a0151a5   Benjamin Renard   wip
113
114
115
116
117
118
119
120
121
          case 3: //int
            fieldsConfig.push({
              type: 'int',
              id: param.get('id'),
              name: param.get('id')
            });
            break;
        }
      });
8be9a1a8   Benjamin Renard   Fix catalog visu
122

1a0151a5   Benjamin Renard   wip
123
124
125
126
      me.catalogStore = Ext.create('Ext.data.Store', {
        fields : fieldsConfig
      });
      me.catalogStore.loadData(result.intervals);
b0720b91   Benjamin Renard   Finalize catalog ...
127
128

      me.reset();
5cfea1f2   elena   vizu draft
129
		}
e1fd05b4   Elena.Budnik   visu from cacheCat
130

1a0151a5   Benjamin Renard   wip
131
132
    var opt = {
      'typeTT' : 'catalog', 'id' : this.object.get('id'),
b0720b91   Benjamin Renard   Finalize catalog ...
133
						         'name' : this.object.get('name')
1a0151a5   Benjamin Renard   wip
134
    };
b0720b91   Benjamin Renard   Finalize catalog ...
135

33705dc4   Benjamin Renard   Catalog visu rework
136
    this.formPanel.getForm().loadRecord(this.object);
b0720b91   Benjamin Renard   Finalize catalog ...
137
		AmdaAction.readIntervalsForChart(opt, onAfterInit);
5cfea1f2   elena   vizu draft
138
	},
8be9a1a8   Benjamin Renard   Fix catalog visu
139

5cfea1f2   elena   vizu draft
140
	/**
8be9a1a8   Benjamin Renard   Fix catalog visu
141
	 * Check if changes were made before closing window
5cfea1f2   elena   vizu draft
142
	 * @return true if changes
8be9a1a8   Benjamin Renard   Fix catalog visu
143
144
145
	 */
	fclose : function()
	{
e1fd05b4   Elena.Budnik   visu from cacheCat
146
		return false;
fded4fcb   elena   reload corrected
147
148
	},

5cfea1f2   elena   vizu draft
149
	plotChart : function () {
33705dc4   Benjamin Renard   Catalog visu rework
150
    var tabPanel = Ext.getCmp('visu-tabpanel');
b0720b91   Benjamin Renard   Finalize catalog ...
151
152
153
    var newChartConfig = tabPanel.activeTab.items.items[0].getChartConfig(this.catalogStore);
    this.replaceChart(newChartConfig);
	},
33705dc4   Benjamin Renard   Catalog visu rework
154

b0720b91   Benjamin Renard   Finalize catalog ...
155
156
157
158
159
  replaceChart: function(newChartConfig) {
    if (!newChartConfig) {
      newChartConfig = this.emptyChartConfig;
    }
    var chart = Ext.getCmp('visu-chart');
33705dc4   Benjamin Renard   Catalog visu rework
160
161
    var chartPanel = chart.up();
    chartPanel.remove(chart);
b0720b91   Benjamin Renard   Finalize catalog ...
162
163
    chartPanel.insert(Ext.create('Ext.chart.Chart', newChartConfig));
  },
8be9a1a8   Benjamin Renard   Fix catalog visu
164

738e0997   Benjamin Renard   Draw histogram
165
166
  saveChart : function() {
    var chart = Ext.getCmp('visu-chart');
b0720b91   Benjamin Renard   Finalize catalog ...
167
168
169
170
171
172
    if (chart) {
      chart.save({
  		   type: 'image/png',
  			 defaultUrl : window.location
  		});
    }
738e0997   Benjamin Renard   Draw histogram
173
  },
8be9a1a8   Benjamin Renard   Fix catalog visu
174

33705dc4   Benjamin Renard   Catalog visu rework
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
  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
211
212
	init : function (config)
	{
1a0151a5   Benjamin Renard   wip
213
214
215
216
    this.catalogStore = Ext.create('Ext.data.Store', {
      fields: []
    });

33705dc4   Benjamin Renard   Catalog visu rework
217
218
    this.parametersStore =  Ext.create('Ext.data.Store', {
			fields: [
903e5e09   Benjamin Renard   WIP
219
        {name: 'id', type: 'string'},
33705dc4   Benjamin Renard   Catalog visu rework
220
				{name: 'name',  type: 'string'},
1a0151a5   Benjamin Renard   wip
221
        {name: 'type', type: 'int'}
33705dc4   Benjamin Renard   Catalog visu rework
222
223
			],
			data: []
5cfea1f2   elena   vizu draft
224
		});
8be9a1a8   Benjamin Renard   Fix catalog visu
225

b0720b91   Benjamin Renard   Finalize catalog ...
226
227
228
229
230
231
232
233
234
235
236
237
    this.emptyChartConfig = {
      xtype: 'chart',
      region: 'center',
      store: this.catalogStore,
      id: 'visu-chart',
      animate: false,
      mask: false,
      shadow: false,
      theme:'Blue',
      background: { fill : "#fff" }
    };

33705dc4   Benjamin Renard   Catalog visu rework
238
239
240
		this.formPanel = Ext.create('Ext.form.Panel', {
      region: 'center',
			layout:  'border',
5cfea1f2   elena   vizu draft
241
242
			bodyStyle: {background : '#dfe8f6'},
			defaults: { border : false, align: 'stretch',  padding: '3'},
33705dc4   Benjamin Renard   Catalog visu rework
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
			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'
            },
b0720b91   Benjamin Renard   Finalize catalog ...
272
            this.emptyChartConfig
33705dc4   Benjamin Renard   Catalog visu rework
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
          ]
        }
      ],
      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
299
			layout: 'border',
8be9a1a8   Benjamin Renard   Fix catalog visu
300
			items: [
33705dc4   Benjamin Renard   Catalog visu rework
301
        this.formPanel,
5cfea1f2   elena   vizu draft
302
				{
8be9a1a8   Benjamin Renard   Fix catalog visu
303
					xtype: 'panel',
e1fd05b4   Elena.Budnik   visu from cacheCat
304
305
306
					region: 'south',
					title: 'Information',
					collapsible: true,
42863f42   Elena.Budnik   collapseMode: "he...
307
					collapseMode: 'header',
e1fd05b4   Elena.Budnik   visu from cacheCat
308
309
310
311
312
313
314
					height: 100,
					autoHide: false,
					bodyStyle: 'padding:5px',
					iconCls:  'icon-information',
					loader: {
						autoLoad: true,
						url: helpDir+'visuHOWTO'
8be9a1a8   Benjamin Renard   Fix catalog visu
315
					}
5cfea1f2   elena   vizu draft
316
				}
8be9a1a8   Benjamin Renard   Fix catalog visu
317
			]
5cfea1f2   elena   vizu draft
318
		};
8be9a1a8   Benjamin Renard   Fix catalog visu
319

33705dc4   Benjamin Renard   Catalog visu rework
320
321
    this.initChartTypes();

8be9a1a8   Benjamin Renard   Fix catalog visu
322
323
324
		Ext.apply (this, Ext.apply(arguments, myConf));
    }
});