diff --git a/src/app/pages/app.crud.component.html b/src/app/pages/app.crud.component.html index 092512c..9b9d810 100644 --- a/src/app/pages/app.crud.component.html +++ b/src/app/pages/app.crud.component.html @@ -1,20 +1,22 @@ -
+
- - +
+ + +
- - + +
- +
Manage Products
@@ -44,8 +46,8 @@ - Code - {{product.code}} + Code + {{product.code || product.id}} Name @@ -82,7 +84,7 @@
- + Name is required.
@@ -92,9 +94,9 @@
- + - {{selectedStatus.label}} + {{product.inventoryStatus.label}} {{status.label}} @@ -103,7 +105,7 @@
- +
@@ -142,6 +144,26 @@ - + +
+ + Are you sure you want to delete {{product.name}}? +
+ + + + +
+ + +
+ + Are you sure you want to delete selected products? +
+ + + + +
diff --git a/src/app/pages/app.crud.component.ts b/src/app/pages/app.crud.component.ts index c0e55c0..f498d63 100644 --- a/src/app/pages/app.crud.component.ts +++ b/src/app/pages/app.crud.component.ts @@ -11,6 +11,10 @@ export class AppCrudComponent implements OnInit { productDialog: boolean; + deleteProductDialog: boolean = false; + + deleteProductsDialog: boolean = false; + products: Product[]; product: Product; @@ -23,8 +27,6 @@ export class AppCrudComponent implements OnInit { statuses: any[]; - selectedStatus:any; - rowsPerPageOptions = [5, 10, 20]; constructor(private productService: ProductService, private messageService: MessageService, @@ -55,16 +57,7 @@ export class AppCrudComponent implements OnInit { } deleteSelectedProducts() { - this.confirmationService.confirm({ - message: 'Are you sure you want to delete the selected products?', - header: 'Confirm', - icon: 'pi pi-exclamation-triangle', - accept: () => { - this.products = this.products.filter(val => !this.selectedProducts.includes(val)); - this.selectedProducts = null; - this.messageService.add({severity: 'success', summary: 'Successful', detail: 'Products Deleted', life: 3000}); - } - }); + this.deleteProductsDialog = true; } editProduct(product: Product) { @@ -73,16 +66,22 @@ export class AppCrudComponent implements OnInit { } deleteProduct(product: Product) { - this.confirmationService.confirm({ - message: 'Are you sure you want to delete ' + product.name + '?', - header: 'Confirm', - icon: 'pi pi-exclamation-triangle', - accept: () => { - this.products = this.products.filter(val => val.id !== product.id); - this.product = {}; - this.messageService.add({severity: 'success', summary: 'Successful', detail: 'Product Deleted', life: 3000}); - } - }); + this.deleteProductDialog = true; + this.product = {...product}; + } + + confirmDeleteSelected(){ + this.deleteProductsDialog = false; + this.products = this.products.filter(val => !this.selectedProducts.includes(val)); + this.messageService.add({severity: 'success', summary: 'Successful', detail: 'Products Deleted', life: 3000}); + this.selectedProducts = null; + } + + confirmDelete(){ + this.deleteProductDialog = false; + this.products = this.products.filter(val => val.id !== this.product.id); + this.messageService.add({severity: 'success', summary: 'Successful', detail: 'Product Deleted', life: 3000}); + this.product = {}; } hideDialog() { @@ -95,11 +94,16 @@ export class AppCrudComponent implements OnInit { if (this.product.name.trim()) { if (this.product.id) { + // @ts-ignore + this.product.inventoryStatus = this.product.inventoryStatus.value ? this.product.inventoryStatus.value: this.product.inventoryStatus; this.products[this.findIndexById(this.product.id)] = this.product; this.messageService.add({severity: 'success', summary: 'Successful', detail: 'Product Updated', life: 3000}); } else { this.product.id = this.createId(); + this.product.code = this.createId(); this.product.image = 'product-placeholder.svg'; + // @ts-ignore + this.product.inventoryStatus = this.product.inventoryStatus ? this.product.inventoryStatus.value : 'INSTOCK'; this.products.push(this.product); this.messageService.add({severity: 'success', summary: 'Successful', detail: 'Product Created', life: 3000}); } diff --git a/src/styles.scss b/src/styles.scss index 3314578..5f65713 100644 --- a/src/styles.scss +++ b/src/styles.scss @@ -101,60 +101,6 @@ } } -.crud-demo { - .p-toolbar { - flex-wrap: wrap; - } - - /* Responsive */ - .datatable-responsive .p-datatable-tbody > tr > td .p-column-title { - display: none; - } - - @media screen and (max-width: 960px) { - .p-datatable { - &.datatable-responsive { - .p-datatable-thead > tr > th, - .p-datatable-tfoot > tr > td { - display: none !important; - } - - .p-datatable-tbody > tr { - border-bottom: 1px solid var(--surface-d); - > td { - text-align: left; - display: flex; - align-items: center; - border: 0 none !important; - width: 100% !important; - float: left; - clear: left; - border: 0 none; - - .p-column-title { - padding: .4rem; - min-width: 30%; - display: inline-block; - margin: -.4rem 1rem -.4rem -.4rem; - font-weight: bold; - } - - .p-progressbar { - margin-top: .5rem; - } - - .actions { - display: flex; - flex-grow: 1; - justify-content: center; - } - } - } - } - } - } -} - .docs { i:not([class~="pi"]) { background-color: transparent;