Fixed bugs where searchresult did not update, where searchlist got duplicated when...
authorYrjan A. F. Fraschetti <yrjanaff@1x-193-157-241-240.uio.no>
Sun, 6 Dec 2015 11:51:38 +0000 (12:51 +0100)
committerYrjan A. F. Fraschetti <yrjanaff@1x-193-157-241-240.uio.no>
Sun, 6 Dec 2015 11:51:38 +0000 (12:51 +0100)
src/components/search/livesearch.ts
src/components/search/search.html
src/components/search/search.ts

index 60c364f..390a903 100644 (file)
@@ -46,58 +46,5 @@ export class LiveSearch {
                 }
             )
     }
-
-    filterUnits(orgunits) {
-        var filteredOrgunits: Array<any> = [];
-        for (var i = 0; i < orgunits.length; i++) {
-            this.http.get(orgunits[i].href)
-                .map(res => res.json())
-                .subscribe(
-                    zone.bind(orgunits => {
-                        if (ownershipSelector.value == "" && typeSelector.value == "" && locationSelector.value == "") {
-                            filteredOrgunits.push(orgunits);
-                        }
-                        else {
-                            var os = false;
-                            var ls = false;
-                            var ts = false;
-                            for (var group in orgunits.organisationUnitGroups) {
-                                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);
-                                    os = false;
-                                    ts = false;
-                                    ls = false;
-                                }
-                            }
-                        }
-                    })
-                )
-        }
-        return filteredOrgunits;
-    }
 }
 
index 5102804..57c19eb 100644 (file)
                     name="livesearch"
                     id="livesearch"
                     placeholder="Search"
-                    value=""/>
+                    value=""
+                    (change)="checkOrgunits()"/>
 
 
             <!--<button class="exitsearch" id="exitsearch" (click)="emptyByClick()">
           &cross; </button>-->
             <button type="button" class="knapp col-md-2" (click)="toggle()"
-                    onclick="$('#ownershipSelector, #typeSelector, #locationSelector').prop('selectedIndex',0);"
                     data-toggle="collapse" data-target="#dropdown-menu">
                 {{ visible ? '&xdtri;' : '&cross;' }}
             </button>
index 28aad7a..dc5d2a3 100644 (file)
@@ -51,7 +51,12 @@ export class Search {
 
     toggle() {
         this.visible = !this.visible;
-        //this.getUnitGroupSets();
+        if(this.visible){
+            this.ownershipSelector.selectedIndex = 0;
+            this.typeSelector.selectedIndex = 0;
+            this.locationSelector.selectedIndex = 0;
+            this.checkOrgunits();
+        }
     }
 
     hideDiv(){
@@ -117,9 +122,14 @@ export class Search {
     }
 
     checkOrgunits(){
-        if(!this.orgunits.length == false && !this.filterset){
+        if (this.ownershipSelector.value == "" && this.typeSelector.value == "" && this.locationSelector.value == "") {
+            this.filteredOrgunits = [];
+            for(var i = 0; i < this.orgunits.length; i++) {
+                this.filteredOrgunits.push(this.orgunits[i]);
+            }
+        }
+        else if(!this.orgunits.length == false && !this.filterset){
             this.setFilter();
-            this.filterset = true;
         }
         else if(!this.orgunits.length){
             this.filteredOrgunits = [];
@@ -134,7 +144,7 @@ export class Search {
 
     setFilter(){
         this.filteredOrgunits = [];
-
+        this.filterset = true;
         for (var i = 0; i < this.orgunits.length; i++) {
             this.http.get(this.orgunits[i].href)
                 .map(res => res.json())
@@ -145,9 +155,9 @@ export class Search {
                         }
                         else {
                             var os = false; var ls = false;var ts = false;
-                            for (var group in orgunits.organisationUnitGroups) {
+                            for (var j = 0; j < orgunits.organisationUnitGroups.length; j++) {
                                 if (this.ownershipSelector.value != "") {
-                                    if (orgunits.organisationUnitGroups[group].name == this.ownershipSelector.value) {
+                                    if (orgunits.organisationUnitGroups[j].name == this.ownershipSelector.value) {
                                         os = true;
                                     }
                                 }
@@ -155,7 +165,7 @@ export class Search {
                                     os = true;
                                 }
                                 if (this.typeSelector.value != "") {
-                                    if (orgunits.organisationUnitGroups[group].name == this.typeSelector.value) {
+                                    if (orgunits.organisationUnitGroups[j].name == this.typeSelector.value) {
                                         ts = true;
                                     }
                                 }
@@ -163,7 +173,7 @@ export class Search {
                                     ts = true;
                                 }
                                 if (this.locationSelector.value != "") {
-                                    if (orgunits.organisationUnitGroups[group].name == this.locationSelector.value) {
+                                    if (orgunits.organisationUnitGroups[j].name == this.locationSelector.value) {
                                         ls = true;
                                     }
                                 }
@@ -175,7 +185,6 @@ export class Search {
                                     os = false;
                                     ts = false;
                                     ls = false;
-
                                 }
                             }
                         }