Blame view

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

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

	extend: 'amdaDesktop.AmdaModule',
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
13
	requires: ['amdaUI.EpnTapUI'],
9b951b58   Nathanael Jourdane   Move EPN-TAP modu...
14
	// contentId : 'EpnTapUI',
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
15
16
17
18
19
20
21
22
23
24

	/** 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',

b185823c   Nathanael Jourdane   Use IntervalUI mo...
25
26
27
	/**
	Module initialisation.
	*/
7055f5d6   Nathanael Jourdane   Code refactoring
28
	init: function() {
7055f5d6   Nathanael Jourdane   Code refactoring
29
30
		this.select = Array();
		this.filter = Array();
7055f5d6   Nathanael Jourdane   Code refactoring
31
		this.selectedServiceId = null;
78c2f505   Nathanael Jourdane   Improve granules ...
32

7055f5d6   Nathanael Jourdane   Code refactoring
33
34
35
36
37
38
39
40
		this.launcher = {
			text: this.title,
			iconCls: this.icon,
			handler: this.createWindow,
			scope: this
		};
	},

b185823c   Nathanael Jourdane   Use IntervalUI mo...
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
	/**
	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();
	},

72195d65   Nathanael Jourdane   Automatically set...
57
58
	isDate: function(date) {
		if (date === null) {
b185823c   Nathanael Jourdane   Use IntervalUI mo...
59
60
			return false;
		}
72195d65   Nathanael Jourdane   Automatically set...
61
62
		var dateArr = date.split('/');
		if (dateArr.length != 3 || isNaN(parseInt(dateArr[0])) || isNaN(parseInt(dateArr[1])) || isNaN(parseInt(dateArr[2])) ) {
b185823c   Nathanael Jourdane   Use IntervalUI mo...
63
64
			return false;
		}
72195d65   Nathanael Jourdane   Automatically set...
65
	return true;
b185823c   Nathanael Jourdane   Use IntervalUI mo...
66
67
68
69
70
71
	},

	/****************************
	*** Service filter events ***
	****************************/

9f9ca1da   Nathanael Jourdane   Fix scrollbar (WIP)
72
	createWindow: function (icon_id) {
a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
73
		this.callParent();
9f9ca1da   Nathanael Jourdane   Fix scrollbar (WIP)
74
75
76
77
78
79
80
81
82
83
84
85
		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']
a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
86
		}
9f9ca1da   Nathanael Jourdane   Fix scrollbar (WIP)
87
88

		var target = icons_dic[icon_id];
494949bb   Nathanael Jourdane   Remove dataproduc...
89
		// console.log("target: ", target);
9f9ca1da   Nathanael Jourdane   Fix scrollbar (WIP)
90
		this.initWindow(target);
a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
91
92
	},

b185823c   Nathanael Jourdane   Use IntervalUI mo...
93
94
95
	/**
	Trigerred after the render of `gridsPanel` (containing `servicesGrid` and `granulesGrid`). Among other things,
	initializes the `productType` combobox and the `servicesGrid` table.
9f9ca1da   Nathanael Jourdane   Fix scrollbar (WIP)
96
	- `target`: an array of 3 values: [dataproduct_type, target_class, target_name]; or null.
b185823c   Nathanael Jourdane   Use IntervalUI mo...
97
	*/
9f9ca1da   Nathanael Jourdane   Fix scrollbar (WIP)
98
	initWindow: function(target) {
3a42858d   Nathanael Jourdane   Update the number...
99
		Ext.data.StoreManager.lookup('servicesStore').on('add', function() { this.updateNbResults(); }, this);
b083bc63   Nathanael Jourdane   Update productTyp...
100
101
102
		Ext.data.StoreManager.lookup('servicesStore').load();
		Ext.data.StoreManager.lookup('metadataStore').load();

b185823c   Nathanael Jourdane   Use IntervalUI mo...
103
104
105
106
107
108
109
110
111
112
113
114
115
		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');
98760ae1   Nathanael Jourdane   BugFix window siz...
116
117
		this.epnTapPanel = this.productTypeCB.findParentByType('panelEpnTap');

2b6b4308   Nathanael Jourdane   Make the epntap m...
118
119
120
121
		// If the EPN-TAP module is launched from the AMDA tree
		if(target) {
			// --- Select product types ---
			if (! target[0] in this.productTypeCB.getStore()) {
b083bc63   Nathanael Jourdane   Update productTyp...
122
				alert("Sorry, product type " + target[0] + " is not found in available services.");
2b6b4308   Nathanael Jourdane   Make the epntap m...
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
				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;
			}
8d5634e3   Nathanael Jourdane   Use epn-tap store...
141
			this.targetNameCB.select(target[2]);
2b6b4308   Nathanael Jourdane   Make the epntap m...
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
			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();
		}
2dd526c8   Nathanael Jourdane   Load the services...
158
159
	},

b185823c   Nathanael Jourdane   Use IntervalUI mo...
160
	/**
9f9ca1da   Nathanael Jourdane   Fix scrollbar (WIP)
161
162
163
	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.
b185823c   Nathanael Jourdane   Use IntervalUI mo...
164
	*/
7055f5d6   Nathanael Jourdane   Code refactoring
165
166
167
168
169
	onProductTypeCBChanged: function() {
		this.targetClassCB.getStore().removeAll();
		this.targetNameCB.getStore().removeAll();
		this.targetNameCB.disable();

b185823c   Nathanael Jourdane   Use IntervalUI mo...
170
		if (this.productTypeCB.value == 'all') {
7055f5d6   Nathanael Jourdane   Code refactoring
171
			this.targetClassCB.disable();
2dd526c8   Nathanael Jourdane   Load the services...
172
		} else {
b083bc63   Nathanael Jourdane   Update productTyp...
173
174
			Ext.data.StoreManager.lookup('metadataStore').filter('dataproduct_type', this.productTypeCB.value)
			var targetClasses = Ext.data.StoreManager.lookup('metadataStore').collect('target_class');
2dd526c8   Nathanael Jourdane   Load the services...
175

8d5634e3   Nathanael Jourdane   Use epn-tap store...
176
177
			if (targetClasses.length == 1) {
				this.targetClassCB.getStore().add({'id': targetClasses[0], 'name': this.prettify(targetClasses[0])});
7055f5d6   Nathanael Jourdane   Code refactoring
178
179
				this.targetClassCB.disable();
				this.targetClassCB.select(this.targetClassCB.getStore().getAt(0)['internalId']);
2dd526c8   Nathanael Jourdane   Load the services...
180
			} else {
494949bb   Nathanael Jourdane   Remove dataproduc...
181
				this.targetClassCB.getStore().add({'id': 'all', 'name': this.allPrettify(productTypeDict[this.productTypeCB.value])});
8d5634e3   Nathanael Jourdane   Use epn-tap store...
182
183
				for (var i = 0; i < targetClasses.length; i++) {
					this.targetClassCB.getStore().add({'id': targetClasses[i], 'name': this.prettify(targetClasses[i])});
2dd526c8   Nathanael Jourdane   Load the services...
184
				}
7055f5d6   Nathanael Jourdane   Code refactoring
185
186
				this.targetClassCB.select('all');
				this.targetClassCB.enable();
2dd526c8   Nathanael Jourdane   Load the services...
187
			}
2dd526c8   Nathanael Jourdane   Load the services...
188
		}
7055f5d6   Nathanael Jourdane   Code refactoring
189
190
		this.targetNameCB.getStore().add({'id': 'all', 'name': 'All target names'});
		this.targetNameCB.select('all');
12c10cdb   Nathanael Jourdane   Get the list of s...
191
		this.updateNbResults();
2dd526c8   Nathanael Jourdane   Load the services...
192
193
	},

b185823c   Nathanael Jourdane   Use IntervalUI mo...
194
	/**
9f9ca1da   Nathanael Jourdane   Fix scrollbar (WIP)
195
196
197
	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.
b185823c   Nathanael Jourdane   Use IntervalUI mo...
198
	*/
7055f5d6   Nathanael Jourdane   Code refactoring
199
200
	onTargetClassCBChanged: function() {
		this.targetNameCB.getStore().removeAll();
2dd526c8   Nathanael Jourdane   Load the services...
201

7055f5d6   Nathanael Jourdane   Code refactoring
202
203
204
205
		if (this.targetClassCB.value == 'all') {
			this.targetNameCB.getStore().add({'id': 'all', 'name': 'All target names'});
			this.targetNameCB.select('all');
			this.targetNameCB.disable();
2dd526c8   Nathanael Jourdane   Load the services...
206
		} else {
b083bc63   Nathanael Jourdane   Update productTyp...
207
208
			Ext.data.StoreManager.lookup('metadataStore').filter('target_class', this.targetClassCB.value);
			var targetNames = Ext.data.StoreManager.lookup('metadataStore').collect('target_name');
8d5634e3   Nathanael Jourdane   Use epn-tap store...
209
210
			if (targetNames.length == 1) {
				this.targetNameCB.getStore().add({'id': targetNames[0], 'name': this.prettify(targetNames[0])});
7055f5d6   Nathanael Jourdane   Code refactoring
211
212
				this.targetNameCB.select(this.targetNameCB.getStore().getAt(0)['internalId']);
				this.targetNameCB.disable();
2dd526c8   Nathanael Jourdane   Load the services...
213
			} else {
b185823c   Nathanael Jourdane   Use IntervalUI mo...
214
				this.targetNameCB.getStore().add({'id': 'all', 'name': this.allPrettify(this.targetClassCB.value)});
8d5634e3   Nathanael Jourdane   Use epn-tap store...
215
216
				for (var i = 0; i < targetNames.length; i++) {
					this.targetNameCB.getStore().add({'id': targetNames[i], 'name': this.prettify(targetNames[i])});
2dd526c8   Nathanael Jourdane   Load the services...
217
				}
7055f5d6   Nathanael Jourdane   Code refactoring
218
219
				this.targetNameCB.select('all');
				this.targetNameCB.enable();
2dd526c8   Nathanael Jourdane   Load the services...
220
			}
2dd526c8   Nathanael Jourdane   Load the services...
221
		}
12c10cdb   Nathanael Jourdane   Get the list of s...
222
		this.updateNbResults();
2dd526c8   Nathanael Jourdane   Load the services...
223
224
	},

b185823c   Nathanael Jourdane   Use IntervalUI mo...
225
	/**
9f9ca1da   Nathanael Jourdane   Fix scrollbar (WIP)
226
227
228
	Trigerred when *the user* (not `targetClassCB.select()`) select a new item in `targetNameCB`
	(see `EpnTapUI.createTargetNameCB()`).
	Updates the `servicesGrid` table.
b185823c   Nathanael Jourdane   Use IntervalUI mo...
229
	*/
7055f5d6   Nathanael Jourdane   Code refactoring
230
	onTargetNameCBChanged: function() {
12c10cdb   Nathanael Jourdane   Get the list of s...
231
		this.updateNbResults();
2dd526c8   Nathanael Jourdane   Load the services...
232
233
	},

b185823c   Nathanael Jourdane   Use IntervalUI mo...
234
235
236
237
	/**
	Trigerred when the value of `rowsPerPageNf` is updated (see `EpnTapUI.createRowsPerPageNf()`). Do nothing yet, used
	for debug purposes only.
	*/
7055f5d6   Nathanael Jourdane   Code refactoring
238
	onRowsPerPageChanged: function() {
494949bb   Nathanael Jourdane   Remove dataproduc...
239
		// console.log("rows per page: " + this.productTypeCB);
2dd526c8   Nathanael Jourdane   Load the services...
240
241
	},

b185823c   Nathanael Jourdane   Use IntervalUI mo...
242
243
244
245
246
247
248
249
250
251
252
253
254
	/*********************
	*** 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);
	},
2dd526c8   Nathanael Jourdane   Load the services...
255

b185823c   Nathanael Jourdane   Use IntervalUI mo...
256
257
258
259
	/**
	Trigerred when the `firstPageBtn` button is clicked (see `EpnTapUI.createNavigationPanel()`). Among other things,
	send a new query and fill `granulesGrid`.
	*/
78c2f505   Nathanael Jourdane   Improve granules ...
260
	onFirstPageBtnClicked: function() {
b185823c   Nathanael Jourdane   Use IntervalUI mo...
261
262
263
		var newPageNumber = 1;
		var limit = Number(this.rowsPerPageNf.value);
		var offset = 0;
b083bc63   Nathanael Jourdane   Update productTyp...
264
		var selectedServiceURL = Ext.data.StoreManager.lookup('servicesStore').getById(this.selectedServiceId)['accessurl'];
47a2829d   Nathanael Jourdane   Fix the paginatio...
265

b185823c   Nathanael Jourdane   Use IntervalUI mo...
266
267
268
		this.wait();
		this.disableNavBtns(true, true, false, false);
		this.currentPageLb.setText('' + newPageNumber);
7055f5d6   Nathanael Jourdane   Code refactoring
269
		AmdaAction.epnTapGetGranules(this.selectedServiceId, selectedServiceURL, this.filter, this.select, limit, offset, this.fillGranules);
78c2f505   Nathanael Jourdane   Improve granules ...
270
271
	},

b185823c   Nathanael Jourdane   Use IntervalUI mo...
272
273
274
275
	/**
	Trigerred when the `previousPageBtn` button is clicked (see `EpnTapUI.createNavigationPanel()`). Among other things,
	send a new query and fill `granulesGrid`.
	*/
78c2f505   Nathanael Jourdane   Improve granules ...
276
	onPreviousPageBtnClicked: function() {
47a2829d   Nathanael Jourdane   Fix the paginatio...
277
		var newPageNumber = Number(this.currentPageLb.text) - 1;
b185823c   Nathanael Jourdane   Use IntervalUI mo...
278
279
		var limit = Number(this.rowsPerPageNf.value);
		var offset = (newPageNumber-1) * limit;
b083bc63   Nathanael Jourdane   Update productTyp...
280
		var selectedServiceURL = Ext.data.StoreManager.lookup('servicesStore').getById(this.selectedServiceId)['accessurl'];
47a2829d   Nathanael Jourdane   Fix the paginatio...
281

b185823c   Nathanael Jourdane   Use IntervalUI mo...
282
283
284
285
		this.wait();
		this.currentPageLb.setText('' + newPageNumber);
		var isFirstPage = this.currentPageLb.text === '1';
		this.disableNavBtns(isFirstPage, isFirstPage, false, false);
7055f5d6   Nathanael Jourdane   Code refactoring
286
		AmdaAction.epnTapGetGranules(this.selectedServiceId, selectedServiceURL, this.filter, this.select, limit, offset, this.fillGranules);
78c2f505   Nathanael Jourdane   Improve granules ...
287
288
	},

b185823c   Nathanael Jourdane   Use IntervalUI mo...
289
290
291
292
	/**
	Trigerred when the `nextPageBtn` button is clicked (see `EpnTapUI.createNavigationPanel()`). Among other things,
	send a new query and fill `granulesGrid`.
	*/
78c2f505   Nathanael Jourdane   Improve granules ...
293
	onNextPageBtnClicked: function() {
47a2829d   Nathanael Jourdane   Fix the paginatio...
294
		var newPageNumber = Number(this.currentPageLb.text) + 1;
b185823c   Nathanael Jourdane   Use IntervalUI mo...
295
296
		var limit = Number(this.rowsPerPageNf.value);
		var offset = (newPageNumber-1) * limit;
b083bc63   Nathanael Jourdane   Update productTyp...
297
		var selectedServiceURL = Ext.data.StoreManager.lookup('servicesStore').getById(this.selectedServiceId)['accessurl'];
47a2829d   Nathanael Jourdane   Fix the paginatio...
298

b185823c   Nathanael Jourdane   Use IntervalUI mo...
299
300
301
302
		this.wait();
		this.currentPageLb.setText('' + newPageNumber);
		var isLastPage = this.currentPageLb.text == this.totalPagesLb.text;
		this.disableNavBtns(false, false, isLastPage, isLastPage);
7055f5d6   Nathanael Jourdane   Code refactoring
303
		AmdaAction.epnTapGetGranules(this.selectedServiceId, selectedServiceURL, this.filter, this.select, limit, offset, this.fillGranules);
78c2f505   Nathanael Jourdane   Improve granules ...
304
305
	},

b185823c   Nathanael Jourdane   Use IntervalUI mo...
306
307
308
309
	/**
	Trigerred when the `lastPageBtn` button is clicked (see `EpnTapUI.createNavigationPanel()`). Among other things,
	send a new query and fill `granulesGrid`.
	*/
78c2f505   Nathanael Jourdane   Improve granules ...
310
	onLastPageBtnClicked: function() {
b185823c   Nathanael Jourdane   Use IntervalUI mo...
311
312
313
		var newPageNumber = Number(this.totalPagesLb.text);
		var limit = Number(this.rowsPerPageNf.value);
		var offset = (newPageNumber-1) * limit;
b083bc63   Nathanael Jourdane   Update productTyp...
314
		var selectedServiceURL = Ext.data.StoreManager.lookup('servicesStore').getById(this.selectedServiceId)['accessurl'];
b185823c   Nathanael Jourdane   Use IntervalUI mo...
315
316
317
318

		this.wait();
		this.currentPageLb.setText('' + newPageNumber);
		this.disableNavBtns(false, false, true, true);
7055f5d6   Nathanael Jourdane   Code refactoring
319
		AmdaAction.epnTapGetGranules(this.selectedServiceId, selectedServiceURL, this.filter, this.select, limit, offset, this.fillGranules);
574171f0   Nathanael Jourdane   Display granules ...
320
321
	},

b185823c   Nathanael Jourdane   Use IntervalUI mo...
322
323
324
	/*******************
	*** Grids events ***
	*******************/
7055f5d6   Nathanael Jourdane   Code refactoring
325

b185823c   Nathanael Jourdane   Use IntervalUI mo...
326
327
328
329
	/**
	Trigerred when a row is clicked in `servicesGrid` table (see `EpnTapUI.createServicesGrid()`). Among other things,
	send a new query and fill `granulesGrid`.
	*/
7055f5d6   Nathanael Jourdane   Code refactoring
330
	onServiceSelected: function(selectedServiceId) {
8d5634e3   Nathanael Jourdane   Use epn-tap store...
331
		// console.log("Selected service " + selectedServiceId);
9cd58692   Nathanael Jourdane   Disable services ...
332
		this.wait();
7055f5d6   Nathanael Jourdane   Code refactoring
333
		this.selectedServiceId = selectedServiceId;
78c2f505   Nathanael Jourdane   Improve granules ...
334
		this.select = Array();
8d5634e3   Nathanael Jourdane   Use epn-tap store...
335

b083bc63   Nathanael Jourdane   Update productTyp...
336
		var selectedService = Ext.data.StoreManager.lookup('servicesStore').findRecord('id', selectedServiceId).data;
3a42858d   Nathanael Jourdane   Update the number...
337
		console.log(selectedService);
8d5634e3   Nathanael Jourdane   Use epn-tap store...
338
		if (selectedService == null) {
7055f5d6   Nathanael Jourdane   Code refactoring
339
			throw this.selectedServiceId + ' not found in the list of services.';
78c2f505   Nathanael Jourdane   Improve granules ...
340
341
342
			return;
		}

8d5634e3   Nathanael Jourdane   Use epn-tap store...
343
		var columns = selectedService['columns'].split(',');
7055f5d6   Nathanael Jourdane   Code refactoring
344
345
346
		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);
574171f0   Nathanael Jourdane   Display granules ...
347
348
			}
		}
78c2f505   Nathanael Jourdane   Improve granules ...
349
		this.filter = Array(
9f9ca1da   Nathanael Jourdane   Fix scrollbar (WIP)
350
351
			this.productTypeCB.value === 'all' ? null : this.productTypeCB.value, // product type
			this.targetNameCB.value === 'all' ? null : this.targetNameCB.value, // target name
b97c59e9   Nathanael Jourdane   Provide to the us...
352
353
			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
78c2f505   Nathanael Jourdane   Improve granules ...
354
355
		);

12c10cdb   Nathanael Jourdane   Get the list of s...
356
		// console.log(selectedServiceId, selectedService['access_url'], this.filter);
8d5634e3   Nathanael Jourdane   Use epn-tap store...
357
358
		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);
2dd526c8   Nathanael Jourdane   Load the services...
359
360
	},

b185823c   Nathanael Jourdane   Use IntervalUI mo...
361
362
363
364
	/**
	Trigerred when a row is clicked in `granulesGrid` table (see `EpnTapUI.createGranulesGrid()`). Do nothing yet, used
	for debug purposes only.
	*/
494949bb   Nathanael Jourdane   Remove dataproduc...
365
	onGranuleSelected: function(granule) {
1227cc87   Nathanael Jourdane   Fix the scrollbar...
366
		// console.log('selected granule: ', granule);
2dd526c8   Nathanael Jourdane   Load the services...
367
368
	},

b185823c   Nathanael Jourdane   Use IntervalUI mo...
369
370
371
	/**********************
	*** Other functions ***
	**********************/
78c2f505   Nathanael Jourdane   Improve granules ...
372

b185823c   Nathanael Jourdane   Use IntervalUI mo...
373
	/**
12c10cdb   Nathanael Jourdane   Get the list of s...
374
	Update the nb_result field of the services store (see `EpnTapUI.servicesStore`), according to the field values in `serviceFilterPanel`.
b185823c   Nathanael Jourdane   Use IntervalUI mo...
375
	*/
3a42858d   Nathanael Jourdane   Update the number...
376
377
378
379
380
381
382
383
384
	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 ) {
b083bc63   Nathanael Jourdane   Update productTyp...
385
			var filter = [];
3a42858d   Nathanael Jourdane   Update the number...
386
		} else if(targetClass === 'all') {
b083bc63   Nathanael Jourdane   Update productTyp...
387
			var filter = [
3a42858d   Nathanael Jourdane   Update the number...
388
				{property: "dataproduct_type", value: productType}
8d5634e3   Nathanael Jourdane   Use epn-tap store...
389
			];
3a42858d   Nathanael Jourdane   Update the number...
390
		} else if(targetName === 'all') {
b083bc63   Nathanael Jourdane   Update productTyp...
391
			var filter = [
3a42858d   Nathanael Jourdane   Update the number...
392
393
				{property: "dataproduct_type", value: productType},
				{property: "target_class", value: targetClass}
8d5634e3   Nathanael Jourdane   Use epn-tap store...
394
			];
7055f5d6   Nathanael Jourdane   Code refactoring
395
		} else {
b083bc63   Nathanael Jourdane   Update productTyp...
396
			var filter = [
3a42858d   Nathanael Jourdane   Update the number...
397
398
399
				{property: "dataproduct_type", value: productType},
				{property: "target_class", value: targetClass},
				{property: "target_name", value: targetName}
8d5634e3   Nathanael Jourdane   Use epn-tap store...
400
401
			];
		}
72195d65   Nathanael Jourdane   Automatically set...
402

3a42858d   Nathanael Jourdane   Update the number...
403
		servicesStore.each(function(record, idx) {
b083bc63   Nathanael Jourdane   Update productTyp...
404
405
406
			metadataStore.filter(filter.concat({property: 'service_id', value: record.get('id')}));
			record.set('nb_results', metadataStore.sum('nb_results'));
			metadataStore.clearFilter();
12c10cdb   Nathanael Jourdane   Get the list of s...
407
		});
3a42858d   Nathanael Jourdane   Update the number...
408
		servicesStore.sort('nb_results', 'DESC');
7055f5d6   Nathanael Jourdane   Code refactoring
409

b083bc63   Nathanael Jourdane   Update productTyp...
410
411
		var timeMin = metadataStore.min('time_min');
		var timeMax = metadataStore.max('time_max');
3a42858d   Nathanael Jourdane   Update the number...
412
413
		timeSelector.setLimits(timeMin, timeMax);
		timeSelector.setInterval(timeMin, timeMax);
b185823c   Nathanael Jourdane   Use IntervalUI mo...
414
415
416
417
418
419
420
421
	},

	/**
	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) {
73a466f0   Nathanael Jourdane   Fix NavigationPan...
422
		var totalPages = Math.ceil(Number(nb_results) / Ext.getCmp('epnTapRowsPerPageNf').value);
b185823c   Nathanael Jourdane   Use IntervalUI mo...
423

73a466f0   Nathanael Jourdane   Fix NavigationPan...
424
425
		Ext.getCmp('epnTapCurrentPageLb').setText(totalPages == 0 ? '-' : '1');
		Ext.getCmp('epnTapTotalPagesLb').setText(totalPages == 0 ? '-' : totalPages);
b185823c   Nathanael Jourdane   Use IntervalUI mo...
426
427
428

		Ext.getCmp('epnTapPreviousPageBtn').setDisabled(true);
		Ext.getCmp('epnTapFirstPageBtn').setDisabled(true);
73a466f0   Nathanael Jourdane   Fix NavigationPan...
429
430
		Ext.getCmp('epnTapNextPageBtn').setDisabled(totalPages <= 1);
		Ext.getCmp('epnTapLastPageBtn').setDisabled(totalPages <= 1);
b185823c   Nathanael Jourdane   Use IntervalUI mo...
431
432
433
434
435
436
437
438
439
	},

	/**
	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) {
b97c59e9   Nathanael Jourdane   Provide to the us...
440
		if (granules["error"] != null) {
ba6dfa5e   Nathanael Jourdane   (regression bug) ...
441
			console.log('Can not get request response:', granules["error"]);
b185823c   Nathanael Jourdane   Use IntervalUI mo...
442
443
		} else {
			try {
b185823c   Nathanael Jourdane   Use IntervalUI mo...
444
445
446
				Ext.getCmp('epnTapGranulesGrid').getStore().removeAll();
				Ext.getCmp('epnTapGranulesGrid').getStore().add(granules);
			} catch( e ) {
ba6dfa5e   Nathanael Jourdane   (regression bug) ...
447
				console.log('Can not add granules: ' + e);
b185823c   Nathanael Jourdane   Use IntervalUI mo...
448
449
450
			}
		}
		Ext.getCmp('epnTapServicesGrid').setDisabled(false);
a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
451
		Ext.getCmp('epnTapGranulesGrid').setDisabled(false);
b185823c   Nathanael Jourdane   Use IntervalUI mo...
452
453
454
455
456
457
458
459
		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() {
a048eff4   Nathanael Jourdane   Add EPN-TAP to Am...
460
461
462
		this.servicesGrid.getEl().setStyle('cursor', 'wait');  // CSS is correctly changed but without visible result.
		this.servicesGrid.setDisabled(true);
		this.granulesGrid.setDisabled(true);
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
463
	}
7055f5d6   Nathanael Jourdane   Code refactoring
464

3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
465
});