| @@ -13,6 +13,7 @@ import { MenuItemService } from './services/menu-item.service'; | |||||
| import { OfferService } from './services/offer.service'; | import { OfferService } from './services/offer.service'; | ||||
| import { OutletService } from './services/outlet.service'; | import { OutletService } from './services/outlet.service'; | ||||
| import { CartItemService } from './services/cart-item.service'; | import { CartItemService } from './services/cart-item.service'; | ||||
| import { UserDataService } from './services/user-data.service'; | |||||
| import { AppComponent } from './app.component'; | import { AppComponent } from './app.component'; | ||||
| import { AppRoutingModule } from './app-routing.module'; | import { AppRoutingModule } from './app-routing.module'; | ||||
| @@ -36,6 +37,7 @@ import { environment } from '../environments/environment'; | |||||
| OfferService, | OfferService, | ||||
| OutletService, | OutletService, | ||||
| CartItemService, | CartItemService, | ||||
| UserDataService, | |||||
| { provide: RouteReuseStrategy, useClass: IonicRouteStrategy } | { provide: RouteReuseStrategy, useClass: IonicRouteStrategy } | ||||
| ], | ], | ||||
| bootstrap: [AppComponent] | bootstrap: [AppComponent] | ||||
| @@ -1,6 +1,6 @@ | |||||
| import MenuItem from './menu-item'; | import MenuItem from './menu-item'; | ||||
| class CartItem { | |||||
| export default class CartItem { | |||||
| menu_item: string; | menu_item: string; | ||||
| quantity: number; | quantity: number; | ||||
| pickup_time: Date; | pickup_time: Date; | ||||
| @@ -52,6 +52,3 @@ export interface ICartItem { | |||||
| take_away: boolean; | take_away: boolean; | ||||
| total_price: number; | total_price: number; | ||||
| } | } | ||||
| export default CartItem; | |||||
| @@ -0,0 +1,10 @@ | |||||
| <div class="tab-utilities-holder"> | |||||
| <h5> MY ORDERS </h5> | |||||
| <ion-button fill="clear"> | |||||
| SORT / FILTER | |||||
| </ion-button> | |||||
| </div> | |||||
| <p> | |||||
| orders works! | |||||
| </p> | |||||
| @@ -0,0 +1,27 @@ | |||||
| import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; | |||||
| import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | |||||
| import { OrdersComponent } from './orders.component'; | |||||
| describe('OrdersComponent', () => { | |||||
| let component: OrdersComponent; | |||||
| let fixture: ComponentFixture<OrdersComponent>; | |||||
| beforeEach(async(() => { | |||||
| TestBed.configureTestingModule({ | |||||
| declarations: [ OrdersComponent ], | |||||
| schemas: [CUSTOM_ELEMENTS_SCHEMA], | |||||
| }) | |||||
| .compileComponents(); | |||||
| })); | |||||
| beforeEach(() => { | |||||
| fixture = TestBed.createComponent(OrdersComponent); | |||||
| component = fixture.componentInstance; | |||||
| fixture.detectChanges(); | |||||
| }); | |||||
| it('should create', () => { | |||||
| expect(component).toBeTruthy(); | |||||
| }); | |||||
| }); | |||||
| @@ -0,0 +1,17 @@ | |||||
| import { Component, OnInit } from '@angular/core'; | |||||
| import { UserDataService } from '../services/user-data.service'; | |||||
| @Component({ | |||||
| selector: 'app-orders', | |||||
| templateUrl: './orders.component.html', | |||||
| styleUrls: ['./orders.component.scss'], | |||||
| }) | |||||
| export class OrdersComponent implements OnInit { | |||||
| constructor( | |||||
| private userDataService: UserDataService | |||||
| ) { } | |||||
| ngOnInit() { } | |||||
| } | |||||
| @@ -7,6 +7,8 @@ import { IonicModule } from '@ionic/angular'; | |||||
| import { ProfilePage } from './profile.page'; | import { ProfilePage } from './profile.page'; | ||||
| import { OrdersComponent } from '../orders/orders.component'; | |||||
| const routes: Routes = [ | const routes: Routes = [ | ||||
| { | { | ||||
| path: '', | path: '', | ||||
| @@ -21,6 +23,6 @@ const routes: Routes = [ | |||||
| IonicModule, | IonicModule, | ||||
| RouterModule.forChild(routes) | RouterModule.forChild(routes) | ||||
| ], | ], | ||||
| declarations: [ProfilePage] | |||||
| declarations: [ProfilePage, OrdersComponent] | |||||
| }) | }) | ||||
| export class ProfilePageModule {} | export class ProfilePageModule {} | ||||
| @@ -50,11 +50,6 @@ | |||||
| </div> | </div> | ||||
| </div> | </div> | ||||
| <div class="tab-utilities-holder"> | |||||
| <h5> {{ selected_tab }} </h5> | |||||
| <ion-button fill="clear"> | |||||
| SORT / FILTER | |||||
| </ion-button> | |||||
| </div> | |||||
| <app-orders *ngIf="selected_tab === 'MY ORDERS'"></app-orders> | |||||
| </ion-content> | </ion-content> | ||||
| @@ -10,7 +10,7 @@ export class ProfilePage implements OnInit { | |||||
| selected_tab: string = 'MY ORDERS'; | selected_tab: string = 'MY ORDERS'; | ||||
| constructor( | constructor( | ||||
| private location: Location | |||||
| private location: Location, | |||||
| ) { } | ) { } | ||||
| ngOnInit() { | ngOnInit() { | ||||
| @@ -0,0 +1,12 @@ | |||||
| import { TestBed } from '@angular/core/testing'; | |||||
| import { UserDataService } from './user-data.service'; | |||||
| describe('UserDataService', () => { | |||||
| beforeEach(() => TestBed.configureTestingModule({})); | |||||
| it('should be created', () => { | |||||
| const service: UserDataService = TestBed.get(UserDataService); | |||||
| expect(service).toBeTruthy(); | |||||
| }); | |||||
| }); | |||||
| @@ -0,0 +1,30 @@ | |||||
| import { Injectable } from '@angular/core'; | |||||
| import CartItem from '../models/cart-item'; | |||||
| import { Storage } from '@ionic/storage'; | |||||
| @Injectable({ | |||||
| providedIn: 'root' | |||||
| }) | |||||
| export class UserDataService { | |||||
| orders: Array<CartItem> = []; | |||||
| constructor( | |||||
| private storage: Storage | |||||
| ) { } | |||||
| async updateUserOrders(orders: Array<CartItem>) { | |||||
| this.orders = orders; | |||||
| this.storage.set('user_orders', JSON.stringify(this.orders)); | |||||
| return await this.orders; | |||||
| } | |||||
| async getAllUserOrders() { | |||||
| return await this.storage.get('user_orders').then((data: string) => { | |||||
| if (data) { | |||||
| return JSON.parse(data); | |||||
| } else { | |||||
| return []; | |||||
| } | |||||
| }); | |||||
| } | |||||
| } | |||||