EpnTapModule.js
7.93 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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
/**
* Project : AMDA-NG
* Name : EpnTapModule.js
* @class amdaDesktop.EpnTapModule
* @extends amdaDesktop.AmdaModule
* @brief EpnTap Module controller definition
* @author Nathanael Jourdane
*/
// 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 : 800,
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.metadata) {
for (var tc in this.metadata[dpt]) {
for (tn in this.metadata[dpt][tc]) {
for (serv in this.metadata[dpt][tc][tn]) {
filter_dic[serv] = this.metadata[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.metadata[this.dpt_cb.value]) {
for (tn in this.metadata[this.dpt_cb.value][tc]) {
for (serv in this.metadata[this.dpt_cb.value][tc][tn]) {
filter_dic[serv] = this.metadata[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.metadata[this.dpt_cb.value][this.tc_cb.value]) {
for (serv in this.metadata[this.dpt_cb.value][this.tc_cb.value][tn]) {
filter_dic[serv] = this.metadata[this.dpt_cb.value][this.tc_cb.value][tn][serv][0] + (serv in filter_dic ? filter_dic[serv] : 0);
}
}
} else {
for (serv in this.metadata[this.dpt_cb.value][this.tc_cb.value][this.tn_cb.value]) {
filter_dic[serv] = this.metadata[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.metadata = JSON.parse(loadTextFileAjaxSync('../../generic_data/EpnTapData/metadata.json', "application/json"));
this.services = JSON.parse(loadTextFileAjaxSync('../../generic_data/EpnTapData/EpnTapServices.json', "application/json"));
console.log(Object.keys(this.metadata).length + " dataproduct_type répertoriés.");
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'});
this.tc_cb.getStore().add({'id': 'all', 'name': 'All target names'});
this.tn_cb.getStore().add({'id': 'all', 'name': 'All target classes'});
for (var dpt_id in this.metadata) {
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.tc_cb.select('all');
this.tn_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.metadata[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.tn_cb.getStore().add({'id': 'all', 'name': 'All target names'});
this.tn_cb.select('all');
this.update_services();
},
onTargetClassCB: function() {
this.tn_cb.getStore().removeAll();
if (this.tc_cb.value == 'all') {
this.tn_cb.getStore().add({'id': 'all', 'name': 'All target names'});
this.tn_cb.select('all');
this.tn_cb.disable();
} else {
var target_names = this.metadata[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");
},
fillGranules: function(granules) {
console.log(granules);
Ext.getCmp('granulesPanel').getStore().removeAll();
Ext.getCmp('granulesPanel').getStore().add(granules);
},
onServiceSelected: function(service) {
var select = Array();
for (var i_s = 0 ; i_s < this.services.length ; i_s++) {
if (this.services[i_s]['schema'] === service['id']) {
var columns = this.services[i_s]['columns'].split(',');
for (var i_c=0 ; i_c<this.gp_grid.columns.length ; i_c++) {
if (columns.indexOf(this.gp_grid.columns[i_c].dataIndex) != -1)
select.push(this.gp_grid.columns[i_c].dataIndex)
}
var filter = Array(
this.dpt_cb.value !== 'all' ? this.dpt_cb.value : null,
this.tn_cb.value !== 'all' ? this.dpt_cb.value : null,
Ext.getCmp('startTimeDF').rawValue !== '' ? this.dpt_cb.value : null,
Ext.getCmp('stopTimeDF').rawValue !== '' ? this.dpt_cb.value : null);
break;
}
}
console.log("Getting granules of " + service['id'] + "...");
AmdaAction.epnTapGetGranules(service['id'], this.services[i_s]['accessurl'], filter, select, this.fillGranules);
},
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
};
}
});