From 0aec89e0aba8be5ac4a9f3c56a24172b4c4c1e77 Mon Sep 17 00:00:00 2001 From: bnymncoskuner Date: Fri, 10 Dec 2021 13:41:15 +0300 Subject: [PATCH] feat: open modals on edit, delete --- .../src/pages/product/product.component.html | 54 ++++++++++++++++++- .../src/pages/product/product.component.ts | 39 ++++++++++++-- 2 files changed, 88 insertions(+), 5 deletions(-) diff --git a/apps/angular/projects/catalog/src/pages/product/product.component.html b/apps/angular/projects/catalog/src/pages/product/product.component.html index f4e5e651..0cc424c2 100644 --- a/apps/angular/projects/catalog/src/pages/product/product.component.html +++ b/apps/angular/projects/catalog/src/pages/product/product.component.html @@ -5,7 +5,9 @@
{{ 'AbpCatalog::Products' | abpLocalization }}
- +
@@ -41,3 +43,53 @@ + + + +

{{ (selected?.id ? 'AbpCatalog::Edit' : 'AbpCatalog::NewProduct') | abpLocalization }}

+
+ + +
+ + +
+ + + + {{ 'AbpIdentity::Save' | abpLocalization }} + +
diff --git a/apps/angular/projects/catalog/src/pages/product/product.component.ts b/apps/angular/projects/catalog/src/pages/product/product.component.ts index 365d2cc7..a29d12cc 100644 --- a/apps/angular/projects/catalog/src/pages/product/product.component.ts +++ b/apps/angular/projects/catalog/src/pages/product/product.component.ts @@ -1,4 +1,5 @@ import { ListService } from '@abp/ng.core'; +import { Confirmation, ConfirmationService } from '@abp/ng.theme.shared'; import { Component, OnInit } from '@angular/core'; import { ProductDto, ProductService } from '@catalog/proxy/products'; @@ -11,7 +12,17 @@ import { ProductDto, ProductService } from '@catalog/proxy/products'; export class ProductComponent implements OnInit { items: ProductDto[] = []; count = 0; - constructor(public readonly productService: ProductService, public readonly list: ListService) { + + selected: ProductDto; + + isModalVisible: boolean; + + modalBusy = false; + constructor( + public readonly productService: ProductService, + public readonly list: ListService, + private confirmationService: ConfirmationService + ) { // TODO: this is an example of paging this.list.maxResultCount = 2; } @@ -25,9 +36,29 @@ export class ProductComponent implements OnInit { }); } - onEdit(row: ProductDto) { - // this.productService.edit(row); + onEdit(product: ProductDto) { + this.selected = product; + this.openModal(); + } + + onCreate() { + this.selected = {} as ProductDto; + this.openModal(); + } + + openModal() { + this.isModalVisible = true; } - onDelete(row: ProductDto) {} + onDelete(product: ProductDto) { + this.confirmationService + .warn('AbpCatalog::ProductDeletionConfirmationMessage', 'AbpCatalog::AreYouSure', { + messageLocalizationParams: [product.name], + }) + .subscribe((status: Confirmation.Status) => { + if (status === Confirmation.Status.confirm) { + this.productService.delete(product.id).subscribe(() => this.list.get()); + } + }); + } }