Commit 1fecb221a4c82ee15bfc37f942b961b5c83f2098
1 parent
d6674d39
Exists in
master
and in
111 other branches
Fill granules grid on Send btn click
Showing
1 changed file
with
57 additions
and
28 deletions
Show diff stats
js/app/controllers/EpnTapModule.js
... | ... | @@ -88,7 +88,7 @@ Ext.define('amdaDesktop.EpnTapModule', { |
88 | 88 | }, this); |
89 | 89 | |
90 | 90 | this.servicesGrid.on('cellclick', function(grid, td, cellIndex, record) { |
91 | - this.onServiceSelected(record.data['id']); | |
91 | + this.onServiceSelected(record); | |
92 | 92 | }, this); |
93 | 93 | |
94 | 94 | this.granulesGrid.on('cellclick', function(grid, td, cellIndex, record) { |
... | ... | @@ -270,13 +270,12 @@ Ext.define('amdaDesktop.EpnTapModule', { |
270 | 270 | var timeMin = Ext.Date.format(this.timeSelector.getStartTime(), 'd/m/Y H:i:s'); // start time |
271 | 271 | var timeMax = Ext.Date.format(this.timeSelector.getStopTime(), 'd/m/Y H:i:s'); // stop time |
272 | 272 | |
273 | + loadMask.show(); | |
273 | 274 | this.servicesStore.each(function(record) { |
274 | 275 | Ext.Ajax.request({ |
275 | 276 | url: 'php/epntap.php', |
276 | 277 | method: 'GET', |
277 | 278 | headers: {'Content-Type': 'application/json'}, |
278 | - waitTitle: 'Connecting', | |
279 | - waitMsg: 'Sending data...', | |
280 | 279 | params: { |
281 | 280 | 'action': 'getNbResults', |
282 | 281 | 'serviceId': record.data['id'], |
... | ... | @@ -288,29 +287,35 @@ Ext.define('amdaDesktop.EpnTapModule', { |
288 | 287 | 'timeMax': timeMax |
289 | 288 | }, |
290 | 289 | success: this.updateNbResults, |
291 | - failure: this.onRequestFailure, | |
290 | + failure: this.updateNbResultsFail, | |
292 | 291 | scope: this |
293 | 292 | }); |
294 | - // AmdaAction.epnTapGetNbResults(url, tableName, targetName, productType, timeMin, timeMax, this.updateNbResults); | |
295 | 293 | }, this); |
296 | 294 | }, |
297 | 295 | |
298 | - onRequestFailure: function(response) { | |
299 | - var reason = response.status === 200 ? response.responseText : response.statusText; | |
300 | - console.log(response.request.options.params['serviceId'] + ' failed: ' + reason); | |
301 | - }, | |
302 | - | |
303 | 296 | /** |
304 | 297 | Update the nb_result field of the services store (see `EpnTapUI.servicesStore`), according to the field values in `serviceFilterPanel`. |
305 | 298 | */ |
306 | 299 | updateNbResults: function(response) { |
307 | 300 | if(response.status !== 200 || isNaN(response.responseText)) { |
308 | - this.onRequestFailure(response); | |
301 | + this.updateNbResultsFail(response); | |
309 | 302 | } else { |
310 | 303 | var record = this.servicesStore.getById(response.request.options.params['serviceId']); |
304 | + var nbRes = Number(response.responseText); | |
311 | 305 | record.set('nb_results', response.responseText); |
306 | + record.set('error', ''); | |
307 | + record.set('info', 'The service returned ' + (nbRes == 0 ? 'any' : nbRes) + ' result' + (nbRes > 1 ? 's' : '') + ' for the given query.'); | |
312 | 308 | this.servicesStore.sort(); |
313 | 309 | } |
310 | + loadMask.hide(); | |
311 | + }, | |
312 | + | |
313 | + updateNbResultsFail: function(response) { | |
314 | + var record = this.servicesStore.getById(response.request.options.params['serviceId']); | |
315 | + var reason = response.status === 200 ? response.responseText : response.statusText; | |
316 | + record.set('error', reason); | |
317 | + record.set('info', ''); | |
318 | + loadMask.hide(); | |
314 | 319 | }, |
315 | 320 | |
316 | 321 | /******************* |
... | ... | @@ -321,33 +326,57 @@ Ext.define('amdaDesktop.EpnTapModule', { |
321 | 326 | Trigerred when a row is clicked in `servicesGrid` table (see `EpnTapUI.createServicesGrid()`). Among other things, |
322 | 327 | send a new query and fill `granulesGrid`. |
323 | 328 | */ |
324 | - onServiceSelected: function(selectedServiceId) { | |
325 | - // console.log("Selected service " + selectedServiceId); | |
326 | - var selectedService = this.servicesStore.findRecord('id', selectedServiceId).data; | |
327 | - | |
328 | - this.selectedServiceId = selectedServiceId; | |
329 | - if (selectedService == null) { | |
330 | - throw this.selectedServiceId + ' not found in the list of services.'; | |
329 | + onServiceSelected: function(record) { | |
330 | + var nbRes = record.get('nb_results'); | |
331 | + if(nbRes <= 0 || isNaN(nbRes)) { | |
331 | 332 | return; |
332 | 333 | } |
333 | - | |
334 | - this.filter = Array( | |
335 | - this.targetNameCB.value === 'all' ? null : this.targetNameCB.value, // target name | |
336 | - this.productTypeCB.value === 'all' ? null : this.productTypeCB.value, // product type | |
337 | - Ext.Date.format(this.timeSelector.getStartTime(), 'd/m/Y H:i:s'), // start time | |
338 | - Ext.Date.format(this.timeSelector.getStopTime(), 'd/m/Y H:i:s') // stop time | |
339 | - ); | |
334 | + var targetName = this.targetNameCB.rawValue; | |
335 | + var productTypes = this.productTypeCB.value.join(';'); | |
336 | + var timeMin = Ext.Date.format(this.timeSelector.getStartTime(), 'd/m/Y H:i:s'); // start time | |
337 | + var timeMax = Ext.Date.format(this.timeSelector.getStopTime(), 'd/m/Y H:i:s'); // stop time | |
340 | 338 | |
341 | 339 | loadMask.show(); |
342 | - AmdaAction.epnTapGetNbRows(selectedService['table_name'], selectedService['access_url'], this.filter, this.updateNbRows); | |
343 | - AmdaAction.epnTapGetGranules(selectedService['table_name'], selectedService['access_url'], this.filter, this.rowsPerPageNf.value, 0, this.fillGranules); | |
340 | + Ext.Ajax.request({ | |
341 | + url: 'php/epntap.php', | |
342 | + method: 'GET', | |
343 | + headers: {'Content-Type': 'application/json'}, | |
344 | + // waitTitle: 'Connecting', | |
345 | + // waitMsg: 'Sending data...', | |
346 | + params: { | |
347 | + 'action': 'getGranules', | |
348 | + 'url': record.data['access_url'], | |
349 | + 'tableName': record.data['table_name'], | |
350 | + 'targetName': targetName, | |
351 | + 'productTypes': productTypes, | |
352 | + 'timeMin': timeMin, | |
353 | + 'timeMax': timeMax | |
354 | + }, | |
355 | + success: this.updateGranules, | |
356 | + failure: this.updateGranulesFail, | |
357 | + scope: this | |
358 | + }); | |
359 | + }, | |
360 | + | |
361 | + updateGranules: function(response) { | |
362 | + try { | |
363 | + granules = JSON.parse(response.responseText); | |
364 | + } catch (e) { | |
365 | + response.responseText = 'Can not decode the returned Json.' | |
366 | + this.updateGranulesFail(response); | |
367 | + } | |
368 | + this.granulesStore.add(granules); | |
369 | + loadMask.hide(); | |
344 | 370 | }, |
345 | 371 | |
346 | 372 | /** |
347 | 373 | Trigerred when a row is clicked in `granulesGrid` table (see `EpnTapUI.createGranulesGrid()`). Do nothing yet, used |
348 | 374 | for debug purposes only. |
349 | 375 | */ |
350 | - onGranuleSelected: function(granule) { | |
376 | + updateGranulesFail: function(granule) { | |
377 | + var reason = response.status === 200 ? response.responseText : response.statusText; | |
378 | + Ext.Msg.alert('Can not display granules: ' + reason); | |
379 | + loadMask.hide(); | |
351 | 380 | // console.log('selected granule: ', granule); |
352 | 381 | }, |
353 | 382 | ... | ... |