Blame view

js/app/views/EpnTapUI.js 26.4 KB
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
1
2
3
4
5
/**
 * Project: AMDA-NG
 * Name: EpnTapUI.js
 * @class amdaUI.EpnTapUI
 * @extends Ext.tab.Panel
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
6
7
8
9
 * @author Nathanael JOURDANE
 * 24/10/2016: file creation
 */

76d60878   Nathanael Jourdane   Add compatibility...
10
'use strict'
428eb66e   Nathanael Jourdane   Use JS standard c...
11
Ext.require(['Ext.grid.plugin.BufferedRenderer'])
b185823c   Nathanael Jourdane   Use IntervalUI mo...
12
13
14
15
16
17
18
19
/**
`productTypesStore`: An ExtJS Store containing the list of the different data product types defined on all granules, on
all available EPN-TAP services (defined in `generic_data/EpnTapData/metadata.json`, updated periodically with a cron
script).

This list is used to fill the `productTypeCB` combo box, which is initilized in `EpnTapModule` at the panel creation.

- `id`: the data product type IDs, according to the EPN-TAP specification (see
428eb66e   Nathanael Jourdane   Use JS standard c...
20
    https://voparis-confluence.obspm.fr/pages/viewpage.action?pageId=1148225);
b185823c   Nathanael Jourdane   Use IntervalUI mo...
21
22
23
24
25
26
27
28
29
- `name`: the data product name, according to the EPN-TAP specification (ibid).

These IDs and names are hard-defined in the JSon file `generic_data/EpnTapData/dataproduct_types.json`.

Notes:
- if a granule contains a data product type which is not conform to the EPN-TAP definition (ibid), it is not displayed
in this store and an information message is displayed on the JavaScript console during the panel creation.
- if a data product type is not present in any of the granules from the EPN-TAP services, it is not present in this
store.
b185823c   Nathanael Jourdane   Use IntervalUI mo...
30
*/
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
31
Ext.create('Ext.data.Store', {
428eb66e   Nathanael Jourdane   Use JS standard c...
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
  storeId: 'productTypesStore',
  autoLoad: true,
  fields: ['id', 'name', 'desc'],
  data: [
    {'id': 'all', 'name': '--All--', 'desc': 'Select all produt types.'},
    {'id': 'clear', 'name': '--Clear--', 'desc': 'Clear the selection.'},
    {'id': 'im', 'name': 'Image', 'desc': '2D series of values depending on 2 spatial axes, with measured parameters.'},
    {'id': 'ma', 'name': 'Map', 'desc': '2D series of values depending on 2 spatial axes, with derived parameters.'},
    {'id': 'sp', 'name': 'Spectrum', 'desc': '1D series of values depending on a spectral axis (or Frequency, Energy, Mass,...).'},
    {'id': 'ds', 'name': 'Dynamic spectrum', 'desc': '2D series of values depending on time and on a spectral axis (Frequency, Energy, Mass,...), FoV is homogeneous.'},
    {'id': 'sc', 'name': 'Spectral cube', 'desc': '3D series of values depending on 2 spatial axes and on a spectral axis (Frequency, Energy, Mass,..).'},
    {'id': 'pr', 'name': 'Profile', 'desc': '1D series of values depending on a spatial axis.'},
    {'id': 'vo', 'name': 'Volume', 'desc': '3D series of values depending on 3 spatial axes (spatial coordinates or tabulated values in a volumic grid).'},
    {'id': 'mo', 'name': 'Movie', 'desc': '3D series of values depending on 2 spatial axes and on time.'},
    // {'id': 'cu', 'name': 'Cube', 'desc': '.'},
    {'id': 'ts', 'name': 'Time series', 'desc': '1D series of values depending on time.'},
    {'id': 'ca', 'name': 'Catalogue', 'desc': '1D list of elements.'},
    {'id': 'ci', 'name': 'Catalogue item', 'desc': '0D list of elements.'}
  ]
})
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
52

b185823c   Nathanael Jourdane   Use IntervalUI mo...
53
54
55
56
57
58
59
60
61
62
63
/**
`targetNamesStore`: An ExtJS Store containing the list of the different target names defined on all granules, on
all available EPN-TAP services (defined in `generic_data/EpnTapData/metadata.json`, updated periodically with a cron
script), which match with the selected data product and target class.

This list is used to fill the `targetNameCB` combo box, which is updated by `EpnTapModule` each time a new target class
(or, by transitivity, product type) is selected.

- `id`: the target name in lowercase, with the underscore between each word;
- `name`: the target name, capitalized with spaces between each word (done `EpnTapModule.prettify()`).
*/
68664dca   Nathanael Jourdane   make epntap php f...
64
Ext.create('Ext.data.Store', {
428eb66e   Nathanael Jourdane   Use JS standard c...
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
  storeId: 'targetNamesStore',
  fields: ['id', 'text', 'name', 'type', 'parent', 'aliases'],
  proxy: {
    type: 'ajax',
    url: 'php/epntap.php',
    extraParams: { action: 'resolver' }
  },
  errorDisplayed: false,
  listeners: {
    load: function (store, records, successful) {
      if (!successful && !store.errorDisplayed) {
        Ext.Msg.alert('Error', 'Can not load results from the resolver. Please enter target names manually.')
        store.errorDisplayed = true
      }
    }
  }
})
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
82

12c10cdb   Nathanael Jourdane   Get the list of s...
83
84
85
86
87
88
89
/**
`servicesStore`: An ExtJS Store containing the list of the EPN-TAP services (defined in
`generic_data/EpnTapData/metadata.json`, updated periodically with a cron script), which contains at least one granule
matching with the granules filter (the selected data product type, target class and target name).

This list is used to fill the `servicesGrid` table, which is updated by `EpnTapModule` each time a new target name
(or, by transitivity, target class or product type) is selected.
8d5634e3   Nathanael Jourdane   Use epn-tap store...
90

12c10cdb   Nathanael Jourdane   Get the list of s...
91
- `id`: the database name of the service, according to the `table_name` column from the `rr.res_table` in the
428eb66e   Nathanael Jourdane   Use JS standard c...
92
    registry database;
12c10cdb   Nathanael Jourdane   Get the list of s...
93
94
- `nbResults`: the number of granules matching with the granules filter for this service;
- `shortName`: the service short name, according to the `short_name` column from the `rr.resource` table in the registry
428eb66e   Nathanael Jourdane   Use JS standard c...
95
    database;
12c10cdb   Nathanael Jourdane   Get the list of s...
96
97
- `title`: the service title, according to the `res_title` column from the `rr.resource` table in the registry database;
- `accessURL`: the service access URL, according to the `access_url` column from the `rr.interface` table in the
428eb66e   Nathanael Jourdane   Use JS standard c...
98
    registry database.
12c10cdb   Nathanael Jourdane   Get the list of s...
99
*/
8d5634e3   Nathanael Jourdane   Use epn-tap store...
100
Ext.create('Ext.data.Store', {
428eb66e   Nathanael Jourdane   Use JS standard c...
101
102
  storeId: 'servicesStore',
  autoLoad: true,
853c8154   Nathanael Jourdane   Init start/stop d...
103
104
  tMin: null,
  tMax: null,
428eb66e   Nathanael Jourdane   Use JS standard c...
105
106
107
108
109
110
111
112
113
114
115
116
117
118
  fields: [
    {name: 'id', type: 'string'},
    {name: 'short_name', type: 'string'},
    {name: 'res_title', type: 'string'},
    {name: 'ivoid', type: 'string'},
    {name: 'access_url', type: 'string'},
    {name: 'table_name', type: 'string'},
    {name: 'content_type', type: 'string'},
    {name: 'creator_seq', type: 'string'},
    {name: 'content_level', type: 'string'},
    {name: 'reference_url', type: 'string'},
    {name: 'created', type: 'date', dateFormat: 'c'},
    {name: 'updated', type: 'date', dateFormat: 'c'},
    {name: 'nb_results', type: 'integer'},
853c8154   Nathanael Jourdane   Init start/stop d...
119
120
121
    {name: 'info', type: 'string'},
    {name: 'time_min', type: 'string'},
    {name: 'time_max', type: 'string'}
428eb66e   Nathanael Jourdane   Use JS standard c...
122
123
124
125
126
127
128
129
130
131
132
133
134
135
  ],
  proxy: {
    type: 'ajax',
    url: 'php/epntap.php',
    extraParams: {action: 'getServices'}
  },
  sorters: [
    {property: 'nb_results', direction: 'DESC'},
    {property: 'short_name', direction: 'ASC'}
  ],
  listeners: {
    // beforeload: function(s, operation) { console.log(operation); },
    load: function (store, records, successful) {
      if (!successful) {
f4eaa5ae   NathanaĆ«l Jourdane   Display registry ...
136
        store.errorMessage = 'Can not get epntap services from registries.'
428eb66e   Nathanael Jourdane   Use JS standard c...
137
138
139
140
      }
    }
  }
})
8d5634e3   Nathanael Jourdane   Use epn-tap store...
141

b185823c   Nathanael Jourdane   Use IntervalUI mo...
142
/**
b185823c   Nathanael Jourdane   Use IntervalUI mo...
143
`granulesStore`: An ExtJS Store containing the list of granules of the selected service (on `servicesGrid`), which match
ba6dfa5e   Nathanael Jourdane   (regression bug) ...
144
with the granules filter (the selected data product type, target class and target name).
b185823c   Nathanael Jourdane   Use IntervalUI mo...
145
146
147
148
149
150

This list is used to fill the `granulesGrid` table, which is updated by `EpnTapModule` each time a new service is
selected.

- `num`: the line number, according to the order of the query response and the current page (see `currentPageLb`);
- `dataproduct_type`: the dataproduct_type EPN-TAP parameter, as defined in
428eb66e   Nathanael Jourdane   Use JS standard c...
151
  https://voparis-confluence.obspm.fr/display/VES/EPN-TAP+V2.0+parameters.
b185823c   Nathanael Jourdane   Use IntervalUI mo...
152
153
154
155
156
157
158
159
160
- `target_name`: the target_name EPN-TAP parameter (ibid);
- `time_min`: the time_min EPN-TAP parameter (ibid);
- `time_max`: the time_max EPN-TAP parameter (ibid);
- `access_format`: the access_format EPN-TAP parameter (ibid);
- `granule_uid`: the granule_uid EPN-TAP parameter (ibid);
- `access_estsize`: the access_estsize EPN-TAP parameter (ibid);
- `access_url`: the access_url EPN-TAP parameter (ibid);
- `thumbnail_url`: the thumbnail_url EPN-TAP parameter (ibid).
*/
6d616600   Nathanael Jourdane   Fix granules sorter
161
// TODO: Add granules filter (see http://docs.sencha.com/extjs/4.0.7/#!/example/grid-filtering/grid-filter-local.html)
016bdaae   Nathanael Jourdane   Fix bad rendering...
162
163

Ext.define('GranulesModel', {
428eb66e   Nathanael Jourdane   Use JS standard c...
164
165
166
  extend: 'Ext.data.Model'
  // columns are created dynamically
})
016bdaae   Nathanael Jourdane   Fix bad rendering...
167

3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
168
Ext.create('Ext.data.Store', {
428eb66e   Nathanael Jourdane   Use JS standard c...
169
170
171
172
173
174
175
176
177
  storeId: 'granulesStore',
  model: 'GranulesModel',
  buffered: true,
  autoload: false,
  pageSize: 500,
  leadingBufferZone: 0,
  proxy: {
    type: 'ajax',
    url: 'php/epntap.php',
538afb92   Nathanael Jourdane   Refactoring
178
    reader: {type: 'json', root: 'data'},
428eb66e   Nathanael Jourdane   Use JS standard c...
179
180
181
    simpleSortMode: true
  },
  listeners: {
538afb92   Nathanael Jourdane   Refactoring
182
183
    'beforeprefetch': function (store) {
      const service = Ext.data.StoreManager.lookup('servicesStore').getById(store.selectedService).data
428eb66e   Nathanael Jourdane   Use JS standard c...
184
185
186
187
188
189
190
191
192
193
194
      store.getProxy().extraParams = {
        'action': 'getGranules',
        'url': service['access_url'],
        'tableName': service['table_name'],
        'targetNames': Ext.getCmp('epnTapTargetNameCB').rawValue,
        'productTypes': Ext.getCmp('epnTapProductTypeCB').value.join(';'),
        'timeMin': Ext.Date.format(Ext.getCmp('epnTapTimeSelector').getStartTime(), 'd/m/Y H:i:s'),
        'timeMax': Ext.Date.format(Ext.getCmp('epnTapTimeSelector').getStopTime(), 'd/m/Y H:i:s'),
        'nbRes': service['nb_results']
      }
    },
538afb92   Nathanael Jourdane   Refactoring
195
196
197
198
199
    // 'prefetch': function(store, records, successful, operation) {
    // console.log('(prefetch) operation ' + (successful ? 'success' : 'failed') + ': ', operation)
    // console.log(operation.params)
    // console.log(Ext.decode(operation.response.responseText))
    // },
428eb66e   Nathanael Jourdane   Use JS standard c...
200
    'metachange': function (store, meta) {
538afb92   Nathanael Jourdane   Refactoring
201
      if (meta.metaHash !== store.metaHash) {
428eb66e   Nathanael Jourdane   Use JS standard c...
202
203
204
205
206
207
        Ext.getCmp('epnTapGranulesGrid').reconfigure(store, meta.columns)
        store.metaHash = meta.metaHash
      }
    }
  }
})
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
208

465b7a40   Nathanael Jourdane   Escape quotes in ...
209
210
211
/**
Error are not displayed here, use try/catch each time it's necessary.
*/
7211d9b5   Nathanael Jourdane   Move util.Format ...
212
Ext.define('App.util.Format', {
428eb66e   Nathanael Jourdane   Use JS standard c...
213
214
215
216
217
218
219
  override: 'Ext.util.Format',

  // Utils

  'prettify': function (data) {
    return data.charAt(0).toUpperCase() + data.replace(/_/g, ' ').substr(1).toLowerCase()
  },
538afb92   Nathanael Jourdane   Refactoring
220
  'sanitizeData': function (data) {
76d60878   Nathanael Jourdane   Add compatibility...
221
222
    // noinspection ES6ConvertVarToLetConst
    for (var dKey in data) {
538afb92   Nathanael Jourdane   Refactoring
223
224
225
226
227
228
      if (data.hasOwnProperty(dKey) && typeof data[dKey] === 'string' && data[dKey] !== '') {
        data[dKey] = data[dKey].replace(/'/g, ''').replace(/"/g, '"')
      }
    }
    return data
  },
428eb66e   Nathanael Jourdane   Use JS standard c...
229
  'url': function (data) {
538afb92   Nathanael Jourdane   Refactoring
230
231
232
233
234
235
236
    const urlPattern = new RegExp('^(https?:\\/\\/)?' + // protocol
      '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.?)+[a-z]{2,}|' + // domain name
      '((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address
      '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path
      '(\\?[;&a-z\\d%_.~+=-]*)?' + // query string
      '(\\#[-a-z\\d_]*)?$', 'i') // fragment locator
    return urlPattern.test(data) ? data : null
428eb66e   Nathanael Jourdane   Use JS standard c...
237
238
  },
  'cell': function (content, tooltip, tooltipTitle) {
538afb92   Nathanael Jourdane   Refactoring
239
240
241
    const ttTitle = tooltipTitle ? " data-qtitle='" + tooltipTitle + "'" : ''
    const ttAttr = tooltip === '' ? '' : "' data-qtip='" + (tooltip || content || 'No value.') + "'"
    return '<div class=epntap_cell ' + ttTitle + ttAttr + '>' + (content || '-') + '</div>'
428eb66e   Nathanael Jourdane   Use JS standard c...
242
243
244
245
246
  },

  // Services grid

  'serviceTooltip': function (data) {
538afb92   Nathanael Jourdane   Refactoring
247
248
249
    const sData = Ext.util.Format.sanitizeData(data)
    const infoColor = sData['nb_results'] === -2 ? 'IndianRed' : 'green'
    const info = sData.info.length > 0 ? '<p style="color:' + infoColor + '">' + sData.info + '</p>' : ''
853c8154   Nathanael Jourdane   Init start/stop d...
250
    const timeInfo = sData['time_min'] !== '-' || sData['time_min'] !== '-' ? '<p>Time period: from ' + sData['time_min'] + ' to ' + sData['time_min'] + '</p>' : ''
538afb92   Nathanael Jourdane   Refactoring
251

34cf0b45   Nathanael Jourdane   Display table nam...
252
    const colums = ['short_name', 'res_title', 'ivoid', 'access_url', 'table_name', 'content_type', 'creator_seq', 'content_level', 'reference_url', 'created', 'updated']
76d60878   Nathanael Jourdane   Add compatibility...
253
254
255
256
    // noinspection ES6ConvertVarToLetConst
    var details = ''
    // noinspection ES6ConvertVarToLetConst
    for (var cKey in colums) {
538afb92   Nathanael Jourdane   Refactoring
257
258
259
      if (colums.hasOwnProperty(cKey) && sData[colums[cKey]] !== '') {
        const val = colums[cKey] === 'content_level' ? sData[colums[cKey]].replace(/#/g, ', ') : sData[colums[cKey]]
        details += '<li><b>' + Ext.util.Format.prettify(colums[cKey]) + '</b>: ' + val + '</li>'
428eb66e   Nathanael Jourdane   Use JS standard c...
260
261
      }
    }
853c8154   Nathanael Jourdane   Init start/stop d...
262
    return info + timeInfo + '<ul>' + details + '</ul>'
428eb66e   Nathanael Jourdane   Use JS standard c...
263
264
  },
  'service.text': function (data, metadata, record) {
34cf0b45   Nathanael Jourdane   Display table nam...
265
266
    const serviceName = Ext.util.Format.prettify(data.replace('.epn_core' , ''))
    return Ext.util.Format.cell(serviceName, Ext.util.Format.serviceTooltip(record.data), data)
428eb66e   Nathanael Jourdane   Use JS standard c...
267
268
  },
  'service.number': function (data, metadata, record) {
538afb92   Nathanael Jourdane   Refactoring
269
270
271
272
273
274
    const block = Math.pow(10, 3)
    const value = data < 0 ? '-'
      : data >= block * block ? (data / (block * block)).toPrecision(3) + 'm'
      : data >= block ? (data / block).toPrecision(3) + 'k'
      : '' + data
    return Ext.util.Format.cell(value, Ext.util.Format.serviceTooltip(record.data), record.data['short_name'])
428eb66e   Nathanael Jourdane   Use JS standard c...
275
276
277
278
  },

  // Granules grid

538afb92   Nathanael Jourdane   Refactoring
279
  'granule.text': function (data) {
428eb66e   Nathanael Jourdane   Use JS standard c...
280
281
    return Ext.util.Format.cell(data)
  },
538afb92   Nathanael Jourdane   Refactoring
282
283
284
285
286
287
288
289
  'granule.link': function (data) {
    const iconImage = 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/PjxzdmcgaGVpZ2h0PSIxMDI0IiB3aWR0aD0iNzY4' +
      'IiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxwYXRoIGQ9Ik02NDAgNzY4SDEyOFYyNTcuOTA1OTk5OTk5OTk5OTVMMjU2ID' +
      'I1NlYxMjhIMHY3NjhoNzY4VjU3Nkg2NDBWNzY4ek0zODQgMTI4bDEyOCAxMjhMMzIwIDQ0OGwxMjggMTI4IDE5Mi0xOTIgMTI4IDEyOFYxMjhI' +
      'Mzg0eiIvPjwvc3ZnPg=='
    const icon = '<img style="width:15px;" alt="link" src="' + iconImage + '">'
    const url = Ext.util.Format.url(data)
    const txt = url ? '<a style="font-size:150%" target="_blank" href="' + url + '">' + icon + '</a>' : false
428eb66e   Nathanael Jourdane   Use JS standard c...
290
291
    return Ext.util.Format.cell(txt, url)
  },
538afb92   Nathanael Jourdane   Refactoring
292
293
294
295
  'granule.img': function (data) {
    const imgUrl = Ext.util.Format.url(data)
    const icon = imgUrl ? '<img style="max-width:100%; max-height:100%" alt="-" src="' + imgUrl + '">' : false
    const img = imgUrl ? '<img style="max-width:200px; max-height:200px" src="' + imgUrl + '">' : false
428eb66e   Nathanael Jourdane   Use JS standard c...
296
297
    return Ext.util.Format.cell(icon, img)
  },
538afb92   Nathanael Jourdane   Refactoring
298
299
  'granule.type': function (data) {
    const productTypeDict = Ext.data.StoreManager.lookup('productTypesStore').data.map
428eb66e   Nathanael Jourdane   Use JS standard c...
300
301
    return Ext.util.Format.cell(productTypeDict[data].data.name)
  },
538afb92   Nathanael Jourdane   Refactoring
302
303
  'granule.size': function (data) {
    const size = parseInt(data)
cc663bbe   Nathanael Jourdane   Remove button dis...
304
    const block = Math.pow(2, 10)
538afb92   Nathanael Jourdane   Refactoring
305
306
307
308
    const txt = isNaN(size) ? false
      : size >= block * block ? (size / (block * block)).toPrecision(3) + 'Go'
        : size >= block ? (size / block).toPrecision(3) + 'Mo'
          : size + 'Ko'
428eb66e   Nathanael Jourdane   Use JS standard c...
309
310
    return Ext.util.Format.cell(txt)
  },
538afb92   Nathanael Jourdane   Refactoring
311
312
  'granule.proc_lvl': function (data) {
    const levels = {1: 'Raw', 2: 'Edited', 3: 'Calibrated', 4: 'Resampled', 5: 'Derived', 6: 'Ancillary'}
428eb66e   Nathanael Jourdane   Use JS standard c...
313
314
    return Ext.util.Format.cell((data in levels) ? levels[data] : '<em>' + data + '</em>')
  },
538afb92   Nathanael Jourdane   Refactoring
315
316
317
318
  'granule.date': function (data) {
    // See https://en.wikipedia.org/wiki/Julian_day#Julian_or_Gregorian_calendar_from_Julian_day_number
    // noinspection MagicNumberJS
    const jd = {y: 4716, j: 1401, m: 2, n: 12, r: 4, p: 1461, v: 3, u: 5, s: 153, w: 2}
76d60878   Nathanael Jourdane   Add compatibility...
319
320
    // noinspection ES6ConvertVarToLetConst
    var strDate
428eb66e   Nathanael Jourdane   Use JS standard c...
321
    if (isNaN(data)) {
538afb92   Nathanael Jourdane   Refactoring
322
323
324
325
326
327
328
329
330
331
332
      strDate = false
    } else {
      const f = Number(data) + jd.j
      const e = jd.r * f + jd.v
      const g = Math.floor((e % jd.p) / jd.r)
      const h = jd.u * g + jd.w
      const day = Math.floor((h % jd.s) / jd.u) + 1
      const month = ((Math.floor(h / jd.s) + jd.m) % jd.n) + 1
      const year = Math.floor(e / jd.p) - jd.y + Math.floor((jd.n + jd.m - month) / jd.n)
      const date = new Date(year, month - 1, day)
      strDate = Ext.util.Format.cell(Ext.Date.format(date, 'Y/m/d'), Ext.Date.format(date, 'F j, Y, g:i a'))
428eb66e   Nathanael Jourdane   Use JS standard c...
333
    }
538afb92   Nathanael Jourdane   Refactoring
334
    return strDate
428eb66e   Nathanael Jourdane   Use JS standard c...
335
  },
538afb92   Nathanael Jourdane   Refactoring
336
337
  'granule.format': function (data) {
    const mimetypeDict = {
428eb66e   Nathanael Jourdane   Use JS standard c...
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
      'application/fits': 'fits',
      'application/x-pds': 'pds',
      'image/x-pds': 'pds',
      'application/gml+xml': 'gml',
      'application/json': 'json',
      'application/octet-stream': 'bin, idl, envi or matlab',
      'application/pdf': 'pdf',
      'application/postscript': 'ps',
      'application/vnd.geo+json': 'geojson',
      'application/vnd.google-earth.kml+xml': 'kml',
      'application/vnd.google-earth.kmz': 'kmz',
      'application/vnd.ms-excel': 'xls',
      'application/x-asdm': 'asdm',
      'application/x-cdf': 'cdf',
      'application/x-cdf-istp': 'cdf',
      'application/x-cdf-pds4': 'cdf',
      'application/x-cef1': 'cef1',
      'application/x-cef2': 'cef2',
      'application/x-directory': 'dir',
      'application/x-fits-bintable': 'bintable',
      'application/x-fits-euro3d': 'euro3d',
      'application/x-fits-mef': 'mef',
      'application/x-geotiff': 'geotiff',
      'application/x-hdf': 'hdf',
      'application/x-netcdf': 'nc',
      'application/x-netcdf4': 'nc',
      'application/x-tar': 'tar',
      'application/x-tar-gzip': 'gtar',
      'application/x-votable+xml': 'votable',
      'application/x-votable+xml;content=datalink': 'votable',
      'application/zip': 'zip',
      'image/fits': 'fits',
      'image/gif': 'gif',
      'image/jpeg': 'jpeg',
      'image/png': 'png',
      'image/tiff': 'tiff',
      'image/x-fits-gzip': 'fits',
      'image/x-fits-hcompress': 'fits',
      'text/csv': 'csv',
      'text/html': 'html',
      'text/plain': 'txt',
      'text/tab-separated-values': 'tsv',
      'text/xml': 'xml',
      'video/mpeg': 'mpeg',
      'video/quicktime': 'mov',
      'video/x-msvideo': 'avi'
    }
    return Ext.util.Format.cell((data in mimetypeDict) ? '<p>' + mimetypeDict[data] + '</p>' : '<em>' + data + '</em>')
  }
})
7211d9b5   Nathanael Jourdane   Move util.Format ...
388

b185823c   Nathanael Jourdane   Use IntervalUI mo...
389
390
391
392
393
394
/**
`EpnTapUI`: The view of the AMDA EPN-TAP module, allowing the user to query and display granules information from
EPN-TAP services.

Note: The controller part of this module is defined in `js/app/controller/EpnTapModule`.
*/
78c2f505   Nathanael Jourdane   Improve granules ...
395
Ext.define('amdaUI.EpnTapUI', {
428eb66e   Nathanael Jourdane   Use JS standard c...
396
397
398
399
400
401
402
403
404
  extend: 'Ext.panel.Panel',
  alias: 'widget.panelEpnTap',
  requires: ['amdaUI.IntervalUI'],

  /**
  Method constructor, which basically call the `init()` method to create the EpnTap panel.
  */
  constructor: function (config) {
    this.init(config)
76d60878   Nathanael Jourdane   Add compatibility...
405
    this.superclass.constructor.apply(this, arguments)
428eb66e   Nathanael Jourdane   Use JS standard c...
406
407
408
409
410
411
412
413
414
415
416
  },

  /**
  Create all the EpnTapPanel UI elements, and apply the AMDA module `config` (which includes the created items).

  When the panel is correctly rendered, the panel triggers `EpnTapModule.onWindowLoaded()`.

  Note: All the UI elements creation are defined as functions in this init method and not as methods in order to make
  them private (ie. to avoid `EpnTapUI.createServicesGrid();`, which doesn't make sense).
  */
  init: function (config) {
76d60878   Nathanael Jourdane   Add compatibility...
417
    const myConf = {
428eb66e   Nathanael Jourdane   Use JS standard c...
418
      id: 'epntapTab',
78bffaa7   Benjamin Renard   Add VESPA acknowl...
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
      tabConfig: {
        title: 'EPN-TAP&nbsp;<img amda_clicktip="vespaHelp" src="js/resources/images/16x16/info_mini.png"',
        listeners: {
          click: {
            element: 'el',
            fn: function (e, t) {
              var me = t,
                text = me.getAttribute('amda_clicktip');
              if (text) {
                e.preventDefault();
                AmdaAction.getInfo({ name: text }, function (res, e) {
                  if (res.success) myDesktopApp.infoMsg(res.result);
                });
              }
            }
          }
        }
      },
428eb66e   Nathanael Jourdane   Use JS standard c...
437
438
      items: [{
        xtype: 'container',
538afb92   Nathanael Jourdane   Refactoring
439
        layout: {type: 'vbox', pack: 'start', align: 'stretch'},
428eb66e   Nathanael Jourdane   Use JS standard c...
440
441
442
443
        items: [
          this.createServiceFilterPanel(),
          this.createGridsPanel()
        ]
f4eaa5ae   NathanaĆ«l Jourdane   Display registry ...
444
445
446
447
448
449
450
451
452
      }],
      listeners: {
        render: function () {
          var service = Ext.data.StoreManager.lookup('servicesStore')
          if (service.errorMessage) {
            Ext.Msg.alert('Error', service.errorMessage)
          }
        }
      }
428eb66e   Nathanael Jourdane   Use JS standard c...
453
454
455
456
457
458
459
460
461
462
463
    }
    Ext.apply(this, Ext.apply(arguments, myConf))
  },

  /***************************
  *** Service filter panel ***
  ***************************/

  /**
  Create `epnTapServiceFilterPanel`, an ExtJS Panel containing two containers:
  - the left container, containing the combo boxes (for product type, target class and target name)
538afb92   Nathanael Jourdane   Refactoring
464
  and the navigation panel;
428eb66e   Nathanael Jourdane   Use JS standard c...
465
466
467
468
469
470
  - the right container, containing the time selector.
  */
  createServiceFilterPanel: function () {
    return {
      xtype: 'form',
      id: 'epnTapServiceFilterPanel',
538afb92   Nathanael Jourdane   Refactoring
471
      layout: {type: 'hbox', pack: 'start', align: 'stretch'},
428eb66e   Nathanael Jourdane   Use JS standard c...
472
      region: 'north',
538afb92   Nathanael Jourdane   Refactoring
473
      defaults: {margin: '5 0 5 5'},
428eb66e   Nathanael Jourdane   Use JS standard c...
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
      items: [{ // Left part
        xtype: 'container',
        flex: 1,
        items: [
          this.createTargetNameCB(),
          this.createProductTypeCB()
        ]
      }, { // Middle part
        xtype: 'container',
        flex: 1,
        items: [
          this.createTimeSelector()
        ]
      }, { // Right part
        xtype: 'container',
        items: [
          this.createSendButton()
        ]

      }]
    }
  },

538afb92   Nathanael Jourdane   Refactoring
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
  /**
  Create `epnTapTargetNameCB`, an ExtJS ComboBox, containing a list of target names corresponding to the selected
  target class, as defined in `targetNamesStore`, which is initilized by `EpnTapModule`.

  The selection of a target name triggers `EpnTapModule.onTargetNameCBChanged()`, which basically updates
  `granulesGrid`.
  */
  createTargetNameCB: function () {
    return {
      xtype: 'combobox',
      id: 'epnTapTargetNameCB',
      fieldLabel: 'Target name',
      emptyText: 'Earth, Saturn, 67P, ...',
      tooltip: 'Start to type a text, then select a target name (required). ' +
      'Several values are allowed, separated by a semicolon.',
      store: Ext.data.StoreManager.lookup('targetNamesStore'),
      queryMode: 'remote',
      queryParam: 'input',
      displayField: 'text',
      valueField: 'id',
      margin: '15 0 5 0',
      labelWidth: 71,
      minWidth: 20,
      minChars: 2,
      hideTrigger: true,
      listConfig: {
        getInnerTpl: function () {
          const ttContent = '<p>type: {type}</p><p>parent: {parent}</p><p>aliases:</p><ul>{aliases}</ul>'
          return '<div data-qtitle="{name}" data-qtip="' + ttContent + '">{name}</div>'
        }
      },
      listeners: {
        render: function (cb) {
          Ext.ToolTip({target: cb.getEl(), html: '<div style="width:200px">' + cb.tooltip + '</div>'})
428eb66e   Nathanael Jourdane   Use JS standard c...
531
532
        }
      }
538afb92   Nathanael Jourdane   Refactoring
533
534
    }
  },
428eb66e   Nathanael Jourdane   Use JS standard c...
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562

  /**
  Create `epnTapProductTypeCB`, an ExtJS ComboBox, containing a list of product types as defined in
  `epnTapProductTypesStore`, which is initilized by `EpnTapModule`.

  The selection of a produt type triggers `EpnTapModule.onProductTypeCBChanged()`, which basically update
  `epnTapGranulesGrid`.
  */
  createProductTypeCB: function () {
    return {
      xtype: 'combobox',
      id: 'epnTapProductTypeCB',
      fieldLabel: 'Product type',
      emptyText: 'Image, Time series, ...',
      tooltip: 'Select one or several data product types (required).',
      store: Ext.data.StoreManager.lookup('productTypesStore'),
      queryMode: 'local',
      valueField: 'id',
      multiSelect: true,
      displayField: 'name',
      labelWidth: 71,
      editable: false,
      listConfig: {
        getInnerTpl: function () {
          return '<div data-qtitle="{name}" data-qwidth=200 data-qtip="<p>{desc}</p>">{name}</div>'
        }
      },
      listeners: {
538afb92   Nathanael Jourdane   Refactoring
563
564
        change: function (cb) {
          const val = cb.value[cb.value.length - 1]
428eb66e   Nathanael Jourdane   Use JS standard c...
565
566
567
568
569
570
571
          if (val === 'all') {
            cb.select(cb.store.getRange().slice(2))
          } else if (val === 'clear') {
            cb.reset()
          }
        },
        render: function (cb) {
538afb92   Nathanael Jourdane   Refactoring
572
          Ext.ToolTip({target: cb.getEl(), html: '<div style="width:200px">' + cb.tooltip + '</div>'})
428eb66e   Nathanael Jourdane   Use JS standard c...
573
574
        }
      }
cc663bbe   Nathanael Jourdane   Remove button dis...
575
    }
428eb66e   Nathanael Jourdane   Use JS standard c...
576
577
578
579
580
581
582
583
584
585
586
587
  },

  /**
  Create `epnTapTimeSelector`, an IntervalUI object, allowing the user to select a time interval (by filling two
  dates and/or a duration).

  See `js/app/views/IntervalUI.js` for more information about this component.
  */
  createTimeSelector: function () {
    return {
      xtype: 'intervalSelector',
      id: 'epnTapTimeSelector'
cc663bbe   Nathanael Jourdane   Remove button dis...
588
    }
428eb66e   Nathanael Jourdane   Use JS standard c...
589
590
591
592
593
594
595
  },

  /***********************
  *** Navigation panel ***
  ***********************/

  /**
538afb92   Nathanael Jourdane   Refactoring
596
597
   The button used to send the query.
   */
428eb66e   Nathanael Jourdane   Use JS standard c...
598
599
600
601
602
  createSendButton: function () {
    return {
      xtype: 'button',
      id: 'epnTapGetBtn',
      text: 'Get services',
428eb66e   Nathanael Jourdane   Use JS standard c...
603
604
605
      width: 140,
      height: 50,
      margin: 10
cc663bbe   Nathanael Jourdane   Remove button dis...
606
    }
428eb66e   Nathanael Jourdane   Use JS standard c...
607
608
609
610
611
612
613
  },

  /************
  *** Grids ***
  ************/

  /**
538afb92   Nathanael Jourdane   Refactoring
614
   Create `epnTapGridsPanel`, an ExtJS Panel, containing `epnTapServicesGrid` and `epnTapGranulesGrid`.
428eb66e   Nathanael Jourdane   Use JS standard c...
615

538afb92   Nathanael Jourdane   Refactoring
616
617
618
   After the rendering of the grids, it triggers `epnTapModule.onWindowLoaded()`, which basically fill
   `epnTapServicesGrid` for the first time.
   */
428eb66e   Nathanael Jourdane   Use JS standard c...
619
620
621
622
623
624
625
626
  createGridsPanel: function () {
    return {
      xtype: 'panel',
      id: 'epnTapGridsPanel',
      layout: 'fit',
      flex: 1,
      items: [{
        xtype: 'container',
538afb92   Nathanael Jourdane   Refactoring
627
        layout: {type: 'hbox', pack: 'start', align: 'stretch'},
428eb66e   Nathanael Jourdane   Use JS standard c...
628
629
630
631
632
633
634
635
636
        items: [
          this.createServicesGrid(),
          this.createGranulesGrid()
        ]
      }]
    }
  },

  /**
538afb92   Nathanael Jourdane   Refactoring
637
638
   Create `epnTapServicesGrid`, an ExtJS grid containing the EPN-TAP services matching with the filter form
   (`serviceFilterPanel`).
428eb66e   Nathanael Jourdane   Use JS standard c...
639

538afb92   Nathanael Jourdane   Refactoring
640
641
642
   For each service, this grid displays:
   - the service name;
   - the number of granules matching with the filter.
428eb66e   Nathanael Jourdane   Use JS standard c...
643

538afb92   Nathanael Jourdane   Refactoring
644
645
646
647
   Other informations are available through an ExtJS Tooltip, on each row:
   - short name;
   - title;
   - access URL.
428eb66e   Nathanael Jourdane   Use JS standard c...
648

538afb92   Nathanael Jourdane   Refactoring
649
650
651
   A click on a service triggers `EpnTapModule.onServiceSelected()`, which basically fills `GranulesGrid` by the
   service granules.
   */
428eb66e   Nathanael Jourdane   Use JS standard c...
652
653
654
655
656
657
658
659
660
  createServicesGrid: function () {
    return {
      xtype: 'grid',
      cls: 'epntap_grid',
      id: 'epnTapServicesGrid',
      title: 'Services',
      store: Ext.data.StoreManager.lookup('servicesStore'),
      flex: 1,
      columns: [
34cf0b45   Nathanael Jourdane   Display table nam...
661
        {text: 'Name', dataIndex: 'table_name', flex: 1, renderer: 'service.text'},
428eb66e   Nathanael Jourdane   Use JS standard c...
662
663
664
        {text: 'Nb res.', dataIndex: 'nb_results', width: 50, renderer: 'service.number'}
      ],
      viewConfig: {
538afb92   Nathanael Jourdane   Refactoring
665
666
667
668
669
        getRowClass: function (record) {
          const nbRes = record.get('nb_results')
          return nbRes === 0 || nbRes === -1 ? 'disabled_row'
            : nbRes === -2 ? 'error_row'
            : false
428eb66e   Nathanael Jourdane   Use JS standard c...
670
671
672
673
674
675
        }
      }
    }
  },

  /**
538afb92   Nathanael Jourdane   Refactoring
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
   Create `epnTapGranulesGrid`, an ExtJS grid containing the granules of the selected service in
   `epnTapServicesGrid`.

   For each granule, this grid displays:
   - the row number;
   - the dataproduct type;
   - the target name;
   - the min and max times;
   - the format;
   - the UID (granule identifier);
   - the estimated size;
   - the URL;
   - the thumbnail.

   Each of these information are displayed in a specific rendering to improve user experience.
   For more information about these parameters,
   see https://voparis-confluence.obspm.fr/display/VES/EPN-TAP+V2.0+parameters.

   Other informations are available through an ExtJS Tooltip on each row:
   - currently only the granule thumbnail, in full size.

   A click on a granule triggers `EpnTapModule.onGranuleSelected()`.
   */
428eb66e   Nathanael Jourdane   Use JS standard c...
699
700
701
702
703
704
705
706
  createGranulesGrid: function () {
    return {
      xtype: 'grid',
      cls: 'epntap_grid',
      id: 'epnTapGranulesGrid',
      title: 'Granules',
      store: Ext.data.StoreManager.lookup('granulesStore'),
      flex: 4,
538afb92   Nathanael Jourdane   Refactoring
707
      loadMask: true,
428eb66e   Nathanael Jourdane   Use JS standard c...
708
709
710
711
712
713
714
715
      plugins: {
        ptype: 'bufferedrenderer',
        trailingBufferZone: 20,
        leadingBufferZone: 50
      },
      columns: []
    }
  }
cc663bbe   Nathanael Jourdane   Remove button dis...
716
})