1 import {Component,EventEmitter, View, CORE_DIRECTIVES} from 'angular2/angular2';
2 import {Http} from 'angular2/http';
3 import {LiveSearch} from "./livesearch";
4 import {Sidebar} from "../sidebar/sidebar";
5 import * as Rx from '@reactivex/rxjs/dist/cjs/Rx';
7 declare var zone: Zone;
10 selector: 'mou-search',
11 directives: [CORE_DIRECTIVES, LiveSearch],
12 events: ['newsearch'],
13 templateUrl: './components/search/search.html',
14 styleUrls: ['./components/search/search.css']
17 orgunits: Array<any> = [];
18 filteredOrgunits: Array<any> = [];
19 loading: boolean = false;
20 groups: Array<any> = [];
21 groupSet: Array<any> = [];
22 ownershipSelector: any;
24 locationSelector: any;
27 filterset: boolean = false;
32 constructor(public http:Http) {
33 this.newsearch = new EventEmitter();
35 this.emptySearch = document.getElementById("divresult");
36 this.getUnitGroupSets();
37 this.ownershipSelector = document.getElementById("ownershipSelector");
38 this.typeSelector = document.getElementById("typeSelector");
39 this.locationSelector = document.getElementById("locationSelector");
40 this.searchBar = document.getElementById("livesearch");
41 this.orglist = document.getElementById("orglist");
42 this.a = document.getElementById("testunit");
45 getMoreInfo(orgunit) {
47 this.newsearch.next(orgunit.id);
53 this.visible = !this.visible;
54 //this.getUnitGroupSets();
58 if(livesearch.value == "")
65 return this.emptySearch = document.getElementById("divresult").style.visibility = "hidden";
70 this.http.get(dhisAPI + "/api/organisationUnitGroupSets")
71 .map(res => res.json())
72 .map(res => res.organisationUnitGroupSets)
75 this.setOptionHeader(this.ownershipSelector, res[0].name);
76 this.setOptionHeader(this.typeSelector, res[1].name);
77 this.setOptionHeader(this.locationSelector, res[2].name);
79 for(var i = 0; i < res.length; i++) {
80 this.http.get(res[i].href)
81 .map(result => result.json())
84 if(result.displayName == "Facility Ownership"){
85 for(var j = 0; j < result.organisationUnitGroups.length; j++) {
86 this.setOption(this.ownershipSelector, result.organisationUnitGroups[j].name);
89 else if(result.displayName == "Facility Type"){
90 for(var j = 0; j < result.organisationUnitGroups.length; j++) {
91 this.setOption(this.typeSelector, result.organisationUnitGroups[j].name);
94 else if(result.displayName == "Location Rural/Urban"){
95 for(var j = 0; j < result.organisationUnitGroups.length; j++) {
96 this.setOption(this.locationSelector, result.organisationUnitGroups[j].name);
105 setOptionHeader(selector, value){
106 this.option = document.createElement("option");
107 this.option.text = "-- " + value + " --";
108 this.option.value = "";
109 selector.appendChild(this.option);
112 setOption(selector, value){
113 this.option = document.createElement("option");
114 this.option.text = value;
115 this.option.value = value;
116 selector.appendChild(this.option);
120 if(!this.orgunits.length == false && !this.filterset){
122 this.filterset = true;
124 else if(!this.orgunits.length){
125 this.filteredOrgunits = [];
127 this.filterset = false;
131 return !this.orgunits.length;
136 this.filteredOrgunits = [];
138 for (var i = 0; i < this.orgunits.length; i++) {
139 this.http.get(this.orgunits[i].href)
140 .map(res => res.json())
142 zone.bind(orgunits => {
143 if (this.ownershipSelector.value == "" && this.typeSelector.value == "" && this.locationSelector.value == "") {
144 this.filteredOrgunits.push(orgunits);
147 var os = false; var ls = false;var ts = false;
148 for (var group in orgunits.organisationUnitGroups) {
149 if (this.ownershipSelector.value != "") {
150 if (orgunits.organisationUnitGroups[group].name == this.ownershipSelector.value) {
154 if (this.ownershipSelector.value == "") {
157 if (this.typeSelector.value != "") {
158 if (orgunits.organisationUnitGroups[group].name == this.typeSelector.value) {
162 if (this.typeSelector.value == "") {
165 if (this.locationSelector.value != "") {
166 if (orgunits.organisationUnitGroups[group].name == this.locationSelector.value) {
170 if (this.locationSelector.value == "") {
173 if (os == true && ts == true && ls == true) {
174 this.filteredOrgunits.push(orgunits);