From b083bc63210d851c61bfe28efe474b64b273df14 Mon Sep 17 00:00:00 2001 From: Nathanael Jourdane <nathanael.jourdane@irap.omp.eu> Date: Fri, 9 Jun 2017 13:06:51 +0200 Subject: [PATCH] Update productType combobox when loading services store. --- js/app/controllers/EpnTapModule.js | 128 +++++++++++++++++++++++++------------------------------------------------------------------------------------------------------- js/app/views/EpnTapUI.js | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 110 insertions(+), 106 deletions(-) diff --git a/js/app/controllers/EpnTapModule.js b/js/app/controllers/EpnTapModule.js index 4618f9c..24cdbaa 100644 --- a/js/app/controllers/EpnTapModule.js +++ b/js/app/controllers/EpnTapModule.js @@ -7,72 +7,6 @@ * @author Nathanael Jourdane */ -// A dictionnary used to associate the productType id (i.e "im") to its value (i.e "Image"). -productTypeDict = { - 'im': 'Image', - 'ma': 'Map', - 'sp': 'Spectrum', - 'ds': 'Dynamic spectrum', - 'sc': 'Spectral cube', - 'pr': 'Profile', - 'vo': 'Volume', - 'mo': 'Movie', - 'cu': 'Cube', - 'ts': 'Time series', - 'ca': 'Catalogue', - 'ci': 'Catalogue item' -}; - -// A dictionnary used to associate the mimetype (i.e "application/fits") to a pretty printed word (i.e "fits"). -mimetypeDict = { - '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' -}; - Ext.define('amdaDesktop.EpnTapModule', { extend: 'amdaDesktop.AmdaModule', @@ -92,12 +26,8 @@ Ext.define('amdaDesktop.EpnTapModule', { Module initialisation. */ init: function() { - this.metadataStore = Ext.data.StoreManager.lookup('metadataStore'); - this.metadataStore.load(); - this.select = Array(); this.filter = Array(); - this.selectedServiceId = null; this.launcher = { @@ -166,6 +96,9 @@ Ext.define('amdaDesktop.EpnTapModule', { - `target`: an array of 3 values: [dataproduct_type, target_class, target_name]; or null. */ initWindow: function(target) { + Ext.data.StoreManager.lookup('servicesStore').load(); + Ext.data.StoreManager.lookup('metadataStore').load(); + this.productTypeCB = Ext.getCmp('epnTapProductTypeCB'); this.targetClassCB = Ext.getCmp('epnTapTargetClassCB'); this.targetNameCB = Ext.getCmp('epnTapTargetNameCB'); @@ -181,23 +114,11 @@ Ext.define('amdaDesktop.EpnTapModule', { this.lastPageBtn = Ext.getCmp('epnTapLastPageBtn'); this.epnTapPanel = this.productTypeCB.findParentByType('panelEpnTap'); - this.servicesGrid.getStore().load(); - // Update productTypeCB - this.productTypeCB.getStore().add({'id': 'all', 'name': 'All data product types'}); - var dataproductType = this.metadataStore.collect('dataproduct_type'); - for (var i = 0; i < dataproductType.length; i++) { - if (dataproductType[i] in productTypeDict) { - this.productTypeCB.getStore().add({'id': dataproductType[i], 'name': this.prettify(productTypeDict[dataproductType[i]])}); - } else { - console.log('Unknown data product type "' + dataproductType[i] + '"'); - } - } - // If the EPN-TAP module is launched from the AMDA tree if(target) { // --- Select product types --- if (! target[0] in this.productTypeCB.getStore()) { - alert("Sorry, product type " + productTypeDict[target[0]] + " is not found in available services."); + alert("Sorry, product type " + target[0] + " is not found in available services."); return; } this.productTypeCB.select(target[0]); @@ -250,8 +171,8 @@ Ext.define('amdaDesktop.EpnTapModule', { if (this.productTypeCB.value == 'all') { this.targetClassCB.disable(); } else { - this.metadataStore.filter('dataproduct_type', this.productTypeCB.value) - var targetClasses = this.metadataStore.collect('target_class'); + Ext.data.StoreManager.lookup('metadataStore').filter('dataproduct_type', this.productTypeCB.value) + var targetClasses = Ext.data.StoreManager.lookup('metadataStore').collect('target_class'); if (targetClasses.length == 1) { this.targetClassCB.getStore().add({'id': targetClasses[0], 'name': this.prettify(targetClasses[0])}); @@ -284,8 +205,8 @@ Ext.define('amdaDesktop.EpnTapModule', { this.targetNameCB.select('all'); this.targetNameCB.disable(); } else { - this.metadataStore.filter('target_class', this.targetClassCB.value); - var targetNames = this.metadataStore.collect('target_name'); + Ext.data.StoreManager.lookup('metadataStore').filter('target_class', this.targetClassCB.value); + var targetNames = Ext.data.StoreManager.lookup('metadataStore').collect('target_name'); if (targetNames.length == 1) { this.targetNameCB.getStore().add({'id': targetNames[0], 'name': this.prettify(targetNames[0])}); this.targetNameCB.select(this.targetNameCB.getStore().getAt(0)['internalId']); @@ -341,7 +262,7 @@ Ext.define('amdaDesktop.EpnTapModule', { var newPageNumber = 1; var limit = Number(this.rowsPerPageNf.value); var offset = 0; - var selectedServiceURL = this.servicesGrid.getStore().getById(this.selectedServiceId)['accessurl']; + var selectedServiceURL = Ext.data.StoreManager.lookup('servicesStore').getById(this.selectedServiceId)['accessurl']; this.wait(); this.disableNavBtns(true, true, false, false); @@ -357,7 +278,7 @@ Ext.define('amdaDesktop.EpnTapModule', { var newPageNumber = Number(this.currentPageLb.text) - 1; var limit = Number(this.rowsPerPageNf.value); var offset = (newPageNumber-1) * limit; - var selectedServiceURL = this.servicesGrid.getStore().getById(this.selectedServiceId)['accessurl']; + var selectedServiceURL = Ext.data.StoreManager.lookup('servicesStore').getById(this.selectedServiceId)['accessurl']; this.wait(); this.currentPageLb.setText('' + newPageNumber); @@ -374,7 +295,7 @@ Ext.define('amdaDesktop.EpnTapModule', { var newPageNumber = Number(this.currentPageLb.text) + 1; var limit = Number(this.rowsPerPageNf.value); var offset = (newPageNumber-1) * limit; - var selectedServiceURL = this.servicesGrid.getStore().getById(this.selectedServiceId)['accessurl']; + var selectedServiceURL = Ext.data.StoreManager.lookup('servicesStore').getById(this.selectedServiceId)['accessurl']; this.wait(); this.currentPageLb.setText('' + newPageNumber); @@ -391,7 +312,7 @@ Ext.define('amdaDesktop.EpnTapModule', { var newPageNumber = Number(this.totalPagesLb.text); var limit = Number(this.rowsPerPageNf.value); var offset = (newPageNumber-1) * limit; - var selectedServiceURL = this.servicesGrid.getStore().getById(this.selectedServiceId)['accessurl']; + var selectedServiceURL = Ext.data.StoreManager.lookup('servicesStore').getById(this.selectedServiceId)['accessurl']; this.wait(); this.currentPageLb.setText('' + newPageNumber); @@ -413,7 +334,7 @@ Ext.define('amdaDesktop.EpnTapModule', { this.selectedServiceId = selectedServiceId; this.select = Array(); - var selectedService = this.servicesGrid.getStore().findRecord('id', selectedServiceId).data; + var selectedService = Ext.data.StoreManager.lookup('servicesStore').findRecord('id', selectedServiceId).data; if (selectedService == null) { throw this.selectedServiceId + ' not found in the list of services.'; return; @@ -454,33 +375,34 @@ Ext.define('amdaDesktop.EpnTapModule', { */ updateNbResults: function(ui) { if(this.productTypeCB.value === 'all' && !this.launchedFromTree ) { - filter = []; + var filter = []; } else if(this.targetClassCB.value === 'all') { - filter = [ + var filter = [ {property: "dataproduct_type", value: this.productTypeCB.value} ]; } else if(this.targetNameCB.value === 'all') { - filter = [ + var filter = [ {property: "dataproduct_type", value: this.productTypeCB.value}, {property: "target_class", value: this.targetClassCB.value} ]; } else { - filter = [ + var filter = [ {property: "dataproduct_type", value: this.productTypeCB.value}, {property: "target_class", value: this.targetClassCB.value}, {property: "target_name", value: this.targetNameCB.value} ]; } + var metadataStore = Ext.data.StoreManager.lookup('metadataStore'); - this.servicesGrid.getStore().each(function(record, idx) { - this.metadataStore.filter(filter.concat({property: 'service_id', value: record['id']})); - record.set('nb_results', this.metadataStore.sum('nb_results')); - this.metadataStore.clearFilter(); + Ext.data.StoreManager.lookup('servicesStore').each(function(record, idx) { + metadataStore.filter(filter.concat({property: 'service_id', value: record.get('id')})); + record.set('nb_results', metadataStore.sum('nb_results')); + metadataStore.clearFilter(); }); - this.servicesGrid.getStore().sort('nb_results', 'DESC'); + Ext.data.StoreManager.lookup('servicesStore').sort('nb_results', 'DESC'); - var timeMin = this.metadataStore.min('time_min'); - var timeMax = this.metadataStore.max('time_max'); + var timeMin = metadataStore.min('time_min'); + var timeMax = metadataStore.max('time_max'); this.timeSelector.setLimits(timeMin, timeMax); this.timeSelector.setInterval(timeMin, timeMax); }, diff --git a/js/app/views/EpnTapUI.js b/js/app/views/EpnTapUI.js index aa49cf8..63bcc98 100644 --- a/js/app/views/EpnTapUI.js +++ b/js/app/views/EpnTapUI.js @@ -26,7 +26,7 @@ in this store and an information message is displayed on the JavaScript console - 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. */ -Ext.create('Ext.data.Store', { +Ext.create('Ext.data.ArrayStore', { storeId:'productTypesStore', fields: ['id', 'name'] }); @@ -123,6 +123,39 @@ Ext.create('Ext.data.ArrayStore', { proxy: { type: 'ajax', url : '../../../generic_data/EpnTapData/metadata.json' + }, + listeners: { + load: function(store) { + // A dictionnary used to associate the productType id (i.e "im") to its value (i.e "Image"). + productTypeDict = { + 'im': 'Image', + 'ma': 'Map', + 'sp': 'Spectrum', + 'ds': 'Dynamic spectrum', + 'sc': 'Spectral cube', + 'pr': 'Profile', + 'vo': 'Volume', + 'mo': 'Movie', + 'cu': 'Cube', + 'ts': 'Time series', + 'ca': 'Catalogue', + 'ci': 'Catalogue item' + }; + + // Update productTypeCB + var productTypeCBStore = Ext.data.StoreManager.lookup('productTypesStore'); + var dataproductTypes = store.collect('dataproduct_type'); + productTypeCBStore.add({'id': 'all', 'name': 'All dataproduct types'}); + for (var i = 0; i < dataproductTypes.length; i++) { + if (dataproductTypes[i] in productTypeDict) { + productTypeCBStore.add({'id': dataproductTypes[i], 'name': productTypeDict[dataproductTypes[i]]}); + } else { + productTypeCBStore.add({'id': dataproductTypes[i], 'name': dataproductTypes[i]}); + console.log('Unknown data product type "' + dataproductTypes[i] + '".'); + } + } + Ext.getCmp('epnTapProductTypeCB').select('all'); + } } }); @@ -298,7 +331,56 @@ Ext.define('amdaUI.EpnTapUI', { return (val in mod.productTypeDict) ? '<p style="white-space: normal;">' + mod.productTypeDict[val] + '</p>' : '<em>' + val + '</em>'; }; var formatRender = function(val) { - return (val in mod.mimetypeDict) ? mod.mimetypeDict[val] : '<em style="white-space: normal;">' + val + '</em>'; + // A dictionnary used to associate the mimetype (i.e "application/fits") to a pretty printed word (i.e "fits"). + mimetypeDict = { + '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 (val in mod.mimetypeDict) ? mimetypeDict[val] : '<em style="white-space: normal;">' + val + '</em>'; }; var sizeRender = function(val) { var size = parseInt(val); @@ -393,8 +475,8 @@ Ext.define('amdaUI.EpnTapUI', { fieldLabel: 'Product type', store: Ext.data.StoreManager.lookup('productTypesStore'), queryMode: 'local', - displayField: 'name', valueField: 'id', + displayField: 'name', name: 'productType', editable: false, listeners: { -- libgit2 0.21.2