Blame view

js/app/views/VisuUI.js 12.7 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
 */

Ext.define('amdaUI.VisuUI', {
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
11
12
    extend: 'Ext.container.Container',
    alias: 'widget.panelVisu',
8be9a1a8   Benjamin Renard   Fix catalog visu
13

d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
14
15
16
17
    requires: [
        'amdaUI.CatalogVisuScatter',
        'amdaUI.CatalogVisuHistogram'
    ],
33705dc4   Benjamin Renard   Catalog visu rework
18

d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
19
    visuTabContents: [],
33705dc4   Benjamin Renard   Catalog visu rework
20

d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
21
22
23
    parametersStore: null,
    catalogStore: null,
    emptyChartConfig: null,
33705dc4   Benjamin Renard   Catalog visu rework
24

d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
25
26
27
28
29
30
31
32
33
    constructor: function (config) {
        this.init(config);
        this.callParent(arguments);
        if (this.object)
            this.loadObject();
    },

    setObject: function (obj) {
        this.object = obj;
b0720b91   Benjamin Renard   Finalize catalog ...
34
        this.loadObject();
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
35
36
37
38
39
    },

    updateObject: function () {
        return true;
    },
75a90e82   Hacene SI HADJ MOHAND   ticket ok
40
    addCatalog: function (cat) {
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
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
86
87
88
        this.setObject(cat)
    },

    reset: function () {
        var tabPanel = Ext.getCmp('visu-tabpanel');
        Ext.Array.each(tabPanel.items.items, function (item) {
            Ext.each(item.query('field'), function (field) {
                field.reset();
            });
        });
        this.replaceChart(null);
    },

    /**
     * load object catalog into this view
     */
    loadObject: function ()
    {
        var me = this;

        var onAfterInit = function (result, e)
        {
            if (!result) {
                myDesktopApp.errorMsg(e.message);
                Ext.defer(function () {
                    Ext.Msg.toFront()
                }, 10);

                return;
            } else if (!result.success)
            {
                if (result.message)
                    myDesktopApp.errorMsg(result.message);
                else
                    myDesktopApp.errorMsg('Unknown error during catalog cache initialisation');

                Ext.defer(function () {
                    Ext.Msg.toFront()
                }, 10);

                return;
            }

            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
89
            });
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
90
91
92
93
94
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

            var dateConvert = function (value, rec) {
                if (!Ext.isDate(value)) {
                    var valueString = new String(value);
                    return new Date(valueString + 'Z');
                }
                return value;
            };

            var fieldsConfig = [];
            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});
            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;
                    case 3: //int
                        fieldsConfig.push({
                            type: 'int',
                            id: param.get('id'),
                            name: param.get('id')
                        });
                        break;
                }
1a0151a5   Benjamin Renard   wip
127
            });
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
128
129
130

            me.catalogStore = Ext.create('Ext.data.Store', {
                fields: fieldsConfig
1a0151a5   Benjamin Renard   wip
131
            });
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
132
133
134
            me.catalogStore.loadData(result.intervals);

            me.reset();
1a0151a5   Benjamin Renard   wip
135
        }
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
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
177
178
179
180
181
182
183
184
185
186
187
188

        var opt = {
            'typeTT': 'catalog', 'id': this.object.get('id'),
            'name': this.object.get('name')
        };

        this.formPanel.getForm().loadRecord(this.object);
        AmdaAction.readIntervalsForChart(opt, onAfterInit);
    },

    /**
     * Check if changes were made before closing window
     * @return true if changes
     */
    fclose: function ()
    {
        return false;
    },

    plotChart: function () {
        var tabPanel = Ext.getCmp('visu-tabpanel');
        var newChartConfig = tabPanel.activeTab.items.items[0].getChartConfig(this.catalogStore);
        this.replaceChart(newChartConfig);
    },

    replaceChart: function (newChartConfig) {
        if (!newChartConfig) {
            newChartConfig = this.emptyChartConfig;
        }
        var chart = Ext.getCmp('visu-chart');
        var chartPanel = chart.up();
        chartPanel.remove(chart);
        chartPanel.insert(Ext.create('Ext.chart.Chart', newChartConfig));
    },

    saveChart: function () {
        var chart = Ext.getCmp('visu-chart');
        if (chart) {
            chart.save({
                type: 'image/png',
                defaultUrl: window.location
            });
        }
    },

    initChartTypes: function () {
        var me = this;

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

        var chartTypes = [
33705dc4   Benjamin Renard   Catalog visu rework
189
            {
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
190
191
192
                title: 'Scatter',
                widget: 'widget.panelCatalogVisuScatter'
            },
33705dc4   Benjamin Renard   Catalog visu rework
193
            {
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
194
195
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
272
273
274
                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;
            }
        });
    },

    init: function (config)
    {
        this.catalogStore = Ext.create('Ext.data.Store', {
            fields: []
        });

        this.parametersStore = Ext.create('Ext.data.Store', {
            fields: [
                {name: 'id', type: 'string'},
                {name: 'name', type: 'string'},
                {name: 'type', type: 'int'}
            ],
            data: []
        });

        this.emptyChartConfig = {
            xtype: 'chart',
            region: 'center',
            store: this.catalogStore,
            id: 'visu-chart',
            animate: false,
            mask: false,
            shadow: false,
            theme: 'Blue',
            background: {fill: "#fff"}
        };

        this.formPanel = Ext.create('Ext.form.Panel', {
            region: 'center',
            layout: 'border',
            bodyStyle: {background: '#dfe8f6'},
            defaults: {border: false, align: 'stretch', padding: '3'},
            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,
33705dc4   Benjamin Renard   Catalog visu rework
275
//              height: 400,
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
276
277
278
279
280
281
282
283
284
285
286
287
288
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
325
326
327
328
329
330
331
                            id: 'visu-tabpanel'
                        },
                        this.emptyChartConfig
                    ]
                }
            ],
            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
                }
            ],
            listeners:
                    {
                        render: function (o, op)
                        {
                            var me = this;
                            var el = me.body.dom;
                            var dropTarget = Ext.create('Ext.dd.DropTarget', el, {
                                ddGroup: 'explorerTree',
                                notifyEnter: function (ddSource, e, data)
                                {

                                },
                                notifyOver: function (ddSource, e, data)
                                {
                                    var nodeType = data.records[0].get('nodeType');
                                    if ((nodeType == 'catalog' || nodeType == 'sharedcatalog') &&
                                            (data.records[0].get('leaf')))
                                    {
                                        this.valid = true;
                                        return this.dropAllowed;
                                    }
                                    this.valid = false;
                                    return this.dropNotAllowed;
                                },
                                notifyDrop: function (ddSource, e, data)
                                {
                                    if (!this.valid)
                                        return false;
                                    var visuModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.visu.id);
                                    if (visuModule) {
75a90e82   Hacene SI HADJ MOHAND   ticket ok
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
                                        
                                        var catNode = data.records[0];
                                        AmdaAction.getObject( catNode.get('id'), catNode.get('nodeType'), function(result, remoteEvent) {
                                            var catObj = Ext.create(catNode.get('objectDataModel'), result);
                                            if(catObj !== null){
                                            visuModule.addCatalog(catObj);
                                        }else{
                                        Ext.MessageBox.show({title: 'Warning',
                                        msg:  '<br/>Undifined Catalog '+catNode.get('text'),
                                        width: 300,
                                        buttons: Ext.MessageBox,
                                        fn: me.overwriteProcess,
                                        icon: Ext.MessageBox.WARNING,
                                        scope: me
                                    });
                                    return false;
                                        }
                                            
                                        }, this);
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
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
                                    }
                                    return true;
                                }
                            });
                        }
                    }
        });

        var myConf = {
            layout: 'border',
            items: [
                this.formPanel,
                {
                    xtype: 'panel',
                    region: 'south',
                    title: 'Information',
                    collapsible: true,
                    collapseMode: 'header',
                    height: 100,
                    autoHide: false,
                    bodyStyle: 'padding:5px',
                    iconCls: 'icon-information',
                    loader: {
                        autoLoad: true,
                        url: helpDir + 'visuHOWTO'
                    }
                }
            ]
        };

        this.initChartTypes();

        Ext.apply(this, Ext.apply(arguments, myConf));
8be9a1a8   Benjamin Renard   Fix catalog visu
384
385
    }
});