Implement add-to-order dialog
This commit is contained in:
parent
8b3dfb2984
commit
064044c011
7 changed files with 94 additions and 3 deletions
|
@ -18,6 +18,7 @@ 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 { 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 { OrderComponent } from './order/order.component';
|
import { OrderComponent } from './order/order.component';
|
||||||
//import { NameDialogComponent } from './namedialog/namedialog.component';
|
//import { NameDialogComponent } from './namedialog/namedialog.component';
|
||||||
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
||||||
|
@ -31,7 +32,8 @@ import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
||||||
LoginComponent,
|
LoginComponent,
|
||||||
OrderComponent,
|
OrderComponent,
|
||||||
ItemCreateComponent,
|
ItemCreateComponent,
|
||||||
ItemDeleteComponent
|
ItemDeleteComponent,
|
||||||
|
ItemAddComponent
|
||||||
//NameDialogComponent,
|
//NameDialogComponent,
|
||||||
],
|
],
|
||||||
imports: [
|
imports: [
|
||||||
|
@ -54,6 +56,6 @@ import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
||||||
],
|
],
|
||||||
providers: [],
|
providers: [],
|
||||||
bootstrap: [AppComponent],
|
bootstrap: [AppComponent],
|
||||||
entryComponents: [ItemCreateComponent, ItemDeleteComponent]
|
entryComponents: [ItemCreateComponent, ItemDeleteComponent, ItemAddComponent]
|
||||||
})
|
})
|
||||||
export class AppModule { }
|
export class AppModule { }
|
||||||
|
|
3
src/app/items/item-add/item-add.component.css
Normal file
3
src/app/items/item-add/item-add.component.css
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
.text {
|
||||||
|
font-family: "Roboto Mono", monospace;
|
||||||
|
}
|
13
src/app/items/item-add/item-add.component.html
Normal file
13
src/app/items/item-add/item-add.component.html
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
<h2 mat-dialog-title class="text">Add to Order</h2>
|
||||||
|
|
||||||
|
<mat-dialog-content [formGroup]="orderForm">
|
||||||
|
<p class="text">{{lineItem.name}}</p>
|
||||||
|
<mat-form-field>
|
||||||
|
<input matInput placeholder="Quantity" formControlName="qty">
|
||||||
|
</mat-form-field>
|
||||||
|
</mat-dialog-content>
|
||||||
|
|
||||||
|
<mat-dialog-actions>
|
||||||
|
<button mat-raised-button class="text" (click)="close()">Cancel</button>
|
||||||
|
<button mat-raised-button class="text" color="primary" (click)="save()">Add</button>
|
||||||
|
</mat-dialog-actions>
|
45
src/app/items/item-add/item-add.component.ts
Normal file
45
src/app/items/item-add/item-add.component.ts
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
import { Inject, Component, OnInit, OnDestroy, ViewEncapsulation } from '@angular/core';
|
||||||
|
import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
|
||||||
|
import { FormBuilder, Validators, FormGroup, FormControl } from '@angular/forms';
|
||||||
|
import { LineItem } from '../lineitem.model';
|
||||||
|
import { Order } from '../../order/order.model';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-item-add',
|
||||||
|
templateUrl: './item-add.component.html',
|
||||||
|
styleUrls: ['./item-add.component.css']
|
||||||
|
})
|
||||||
|
|
||||||
|
export class ItemAddComponent implements OnInit {
|
||||||
|
|
||||||
|
orderForm: FormGroup;
|
||||||
|
lineItem: LineItem;
|
||||||
|
//order: Order;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private fb: FormBuilder,
|
||||||
|
private dialogRef: MatDialogRef<ItemAddComponent>,
|
||||||
|
@Inject(MAT_DIALOG_DATA) public data: LineItem
|
||||||
|
) {
|
||||||
|
this.orderForm = fb.group({
|
||||||
|
qty: [data.qty, Validators.required]
|
||||||
|
});
|
||||||
|
this.lineItem = {
|
||||||
|
qty : data.qty,
|
||||||
|
name : data.name,
|
||||||
|
cost : data.cost
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnInit() {
|
||||||
|
}
|
||||||
|
|
||||||
|
close() {
|
||||||
|
this.dialogRef.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
save() {
|
||||||
|
this.lineItem.qty = this.orderForm.value.qty;
|
||||||
|
this.dialogRef.close(this.lineItem);
|
||||||
|
}
|
||||||
|
}
|
|
@ -27,7 +27,7 @@
|
||||||
</button>
|
</button>
|
||||||
</td>
|
</td>
|
||||||
<td align="right">
|
<td align="right">
|
||||||
<button mat-raised-button color="primary" class="icons">
|
<button mat-raised-button color="primary" class="icons" (click)="addToOrder(item._id!)">
|
||||||
<mat-icon>shopping_cart</mat-icon>
|
<mat-icon>shopping_cart</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
</td>
|
</td>
|
||||||
|
|
|
@ -8,6 +8,7 @@ import { UserService } from '../../user.service';
|
||||||
import { ItemService } from '../items.service';
|
import { ItemService } from '../items.service';
|
||||||
import { ItemCreateComponent } from '../item-create/item-create.component';
|
import { ItemCreateComponent } from '../item-create/item-create.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';
|
||||||
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
|
@ -115,5 +116,27 @@ export class ItemListComponent implements OnInit{
|
||||||
this.itemService.getItems(this.owner.address);
|
this.itemService.getItems(this.owner.address);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addToOrder(id: string) {
|
||||||
|
const item = this.items.find(element => element._id == id);
|
||||||
|
//console.log(item);
|
||||||
|
const dialogConfig = new MatDialogConfig();
|
||||||
|
|
||||||
|
dialogConfig.disableClose = true;
|
||||||
|
dialogConfig.autoFocus = true;
|
||||||
|
dialogConfig.data = {
|
||||||
|
qty: 1,
|
||||||
|
name: item!.name,
|
||||||
|
cost: item!.cost
|
||||||
|
};
|
||||||
|
|
||||||
|
const dialogRef = this.dialog.open(ItemAddComponent, dialogConfig);
|
||||||
|
dialogRef.afterClosed().subscribe((val) => {
|
||||||
|
if (val != null) {
|
||||||
|
console.log('Adding to order', val);
|
||||||
|
}
|
||||||
|
this.itemService.getItems(this.owner.address);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
5
src/app/items/lineitem.model.ts
Normal file
5
src/app/items/lineitem.model.ts
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
export interface LineItem {
|
||||||
|
qty: number;
|
||||||
|
name: string;
|
||||||
|
cost: number;
|
||||||
|
}
|
Loading…
Reference in a new issue