/** * Project : AMDA-NG * Name : EpnTapModule.js * @class amdaDesktop.EpnTapModule * @extends amdaDesktop.AmdaModule * @brief EpnTap Module controller definition * @author Nathanael Jourdane */ // for(let service of Ext.getCmp('servicesPanel').getStore().getRange()) { // var filter = Array(service.data.schema, service.data.accessurl, targetName, productType, startTime, stopTime); // AmdaAction.epnTapMgr('getServiceNbResults', filter, function(epnTapServices) { // service.set('nb_responses', epnTapServices===null ? "-" : epnTapServices); // console.log(epnTapServices); // }); // } // var grid = Ext.getCmp('servicesPanel'); // var selection = grid.getSelectionModel(); // access_url = []; // table_name = []; // for(i=0 ; i<grid.store.getCount() ; i++) { // if(selection.isSelected(i)) { // table_name.push(grid.store.getAt(i).data.table_name); // access_url.push(grid.store.getAt(i).data.access_url); // } // // } // Load text with Ajax synchronously: takes path to file and optional MIME type function loadTextFileAjaxSync(filePath, mimeType) { var xmlhttp=new XMLHttpRequest(); xmlhttp.open("GET", filePath, false); if (mimeType != null) { if (xmlhttp.overrideMimeType) { xmlhttp.overrideMimeType(mimeType); } } xmlhttp.send(); if (xmlhttp.status == 200) { return xmlhttp.responseText; } else { return null; } } Ext.define('amdaDesktop.EpnTapModule', { extend: 'amdaDesktop.AmdaModule', // requires: ['amdaUI.EpnTapUI', 'amdaReader.EpnTapReader'], requires: ['amdaUI.EpnTapUI'], contentId : 'EpnTapUI', /** 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', width : 600, height: 550, dpt_dic: { "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" }, prettify: function(name) { return name.charAt(0).toUpperCase() + name.replace(/_/g, ' ').substr(1).toLowerCase(); }, all_prettify: function(name) { return 'All ' + (name[name.length-1] == 's' ? name : name + 's').replace(/_/g, ' ').toLowerCase(); }, update_services: function() { this.sp_grid.getStore().removeAll(); this.gp_grid.getStore().removeAll(); var filter_dic = new Array(); if(this.dpt_cb.value == 'all') { for (var dpt in this.services) { for (var tc in this.services[dpt]) { for (tn in this.services[dpt][tc]) { for (serv in this.services[dpt][tc][tn]) { filter_dic[serv] = this.services[dpt][tc][tn][serv][0] + (serv in filter_dic ? filter_dic[serv] : 0); } } } } } else if (this.tc_cb.value == 'all') { for (var tc in this.services[this.dpt_cb.value]) { for (tn in this.services[this.dpt_cb.value][tc]) { for (serv in this.services[this.dpt_cb.value][tc][tn]) { filter_dic[serv] = this.services[this.dpt_cb.value][tc][tn][serv][0] + (serv in filter_dic ? filter_dic[serv] : 0); } } } } else if (this.tn_cb.value == 'all') { for (tn in this.services[this.dpt_cb.value][this.tc_cb.value]) { for (serv in this.services[this.dpt_cb.value][this.tc_cb.value][tn]) { filter_dic[serv] = this.services[this.dpt_cb.value][this.tc_cb.value][tn][serv][0] + (serv in filter_dic ? filter_dic[serv] : 0); } } } else { for (serv in this.services[this.dpt_cb.value][this.tc_cb.value][this.tn_cb.value]) { filter_dic[serv] = this.services[this.dpt_cb.value][this.tc_cb.value][this.tn_cb.value][serv][0] + (serv in filter_dic ? filter_dic[serv] : 0); } } var filter = Object.keys(filter_dic).map(function(key) { return [key, filter_dic[key]]; }); filter.sort(function(first, second) { return second[1] - first[1]; }); for (var s = 0; s < filter.length; s++) { this.sp_grid.getStore().add({'id': filter[s][0], 'nb_results': filter[s][1]}); } }, onWindowLoaded: function(services) { this.services = JSON.parse(loadTextFileAjaxSync('../../generic_data/EpnTapData/services.json', "application/json")); this.dpt_cb = Ext.getCmp('productTypeCB'); this.tc_cb = Ext.getCmp('targetClassCB'); this.tn_cb = Ext.getCmp('targetNameCB'); this.sp_grid = Ext.getCmp('servicesPanel'); this.gp_grid = Ext.getCmp('granulesPanel'); this.dpt_cb.getStore().removeAll(); this.tc_cb.getStore().removeAll(); this.tn_cb.getStore().removeAll(); this.tc_cb.disable(); this.tn_cb.disable(); this.dpt_cb.getStore().add({'id': 'all', 'name': 'All data product types'}); for (var dpt_id in this.services) { if (dpt_id in this.dpt_dic) { this.dpt_cb.getStore().add({'id': dpt_id, 'name': this.prettify(this.dpt_dic[dpt_id])}); } else { console.log("Unknown data product type '" + dpt_id + "'"); } } this.dpt_cb.select('all'); this.update_services(); }, onProductTypeCB: function() { this.tc_cb.getStore().removeAll(); this.tn_cb.getStore().removeAll(); this.tn_cb.disable(); if (this.dpt_cb.value == 'all') { this.tc_cb.disable(); } else { var target_classes = this.services[this.dpt_cb.value]; if (Object.keys(target_classes).length == 1) { this.tc_cb.getStore().add({'id': Object.keys(target_classes)[0], 'name': this.prettify(Object.keys(target_classes)[0])}); this.tc_cb.disable(); this.tc_cb.select(this.tc_cb.getStore().getAt(0)['internalId']); this.onTargetClassCB(); } else { this.tc_cb.getStore().add({'id': 'all', 'name': this.all_prettify(this.dpt_dic[this.dpt_cb.value])}); for (var tc_id in target_classes) { this.tc_cb.getStore().add({'id': tc_id, 'name': this.prettify(tc_id)}); } this.tc_cb.select('all'); this.tc_cb.enable(); } } this.update_services(); }, onTargetClassCB: function() { this.tn_cb.getStore().removeAll(); if (this.tc_cb.value == 'all') { this.tn_cb.disable(); } else { var target_names = this.services[this.dpt_cb.value][this.tc_cb.value]; if (Object.keys(target_names).length == 1) { this.tn_cb.getStore().add({'id': Object.keys(target_names)[0], 'name': this.prettify(Object.keys(target_names)[0])}); this.tn_cb.select(this.tn_cb.getStore().getAt(0)['internalId']); this.tn_cb.disable(); } else { this.tn_cb.getStore().add({'id': 'all', 'name': this.all_prettify(this.tc_cb.value)}); for (var tn_id in target_names) { this.tn_cb.getStore().add({'id': tn_id, 'name': this.prettify(tn_id)}); } this.tn_cb.select('all'); this.tn_cb.enable(); } } this.update_services(); }, onTargetNameCB: function() { this.update_services(); }, onSearchBtnClicked: function() { console.log("onSearchBtnClicked"); }, onServiceSelected: function(service) { var filter = Array(service['schema'], service['accessurl'], Ext.getCmp('targetNameCB').value, this.dpt_cb.value, Ext.getCmp('startTimeDF').rawValue, Ext.getCmp('stopTimeDF').rawValue); AmdaAction.epnTapMgr('getGranules', filter, function(granules) { console.log(granules); }); }, onGranuleSelected: function(granule) { console.log('selected granule: ' + granule.target_name); }, /** @class Module initialisation. */ init: function() { this.launcher = { text: this.title, iconCls: this.icon, handler: this.createWindow, scope: this }; } });