EpnTapModule.js
17.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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
89
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
127
128
129
130
131
132
133
134
135
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
189
190
191
192
193
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
275
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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
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
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
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
/**
* Project : AMDA-NG
* Name : EpnTapModule.js
* @class amdaDesktop.EpnTapModule
* @extends amdaDesktop.AmdaModule
* @brief EpnTap Module controller definition
* @author Nathanael Jourdane
*/
Ext.define('amdaDesktop.EpnTapModule', {
extend: 'amdaDesktop.AmdaModule',
requires: ['amdaUI.EpnTapUI'],
// contentId : 'EpnTapUI',
/** The alias name of the module view. */
uiType: 'panelEpnTap',
/** The text displayed on the *help button* tooltip. */
helpTitle: 'Help on EPN-TAP Module',
/** The name of the documentation file related to the module. */
helpFile : 'epnTapHelp',
/**
Module initialisation.
*/
init: function() {
this.select = Array();
this.filter = Array();
this.selectedServiceId = null;
this.launcher = {
text: this.title,
iconCls: this.icon,
handler: this.createWindow,
scope: this
};
},
/**
Capitalize a name and replace underscores with spaces.
- `name`: The string to make pretty.
*/
prettify: function(name) {
return name.charAt(0).toUpperCase() + name.replace(/_/g, ' ').substr(1).toLowerCase();
},
/**
Capitalize a name, replace underscores with spaces, and write it in a plurial form.
- `name`: The string to make pretty.
*/
allPrettify: function(name) {
return 'All ' + (name[name.length-1] == 's' ? name : name + 's').replace(/_/g, ' ').toLowerCase();
},
isDate: function(date) {
if (date === null) {
return false;
}
var dateArr = date.split('/');
if (dateArr.length != 3 || isNaN(parseInt(dateArr[0])) || isNaN(parseInt(dateArr[1])) || isNaN(parseInt(dateArr[2])) ) {
return false;
}
return true;
},
/****************************
*** Service filter events ***
****************************/
createWindow: function (icon_id) {
this.callParent();
this.epnTapPanel.setSize(800, 600);
var icons_dic = {
'icon-mercury': ['ts', 'planet', 'mercury'],
'icon-venus': ['ts', 'planet', 'venus'],
'icon-earth': ['ts', 'planet', 'earth'],
'icon-mars': ['ts', 'planet', 'mars'],
'icon-jupiter': ['ts', 'planet', 'jupiter'],
'icon-saturn': ['ts', 'planet', 'saturn'],
'icon-comet': ['ts', 'comet', 'comet'],
'icon-sw': ['ts', 'interplanetary_medium', 'all'],
'icon-solarsystem': ['ts', 'interplanetary_medium', 'all']
}
var target = icons_dic[icon_id];
// console.log("target: ", target);
this.initWindow(target);
},
/**
Trigerred after the render of `gridsPanel` (containing `servicesGrid` and `granulesGrid`). Among other things,
initializes the `productType` combobox and the `servicesGrid` table.
- `target`: an array of 3 values: [dataproduct_type, target_class, target_name]; or null.
*/
initWindow: function(target) {
Ext.data.StoreManager.lookup('servicesStore').on('add', function() { this.updateNbResults(); }, this);
Ext.data.StoreManager.lookup('servicesStore').load();
Ext.data.StoreManager.lookup('metadataStore').load();
this.productTypeCB = Ext.getCmp('epnTapProductTypeCB');
this.targetClassCB = Ext.getCmp('epnTapTargetClassCB');
this.targetNameCB = Ext.getCmp('epnTapTargetNameCB');
this.timeSelector = Ext.getCmp('epnTapTimeSelector');
this.rowsPerPageNf = Ext.getCmp('epnTapRowsPerPageNf');
this.servicesGrid = Ext.getCmp('epnTapServicesGrid');
this.granulesGrid = Ext.getCmp('epnTapGranulesGrid');
this.currentPageLb = Ext.getCmp('epnTapCurrentPageLb');
this.totalPagesLb = Ext.getCmp('epnTapTotalPagesLb');
this.firstPageBtn = Ext.getCmp('epnTapFirstPageBtn');
this.previousPageBtn = Ext.getCmp('epnTapPreviousPageBtn');
this.nextPageBtn = Ext.getCmp('epnTapNextPageBtn');
this.lastPageBtn = Ext.getCmp('epnTapLastPageBtn');
this.epnTapPanel = this.productTypeCB.findParentByType('panelEpnTap');
// If the EPN-TAP module is launched from the AMDA tree
if(target) {
// --- Select product types ---
if (! target[0] in this.productTypeCB.getStore()) {
alert("Sorry, product type " + target[0] + " is not found in available services.");
return;
}
this.productTypeCB.select(target[0]);
this.onProductTypeCBChanged(); // Fill target class CB
// --- Select target class ---
if (! target[1] in this.targetClassCB.getStore()) {
alert("Sorry, target class " + this.pretify(target[1]) + " is not found in available services.");
return;
}
this.targetClassCB.select(target[1]);
this.onTargetClassCBChanged();
// --- Select target name ---
if (! target[2] in this.targetNameCB.getStore()) {
alert("Sorry, target name " + this.pretify(target[2]) + " is not found in available services.");
return;
}
this.targetNameCB.select(target[2]);
this.onTargetNameCBChanged();
// If the EPN-TAP module is launched from the Interop window
} else {
this.productTypeCB.select('all');
// Update targetClassCB
this.targetClassCB.getStore().add({'id': 'all', 'name': 'All target classes'});
this.targetClassCB.select('all');
this.targetClassCB.disable();
// Update targetNameCB
this.targetNameCB.getStore().add({'id': 'all', 'name': 'All target names'});
this.targetNameCB.select('all');
this.targetNameCB.disable();
}
},
/**
Trigerred when *the user* (not `productTypeCB.select()`) select a new item in `productTypeCB`
(see `EpnTapUI.createProductTypeCB()`).
Among other things, updates the `targetClassCB` combobox and the `servicesGrid` table.
*/
onProductTypeCBChanged: function() {
this.targetClassCB.getStore().removeAll();
this.targetNameCB.getStore().removeAll();
this.targetNameCB.disable();
if (this.productTypeCB.value == 'all') {
this.targetClassCB.disable();
} else {
Ext.data.StoreManager.lookup('metadataStore').filter('dataproduct_type', this.productTypeCB.value)
var targetClasses = Ext.data.StoreManager.lookup('metadataStore').collect('target_class');
if (targetClasses.length == 1) {
this.targetClassCB.getStore().add({'id': targetClasses[0], 'name': this.prettify(targetClasses[0])});
this.targetClassCB.disable();
this.targetClassCB.select(this.targetClassCB.getStore().getAt(0)['internalId']);
} else {
this.targetClassCB.getStore().add({'id': 'all', 'name': this.allPrettify(productTypeDict[this.productTypeCB.value])});
for (var i = 0; i < targetClasses.length; i++) {
this.targetClassCB.getStore().add({'id': targetClasses[i], 'name': this.prettify(targetClasses[i])});
}
this.targetClassCB.select('all');
this.targetClassCB.enable();
}
}
this.targetNameCB.getStore().add({'id': 'all', 'name': 'All target names'});
this.targetNameCB.select('all');
this.updateNbResults();
},
/**
Trigerred when *the user* (not `targetClassCB.select()`) select a new item in `targetClassCB` (see
`EpnTapUI.createTargetClassCB()`).
Among other things, updates the `targetNameCB` combobox and the `servicesGrid` table.
*/
onTargetClassCBChanged: function() {
this.targetNameCB.getStore().removeAll();
if (this.targetClassCB.value == 'all') {
this.targetNameCB.getStore().add({'id': 'all', 'name': 'All target names'});
this.targetNameCB.select('all');
this.targetNameCB.disable();
} else {
Ext.data.StoreManager.lookup('metadataStore').filter('target_class', this.targetClassCB.value);
var targetNames = Ext.data.StoreManager.lookup('metadataStore').collect('target_name');
if (targetNames.length == 1) {
this.targetNameCB.getStore().add({'id': targetNames[0], 'name': this.prettify(targetNames[0])});
this.targetNameCB.select(this.targetNameCB.getStore().getAt(0)['internalId']);
this.targetNameCB.disable();
} else {
this.targetNameCB.getStore().add({'id': 'all', 'name': this.allPrettify(this.targetClassCB.value)});
for (var i = 0; i < targetNames.length; i++) {
this.targetNameCB.getStore().add({'id': targetNames[i], 'name': this.prettify(targetNames[i])});
}
this.targetNameCB.select('all');
this.targetNameCB.enable();
}
}
this.updateNbResults();
},
/**
Trigerred when *the user* (not `targetClassCB.select()`) select a new item in `targetNameCB`
(see `EpnTapUI.createTargetNameCB()`).
Updates the `servicesGrid` table.
*/
onTargetNameCBChanged: function() {
this.updateNbResults();
},
/**
Trigerred when the value of `rowsPerPageNf` is updated (see `EpnTapUI.createRowsPerPageNf()`). Do nothing yet, used
for debug purposes only.
*/
onRowsPerPageChanged: function() {
// console.log("rows per page: " + this.productTypeCB);
},
/*********************
*** Buttons events ***
*********************/
/**
Disable or enable the navigation buttons (see `EpnTapUI.createNavigationPanel()`).
*/
disableNavBtns: function(firt, previous, next, last) {
Ext.getCmp('epnTapFirstPageBtn').setDisabled(firt);
Ext.getCmp('epnTapPreviousPageBtn').setDisabled(previous);
Ext.getCmp('epnTapNextPageBtn').setDisabled(next);
Ext.getCmp('epnTapLastPageBtn').setDisabled(last);
},
/**
Trigerred when the `firstPageBtn` button is clicked (see `EpnTapUI.createNavigationPanel()`). Among other things,
send a new query and fill `granulesGrid`.
*/
onFirstPageBtnClicked: function() {
var newPageNumber = 1;
var limit = Number(this.rowsPerPageNf.value);
var offset = 0;
var selectedServiceURL = Ext.data.StoreManager.lookup('servicesStore').getById(this.selectedServiceId)['accessurl'];
this.wait();
this.disableNavBtns(true, true, false, false);
this.currentPageLb.setText('' + newPageNumber);
AmdaAction.epnTapGetGranules(this.selectedServiceId, selectedServiceURL, this.filter, this.select, limit, offset, this.fillGranules);
},
/**
Trigerred when the `previousPageBtn` button is clicked (see `EpnTapUI.createNavigationPanel()`). Among other things,
send a new query and fill `granulesGrid`.
*/
onPreviousPageBtnClicked: function() {
var newPageNumber = Number(this.currentPageLb.text) - 1;
var limit = Number(this.rowsPerPageNf.value);
var offset = (newPageNumber-1) * limit;
var selectedServiceURL = Ext.data.StoreManager.lookup('servicesStore').getById(this.selectedServiceId)['accessurl'];
this.wait();
this.currentPageLb.setText('' + newPageNumber);
var isFirstPage = this.currentPageLb.text === '1';
this.disableNavBtns(isFirstPage, isFirstPage, false, false);
AmdaAction.epnTapGetGranules(this.selectedServiceId, selectedServiceURL, this.filter, this.select, limit, offset, this.fillGranules);
},
/**
Trigerred when the `nextPageBtn` button is clicked (see `EpnTapUI.createNavigationPanel()`). Among other things,
send a new query and fill `granulesGrid`.
*/
onNextPageBtnClicked: function() {
var newPageNumber = Number(this.currentPageLb.text) + 1;
var limit = Number(this.rowsPerPageNf.value);
var offset = (newPageNumber-1) * limit;
var selectedServiceURL = Ext.data.StoreManager.lookup('servicesStore').getById(this.selectedServiceId)['accessurl'];
this.wait();
this.currentPageLb.setText('' + newPageNumber);
var isLastPage = this.currentPageLb.text == this.totalPagesLb.text;
this.disableNavBtns(false, false, isLastPage, isLastPage);
AmdaAction.epnTapGetGranules(this.selectedServiceId, selectedServiceURL, this.filter, this.select, limit, offset, this.fillGranules);
},
/**
Trigerred when the `lastPageBtn` button is clicked (see `EpnTapUI.createNavigationPanel()`). Among other things,
send a new query and fill `granulesGrid`.
*/
onLastPageBtnClicked: function() {
var newPageNumber = Number(this.totalPagesLb.text);
var limit = Number(this.rowsPerPageNf.value);
var offset = (newPageNumber-1) * limit;
var selectedServiceURL = Ext.data.StoreManager.lookup('servicesStore').getById(this.selectedServiceId)['accessurl'];
this.wait();
this.currentPageLb.setText('' + newPageNumber);
this.disableNavBtns(false, false, true, true);
AmdaAction.epnTapGetGranules(this.selectedServiceId, selectedServiceURL, this.filter, this.select, limit, offset, this.fillGranules);
},
/*******************
*** Grids events ***
*******************/
/**
Trigerred when a row is clicked in `servicesGrid` table (see `EpnTapUI.createServicesGrid()`). Among other things,
send a new query and fill `granulesGrid`.
*/
onServiceSelected: function(selectedServiceId) {
// console.log("Selected service " + selectedServiceId);
this.wait();
this.selectedServiceId = selectedServiceId;
this.select = Array();
var selectedService = Ext.data.StoreManager.lookup('servicesStore').findRecord('id', selectedServiceId).data;
console.log(selectedService);
if (selectedService == null) {
throw this.selectedServiceId + ' not found in the list of services.';
return;
}
var columns = selectedService['columns'].split(',');
for (var ic=0 ; ic<this.granulesGrid.columns.length ; ic++) {
if (columns.indexOf(this.granulesGrid.columns[ic].dataIndex) != -1) {
this.select.push(this.granulesGrid.columns[ic].dataIndex);
}
}
this.filter = Array(
this.productTypeCB.value === 'all' ? null : this.productTypeCB.value, // product type
this.targetNameCB.value === 'all' ? null : this.targetNameCB.value, // target name
Ext.Date.format(this.timeSelector.getStartTime(), 'd/m/Y H:i:s'), // start time
Ext.Date.format(this.timeSelector.getStopTime(), 'd/m/Y H:i:s') // stop time
);
// console.log(selectedServiceId, selectedService['access_url'], this.filter);
AmdaAction.epnTapGetNbRows(selectedServiceId, selectedService['access_url'], this.filter, this.updateNbRows);
AmdaAction.epnTapGetGranules(selectedServiceId, selectedService['access_url'], this.filter, this.select, this.rowsPerPageNf.value, 0, this.fillGranules);
},
/**
Trigerred when a row is clicked in `granulesGrid` table (see `EpnTapUI.createGranulesGrid()`). Do nothing yet, used
for debug purposes only.
*/
onGranuleSelected: function(granule) {
// console.log('selected granule: ', granule);
},
/**********************
*** Other functions ***
**********************/
/**
Update the nb_result field of the services store (see `EpnTapUI.servicesStore`), according to the field values in `serviceFilterPanel`.
*/
updateNbResults: function() {
var productType = Ext.getCmp('epnTapProductTypeCB').value;
var targetClass = Ext.getCmp('epnTapTargetClassCB').value;
var targetName = Ext.getCmp('epnTapTargetNameCB').value;
var metadataStore = Ext.data.StoreManager.lookup('metadataStore');
var servicesStore = Ext.data.StoreManager.lookup('servicesStore');
var timeSelector = Ext.getCmp('epnTapTimeSelector');
if(productType === 'all' && !this.launchedFromTree ) {
var filter = [];
} else if(targetClass === 'all') {
var filter = [
{property: "dataproduct_type", value: productType}
];
} else if(targetName === 'all') {
var filter = [
{property: "dataproduct_type", value: productType},
{property: "target_class", value: targetClass}
];
} else {
var filter = [
{property: "dataproduct_type", value: productType},
{property: "target_class", value: targetClass},
{property: "target_name", value: targetName}
];
}
servicesStore.each(function(record, idx) {
metadataStore.filter(filter.concat({property: 'service_id', value: record.get('id')}));
record.set('nb_results', metadataStore.sum('nb_results'));
metadataStore.clearFilter();
});
servicesStore.sort('nb_results', 'DESC');
var timeMin = metadataStore.min('time_min');
var timeMax = metadataStore.max('time_max');
timeSelector.setLimits(timeMin, timeMax);
timeSelector.setInterval(timeMin, timeMax);
},
/**
Callback function, called from the PHP script when the query result is received, when a service is selected.
Among other things, update the `epnTapCurrentPageLb` label (see `EpnTapUI.createNavigationPanel()`).
*/
updateNbRows: function(nb_results) {
var totalPages = Math.ceil(Number(nb_results) / Ext.getCmp('epnTapRowsPerPageNf').value);
Ext.getCmp('epnTapCurrentPageLb').setText(totalPages == 0 ? '-' : '1');
Ext.getCmp('epnTapTotalPagesLb').setText(totalPages == 0 ? '-' : totalPages);
Ext.getCmp('epnTapPreviousPageBtn').setDisabled(true);
Ext.getCmp('epnTapFirstPageBtn').setDisabled(true);
Ext.getCmp('epnTapNextPageBtn').setDisabled(totalPages <= 1);
Ext.getCmp('epnTapLastPageBtn').setDisabled(totalPages <= 1);
},
/**
Callback function, called from the PHP script when the query result is received, when a service is selected or a
navigation button is clicked.
Among other things, fill the `epnTapGranulesGrid` table (see `EpnTapUI.granulesStore`).
*/
fillGranules: function(granules) {
if (granules["error"] != null) {
console.log('Can not get request response:', granules["error"]);
} else {
try {
Ext.getCmp('epnTapGranulesGrid').getStore().removeAll();
Ext.getCmp('epnTapGranulesGrid').getStore().add(granules);
} catch( e ) {
console.log('Can not add granules: ' + e);
}
}
Ext.getCmp('epnTapServicesGrid').setDisabled(false);
Ext.getCmp('epnTapGranulesGrid').setDisabled(false);
Ext.getCmp('epnTapServicesGrid').getEl().setStyle('cursor', 'default'); // CSS is correctly changed but without visible result.
},
/**
Called before to send a query. Set the EpnTap panel in "waiting mode", informing to the user that a request is
processing. The altered elements are resetted in `fillGranules()`.
*/
wait: function() {
this.servicesGrid.getEl().setStyle('cursor', 'wait'); // CSS is correctly changed but without visible result.
this.servicesGrid.setDisabled(true);
this.granulesGrid.setDisabled(true);
}
});