|
|
|
@@ -1,5 +1,6 @@ |
|
|
|
import { Component, OnInit, ViewChild,ElementRef } from '@angular/core'; |
|
|
|
import { MallService } from '../services/mall.service'; |
|
|
|
import { ToastService } from '../services/toast.service'; |
|
|
|
import { Router } from '@angular/router'; |
|
|
|
|
|
|
|
@Component({ |
|
|
|
@@ -19,11 +20,12 @@ export class MallsPage implements OnInit { |
|
|
|
|
|
|
|
constructor( |
|
|
|
private mallService: MallService, |
|
|
|
private router: Router |
|
|
|
private router: Router, |
|
|
|
private toastService: ToastService |
|
|
|
) { } |
|
|
|
|
|
|
|
ngOnInit() { |
|
|
|
this.storeAllMalls(); |
|
|
|
this.getMallsByLocation(); |
|
|
|
} |
|
|
|
|
|
|
|
toggleSearchBar() { |
|
|
|
@@ -48,7 +50,29 @@ export class MallsPage implements OnInit { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
storeAllMalls() { |
|
|
|
getMallsByLocation() { |
|
|
|
if (navigator.geolocation) { |
|
|
|
this.toastService.presentToast("Getting malls based on your location...", "dark"); |
|
|
|
navigator.geolocation.getCurrentPosition((position) => { |
|
|
|
this.mallService.mallsByLocation(position.coords.latitude, position.coords.longitude).then((response: any) => { |
|
|
|
if (response.length > 0) { |
|
|
|
localStorage.allMalls = JSON.stringify(response); |
|
|
|
this.allMalls = JSON.parse(localStorage.allMalls); |
|
|
|
this.tempMalls = JSON.parse(localStorage.allMalls); |
|
|
|
} else { |
|
|
|
this.toastService.presentToast("No malls near you your location, Getting all the malls...", "warning"); |
|
|
|
this.getAllMalls(); |
|
|
|
} |
|
|
|
}, () => { |
|
|
|
this.toastService.presentToast("Failed to fetch malls for your location", "danger"); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} else { |
|
|
|
this.getAllMalls(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
getAllMalls() { |
|
|
|
this.mallService.allMalls().then((response) => { |
|
|
|
localStorage.allMalls = JSON.stringify(response); |
|
|
|
this.allMalls = JSON.parse(localStorage.allMalls); |
|
|
|
|