semi working live search
[u/erikhf/frm.git] / src / components / search / SearchService.ts
1 import {provide, Injectable} from 'angular2/angular2';
2 import {Http} from 'angular2/http';
3 import * as Rx from '@reactivex/rxjs/dist/cjs/Rx';
4
5 @Injectable()
6 export class SearchService {
7 /*
8     data: Rx.Observable<any[]>;
9
10     constructor(http: Http){
11         this.data = http.get('testData.json')
12             .map(res => res.json())
13             .map(res => res.items);
14     }
15 */
16
17     constructor(public http: Http){
18
19     }
20     search(query: string): Rx.Observable<any[]>{
21         return this.http.get('testData.json')
22             .map(res=>res.json())
23             .map(res => res.organisationUnits)
24             .filter(function(name:string){
25                 return name.toLowerCase().indexOf(query.toLowerCase());
26             });
27
28             //.map(res => res.json())
29             //.map(res => res.organizationUnits);
30     //.filter(function(name){
31     //        return name.indexOf(query);
32     //    })
33     }
34 }
35
36 export var SEARCH_PROVIDERS: Array<any> = [
37     provide(SearchService, {useClass: SearchService})
38 ];