Blame view

js/app/views/VisuUI.js 12.5 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
        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...
57
    loadObject: function () {
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
58
59
        var me = this;

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

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

            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...
97
98
            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...
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
            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
124
            });
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
125
126
127

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

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

        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...
147
    fclose: function () {
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
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
        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
185
            {
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
186
187
188
                title: 'Scatter',
                widget: 'widget.panelCatalogVisuScatter'
            },
33705dc4   Benjamin Renard   Catalog visu rework
189
            {
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
190
191
192
193
194
195
196
                title: 'Histogram',
                widget: 'widget.panelCatalogVisuHistogram'
            }
        ];

        var isFirst = true;
        Ext.Array.each(chartTypes, function (chartType) {
1be6ea03   Erdogan Furkan   #10098 - Final co...
197
            var tabContent = Ext.create(chartType.widget, { parametersStore: me.parametersStore });
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
            var tab = tabPanel.add({
                title: chartType.title,
                items: [
                    tabContent
                ],
                layout: 'fit'
            });
            me.visuTabContents.push(tabContent);
            if (isFirst) {
                tabPanel.setActiveTab(tab);
                isFirst = false;
            }
        });
    },

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

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

        this.emptyChartConfig = {
            xtype: 'chart',
            region: 'center',
            store: this.catalogStore,
            id: 'visu-chart',
            animate: false,
            mask: false,
            shadow: false,
            theme: 'Blue',
1be6ea03   Erdogan Furkan   #10098 - Final co...
236
            background: { fill: "#fff" }
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
237
238
239
240
241
        };

        this.formPanel = Ext.create('Ext.form.Panel', {
            region: 'center',
            layout: 'border',
1be6ea03   Erdogan Furkan   #10098 - Final co...
242
243
            bodyStyle: { background: '#dfe8f6' },
            defaults: { border: false, align: 'stretch', padding: '3' },
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
244
245
246
247
248
249
250
251
            items: [
                {
                    xtype: 'fieldset',
                    region: 'north',
                    items: [
                        {
                            xtype: 'fieldcontainer',
                            layout: 'hbox',
1be6ea03   Erdogan Furkan   #10098 - Final co...
252
                            fieldDefaults: { labelWidth: 80, labelAlign: 'right' },
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
253
                            items: [
1be6ea03   Erdogan Furkan   #10098 - Final co...
254
255
256
                                { 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...
257
258
259
260
261
262
263
264
265
266
267
268
269
                            ]
                        }
                    ],
                },
                {
                    xtype: 'container',
                    region: 'center',
                    layout: 'border',
                    items: [
                        {
                            xtype: 'tabpanel',
                            region: 'west',
                            width: 250,
33705dc4   Benjamin Renard   Catalog visu rework
270
//              height: 400,
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
271
272
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
                            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:
1be6ea03   Erdogan Furkan   #10098 - Final co...
298
299
300
301
302
303
304
            {
                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...
305
306

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

75a90e82   Hacene SI HADJ MOHAND   ticket ok
323
                                        var catNode = data.records[0];
1be6ea03   Erdogan Furkan   #10098 - Final co...
324
                                        AmdaAction.getObject(catNode.get('id'), catNode.get('nodeType'), function (result, remoteEvent) {
75a90e82   Hacene SI HADJ MOHAND   ticket ok
325
                                            var catObj = Ext.create(catNode.get('objectDataModel'), result);
1be6ea03   Erdogan Furkan   #10098 - Final co...
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
                                            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
341
                                        }, this);
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
342
343
344
345
                                    }
                                    return true;
                                }
                            });
1be6ea03   Erdogan Furkan   #10098 - Final co...
346
347
                }
            }
d9a1b6f6   Hacene SI HADJ MOHAND   ajout de fonction...
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
        });

        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
375
376
    }
});