src="https://www.brown.edu/sites/default/themes/pawtuxet/img/loader-larger.gif">
- <div class="divresult" id="divresult" [hidden]="!orgunits.length">
- <ul class="dropdown-menu result" >
- <li *ng-for="#orgunit of orgunits" (click)="getMoreInfo(orgunit)">
+
+ <div class="divresult" id="divresult" [hidden]="checkOrgunits()" >
+ <ul class="dropdown-menu result">
+ <li *ng-for="#orgunit of filteredOrgunits" id="orglist" (click)="getMoreInfo(orgunit)" >
<a href="#">{{orgunit.name}}<br/><span>{{orgunit.lastUpdated}}</span></a>
</li>
</ul>
+<!--
+<a var-unit id="testunit" (click)="getMoreInfo(unit.id)" href="#"></a>
+*ng-for="#orgunit of filteredOrgunits"
+<a href="#">{{orgunit.name}}<br/><span>{{orgunit.lastUpdated}}</span></a>
+(click)="getMoreInfo(orgunit)"
+-->
+
</div>
<button type="button" class="knapp" data-toggle="collapse" data-target="#dropdown-menu">
})
export class Search {
orgunits: Array<any> = [];
+ filteredOrgunits: Array<any> = [];
loading: boolean = false;
groups: Array<any> = [];
groupSet: Array<any> = [];
- counter: number = 0;
ownershipSelector: any;
typeSelector: any;
locationSelector: any;
option: any;
searchBar: any;
+ filterset: boolean = false;
+
+
constructor(public http:Http) {
this.newsearch = new EventEmitter();
this.typeSelector = document.getElementById("typeSelector");
this.locationSelector = document.getElementById("locationSelector");
this.searchBar = document.getElementById("livesearch");
+ this.orglist = document.getElementById("orglist");
+ this.a = document.getElementById("testunit");
}
getMoreInfo(orgunit) {
- console.log("yolo");
+ console.log();
this.newsearch.next(orgunit.id);
}
selector.appendChild(this.option);
}
- setFilter(){
- console.log("Dette er setFilter");
- console.log(this.ownershipSelector.value);
- var text = livesearch.value;
+ checkOrgunits(){
+ if(!this.orgunits.length == false && !this.filterset){
+ this.setFilter();
+ this.filterset = true;
+ }
+ else if(!this.orgunits.length){
+ this.filteredOrgunits = [];
+ if(this.filterset) {
+ this.filterset = false;
+ }
+
+ }
+ return !this.orgunits.length;
+ }
- //livesearch.value = "";
- //console.log(this.searchBar.key);
- /*for(var i = 0; i < text.length; i++){
- livesearch.value += text.charAt(i);
- }*/
- //this.searchBar.createEvent('keyup');
+ setFilter(){
+ this.filteredOrgunits = [];
+
+ for (var i = 0; i < this.orgunits.length; i++) {
+ this.http.get(this.orgunits[i].href)
+ .map(res => res.json())
+ .subscribe(
+ zone.bind(orgunits => {
+ if (this.ownershipSelector.value == "" && this.typeSelector.value == "" && this.locationSelector.value == "") {
+ this.filteredOrgunits.push(orgunits);
+ }
+ else {
+ var os = false; var ls = false;var ts = false;
+ for (var group in orgunits.organisationUnitGroups) {
+ if (this.ownershipSelector.value != "") {
+ if (orgunits.organisationUnitGroups[group].name == this.ownershipSelector.value) {
+ os = true;
+ }
+ }
+ if (this.ownershipSelector.value == "") {
+ os = true;
+ }
+ if (this.typeSelector.value != "") {
+ if (orgunits.organisationUnitGroups[group].name == this.typeSelector.value) {
+ ts = true;
+ }
+ }
+ if (this.typeSelector.value == "") {
+ ts = true;
+ }
+ if (this.locationSelector.value != "") {
+ if (orgunits.organisationUnitGroups[group].name == this.locationSelector.value) {
+ ls = true;
+ }
+ }
+ if (this.locationSelector.value == "") {
+ ls = true;
+ }
+ if (os == true && ts == true && ls == true) {
+ this.filteredOrgunits.push(orgunits);
+ os = false;
+ ts = false;
+ ls = false;
- this.searchBar.focus(true);
+ }
+ }
+ }
+ })
+ )
+ }
}
}