From b8ebfa07d776d5bd09aa64d2bb342e084de76765 Mon Sep 17 00:00:00 2001 From: Rene Vergara A Date: Sun, 17 Jul 2022 19:46:56 -0500 Subject: [PATCH] Delete item in order funcionality active --- .../items/item-list/item-list.component.css | 24 +++--- .../items/item-list/item-list.component.html | 14 +++- .../items/item-list/item-list.component.ts | 10 ++- src/app/items/newlineitem.model.ts | 6 ++ src/app/listorders/listorders.component.html | 2 +- src/app/order/order.component.css | 23 ++++++ src/app/order/order.component.html | 46 ++++++++++-- src/app/order/order.component.ts | 75 ++++++++++++++++++- src/app/order/order.service.ts | 33 +++++++- 9 files changed, 200 insertions(+), 33 deletions(-) create mode 100644 src/app/items/newlineitem.model.ts diff --git a/src/app/items/item-list/item-list.component.css b/src/app/items/item-list/item-list.component.css index 1a8e670..652f03a 100644 --- a/src/app/items/item-list/item-list.component.css +++ b/src/app/items/item-list/item-list.component.css @@ -35,17 +35,15 @@ p.price{ text-align: right; } - /* Style buttons */ -.btn { - background-color: DodgerBlue; /* Blue background */ - border: none; /* Remove borders */ - color: white; /* White text */ - padding: 12px 16px; /* Some padding */ - font-size: 16px; /* Set a font size */ - cursor: pointer; /* Mouse pointer on hover */ -} - -/* Darker background on mouse-over */ -.btn:hover { - background-color: RoyalBlue; +.buttons-class-cart{ + background-color: #ff4700; + color: white; + font-size: 18px; + font-weight: 700; + height: 25px !important; + width: 50px !important; + display: flex; + align-items: center; + justify-content: center; + cursor: pointer; } diff --git a/src/app/items/item-list/item-list.component.html b/src/app/items/item-list/item-list.component.html index f88eb92..a693018 100644 --- a/src/app/items/item-list/item-list.component.html +++ b/src/app/items/item-list/item-list.component.html @@ -49,8 +49,10 @@ --> - @@ -61,5 +63,9 @@

No items yet!


- + diff --git a/src/app/items/item-list/item-list.component.ts b/src/app/items/item-list/item-list.component.ts index edc7136..52a640e 100644 --- a/src/app/items/item-list/item-list.component.ts +++ b/src/app/items/item-list/item-list.component.ts @@ -1,5 +1,8 @@ import { Component, OnInit, Input } from '@angular/core'; import { MatDialog, MatDialogConfig} from '@angular/material/dialog'; + +import { faCartShopping } from '@fortawesome/free-solid-svg-icons'; + import { Observable } from 'rxjs'; import { Item } from '../item.model'; import { Owner } from '../../owner.model'; @@ -20,10 +23,12 @@ import { ItemAddComponent } from '../item-add/item-add.component'; export class ItemListComponent implements OnInit{ - @Input() - zecPrice: number = 1; + @Input() zecPrice: number = 1; public items: Item[] = []; + + faCartShopping = faCartShopping; + owner: Owner = { _id: '', name: '', @@ -49,6 +54,7 @@ export class ItemListComponent implements OnInit{ expiration: new Date(Date.now()).toISOString(), viewkey: '' }; + public ownerUpdate: Observable; public itemsUpdate: Observable; diff --git a/src/app/items/newlineitem.model.ts b/src/app/items/newlineitem.model.ts new file mode 100644 index 0000000..88c7a56 --- /dev/null +++ b/src/app/items/newlineitem.model.ts @@ -0,0 +1,6 @@ +export interface newLineItem { + line_id: number; + qty: number; + name: string; + cost: number; +} diff --git a/src/app/listorders/listorders.component.html b/src/app/listorders/listorders.component.html index d9676bb..45c191b 100644 --- a/src/app/listorders/listorders.component.html +++ b/src/app/listorders/listorders.component.html @@ -82,7 +82,7 @@ >1.0 = {{ order.price | currency: order.currency.toUpperCase()}} - {{ order.total | number: '1.02' | currency: order.currency.toUpperCase()}} + {{ order.total | currency: order.currency.toUpperCase()}} diff --git a/src/app/order/order.component.css b/src/app/order/order.component.css index 3e881d4..b27ca21 100644 --- a/src/app/order/order.component.css +++ b/src/app/order/order.component.css @@ -49,3 +49,26 @@ img.icon{ cursor: pointer; } +.buttons-class { + background-color: #ff4700; + color: white; + font-weight: 700; + height: 25px !important; + width: 80px !important; + display: flex; + align-items: center; + justify-content: center; + cursor: pointer; + margin: auto; +} + +.button-cancel-class { + font-weight: 700; + height: 25px !important; + width: 80px !important; + display: flex; + align-items: center; + justify-content: center; + cursor: pointer; + margin: auto; +} diff --git a/src/app/order/order.component.html b/src/app/order/order.component.html index 7be2b7f..81a5401 100644 --- a/src/app/order/order.component.html +++ b/src/app/order/order.component.html @@ -51,7 +51,8 @@ - + {{item.name}} @@ -65,10 +66,10 @@ width="30%">{{item.qty * item.cost | number:'1.02' | currency: getCurrency() }} - + @@ -77,21 +78,50 @@ +
+ + + -
- + - + + + + +
+ +
> line_id: " + nl.line_id + +// " name: " + nl.name + +// " qty: " + nl.qty + +// " cost: " + nl.cost + " <<" +// ) + this.oLines.push(nl); + // this.oLines[i].cost = this.myLines[i].cost; + } +// ------------------------------------------------ }); this.totalUpdate = orderService.totalUpdate; this.totalUpdate.subscribe((total) => { this.total = total; }); + } ngOnInit() { @@ -95,6 +124,7 @@ export class OrderComponent implements OnInit{ console.log('Returning to page'); } this.orderService.getOrder(); + this.oLines = []; }); } @@ -126,6 +156,7 @@ export class OrderComponent implements OnInit{ dialogRef2.afterClosed().subscribe( val => { if (val) { console.log('Receipt closed.'); + this.oLines = []; } }); } else { @@ -149,6 +180,7 @@ export class OrderComponent implements OnInit{ dialogRef.afterClosed().subscribe((val) => { if (val) { this.orderService.closeOrder(false); + this.oLines = []; } else { console.log('Returning to order'); } @@ -159,8 +191,43 @@ export class OrderComponent implements OnInit{ return this.order.currency.toUpperCase(); } - trashCanClicked(item : LineItem, lines: LineItem[]) { - console.log(item); - console.log(lines); + + fillLineData(i: number, + iname: string, + iqty: number, + icost: number) : newLineItem { + + const a = { line_id: i, + name: iname, + qty: iqty, + cost: icost } as newLineItem; + return a; + } + + trashCanClicked(item : newLineItem, lines: newLineItem[]) { + + const dialogConfig = new MatDialogConfig(); + + dialogConfig.disableClose = true; + dialogConfig.autoFocus = true; + dialogConfig.data = {title: 'Remove Item?', + msg: 'Are you sure you want to remove <<' + + item.name + ' x ' + item.qty + + '>> from this order?'}; + const dialogRef = this.dialog.open(CancelComponent, dialogConfig); + dialogRef.afterClosed().subscribe((val) => { + if (val) { +// console.log('Deleting item at line: ' +// + (item.line_id +1) +// + " => (" + item.name +")"); + this.orderService.updateOrder(item.line_id,lines); + this.orderService.getOrder(); + + } else { + console.log('Returning to order'); + } + }); + + } } diff --git a/src/app/order/order.service.ts b/src/app/order/order.service.ts index ab6cda3..5caf6a1 100644 --- a/src/app/order/order.service.ts +++ b/src/app/order/order.service.ts @@ -6,7 +6,8 @@ import { UserService } from '../user.service'; import { FullnodeService } from '../fullnode.service'; import { User } from '../user.model'; import { Owner } from '../owner.model'; -import { LineItem} from '../items/lineitem.model'; +import { LineItem } from '../items/lineitem.model'; +import { newLineItem } from '../items/newlineitem.model'; import { ConfigData } from '../configdata'; @@ -234,4 +235,34 @@ export class OrderService { return obs; } + updateOrder(itemid: number, iLines : newLineItem[]) { + if(this.dataStore.order._id != null) { + + var item = {} as LineItem; + this.dataStore.order.lines = []; + for ( let i = 0; i < iLines.length; i++) + { + if ( i !== itemid ) + { + item = this.fillItemData(iLines[i].name, iLines[i].qty, iLines[i].cost); +// console.log("Push => ", item); + this.dataStore.order.lines.push(item); + } + } + let obs = this.http.post(this.beUrl+'api/order', { payload: this.dataStore.order }, { headers: this.reqHeaders }); + obs.subscribe((orderData) => { + this.getOrder(); + }); + } + } + + fillItemData(iname:string, iqty: number, icost: number) : LineItem { + + const a = { name: iname, + qty: iqty, + cost: icost } as LineItem; + return a; + } + + }