|
|
|
@@ -1,7 +1,6 @@ |
|
|
|
import { Component, OnInit, ViewChild,ElementRef } from '@angular/core'; |
|
|
|
import { MallService } from '../services/mall.service'; |
|
|
|
import { Router } from '@angular/router'; |
|
|
|
import { Geolocation } from '@ionic-native/geolocation/ngx'; |
|
|
|
|
|
|
|
@Component({ |
|
|
|
selector: 'app-malls', |
|
|
|
@@ -13,7 +12,6 @@ export class MallsPage implements OnInit { |
|
|
|
selected_tab: string = 'you'; |
|
|
|
tempMalls: any = []; |
|
|
|
allMalls: any = []; |
|
|
|
nearByMalls: any = []; |
|
|
|
show_sort_popup: boolean = false; |
|
|
|
showSearchBar: boolean = false; |
|
|
|
selected_sort: string = null; |
|
|
|
@@ -21,34 +19,22 @@ export class MallsPage implements OnInit { |
|
|
|
|
|
|
|
constructor( |
|
|
|
private mallService: MallService, |
|
|
|
private router: Router, |
|
|
|
private geolocation: Geolocation |
|
|
|
private router: Router |
|
|
|
) { } |
|
|
|
|
|
|
|
ngOnInit() { |
|
|
|
this.fetchMallsByLocation(); |
|
|
|
this.storeAllMalls(); |
|
|
|
this.storeAllMalls(); |
|
|
|
} |
|
|
|
|
|
|
|
fetchMallsByLocation() { |
|
|
|
this.geolocation.getCurrentPosition().then((position) => { |
|
|
|
this.mallService.mallsByLocation(position.coords.latitude, position.coords.longitude) |
|
|
|
.then((response) => { |
|
|
|
this.nearByMalls = response; |
|
|
|
this.tempMalls = response; |
|
|
|
}) |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
toggleSearchBar() { |
|
|
|
if (this.searchTerm.length > 0) { |
|
|
|
this.searchTerm = ''; |
|
|
|
this.tempMalls = JSON.parse(JSON.stringify(this.allMalls)); |
|
|
|
} else { |
|
|
|
this.showSearchBar = !this.showSearchBar; |
|
|
|
this.fetchMallsByLocation(); |
|
|
|
setTimeout(()=>{ // this will make the execution after the above boolean has changed |
|
|
|
this.searchElement.nativeElement.focus(); |
|
|
|
}, 1000); |
|
|
|
}, 1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@@ -58,7 +44,7 @@ export class MallsPage implements OnInit { |
|
|
|
return mallData.mall.mall_name.toLowerCase().includes(this.searchTerm.toLowerCase()); |
|
|
|
}); |
|
|
|
} else { |
|
|
|
this.tempMalls = JSON.parse(JSON.stringify(this.nearByMalls)); |
|
|
|
this.tempMalls = JSON.parse(JSON.stringify(this.allMalls)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@@ -66,6 +52,7 @@ export class MallsPage implements OnInit { |
|
|
|
this.mallService.allMalls().then((response) => { |
|
|
|
localStorage.allMalls = JSON.stringify(response); |
|
|
|
this.allMalls = JSON.parse(localStorage.allMalls); |
|
|
|
this.tempMalls = JSON.parse(localStorage.allMalls); |
|
|
|
}, (error) => { |
|
|
|
console.log(error) |
|
|
|
}); |
|
|
|
|