added edit function

This commit is contained in:
2025-12-12 21:46:16 +01:00
parent a707a33a87
commit 750a0da817
7 changed files with 104 additions and 50 deletions

View File

@@ -79,20 +79,12 @@ export class DelivererTable implements OnInit {
} }
try { try {
const deliverers = updateDelivererComponent.delivererForm.getRawValue(); const deliverers = updateDelivererComponent.delivererForm.getRawValue();
await firstValueFrom(this.deliverersService.updateDelivererEndpoint(id, deliverers)) await firstValueFrom(this.deliverersService.updateDelivererEndpoint(id, deliverers))
this.notificationService.success( this.notificationService.success('Success', 'Transporteur modifié')
'Success',
'Transporteur modifié'
)
} catch (e) { } catch (e) {
console.error(e); this.notificationService.error('Erreur', 'Erreur lors de la modification')
this.notificationService.error(
'Erreur',
'Erreur lors de la modification'
)
} }
} }

View File

@@ -116,25 +116,6 @@ export class DelivereryNoteTable implements OnInit {
this.deliveryNotesLoading.set(false) 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) { async edit(id: number, updateDelivereryNoteComponent: DelivereryNoteForm) {
if (updateDelivereryNoteComponent.deliveryNoteForm.invalid) { if (updateDelivereryNoteComponent.deliveryNoteForm.invalid) {
this.notificationService.error('Erreur', 'Formulaire invalide'); 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;
}
} }

View File

@@ -1,11 +1,11 @@
<form nz-form nzLayout="horizontal" [formGroup]="QuotationForm"> <form nz-form nzLayout="horizontal" [formGroup]="quotationForm">
<nz-form-item nz-flex> <nz-form-item nz-flex>
<nz-form-label nzSpan="9"> <nz-form-label nzSpan="9">
Message du devis Message du devis
</nz-form-label> </nz-form-label>
<nz-form-control nzSpan="12"> <nz-form-control nzSpan="12">
<input nz-input placeholder="Message du devis" formControlName="quotationMessage"> <input nz-input placeholder="Message du devis" formControlName="message">
</nz-form-control> </nz-form-control>
</nz-form-item> </nz-form-item>
@@ -15,7 +15,7 @@
</nz-form-label> </nz-form-label>
<nz-form-control nzSpan="12"> <nz-form-control nzSpan="12">
<input nz-input placeholder="Conditions de vente" formControlName="quotationConditionsSale"> <input nz-input placeholder="Conditions de vente" formControlName="conditionsSale">
</nz-form-control> </nz-form-control>
</nz-form-item> </nz-form-item>
</form> </form>

View File

@@ -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 {FormControl, FormGroup, ReactiveFormsModule, Validators} from "@angular/forms";
import {NzFormControlComponent, NzFormDirective, NzFormItemComponent, NzFormLabelComponent} from "ng-zorro-antd/form"; import {NzFormControlComponent, NzFormDirective, NzFormItemComponent, NzFormLabelComponent} from "ng-zorro-antd/form";
import {NzInputDirective} from "ng-zorro-antd/input"; import {NzInputDirective} from "ng-zorro-antd/input";
import {NzColDirective} from "ng-zorro-antd/grid"; import {NzColDirective} from "ng-zorro-antd/grid";
import {NzFlexDirective} from "ng-zorro-antd/flex"; import {NzFlexDirective} from "ng-zorro-antd/flex";
import {NzDatePickerComponent} from "ng-zorro-antd/date-picker"; import {GetQuotationDto} from "../../services/api";
@Component({ @Component({
selector: 'app-quotation-form', selector: 'app-quotation-form',
@@ -22,8 +22,20 @@ import {NzDatePickerComponent} from "ng-zorro-antd/date-picker";
styleUrl: './quotation-form.css', styleUrl: './quotation-form.css',
}) })
export class QuotationForm { export class QuotationForm {
QuotationForm: FormGroup = new FormGroup({ quotationForm: FormGroup = new FormGroup({
quotationMessage: new FormControl<string>(null), message: new FormControl<string>(null, [Validators.required]),
quotationConditionsSale: new FormControl<string>(null), conditionsSale: new FormControl<string>(null, [Validators.required]),
}) })
quotation= input<GetQuotationDto>();
constructor() {
effect(() => {
if (this.quotation()) {
this.quotationForm.patchValue({
message: this.quotation().message,
conditionsSale: this.quotation().conditionsSale,
});
}
});
}
} }

View File

@@ -52,21 +52,13 @@
</td> </td>
<td> <td>
<div style="justify-content: center; display: flex"> <div style="justify-content: center; display: flex">
<div> <nz-icon nzType="plus-circle" nzTheme="outline" class="cursor-pointer text-green-700" />
<nz-icon nzType="plus-circle" nzTheme="outline" class="cursor-pointer text-green-700" />
</div>
<nz-divider nzType="vertical"></nz-divider> <nz-divider nzType="vertical"></nz-divider>
<app-modal-nav nameIcon="edit" name="Modification du devis" class="cursor-pointer"> <nz-icon nzType="edit" nzTheme="outline" class="cursor-pointer" (click)="openEditModal(quotation)"></nz-icon>
<app-quotation-form></app-quotation-form>
</app-modal-nav>
<nz-divider nzType="vertical"></nz-divider> <nz-divider nzType="vertical"></nz-divider>
<div> <nz-icon nzType="delete" nzTheme="outline" class="cursor-pointer text-red-700" (click)="delete(quotation.id)"/>
<nz-icon nzType="delete" nzTheme="outline" class="cursor-pointer text-red-700" (click)="delete(quotation.id)"/>
</div>
<nz-divider nzType="vertical"></nz-divider> <nz-divider nzType="vertical"></nz-divider>
<div> <nz-icon nzType="export" (click)="export(quotation.id)" nzTheme="outline" class="cursor-pointer text-green-700"/>
<nz-icon nzType="export" (click)="export(quotation.id)" nzTheme="outline" class="cursor-pointer text-green-700"/>
</div>
</div> </div>
</td> </td>
</tr> </tr>
@@ -74,3 +66,8 @@
</tbody> </tbody>
</nz-table> </nz-table>
<div class="hidden">
<app-modal-nav #modalNav nameIcon="edit" [name]="'Modification du devis'" (ok)="onModalOk(selectedQuotation.id, quotationForm, modalNav)" (cancel)="onModalCancel(modalNav)">
<app-quotation-form #quotationForm [quotation]="selectedQuotation"></app-quotation-form>
</app-modal-nav>
</div>

View File

@@ -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 {NzTableComponent} from "ng-zorro-antd/table";
import {ModalButton} from "../modal-button/modal-button"; import {ModalButton} from "../modal-button/modal-button";
import {ModalNav} from "../modal-nav/modal-nav"; 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 {NzNotificationService} from "ng-zorro-antd/notification";
import {firstValueFrom} from "rxjs"; import {firstValueFrom} from "rxjs";
import {FileService} from "../../services/file.service"; import {FileService} from "../../services/file.service";
import {DelivereryNoteForm} from "../deliverery-note-form/deliverery-note-form";
@Component({ @Component({
selector: 'app-quotation-table', selector: 'app-quotation-table',
@@ -19,6 +20,7 @@ import {FileService} from "../../services/file.service";
NzIconDirective, NzIconDirective,
NzTableComponent, NzTableComponent,
QuotationForm, QuotationForm,
DelivereryNoteForm,
], ],
templateUrl: './quotation-table.html', templateUrl: './quotation-table.html',
styleUrl: './quotation-table.css', styleUrl: './quotation-table.css',
@@ -30,6 +32,7 @@ export class QuotationTable implements OnInit {
private fileService = inject(FileService); private fileService = inject(FileService);
quotations = signal<GetQuotationDto[]>([]); quotations = signal<GetQuotationDto[]>([]);
quotationsLoading = signal<boolean>(false); quotationsLoading = signal<boolean>(false);
modal = viewChild.required<ModalNav>('modalNav');
async ngOnInit() { async ngOnInit() {
await this.fetchQuotations(); await this.fetchQuotations();
@@ -84,5 +87,40 @@ export class QuotationTable implements OnInit {
} }
this.quotationsLoading.set(false) 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;
}
} }

View File

@@ -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;
}