Blame view

js/app/views/EpnTapUI.js 10.2 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
12
13
 Ext.create('Ext.data.Store', {
	storeId:'productTypes_store',
	fields: ['id', 'name']
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
14
15
16
});

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

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

Ext.create('Ext.data.Store', {
bfcf6dc8   Nathanael Jourdane   Fill the combo-bo...
27
	storeId: 'services_store',
78c2f505   Nathanael Jourdane   Improve granules ...
28
	fields: ['id', 'nb_results', 'shortname', 'title', 'accessurl']
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
29
30
31
});

Ext.create('Ext.data.Store', {
bfcf6dc8   Nathanael Jourdane   Fill the combo-bo...
32
	storeId:'granules_store',
574171f0   Nathanael Jourdane   Display granules ...
33
	fields:['dataproduct_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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
Ext.define('amdaUI.EpnTapUI', {
	extend: 'Ext.container.Container',
	alias: 'widget.panelEpnTap',

	txt_render: function(val) {
		return '<p style="white-space: normal;">' + val + '</p>';
	},
	link_render: function(val) {
		return '<a href="' + val + '">data</a>';
	},
	img_render: function(val) {
		return '<img src="' + val + '">';
	},
	dpt_render: function(val) {
		var dpt_dic = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.epntap.id).dpt_dic;
		return (val in dpt_dic) ? '<p style="white-space: normal;">' + dpt_dic[val] + '</p>' : '<em>' + val + '</em>';
	},
	format_render: function(val) {
		var mimetype_dic = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.epntap.id).mimetype_dic;
		return (val in mimetype_dic) ? mimetype_dic[val] : '<em style="white-space: normal;">' + val + '</em>';
	},
	size_render: function(val) {
		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);
	},


	init: function(config) {

		// *** Grids ***

		this.servicesGrid = new Ext.grid.Panel({
			id: 'servicesGrid',
			title: 'Services',
			store: Ext.data.StoreManager.lookup('services_store'),
			flex: 1,
			columns: [
				{text: 'Name', dataIndex: 'id', flex: 3},
				{text: 'Results', dataIndex: 'nb_results', flex: 2}
			],
			renderer: function(value, metadata,record) { return getExpandableImage(value, metadata,record); },
			listeners: {
				'cellclick': function(grid, td, cellIndex, record, tr, rowIndex, e, eOpts) {
					myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.epntap.id).onServiceSelected(record.data);
				}
			},
			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);
					var tt_content = '<h3>' + service.get('shortname') + '</h3>';
					tt_content += '<p>' + service.get('title') + '</p>';
					tt_content += '<p>' + service.get('accessurl') + '</p>';
					tooltip.update(tt_content);
				}
			},
			renderTo: Ext.getBody()
		});

		this.granulesGrid = new Ext.grid.Panel({
			id: 'granulesGrid',
			title: 'Granules',
			store: Ext.data.StoreManager.lookup('granules_store'),
			flex: 5,
			cls: 'epntap_granules',
			columns: [
				{ text: 'Type',  dataIndex: 'dataproduct_type', flex: 2, renderer: this.dpt_render },
				{ text: 'Target', dataIndex: 'target_name', flex: 2, renderer: this.txt_render },
				{ text: 'Time min', dataIndex: 'time_min', flex: 2, renderer: this.txt_render },
				{ text: 'Time max', dataIndex: 'time_max', flex: 2, renderer: this.txt_render },
				{ text: 'Format', dataIndex: 'access_format', flex: 2, renderer: this.format_render },
				{ text: 'uid', dataIndex: 'granule_uid', flex: 2, renderer: this.txt_render },
				{ text: 'Size', dataIndex: 'access_estsize', flex: 1, renderer: this.size_render },
				{ text: 'URL', dataIndex: 'access_url', flex: 1, renderer: this.link_render },
				{ text: 'Thumb.', dataIndex: 'thumbnail_url', flex: 1, renderer: this.img_render}
			],
			listeners: {
				'cellclick': function(grid, td, cellIndex, record, tr, rowIndex, e, eOpts) {
					myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.epntap.id).onGranuleSelected(record.data);
				}
			},
			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
161
162
163
164
165
166
			fieldLabel: 'Product type',
			store: Ext.data.StoreManager.lookup('productTypes_store'),
			queryMode: 'local',
			displayField: 'name',
			valueField: 'id',
			name: 'productType',
			editable: false,
bfcf6dc8   Nathanael Jourdane   Fill the combo-bo...
167
168
			listeners: {
				scope: window,
78c2f505   Nathanael Jourdane   Improve granules ...
169
				'change': function(cb) { myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.epntap.id).onProductTypeCB(cb.value); }
bfcf6dc8   Nathanael Jourdane   Fill the combo-bo...
170
			}
78c2f505   Nathanael Jourdane   Improve granules ...
171
172
173
		});

		this.targetClassCB = new Ext.form.field.ComboBox({
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
174
			id: 'targetClassCB',
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
175
176
177
178
179
180
181
			fieldLabel: 'Target class',
			store: Ext.data.StoreManager.lookup('targetClasses_store'),
			queryMode: 'local',
			displayField: 'name',
			valueField: 'id',
			name: 'targetClass',
			editable: false,
bfcf6dc8   Nathanael Jourdane   Fill the combo-bo...
182
183
			listeners: {
				scope: window,
78c2f505   Nathanael Jourdane   Improve granules ...
184
				'select': function(store, records) { myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.epntap.id).onTargetClassCB(records[0]['internalId']); }
bfcf6dc8   Nathanael Jourdane   Fill the combo-bo...
185
			}
78c2f505   Nathanael Jourdane   Improve granules ...
186
187
188
		});

		this.targetNameCB = new Ext.form.field.ComboBox({
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
189
			id: 'targetNameCB',
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
190
191
192
			fieldLabel: 'Target name',
			store: Ext.data.StoreManager.lookup('targetNames_store'),
			queryMode: 'local',
bfcf6dc8   Nathanael Jourdane   Fill the combo-bo...
193
194
			displayField: 'name',
			valueField: 'id',
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
195
			name: 'targetName',
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
196
197
198
199
			triggerAction: 'all',
			typeAhead: true,
			mode: 'remote',
			minChars: 2,
bfcf6dc8   Nathanael Jourdane   Fill the combo-bo...
200
201
202
			forceSelection: true,
			listeners: {
				scope: window,
78c2f505   Nathanael Jourdane   Improve granules ...
203
				'select': function(store, records) { myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.epntap.id).onTargetNameCB(records[0]['internalId']);}
bfcf6dc8   Nathanael Jourdane   Fill the combo-bo...
204
			}
78c2f505   Nathanael Jourdane   Improve granules ...
205
206
207
208
209
		});

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

		this.startTimeDF = new Ext.form.field.Date({
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
210
			id: 'startTimeDF',
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
211
			fieldLabel: 'Start time',
78c2f505   Nathanael Jourdane   Improve granules ...
212
213
214
215
216
			format: 'Y/m/d H:i:s',
			width: 100
		});

		this.stopTimeDF = new Ext.form.field.Date({
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
217
			id: 'stopTimeDF',
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
218
			fieldLabel: 'Stop time',
78c2f505   Nathanael Jourdane   Improve granules ...
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
			format: 'Y/m/d H:i:s',
			width: 100
		});

		this.durationPanel = new Ext.panel.Panel({
			id: 'duration',
			layout: { type: 'hbox', pack: 'start', align: 'stretch' },
			border: false,
			defaults: { width: 60, margin: '0, 5, 0, 5', xtype: 'numberfield'},
			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: {
				'change': function(newValue, oldValue) { myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.epntap.id).updateRowsPerPage(newValue); }
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
257
			}
78c2f505   Nathanael Jourdane   Improve granules ...
258
		});
574171f0   Nathanael Jourdane   Display granules ...
259

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

78c2f505   Nathanael Jourdane   Improve granules ...
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
		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: '|<',
				handler: function() { myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.epntap.id).onFirstPageBtnClicked(); }
			}, {
				id: 'firstPageBtn',
				text: '<',
				handler: function() { myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.epntap.id).onPreviousPageBtnClicked(); }
			}, {
				xtype: 'label',
				id: 'pageLb',
				text: '0/0'
			}, {
				id: 'nextPageBtn',
				text: '>',
				handler: function() { myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.epntap.id).onNextPageBtnClicked(); }
			}, {
				id: 'lastPageBtn',
				text: '>|',
				handler: function() { myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.epntap.id).onLastPageBtnClicked(); }
			}]
		});
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
292

78c2f505   Nathanael Jourdane   Improve granules ...
293
294
295
296
297
298
		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...
299

78c2f505   Nathanael Jourdane   Improve granules ...
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
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
340
		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: {
				afterrender: function() { myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.epntap.id).onWindowLoaded(); }
			}
		});

		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...
341

3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
342
		var myConf = {
78c2f505   Nathanael Jourdane   Improve granules ...
343
			width: 1000,
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
344
345
			height: 550,
			layout: 'border',
78c2f505   Nathanael Jourdane   Improve granules ...
346
			items: [ this.serviceFilterPanel, this.gridsPanel, this.infoPanel ]
3fc0b658   Nathanael Jourdane   Add EPN-TAP modul...
347
		};
78c2f505   Nathanael Jourdane   Improve granules ...
348

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

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