| @@ -26,6 +26,7 @@ import { MoreComponent } from './more/more.component'; | |||||
| // Services | // Services | ||||
| import { AuthService } from './services/auth.service'; | import { AuthService } from './services/auth.service'; | ||||
| import { OrderService } from './services/order.service'; | import { OrderService } from './services/order.service'; | ||||
| import { ItemService } from './services/item.service'; | |||||
| @NgModule({ | @NgModule({ | ||||
| declarations: [ | declarations: [ | ||||
| @@ -51,7 +52,8 @@ import { OrderService } from './services/order.service'; | |||||
| ], | ], | ||||
| providers: [ | providers: [ | ||||
| AuthService, | AuthService, | ||||
| OrderService | |||||
| OrderService, | |||||
| ItemService | |||||
| ], | ], | ||||
| bootstrap: [AppComponent] | bootstrap: [AppComponent] | ||||
| }) | }) | ||||
| @@ -41,7 +41,7 @@ | |||||
| </td> | </td> | ||||
| <td> | <td> | ||||
| <div class="toggle" [ngClass]="{'on' : item.is_available }" | <div class="toggle" [ngClass]="{'on' : item.is_available }" | ||||
| (click)="item.is_available = !item.is_available"> | |||||
| (click)="item.is_available = !item.is_available; updateItem(item)"> | |||||
| <div class="knob"></div> | <div class="knob"></div> | ||||
| </div> | </div> | ||||
| </td> | </td> | ||||
| @@ -1,4 +1,5 @@ | |||||
| import { Component, OnInit } from '@angular/core'; | import { Component, OnInit } from '@angular/core'; | ||||
| import { ItemService } from '../services/item.service'; | |||||
| @Component({ | @Component({ | ||||
| selector: 'app-menu-items', | selector: 'app-menu-items', | ||||
| @@ -12,7 +13,9 @@ export class MenuItemsComponent implements OnInit { | |||||
| searchTerm: string = ''; | searchTerm: string = ''; | ||||
| menuItems: any = []; | menuItems: any = []; | ||||
| constructor() { } | |||||
| constructor( | |||||
| private itemService: ItemService | |||||
| ) { } | |||||
| ngOnInit() { | ngOnInit() { | ||||
| this.profile_type = localStorage.current_login_type; | this.profile_type = localStorage.current_login_type; | ||||
| @@ -24,7 +27,22 @@ export class MenuItemsComponent implements OnInit { | |||||
| } | } | ||||
| this.menuItems = JSON.parse(JSON.stringify(this.profile_info.menuitems)); | this.menuItems = JSON.parse(JSON.stringify(this.profile_info.menuitems)); | ||||
| } | |||||
| updateItem(menuItem) { | |||||
| this.itemService.updateMenuItem(menuItem, this.profile_info.outlet_id).then((data) => { | |||||
| this.profile_info.menuitems = JSON.parse(JSON.stringify(this.menuItems)); | |||||
| if (this.profile_type === 'VENDOR') { | |||||
| localStorage.vendor_info = JSON.stringify(this.profile_info); | |||||
| } else if (this.profile_type === 'OUTLET') { | |||||
| localStorage.outlet_info = JSON.stringify(this.profile_info); | |||||
| } | |||||
| }, (err) => { | |||||
| console.log(err); | |||||
| alert("Failed to update"); | |||||
| }); | |||||
| } | } | ||||
| searchItems() { | searchItems() { | ||||
| @@ -0,0 +1,12 @@ | |||||
| import { TestBed } from '@angular/core/testing'; | |||||
| import { ItemService } from './item.service'; | |||||
| describe('ItemService', () => { | |||||
| beforeEach(() => TestBed.configureTestingModule({})); | |||||
| it('should be created', () => { | |||||
| const service: ItemService = TestBed.get(ItemService); | |||||
| expect(service).toBeTruthy(); | |||||
| }); | |||||
| }); | |||||
| @@ -0,0 +1,27 @@ | |||||
| import { Injectable } from '@angular/core'; | |||||
| import { URL } from '../data/url'; | |||||
| import { HttpClient, HttpHeaders } from '@angular/common/http'; | |||||
| @Injectable({ | |||||
| providedIn: 'root' | |||||
| }) | |||||
| export class ItemService { | |||||
| constructor( | |||||
| private http: HttpClient | |||||
| ) { } | |||||
| updateMenuItem(menuItem: any, outlet_id: string | number) { | |||||
| menuItem.outlet = { | |||||
| outlet_id: outlet_id | |||||
| }; | |||||
| const httpOptions = { | |||||
| headers: new HttpHeaders({ | |||||
| 'Access-Control-Allow-Origin': '*', | |||||
| 'Content-Type': 'application/json', | |||||
| 'Authorization': 'Bearer ' + localStorage.token | |||||
| }) | |||||
| }; | |||||
| return this.http.put(URL + '/api/maioraservice/menuitems/v1/update/', menuItem, httpOptions).toPromise(); | |||||
| } | |||||
| } | |||||