Commit afbadcae by Adarsh K

bug fixes

parent 99f7053b
...@@ -133,7 +133,7 @@ export class CartPage implements OnInit { ...@@ -133,7 +133,7 @@ export class CartPage implements OnInit {
} }
getTax(amount) { getTax(amount) {
return Math.round((this.taxAmount = (amount * 10) / 100)).toFixed(2); return (this.taxAmount = (amount * 10) / 100).toFixed(2);
} }
getwaypayk() { getwaypayk() {
...@@ -154,7 +154,7 @@ export class CartPage implements OnInit { ...@@ -154,7 +154,7 @@ export class CartPage implements OnInit {
} }
goToPage(path, data = null) { goToPage(path, data = null) {
this.router.navigateByUrl(path, { queryParams: data }); this.router.navigateByUrl(path, { queryParams: data, replaceUrl: true });
document.body.scrollTop = document.documentElement.scrollTop = 0; document.body.scrollTop = document.documentElement.scrollTop = 0;
} }
......
...@@ -66,6 +66,7 @@ export class HomePage implements OnInit { ...@@ -66,6 +66,7 @@ export class HomePage implements OnInit {
private authService: AuthService private authService: AuthService
) { ) {
this.loader = false; this.loader = false;
this.address = 'Pick your Location';
} }
ngOnInit() { ngOnInit() {
...@@ -89,7 +90,7 @@ export class HomePage implements OnInit { ...@@ -89,7 +90,7 @@ export class HomePage implements OnInit {
navigator.geolocation.getCurrentPosition(position => { navigator.geolocation.getCurrentPosition(position => {
this.lat = position.coords.latitude; this.lat = position.coords.latitude;
this.lng = position.coords.longitude; this.lng = position.coords.longitude;
this.centerService.getNearBy(this.lat, this.lng, 10); this.centerService.getNearBy(this.lat, this.lng, this.service.distance);
this.getAddress(this.lat, this.lng); this.getAddress(this.lat, this.lng);
}); });
} }
...@@ -121,7 +122,7 @@ export class HomePage implements OnInit { ...@@ -121,7 +122,7 @@ export class HomePage implements OnInit {
this.addressService.setDefaultAddress(address.addressId, this.custId).then(() => { this.addressService.setDefaultAddress(address.addressId, this.custId).then(() => {
this.address = address.address; this.address = address.address;
console.log(address.latLng); console.log(address.latLng);
this.centerService.getNearBy(address.latLng._lat, address.latLng._long, 10); this.centerService.getNearBy(address.latLng._lat, address.latLng._long, this.service.distance);
this.loader = false; this.loader = false;
}).catch(err => { }).catch(err => {
this.loader = false; this.loader = false;
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
<span *ngIf="product.size !== 'Any-Size'">{{product.size}}</span>&nbsp;<span>{{product.qty}}</span> <span *ngIf="product.size !== 'Any-Size'">{{product.size}}</span>&nbsp;<span>{{product.qty}}</span>
</h5> </h5>
<p *ngIf="product.price">A$ {{service.formatNumber(product.price)}}</p> <p *ngIf="product.price">A$ {{service.formatNumber(product.price.toFixed(2))}}</p>
</div> </div>
<div class="order_other"> <div class="order_other">
<h6 class="floatRight" *ngIf="order.bookDate"> <h6 class="floatRight" *ngIf="order.bookDate">
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
</div> </div>
<div class="order_info"> <div class="order_info">
<h5 class="floatRight">TOTAL PRICE : {{service.formatNumber(order.amount)}}</h5> <h5 class="floatRight">TOTAL PRICE : {{getProductTotal(order.product)}}</h5>
<div class="clear"></div> <div class="clear"></div>
</div> </div>
......
...@@ -120,4 +120,11 @@ export class MyorderPage implements OnInit { ...@@ -120,4 +120,11 @@ export class MyorderPage implements OnInit {
return unescape(text.replace(/%uFFFD/g, '')); return unescape(text.replace(/%uFFFD/g, ''));
} }
getProductTotal(products) {
let amtPrice = 0;
products.forEach(element => {
amtPrice += element.price * element.qty;
});
return 'A$' + this.service.formatNumber(amtPrice);
}
} }
...@@ -23,10 +23,10 @@ const routes: Routes = [ ...@@ -23,10 +23,10 @@ const routes: Routes = [
IonicModule, IonicModule,
AgmDirectionModule, AgmDirectionModule,
AgmCoreModule.forRoot({ AgmCoreModule.forRoot({
apiKey: "AIzaSyBn6hOlr6YHcZAmbptlsmbhvH5iQllWflE" apiKey: 'AIzaSyBn6hOlr6YHcZAmbptlsmbhvH5iQllWflE'
}), }),
RouterModule.forChild(routes) RouterModule.forChild(routes)
], ],
declarations: [NearbyPage] declarations: [NearbyPage]
}) })
export class NearbyPageModule {} export class NearbyPageModule { }
<div class="nav_header"> <div class="nav_header">
<button class="nav_btn nav_back floatLeft" (click)="goBack()"> <button class="nav_btn nav_back floatLeft" (click)="goBack()" *ngIf="authService.regState">
<img src="../assets/Group17_2.png" /> <img src="../assets/Group17_2.png" />
</button> </button>
<div class="nav_title floatLeft"> <div class="nav_title floatLeft">
...@@ -9,119 +9,54 @@ ...@@ -9,119 +9,54 @@
</div> </div>
<ion-content> <ion-content>
<div class="nearby_map"> <div class="nearby_map">
<agm-map <agm-map [latitude]="latitude" [longitude]="longitude" [zoom]="8" [backgroundColor]="'rgba(29, 27, 130,0.2)'">
[latitude]="latitude" <agm-marker [latitude]="latitude" [longitude]="longitude" [markerDraggable]="true"
[longitude]="longitude" (dragEnd)="markerDragEnd($event)"></agm-marker>
[zoom]="8"
[backgroundColor]="'rgba(29, 27, 130,0.2)'"
>
<agm-marker
[latitude]="latitude"
[longitude]="longitude"
[markerDraggable]="true"
(dragEnd)="markerDragEnd($event)"
></agm-marker>
</agm-map> </agm-map>
<form <form (ngSubmit)="onSubmit(addressForm.value); addressForm.reset()" #addressForm="ngForm" method="post"
(ngSubmit)="onSubmit(addressForm.value); addressForm.reset()" class="form-horizontal">
#addressForm="ngForm"
method="post"
class="form-horizontal"
>
<div class="add_address_wrapper"> <div class="add_address_wrapper">
<h5>DELIVERY</h5> <h5>DELIVERY</h5>
<p>{{address}}</p> <p>{{address}}</p>
<input <input [(ngModel)]="addressForm.building" name="building" #building="ngModel" name="building" required
[(ngModel)]="addressForm.building" placeholder="House No./ Building No" />
name="building" <div class="md-errors-spacer" [hidden]="building.valid || landmark.pristine" class="ion-padding-start">
#building="ngModel"
name="building"
required
placeholder="House No./ Building No"
/>
<div
class="md-errors-spacer"
[hidden]="building.valid || landmark.pristine"
class="ion-padding-start"
>
Building Name is required Building Name is required
</div> </div>
<input <input [(ngModel)]="addressForm.landmark" name="landmark" #landmark="ngModel" name="landmark" required
[(ngModel)]="addressForm.landmark" placeholder="Landmark" />
name="landmark" <div class="md-errors-spacer" [hidden]="landmark.valid || landmark.pristine" class="ion-padding-start">
#landmark="ngModel"
name="landmark"
required
placeholder="Landmark"
/>
<div
class="md-errors-spacer"
[hidden]="landmark.valid || landmark.pristine"
class="ion-padding-start"
>
Landmark is required Landmark is required
</div> </div>
<ion-grid> <ion-grid>
<ion-row> <ion-row>
<ion-col> <ion-col>
<h6> <h6>
<input <input class="styled-checkbox" id="styled-check-1" type="radio" value="Home"
class="styled-checkbox" [(ngModel)]="addressForm.addressType" name="addressType" #addressType="ngModel" required />
id="styled-check-1"
type="radio"
value="Home"
[(ngModel)]="addressForm.addressType"
name="addressType"
#addressType="ngModel"
required
/>
<label for="styled-check-1"><span>Home</span></label> <label for="styled-check-1"><span>Home</span></label>
</h6> </h6>
</ion-col> </ion-col>
<ion-col> <ion-col>
<h6> <h6>
<input <input class="styled-checkbox" id="styled-check-2" type="radio" value="Work"
class="styled-checkbox" [(ngModel)]="addressForm.addressType" name="addressType" #addressType="ngModel" required />
id="styled-check-2"
type="radio"
value="Work"
[(ngModel)]="addressForm.addressType"
name="addressType"
#addressType="ngModel"
required
/>
<label for="styled-check-2"><span>Office</span></label> <label for="styled-check-2"><span>Office</span></label>
</h6> </h6>
</ion-col> </ion-col>
<ion-col> <ion-col>
<h6> <h6>
<input <input class="styled-checkbox" id="styled-check-3" type="radio" value="Other"
class="styled-checkbox" [(ngModel)]="addressForm.addressType" name="addressType" #addressType="ngModel" required />
id="styled-check-3"
type="radio"
value="Other"
[(ngModel)]="addressForm.addressType"
name="addressType"
#addressType="ngModel"
required
/>
<label for="styled-check-3"><span>Others</span></label> <label for="styled-check-3"><span>Others</span></label>
</h6> </h6>
</ion-col> </ion-col>
</ion-row> </ion-row>
<div <div class="md-errors-spacer" [hidden]="addressType.valid || addressType.pristine" class="ion-padding-start">
class="md-errors-spacer"
[hidden]="addressType.valid || addressType.pristine"
class="ion-padding-start"
>
Address Type is required Address Type is required
</div> </div>
</ion-grid> </ion-grid>
<button <button class="add_btn" type="submit" [disabled]="!addressForm.form.valid">
class="add_btn"
type="submit"
[disabled]="!addressForm.form.valid"
>
ADD ADD
</button> </button>
</div> </div>
...@@ -133,4 +68,4 @@ ...@@ -133,4 +68,4 @@
<div></div> <div></div>
</div> </div>
</div> </div>
</ion-content> </ion-content>
\ No newline at end of file
...@@ -11,6 +11,7 @@ import { MapsAPILoader, MouseEvent } from '@agm/core'; ...@@ -11,6 +11,7 @@ import { MapsAPILoader, MouseEvent } from '@agm/core';
import { Address } from './../../config/services/address'; import { Address } from './../../config/services/address';
import { AddressService } from './../../config/address.service'; import { AddressService } from './../../config/address.service';
import { ServiceService } from './../../config/service.service'; import { ServiceService } from './../../config/service.service';
import { AuthService } from './../../config/auth.service';
import { NgForm } from '@angular/forms'; import { NgForm } from '@angular/forms';
import * as firebase from 'firebase'; import * as firebase from 'firebase';
/* import { google } from '@agm/core/services/google-maps-types'; */ /* import { google } from '@agm/core/services/google-maps-types'; */
...@@ -41,7 +42,8 @@ export class NearbyPage implements OnInit { ...@@ -41,7 +42,8 @@ export class NearbyPage implements OnInit {
private mapsAPILoader: MapsAPILoader, private mapsAPILoader: MapsAPILoader,
private ngZone: NgZone, private ngZone: NgZone,
public addressService: AddressService, public addressService: AddressService,
public service: ServiceService public service: ServiceService,
public authService: AuthService
) { ) {
this.successState = false; this.successState = false;
this.type = 0; this.type = 0;
...@@ -67,7 +69,13 @@ export class NearbyPage implements OnInit { ...@@ -67,7 +69,13 @@ export class NearbyPage implements OnInit {
// google maps zoom level // google maps zoom level
private setCurrentLocation() { private setCurrentLocation() {
console.log('map-called');
if ('geolocation' in navigator) { if ('geolocation' in navigator) {
console.log(navigator);
this.latitude = -33.87276;
this.longitude = 151.20534;
this.zoom = 8;
this.getAddress(this.latitude, this.longitude);
navigator.geolocation.getCurrentPosition(position => { navigator.geolocation.getCurrentPosition(position => {
this.latitude = position.coords.latitude; this.latitude = position.coords.latitude;
this.longitude = position.coords.longitude; this.longitude = position.coords.longitude;
...@@ -85,6 +93,7 @@ export class NearbyPage implements OnInit { ...@@ -85,6 +93,7 @@ export class NearbyPage implements OnInit {
} }
getAddress(latitude, longitude) { getAddress(latitude, longitude) {
this.geoCoder = new google.maps.Geocoder();
this.geoCoder.geocode( this.geoCoder.geocode(
{ location: { lat: latitude, lng: longitude } }, { location: { lat: latitude, lng: longitude } },
(results, status) => { (results, status) => {
...@@ -96,10 +105,10 @@ export class NearbyPage implements OnInit { ...@@ -96,10 +105,10 @@ export class NearbyPage implements OnInit {
this.address = results[0].formatted_address; this.address = results[0].formatted_address;
console.log(this.address); console.log(this.address);
} else { } else {
window.alert('No results found'); console.log('No results found');
} }
} else { } else {
window.alert('Geocoder failed due to: ' + status); console.log('Geocoder failed due to: ' + status);
} }
} }
); );
...@@ -133,7 +142,7 @@ export class NearbyPage implements OnInit { ...@@ -133,7 +142,7 @@ export class NearbyPage implements OnInit {
setTimeout(() => { setTimeout(() => {
this.loader = false; this.loader = false;
this.successState = false; this.successState = false;
if (this.type === 1) { if (this.authService.regState === false) {
this.router.navigateByUrl('preference', { queryParams: null }); this.router.navigateByUrl('preference', { queryParams: null });
} else { } else {
this.goBack(); this.goBack();
......
<div class="nav_header"> <div class="nav_header">
<button class="nav_btn nav_back floatLeft" (click)="goBack()"> <button class="nav_btn nav_back floatLeft" (click)="goBack()" *ngIf="authService.regState">
<img src="../assets/Group17_2.png" /> <img src="../assets/Group17_2.png" />
</button> </button>
<div class="nav_title floatLeft"> <div class="nav_title floatLeft">
......
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { CategoriesService } from './../../config/category.service'; import { CategoriesService } from './../../config/category.service';
import { ServiceService } from './../../config/service.service'; import { ServiceService } from './../../config/service.service';
import { AuthService } from './../../config/auth.service';
import { Router, ActivatedRoute } from '@angular/router'; import { Router, ActivatedRoute } from '@angular/router';
@Component({ @Component({
...@@ -18,7 +19,8 @@ export class PreferencePage implements OnInit { ...@@ -18,7 +19,8 @@ export class PreferencePage implements OnInit {
constructor( constructor(
private categoriesService: CategoriesService, private categoriesService: CategoriesService,
private service: ServiceService, private service: ServiceService,
private router: Router private router: Router,
private authService: AuthService
) { ) {
this.successState = false; this.successState = false;
this.userPrefence = []; this.userPrefence = [];
...@@ -73,9 +75,11 @@ export class PreferencePage implements OnInit { ...@@ -73,9 +75,11 @@ export class PreferencePage implements OnInit {
this.loader = false; this.loader = false;
this.successState = false; this.successState = false;
this.service.set('type', 0); this.service.set('type', 0);
if (this.type === 1) { if (this.authService.regState === false) {
this.authService.regState = true;
this.router.navigateByUrl('home', { queryParams: null }); this.router.navigateByUrl('home', { queryParams: null });
} else { } else {
this.authService.regState = true;
this.goBack(); this.goBack();
} }
}, 3000); }, 3000);
......
...@@ -151,7 +151,7 @@ export class ProductdetailPage implements OnInit { ...@@ -151,7 +151,7 @@ export class ProductdetailPage implements OnInit {
this.cartService.buyNow(product).then((data) => { this.cartService.buyNow(product).then((data) => {
if (data === true) { if (data === true) {
if (type === 1) { if (type === 1) {
this.router.navigateByUrl('cart'); this.router.navigateByUrl('cart', { replaceUrl: true });
} else { } else {
this.service.showToast('Added into cart', 'top', 'my-toast', 2000); this.service.showToast('Added into cart', 'top', 'my-toast', 2000);
} }
......
<div class="nav_header"> <div class="nav_header">
<button class="nav_btn nav_back floatLeft" (click)="goBack()"> <button class="nav_btn nav_back floatLeft" (click)="goBack()" *ngIf="authService.regState">
<img src="../assets/Group17_2.png" /> <img src="../assets/Group17_2.png" />
</button> </button>
<div class="nav_title floatLeft"> <div class="nav_title floatLeft">
...@@ -15,14 +15,7 @@ ...@@ -15,14 +15,7 @@
<h6>+01 {{authService.userPostData.phone}}</h6> <h6>+01 {{authService.userPostData.phone}}</h6>
</div> </div>
<div class="row"> <div class="row">
<input <input class="" type="number" placeholder="Type OTP" maxlength="4" #otp required />
class=""
type="number"
placeholder="Type OTP"
maxlength="4"
#otp
required
/>
</div> </div>
<div class="row"> <div class="row">
<button class="login_btn" (click)="authService.verify(otp.value)"> <button class="login_btn" (click)="authService.verify(otp.value)">
...@@ -43,4 +36,4 @@ ...@@ -43,4 +36,4 @@
<div></div> <div></div>
</div> </div>
</div> </div>
</ion-content> </ion-content>
\ No newline at end of file
...@@ -135,7 +135,7 @@ export class AddressService { ...@@ -135,7 +135,7 @@ export class AddressService {
.delete(); .delete();
} }
public async getNearBy(centerId, userId) { public async getNearBy(centerId, userId, distance) {
// latitude, longitude, distance, userId // latitude, longitude, distance, userId
console.log(centerId); console.log(centerId);
if (centerId) { if (centerId) {
...@@ -161,7 +161,6 @@ export class AddressService { ...@@ -161,7 +161,6 @@ export class AddressService {
const lat = 0.0144927536231884; const lat = 0.0144927536231884;
const lon = 0.0181818181818182; const lon = 0.0181818181818182;
const distance = 10;
const lowerLat = latitude - lat * distance; const lowerLat = latitude - lat * distance;
const lowerLon = longitude - lon * distance; const lowerLon = longitude - lon * distance;
......
...@@ -51,7 +51,7 @@ export class AuthService { ...@@ -51,7 +51,7 @@ export class AuthService {
this.router.navigateByUrl('home', { replaceUrl: true }); this.router.navigateByUrl('home', { replaceUrl: true });
} else { } else {
this.regState = false; this.regState = false;
this.router.navigateByUrl('verification'); this.router.navigateByUrl('verification', { replaceUrl: true });
} }
} else { } else {
console.log('here too'); console.log('here too');
...@@ -109,7 +109,7 @@ export class AuthService { ...@@ -109,7 +109,7 @@ export class AuthService {
.update({ otp: '', phoneVerified: true }); .update({ otp: '', phoneVerified: true });
this.service.set('type', 1); this.service.set('type', 1);
this.loader = false; this.loader = false;
this.router.navigateByUrl('nearby'); this.router.navigateByUrl('nearby', { replaceUrl: true });
} else { } else {
this.loader = false; this.loader = false;
this.service.showToast( this.service.showToast(
......
...@@ -60,7 +60,7 @@ export class CartsService { ...@@ -60,7 +60,7 @@ export class CartsService {
if (this.cartCenter === '') { if (this.cartCenter === '') {
this.cartCenter = product.centerId; this.cartCenter = product.centerId;
this.addressService.defaultAddress(this.custId); this.addressService.defaultAddress(this.custId);
this.addressService.getNearBy(this.cartCenter, this.custId); this.addressService.getNearBy(this.cartCenter, this.custId, this.service.distance);
} }
const cartRef: AngularFirestoreCollection<any> = this.afs.collection( const cartRef: AngularFirestoreCollection<any> = this.afs.collection(
'carts', 'carts',
...@@ -156,7 +156,7 @@ export class CartsService { ...@@ -156,7 +156,7 @@ export class CartsService {
if (this.cartCenter === '') { if (this.cartCenter === '') {
this.cartCenter = res[0].centerId; this.cartCenter = res[0].centerId;
this.addressService.defaultAddress(this.custId); this.addressService.defaultAddress(this.custId);
this.addressService.getNearBy(this.cartCenter, this.custId); this.addressService.getNearBy(this.cartCenter, this.custId, this.service.distance);
} }
res.forEach(item => { res.forEach(item => {
const cartItem: CartItem = { const cartItem: CartItem = {
......
...@@ -5,6 +5,7 @@ import { ...@@ -5,6 +5,7 @@ import {
AngularFirestoreCollection AngularFirestoreCollection
} from '@angular/fire/firestore'; } from '@angular/fire/firestore';
import { Centers, CenterData } from './services/center'; import { Centers, CenterData } from './services/center';
import { ServiceService } from './service.service';
import * as firebase from 'firebase'; import * as firebase from 'firebase';
@Injectable({ @Injectable({
...@@ -13,9 +14,10 @@ import * as firebase from 'firebase'; ...@@ -13,9 +14,10 @@ import * as firebase from 'firebase';
export class CenterService { export class CenterService {
centers: Centers[] = []; centers: Centers[] = [];
nearcenters: Centers[] = []; nearcenters: Centers[] = [];
constructor(public afs: AngularFirestore) { constructor(public afs: AngularFirestore, public service: ServiceService) {
console.log(this.service.distance);
this.centerList(); this.centerList();
this.getNearBy(10.0159, 76.3419, 10); this.getNearBy(10.0159, 76.3419, this.service.distance);
} }
public async centerList() { public async centerList() {
...@@ -54,6 +56,7 @@ export class CenterService { ...@@ -54,6 +56,7 @@ export class CenterService {
} }
public async getNearBy(latitude, longitude, distance) { public async getNearBy(latitude, longitude, distance) {
console.log(distance);
const This = this; const This = this;
const state = true; const state = true;
......
...@@ -233,7 +233,7 @@ export class MyordersService { ...@@ -233,7 +233,7 @@ export class MyordersService {
const lat = 0.0144927536231884; const lat = 0.0144927536231884;
const lon = 0.0181818181818182; const lon = 0.0181818181818182;
const distance = 10; const distance = this.service.distance;
const lowerLat = latitude - lat * distance; const lowerLat = latitude - lat * distance;
const lowerLon = longitude - lon * distance; const lowerLon = longitude - lon * distance;
......
...@@ -163,11 +163,11 @@ export class OrdersService { ...@@ -163,11 +163,11 @@ export class OrdersService {
const product = cartItem[0]; const product = cartItem[0];
this.custId = this.custId.trim(); this.custId = this.custId.trim();
const orderItem: Order = { const orderItem: Order = {
amount: 'A$ ' + otherCharge.totalAmt, amount: 'A$ ' + otherCharge.totalAmt.toFixed(2),
customer: firebase.firestore().doc('/customer/' + this.custId), customer: firebase.firestore().doc('/customer/' + this.custId),
shopper: product.shopper, shopper: product.shopper,
deliveryAddress: otherCharge.custAddress, deliveryAddress: otherCharge.custAddress,
deliveryCharge: 'A$ ' + otherCharge.deliveryCharge, deliveryCharge: 'A$ ' + otherCharge.deliveryCharge.toFixed(2),
deliveryLocation: otherCharge.custAddress.latLng, deliveryLocation: otherCharge.custAddress.latLng,
bookDate: firebase.firestore.FieldValue.serverTimestamp(), bookDate: firebase.firestore.FieldValue.serverTimestamp(),
orderDate: Math.floor(Date.now() / 1000), orderDate: Math.floor(Date.now() / 1000),
...@@ -195,9 +195,9 @@ export class OrdersService { ...@@ -195,9 +195,9 @@ export class OrdersService {
shopperName: '', shopperName: '',
product: products, product: products,
timeRemain: timer, timeRemain: timer,
discount: 'A$ ' + otherCharge.discount, discount: 'A$ ' + otherCharge.discount.toFixed(2),
promoApplied: otherCharge.discountApplied, promoApplied: otherCharge.discountApplied,
tax: 'A$ ' + otherCharge.taxAmount tax: 'A$ ' + otherCharge.taxAmount.toFixed(2)
}; };
// console.log(orderItem); // console.log(orderItem);
......
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Storage } from '@ionic/storage'; import { Storage } from '@ionic/storage';
import { ToastController } from '@ionic/angular'; import { ToastController } from '@ionic/angular';
import * as firebase from 'firebase';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
}) })
export class ServiceService { export class ServiceService {
state: boolean; state: boolean;
distance: any;
constructor( constructor(
public storage: Storage, public storage: Storage,
public toastController: ToastController public toastController: ToastController
) { ) {
this.state = true; this.state = true;
this.distance = 10;
this.storage.ready().then(() => { this.storage.ready().then(() => {
this.get('user'); this.get('user');
}); });
this.setting().then((data) => {
if (data) {
this.distance = data;
}
}).catch(err => {
this.distance = 10;
});
} }
public set(settingName: string, value: any) { public set(settingName: string, value: any) {
...@@ -80,4 +89,21 @@ export class ServiceService { ...@@ -80,4 +89,21 @@ export class ServiceService {
formatNumber(num: number) { formatNumber(num: number) {
return num.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,') return num.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,')
} }
setting() {
const promise = new Promise(resolve => {
const prodRef = firebase
.firestore()
.collection('setting')
.doc('basic').onSnapshot(doc => {
console.log(doc.data());
if (doc.exists) {
const data = doc.data();
this.distance = data.distance;
resolve(this.distance);
}
});
});
return promise;
}
} }
...@@ -5,6 +5,7 @@ import { ...@@ -5,6 +5,7 @@ import {
AngularFirestoreDocument, AngularFirestoreDocument,
AngularFirestoreCollection AngularFirestoreCollection
} from '@angular/fire/firestore'; } from '@angular/fire/firestore';
import { ServiceService } from './service.service';
import { Shopper } from './services/shopper'; import { Shopper } from './services/shopper';
import * as firebase from 'firebase'; import * as firebase from 'firebase';
...@@ -15,9 +16,9 @@ export class ShoppersService { ...@@ -15,9 +16,9 @@ export class ShoppersService {
shoppers: Shopper[] = []; shoppers: Shopper[] = [];
activeshoppers: Shopper[] = []; activeshoppers: Shopper[] = [];
nearshoppers: Shopper[] = []; nearshoppers: Shopper[] = [];
constructor(public afs: AngularFirestore, public afAuth: AngularFireAuth) { constructor(public afs: AngularFirestore, public afAuth: AngularFireAuth, public service: ServiceService) {
this.featuredshopperList(); this.featuredshopperList();
this.getNearBy(10.0159, 76.3419, 10); this.getNearBy(-33.87276, 151.20534, this.service.distance);
} }
public async shopperList(centerId: any, type: string) { public async shopperList(centerId: any, type: string) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment