Blame view

js/app/views/EpnTapUI.js 23.1 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
 */

016bdaae   Nathanael Jourdane   Fix bad rendering...
10
Ext.require(['Ext.grid.plugin.BufferedRenderer']);
b185823c   Nathanael Jourdane   Use IntervalUI mo...
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/**
`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
		https://voparis-confluence.obspm.fr/pages/viewpage.action?pageId=1148225);
- `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...
29
*/
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
30
Ext.create('Ext.data.Store', {
24fcdbc7   Nathanael Jourdane   Fix crash when ep...
31
32
	storeId: 'productTypesStore',
	autoLoad: true,
977e2c07   Nathanael Jourdane   Add tooltips on p...
33
	fields: ['id', 'name', 'desc'],
ebdc15a7   Nathanael Jourdane   remove targetclas...
34
	data: [
977e2c07   Nathanael Jourdane   Add tooltips on p...
35
36
37
38
39
40
41
42
43
44
45
46
47
48
		{'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.'}
ebdc15a7   Nathanael Jourdane   remove targetclas...
49
	]
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
50
51
});

b185823c   Nathanael Jourdane   Use IntervalUI mo...
52
53
54
55
56
57
58
59
60
61
62
/**
`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...
63
Ext.create('Ext.data.Store', {
7055f5d6   Nathanael Jourdane   Code refactoring
64
	storeId: 'targetNamesStore',
8a0f1e9e   Nathanael Jourdane   Add autocompletio...
65
66
67
	fields: ['id', 'name', 'type', 'parent', 'aliases'],
	proxy: {
		type: 'ajax',
68664dca   Nathanael Jourdane   make epntap php f...
68
		url: 'php/epntap.php',
50dd7220   Nathanael Jourdane   epntap.php works ...
69
70
71
72
73
74
		extraParams: { action: 'resolver' }
		// listeners: {
		// 	exception: function(proxy, response, operation) {
		// 		console.log('Error ', response); //TODO: Use ExtJs alert instead
		// 	}
		// }
8a0f1e9e   Nathanael Jourdane   Add autocompletio...
75
	}
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
76
77
});

12c10cdb   Nathanael Jourdane   Get the list of s...
78
79
80
81
82
83
84
/**
`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...
85

12c10cdb   Nathanael Jourdane   Get the list of s...
86
87
88
89
90
91
92
93
94
- `id`: the database name of the service, according to the `table_name` column from the `rr.res_table` in the
		registry database;
- `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
		database;
- `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
		registry database.
*/
8d5634e3   Nathanael Jourdane   Use epn-tap store...
95
Ext.create('Ext.data.Store', {
12c10cdb   Nathanael Jourdane   Get the list of s...
96
	storeId: 'servicesStore',
24fcdbc7   Nathanael Jourdane   Fix crash when ep...
97
	autoLoad: true,
12c10cdb   Nathanael Jourdane   Get the list of s...
98
99
100
101
102
103
104
105
106
107
108
109
110
	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'},
d6674d39   Nathanael Jourdane   Add error and inf...
111
		{name: 'nb_results', type: 'integer'},
016bdaae   Nathanael Jourdane   Fix bad rendering...
112
		{name: 'info', type: 'string'}
8d5634e3   Nathanael Jourdane   Use epn-tap store...
113
114
115
	],
	proxy: {
		type: 'ajax',
49401187   Nathanael Jourdane   epntap: Do not us...
116
		url: 'php/epntap.php',
8c2fa14d   Nathanael Jourdane   Update services g...
117
118
119
120
121
		extraParams : {action: 'getServices'}
	},
	sorters: [
		{property: 'nb_results', direction: 'DESC'},
		{property: 'short_name', direction: 'ASC'}
a8a12768   Nathanael Jourdane   Create the grid m...
122
123
124
125
	],
	listeners: {
		// load: function(record) { console.log(record); }
	}
8d5634e3   Nathanael Jourdane   Use epn-tap store...
126
127
});

b185823c   Nathanael Jourdane   Use IntervalUI mo...
128
/**
b185823c   Nathanael Jourdane   Use IntervalUI mo...
129
`granulesStore`: An ExtJS Store containing the list of granules of the selected service (on `servicesGrid`), which match
ba6dfa5e   Nathanael Jourdane   (regression bug) ...
130
with the granules filter (the selected data product type, target class and target name).
b185823c   Nathanael Jourdane   Use IntervalUI mo...
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146

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
	https://voparis-confluence.obspm.fr/display/VES/EPN-TAP+V2.0+parameters.
- `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
147
// 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...
148
149
150
151
152
153

Ext.define('GranulesModel', {
	extend: 'Ext.data.Model'
	// columns are created dynamically
});

3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
154
Ext.create('Ext.data.Store', {
24fcdbc7   Nathanael Jourdane   Fix crash when ep...
155
	storeId: 'granulesStore',
016bdaae   Nathanael Jourdane   Fix bad rendering...
156
	model: 'GranulesModel',
11f8b45b   Nathanael Jourdane   Use buffered scro...
157
	buffered: true,
87467502   Nathanael Jourdane   Replace page butt...
158
	autoload: false,
016bdaae   Nathanael Jourdane   Fix bad rendering...
159
160
	pageSize: 500,
	leadingBufferZone: 0,
87467502   Nathanael Jourdane   Replace page butt...
161
162
163
	proxy: {
		type: 'ajax',
		url: 'php/epntap.php',
11f8b45b   Nathanael Jourdane   Use buffered scro...
164
		reader: { type: 'json', root: 'data'},
6d616600   Nathanael Jourdane   Fix granules sorter
165
		simpleSortMode: true
016bdaae   Nathanael Jourdane   Fix bad rendering...
166
167
	},
	listeners: {
11f8b45b   Nathanael Jourdane   Use buffered scro...
168
		'beforeprefetch': function(store, operation) {
016bdaae   Nathanael Jourdane   Fix bad rendering...
169
			var service = Ext.data.StoreManager.lookup('servicesStore').getById(store.selectedService).data;
11f8b45b   Nathanael Jourdane   Use buffered scro...
170
171
172
173
174
175
176
177
178
179
180
			store.getProxy().extraParams = {
				'action': 'getGranules',
				'url': service['access_url'],
				'tableName': service['table_name'],
				'targetName': 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']
			};
		},
6d616600   Nathanael Jourdane   Fix granules sorter
181
		'prefetch': function(store, records, successful, operation) {
30cd92df   Roipoussiere   Fix merge conflicts
182
			// console.log('(prefetch) operation ' + (successful ? 'success' : 'failed') + ': ', operation);
6d616600   Nathanael Jourdane   Fix granules sorter
183
184
185
			// console.log(operation.params);
			// console.log(Ext.decode(operation.response.responseText));
		},
a8a12768   Nathanael Jourdane   Create the grid m...
186
		'metachange': function(store, meta) {
a5475297   Nathanael Jourdane   use a hash for me...
187
188
189
190
			if(meta.metaHash != store.metaHash) {
				Ext.getCmp('epnTapGranulesGrid').reconfigure(store, meta.columns);
				store.metaHash = meta.metaHash;
			}
a8a12768   Nathanael Jourdane   Create the grid m...
191
192
		}
	}
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
193
194
});

465b7a40   Nathanael Jourdane   Escape quotes in ...
195
196
197
/**
Error are not displayed here, use try/catch each time it's necessary.
*/
7211d9b5   Nathanael Jourdane   Move util.Format ...
198
199
Ext.define('App.util.Format', {
	override: 'Ext.util.Format',
465b7a40   Nathanael Jourdane   Escape quotes in ...
200
201
202

	// Utils

24fcdbc7   Nathanael Jourdane   Fix crash when ep...
203
204
205
	'prettify': function(data) {
		return data.charAt(0).toUpperCase() + data.replace(/_/g, ' ').substr(1).toLowerCase();
	},
120b2445   Nathanael Jourdane   epntap grids: che...
206
207
208
209
210
211
212
213
214
	'url': function(data) {
		var url_pattern = 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 url_pattern.test(data) ? data : null;
	},
3f51339d   Nathanael Jourdane   Make granules cel...
215
216
	'cell': function(content, tooltip, tooltipTitle) {
		var ttAttr = "";
120b2445   Nathanael Jourdane   epntap grids: che...
217
		if(tooltip !== '') {
3f51339d   Nathanael Jourdane   Make granules cel...
218
219
			var ttTitle = tooltipTitle ? " data-qtitle='" + tooltipTitle + "'" : "";
			ttAttr = ttTitle + "' data-qtip='" + (tooltip ? tooltip : (content ? content : 'No value.')) + "'";
120b2445   Nathanael Jourdane   epntap grids: che...
220
		}
3f51339d   Nathanael Jourdane   Make granules cel...
221
		return "<div class=epntap_cell " + ttAttr + ">" + (content ? content : '-') + "</div>";
120b2445   Nathanael Jourdane   epntap grids: che...
222
	},
465b7a40