From cdcdaaa25e2cab701b856a92fd02dd4e530a78f0 Mon Sep 17 00:00:00 2001 From: sanchezvem Date: Mon, 1 Dec 2025 12:41:40 +0100 Subject: [PATCH 1/2] added suppr and edit modal for supplier price --- src/app/components/price-form/price-form.css | 0 src/app/components/price-form/price-form.html | 13 ++ src/app/components/price-form/price-form.ts | 40 +++++ .../supplier-table/supplier-table.html | 38 ++++- .../supplier-table/supplier-table.ts | 137 +++++++++++------- 5 files changed, 170 insertions(+), 58 deletions(-) create mode 100644 src/app/components/price-form/price-form.css create mode 100644 src/app/components/price-form/price-form.html create mode 100644 src/app/components/price-form/price-form.ts diff --git a/src/app/components/price-form/price-form.css b/src/app/components/price-form/price-form.css new file mode 100644 index 0000000..e69de29 diff --git a/src/app/components/price-form/price-form.html b/src/app/components/price-form/price-form.html new file mode 100644 index 0000000..fb025a8 --- /dev/null +++ b/src/app/components/price-form/price-form.html @@ -0,0 +1,13 @@ +
+ + + Prix + + + + + + +
+ + diff --git a/src/app/components/price-form/price-form.ts b/src/app/components/price-form/price-form.ts new file mode 100644 index 0000000..ec8d527 --- /dev/null +++ b/src/app/components/price-form/price-form.ts @@ -0,0 +1,40 @@ +import {Component, effect, input} from '@angular/core'; +import {FormControl, FormGroup, FormsModule, ReactiveFormsModule, Validators} from "@angular/forms"; +import {NzColDirective} from "ng-zorro-antd/grid"; +import {NzFlexDirective} from "ng-zorro-antd/flex"; +import {NzFormControlComponent, NzFormDirective, NzFormItemComponent, NzFormLabelComponent} from "ng-zorro-antd/form"; +import {NzInputDirective} from "ng-zorro-antd/input"; +import {GetPriceDto, GetSupplierDto} from "../../services/api"; + +@Component({ + selector: 'app-price-form', + imports: [ + FormsModule, + NzColDirective, + NzFlexDirective, + NzFormControlComponent, + NzFormDirective, + NzFormItemComponent, + NzFormLabelComponent, + NzInputDirective, + ReactiveFormsModule + ], + templateUrl: './price-form.html', + styleUrl: './price-form.css', +}) +export class PriceForm { + priceForm: FormGroup = new FormGroup({ + price: new FormControl(null, [Validators.required]), + }) + + price= input(); + constructor() { + effect(() => { + if (this.price()) { + this.priceForm.patchValue({ + price: this.price().sellingPrice + }); + } + }); + } +} diff --git a/src/app/components/supplier-table/supplier-table.html b/src/app/components/supplier-table/supplier-table.html index 4cae48c..1a89523 100644 --- a/src/app/components/supplier-table/supplier-table.html +++ b/src/app/components/supplier-table/supplier-table.html @@ -25,22 +25,32 @@ {{ supplier.city }} {{ supplier.deliveryDelay }} jours - - + + - + Produit Référence Prix + Action - + @for (product of supplier.prices; track product.id) { {{ product.productName }} {{ product.productReferences }} {{ product.sellingPrice }}€ + +
+ + + +
+ } @@ -49,9 +59,11 @@
- + - +
@@ -60,7 +72,17 @@
+ + diff --git a/src/app/components/supplier-table/supplier-table.ts b/src/app/components/supplier-table/supplier-table.ts index 98ae8c3..d95457b 100644 --- a/src/app/components/supplier-table/supplier-table.ts +++ b/src/app/components/supplier-table/supplier-table.ts @@ -5,9 +5,10 @@ import {NzIconDirective} from "ng-zorro-antd/icon"; import {NzTableComponent} from "ng-zorro-antd/table"; import {ModalButton} from "../modal-button/modal-button"; import {SupplierForm} from "../supplier-form/supplier-form"; -import {GetPriceDto, GetSupplierDto, SuppliersService} from "../../services/api"; +import {GetPriceDto, GetSupplierDto, PricesService, SuppliersService} from "../../services/api"; import {NzNotificationService} from "ng-zorro-antd/notification"; import {firstValueFrom} from "rxjs"; +import {PriceForm} from "../price-form/price-form"; @Component({ selector: 'app-supplier-table', @@ -18,6 +19,7 @@ import {firstValueFrom} from "rxjs"; NzTableComponent, ModalButton, SupplierForm, + PriceForm, ], templateUrl: './supplier-table.html', styleUrl: './supplier-table.css', @@ -25,82 +27,68 @@ import {firstValueFrom} from "rxjs"; export class SupplierTable implements OnInit { private suppliersService = inject(SuppliersService); - private notificationService = inject(NzNotificationService) + private pricesService = inject(PricesService); + private notificationService = inject(NzNotificationService); suppliers = signal([]); suppliersLoading = signal(false); updateSupplier = viewChild.required('supplierForm'); - modal = viewChild.required('modalNav'); + supplierModal = viewChild.required('supplierModal'); + productModal = viewChild.required('productModal'); + selectedSupplier: GetSupplierDto | null = null; + selectedProduct: GetPriceDto | null = null; async ngOnInit() { await this.fetchSuppliers(); } async fetchSuppliers() { - this.suppliersLoading.set(true) - + this.suppliersLoading.set(true); try { - const suppliers = await firstValueFrom(this.suppliersService.getAllSuppliersEndpoint()) + const suppliers = await firstValueFrom(this.suppliersService.getAllSuppliersEndpoint()); this.suppliers.set(suppliers); } catch (e) { - this.notificationService.error( - 'Erreur', - 'Erreur de communication avec l\'API' - ) + this.notificationService.error('Erreur', 'Erreur de communication avec l\'API'); } - this.suppliersLoading.set(false) - } - - async delete(supplier:number) { - try { - await firstValueFrom(this.suppliersService.deleteSupplierEndpoint(supplier)) - this.notificationService.success( - 'Success', - 'Suppression effectuée' - ) - } catch (e) { - this.notificationService.error( - 'Erreur', - 'Impossible de supprimer la ligne' - ) - } - await this.fetchSuppliers(); + this.suppliersLoading.set(false); } async edit(id: number, updateSupplierComponent: SupplierForm) { if (updateSupplierComponent.supplierForm.invalid) { - this.notificationService.error( - 'Erreur', - 'Erreur d\'écriture dans le formulaire' - ) + this.notificationService.error('Erreur', 'Erreur d\'écriture dans le formulaire'); return; } - try { - const suppliers = updateSupplierComponent.supplierForm.getRawValue(); - await firstValueFrom(this.suppliersService.updateSupplierEndpoint(id, suppliers)) - - this.notificationService.success( - 'Success', - 'Fournisseur modifié' - ) + await firstValueFrom(this.suppliersService.updateSupplierEndpoint(id, suppliers)); + this.notificationService.success('Success', 'Fournisseur modifié'); } catch (e) { console.error(e); - this.notificationService.error( - 'Erreur', - 'Erreur lors de la modification' - ) + this.notificationService.error('Erreur', 'Erreur lors de la modification'); } } - selectedSupplier: GetSupplierDto | null = null; - openEditModal(supplier: GetSupplierDto) { - this.selectedSupplier = { ...supplier }; - this.modal().showModal(); + async delete(supplier: number) { + try { + await firstValueFrom(this.suppliersService.deleteSupplierEndpoint(supplier)); + this.notificationService.success('Succès', 'Suppression effectuée'); + await this.fetchSuppliers(); + } catch (e) { + this.notificationService.error('Erreur', 'Impossible de supprimer la ligne'); + } } - async onModalOk(supplierId: number, updateSupplierComponent: SupplierForm, modal: ModalNav) { - if (!this.selectedSupplier) return; + openEditModal(supplier: GetSupplierDto) { + this.selectedSupplier = { ...supplier }; + this.supplierModal().showModal(); + } + + openEditProductModal(product: GetPriceDto) { + this.selectedProduct = { ...product }; + this.productModal().showModal(); + } + + async onModalOk(supplierId: number | undefined, updateSupplierComponent: SupplierForm, modal: ModalNav) { + if (!supplierId || !this.selectedSupplier) return; await this.edit(supplierId, updateSupplierComponent); updateSupplierComponent.supplierForm.reset(); @@ -108,7 +96,56 @@ export class SupplierTable implements OnInit { await this.fetchSuppliers(); } + async onModalProductOk( + productId: number | undefined, + supplierId: number | undefined, + updateProductComponent: PriceForm, + modal: ModalNav + ) { + if (!productId || !supplierId || !this.selectedProduct) return; + + await this.editPrice(productId, supplierId, updateProductComponent); + updateProductComponent.priceForm.reset(); + modal.isVisible = false; + await this.fetchSuppliers(); + } + onModalCancel(modal: ModalNav) { modal.isVisible = false; } -} \ No newline at end of file + + async editPrice(productId: number, supplierId: number, updateProductComponent: PriceForm) { + if (updateProductComponent.priceForm.invalid) { + this.notificationService.error('Erreur', 'Erreur d\'écriture dans le formulaire'); + return; + } + + try { + const formValue = updateProductComponent.priceForm.getRawValue(); + const body = { + productId, + supplierId, + sellingPrice: Number(formValue.price), + }; + + console.log('PATCH body =>', body); + + await firstValueFrom(this.pricesService.patchPriceEndpoint(productId, supplierId, body)); + this.notificationService.success('Success', 'Prix modifié'); + } catch (e) { + console.error(e); + this.notificationService.error('Erreur', 'Erreur lors de la modification'); + } + } + + + async deleteProduct(idProduct: number, idSupplier: number) { + try { + await firstValueFrom(this.pricesService.deletePriceEndpoint(idProduct, idSupplier)); + this.notificationService.success('Succès', 'Produit supprimé'); + await this.fetchSuppliers(); + } catch (e) { + this.notificationService.error('Erreur', 'Impossible de supprimer le produit'); + } + } +} From 0470b9c45c8d8e150f331354bf670de7dac7f075 Mon Sep 17 00:00:00 2001 From: sanchezvem Date: Mon, 1 Dec 2025 12:52:52 +0100 Subject: [PATCH 2/2] added suppr and edit modal for supplier price --- .../components/supplier-table/supplier-table.html | 4 ++-- .../components/supplier-table/supplier-table.ts | 15 ++++++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/app/components/supplier-table/supplier-table.html b/src/app/components/supplier-table/supplier-table.html index 1a89523..8c6c89b 100644 --- a/src/app/components/supplier-table/supplier-table.html +++ b/src/app/components/supplier-table/supplier-table.html @@ -45,7 +45,7 @@
+ (click)="openEditProductModal(product, supplier.id)"> @@ -81,7 +81,7 @@