Blame view

js/app/controllers/EpnTapModule.js 6.04 KB
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
1
2
/**
 * Project  : AMDA-NG
428eb66e   Nathanael Jourdane   Use JS standard c...
3
 * Name   : EpnTapModule.js
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
4
5
6
7
8
9
 * @class   amdaDesktop.EpnTapModule
 * @extends amdaDesktop.AmdaModule
 * @brief   EpnTap Module controller definition
 * @author  Nathanael Jourdane
 */

76d60878   Nathanael Jourdane   Add compatibility...
10
'use strict'
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
11
12
Ext.define('amdaDesktop.EpnTapModule', {

428eb66e   Nathanael Jourdane   Use JS standard c...
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
  extend: 'amdaDesktop.AmdaModule',
  requires: ['amdaUI.EpnTapUI'],
  contentId: 'EpnTapUI',

  /** The alias name of the module view. */
  // uiType: 'panelEpnTap',
  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. Called the first time that the user open the epnTap module.
  */
  init: function () {
    this.launcher = {
      text: this.title,
      iconCls: this.icon,
      handler: this.createWindow,
      scope: this
    }
  },

  /**
538afb92   Nathanael Jourdane   Refactoring
40
41
42
   Called each time the epntap module is loaded.
   - `target`: an array of 3 values: [target_name, dataproduct_type]; or null.
   */
428eb66e   Nathanael Jourdane   Use JS standard c...
43
  loadTarget: function (filter) {
538afb92   Nathanael Jourdane   Refactoring
44
    this.acquireElements()
428eb66e   Nathanael Jourdane   Use JS standard c...
45
46
    this.addListeners()

428eb66e   Nathanael Jourdane   Use JS standard c...
47
48
49
    if (filter) {
      this.targetNameCB.setRawValue(filter['targetName'])
      this.productTypeCB.select(filter['productType'])
feed9c98   Nathanael Jourdane   Update services r...
50
      if (this.servicesStore.count() > 0) {
853c8154   Nathanael Jourdane   Init start/stop d...
51
        this.updateNbResults()
feed9c98   Nathanael Jourdane   Update services r...
52
53
54
55
56
57
      }
    } else {
      this.servicesStore.each(function (record) {
        record.set('nb_results', -1)
      }, this)
      this.granulesStore.removeAll()
428eb66e   Nathanael Jourdane   Use JS standard c...
58
59
60
    }
  },

538afb92   Nathanael Jourdane   Refactoring
61
  acquireElements: function () {
428eb66e   Nathanael Jourdane   Use JS standard c...
62
63
    // UI elements
    this.servicesGrid = Ext.getCmp('epnTapServicesGrid')
428eb66e   Nathanael Jourdane   Use JS standard c...
64
65
66
67
68
69
70
71
72
73
74
75
76
    this.productTypeCB = Ext.getCmp('epnTapProductTypeCB')
    this.targetNameCB = Ext.getCmp('epnTapTargetNameCB')
    this.timeSelector = Ext.getCmp('epnTapTimeSelector')
    this.getBtn = Ext.getCmp('epnTapGetBtn')

    // stores elements
    this.servicesStore = Ext.data.StoreManager.lookup('servicesStore')
    this.granulesStore = Ext.data.StoreManager.lookup('granulesStore')
    this.productTypesStore = Ext.data.StoreManager.lookup('productTypesStore')
    this.targetNamesStore = Ext.data.StoreManager.lookup('targetNamesStore')
  },

  addListeners: function () {
feed9c98   Nathanael Jourdane   Update services r...
77
    this.servicesStore.on('load', function () {
853c8154   Nathanael Jourdane   Init start/stop d...
78
      this.updateNbResults()
feed9c98   Nathanael Jourdane   Update services r...
79
80
    }, this)

428eb66e   Nathanael Jourdane   Use JS standard c...
81
82
83
84
85
    this.servicesGrid.on('cellclick', function (grid, td, cellIndex, record) {
      this.onServiceSelected(record)
    }, this)

    this.getBtn.on('click', function () {
853c8154   Nathanael Jourdane   Init start/stop d...
86
      this.updateNbResults()
428eb66e   Nathanael Jourdane   Use JS standard c...
87
88
89
    }, this)
  },

428eb66e   Nathanael Jourdane   Use JS standard c...
90
91
92
93
94
  /*************
  *** Events ***
  *************/

  /**
538afb92   Nathanael Jourdane   Refactoring
95
96
   Triggered when the 'Get results' button is clicked.
   */
853c8154   Nathanael Jourdane   Init start/stop d...
97
  updateNbResults: function () {
538afb92   Nathanael Jourdane   Refactoring
98
    /* global loadMask */
feed9c98   Nathanael Jourdane   Update services r...
99
100
101
102
    loadMask.show()

    const targetName = this.targetNameCB.rawValue
    const productTypes = this.productTypeCB.value.join(';')
853c8154   Nathanael Jourdane   Init start/stop d...
103
104
105
106
    const initTMin = this.timeSelector.getStartTime()
    const initTMax = this.timeSelector.getStopTime()
    const initTMinStr = Ext.Date.format(initTMin, 'd/m/Y H:i:s')
    const initTMaxStr = Ext.Date.format(initTMax, 'd/m/Y H:i:s')
feed9c98   Nathanael Jourdane   Update services r...
107

81bfd64a   Nathanael Jourdane   Reset nb results ...
108
109
110
    this.servicesStore.each(function (record) {
      record.set('nb_results', -1)
    }, this)
428eb66e   Nathanael Jourdane   Use JS standard c...
111
    this.granulesStore.removeAll()
428eb66e   Nathanael Jourdane   Use JS standard c...
112

428eb66e   Nathanael Jourdane   Use JS standard c...
113
    this.servicesStore.each(function (record) {
538afb92   Nathanael Jourdane   Refactoring
114
      const ss = this.servicesStore
428eb66e   Nathanael Jourdane   Use JS standard c...
115
116
117
118
119
      Ext.Ajax.request({
        url: 'php/epntap.php',
        method: 'GET',
        headers: {'Content-Type': 'application/json'},
        params: {
853c8154   Nathanael Jourdane   Init start/stop d...
120
          'action': 'updateNbResults',
428eb66e   Nathanael Jourdane   Use JS standard c...
121
122
123
124
125
          'serviceId': record.data['id'],
          'url': record.data['access_url'],
          'tableName': record.data['table_name'],
          'targetNames': targetName,
          'productTypes': productTypes,
853c8154   Nathanael Jourdane   Init start/stop d...
126
127
          'timeMin': initTMinStr,
          'timeMax': initTMaxStr
428eb66e   Nathanael Jourdane   Use JS standard c...
128
129
130
        },
        // timeout: 3000,
        success: function (response, options) {
538afb92   Nathanael Jourdane   Refactoring
131
132
133
          const record = ss.getById(options.params['serviceId'])
          // noinspection JSValidateTypes
          const responseObj = Ext.decode(response.responseText)
853c8154   Nathanael Jourdane   Init start/stop d...
134
          this.updateService(record, responseObj['success'] ? responseObj['data'] : {'nbRes': -2}, responseObj['msg'], initTMin, initTMax)
428eb66e   Nathanael Jourdane   Use JS standard c...
135
136
        },
        failure: function (response, options) {
538afb92   Nathanael Jourdane   Refactoring
137
          const record = ss.getById(options.params['serviceId'])
428eb66e   Nathanael Jourdane   Use JS standard c...
138
139
140
141
142
143
144
145
          this.updateService(record, -1, response.statusText)
        },
        scope: this
      })
    }, this)
  },

  /**
538afb92   Nathanael Jourdane   Refactoring
146
147
   Update the nb_result field of the services store (see `EpnTapUI.servicesStore`), according to the field values in `serviceFilterPanel`.
   */
853c8154   Nathanael Jourdane   Init start/stop d...
148
149
150
151
  updateService: function (record, data, info, timeMin, timeMax) {
    record.set('nb_results', data['nbRes'])
    record.set('time_min', data['tMin'])
    record.set('time_max', data['tMax'])
428eb66e   Nathanael Jourdane   Use JS standard c...
152
    record.set('info', info)
853c8154   Nathanael Jourdane   Init start/stop d...
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170

    const tMinService = Ext.Date.parse(data['tMin'], 'd/m/Y H:i:s')
    const tMaxService = Ext.Date.parse(data['tMax'], 'd/m/Y H:i:s')

    if(tMinService !== null && (this.servicesStore.tMin === null || tMinService < this.servicesStore.tMin)) {
      this.servicesStore.tMin = tMinService
      if(timeMin === null) {
        this.timeSelector.setStartTime(this.servicesStore.tMin)
      }
    }

    if(tMaxService !== null && (this.servicesStore.tMax === null || tMaxService > this.servicesStore.tMax)) {
      this.servicesStore.tMax = tMaxService
      if(timeMax === null) {
        this.timeSelector.setStopTime(this.servicesStore.tMax)
      }
    }

428eb66e   Nathanael Jourdane   Use JS standard c...
171
172
173
174
175
    this.servicesStore.sort()
    loadMask.hide()
  },

  /**
538afb92   Nathanael Jourdane   Refactoring
176
177
178
   Triggered when a row is clicked in `servicesGrid` table (see `EpnTapUI.createServicesGrid()`). Among other things,
   send a new query and fill `granulesGrid`.
   */
428eb66e   Nathanael Jourdane   Use JS standard c...
179
180
181
182
183
184
185
186
  onServiceSelected: function (record) {
    this.granulesStore.selectedService = record.data.id
    Ext.Ajax.suspendEvent('requestexception')
    Ext.Ajax.abortAll()

    if (record.get('nb_results') > 0) {
      this.granulesStore.removeAll()
      this.granulesStore.load({
538afb92   Nathanael Jourdane   Refactoring
187
        callback: function () {
428eb66e   Nathanael Jourdane   Use JS standard c...
188
          Ext.Ajax.resumeEvents('requestexception')
538afb92   Nathanael Jourdane   Refactoring
189
          // console.log(Ext.decode(operation.response.responseText))
428eb66e   Nathanael Jourdane   Use JS standard c...
190
191
192
193
194
195
196
197
        },
        start: 0,
        limit: this.granulesStore.pageSize,
        scope: this
      })
    }
  }
})