Commit e414332703ccb86fdb7398ddf44df0148a200620
1 parent
c6b0cc1f
Exists in
master
and in
112 other branches
Update the service panel dynamically according to the filter.
Showing
1 changed file
with
46 additions
and
18 deletions
Show diff stats
js/app/controllers/EpnTapModule.js
... | ... | @@ -72,19 +72,53 @@ Ext.define('amdaDesktop.EpnTapModule', { |
72 | 72 | }, |
73 | 73 | |
74 | 74 | all_prettify: function(name) { |
75 | - return 'All ' + this.prettify(name[name.length-1] == 's' ? name : name + 's'); | |
75 | + return 'All ' + (name[name.length-1] == 's' ? name : name + 's').replace(/_/g, ' ').toLowerCase(); | |
76 | 76 | }, |
77 | 77 | |
78 | 78 | update_services: function() { |
79 | 79 | this.sp_grid.getStore().removeAll(); |
80 | 80 | this.gp_grid.getStore().removeAll(); |
81 | 81 | |
82 | - // TODO: mettre à jour la liste des services | |
82 | + var filter_dic = new Array(); | |
83 | + if(this.dpt_cb.value == 'all') { | |
84 | + for (var dpt in this.services) { | |
85 | + for (var tc in this.services[dpt]) { | |
86 | + for (tn in this.services[dpt][tc]) { | |
87 | + for (serv in this.services[dpt][tc][tn]) { | |
88 | + filter_dic[serv] = this.services[dpt][tc][tn][serv][0] + (serv in filter_dic ? filter_dic[serv] : 0); | |
89 | + } | |
90 | + } | |
91 | + } | |
92 | + } | |
93 | + } else if (this.tc_cb.value == 'all') { | |
94 | + for (var tc in this.services[this.dpt_cb.value]) { | |
95 | + for (tn in this.services[this.dpt_cb.value][tc]) { | |
96 | + for (serv in this.services[this.dpt_cb.value][tc][tn]) { | |
97 | + filter_dic[serv] = this.services[this.dpt_cb.value][tc][tn][serv][0] + (serv in filter_dic ? filter_dic[serv] : 0); | |
98 | + } | |
99 | + } | |
100 | + } | |
101 | + } else if (this.tn_cb.value == 'all') { | |
102 | + for (tn in this.services[this.dpt_cb.value][this.tc_cb.value]) { | |
103 | + for (serv in this.services[this.dpt_cb.value][this.tc_cb.value][tn]) { | |
104 | + filter_dic[serv] = this.services[this.dpt_cb.value][this.tc_cb.value][tn][serv][0] + (serv in filter_dic ? filter_dic[serv] : 0); | |
105 | + } | |
106 | + } | |
107 | + } else { | |
108 | + for (serv in this.services[this.dpt_cb.value][this.tc_cb.value][this.tn_cb.value]) { | |
109 | + 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); | |
110 | + } | |
111 | + } | |
83 | 112 | |
84 | - // var target_names = services[this.dpt_cb.value][this.tc_cb.value]; | |
85 | - // for (var res_key in results) { | |
86 | - // sp_store.add({'id': res_key, 'nb_results': results[res_key][0]}); | |
87 | - // } | |
113 | + var filter = Object.keys(filter_dic).map(function(key) { | |
114 | + return [key, filter_dic[key]]; | |
115 | + }); | |
116 | + filter.sort(function(first, second) { | |
117 | + return second[1] - first[1]; | |
118 | + }); | |
119 | + for (var s = 0; s < filter.length; s++) { | |
120 | + this.sp_grid.getStore().add({'id': filter[s][0], 'nb_results': filter[s][1]}); | |
121 | + } | |
88 | 122 | }, |
89 | 123 | |
90 | 124 | onWindowLoaded: function(services) { |
... | ... | @@ -126,16 +160,18 @@ Ext.define('amdaDesktop.EpnTapModule', { |
126 | 160 | var target_classes = this.services[this.dpt_cb.value]; |
127 | 161 | |
128 | 162 | if (Object.keys(target_classes).length == 1) { |
129 | - this.tc_cb.getStore().add({'id': target_classes[0], 'name': this.prettify(target_classes[0])}); | |
163 | + this.tc_cb.getStore().add({'id': Object.keys(target_classes)[0], 'name': this.prettify(Object.keys(target_classes)[0])}); | |
130 | 164 | this.tc_cb.disable(); |
165 | + this.tc_cb.select(this.tc_cb.getStore().getAt(0)['internalId']); | |
166 | + this.onTargetClassCB(); | |
131 | 167 | } else { |
132 | 168 | this.tc_cb.getStore().add({'id': 'all', 'name': this.all_prettify(this.dpt_dic[this.dpt_cb.value])}); |
133 | 169 | for (var tc_id in target_classes) { |
134 | 170 | this.tc_cb.getStore().add({'id': tc_id, 'name': this.prettify(tc_id)}); |
135 | 171 | } |
172 | + this.tc_cb.select('all'); | |
136 | 173 | this.tc_cb.enable(); |
137 | 174 | } |
138 | - this.tc_cb.select(this.tc_cb.getStore().getAt(0)['internalId']); | |
139 | 175 | } |
140 | 176 | this.update_services(); |
141 | 177 | }, |
... | ... | @@ -150,15 +186,16 @@ Ext.define('amdaDesktop.EpnTapModule', { |
150 | 186 | |
151 | 187 | if (Object.keys(target_names).length == 1) { |
152 | 188 | this.tn_cb.getStore().add({'id': Object.keys(target_names)[0], 'name': this.prettify(Object.keys(target_names)[0])}); |
189 | + this.tn_cb.select(this.tn_cb.getStore().getAt(0)['internalId']); | |
153 | 190 | this.tn_cb.disable(); |
154 | 191 | } else { |
155 | 192 | this.tn_cb.getStore().add({'id': 'all', 'name': this.all_prettify(this.tc_cb.value)}); |
156 | 193 | for (var tn_id in target_names) { |
157 | 194 | this.tn_cb.getStore().add({'id': tn_id, 'name': this.prettify(tn_id)}); |
158 | 195 | } |
196 | + this.tn_cb.select('all'); | |
159 | 197 | this.tn_cb.enable(); |
160 | 198 | } |
161 | - this.tn_cb.select(this.tn_cb.getStore().getAt(0)['internalId']); | |
162 | 199 | } |
163 | 200 | this.update_services(); |
164 | 201 | }, |
... | ... | @@ -192,14 +229,5 @@ Ext.define('amdaDesktop.EpnTapModule', { |
192 | 229 | handler: this.createWindow, |
193 | 230 | scope: this |
194 | 231 | }; |
195 | - | |
196 | - // this.onWindowLoaded = onWindowLoaded; | |
197 | - // this.onSearchBtnClicked = onSearchBtnClicked; | |
198 | - // this.onProductTypeCB = onProductTypeCB; | |
199 | - // this.onGranuleSelected = onGranuleSelected; | |
200 | - // this.onServiceSelected = onServiceSelected; | |
201 | - // this.onTargetClassCB = onTargetClassCB; | |
202 | - // this.onTargetNameCB = onTargetNameCB; | |
203 | 232 | } |
204 | - | |
205 | 233 | }); |
... | ... |