blob: 40d42585a05862b29645b1460c650ab18e8893c0 [file] [log] [blame]
/**
******************************************************************************
* Copyright © 2017-2018 PTA GmbH.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
*
* http://www.eclipse.org/legal/epl-v10.html
*
******************************************************************************
*/
import { Pipe, PipeTransform } from '@angular/core';
import { ListItem } from './multiselect.model';
@Pipe({
name: 'listFilter',
pure: false
})
export class ListFilterPipe implements PipeTransform {
transform(items: ListItem[], filter: ListItem): ListItem[] {
if (!items || !filter) {
return items;
}
// filter items array, items which match and return true will be kept, false will be filtered out
return items.filter((item: ListItem) => this.applyFilter(item, filter));
}
/**
* Perform the filtering.
*
* @param {Book} book The book to compare to the filter.
* @param {Book} filter The filter to apply.
* @return {boolean} True if book satisfies filters, false if not.
*/
applyFilter(item: ListItem, filter: ListItem): boolean {
return !(filter.itemName && item.itemName && item.itemName.toLowerCase().indexOf(filter.itemName.toLowerCase()) === -1);
}
}