src/app/pipes/payments-filter.pipe.ts
name | paymentsFilter |
searchAmount |
searchAmount(value: Payment, target: string)
|
Defined in src/app/pipes/payments-filter.pipe.ts:75
|
Returns :
boolean
|
searchDate |
searchDate(date: string, target: string)
|
Defined in src/app/pipes/payments-filter.pipe.ts:71
|
Returns :
boolean
|
searchMemo |
searchMemo(value: Payment, target: string)
|
Defined in src/app/pipes/payments-filter.pipe.ts:61
|
Returns :
boolean
|
searchName |
searchName(value: Payment, target: string)
|
Defined in src/app/pipes/payments-filter.pipe.ts:36
|
Returns :
boolean
|
searchPayment |
searchPayment(value: Payment, target: string)
|
Defined in src/app/pipes/payments-filter.pipe.ts:18
|
Returns :
boolean
|
searchStatus |
searchStatus(value: Payment, target: string)
|
Defined in src/app/pipes/payments-filter.pipe.ts:51
|
Returns :
boolean
|
transform |
transform(input: Payment[], targetRaw: string)
|
Defined in src/app/pipes/payments-filter.pipe.ts:10
|
Returns :
[]
|
import { DatePipe } from '@angular/common';
import { Pipe, PipeTransform } from '@angular/core';
import { LOCALE } from '../app.constants';
import { Payment } from '../models';
@Pipe({
name: 'paymentsFilter',
})
export class PaymentsFilterPipe implements PipeTransform {
transform(input: Payment[], targetRaw: string): Payment[] {
if (input === null || input === undefined || targetRaw === null || targetRaw === undefined) {
return input;
}
const target = targetRaw.toLowerCase();
return input.filter((value) => this.searchPayment(value, target));
}
searchPayment(value: Payment, target: string) {
const datePipe = new DatePipe(LOCALE);
const dateStr = value.paymentDateFormatted;
const shortDate = dateStr ? datePipe.transform(new Date(dateStr), 'shortDate') : null;
const mediumDate = dateStr ? datePipe.transform(new Date(dateStr), 'mediumDate').toLowerCase() : null;
const longDate = dateStr ? datePipe.transform(new Date(dateStr), 'longDate').toLowerCase() : null;
return (
this.searchName(value, target) ||
this.searchStatus(value, target) ||
this.searchMemo(value, target) ||
this.searchDate(shortDate, target) ||
this.searchDate(mediumDate, target) ||
this.searchDate(longDate, target) ||
this.searchAmount(value, target)
);
}
searchName(value: Payment, target: string): boolean {
return (
(value !== null &&
value !== undefined &&
value.payToName !== null &&
value.payToName !== undefined &&
value.payToName.toLowerCase().indexOf(target) > -1) ||
(value !== null &&
value !== undefined &&
value.displayName !== null &&
value.displayName !== undefined &&
value.displayName.toLowerCase().indexOf(target) > -1)
);
}
searchStatus(value: Payment, target: string): boolean {
return (
value !== null &&
value !== undefined &&
value.status !== null &&
value.status !== undefined &&
value.status.toLowerCase().indexOf(target) > -1
);
}
searchMemo(value: Payment, target: string): boolean {
return (
value !== null &&
value !== undefined &&
value.memo !== null &&
value.memo !== undefined &&
value.memo.toLowerCase().indexOf(target) > -1
);
}
searchDate(date: string, target: string): boolean {
return date != null && date !== undefined && date.indexOf(target) > -1;
}
searchAmount(value: Payment, target: string): boolean {
return (
value !== null &&
value !== undefined &&
value.amountFormatted !== null &&
value.amountFormatted !== undefined &&
value.amountFormatted.indexOf(target) > -1
);
}
}