File

src/app/pipes/templates-filter.pipe.ts

Description

Search the given account array for templates that match the given string.

Metadata

Methods

searchAccount
searchAccount(value: Template, target: string)
Parameters :
Name Type Optional
value Template No
target string No
Returns : any
searchDisplayName
searchDisplayName(value: Template, target: string)
Parameters :
Name Type Optional
value Template No
target string No
Returns : any
searchName
searchName(value: Template, target: string)
Parameters :
Name Type Optional
value Template No
target string No
Returns : any
searchTemplate
searchTemplate(value: Template, target: string)
Parameters :
Name Type Optional
value Template No
target string No
Returns : any
transform
transform(input: Template[], targetRaw: string)
Parameters :
Name Type Optional
input Template[] No
targetRaw string No
Returns : Template[]
import { Pipe, PipeTransform } from '@angular/core';
import { Template } from '../models';
import { LOCALE } from '../app.constants';

/**
 * Search the given account array for templates that match the given string.
 *
 * @export
 * @class TemplatesFilterPipe
 */
@Pipe({
  name: 'templatesFilter'
})
export class TemplatesFilterPipe implements PipeTransform {
  transform(input: Template[], targetRaw: string): Template[] {
    if (
      input === null ||
      input === undefined ||
      targetRaw === null ||
      targetRaw === undefined
    ) {
      return input;
    }
    const target = targetRaw.toLowerCase();
    return input.filter(value => this.searchTemplate(value, target));
  }

  searchTemplate(value: Template, target: string) {
    return (
      this.searchName(value, target) ||
      this.searchAccount(value, target) ||
      this.searchDisplayName(value, target)
    );
  }

  searchName(value: Template, target: string) {
    return (
      value !== null &&
      value !== undefined &&
      value.name !== null &&
      value.name !== undefined &&
      value.name.toLowerCase().includes(target)
    );
  }

  searchAccount(value: Template, target: string) {
    return (
      value !== null &&
      value !== undefined &&
      value.accountNumber !== null &&
      value.accountNumber !== undefined &&
      value.accountNumber.length > 0 &&
      value.accountNumber.toLowerCase().includes(target)
    );
  }

  searchDisplayName(value: Template, target: string) {
    return (
      value !== null &&
      value !== undefined &&
      value.displayName !== null &&
      value.displayName !== undefined &&
      value.displayName.length > 0 &&
      value.displayName.toLowerCase().includes(target)
    );
  }
}

results matching ""

    No results matching ""