1 import {Component,EventEmitter, View, CORE_DIRECTIVES} from 'angular2/angular2';
2 import {Http} from 'angular2/http';
3 import {LiveSearch} from "./livesearch";
4 import * as Rx from '@reactivex/rxjs/dist/cjs/Rx';
6 declare var zone: Zone;
9 selector: 'mou-search',
10 directives: [CORE_DIRECTIVES, LiveSearch],
11 events: ['newsearch'],
12 templateUrl: './components/search/search.html',
13 styleUrls: ['./components/search/search.css']
16 orgunits: Array<any> = [];
17 loading: boolean = false;
18 groups: Array<any> = [];
19 groupSet: Array<any> = [];
21 ownershipSelector: any;
23 locationSelector: any;
27 constructor(public http:Http) {
28 this.newsearch = new EventEmitter();
30 this.getUnitGroupSets();
31 this.ownershipSelector = document.getElementById("ownershipSelector");
32 this.typeSelector = document.getElementById("typeSelector");
33 this.locationSelector = document.getElementById("locationSelector");
34 this.searchBar = document.getElementById("livesearch");
37 getMoreInfo(orgunit) {
39 this.newsearch.next(orgunit.id);
45 this.visible = !this.visible;
46 //this.getUnitGroupSets();
51 this.http.get(dhisAPI + "/api/organisationUnitGroupSets")
52 .map(res => res.json())
53 .map(res => res.organisationUnitGroupSets)
56 this.setOptionHeader(this.ownershipSelector, res[0].name);
57 this.setOptionHeader(this.typeSelector, res[1].name);
58 this.setOptionHeader(this.locationSelector, res[2].name);
60 for(var i = 0; i < res.length; i++) {
61 this.http.get(res[i].href)
62 .map(result => result.json())
65 if(result.displayName == "Facility Ownership"){
66 for(var j = 0; j < result.organisationUnitGroups.length; j++) {
67 this.setOption(this.ownershipSelector, result.organisationUnitGroups[j].name);
70 else if(result.displayName == "Facility Type"){
71 for(var j = 0; j < result.organisationUnitGroups.length; j++) {
72 this.setOption(this.typeSelector, result.organisationUnitGroups[j].name);
75 else if(result.displayName == "Location Rural/Urban"){
76 for(var j = 0; j < result.organisationUnitGroups.length; j++) {
77 this.setOption(this.locationSelector, result.organisationUnitGroups[j].name);
86 setOptionHeader(selector, value){
87 this.option = document.createElement("option");
88 this.option.text = "-- " + value + " --";
89 this.option.value = "";
90 selector.appendChild(this.option);
93 setOption(selector, value){
94 this.option = document.createElement("option");
95 this.option.text = value;
96 this.option.value = value;
97 selector.appendChild(this.option);
101 console.log("Dette er setFilter");
102 console.log(this.ownershipSelector.value);
103 var text = livesearch.value;
105 //livesearch.value = "";
106 //console.log(this.searchBar.key);
108 /*for(var i = 0; i < text.length; i++){
109 livesearch.value += text.charAt(i);
111 //this.searchBar.createEvent('keyup');
113 this.searchBar.focus(true);