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;
55 this.ownershipSelector.selectedIndex = 0;
56 this.typeSelector.selectedIndex = 0;
57 this.locationSelector.selectedIndex = 0;
63 if(livesearch.value == "")
70 return this.emptySearch = document.getElementById("divresult").style.visibility = "hidden";
75 this.http.get(dhisAPI + "/api/organisationUnitGroupSets")
76 .map(res => res.json())
77 .map(res => res.organisationUnitGroupSets)
80 this.setOptionHeader(this.ownershipSelector, res[0].name);
81 this.setOptionHeader(this.typeSelector, res[1].name);
82 this.setOptionHeader(this.locationSelector, res[2].name);
84 for(var i = 0; i < res.length; i++) {
85 this.http.get(res[i].href)
86 .map(result => result.json())
89 if(result.displayName == "Facility Ownership"){
90 for(var j = 0; j < result.organisationUnitGroups.length; j++) {
91 this.setOption(this.ownershipSelector, result.organisationUnitGroups[j].name);
94 else if(result.displayName == "Facility Type"){
95 for(var j = 0; j < result.organisationUnitGroups.length; j++) {
96 this.setOption(this.typeSelector, result.organisationUnitGroups[j].name);
99 else if(result.displayName == "Location Rural/Urban"){
100 for(var j = 0; j < result.organisationUnitGroups.length; j++) {
101 this.setOption(this.locationSelector, result.organisationUnitGroups[j].name);
110 setOptionHeader(selector, value){
111 this.option = document.createElement("option");
112 this.option.text = "-- " + value + " --";
113 this.option.value = "";
114 selector.appendChild(this.option);
117 setOption(selector, value){
118 this.option = document.createElement("option");
119 this.option.text = value;
120 this.option.value = value;
121 selector.appendChild(this.option);
125 if (this.ownershipSelector.value == "" && this.typeSelector.value == "" && this.locationSelector.value == "") {
126 this.filteredOrgunits = [];
127 for(var i = 0; i < this.orgunits.length; i++) {
128 this.filteredOrgunits.push(this.orgunits[i]);
131 else if(!this.orgunits.length == false && !this.filterset){
134 else if(!this.orgunits.length){
135 this.filteredOrgunits = [];
137 this.filterset = false;
141 return !this.orgunits.length;
146 this.filteredOrgunits = [];
147 this.filterset = true;
148 for (var i = 0; i < this.orgunits.length; i++) {
149 this.http.get(this.orgunits[i].href)
150 .map(res => res.json())
152 zone.bind(orgunits => {
153 if (this.ownershipSelector.value == "" && this.typeSelector.value == "" && this.locationSelector.value == "") {
154 this.filteredOrgunits.push(orgunits);
157 var os = false; var ls = false;var ts = false;
158 for (var j = 0; j < orgunits.organisationUnitGroups.length; j++) {
159 if (this.ownershipSelector.value != "") {
160 if (orgunits.organisationUnitGroups[j].name == this.ownershipSelector.value) {
164 if (this.ownershipSelector.value == "") {
167 if (this.typeSelector.value != "") {
168 if (orgunits.organisationUnitGroups[j].name == this.typeSelector.value) {
172 if (this.typeSelector.value == "") {
175 if (this.locationSelector.value != "") {
176 if (orgunits.organisationUnitGroups[j].name == this.locationSelector.value) {
180 if (this.locationSelector.value == "") {
183 if (os == true && ts == true && ls == true) {
184 this.filteredOrgunits.push(orgunits);