Blame view

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

bfcf6dc8   Nathanael Jourdane   Fill the combo-bo...
11
 Ext.create('Ext.data.Store', {
7055f5d6   Nathanael Jourdane   Code refactoring
12
	storeId:'productTypesStore',
bfcf6dc8   Nathanael Jourdane   Fill the combo-bo...
13
	fields: ['id', 'name']
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
14
15
16
});

Ext.create('Ext.data.Store', {
7055f5d6   Nathanael Jourdane   Code refactoring
17
	storeId:'targetClassesStore',
bfcf6dc8   Nathanael Jourdane   Fill the combo-bo...
18
	fields: ['id', 'name']
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
19
20
21
});

Ext.create('Ext.data.Store', {
7055f5d6   Nathanael Jourdane   Code refactoring
22
	storeId: 'targetNamesStore',
bfcf6dc8   Nathanael Jourdane   Fill the combo-bo...
23
	fields: ['id', 'name']
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
24
25
26
});

Ext.create('Ext.data.Store', {
7055f5d6   Nathanael Jourdane   Code refactoring
27
28
	storeId: 'servicesStore',
	fields: ['id', 'nbResults', 'shortName', 'title', 'accessURL']
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
29
30
31
});

Ext.create('Ext.data.Store', {
7055f5d6   Nathanael Jourdane   Code refactoring
32
33
	storeId:'granulesStore',
	fields:['product_type', 'target_name', 'time_min', 'time_max', 'access_format', 'granule_uid', 'access_estsize', 'access_url', 'thumbnail_url']
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
34
35
});

78c2f505   Nathanael Jourdane   Improve granules ...
36
37
38
39
Ext.define('amdaUI.EpnTapUI', {
	extend: 'Ext.container.Container',
	alias: 'widget.panelEpnTap',

7055f5d6   Nathanael Jourdane   Code refactoring
40
	txtRender: function(val) {
78c2f505   Nathanael Jourdane   Improve granules ...
41
42
		return '<p style="white-space: normal;">' + val + '</p>';
	},
7055f5d6   Nathanael Jourdane   Code refactoring
43
	linkRender: function(val) {
78c2f505   Nathanael Jourdane   Improve granules ...
44
45
		return '<a href="' + val + '">data</a>';
	},
7055f5d6   Nathanael Jourdane   Code refactoring
46
47
	imgRender: function(val) {
		return '<img width="40px height="40px" src="' + val + '">';
78c2f505   Nathanael Jourdane   Improve granules ...
48
	},
7055f5d6   Nathanael Jourdane   Code refactoring
49
50
51
	dptRender: function(val) {
		var productTypeDict = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.epntap.id).productTypeDict;
		return (val in productTypeDict) ? '<p style="white-space: normal;">' + productTypeDict[val] + '</p>' : '<em>' + val + '</em>';
78c2f505   Nathanael Jourdane   Improve granules ...
52
	},
7055f5d6   Nathanael Jourdane   Code refactoring
53
54
55
	formatRender: function(val) {
		var mimetypeDict = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.epntap.id).mimetypeDict;
		return (val in mimetypeDict) ? mimetypeDict[val] : '<em style="white-space: normal;">' + val + '</em>';
78c2f505   Nathanael Jourdane   Improve granules ...
56
	},
7055f5d6   Nathanael Jourdane   Code refactoring
57
	sizeRender: function(val) {
78c2f505   Nathanael Jourdane   Improve granules ...
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
		var size = parseInt(val);
		if (isNaN(size)) {
			return '';
		} else if (size >= 1024*1024) {
			return (size/(1024*1024)).toPrecision(3) + 'Go';
		} else if (size >= 1024) {
			return (size/1024).toPrecision(3) + 'Mo';
		} else {
			return size + 'Ko';
		}
	},

	constructor: function(config) {
		this.init(config);
		this.callParent(arguments);
	},

78c2f505   Nathanael Jourdane   Improve granules ...
75
76
	init: function(config) {

7055f5d6   Nathanael Jourdane   Code refactoring
77
78
		var epnTapModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.epntap.id);

78c2f505   Nathanael Jourdane   Improve granules ...
79
80
81
82
83
		// *** Grids ***

		this.servicesGrid = new Ext.grid.Panel({
			id: 'servicesGrid',
			title: 'Services',
7055f5d6   Nathanael Jourdane   Code refactoring
84
			store: Ext.data.StoreManager.lookup('servicesStore'),
78c2f505   Nathanael Jourdane   Improve granules ...
85
86
87
			flex: 1,
			columns: [
				{text: 'Name', dataIndex: 'id', flex: 3},
7055f5d6   Nathanael Jourdane   Code refactoring
88
				{text: 'Results', dataIndex: 'nbResults', flex: 2}
78c2f505   Nathanael Jourdane   Improve granules ...
89
90
91
			],
			renderer: function(value, metadata,record) { return getExpandableImage(value, metadata,record); },
			listeners: {
7055f5d6   Nathanael Jourdane   Code refactoring
92
93
				'cellclick': function(grid, td, cellIndex, record) {
					epnTapModule.onServiceSelected(record.data['id']);
78c2f505   Nathanael Jourdane   Improve granules ...
94
95
96
97
98
99
100
101
102
103
104
105
106
107
				}
			},
			renderTo: Ext.getBody()
		});

		var servicesGridView = this.servicesGrid.getView();
		this.serviceTooltip = new Ext.tip.ToolTip({
			id: 'serviceTooltip',
			target: servicesGridView.el,
			delegate: servicesGridView.itemSelector,
			trackMouse: true,
			listeners: {
				beforeshow: function updateTipBody(tooltip) {
					var service = servicesGridView.getRecord(tooltip.triggerElement);
7055f5d6   Nathanael Jourdane   Code refactoring
108
109
110
111
					var ttContent = '<h3>' + service.get('shortName') + '</h3>';
					ttContent += '<p>' + service.get('title') + '</p>';
					ttContent += '<p>' + service.get('accessURL') + '</p>';
					tooltip.update(ttContent);
78c2f505   Nathanael Jourdane   Improve granules ...
112
113
114
115
116
117
118
119
				}
			},
			renderTo: Ext.getBody()
		});

		this.granulesGrid = new Ext.grid.Panel({
			id: 'granulesGrid',
			title: 'Granules',
7055f5d6   Nathanael Jourdane   Code refactoring
120
			store: Ext.data.StoreManager.lookup('granulesStore'),
78c2f505   Nathanael Jourdane   Improve granules ...
121
			flex: 5,
78c2f505   Nathanael Jourdane   Improve granules ...
122
			columns: [
7055f5d6   Nathanael Jourdane   Code refactoring
123
124
125
126
127
128
129
130
131
				{ text: 'Type',  dataIndex: 'product_type', flex: 2, renderer: this.dptRender },
				{ text: 'Target', dataIndex: 'target_name', flex: 2, renderer: this.txtRender },
				{ text: 'Time min', dataIndex: 'time_min', flex: 2, renderer: this.txtRender },
				{ text: 'Time max', dataIndex: 'time_max', flex: 2, renderer: this.txtRender },
				{ text: 'Format', dataIndex: 'access_format', flex: 2, renderer: this.formatRender },
				{ text: 'uid', dataIndex: 'granule_uid', flex: 2, renderer: this.txtRender },
				{ text: 'Size', dataIndex: 'access_estsize', flex: 1, renderer: this.sizeRender },
				{ text: 'URL', dataIndex: 'access_url', flex: 1, renderer: this.linkRender },
				{ text: 'Thumb.', dataIndex: 'thumbnail_url', flex: 1, renderer: this.imgRender}
78c2f505   Nathanael Jourdane   Improve granules ...
132
133
			],
			listeners: {
7055f5d6   Nathanael Jourdane   Code refactoring
134
135
				'cellclick': function(grid, td, cellIndex, record) {
					epnTapModule.onGranuleSelected(record.data['id']);
78c2f505   Nathanael Jourdane   Improve granules ...
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
				}
			},
			renderTo: Ext.getBody()
		});

		var granulesGridView = this.granulesGrid.getView();
		this.granuleTooltip = new Ext.tip.ToolTip({
			id: 'granuleTooltip',
			target: granulesGridView.el,
			delegate: granulesGridView.itemSelector,
			trackMouse: true,
			listeners: {
				beforeshow: function updateTipBody(tooltip) {
					var thumb = granulesGridView.getRecord(tooltip.triggerElement).get('thumbnail_url');
					tooltip.update('<img src="' + thumb + '">');
				}
			},
			renderTo: Ext.getBody()
		});

		// *** Service filter elements, left part ***

		this.productTypeCB = new Ext.form.field.ComboBox({
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
159
			id: 'productTypeCB',
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
160
			fieldLabel: 'Product type',
7055f5d6   Nathanael Jourdane   Code refactoring
161
			store: Ext.data.StoreManager.lookup('productTypesStore'),
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
162
163
164
165
166
			queryMode: 'local',
			displayField: 'name',
			valueField: 'id',
			name: 'productType',
			editable: false,
bfcf6dc8   Nathanael Jourdane   Fill the combo-bo...
167
			listeners: {
7055f5d6   Nathanael Jourdane   Code refactoring
168
169
170
				'select': function(combo) {
					epnTapModule.onProductTypeCBChanged(combo.value);
				}
bfcf6dc8   Nathanael Jourdane   Fill the combo-bo...
171
			}
78c2f505   Nathanael Jourdane   Improve granules ...
172
173
174
		});

		this.targetClassCB = new Ext.form.field.ComboBox({
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
175
			id: 'targetClassCB',
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
176
			fieldLabel: 'Target class',
7055f5d6   Nathanael Jourdane   Code refactoring
177
			store: Ext.data.StoreManager.lookup('targetClassesStore'),
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
178
179
180
181
182
			queryMode: 'local',
			displayField: 'name',
			valueField: 'id',
			name: 'targetClass',
			editable: false,
bfcf6dc8   Nathanael Jourdane   Fill the combo-bo...
183
			listeners: {
7055f5d6   Nathanael Jourdane   Code refactoring
184
185
186
				'select': function(combo) {
					epnTapModule.onTargetClassCBChanged(combo.value);
				}
bfcf6dc8   Nathanael Jourdane   Fill the combo-bo...
187
			}
78c2f505   Nathanael Jourdane   Improve granules ...
188
189
190
		});

		this.targetNameCB = new Ext.form.field.ComboBox({
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
191
			id: 'targetNameCB',
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
192
			fieldLabel: 'Target name',
7055f5d6   Nathanael Jourdane   Code refactoring
193
			store: Ext.data.StoreManager.lookup('targetNamesStore'),
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
194
			queryMode: 'local',
bfcf6dc8   Nathanael Jourdane   Fill the combo-bo...
195
196
			displayField: 'name',
			valueField: 'id',
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
197
			name: 'targetName',
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
198
199
200
201
			triggerAction: 'all',
			typeAhead: true,
			mode: 'remote',
			minChars: 2,
bfcf6dc8   Nathanael Jourdane   Fill the combo-bo...
202
203
			forceSelection: true,
			listeners: {
7055f5d6   Nathanael Jourdane   Code refactoring
204
205
206
				'select': function(combo) {
					epnTapModule.onTargetNameCBChanged(combo.value);
				}
bfcf6dc8   Nathanael Jourdane   Fill the combo-bo...
207
			}
78c2f505   Nathanael Jourdane   Improve granules ...
208
209
210
211
212
		});

		// *** Service filter elements, right part ***

		this.startTimeDF = new Ext.form.field.Date({
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
213
			id: 'startTimeDF',
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
214
			fieldLabel: 'Start time',
78c2f505   Nathanael Jourdane   Improve granules ...
215
			format: 'Y/m/d H:i:s',
7055f5d6   Nathanael Jourdane   Code refactoring
216
217
218
219
220
221
			width: 100,
			listeners: {
				'select': function(dateField, value) {
					epnTapModule.onTargetNameCBChanged(value);
				}
			}
78c2f505   Nathanael Jourdane   Improve granules ...
222
223
224
		});

		this.stopTimeDF = new Ext.form.field.Date({
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
225
			id: 'stopTimeDF',
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
226
			fieldLabel: 'Stop time',
78c2f505   Nathanael Jourdane   Improve granules ...
227
			format: 'Y/m/d H:i:s',
7055f5d6   Nathanael Jourdane   Code refactoring
228
229
230
231
232
233
			width: 100,
			listeners: {
				'select': function(dateField, value) {
					epnTapModule.onTargetNameCBChanged(value);
				}
			}
78c2f505   Nathanael Jourdane   Improve granules ...
234
235
236
237
238
239
		});

		this.durationPanel = new Ext.panel.Panel({
			id: 'duration',
			layout: { type: 'hbox', pack: 'start', align: 'stretch' },
			border: false,
7055f5d6   Nathanael Jourdane   Code refactoring
240
			defaults: { width: 60, margin: '0, 5, 0, 5', xtype: 'numberfield', listeners: { 'select': function(elmt) { epnTapModule.onDurationChanged(elmt); } } },
78c2f505   Nathanael Jourdane   Improve granules ...
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
			items: [{
				id: 'days',
				margin: '0, 5, 0, 0',
				fieldLabel: 'Duration',
				emptyText: 'Days',
				width: 170
			}, {
				id: 'hours',
				emptyText: 'Hours'
			}, {
				id: 'minutes',
				emptyText: 'Min.'
			}, {
				id: 'seconds',
				emptyText: 'Sec.'
			}]
		});

		this.rowPerPageNf = new Ext.form.field.Number({
			id: 'rowsPerPageNf',
			fieldLabel: 'Rows per page',
			margin: '4 0 4 0',
			width: 160,
			height: 20,
			value: 20,
			minValue: 1,
			maxValue: 500,
			listeners: {
7055f5d6   Nathanael Jourdane   Code refactoring
269
270
271
				'change': function(rowPerPageNf, newValue) {
					epnTapModule.onRowsPerPageChanged(newValue);
				}
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
272
			}
78c2f505   Nathanael Jourdane   Improve granules ...
273
		});
574171f0   Nathanael Jourdane   Display granules ...
274

78c2f505   Nathanael Jourdane   Improve granules ...
275
		// *** Panels ***
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
276

78c2f505   Nathanael Jourdane   Improve granules ...
277
278
279
280
281
282
283
284
285
286
287
		this.pageSelectPanel = new Ext.panel.Panel({
			id: 'pageSelect',
			border: false,
			margin: '2 0 2 50',
			defaults: { margin: '0 5 0 5', width: 20, xtype: 'button', disabled: true},
			items: [{
				xtype: 'label',
				text: 'Page:'
			}, {
				id: 'previousPageBtn',
				text: '|<',
7055f5d6   Nathanael Jourdane   Code refactoring
288
				handler: function() { epnTapModule.onFirstPageBtnClicked(); }
78c2f505   Nathanael Jourdane   Improve granules ...
289
290
291
			}, {
				id: 'firstPageBtn',
				text: '<',
7055f5d6   Nathanael Jourdane   Code refactoring
292
				handler: function() { epnTapModule.onPreviousPageBtnClicked(); }
78c2f505   Nathanael Jourdane   Improve granules ...
293
294
295
296
297
298
299
			}, {
				xtype: 'label',
				id: 'pageLb',
				text: '0/0'
			}, {
				id: 'nextPageBtn',
				text: '>',
7055f5d6   Nathanael Jourdane   Code refactoring
300
				handler: function() { epnTapModule.onNextPageBtnClicked(); }
78c2f505   Nathanael Jourdane   Improve granules ...
301
302
303
			}, {
				id: 'lastPageBtn',
				text: '>|',
7055f5d6   Nathanael Jourdane   Code refactoring
304
				handler: function() { epnTapModule.onLastPageBtnClicked(); }
78c2f505   Nathanael Jourdane   Improve granules ...
305
306
			}]
		});
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
307

78c2f505   Nathanael Jourdane   Improve granules ...
308
309
310
311
312
313
		this.granulePagePanel = new Ext.panel.Panel({
			id: 'granulePagePanel',
			layout: { type: 'hbox', pack: 'start', align: 'stretch' },
			border: false,
			items: [this.rowPerPageNf, this.pageSelectPanel]
		});
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
314

78c2f505   Nathanael Jourdane   Improve granules ...
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
		this.serviceFilterPanel = new Ext.panel.Panel({
			id: 'serviceFilterPanel',
			region : 'north',
			layout: { type: 'hbox', pack: 'start', align: 'stretch' },
			defaults: { margin: 5 },
			items: [{ // Left part
				xtype : 'container',
				layout: 'form',
				flex: 2,
				items: [ this.productTypeCB, this.targetClassCB, this.targetNameCB ]
			}, { // Right part
				xtype : 'container',
				layout: 'form',
				flex: 2,
				items: [ this.startTimeDF, this.stopTimeDF, this.durationPanel, this.granulePagePanel ]
			}]
		});

		this.gridsPanel = new Ext.panel.Panel({
			id: 'gridsPanel',
			region: 'center',
			height: 350,
			layout: { type: 'hbox', pack: 'start', align: 'stretch' },
			items: [ this.servicesGrid, this.granulesGrid ],
			listeners: {
7055f5d6   Nathanael Jourdane   Code refactoring
340
				afterrender: function() { epnTapModule.onWindowLoaded(); }
78c2f505   Nathanael Jourdane   Improve granules ...
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
			}
		});

		this.infoPanel = new Ext.panel.Panel({
			id: 'infoPanel',
			region: 'south',
			title: 'Information',
			collapsible: true,
			flex: 0,
			height: 100,
			autoHide: false,
			bodyStyle: 'padding: 5px',
			iconCls: 'icon-information',
			loader: { autoLoad: true, url: helpDir + 'epnTapHOWTO' }
		});
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
356

3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
357
		var myConf = {
78c2f505   Nathanael Jourdane   Improve granules ...
358
			width: 1000,
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
359
360
			height: 550,
			layout: 'border',
78c2f505   Nathanael Jourdane   Improve granules ...
361
			items: [ this.serviceFilterPanel, this.gridsPanel, this.infoPanel ]
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
362
		};
78c2f505   Nathanael Jourdane   Improve granules ...
363

3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
364
		Ext.apply(this, Ext.apply(arguments, myConf));
78c2f505   Nathanael Jourdane   Improve granules ...
365

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