From c063c0e72faa0eef3a2e29e23b17dc5105ceb04c Mon Sep 17 00:00:00 2001 From: joan Date: Tue, 20 Dec 2022 09:48:41 +0100 Subject: [PATCH] fix(pagination): duplicated rows on paginate Refs: #4531 --- front/core/components/crud-model/crud-model.js | 16 ++++++++++++---- front/core/components/crud-model/index.spec.js | 2 +- front/core/components/drop-down/index.js | 4 ++-- front/core/components/model-proxy/model-proxy.js | 5 +++-- front/core/components/pagination/pagination.js | 4 ++-- .../back/methods/sales-monitor/clientsFilter.js | 1 + modules/monitor/front/index/clients/index.html | 2 +- modules/monitor/front/index/orders/index.html | 2 +- modules/monitor/front/index/tickets/index.html | 2 +- 9 files changed, 24 insertions(+), 14 deletions(-) diff --git a/front/core/components/crud-model/crud-model.js b/front/core/components/crud-model/crud-model.js index 1095985dc..16b837d6a 100644 --- a/front/core/components/crud-model/crud-model.js +++ b/front/core/components/crud-model/crud-model.js @@ -14,6 +14,7 @@ export default class CrudModel extends ModelProxy { this.$q = $q; this.primaryKey = 'id'; this.autoLoad = false; + this.page = 1; } $onInit() { @@ -125,13 +126,20 @@ export default class CrudModel extends ModelProxy { } } - loadMore() { + loadMore(append) { if (!this.moreRows) return this.$q.resolve(); - let filter = Object.assign({}, this.currentFilter); - filter.skip = this.orgData ? this.orgData.length : 0; - return this.sendRequest(filter, true); + const filter = Object.assign({}, this.currentFilter); + if (append) + filter.skip = this.orgData ? this.orgData.length : 0; + + if (!append) { + this.page += 1; + filter.limit = this.page * this.limit; + } + + return this.sendRequest(filter, append); } clear() { diff --git a/front/core/components/crud-model/index.spec.js b/front/core/components/crud-model/index.spec.js index 8673e947f..7eab80405 100644 --- a/front/core/components/crud-model/index.spec.js +++ b/front/core/components/crud-model/index.spec.js @@ -148,7 +148,7 @@ describe('Component vnCrudModel', () => { controller.moreRows = true; - controller.loadMore(); + controller.loadMore(true); expect(controller.sendRequest).toHaveBeenCalledWith({'skip': 2}, true); }); diff --git a/front/core/components/drop-down/index.js b/front/core/components/drop-down/index.js index 08d0da6d0..302c1c6b5 100644 --- a/front/core/components/drop-down/index.js +++ b/front/core/components/drop-down/index.js @@ -212,12 +212,12 @@ export default class DropDown extends Popover { && !this.model.isLoading; if (shouldLoad) - this.model.loadMore(); + this.model.loadMore(true); } onLoadMoreClick(event) { if (event.defaultPrevented) return; - this.model.loadMore(); + this.model.loadMore(true); } onContainerClick(event) { diff --git a/front/core/components/model-proxy/model-proxy.js b/front/core/components/model-proxy/model-proxy.js index 26c28c803..0b8d7ebf9 100644 --- a/front/core/components/model-proxy/model-proxy.js +++ b/front/core/components/model-proxy/model-proxy.js @@ -374,9 +374,10 @@ export class Paginable { /** * When limit is enabled, loads the next set of rows. * + * @param {Boolean} append - Whether should append new data * @return {Promise} The request promise */ - loadMore() { - return Promise.resolve(); + loadMore(append) { + return Promise.resolve(append); } } diff --git a/front/core/components/pagination/pagination.js b/front/core/components/pagination/pagination.js index 9979be368..e7127734c 100644 --- a/front/core/components/pagination/pagination.js +++ b/front/core/components/pagination/pagination.js @@ -73,7 +73,7 @@ class Pagination extends Component { if (shouldLoad) { this.nLoads++; - this.model.loadMore(); + this.model.loadMore(false); this.$.$apply(); } } @@ -82,7 +82,7 @@ class Pagination extends Component { if (this.maxLoads > 0 && this.nLoads == this.maxLoads) this.nLoads = 0; - this.model.loadMore(); + this.model.loadMore(false); } $onDestroy() { diff --git a/modules/monitor/back/methods/sales-monitor/clientsFilter.js b/modules/monitor/back/methods/sales-monitor/clientsFilter.js index 3756a706b..09ea24eb1 100644 --- a/modules/monitor/back/methods/sales-monitor/clientsFilter.js +++ b/modules/monitor/back/methods/sales-monitor/clientsFilter.js @@ -38,6 +38,7 @@ module.exports = Self => { date.setHours(0, 0, 0, 0); const stmt = new ParameterizedSQL(` SELECT + v.id, u.name AS salesPerson, IFNULL(sc.workerSubstitute, c.salesPersonFk) AS salesPersonFk, c.id AS clientFk, diff --git a/modules/monitor/front/index/clients/index.html b/modules/monitor/front/index/clients/index.html index 381c0e1ae..c0e3d1b14 100644 --- a/modules/monitor/front/index/clients/index.html +++ b/modules/monitor/front/index/clients/index.html @@ -61,7 +61,7 @@ - + {{::visit.dated | date:'dd/MM/yy'}} diff --git a/modules/monitor/front/index/orders/index.html b/modules/monitor/front/index/orders/index.html index 6126e23ef..74e80e40e 100644 --- a/modules/monitor/front/index/orders/index.html +++ b/modules/monitor/front/index/orders/index.html @@ -41,7 +41,7 @@ SalesPerson - diff --git a/modules/monitor/front/index/tickets/index.html b/modules/monitor/front/index/tickets/index.html index 138788ed6..2f7c34e2d 100644 --- a/modules/monitor/front/index/tickets/index.html +++ b/modules/monitor/front/index/tickets/index.html @@ -78,7 +78,7 @@ -