From 750a0da8173975238f25a2f408b0bd88fbf9f6ac Mon Sep 17 00:00:00 2001 From: sanchezvem Date: Fri, 12 Dec 2025 21:46:16 +0100 Subject: [PATCH] added edit function --- .../deliverer-table/deliverer-table.ts | 12 +----- .../deliverery-note-table.ts | 37 +++++++++-------- .../quotation-form/quotation-form.html | 6 +-- .../quotation-form/quotation-form.ts | 22 +++++++--- .../quotation-table/quotation-table.html | 21 +++++----- .../quotation-table/quotation-table.ts | 40 ++++++++++++++++++- .../api/model/update-quotation-dto.ts | 16 ++++++++ 7 files changed, 104 insertions(+), 50 deletions(-) create mode 100644 src/app/services/api/model/update-quotation-dto.ts diff --git a/src/app/components/deliverer-table/deliverer-table.ts b/src/app/components/deliverer-table/deliverer-table.ts index ca1b4c8..c688c9f 100644 --- a/src/app/components/deliverer-table/deliverer-table.ts +++ b/src/app/components/deliverer-table/deliverer-table.ts @@ -79,20 +79,12 @@ export class DelivererTable implements OnInit { } try { - const deliverers = updateDelivererComponent.delivererForm.getRawValue(); await firstValueFrom(this.deliverersService.updateDelivererEndpoint(id, deliverers)) - this.notificationService.success( - 'Success', - 'Transporteur modifié' - ) + this.notificationService.success('Success', 'Transporteur modifié') } catch (e) { - console.error(e); - this.notificationService.error( - 'Erreur', - 'Erreur lors de la modification' - ) + this.notificationService.error('Erreur', 'Erreur lors de la modification') } } diff --git a/src/app/components/deliverery-note-table/deliverery-note-table.ts b/src/app/components/deliverery-note-table/deliverery-note-table.ts index 205c26f..4a31036 100644 --- a/src/app/components/deliverery-note-table/deliverery-note-table.ts +++ b/src/app/components/deliverery-note-table/deliverery-note-table.ts @@ -116,25 +116,6 @@ export class DelivereryNoteTable implements OnInit { this.deliveryNotesLoading.set(false) } - selectedDeliveryNote: GetDeliveryNoteDto | null = null; - openEditModal(deliveryNote: GetDeliveryNoteDto) { - this.selectedDeliveryNote = { ...deliveryNote }; - this.modal().showModal(); - } - - async onModalOk(id: number, updateDelivereryNoteComponent: DelivereryNoteForm, modal: ModalNav) { - if (!this.selectedDeliveryNote) return; - - await this.edit(id, updateDelivereryNoteComponent); - updateDelivereryNoteComponent.deliveryNoteForm.reset(); - modal.isVisible = false; - await this.fetchDeliveryNotes(); - } - - onModalCancel(modal: ModalNav) { - modal.isVisible = false; - } - async edit(id: number, updateDelivereryNoteComponent: DelivereryNoteForm) { if (updateDelivereryNoteComponent.deliveryNoteForm.invalid) { this.notificationService.error('Erreur', 'Formulaire invalide'); @@ -176,4 +157,22 @@ export class DelivereryNoteTable implements OnInit { } } + selectedDeliveryNote: GetDeliveryNoteDto | null = null; + openEditModal(deliveryNote: GetDeliveryNoteDto) { + this.selectedDeliveryNote = { ...deliveryNote }; + this.modal().showModal(); + } + + async onModalOk(id: number, updateDelivereryNoteComponent: DelivereryNoteForm, modal: ModalNav) { + if (!this.selectedDeliveryNote) return; + + await this.edit(id, updateDelivereryNoteComponent); + updateDelivereryNoteComponent.deliveryNoteForm.reset(); + modal.isVisible = false; + await this.fetchDeliveryNotes(); + } + + onModalCancel(modal: ModalNav) { + modal.isVisible = false; + } } diff --git a/src/app/components/quotation-form/quotation-form.html b/src/app/components/quotation-form/quotation-form.html index 0ca8812..b0b4420 100644 --- a/src/app/components/quotation-form/quotation-form.html +++ b/src/app/components/quotation-form/quotation-form.html @@ -1,11 +1,11 @@ -
+ Message du devis - + @@ -15,7 +15,7 @@ - +
diff --git a/src/app/components/quotation-form/quotation-form.ts b/src/app/components/quotation-form/quotation-form.ts index 0e7a39c..a6aa2b6 100644 --- a/src/app/components/quotation-form/quotation-form.ts +++ b/src/app/components/quotation-form/quotation-form.ts @@ -1,10 +1,10 @@ -import { Component } from '@angular/core'; +import {Component, effect, input} from '@angular/core'; import {FormControl, FormGroup, ReactiveFormsModule, Validators} from "@angular/forms"; import {NzFormControlComponent, NzFormDirective, NzFormItemComponent, NzFormLabelComponent} from "ng-zorro-antd/form"; import {NzInputDirective} from "ng-zorro-antd/input"; import {NzColDirective} from "ng-zorro-antd/grid"; import {NzFlexDirective} from "ng-zorro-antd/flex"; -import {NzDatePickerComponent} from "ng-zorro-antd/date-picker"; +import {GetQuotationDto} from "../../services/api"; @Component({ selector: 'app-quotation-form', @@ -22,8 +22,20 @@ import {NzDatePickerComponent} from "ng-zorro-antd/date-picker"; styleUrl: './quotation-form.css', }) export class QuotationForm { - QuotationForm: FormGroup = new FormGroup({ - quotationMessage: new FormControl(null), - quotationConditionsSale: new FormControl(null), + quotationForm: FormGroup = new FormGroup({ + message: new FormControl(null, [Validators.required]), + conditionsSale: new FormControl(null, [Validators.required]), }) + + quotation= input(); + constructor() { + effect(() => { + if (this.quotation()) { + this.quotationForm.patchValue({ + message: this.quotation().message, + conditionsSale: this.quotation().conditionsSale, + }); + } + }); + } } diff --git a/src/app/components/quotation-table/quotation-table.html b/src/app/components/quotation-table/quotation-table.html index 84ede4d..34309da 100644 --- a/src/app/components/quotation-table/quotation-table.html +++ b/src/app/components/quotation-table/quotation-table.html @@ -52,21 +52,13 @@
-
- -
+ - - - + -
- -
+ -
- -
+
@@ -74,3 +66,8 @@ + \ No newline at end of file diff --git a/src/app/components/quotation-table/quotation-table.ts b/src/app/components/quotation-table/quotation-table.ts index 125499a..229ef9f 100644 --- a/src/app/components/quotation-table/quotation-table.ts +++ b/src/app/components/quotation-table/quotation-table.ts @@ -1,4 +1,4 @@ -import {Component, inject, OnInit, signal} from '@angular/core'; +import {Component, inject, OnInit, signal, viewChild} from '@angular/core'; import {NzTableComponent} from "ng-zorro-antd/table"; import {ModalButton} from "../modal-button/modal-button"; import {ModalNav} from "../modal-nav/modal-nav"; @@ -9,6 +9,7 @@ import {GetQuotationDto, QuotationsService} from "../../services/api"; import {NzNotificationService} from "ng-zorro-antd/notification"; import {firstValueFrom} from "rxjs"; import {FileService} from "../../services/file.service"; +import {DelivereryNoteForm} from "../deliverery-note-form/deliverery-note-form"; @Component({ selector: 'app-quotation-table', @@ -19,6 +20,7 @@ import {FileService} from "../../services/file.service"; NzIconDirective, NzTableComponent, QuotationForm, + DelivereryNoteForm, ], templateUrl: './quotation-table.html', styleUrl: './quotation-table.css', @@ -30,6 +32,7 @@ export class QuotationTable implements OnInit { private fileService = inject(FileService); quotations = signal([]); quotationsLoading = signal(false); + modal = viewChild.required('modalNav'); async ngOnInit() { await this.fetchQuotations(); @@ -84,5 +87,40 @@ export class QuotationTable implements OnInit { } this.quotationsLoading.set(false) } + + async edit(id: number, updateQuotationComponent: QuotationForm) { + if (updateQuotationComponent.quotationForm.invalid) { + this.notificationService.error('Erreur', 'Formulaire invalide'); + return; + } + + try { + const quotations = updateQuotationComponent.quotationForm.getRawValue(); + await firstValueFrom(this.quotationsService.updateQuotationEndpoint(id, quotations)); + this.notificationService.success('Success', 'Devis modifié') + } catch (e) { + console.error(e) + this.notificationService.error('Erreur', 'Erreur lors de la modification') + } + } + + selectedQuotation: GetQuotationDto | null = null; + openEditModal(quotation: GetQuotationDto) { + this.selectedQuotation = { ...quotation }; + this.modal().showModal(); + } + + async onModalOk(id: number, updateQuotationComponent: QuotationForm, modal: ModalNav) { + if (!this.selectedQuotation) return; + + await this.edit(id, updateQuotationComponent); + updateQuotationComponent.quotationForm.reset(); + modal.isVisible = false; + await this.fetchQuotations(); + } + + onModalCancel(modal: ModalNav) { + modal.isVisible = false; + } } diff --git a/src/app/services/api/model/update-quotation-dto.ts b/src/app/services/api/model/update-quotation-dto.ts new file mode 100644 index 0000000..5895594 --- /dev/null +++ b/src/app/services/api/model/update-quotation-dto.ts @@ -0,0 +1,16 @@ +/** + * PyroFetes + * + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +export interface UpdateQuotationDto { + message?: string | null; + conditionsSale?: string | null; +} +