Commit 47a2829d7a617be5762af842a7077cfcdc92f866
1 parent
7055f5d6
Exists in
master
and in
111 other branches
Fix the pagination tool.
Showing
3 changed files
with
99 additions
and
42 deletions
Show diff stats
js/app/controllers/EpnTapModule.js
... | ... | @@ -60,8 +60,6 @@ function isLatest(newStrDate, oldStrDate) { |
60 | 60 | } |
61 | 61 | } |
62 | 62 | |
63 | - | |
64 | - | |
65 | 63 | Ext.define('amdaDesktop.EpnTapModule', { |
66 | 64 | |
67 | 65 | extend: 'amdaDesktop.AmdaModule', |
... | ... | @@ -90,8 +88,6 @@ Ext.define('amdaDesktop.EpnTapModule', { |
90 | 88 | this.productTypeDict = JSON.parse(loadTextFileAjaxSync('../../generic_data/EpnTapData/dataproduct_types.json', 'application/json')); |
91 | 89 | this.mimetypeDict = JSON.parse(loadTextFileAjaxSync('../../generic_data/EpnTapData/mimetypes.json', 'application/json')); |
92 | 90 | |
93 | - this.currentPage = 0; | |
94 | - this.nbRows = 0; | |
95 | 91 | this.select = Array(); |
96 | 92 | this.filter = Array(); |
97 | 93 | |
... | ... | @@ -110,15 +106,20 @@ Ext.define('amdaDesktop.EpnTapModule', { |
110 | 106 | this.dataProdutTypeCB = Ext.getCmp('productTypeCB'); |
111 | 107 | this.targetClassCB = Ext.getCmp('targetClassCB'); |
112 | 108 | this.targetNameCB = Ext.getCmp('targetNameCB'); |
109 | + this.startTimeDF = Ext.getCmp('startTimeDF'); | |
110 | + this.stopTimeDF = Ext.getCmp('stopTimeDF'); | |
111 | + | |
113 | 112 | this.servicesGrid = Ext.getCmp('servicesGrid'); |
114 | 113 | this.granulesGrid = Ext.getCmp('granulesGrid'); |
115 | - this.pageLabel = Ext.getCmp('pageLb'); | |
114 | + | |
115 | + this.rowsPerPageNf = Ext.getCmp('rowsPerPageNf'); | |
116 | + this.currentPageLb = Ext.getCmp('currentPageLb'); | |
117 | + this.totalPagesLb = Ext.getCmp('totalPagesLb'); | |
118 | + | |
116 | 119 | this.previousBtn = Ext.getCmp('previousPageBtn'); |
117 | 120 | this.nextBtn = Ext.getCmp('nextPageBtn'); |
118 | 121 | this.firstBtn = Ext.getCmp('firstPageBtn'); |
119 | 122 | this.lastBtn = Ext.getCmp('lastPageBtn'); |
120 | - this.startTimeDF = Ext.getCmp('startTimeDF'); | |
121 | - this.stopTimeDF = Ext.getCmp('stopTimeDF'); | |
122 | 123 | |
123 | 124 | this.dataProdutTypeCB.getStore().removeAll(); |
124 | 125 | this.dataProdutTypeCB.getStore().add({'id': 'all', 'name': 'All data product types'}); |
... | ... | @@ -130,7 +131,6 @@ Ext.define('amdaDesktop.EpnTapModule', { |
130 | 131 | } |
131 | 132 | } |
132 | 133 | this.dataProdutTypeCB.select('all'); |
133 | - this | |
134 | 134 | |
135 | 135 | this.targetClassCB.getStore().removeAll(); |
136 | 136 | this.targetClassCB.getStore().add({'id': 'all', 'name': 'All target names'}); |
... | ... | @@ -161,7 +161,6 @@ Ext.define('amdaDesktop.EpnTapModule', { |
161 | 161 | this.targetClassCB.getStore().add({'id': Object.keys(targetClasses)[0], 'name': prettify(Object.keys(targetClasses)[0])}); |
162 | 162 | this.targetClassCB.disable(); |
163 | 163 | this.targetClassCB.select(this.targetClassCB.getStore().getAt(0)['internalId']); |
164 | - this.onTargetClassCB(); | |
165 | 164 | } else { |
166 | 165 | this.targetClassCB.getStore().add({'id': 'all', 'name': allPrettify(this.productTypeDict[this.dataProdutTypeCB.value])}); |
167 | 166 | for (var targetClassId in targetClasses) { |
... | ... | @@ -207,44 +206,75 @@ Ext.define('amdaDesktop.EpnTapModule', { |
207 | 206 | }, |
208 | 207 | |
209 | 208 | onRowsPerPageChanged: function() { |
210 | - var rowsPerPage = Ext.getCmp('rowsPerPageNf').value; | |
211 | - var nbPages = Math.ceil(this.nbRows / rowsPerPage); | |
212 | - this.currentPage = 1; | |
213 | - this.pageLabel.setText('1/' + nbPages); | |
214 | - this.previousPageBtn.setDisabled(true); | |
215 | - this.firstPageBtn.setDisabled(true); | |
216 | - if (nbPages==1) { | |
217 | - this.nextPageBtn.setDisabled(true); | |
218 | - this.lastPageBtn.setDisabled(true); | |
219 | - } else { | |
220 | - this.nextPageBtn.setDisabled(false); | |
221 | - this.lastPageBtn.setDisabled(false); | |
222 | - } | |
209 | + console.log("rows per page: " + this.rowsPerPageNf.value); | |
223 | 210 | }, |
224 | 211 | |
225 | 212 | // *** Buttons events *** |
226 | 213 | |
227 | 214 | onFirstPageBtnClicked: function() { |
228 | - var limit = this.rowsPerPageNf.value; | |
215 | + this.currentPageLb.setText('1'); | |
216 | + | |
217 | + this.nextBtn.setDisabled(false); | |
218 | + this.lastBtn.setDisabled(false); | |
219 | + this.firstBtn.setDisabled(true); | |
220 | + this.previousBtn.setDisabled(true); | |
221 | + | |
229 | 222 | var selectedServiceURL = this.services[this.selectedServiceId]['accessurl']; |
223 | + var limit = this.rowsPerPageNf.value; | |
224 | + var offset = '0'; | |
225 | + | |
230 | 226 | AmdaAction.epnTapGetGranules(this.selectedServiceId, selectedServiceURL, this.filter, this.select, limit, offset, this.fillGranules); |
231 | 227 | }, |
232 | 228 | |
233 | 229 | onPreviousPageBtnClicked: function() { |
234 | - var limit = this.rowsPerPageNf.value; | |
230 | + var newPageNumber = Number(this.currentPageLb.text) - 1; | |
231 | + this.currentPageLb.setText('' + newPageNumber); | |
232 | + | |
233 | + this.nextBtn.setDisabled(false); | |
234 | + this.lastBtn.setDisabled(false); | |
235 | + if (this.currentPageLb.text === '1') { | |
236 | + this.previousBtn.setDisabled(true); | |
237 | + this.firstBtn.setDisabled(true); | |
238 | + } | |
239 | + | |
235 | 240 | var selectedServiceURL = this.services[this.selectedServiceId]['accessurl']; |
241 | + var limit = this.rowsPerPageNf.value; | |
242 | + var offset = '' + (newPageNumber-1) * Number(this.rowsPerPageNf.value); | |
243 | + | |
236 | 244 | AmdaAction.epnTapGetGranules(this.selectedServiceId, selectedServiceURL, this.filter, this.select, limit, offset, this.fillGranules); |
237 | 245 | }, |
238 | 246 | |
239 | 247 | onNextPageBtnClicked: function() { |
240 | - var limit = this.rowsPerPageNf.value; | |
248 | + var newPageNumber = Number(this.currentPageLb.text) + 1; | |
249 | + this.currentPageLb.setText('' + newPageNumber); | |
250 | + | |
251 | + this.previousBtn.setDisabled(false); | |
252 | + this.firstBtn.setDisabled(false); | |
253 | + if (this.currentPageLb.text === this.totalPagesLb.text) { | |
254 | + this.nextBtn.setDisabled(true); | |
255 | + this.lastBtn.setDisabled(true); | |
256 | + } | |
257 | + | |
241 | 258 | var selectedServiceURL = this.services[this.selectedServiceId]['accessurl']; |
259 | + var limit = this.rowsPerPageNf.value; | |
260 | + var offset = '' + (newPageNumber-1) * Number(this.rowsPerPageNf.value); | |
261 | + | |
242 | 262 | AmdaAction.epnTapGetGranules(this.selectedServiceId, selectedServiceURL, this.filter, this.select, limit, offset, this.fillGranules); |
243 | 263 | }, |
244 | 264 | |
245 | 265 | onLastPageBtnClicked: function() { |
246 | - var limit = this.rowsPerPageNf.value; | |
266 | + var newPageNumber = this.totalPagesLb.text; | |
267 | + this.currentPageLb.setText('' + newPageNumber); | |
268 | + | |
269 | + this.previousBtn.setDisabled(false); | |
270 | + this.firstBtn.setDisabled(false); | |
271 | + this.nextBtn.setDisabled(true); | |
272 | + this.lastBtn.setDisabled(true); | |
273 | + | |
247 | 274 | var selectedServiceURL = this.services[this.selectedServiceId]['accessurl']; |
275 | + var limit = this.rowsPerPageNf.value; | |
276 | + var offset = '' + (newPageNumber-1) * Number(this.rowsPerPageNf.value); | |
277 | + | |
248 | 278 | AmdaAction.epnTapGetGranules(this.selectedServiceId, selectedServiceURL, this.filter, this.select, limit, offset, this.fillGranules); |
249 | 279 | }, |
250 | 280 | |
... | ... | @@ -273,10 +303,9 @@ Ext.define('amdaDesktop.EpnTapModule', { |
273 | 303 | Ext.getCmp('stopTimeDF').getRawValue() !== '' ? Ext.getCmp('stopTimeDF').getRawValue() : null // stop time |
274 | 304 | ); |
275 | 305 | |
276 | - var limit = Ext.getCmp('rowsPerPageNf').value; | |
277 | - | |
306 | + var limit = this.rowsPerPageNf.value; | |
307 | + AmdaAction.epnTapGetNbRows(selectedServiceId, selectedServiceURL, this.filter, this.updateNbRows); | |
278 | 308 | AmdaAction.epnTapGetGranules(selectedServiceId, selectedServiceURL, this.filter, this.select, limit, 0, this.fillGranules); |
279 | - AmdaAction.epnTapGetNbRows(selectedServiceId, selectedServiceURL, this.filter, this.updateNbResult); | |
280 | 309 | }, |
281 | 310 | |
282 | 311 | onGranuleSelected: function() { |
... | ... | @@ -285,7 +314,26 @@ Ext.define('amdaDesktop.EpnTapModule', { |
285 | 314 | |
286 | 315 | // *** Other functions *** |
287 | 316 | |
317 | + updateNbRows: function(nb_results) { | |
318 | + /* /!\ Can not get `this`. */ | |
319 | + var totalPages = '' + Math.ceil(Number(nb_results) / Ext.getCmp('rowsPerPageNf').value); | |
320 | + | |
321 | + Ext.getCmp('currentPageLb').setText('1'); | |
322 | + Ext.getCmp('totalPagesLb').setText(totalPages); | |
323 | + Ext.getCmp('previousPageBtn').setDisabled(true); | |
324 | + Ext.getCmp('firstPageBtn').setDisabled(true); | |
325 | + if (totalPages === '1') { | |
326 | + Ext.getCmp('nextPageBtn').setDisabled(true); | |
327 | + Ext.getCmp('lastPageBtn').setDisabled(true); | |
328 | + } else { | |
329 | + Ext.getCmp('nextPageBtn').setDisabled(false); | |
330 | + Ext.getCmp('lastPageBtn').setDisabled(false); | |
331 | + } | |
332 | + }, | |
333 | + | |
288 | 334 | fillGranules: function(granules) { |
335 | + /* /!\ Can not get `this`. */ | |
336 | + | |
289 | 337 | if (granules == null) { |
290 | 338 | console.log("There is no granules to add."); |
291 | 339 | } else { |
... | ... | @@ -299,11 +347,6 @@ Ext.define('amdaDesktop.EpnTapModule', { |
299 | 347 | } |
300 | 348 | }, |
301 | 349 | |
302 | - updateNbResult: function(nb_results) { | |
303 | - console.log("updateNbResult"); | |
304 | - console.log(nb_results); | |
305 | - }, | |
306 | - | |
307 | 350 | updateServices: function() { |
308 | 351 | this.servicesGrid.getStore().removeAll(); |
309 | 352 | this.granulesGrid.getStore().removeAll(); | ... | ... |
js/app/views/EpnTapUI.js
... | ... | @@ -283,24 +283,37 @@ Ext.define('amdaUI.EpnTapUI', { |
283 | 283 | xtype: 'label', |
284 | 284 | text: 'Page:' |
285 | 285 | }, { |
286 | - id: 'previousPageBtn', | |
286 | + id: 'firstPageBtn', | |
287 | 287 | text: '|<', |
288 | + tooltip: 'First page', | |
288 | 289 | handler: function() { epnTapModule.onFirstPageBtnClicked(); } |
289 | 290 | }, { |
290 | - id: 'firstPageBtn', | |
291 | + id: 'previousPageBtn', | |
291 | 292 | text: '<', |
293 | + tooltip: 'Previous page', | |
292 | 294 | handler: function() { epnTapModule.onPreviousPageBtnClicked(); } |
293 | 295 | }, { |
294 | 296 | xtype: 'label', |
295 | - id: 'pageLb', | |
296 | - text: '0/0' | |
297 | + id: 'currentPageLb', | |
298 | + tooltip: 'Current page', | |
299 | + text: '-' | |
300 | + }, { | |
301 | + xtype: 'label', | |
302 | + text: '/' | |
303 | + }, { | |
304 | + xtype: 'label', | |
305 | + id: 'totalPagesLb', | |
306 | + tooltip: 'Total pages', | |
307 | + text: '-' | |
297 | 308 | }, { |
298 | 309 | id: 'nextPageBtn', |
299 | 310 | text: '>', |
311 | + tooltip: 'Next page', | |
300 | 312 | handler: function() { epnTapModule.onNextPageBtnClicked(); } |
301 | 313 | }, { |
302 | 314 | id: 'lastPageBtn', |
303 | 315 | text: '>|', |
316 | + tooltip: 'Last page', | |
304 | 317 | handler: function() { epnTapModule.onLastPageBtnClicked(); } |
305 | 318 | }] |
306 | 319 | }); | ... | ... |
php/classes/EpnTapMgr.php
... | ... | @@ -28,12 +28,12 @@ class EpnTapMgr { |
28 | 28 | return ($date == '00/00/0000') ? '' : $date; |
29 | 29 | } |
30 | 30 | |
31 | - public function createFilter($target_name, $dataproduct_type, $time_min, $time_max) { | |
31 | + public function createFilter($dataproduct_type, $target_name, $time_min, $time_max) { | |
32 | 32 | $filter = array(); |
33 | - if($target_name) | |
34 | - array_push($filter, "target_name = '$target_name'"); | |
35 | 33 | if($dataproduct_type) |
36 | 34 | array_push($filter, "dataproduct_type = '$dataproduct_type'"); |
35 | + if($target_name) | |
36 | + array_push($filter, "target_name = '$target_name'"); | |
37 | 37 | if($time_min) |
38 | 38 | array_push($filter, "time_min <= " . $this->dateToJD($time_min)); |
39 | 39 | if($time_max) |
... | ... | @@ -52,7 +52,7 @@ class EpnTapMgr { |
52 | 52 | return $result; |
53 | 53 | } |
54 | 54 | |
55 | - /* filter order: $target_name, $time_min, $time_max, $table_name, $access_url */ | |
55 | + /* filter order: product type, target name, time min, time max */ | |
56 | 56 | public function getGranules($table_name, $access_url, $filter, $select, $limit, $offset) { |
57 | 57 | $query = "SELECT TOP $limit " . join(', ', $select) . " FROM $table_name.epn_core " . $this->createFilter($filter[0], $filter[1], $filter[2], $filter[3]) . " OFFSET $offset"; |
58 | 58 | // return $query; |
... | ... | @@ -64,6 +64,7 @@ class EpnTapMgr { |
64 | 64 | return $result; |
65 | 65 | } |
66 | 66 | |
67 | + /* filter order: product type, target name, time min, time max */ | |
67 | 68 | public function getNbRows($table_name, $access_url, $filter) { |
68 | 69 | $query = "SELECT COUNT(*) AS nb_rows FROM $table_name.epn_core " . $this->createFilter($filter[0], $filter[1], $filter[2], $filter[3]); |
69 | 70 | // return $query; | ... | ... |