pagination bug fix on how found-last-page gets calculated

This commit is contained in:
Sofia Papacharalampous 2024-05-29 14:52:32 +03:00
parent 72cebd0c9d
commit 68b5bc7dd6
2 changed files with 6 additions and 10 deletions

View File

@ -37,7 +37,7 @@
<div class="text-muted d-flex justify-content-center mt-5" *ngIf="listingItems && listingItems.length > 0 && listingItems.length < pageSize">
{{'GENERAL.ACTIONS.NO-MORE-AVAILABLE' | translate}}
</div>
<div *ngIf="listingItems && listingItems.length > 0 && listingItems.length >= currentPage*pageSize && !foundLastPage" class="d-flex justify-content-center">
<div *ngIf="listingItems && listingItems.length > 0 && this.lookup.page.offset < currentPage*pageSize" class="d-flex justify-content-center">
<button type="button" class="btn-load-more" (click)="loadMore()">{{'GENERAL.ACTIONS.LOAD-MORE' | translate}}</button>
</div>
</div>

View File

@ -38,7 +38,6 @@ export class RecentEditedActivityComponent extends BaseComponent implements OnIn
currentPage: number = 0;
pageSize: number = 5;
listingItems: RecentActivityItem[]= [];
foundLastPage: boolean = false; // in case the total-items-count is equal to this.pageSize*this.currentPage
@Input() type: string;
@Input() includeDescriptions: boolean = false;
@ -171,27 +170,25 @@ export class RecentEditedActivityComponent extends BaseComponent implements OnIn
]
};
const initItems = this.currentPage == 0;
this.loadMore({ size: initItems ? this.pageSize : this.pageSize*this.currentPage, offset: 0 }, initItems);
this.loadMore({ size: this.currentPage == 0 ? this.pageSize : this.pageSize*this.currentPage, offset: 0 });
}
loadMore(page?: Lookup.Paging, updatePage: boolean = true) {
loadMore(page?: Lookup.Paging) {
if (!page) page = { size: this.pageSize, offset: this.pageSize*this.currentPage };
this.lookup.page = page;
this.loadItems(PaginationAction.LoadMore, updatePage);
this.loadItems(PaginationAction.LoadMore);
}
loadLess() {
this.loadItems(PaginationAction.LoadLess);
}
private loadItems(action: PaginationAction, updatePage: boolean = true){
private loadItems(action: PaginationAction){
if (action == PaginationAction.LoadLess) {
let latestBatchCount = this.listingItems.length%this.pageSize == 0 ? this.pageSize : this.listingItems.length%this.pageSize;
this.listingItems = this.listingItems.slice(0, this.listingItems.length-latestBatchCount);
this._setPage(this.currentPage-1);
this.foundLastPage = false;
return;
}
@ -221,7 +218,7 @@ export class RecentEditedActivityComponent extends BaseComponent implements OnIn
}
})
if (updatePage && response.length > 0 && this.listingItems.length >= this.currentPage*this.pageSize) this._setPage(this.currentPage+1);
if (this.lookup.page.offset != 0 && response.length > 0 && this.listingItems.length >= this.currentPage*this.pageSize) this._setPage(this.currentPage+1);
else this._resetPagination();
});
}
@ -229,7 +226,6 @@ export class RecentEditedActivityComponent extends BaseComponent implements OnIn
private _resetPagination(): void {
if (this.listingItems.length == 0) this.currentPage = 0;
else this.currentPage = Math.ceil(this.listingItems.length/this.pageSize);
this.foundLastPage = true;
this.updateUrl();
}