-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregionsPage.ts
79 lines (66 loc) · 2.59 KB
/
regionsPage.ts
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import {Page, NavController, NavParams, Searchbar} from 'ionic-framework/ionic';
import {IProvider} from "../../models/models";
import {ProviderService} from "../../providers/leagues/leagues";
import {Logger} from "../../providers/logger/logger";
import {Observable, Subscription, BehaviorSubject} from 'rxjs/Rx';
import {Router, RouteParams, RouterLink, Location, ROUTER_DIRECTIVES, ROUTER_PROVIDERS} from 'angular2/router';
@Page({
templateUrl: 'build/pages/regionsPage/regionsPage.html',
directives: [ROUTER_DIRECTIVES],
providers:[ProviderService]
})
export class RegionsPage {
public allItems : IProvider[];
public items : IProvider[];
private searchTerm: string;
private searchSubject : BehaviorSubject<string>;
private searchActioner: Subscription<string>;
constructor(
private logger : Logger,
private providerService : ProviderService)
{
this.searchTerm = "";
this.searchSubject = new BehaviorSubject<string>("");
//this.searchItems = "";
//throttle the input to avoid
this.searchActioner = this.searchSubject
//.throttleTime(700)
.filter((x) => {
this.logger.notify("all items");
var t = typeof(this.allItems);
return t !== "undefined";
})
.subscribe((x) => {
this.logger.notify("search by: " + x);
this.items = this.allItems.filter(e=>
e.Name.toLowerCase().indexOf(x) >= 0)
});
}
public onPageWillEnter() {
this.providerService.List()
.map(response => response.json())
.subscribe((items : IProvider[]) => {
this.logger.notify("items loaded");
this.logger.notify(items);
this.allItems = items;
if(this.searchTerm.length > 0)
{
this.items = this.allItems.filter(e=>
e.Name.toLowerCase().indexOf(this.searchTerm) >= 0);
}else
{
this.items = this.allItems;
}
});
}
public update(searchBar: Searchbar){
this.searchTerm = searchBar.value ? searchBar.value : "";;
this.logger.notify("search update: " + this.searchTerm);
this.searchSubject.next(this.searchTerm);
}
ngOnDestroy() {
//clear subscribers etc
this.logger.notify("Kill ProvidersListPage");
this.searchActioner.unsubscribe();
}
}