Added auto filling in filter selectors
authorYrjan A. F. Fraschetti <yrjanaff@MacBook-Pro.local>
Mon, 30 Nov 2015 23:33:25 +0000 (00:33 +0100)
committerYrjan A. F. Fraschetti <yrjanaff@MacBook-Pro.local>
Mon, 30 Nov 2015 23:33:25 +0000 (00:33 +0100)
src/components/search/search.html
src/components/search/search.ts

index 64daa6c..242625d 100644 (file)
 <div>
 <ul id="dropdown-menu" class="dropdown-menu">
     <li><select class="form-control filtervalg" id="ownershipSelector" (click)="setFilter()">
-        <!--<option value="">-- All Facility Ownerships --</option>-->
-        <option *ng-for="#owner of facilityOwnership" value={{owner}}>{{owner}}</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 class="form-control filtervalg" 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 class="form-control filtervalg" id="locationSelector" (click)="setFilter()">
-        <option value="">-- All locations --</option>
-        <option value="Rural">Rural</option>
-        <option value="Urban">Urban</option>
+
     </select></li>
 </ul>
 
index 567e8fc..710029a 100644 (file)
@@ -15,19 +15,25 @@ declare var zone: Zone;
 export class Search {
     orgunits: Array<any> = [];
     loading: boolean = false;
-    facilityType: Array<any> = [];
-    facilityOwnership: Array<any> = [];
-    facilityLocation: Array<any> = [];
     groups: Array<any> = [];
     groupSet: Array<any> = [];
     counter: number = 0;
+    ownernshipSelector: any;
+    typeSelector: any;
+    locationSelector: any;
+    option: any;
+    searchBar: any;
 
     constructor(public http:Http) {
         this.newsearch = new EventEmitter();
         this.visible = true;
         //this.getFilterGroups();
         this.getUnitGroupSets();
-
+        this.ownernshipSelector = document.getElementById("ownershipSelector");
+        this.typeSelector = document.getElementById("typeSelector");
+        this.locationSelector = document.getElementById("locationSelector");
+        this.searchBar = document.getElementById("livesearch");
+        this.ownernshipSelector.addEventListener("click", this.testFilter);
     }
 
     getMoreInfo(orgunit) {
@@ -42,35 +48,43 @@ export class Search {
         //this.getUnitGroupSets();
     }
 
+
     getUnitGroupSets(){
         this.http.get(dhisAPI + "/api/organisationUnitGroupSets")
         .map(res => res.json())
         .map(res => res.organisationUnitGroupSets)
         .subscribe(
             zone.bind( res =>{
-                this.facilityOwnership .push("-- " + res[0].name + " --");
-                this.facilityType.push("-- " + res[1].name + " --");
-                this.facilityLocation.push("-- " + res[2].name + " --");
-
+                this.setOption("-- " + res[0].name + " --");
+                this.option.value = "";
+                this.ownernshipSelector.appendChild(this.option);
+                this.setOption("-- " + res[1].name + " --");
+                this.option.value = "";
+                this.typeSelector.appendChild(this.option);
+                this.setOption("-- " + res[2].name + " --");
+                this.option.value = "";
+                this.locationSelector.appendChild(this.option);
                 for(var i = 0; i < res.length; i++) {
                     this.http.get(res[i].href)
                     .map(result => result.json())
-                    .map(result => result.organisationUnitGroups)
                     .subscribe(
                         zone.bind(result => {
-                            if(this.facilityOwnership.length == 1){
-                                for(var j = 0; j < result.length; j++) {
-                                    this.facilityOwnership.push(result[j].name);
+                            if(result.displayName == "Facility Ownership"){
+                                for(var j = 0; j < result.organisationUnitGroups.length; j++) {
+                                    this.setOption(result.organisationUnitGroups[j].name);
+                                    this.ownernshipSelector.appendChild(this.option);
                                 }
                             }
-                            else if(this.facilityType.length == 1){
-                                for(var j = 0; j < result.length; j++) {
-                                    this.facilityType.push(result[j].name);
+                            else if(result.displayName == "Facility Type"){
+                                for(var j = 0; j < result.organisationUnitGroups.length; j++) {
+                                    this.setOption(result.organisationUnitGroups[j].name);
+                                    this.typeSelector.appendChild(this.option);
                                 }
                             }
-                            else if(this.facilityLocation.length == 1){
-                                for(var j = 0; j < result.length; j++) {
-                                    this.facilityLocation.push(result[j].name);
+                            else if(result.displayName == "Location Rural/Urban"){
+                                for(var j = 0; j < result.organisationUnitGroups.length; j++) {
+                                    this.setOption(result.organisationUnitGroups[j].name);
+                                    this.locationSelector.appendChild(this.option);
                                 }
                             }
                     }));
@@ -79,14 +93,32 @@ export class Search {
         )
     }
 
+    setOption(value){
+        this.option = document.createElement("option");
+        this.option.text = value;
+        this.option.value = value;
+    }
+
 
     setFilter(){
+        console.log("Dette er setFilter");
+
         var text = livesearch.value;
-        livesearch.value = "";
-        console.log(text);
-        for(var i = 0; i < text.length; i++){
+
+        //livesearch.value = "";
+        //console.log(this.searchBar.key);
+
+        /*for(var i = 0; i < text.length; i++){
             livesearch.value += text.charAt(i);
-        }
+        }*/
+        //this.searchBar.createEvent('keyup');
+
+        this.searchBar.focus(true);
+    }
+
+    testFilter(test){
+        console.log("Testfilter ble aktivert!");
+        console.log(test);
     }
 
 }