Items Create/Edit Forms updated

This commit is contained in:
Rene V. Vergara A. 2022-07-26 20:37:14 -05:00
parent 1e14ab0c5a
commit fd1cb67f5d
15 changed files with 331 additions and 122 deletions

View file

@ -25,6 +25,7 @@ import { ViewerComponent } from './viewer/viewer.component';
import { LoginComponent } from './login/login.component'; import { LoginComponent } from './login/login.component';
import { ItemListComponent } from './items/item-list/item-list.component'; import { ItemListComponent } from './items/item-list/item-list.component';
import { ItemCreateComponent } from './items/item-create/item-create.component'; import { ItemCreateComponent } from './items/item-create/item-create.component';
import { ItemEditComponent } from './items/item-edit/item-edit.component';
import { ItemDeleteComponent } from './items/item-delete/item-delete.component'; import { ItemDeleteComponent } from './items/item-delete/item-delete.component';
import { ItemAddComponent} from './items/item-add/item-add.component'; import { ItemAddComponent} from './items/item-add/item-add.component';
import { OrderComponent } from './order/order.component'; import { OrderComponent } from './order/order.component';
@ -54,6 +55,7 @@ import { NotifierComponent } from './notifier/notifier.component';
LoginComponent, LoginComponent,
OrderComponent, OrderComponent,
ItemCreateComponent, ItemCreateComponent,
ItemEditComponent,
ItemDeleteComponent, ItemDeleteComponent,
ItemAddComponent, ItemAddComponent,
CancelComponent, CancelComponent,

View file

@ -5,3 +5,12 @@
input[type=number]{ input[type=number]{
text-align: right; text-align: right;
} }
.itemDataTitle {
font-family: 'Spartan', sans-serif;
background: #ff5722;
color: white;
font-size: 26px;
text-align: center;
padding: 5px;
}

View file

@ -1,13 +1,21 @@
<h2 mat-dialog-title class="text">Add to Order</h2> <div class='itemDataTitle'>Add to Order</div>
<div class='container'>
<mat-dialog-content [formGroup]="orderForm"> <mat-dialog-content [formGroup]="orderForm">
<p class="text">{{lineItem.name}}</p> <p class="text">{{lineItem.name}}</p>
<mat-form-field> <mat-form-field [style.width.%]="100">
<input matInput type="number" placeholder="Quantity" formControlName="qty"> <input matInput type="number" placeholder="Quantity" formControlName="qty">
</mat-form-field> </mat-form-field>
</mat-dialog-content> </mat-dialog-content>
<mat-dialog-actions> <div style="display: flex;
<button mat-raised-button class="text" (click)="close()">Cancel</button> justify-content: space-between;">
<button mat-raised-button class="text" color="primary" (click)="save()">Add</button> <button mat-raised-button
</mat-dialog-actions> class="text"
(click)="close()">Cancel</button>
<button mat-raised-button
class="text"
color="primary"
(click)="save()">Add</button>
</div>
</div>

View file

@ -5,3 +5,12 @@
input[type=number]{ input[type=number]{
text-align: right; text-align: right;
} }
.itemDataTitle {
font-family: 'Spartan', sans-serif;
background: #ff5722;
color: white;
font-size: 26px;
text-align: center;
padding: 5px;
}

View file

@ -1,16 +1,27 @@
<h2 mat-dialog-title class="text">Add item</h2>
<div class='itemDataTitle'>Add Item</div>
<div class='container' style="margin-top: 20px;">
<mat-dialog-content [formGroup]="form"> <mat-dialog-content [formGroup]="form">
<mat-form-field class="text" appearance="outline"> <span style="line-height: 10px;"></span>
<mat-form-field class="text" [style.width.%]="100">
<mat-label>Item</mat-label> <mat-label>Item</mat-label>
<input type="hidden" formControlName="id"> <input type="hidden" formControlName="id">
<input matInput placeholder="Item" formControlName="name"> <input matInput
placeholder="Item"
formControlName="name"
maxlength="16">
</mat-form-field > </mat-form-field >
<mat-form-field class="text" appearance="outline"> <mat-form-field class="text" [style.width.%]="100">
<mat-label>Description</mat-label> <mat-label>Description</mat-label>
<textarea matInput placeholder="Description" formControlName="description"></textarea> <textarea matInput
placeholder="Description"
formControlName="description"
maxlength="30"
style="line-height:20px;
overflow:auto;"></textarea>
</mat-form-field> </mat-form-field>
<mat-form-field class="text" appearance="outline"> <mat-form-field class="text" [style.width.%]="100">
<mat-label>Price</mat-label> <mat-label>Price</mat-label>
<input matInput type="number" placeholder="Price" formControlName="cost"> <input matInput type="number" placeholder="Price" formControlName="cost">
<div *ngIf="!form.controls['cost'].valid && form.controls['cost'].touched"> <div *ngIf="!form.controls['cost'].valid && form.controls['cost'].touched">
@ -19,7 +30,10 @@
</mat-form-field> </mat-form-field>
</mat-dialog-content> </mat-dialog-content>
<mat-dialog-actions> <div style="display: flex;
justify-content: space-between;">
<button mat-raised-button class="text" (click)="close()">Close</button> <button mat-raised-button class="text" (click)="close()">Close</button>
<button mat-raised-button class="text" color="primary" (click)="save()">Save</button> <button mat-raised-button class="text" color="primary" (click)="save()">Save</button>
</mat-dialog-actions> </div>
</div>

View file

@ -0,0 +1,16 @@
.text {
font-family: 'Spartan', sans-serif;
}
input[type=number]{
text-align: right;
}
.itemDataTitle {
font-family: 'Spartan', sans-serif;
background: #ff5722;
color: white;
font-size: 26px;
text-align: center;
padding: 5px;
}

View file

@ -0,0 +1,39 @@
<div class='itemDataTitle'>Edit Item</div>
<div class='container' style="margin-top: 20px;">
<mat-dialog-content [formGroup]="form">
<span style="line-height: 10px;"></span>
<mat-form-field class="text" [style.width.%]="100">
<mat-label>Item</mat-label>
<input type="hidden" formControlName="id">
<input matInput
placeholder="Item"
formControlName="name"
maxlength="16">
</mat-form-field >
<mat-form-field class="text" [style.width.%]="100">
<mat-label>Description</mat-label>
<textarea matInput
placeholder="Description"
formControlName="description"
maxlength="30"
style="line-height:20px;
overflow:auto;"></textarea>
</mat-form-field>
<mat-form-field class="text" [style.width.%]="100">
<mat-label>Price</mat-label>
<input matInput type="number" placeholder="Price" formControlName="cost">
<div *ngIf="!form.controls['cost'].valid && form.controls['cost'].touched">
<div *ngIf="form.controls['cost'].errors?.pattern">Use only numbers</div>
</div>
</mat-form-field>
</mat-dialog-content>
<div style="display: flex;
justify-content: space-between;">
<button mat-raised-button class="text" (click)="close()">Close</button>
<button mat-raised-button class="text" color="primary" (click)="save()">Save</button>
</div>
</div>

View file

@ -0,0 +1,59 @@
import { Inject, Component, OnInit, OnDestroy, ViewEncapsulation } from '@angular/core';
import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { UntypedFormBuilder, Validators, UntypedFormGroup, UntypedFormControl } from '@angular/forms';
import { Item } from '../item.model';
@Component({
selector: 'app-item-edit',
templateUrl: './item-edit.component.html',
styleUrls: ['./item-edit.component.css']
})
export class ItemEditComponent implements OnInit {
form: UntypedFormGroup;
id: string | undefined = '';
numberRegEx = /\d*\.?\d{1,2}/;
constructor(
private fb: UntypedFormBuilder,
private dialogRef: MatDialogRef<ItemEditComponent>,
@Inject(MAT_DIALOG_DATA) public data: Item
){
if (data._id === '') {
this.form = fb.group({
id: [''],
name: [null, Validators.required],
description: [null, Validators.required],
cost: new UntypedFormControl('', {
validators: [Validators.required, Validators.pattern(this.numberRegEx)],
updateOn: "blur"
})
});
} else {
this.id = data._id;
this.form = fb.group({
id: [data._id],
name: [data.name, Validators.required],
description: [data.description, Validators.required],
cost: new UntypedFormControl(data.cost, {
validators: [Validators.required, Validators.pattern(this.numberRegEx)],
updateOn: "blur"
})
});
}
}
ngOnInit () {
}
save() {
// console.log(this.form.value);
this.dialogRef.close(this.form.value);
}
close () {
this.dialogRef.close();
}
}

View file

@ -35,12 +35,26 @@ p.price{
text-align: right; text-align: right;
} }
.buttons-class {
background-color: #ff5722;
color: white;
font-family: 'Spartan', sans-serif;
font-size: 12px !important;
font-weight: 700;
height: 25px !important;
width: 100px !important;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
}
.buttons-class-cart{ .buttons-class-cart{
background-color: #ff5722; background-color: #ff5722;
color: white; color: white;
font-size: 18px; font-size: 18px;
font-weight: 700; font-weight: 700;
height: 25px !important; height:30px !important;
width: 50px !important; width: 50px !important;
display: flex; display: flex;
align-items: center; align-items: center;
@ -49,10 +63,14 @@ p.price{
} }
.availableItems{ .availableItems{
display: flex;
justify-content: space-between;
background: lightblue; background: lightblue;
font-family: Roboto Mono; font-family: 'Spartan', sans-serif !important;
font-size: 18px; font-size: 18px;
font-weight: 700; font-weight: 700;
text-align: left; text-align: left;
margin: 5px; margin: 5px;
height: 25px;
padding: 12px;
} }

View file

@ -1,7 +1,19 @@
<div *ngIf="items.length > 0"> <div *ngIf="items.length > 0">
<div class="availableItems" > <div class="availableItems" >
Available Items: Available Items:
<button mat-raised-button
class="buttons-class"
(click)="openDialog()">
<mat-icon class="icon">
add
</mat-icon>
Add item
</button>
</div> </div>
<div style="display: block;
overflow-y: auto;
height: 500px;">
<div class="card" *ngFor="let item of itemsUpdate | async"> <div class="card" *ngFor="let item of itemsUpdate | async">
<mat-card> <mat-card>
<table cellspacing="0" width="100%" > <table cellspacing="0" width="100%" >
@ -64,13 +76,18 @@
</mat-card> </mat-card>
</div> </div>
</div> </div>
<p *ngIf = "items.length <= 0">No items yet!</p> </div>
<br> <div *ngIf = "items.length <= 0">
<button class="text" <div class="availableItems" >
mat-raised-button No items yet!
<button mat-raised-button
class="buttons-class"
(click)="openDialog()"> (click)="openDialog()">
<mat-icon class="icon"> <mat-icon class="icon">
add add
</mat-icon> </mat-icon>
Add item Add item
</button> </button>
</div>
</div>
<br>

View file

@ -1,4 +1,4 @@
import { Component, OnInit, Input } from '@angular/core'; import { Input, Inject, Component, OnInit } 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 { faCartShopping } from '@fortawesome/free-solid-svg-icons';
@ -11,9 +11,10 @@ import { UserService } from '../../user.service';
import { ItemService } from '../items.service'; import { ItemService } from '../items.service';
import { OrderService} from '../../order/order.service'; import { OrderService} from '../../order/order.service';
import { ItemCreateComponent } from '../item-create/item-create.component'; import { ItemCreateComponent } from '../item-create/item-create.component';
import { ItemEditComponent } from '../item-edit/item-edit.component';
import { ItemDeleteComponent } from '../item-delete/item-delete.component'; import { ItemDeleteComponent } from '../item-delete/item-delete.component';
import { ItemAddComponent } from '../item-add/item-add.component'; import { ItemAddComponent } from '../item-add/item-add.component';
import { NotifierService } from '../../notifier.service';
@Component({ @Component({
selector: 'app-item-list', selector: 'app-item-list',
@ -64,8 +65,9 @@ export class ItemListComponent implements OnInit{
userService: UserService, userService: UserService,
public orderService: OrderService, public orderService: OrderService,
public fullnodeService: FullnodeService, public fullnodeService: FullnodeService,
private dialog: MatDialog private dialog: MatDialog,
) { private notifierService: NotifierService )
{
this.ownerUpdate = userService.ownerUpdate; this.ownerUpdate = userService.ownerUpdate;
this.itemsUpdate = itemService.itemsUpdated; this.itemsUpdate = itemService.itemsUpdated;
this.ownerUpdate.subscribe((owner) => { this.ownerUpdate.subscribe((owner) => {
@ -97,6 +99,9 @@ export class ItemListComponent implements OnInit{
if(val != null) { if(val != null) {
var item:Item = {_id: '', name: val.name, description: val.description, cost: val.cost, owner: this.owner.address}; var item:Item = {_id: '', name: val.name, description: val.description, cost: val.cost, owner: this.owner.address};
this.itemService.addItem(item); this.itemService.addItem(item);
this.notifierService
.showNotification("Item successfully created!",
"Close","success");
} }
this.itemService.getItems(this.owner.address); this.itemService.getItems(this.owner.address);
this.itemsUpdate.subscribe((items) => { this.itemsUpdate.subscribe((items) => {
@ -115,7 +120,7 @@ export class ItemListComponent implements OnInit{
dialogConfig.autoFocus = true; dialogConfig.autoFocus = true;
dialogConfig.data = item; dialogConfig.data = item;
const dialogRef = this.dialog.open(ItemCreateComponent, dialogConfig); const dialogRef = this.dialog.open(ItemEditComponent, dialogConfig);
dialogRef.afterClosed().subscribe((val) => { dialogRef.afterClosed().subscribe((val) => {
if (val != null) { if (val != null) {
var editItem: Item = { var editItem: Item = {
@ -128,7 +133,10 @@ export class ItemListComponent implements OnInit{
//console.log('Edit:', editItem); //console.log('Edit:', editItem);
this.itemService.addItem(editItem).subscribe((response) => { this.itemService.addItem(editItem).subscribe((response) => {
this.itemService.getItems(this.owner.address); this.itemService.getItems(this.owner.address);
});; });
this.notifierService
.showNotification("Item information updated!!",
"Close","success");
} }
this.itemService.getItems(this.owner.address); this.itemService.getItems(this.owner.address);
}); });

View file

@ -110,6 +110,12 @@ img.icon{
.minibutton { .minibutton {
font-family: 'Spartan', sans-serif; font-family: 'Spartan', sans-serif;
font-size: 12px;
background: #ff5722;
color: white;
height: 24px;
line-height: 20px;
padding: 2px;
} }
.spacer { .spacer {

View file

@ -122,7 +122,11 @@
</tr> </tr>
</tbody> </tbody>
</table> </table>
<div align="center"> <div style="display: flex;
justify-content: space-between;
padding-left: 20%;
padding-right: 20%;
margin-top: 10px;">
<span> <span>
<button mat-stroked-button class="minibutton" color="primary" (click)="invoice(order)">Invoice</button> <button mat-stroked-button class="minibutton" color="primary" (click)="invoice(order)">Invoice</button>
</span> </span>

View file

@ -12,7 +12,7 @@ img.icon{
} }
.noOrderMsg { .noOrderMsg {
font-family: Roboto Mono; font-family: 'Roboto Mono';
font-size: 20px; font-size: 20px;
font-weight: 700; font-weight: 700;
margin: 10px; margin: 10px;
@ -21,7 +21,7 @@ img.icon{
} }
.newOrder { .newOrder {
font-family: Roboto Mono !important; font-family: 'Roboto Mono' !important;
} }
.newOrderTitle1 { .newOrderTitle1 {
@ -78,7 +78,7 @@ img.icon{
.availableItems{ .availableItems{
background: lightblue; background: lightblue;
font-family: Roboto Mono; font-family: 'Roboto Mono';
font-size: 18px; font-size: 18px;
font-weight: 700; font-weight: 700;
text-align: left; text-align: left;