File

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

Description

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

Example

Metadata

name templatesFilter

Methods

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

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

  searchTemplate(value: Template, target) {
    return (
      this.searchName(value, target) ||
      this.searchEmail(value, target) ||
      this.searchPhone(value, target)
    );
  }

  searchName(value, target) {
    return (
      value !== null &&
      value !== undefined &&
      value.name !== null &&
      value.name !== undefined &&
      value.name.toLowerCase().indexOf(target) > -1
    );
  }

  searchEmail(value, target) {
    return (
      value !== null &&
      value !== undefined &&
      value.p2PPayToEmailAddress !== null &&
      value.p2PPayToEmailAddress !== undefined &&
      value.p2PPayToEmailAddress.length > 0 &&
      value.p2PPayToEmailAddress.toLowerCase().indexOf(target) > -1
    );
  }

  searchPhone(value, target) {
    return (
      value !== null &&
      value !== undefined &&
      value.p2PPayToPhoneNumber !== null &&
      value.p2PPayToPhoneNumber !== undefined &&
      value.p2PPayToPhoneNumber.length > 0 &&
      value.p2PPayToPhoneNumber.toLowerCase().indexOf(target) > -1
    );
  }
}

results matching ""

    No results matching ""