From fdf87c8728b0147bd5b413c03744c60191244f0a Mon Sep 17 00:00:00 2001 From: Patrick Sun Date: Mon, 17 May 2021 23:24:51 +1000 Subject: [PATCH] bug fix number range filter string to number --- .../number-range-filter.component.ts | 6 +- .../list-all-loans.component.html | 93 +++++++++---------- .../list-all-rewards.component.ts | 1 + src/app/pay-in/pay-in.component.html | 10 +- src/app/pay-in/pay-in.component.ts | 82 +++++++++++----- 5 files changed, 110 insertions(+), 82 deletions(-) diff --git a/src/app/grid-filter/number-range-filter/number-range-filter.component.ts b/src/app/grid-filter/number-range-filter/number-range-filter.component.ts index 0049abe..93a1a04 100644 --- a/src/app/grid-filter/number-range-filter/number-range-filter.component.ts +++ b/src/app/grid-filter/number-range-filter/number-range-filter.component.ts @@ -246,7 +246,7 @@ export class NumberRangeFilterComponent extends BaseFilterCellComponent implemen const filter: FilterDescriptor = { field: this.fieldName, operator: this.operator.value, - value: this.valueFrom, + value: Number(this.valueFrom), }; this.applyFilter(this.updateFilter(filter)); } @@ -259,7 +259,7 @@ export class NumberRangeFilterComponent extends BaseFilterCellComponent implemen fs.push({ field: this.fieldName, operator: 'gte', - value: this.valueFrom + value: Number(this.valueFrom) }); } @@ -267,7 +267,7 @@ export class NumberRangeFilterComponent extends BaseFilterCellComponent implemen fs.push({ field: this.fieldName, operator: 'lte', - value: this.valueTo + value: Number(this.valueTo) }); } this.removeFilter(this.fieldName); diff --git a/src/app/list-all-loans/list-all-loans.component.html b/src/app/list-all-loans/list-all-loans.component.html index 85263cd..dbdebcd 100644 --- a/src/app/list-all-loans/list-all-loans.component.html +++ b/src/app/list-all-loans/list-all-loans.component.html @@ -4,6 +4,7 @@ [pageSize]="pageSize" [skip]="skip" [sortable]="true" + [resizable]="true" [sort]="sort" [filter]="filter" [pageable]="true" @@ -57,11 +58,8 @@ - - + + @@ -73,11 +71,8 @@ - - + + @@ -89,11 +84,8 @@ - - + + @@ -112,24 +104,18 @@ - - + + - + {{dataItem.Status}} - - + + @@ -140,26 +126,34 @@ - - + + + + + + + + + + + + + + {{ dataItem.Amount | currency }} - - + + @@ -168,11 +162,10 @@ {{ dataItem.Balance | currency }} - - + + @@ -182,11 +175,10 @@ - - + + @@ -194,11 +186,10 @@ {{ dataItem.IncomeTotal | currency }} - - + + diff --git a/src/app/list-all-rewards/list-all-rewards.component.ts b/src/app/list-all-rewards/list-all-rewards.component.ts index 0963cf6..e0c73ba 100644 --- a/src/app/list-all-rewards/list-all-rewards.component.ts +++ b/src/app/list-all-rewards/list-all-rewards.component.ts @@ -64,6 +64,7 @@ export class ListAllRewardsComponent implements OnInit { public dataStateChange(state: DataStateChangeEvent): void { this.state = state; + console.log(state); this.loadRewards(); } diff --git a/src/app/pay-in/pay-in.component.html b/src/app/pay-in/pay-in.component.html index 80e529b..cd66111 100644 --- a/src/app/pay-in/pay-in.component.html +++ b/src/app/pay-in/pay-in.component.html @@ -2,14 +2,14 @@ [pageable]="pageable" [navigable]="true" [resizable]="true" - [pageSize]="filter.Take" - [skip]="filter.Skip" + [pageSize]="state.Take" + [skip]="state.Skip" [sortable]="sortable" [filterable]="filterable" [loading]="loading" - [sort]="filter.Sort" - [filter]="filter.Filter" + [sort]="state.Sort" + [filter]="state.Filter" [selectable]="selectable" kendoGridSelectBy @@ -38,7 +38,7 @@
{{uploadMeta.Id}} {{uploadMeta.FileName}} - +
diff --git a/src/app/pay-in/pay-in.component.ts b/src/app/pay-in/pay-in.component.ts index e71e3fc..94c0c45 100644 --- a/src/app/pay-in/pay-in.component.ts +++ b/src/app/pay-in/pay-in.component.ts @@ -41,7 +41,7 @@ export class PayInComponent implements OnInit { @Input() selectable: SelectableSettings | boolean; private filterUploadMeta: UploadMetaModel = new UploadMetaModel({}); public filterLoan = new LoanModel({}); - @Input() filter: PayInListFilterModel = new PayInListFilterModel({}); + @Input() state: PayInListFilterModel = new PayInListFilterModel({}); // public state = new GridStateModel(); @Output() errorOccurred = new EventEmitter(); @Output() Updated = new EventEmitter(); @@ -85,13 +85,14 @@ export class PayInComponent implements OnInit { this.lenderListView = this.lenderNameService; this.lenderNameService.query(); if ( this.pageable ) { - this.filter.Take = this.pageSize; + this.state.Take = this.pageSize; } this.rowClassCallbackBind = this.rowClassCallback.bind(this); + this.debouncedLoadFilteredData = debounce(this.loadFilteredPayInList, 500); } ngOnInit(): void { - this.debouncedLoadFilteredData = debounce(this.loadFilteredPayInList, 500); + if (this.privateLoadDataNow) { // not in delayed loading mode this.debouncedLoadFilteredData(); } @@ -117,11 +118,13 @@ export class PayInComponent implements OnInit { public loadFilteredPayInList(): void { this.loading = true; + this.refreshFilterByUpload(); + this.refreshFilterByLoanId(); const state = new GridStateModel(); - state.filter = this.filter.Filter; - state.sort = this.filter.Sort; - state.take = this.filter.Take; - state.group = this.filter.Group; + state.filter = this.state.Filter; + state.sort = this.state.Sort; + state.take = this.state.Take; + state.group = this.state.Group; this.pis.getFilteredPayInList(state).subscribe( ( resp: PayInListResult) => { this.gridData.total = resp.total; @@ -142,9 +145,9 @@ export class PayInComponent implements OnInit { @Input() set uploadMeta(value: UploadMetaModel) { this.filterUploadMeta = value; if ( value.Id <= 0 ) { - this.filter.UploadIds = []; + this.state.UploadIds = []; } else{ - this.filter.UploadIds = [ value.Id.toString() ]; + this.state.UploadIds = [ value.Id.toString() ]; } this.debouncedLoadFilteredData(); // console.log('upload filter changed', value, this.filter); @@ -158,9 +161,9 @@ export class PayInComponent implements OnInit { @Input() set Loan(value: LoanModel){ this.filterLoan = value; if ( value.Id === '' ) { - this.filter.LoanIds = []; + this.state.LoanIds = []; }else{ - this.filter.LoanIds = [ value.Id ]; + this.state.LoanIds = [ value.Id ]; } this.debouncedLoadFilteredData(); // console.log('filter loanId changed', value, this.filter); @@ -314,7 +317,7 @@ export class PayInComponent implements OnInit { } public showUpload(id: number): void { - this.router.navigate(['/upload-details', id]); + this.router.navigate(['/upload-details', id]).then(); } @@ -355,26 +358,26 @@ export class PayInComponent implements OnInit { // } public pageChange(event: PageChangeEvent): void { - this.filter.Skip = event.skip; - this.filter.Take = event.take; + this.state.Skip = event.skip; + this.state.Take = event.take; // this.loadFilteredData(); } public sortChange(sort: SortDescriptor[]): void { - this.filter.Sort = sort; + this.state.Sort = sort; // this.loadFilteredData(); } public filterChange( filter: CompositeFilterDescriptor): void { // console.log (filter, this.state.filter); - this.filter.Skip = 0; + this.state.Skip = 0; } public dataStateChange(state: DataStateChangeEvent): void { - this.filter.Filter = state.filter; - this.filter.Group = state.group; - this.filter.Sort = state.sort; - this.filter.Skip = state.skip; - this.filter.Take = state.take; + this.state.Filter = state.filter; + this.state.Group = state.group; + this.state.Sort = state.sort; + this.state.Skip = state.skip; + this.state.Take = state.take; // console.log(state); this.loadFilteredPayInList(); } @@ -442,9 +445,42 @@ export class PayInComponent implements OnInit { public onFilterEnable(filtering: boolean): void { if ( ! filtering ) { - this.filter.Filter = { logic: 'and', filters: [] }; - this.filter.Skip = 0; + this.state.Filter = { logic: 'and', filters: [] }; + this.state.Skip = 0; this.loadFilteredPayInList(); } } + + private refreshFilterByUpload(): void{ + // make a copy of existing filters + const newFilter = { logic: 'and', filters: [], ...this.state.Filter.filters}; + + // remove any existing filters about UploadsId + newFilter.filters = newFilter.filters.filter(v => { + if (!( 'field' in v) && v.operator === 'or') { // could be LoanId or UploadsIds + const subFilters = v.filters; + return ! subFilters.every( subf => subf.field === 'UploadIds' ); // if sub-filters are all about UploadsIds, we remove it + } + return true; + }); + + // build new filters + const uploadsFilter = { logic: 'or', filters: []}; + this.state.UploadIds.forEach(v => { + uploadsFilter.filters.push( { + field: 'UploadId', + operator: 'eq', + value: v + }); + }); + + // add new filter + newFilter.filters.push( uploadsFilter as CompositeFilterDescriptor ); + this.state.Filter = newFilter as CompositeFilterDescriptor; + + } + + private refreshFilterByLoanId(): void{ + + } }