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;
30 constructor(public http:Http) {
31 this.newsearch = new EventEmitter();
33 this.getUnitGroupSets();
34 this.ownershipSelector = document.getElementById("ownershipSelector");
35 this.typeSelector = document.getElementById("typeSelector");
36 this.locationSelector = document.getElementById("locationSelector");
37 this.searchBar = document.getElementById("livesearch");
38 this.orglist = document.getElementById("orglist");
39 this.a = document.getElementById("testunit");
42 getMoreInfo(orgunit) {
44 this.newsearch.next(orgunit.id);
45 return document.getElementById("myForm").reset();
52 this.visible = !this.visible;
53 //this.getUnitGroupSets();
57 if(livesearch.value == "")
64 return document.getElementById("myForm").reset();
68 this.http.get(dhisAPI + "/api/organisationUnitGroupSets")
69 .map(res => res.json())
70 .map(res => res.organisationUnitGroupSets)
73 this.setOptionHeader(this.ownershipSelector, res[0].name);
74 this.setOptionHeader(this.typeSelector, res[1].name);
75 this.setOptionHeader(this.locationSelector, res[2].name);
77 for(var i = 0; i < res.length; i++) {
78 this.http.get(res[i].href)
79 .map(result => result.json())
82 if(result.displayName == "Facility Ownership"){
83 for(var j = 0; j < result.organisationUnitGroups.length; j++) {
84 this.setOption(this.ownershipSelector, result.organisationUnitGroups[j].name);
87 else if(result.displayName == "Facility Type"){
88 for(var j = 0; j < result.organisationUnitGroups.length; j++) {
89 this.setOption(this.typeSelector, result.organisationUnitGroups[j].name);
92 else if(result.displayName == "Location Rural/Urban"){
93 for(var j = 0; j < result.organisationUnitGroups.length; j++) {
94 this.setOption(this.locationSelector, result.organisationUnitGroups[j].name);
103 setOptionHeader(selector, value){
104 this.option = document.createElement("option");
105 this.option.text = "All";
106 this.option.value = "";
107 selector.appendChild(this.option);
110 setOption(selector, value){
111 this.option = document.createElement("option");
112 this.option.text = value;
113 this.option.value = value;
114 selector.appendChild(this.option);
118 if(!this.orgunits.length == false && !this.filterset){
120 this.filterset = true;
122 else if(!this.orgunits.length){
123 this.filteredOrgunits = [];
125 this.filterset = false;
129 return !this.orgunits.length;
134 this.filteredOrgunits = [];
136 for (var i = 0; i < this.orgunits.length; i++) {
137 this.http.get(this.orgunits[i].href)
138 .map(res => res.json())
140 zone.bind(orgunits => {
141 if (this.ownershipSelector.value == "" && this.typeSelector.value == "" && this.locationSelector.value == "") {
142 this.filteredOrgunits.push(orgunits);
145 var os = false; var ls = false;var ts = false;
146 for (var group in orgunits.organisationUnitGroups) {
147 if (this.ownershipSelector.value != "") {
148 if (orgunits.organisationUnitGroups[group].name == this.ownershipSelector.value) {
152 if (this.ownershipSelector.value == "") {
155 if (this.typeSelector.value != "") {
156 if (orgunits.organisationUnitGroups[group].name == this.typeSelector.value) {
160 if (this.typeSelector.value == "") {
163 if (this.locationSelector.value != "") {
164 if (orgunits.organisationUnitGroups[group].name == this.locationSelector.value) {
168 if (this.locationSelector.value == "") {
171 if (os == true && ts == true && ls == true) {
172 this.filteredOrgunits.push(orgunits);