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;
31 constructor(public http:Http) {
32 this.newsearch = new EventEmitter();
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);
44 return document.getElementById("myForm").reset();
50 this.visible = !this.visible;
57 this.ownershipSelector.selectedIndex = 0;
58 this.typeSelector.selectedIndex = 0;
59 this.locationSelector.selectedIndex = 0;
64 if (this.searchBar.value == "")
72 return document.getElementById("myForm").reset();
76 this.http.get(dhisAPI + "/api/organisationUnitGroupSets")
77 .map(res => res.json())
78 .map(res => res.organisationUnitGroupSets)
81 this.setOptionHeader(this.ownershipSelector, res[0].name);
82 this.setOptionHeader(this.typeSelector, res[1].name);
83 this.setOptionHeader(this.locationSelector, res[2].name);
85 for (var i = 0; i < res.length; i++) {
86 this.http.get(res[i].href)
87 .map(result => result.json())
90 if (result.displayName == "Facility Ownership") {
91 for (var j = 0; j < result.organisationUnitGroups.length; j++) {
92 this.setOption(this.ownershipSelector, result.organisationUnitGroups[j].name);
95 else if (result.displayName == "Facility Type") {
96 for (var j = 0; j < result.organisationUnitGroups.length; j++) {
97 this.setOption(this.typeSelector, result.organisationUnitGroups[j].name);
100 else if (result.displayName == "Location Rural/Urban") {
101 for (var j = 0; j < result.organisationUnitGroups.length; j++) {
102 this.setOption(this.locationSelector, result.organisationUnitGroups[j].name);
112 setOptionHeader(selector, value) {
113 this.option = document.createElement("option");
114 this.option.text = "All";
115 this.option.value = "";
116 selector.appendChild(this.option);
119 setOption(selector, value) {
120 this.option = document.createElement("option");
121 this.option.text = value;
122 this.option.value = value;
123 selector.appendChild(this.option);
127 if (this.ownershipSelector.value == "" && this.typeSelector.value == "" && this.locationSelector.value == "") {
128 this.filteredOrgunits = [];
129 for (var i = 0; i < this.orgunits.length; i++) {
130 this.filteredOrgunits.push(this.orgunits[i]);
133 else if (!this.orgunits.length == false && !this.filterset) {
136 else if (!this.orgunits.length) {
137 this.filteredOrgunits = [];
138 if (this.filterset) {
139 this.filterset = false;
142 if(this.filteredOrgunits.length == 0){
146 return !this.orgunits.length;
152 this.filteredOrgunits = [];
153 this.filterset = true;
154 for (var i = 0; i < this.orgunits.length; i++) {
155 this.http.get(this.orgunits[i].href)
156 .map(res => res.json())
158 zone.bind(orgunits => {
159 if (this.ownershipSelector.value == "" && this.typeSelector.value == "" && this.locationSelector.value == "") {
160 this.filteredOrgunits.push(orgunits);
166 for (var j = 0; j < orgunits.organisationUnitGroups.length; j++) {
167 if (this.ownershipSelector.value != "") {
168 if (orgunits.organisationUnitGroups[j].name == this.ownershipSelector.value) {
172 if (this.ownershipSelector.value == "") {
175 if (this.typeSelector.value != "") {
176 if (orgunits.organisationUnitGroups[j].name == this.typeSelector.value) {
180 if (this.typeSelector.value == "") {
183 if (this.locationSelector.value != "") {
184 if (orgunits.organisationUnitGroups[j].name == this.locationSelector.value) {
188 if (this.locationSelector.value == "") {
191 if (os == true && ts == true && ls == true) {
192 this.filteredOrgunits.push(orgunits);