Added selectors for filter
authorYrjan A. F. Fraschetti <yrjanaff@1x-193-157-251-118.uio.no>
Thu, 26 Nov 2015 09:07:27 +0000 (10:07 +0100)
committerYrjan A. F. Fraschetti <yrjanaff@1x-193-157-251-118.uio.no>
Thu, 26 Nov 2015 09:07:27 +0000 (10:07 +0100)
src/components/search/livesearch.ts
src/components/search/search.html
src/components/search/search.ts

index 2d64f62..40f9249 100644 (file)
@@ -16,6 +16,7 @@ declare var zone: Zone;
 export class LiveSearch {
     results:EventEmitter = new EventEmitter();
     loading:EventEmitter = new EventEmitter();
+    
 
     constructor(private el:ElementRef, public http:Http, public search:SearchService) {
 
@@ -53,15 +54,45 @@ export class LiveSearch {
                 .map(res => res.json())
                 .subscribe(
                     zone.bind(orgunits => {
+                        var os = false;
+                        var ls = false;
+                        var ts = false;
                         for (var group in orgunits.organisationUnitGroups){
-                            if(orgunits.organisationUnitGroups[group].name == "Rural"){
+                            if(ownershipSelector.value != ""){
+                                if(orgunits.organisationUnitGroups[group].name == ownershipSelector.value){
+                                    os = true;
+                                }
+                            }
+                            if(ownershipSelector.value == ""){
+                                os = true;
+                            }
+                            if(typeSelector.value != ""){
+                                if(orgunits.organisationUnitGroups[group].name == typeSelector.value){
+                                    ts = true;
+                                }
+                            }
+                            if(typeSelector.value == ""){
+                                ts = true;
+                            }
+                            if(locationSelector.value != ""){
+                                if(orgunits.organisationUnitGroups[group].name == locationSelector.value){
+                                    ls = true;
+                                }
+                            }
+                            if(locationSelector.value == "") {
+                                ls = true;
+                            }
+                            if(os == true && ts == true && ls == true){
                                 filteredOrgunits.push(orgunits);
-                                console.log(filteredOrgunits);
+                                os = false;
+                                ts = false;
+                                ls = false;
                             }
                         }
                     })
                 )
         }
+        console.log(filteredOrgunits);
         return filteredOrgunits;
     }
 }
index 1e9b50d..266540d 100644 (file)
 
 <div>
 <ul id="dropdown-menu" class="dropdown-menu">
+    <li><select id="ownershipSelector" (click)="setFilter()">
+        <option value="">-- All Facility Ownerships --</option>
+        <option value="Mission">Mission</option>
+        <option value="NGO">NGO</option>
+        <option value="Private Clinic">Private Clinic</option>
+        <option value="Public facilities">Public facilities</option>
+    </select></li>
+    <li><select id="typeSelector" (click)="setFilter()">
+        <option value="">-- All Facility Types --</option>
+        <option value="CHC">CHC</option>
+        <option value="CHP">CHP</option>
+        <option value="Clinic">Clinic</option>
+        <option value="Hospital">Hospital</option>
+        <option value="MCHP">MCHP</option>
+    </select></li>
+    <li><select id="locationSelector" (click)="setFilter()">
+        <option value="">-- All locations --</option>
+        <option value="Rural">Rural</option>
+        <option value="Urban">Urban</option>
+    </select></li>
 
-    <li><a href="#">Another action</a></li>
-    <li><a href="#">Something else here</a></li>
     <li role="separator" class="divider"></li>
     <li><a href="#">Separated link</a></li>
 </ul>
index 7039114..002a981 100644 (file)
@@ -1,4 +1,5 @@
 import {Component,EventEmitter, View, CORE_DIRECTIVES} from 'angular2/angular2';
+import {Http} from 'angular2/http';
 import {LiveSearch} from "./livesearch";
 
 @Component({
@@ -11,8 +12,12 @@ import {LiveSearch} from "./livesearch";
 export class Search {
     orgunits: Array<any> = [];
     loading: boolean = false;
+    facilityType: Array<any> = [];
+    facilityOwnership: Array<any> = [];
+    facilityLocation: Array<any> = [];
 
-    constructor() {
+
+    constructor(public http:Http) {
         this.newsearch = new EventEmitter();
         this.visible = true;
 
@@ -29,6 +34,46 @@ export class Search {
         this.visible = !this.visible;
     }
 
+    /*getFilterTypes(){
+        this.http.get(dhis + "/api/organisationUnitGroups/")
+            .map(res => res.json())
+            .map(res => res.organisationUnitGroups)
+            .subscribe(
+                zone.bind(res => {
+                   for(var i = 0; i < res.length; i++){
+                       this.http.get(res[i].href)
+                        .map(result => result.json())
+                        .map(result => result.organisationUnitGroupSet)
+                        .subscribe(
+                            zone.bind(result => {
+                                if(result.name == "Location Rural/Urban"){
+                                    this.facilityLocation.push(res[i].name);
+                                }
+                                else if(result.name == "Facility Type"){
+                                    this.facilityType.push(res[i].name);
+                                }
+                                else if(result.name == "")
+                            })
+                        )
+                   }
+
+                })
+            )
+    }
+
+    setFilterTypes(){
+
+    }*/
+
+    setFilter(){
+        var text = livesearch.value;
+        livesearch.value = "";
+        console.log(text);
+        for(var i = 0; i < text.length; i++){
+            livesearch.value += text.charAt(i);
+        }
+    }
+
 }