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';
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;
27 filterset:boolean = false;
30 constructor(public http:Http) {
31 this.newsearch = new EventEmitter();
33 this.emptySearch = document.getElementById("divresult");
34 this.getUnitGroupSets();
35 this.ownershipSelector = document.getElementById("ownershipSelector");
36 this.typeSelector = document.getElementById("typeSelector");
37 this.locationSelector = document.getElementById("locationSelector");
38 this.searchBar = document.getElementById("livesearch");
41 getMoreInfo(orgunit) {
43 this.newsearch.next(orgunit.id);
49 this.visible = !this.visible;
56 this.ownershipSelector.selectedIndex = 0;
57 this.typeSelector.selectedIndex = 0;
58 this.locationSelector.selectedIndex = 0;
63 if (this.searchBar.value == "")
68 return this.emptySearch = document.getElementById("divresult").style.visibility = "hidden";
72 this.http.get(dhisAPI + "/api/organisationUnitGroupSets")
73 .map(res => res.json())
74 .map(res => res.organisationUnitGroupSets)
77 this.setOptionHeader(this.ownershipSelector, res[0].name);
78 this.setOptionHeader(this.typeSelector, res[1].name);
79 this.setOptionHeader(this.locationSelector, res[2].name);
81 for (var i = 0; i < res.length; i++) {
82 this.http.get(res[i].href)
83 .map(result => result.json())
86 if (result.displayName == "Facility Ownership") {
87 for (var j = 0; j < result.organisationUnitGroups.length; j++) {
88 this.setOption(this.ownershipSelector, result.organisationUnitGroups[j].name);
91 else if (result.displayName == "Facility Type") {
92 for (var j = 0; j < result.organisationUnitGroups.length; j++) {
93 this.setOption(this.typeSelector, result.organisationUnitGroups[j].name);
96 else if (result.displayName == "Location Rural/Urban") {
97 for (var j = 0; j < result.organisationUnitGroups.length; j++) {
98 this.setOption(this.locationSelector, result.organisationUnitGroups[j].name);
107 setOptionHeader(selector, value) {
108 this.option = document.createElement("option");
109 this.option.text = "-- " + value + " --";
110 this.option.value = "";
111 selector.appendChild(this.option);
114 setOption(selector, value) {
115 this.option = document.createElement("option");
116 this.option.text = value;
117 this.option.value = value;
118 selector.appendChild(this.option);
122 if (this.ownershipSelector.value == "" && this.typeSelector.value == "" && this.locationSelector.value == "") {
123 this.filteredOrgunits = [];
124 for (var i = 0; i < this.orgunits.length; i++) {
125 this.filteredOrgunits.push(this.orgunits[i]);
128 else if (!this.orgunits.length == false && !this.filterset) {
131 else if (!this.orgunits.length) {
132 this.filteredOrgunits = [];
133 if (this.filterset) {
134 this.filterset = false;
137 if(this.filteredOrgunits.length == 0){
142 return !this.orgunits.length;
148 this.filteredOrgunits = [];
149 this.filterset = true;
150 for (var i = 0; i < this.orgunits.length; i++) {
151 this.http.get(this.orgunits[i].href)
152 .map(res => res.json())
154 zone.bind(orgunits => {
155 if (this.ownershipSelector.value == "" && this.typeSelector.value == "" && this.locationSelector.value == "") {
156 this.filteredOrgunits.push(orgunits);
162 for (var j = 0; j < orgunits.organisationUnitGroups.length; j++) {
163 if (this.ownershipSelector.value != "") {
164 if (orgunits.organisationUnitGroups[j].name == this.ownershipSelector.value) {
168 if (this.ownershipSelector.value == "") {
171 if (this.typeSelector.value != "") {
172 if (orgunits.organisationUnitGroups[j].name == this.typeSelector.value) {
176 if (this.typeSelector.value == "") {
179 if (this.locationSelector.value != "") {
180 if (orgunits.organisationUnitGroups[j].name == this.locationSelector.value) {
184 if (this.locationSelector.value == "") {
187 if (os == true && ts == true && ls == true) {
188 this.filteredOrgunits.push(orgunits);