EpnTapModule.js
6.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/**
* 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 ' + this.prettify(name[name.length-1] == 's' ? name : name + 's');
},
update_services: function() {
this.sp_grid.getStore().removeAll();
this.gp_grid.getStore().removeAll();
// TODO: mettre à jour la liste des services
// var target_names = services[this.dpt_cb.value][this.tc_cb.value];
// for (var res_key in results) {
// sp_store.add({'id': res_key, 'nb_results': results[res_key][0]});
// }
},
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': target_classes[0], 'name': this.prettify(target_classes[0])});
this.tc_cb.disable();
} 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.enable();
}
this.tc_cb.select(this.tc_cb.getStore().getAt(0)['internalId']);
}
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.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.enable();
}
this.tn_cb.select(this.tn_cb.getStore().getAt(0)['internalId']);
}
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
};
// this.onWindowLoaded = onWindowLoaded;
// this.onSearchBtnClicked = onSearchBtnClicked;
// this.onProductTypeCB = onProductTypeCB;
// this.onGranuleSelected = onGranuleSelected;
// this.onServiceSelected = onServiceSelected;
// this.onTargetClassCB = onTargetClassCB;
// this.onTargetNameCB = onTargetNameCB;
}
});