Fix Loan lock COB pagination (#1753)

Co-authored-by: Jose Alberto Hernandez <alberto@blue-daemon.local>
This commit is contained in:
José Alberto Hernández
2023-05-22 17:32:22 -06:00
committed by GitHub
co-authored by Jose Alberto Hernandez
parent 02ed7362d3
commit 517584280f
3 changed files with 23 additions and 15 deletions
@@ -23,7 +23,7 @@ import * as _ from 'lodash';
}) })
export class DatatableMultiRowComponent implements OnInit, OnDestroy, OnChanges { export class DatatableMultiRowComponent implements OnInit, OnDestroy, OnChanges {
SELECT_NAME_FIELD:string = 'select'; SELECT_NAME_FIELD = 'select';
/** Data Object */ /** Data Object */
@Input() dataObject: any; @Input() dataObject: any;
@Input() entityId: string; @Input() entityId: string;
@@ -163,7 +163,9 @@ export class DatatableMultiRowComponent implements OnInit, OnDestroy, OnChanges
this.selection.selected.forEach((data) => { this.selection.selected.forEach((data) => {
this.systemService.deleteDatatableEntry(this.entityId, data.row[1], this.datatableName).subscribe(() => { this.systemService.deleteDatatableEntry(this.entityId, data.row[1], this.datatableName).subscribe(() => {
this.datatableData.forEach((item: any, index: any) => { this.datatableData.forEach((item: any, index: any) => {
if (item.row[1] === data.row[1]) delete this.datatableData[index] if (item.row[1] === data.row[1]) {
delete this.datatableData[index];
}
}); });
}); });
}); });
@@ -192,7 +194,7 @@ export class DatatableMultiRowComponent implements OnInit, OnDestroy, OnChanges
/** Whether the number of selected elements matches the total number of rows. */ /** Whether the number of selected elements matches the total number of rows. */
isAllSelected() { isAllSelected() {
const numSelected = this.selection.selected; const numSelected = this.selection.selected;
return (this.datatableData.length == numSelected); return (this.datatableData.length === numSelected);
} }
isAnySelected() { isAnySelected() {
@@ -65,8 +65,8 @@
</tr> </tr>
</table> </table>
<mat-paginator [pageSizeOptions]="[10, 25, 50, 100]" showFirstLastButtons [pageSize]="pageSize" <mat-paginator [hidden]="!showPaginator" [pageSizeOptions]="[100, 500, 1000, 5000]" [pageSize]="pageSize"
[pageIndex]="currentPage" (page)="pageEvent = handlePage($event)"> [pageIndex]="currentPage" showFirstLastButtons (page)="changePaging($event)">
</mat-paginator> </mat-paginator>
</div> </div>
@@ -26,15 +26,23 @@ export class LoanLockedComponent implements OnInit {
selection: SelectionModel<any>; selection: SelectionModel<any>;
/** Displayed Columns for loan disbursal data */ /** Displayed Columns for loan disbursal data */
displayedColumns: string[] = ['select', 'loanId', 'lockPlacedOn', 'lockOwner', 'error', 'details']; displayedColumns: string[] = ['select', 'loanId', 'lockPlacedOn', 'lockOwner', 'error', 'details'];
/** Paginator for the table */ /** Paginator for the table */
@ViewChild(MatPaginator, { static: true }) paginator: MatPaginator; @ViewChild(MatPaginator, {static: false})
set paginator(value: MatPaginator) {
this.dataSource.paginator = value;
}
currentPage = 0; currentPage = 0;
pageSize = 10; itemsToRead = 5000;
pageSize = 100;
/** Control for enable/disable button */ /** Control for enable/disable button */
allowRunInlineJob = false; allowRunInlineJob = false;
/** Const for the jobName */ /** Const for the jobName */
jobName: String = 'LOAN_COB'; jobName: String = 'LOAN_COB';
showPaginator = false;
/** /**
* @param {LoansService} loansService Loans Service * @param {LoansService} loansService Loans Service
* @param {Router} router Router for navigation. * @param {Router} router Router for navigation.
@@ -49,29 +57,27 @@ export class LoanLockedComponent implements OnInit {
} }
ngOnInit(): void { ngOnInit(): void {
this.dataSource = new MatTableDataSource(this.loans);
this.dataSource.paginator = this.paginator;
this.selection = new SelectionModel(true, []);
this.allowRunInlineJob = false; this.allowRunInlineJob = false;
this.getLoansLocked(this.currentPage); this.getLoansLocked(0);
} }
applyFilter(filterValue: string = '') { applyFilter(filterValue: string = '') {
this.dataSource.filter = filterValue.trim().toLowerCase(); this.dataSource.filter = filterValue.trim().toLowerCase();
} }
handlePage(e: any) { changePaging(e: any) {
this.pageSize = e.pageSize;
if (this.currentPage !== e.pageIndex) { if (this.currentPage !== e.pageIndex) {
this.currentPage = e.pageIndex; this.currentPage = e.pageIndex;
this.pageSize = e.pageSize;
this.getLoansLocked(this.currentPage);
} }
} }
getLoansLocked(page: number) { getLoansLocked(page: number) {
this.tasksService.getAllLoansLocked(page, this.pageSize).subscribe((data: any) => { this.tasksService.getAllLoansLocked(page, this.itemsToRead).subscribe((data: any) => {
this.loans = data.content; this.loans = data.content;
this.dataSource = new MatTableDataSource(this.loans); this.dataSource = new MatTableDataSource(this.loans);
this.dataSource.paginator = this.paginator;
this.showPaginator = (this.loans.length > this.pageSize);
this.allowRunInlineJob = false; this.allowRunInlineJob = false;
this.selection = new SelectionModel(true, []); this.selection = new SelectionModel(true, []);
}); });