Delete item in order funcionality active
This commit is contained in:
parent
cbac13b373
commit
b8ebfa07d7
9 changed files with 200 additions and 33 deletions
|
@ -35,17 +35,15 @@ p.price{
|
||||||
text-align: right;
|
text-align: right;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Style buttons */
|
.buttons-class-cart{
|
||||||
.btn {
|
background-color: #ff4700;
|
||||||
background-color: DodgerBlue; /* Blue background */
|
color: white;
|
||||||
border: none; /* Remove borders */
|
font-size: 18px;
|
||||||
color: white; /* White text */
|
font-weight: 700;
|
||||||
padding: 12px 16px; /* Some padding */
|
height: 25px !important;
|
||||||
font-size: 16px; /* Set a font size */
|
width: 50px !important;
|
||||||
cursor: pointer; /* Mouse pointer on hover */
|
display: flex;
|
||||||
}
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
/* Darker background on mouse-over */
|
cursor: pointer;
|
||||||
.btn:hover {
|
|
||||||
background-color: RoyalBlue;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,8 +49,10 @@
|
||||||
</fa-icon>
|
</fa-icon>
|
||||||
</button>
|
</button>
|
||||||
-->
|
-->
|
||||||
<button mat-raised-button color="primary" class="icons" (click)="addToOrder(item._id!)">
|
<button mat-raised-button color="primary"
|
||||||
<mat-icon>shopping_cart</mat-icon>
|
class="buttons-class-cart"
|
||||||
|
(click)="addToOrder(item._id!)">
|
||||||
|
<mat-icon [inline]="true">shopping_cart</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -61,5 +63,9 @@
|
||||||
</div>
|
</div>
|
||||||
<p *ngIf = "items.length <= 0">No items yet!</p>
|
<p *ngIf = "items.length <= 0">No items yet!</p>
|
||||||
<br>
|
<br>
|
||||||
<button class="text" mat-raised-button (click)="openDialog()">
|
<button class="text"
|
||||||
<mat-icon class="icon">add</mat-icon>Add item</button>
|
mat-raised-button
|
||||||
|
(click)="openDialog()">
|
||||||
|
<mat-icon class="icon">add</mat-icon>
|
||||||
|
Add item
|
||||||
|
</button>
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
import { Component, OnInit, Input } from '@angular/core';
|
import { Component, OnInit, Input } from '@angular/core';
|
||||||
import { MatDialog, MatDialogConfig} from '@angular/material/dialog';
|
import { MatDialog, MatDialogConfig} from '@angular/material/dialog';
|
||||||
|
|
||||||
|
import { faCartShopping } from '@fortawesome/free-solid-svg-icons';
|
||||||
|
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
import { Item } from '../item.model';
|
import { Item } from '../item.model';
|
||||||
import { Owner } from '../../owner.model';
|
import { Owner } from '../../owner.model';
|
||||||
|
@ -20,10 +23,12 @@ import { ItemAddComponent } from '../item-add/item-add.component';
|
||||||
|
|
||||||
export class ItemListComponent implements OnInit{
|
export class ItemListComponent implements OnInit{
|
||||||
|
|
||||||
@Input()
|
@Input() zecPrice: number = 1;
|
||||||
zecPrice: number = 1;
|
|
||||||
|
|
||||||
public items: Item[] = [];
|
public items: Item[] = [];
|
||||||
|
|
||||||
|
faCartShopping = faCartShopping;
|
||||||
|
|
||||||
owner: Owner = {
|
owner: Owner = {
|
||||||
_id: '',
|
_id: '',
|
||||||
name: '',
|
name: '',
|
||||||
|
@ -49,6 +54,7 @@ export class ItemListComponent implements OnInit{
|
||||||
expiration: new Date(Date.now()).toISOString(),
|
expiration: new Date(Date.now()).toISOString(),
|
||||||
viewkey: ''
|
viewkey: ''
|
||||||
};
|
};
|
||||||
|
|
||||||
public ownerUpdate: Observable<Owner>;
|
public ownerUpdate: Observable<Owner>;
|
||||||
public itemsUpdate: Observable<Item[]>;
|
public itemsUpdate: Observable<Item[]>;
|
||||||
|
|
||||||
|
|
6
src/app/items/newlineitem.model.ts
Normal file
6
src/app/items/newlineitem.model.ts
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
export interface newLineItem {
|
||||||
|
line_id: number;
|
||||||
|
qty: number;
|
||||||
|
name: string;
|
||||||
|
cost: number;
|
||||||
|
}
|
|
@ -82,7 +82,7 @@
|
||||||
>1.0 = {{ order.price | currency: order.currency.toUpperCase()}}
|
>1.0 = {{ order.price | currency: order.currency.toUpperCase()}}
|
||||||
</td>
|
</td>
|
||||||
<td width="50%" align="right">
|
<td width="50%" align="right">
|
||||||
{{ order.total | number: '1.02' | currency: order.currency.toUpperCase()}}
|
{{ order.total | currency: order.currency.toUpperCase()}}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
|
@ -49,3 +49,26 @@ img.icon{
|
||||||
cursor: pointer;
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -51,7 +51,8 @@
|
||||||
</thead>
|
</thead>
|
||||||
|
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr *ngFor="let item of order.lines">
|
<tr style="height: 30px;"
|
||||||
|
*ngFor="let item of oLines">
|
||||||
<td class="newOrdertbdetail"
|
<td class="newOrdertbdetail"
|
||||||
style="text-align: left;"
|
style="text-align: left;"
|
||||||
width="50%">{{item.name}}
|
width="50%">{{item.name}}
|
||||||
|
@ -65,10 +66,10 @@
|
||||||
width="30%">{{item.qty * item.cost | number:'1.02' | currency: getCurrency() }}
|
width="30%">{{item.qty * item.cost | number:'1.02' | currency: getCurrency() }}
|
||||||
</td>
|
</td>
|
||||||
<td class="lineTrashCan">
|
<td class="lineTrashCan">
|
||||||
<a (click)='trashCanClicked(item,order.lines)' >
|
<a (click)='trashCanClicked(item,oLines)' >
|
||||||
<fa-icon [icon]="faTrashAlt"
|
<fa-icon [icon]="faTrashAlt"
|
||||||
style="color: lightslategrey;
|
style="color: lightslategrey;
|
||||||
font-size: 16px;
|
font-size: 14px;
|
||||||
margin: auto;">
|
margin: auto;">
|
||||||
</fa-icon>
|
</fa-icon>
|
||||||
</a>
|
</a>
|
||||||
|
@ -77,21 +78,50 @@
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="container" style="margin: 2px;
|
||||||
|
height: 35px;
|
||||||
|
background: lightblue;
|
||||||
|
border-top: 2px solid lightgray;
|
||||||
|
border-bottom: 2px solid lightgray;
|
||||||
|
align-content: center;
|
||||||
|
justify-content: center;">
|
||||||
|
<!--
|
||||||
<mat-card-actions>
|
<mat-card-actions>
|
||||||
<table cellspacing="0" width="100%">
|
-->
|
||||||
<tr>
|
<table style="margin-top: 4px;" cellspacing="0" width="100%">
|
||||||
|
<tr style="height: 16px;
|
||||||
|
margin-top: 10px">
|
||||||
<td>
|
<td>
|
||||||
<button mat-raised-button class="text" (click)="cancelOrder()">Cancel</button>
|
<button mat-raised-button
|
||||||
|
class="button-cancel-class"
|
||||||
|
(click)="cancelOrder()">
|
||||||
|
Cancel
|
||||||
|
</button>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<button mat-raised-button class="text" (click)="invoice()"><fa-icon [icon]="faInvoice" size="2x"></fa-icon> Invoice</button>
|
<button mat-raised-button
|
||||||
|
class="buttons-class"
|
||||||
|
(click)="invoice()">
|
||||||
|
<fa-icon [icon]="faInvoice" ></fa-icon> Invoice
|
||||||
|
</button>
|
||||||
</td>
|
</td>
|
||||||
<td align="right">
|
<td align="right">
|
||||||
|
|
||||||
|
<button mat-raised-button
|
||||||
|
class="buttons-class"
|
||||||
|
(click)="checkout()">
|
||||||
|
Checkout
|
||||||
|
</button>
|
||||||
|
<!--
|
||||||
<button mat-raised-button class="text" color="primary" (click)="checkout()">Checkout</button>
|
<button mat-raised-button class="text" color="primary" (click)="checkout()">Checkout</button>
|
||||||
|
-->
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
<!--
|
||||||
</mat-card-actions>
|
</mat-card-actions>
|
||||||
|
-->
|
||||||
|
</div>
|
||||||
</mat-card>
|
</mat-card>
|
||||||
<div style="font-family: Roboto Mono;
|
<div style="font-family: Roboto Mono;
|
||||||
font-size: 18px;
|
font-size: 18px;
|
||||||
|
|
|
@ -2,6 +2,7 @@ import { Component, OnInit } from '@angular/core';
|
||||||
import { MatDialog, MatDialogConfig} from '@angular/material/dialog';
|
import { MatDialog, MatDialogConfig} from '@angular/material/dialog';
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
import { LineItem } from '../items/lineitem.model';
|
import { LineItem } from '../items/lineitem.model';
|
||||||
|
import { newLineItem } from '../items/newlineitem.model';
|
||||||
import { Order } from './order.model';
|
import { Order } from './order.model';
|
||||||
import { FullnodeService } from '../fullnode.service';
|
import { FullnodeService } from '../fullnode.service';
|
||||||
import { OrderService } from './order.service';
|
import { OrderService } from './order.service';
|
||||||
|
@ -13,6 +14,8 @@ import { faFileInvoiceDollar } from '@fortawesome/free-solid-svg-icons';
|
||||||
|
|
||||||
import { faTrash } from '@fortawesome/free-solid-svg-icons';
|
import { faTrash } from '@fortawesome/free-solid-svg-icons';
|
||||||
import { faTrashAlt } from '@fortawesome/free-solid-svg-icons';
|
import { faTrashAlt } from '@fortawesome/free-solid-svg-icons';
|
||||||
|
import { faChevronRight } from '@fortawesome/free-solid-svg-icons';
|
||||||
|
import { faSignOut } from '@fortawesome/free-solid-svg-icons';
|
||||||
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
|
@ -22,6 +25,10 @@ import { faTrashAlt } from '@fortawesome/free-solid-svg-icons';
|
||||||
})
|
})
|
||||||
|
|
||||||
export class OrderComponent implements OnInit{
|
export class OrderComponent implements OnInit{
|
||||||
|
|
||||||
|
public oLines : newLineItem[] = [];
|
||||||
|
public myLines : LineItem[] = [];
|
||||||
|
|
||||||
faInvoice = faFileInvoiceDollar;
|
faInvoice = faFileInvoiceDollar;
|
||||||
public order: Order = {
|
public order: Order = {
|
||||||
address: '',
|
address: '',
|
||||||
|
@ -51,10 +58,11 @@ export class OrderComponent implements OnInit{
|
||||||
//
|
//
|
||||||
faTrash = faTrash;
|
faTrash = faTrash;
|
||||||
faTrashAlt = faTrashAlt;
|
faTrashAlt = faTrashAlt;
|
||||||
|
faChevronRight = faChevronRight;
|
||||||
|
faSignOut = faSignOut;
|
||||||
// -------------------------------------
|
// -------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public fullnodeService: FullnodeService,
|
public fullnodeService: FullnodeService,
|
||||||
public orderService: OrderService,
|
public orderService: OrderService,
|
||||||
|
@ -67,11 +75,32 @@ export class OrderComponent implements OnInit{
|
||||||
this.orderUpdate = orderService.orderUpdate;
|
this.orderUpdate = orderService.orderUpdate;
|
||||||
this.orderUpdate.subscribe((order) => {
|
this.orderUpdate.subscribe((order) => {
|
||||||
this.order = order;
|
this.order = order;
|
||||||
|
// ------------------------------------------------
|
||||||
|
this.oLines = [];
|
||||||
|
this.myLines = this.order.lines;
|
||||||
|
var nl = {} as newLineItem;
|
||||||
|
|
||||||
|
for ( let i = 0; i < this.myLines.length; i++ )
|
||||||
|
{
|
||||||
|
// console.log("Loop : " + i + " - name : " + this.myLines[i].name);
|
||||||
|
nl = this.fillLineData(i,this.myLines[i].name,
|
||||||
|
this.myLines[i].qty,
|
||||||
|
this.myLines[i].cost) ;
|
||||||
|
// console.log(">> 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 = orderService.totalUpdate;
|
||||||
this.totalUpdate.subscribe((total) => {
|
this.totalUpdate.subscribe((total) => {
|
||||||
this.total = total;
|
this.total = total;
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
|
@ -95,6 +124,7 @@ export class OrderComponent implements OnInit{
|
||||||
console.log('Returning to page');
|
console.log('Returning to page');
|
||||||
}
|
}
|
||||||
this.orderService.getOrder();
|
this.orderService.getOrder();
|
||||||
|
this.oLines = [];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,6 +156,7 @@ export class OrderComponent implements OnInit{
|
||||||
dialogRef2.afterClosed().subscribe( val => {
|
dialogRef2.afterClosed().subscribe( val => {
|
||||||
if (val) {
|
if (val) {
|
||||||
console.log('Receipt closed.');
|
console.log('Receipt closed.');
|
||||||
|
this.oLines = [];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
@ -149,6 +180,7 @@ export class OrderComponent implements OnInit{
|
||||||
dialogRef.afterClosed().subscribe((val) => {
|
dialogRef.afterClosed().subscribe((val) => {
|
||||||
if (val) {
|
if (val) {
|
||||||
this.orderService.closeOrder(false);
|
this.orderService.closeOrder(false);
|
||||||
|
this.oLines = [];
|
||||||
} else {
|
} else {
|
||||||
console.log('Returning to order');
|
console.log('Returning to order');
|
||||||
}
|
}
|
||||||
|
@ -159,8 +191,43 @@ export class OrderComponent implements OnInit{
|
||||||
return this.order.currency.toUpperCase();
|
return this.order.currency.toUpperCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
trashCanClicked(item : LineItem, lines: LineItem[]) {
|
|
||||||
console.log(item);
|
fillLineData(i: number,
|
||||||
console.log(lines);
|
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');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import { FullnodeService } from '../fullnode.service';
|
||||||
import { User } from '../user.model';
|
import { User } from '../user.model';
|
||||||
import { Owner } from '../owner.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';
|
import { ConfigData } from '../configdata';
|
||||||
|
|
||||||
|
@ -234,4 +235,34 @@ export class OrderService {
|
||||||
return obs;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue