search.pipe.ts 674 Bytes
Newer Older
mdsecurity's avatar
mdsecurity committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { Pipe, PipeTransform } from '@angular/core';
import { Place } from './place';
@Pipe({
	name: 'search'
})
export class SearchPipe implements PipeTransform {

	transform(value: Place[], arg: string): any {
		let newOrder = [];
		for (let i = 0; i < value.length; i++) {
			if (value[i].isOpen()) {
				newOrder.unshift(value[i]);
			} else {
				newOrder.push(value[i]);
			}
		}
		if (arg !== "") {
			return value.filter((place) => {
				if (place.name.match(new RegExp(arg,'i')) !== null){
					return true;
				}
				if(place.location.match(new RegExp(arg,'i')) !== null){
					return true;
				}
				return false;
			});
		} else {
			return newOrder;
		}

	}

}