From 5cc1f6d087cb7ea8a8d29c21c6166bad2660b444 Mon Sep 17 00:00:00 2001 From: "Yrjan A. F. Fraschetti" Date: Tue, 1 Dec 2015 00:33:25 +0100 Subject: [PATCH] Added auto filling in filter selectors --- src/components/search/search.html | 18 ++------ src/components/search/search.ts | 76 ++++++++++++++++++++++--------- 2 files changed, 57 insertions(+), 37 deletions(-) diff --git a/src/components/search/search.html b/src/components/search/search.html index 64daa6c..242625d 100644 --- a/src/components/search/search.html +++ b/src/components/search/search.html @@ -47,25 +47,13 @@
diff --git a/src/components/search/search.ts b/src/components/search/search.ts index 567e8fc..710029a 100644 --- a/src/components/search/search.ts +++ b/src/components/search/search.ts @@ -15,19 +15,25 @@ declare var zone: Zone; export class Search { orgunits: Array = []; loading: boolean = false; - facilityType: Array = []; - facilityOwnership: Array = []; - facilityLocation: Array = []; groups: Array = []; groupSet: Array = []; 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); } } -- 2.43.0