Blame view

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

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
    requires: [
        'amdaUI.CatalogVisuScatter',
3ccb373f   furkan   #6899 - Done
16
17
        'amdaUI.CatalogVisuHistogram',
        'amdaUI.PlotlyContainer'
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
18
    ],
33705dc4   Benjamin Renard   Catalog visu rework
19

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

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

d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
26
27
28
29
30
31
32
33
34
    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 ...
35
        this.loadObject();
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
36
37
38
39
40
    },

    updateObject: function () {
        return true;
    },
75a90e82   Hacene SI HADJ MOHAND   ticket ok
41
    addCatalog: function (cat) {
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
        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
     */
1be6ea03   Erdogan Furkan   #10098 - Final co...
58
    loadObject: function () {
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
59
60
        var me = this;

1be6ea03   Erdogan Furkan   #10098 - Final co...
61
        var onAfterInit = function (result, e) {
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
62
63
64
65
66
67
68
            if (!result) {
                myDesktopApp.errorMsg(e.message);
                Ext.defer(function () {
                    Ext.Msg.toFront()
                }, 10);

                return;
1be6ea03   Erdogan Furkan   #10098 - Final co...
69
            } else if (!result.success) {
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
                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
87
            });
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
88
89
90
91
92
93
94
95
96
97

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

            var fieldsConfig = [];
1be6ea03   Erdogan Furkan   #10098 - Final co...
98
99
            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 });
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
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
            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
125
            });
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
126
127
128

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

            me.reset();
1a0151a5   Benjamin Renard   wip
133
        }
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
134
135
136
137
138
139
140
141
142
143
144
145
146
147

        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
     */
1be6ea03   Erdogan Furkan   #10098 - Final co...
148
    fclose: function () {
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
149
150
151
        return false;
    },

536a676d   Erdogan Furkan   #10701 & #10702 Done
152
    plotChart: function (isColorBar) {
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
153
        var tabPanel = Ext.getCmp('visu-tabpanel');
536a676d   Erdogan Furkan   #10701 & #10702 Done
154
        var allData = tabPanel.activeTab.items.items[0].getChartConfig(this.catalogStore,isColorBar);
3ccb373f   furkan   #6899 - Done
155
        this.replaceChart(allData);
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
156
157
    },

3ccb373f   furkan   #6899 - Done
158
159
160
161
162
163
    replaceChart: function (allData) {
       
        var config = this.emptyChartConfig;
        if (allData) {
            config.data = allData.data;
            config.layout = allData.layout;
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
164
        }
57eb5d17   Erdogan Furkan   #6899 - Asked mod...
165
166
167
168
        else{
            config.data =[];
            config.layout ={};
        }
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
169
        var chart = Ext.getCmp('visu-chart');
3ccb373f   furkan   #6899 - Done
170
171
172
        if (chart){
            var chartPanel = chart.up();
            chartPanel.remove(chart);  
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
173
        }
3ccb373f   furkan   #6899 - Done
174
175
        var testPlotly = new amdaUI.PlotlyContainer(config);
        chartPanel.insert(testPlotly);
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
176
177
178
179
180
181
182
183
184
185
    },

    initChartTypes: function () {
        var me = this;

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

        var chartTypes = [
33705dc4   Benjamin Renard   Catalog visu rework
186
            {
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
187
188
189
                title: 'Scatter',
                widget: 'widget.panelCatalogVisuScatter'
            },
33705dc4   Benjamin Renard   Catalog visu rework
190
            {
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
191
192
193
194
195
196
197
                title: 'Histogram',
                widget: 'widget.panelCatalogVisuHistogram'
            }
        ];

        var isFirst = true;
        Ext.Array.each(chartTypes, function (chartType) {
560766be   furkan   #6899- Last modif...
198
            var tabContent = Ext.create(chartType.widget, { visuUI:me,parametersStore: me.parametersStore });
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
199
200
201
202
203
            var tab = tabPanel.add({
                title: chartType.title,
                items: [
                    tabContent
                ],
57eb5d17   Erdogan Furkan   #6899 - Asked mod...
204
                layout: 'fit',
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
205
206
207
208
209
210
211
212
213
            });
            me.visuTabContents.push(tabContent);
            if (isFirst) {
                tabPanel.setActiveTab(tab);
                isFirst = false;
            }
        });
    },

1be6ea03   Erdogan Furkan   #10098 - Final co...
214
    init: function (config) {
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
215
216
217
218
219
220
        this.catalogStore = Ext.create('Ext.data.Store', {
            fields: []
        });

        this.parametersStore = Ext.create('Ext.data.Store', {
            fields: [
1be6ea03   Erdogan Furkan   #10098 - Final co...
221
222
223
                { name: 'id', type: 'string' },
                { name: 'name', type: 'string' },
                { name: 'type', type: 'int' }
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
224
225
226
227
228
            ],
            data: []
        });

        this.emptyChartConfig = {
0dd3cab3   Benjamin Renard   Fix bug with visu...
229
            xtype: 'PlotlyContainer',
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
230
            id: 'visu-chart',
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
231
232
233
234
235
        };

        this.formPanel = Ext.create('Ext.form.Panel', {
            region: 'center',
            layout: 'border',
1be6ea03   Erdogan Furkan   #10098 - Final co...
236
237
            bodyStyle: { background: '#dfe8f6' },
            defaults: { border: false, align: 'stretch', padding: '3' },
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
238
239
240
241
242
243
244
245
            items: [
                {
                    xtype: 'fieldset',
                    region: 'north',
                    items: [
                        {
                            xtype: 'fieldcontainer',
                            layout: 'hbox',
1be6ea03   Erdogan Furkan   #10098 - Final co...
246
                            fieldDefaults: { labelWidth: 80, labelAlign: 'right' },
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
247
                            items: [
1be6ea03   Erdogan Furkan   #10098 - Final co...
248
249
250
                                { xtype: 'textfield', fieldLabel: 'Catalog Name', name: 'name', readOnly: true },
                                { xtype: 'splitter' },
                                { xtype: 'textfield', fieldLabel: 'Intervals', name: 'nbIntervals', readOnly: true }
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
251
252
253
254
255
256
257
                            ]
                        }
                    ],
                },
                {
                    xtype: 'container',
                    region: 'center',
0dd3cab3   Benjamin Renard   Fix bug with visu...
258
259
260
261
                    layout: {
                        type: 'hbox',
                        align: 'stretch'
                    },
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
262
263
264
265
                    items: [
                        {
                            xtype: 'tabpanel',
                            region: 'west',
310be321   Erdogan Furkan   Forgot this one
266
                            width: 275,
33705dc4   Benjamin Renard   Catalog visu rework
267
//              height: 400,
57eb5d17   Erdogan Furkan   #6899 - Asked mod...
268
269
270
271
272
273
274
                            id: 'visu-tabpanel',
                            listeners:{
                                tabchange:function(){
                                    this.plotChart();
                                },
                                scope: this
                            }
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
275
                        },
0dd3cab3   Benjamin Renard   Fix bug with visu...
276
277
278
279
280
281
282
283
                        {
                            xtype: 'container',
                            layout:'fit',
                            flex: 1,
                            items: [
                                this.emptyChartConfig
                            ]
                        }
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
284
285
286
287
288
289
                    ]
                }
            ],
            fbar: [
                {
                    type: 'button',
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
290
291
292
293
                    text: 'Reset',
                    scope: this,
                    handler: this.reset
                },
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
294
295
            ],
            listeners:
1be6ea03   Erdogan Furkan   #10098 - Final co...
296
297
298
299
300
301
302
            {
                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) {
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
303
304

                                },
1be6ea03   Erdogan Furkan   #10098 - Final co...
305
                                notifyOver: function (ddSource, e, data) {
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
306
307
                                    var nodeType = data.records[0].get('nodeType');
                                    if ((nodeType == 'catalog' || nodeType == 'sharedcatalog') &&
1be6ea03   Erdogan Furkan   #10098 - Final co...
308
                                        (data.records[0].get('leaf'))) {
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
309
310
311
312
313
314
                                        this.valid = true;
                                        return this.dropAllowed;
                                    }
                                    this.valid = false;
                                    return this.dropNotAllowed;
                                },
1be6ea03   Erdogan Furkan   #10098 - Final co...
315
                                notifyDrop: function (ddSource, e, data) {
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
316
317
318
319
                                    if (!this.valid)
                                        return false;
                                    var visuModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.visu.id);
                                    if (visuModule) {
1be6ea03   Erdogan Furkan   #10098 - Final co...
320

75a90e82   Hacene SI HADJ MOHAND   ticket ok
321
                                        var catNode = data.records[0];
1be6ea03   Erdogan Furkan   #10098 - Final co...
322
                                        AmdaAction.getObject(catNode.get('id'), catNode.get('nodeType'), function (result, remoteEvent) {
75a90e82   Hacene SI HADJ MOHAND   ticket ok
323
                                            var catObj = Ext.create(catNode.get('objectDataModel'), result);
1be6ea03   Erdogan Furkan   #10098 - Final co...
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
                                            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;
                                            }

75a90e82   Hacene SI HADJ MOHAND   ticket ok
339
                                        }, this);
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
340
341
342
343
                                    }
                                    return true;
                                }
                            });
1be6ea03   Erdogan Furkan   #10098 - Final co...
344
345
                }
            }
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
346
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
        });

        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
373
374
    }
});