Ver a proveniência

Added allMalls to LocalStorage

master
prahalad há 4 anos
ascendente
cometimento
a24f21c8e4
4 ficheiros alterados com 86 adições e 16760 eliminações
  1. +46
    -16722
      package-lock.json
  2. +1
    -1
      package.json
  3. +8
    -7
      src/app/cart/cart.page.ts
  4. +31
    -30
      src/app/malls/malls.page.ts

+ 46
- 16722
package-lock.json
A apresentação das diferenças no ficheiro foi suprimida por ser demasiado grande
Ver ficheiro


+ 1
- 1
package.json Ver ficheiro

@@ -91,4 +91,4 @@
"android"
]
}
}
}

+ 8
- 7
src/app/cart/cart.page.ts Ver ficheiro

@@ -65,11 +65,12 @@ export class CartPage implements OnInit {

ionViewDidEnter() {
this.fetchCartItems();
this.mallService.allMalls().then((response) => {
this.allMalls = response;
}, (error) => {
console.log(error);
});
this.allMalls = JSON.parse(localStorage.getItem('malls'))
// this.mallService.allMalls().then((response) => {
// this.allMalls = response;
// }, (error) => {
// console.log(error);
// });
}

fetchCartItems() {
@@ -119,6 +120,7 @@ export class CartPage implements OnInit {

getOutletDetails(cartOutlet: any) {
let mall, outlet;

mall = this.allMalls.find((mall) => {
return mall.mall.mall_id === cartOutlet.mall_id;
});
@@ -279,9 +281,8 @@ export class CartPage implements OnInit {
soft_delete: false,
orderedlist: this.userCart.orderedlist
}).then(() => {
localStorage.removeItem('userCart');
this.toastService.presentToast("Order has been created", "success");
localStorage.removeItem('userCart');
this.router.navigate(['/profile']);
}, () => {
this.toastService.presentToast("Failed to create order!", "danger");


+ 31
- 30
src/app/malls/malls.page.ts Ver ficheiro

@@ -1,4 +1,4 @@
import { Component, OnInit, ViewChild,ElementRef } from '@angular/core';
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';
@@ -32,23 +32,23 @@ export class MallsPage implements OnInit {

async presentLoading() {
this.loader = await this.loadingController.create({
message: 'Please wait...',
spinner: 'dots',
mode: 'ios'
message: 'Please wait...',
spinner: 'dots',
mode: 'ios'
});
await this.loader.present();
}

async presentAlert(message: string) {
const alert = await this.alertController.create({
message: message,
mode: 'ios',
buttons: ['OK']
message: message,
mode: 'ios',
buttons: ['OK']
});
await alert.present();
}
getMallsByFoodType(type: string) {
this.selectedFoodType = type;
this.mallService.mallsByTypes(type).then((response: Array<any>) => {
@@ -81,15 +81,15 @@ export class MallsPage implements OnInit {
}

toggleSearchBar() {
if (this.searchTerm.length > 0) {
this.searchTerm = '';
this.tempMalls = JSON.parse(JSON.stringify(this.allMalls));
} else {
this.showSearchBar = !this.showSearchBar;
setTimeout(()=>{ // this will make the execution after the above boolean has changed
this.searchElement.nativeElement.focus();
}, 1);
}
if (this.searchTerm.length > 0) {
this.searchTerm = '';
this.tempMalls = JSON.parse(JSON.stringify(this.allMalls));
} else {
this.showSearchBar = !this.showSearchBar;
setTimeout(() => { // this will make the execution after the above boolean has changed
this.searchElement.nativeElement.focus();
}, 1);
}
}

searchAllMalls() {
@@ -112,14 +112,14 @@ export class MallsPage implements OnInit {

window.navigator['share'](shareData);
}
}
}

getMallsByLocation() {
if (navigator.geolocation) {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition((position) => {
this.presentLoading();
this.mallService.mallsByLocation(position.coords.latitude, position.coords.longitude).then((response: any) => {
if (response.length > 0) {
if (response.length > 0) {
this.allMalls = response;
this.tempMalls = response;
this.loader ? this.loader.dismiss() : null;
@@ -146,6 +146,7 @@ export class MallsPage implements OnInit {
getAllMalls() {
this.mallService.allMalls().then((response) => {
this.allMalls = response;
localStorage.setItem("malls", JSON.stringify(this.allMalls))
this.tempMalls = response;
this.loader ? this.loader.dismiss() : null;
}, (error) => {
@@ -160,19 +161,19 @@ export class MallsPage implements OnInit {

sortBy(type: string) {
this.selected_sort = type;
switch(this.selected_sort) {
case 'name': this.tempMalls.sort(function(a: any, b: any){
if(a.mall.mall_name < b.mall.mall_name) { return -1; }
if(a.mall.mall_name > b.mall.mall_name) { return 1; }
switch (this.selected_sort) {
case 'name': this.tempMalls.sort(function (a: any, b: any) {
if (a.mall.mall_name < b.mall.mall_name) { return -1; }
if (a.mall.mall_name > b.mall.mall_name) { return 1; }
return 0;
});
break;
case 'rating': this.tempMalls.sort(function(a: any, b: any){
if(a.mall.rating < b.mall.rating) { return -1; }
if(a.mall.rating > b.mall.rating) { return 1; }
break;
case 'rating': this.tempMalls.sort(function (a: any, b: any) {
if (a.mall.rating < b.mall.rating) { return -1; }
if (a.mall.rating > b.mall.rating) { return 1; }
return 0;
}).reverse();
break;
break;
}
}



Carregando…
Cancelar
Guardar