From b55bdedc20dc08d40b51968d24de80448d09ee59 Mon Sep 17 00:00:00 2001 From: Enzo Date: Thu, 27 Nov 2025 18:52:30 +0100 Subject: [PATCH] uptading Supplier Page --- package-lock.json | 29 +-- .../supplier-form/supplier-form.html | 11 +- .../components/supplier-form/supplier-form.ts | 15 +- .../supplier-table/supplier-table.html | 92 ++++---- .../supplier-table/supplier-table.ts | 199 ++++++++---------- src/app/services/api/.openapi-generator/FILES | 1 + src/app/services/api/api.base.service.ts | 2 +- .../services/api/model/get-supplier-dto.ts | 2 + 8 files changed, 148 insertions(+), 203 deletions(-) diff --git a/package-lock.json b/package-lock.json index 488f3a4..0c9a89a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -500,7 +500,6 @@ "resolved": "https://registry.npmjs.org/@angular/common/-/common-20.3.11.tgz", "integrity": "sha512-zQ8xlyUBS+UDAUKk7z/hhWdTtQU2oc/Dwo7jXpyrYlz9y2X1A6sAZpUigdYpbrBkIaNs3MplJevgMiCm3kmN8g==", "license": "MIT", - "peer": true, "dependencies": { "tslib": "^2.3.0" }, @@ -517,7 +516,6 @@ "resolved": "https://registry.npmjs.org/@angular/compiler/-/compiler-20.3.11.tgz", "integrity": "sha512-3O0iMPttD8a4QQQrjVfIjboiZZ17ErkZuqK8BXJBTn2rplpkq1m3kVhgsmzN2OANRR05GF9Ed1dTf8ycTrO1yg==", "license": "MIT", - "peer": true, "dependencies": { "tslib": "^2.3.0" }, @@ -531,7 +529,6 @@ "integrity": "sha512-u6T8kxj7LzK3btEln6Vd8y7p+O1eNXrLiGwqPuRF/QoyjBrRkTYufZ1I4TvzUxdd0ot6mPDRfdmiD15q//Y+oQ==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@babel/core": "7.28.3", "@jridgewell/sourcemap-codec": "^1.4.14", @@ -564,7 +561,6 @@ "resolved": "https://registry.npmjs.org/@angular/core/-/core-20.3.11.tgz", "integrity": "sha512-tOXlxG0SI9Yy1b/ntGyBahfffDpFg7vAbAt+9riOb5ZZ8GYyyOzg78Lqa/lrdBVEG0PXdDjEa0MV93qCyqwYlg==", "license": "MIT", - "peer": true, "dependencies": { "tslib": "^2.3.0" }, @@ -590,7 +586,6 @@ "resolved": "https://registry.npmjs.org/@angular/forms/-/forms-20.3.11.tgz", "integrity": "sha512-jXDvW6a9HUzmLmvgPE+hVoZzc6QJBtQ1kYNn/FZDhbtmjRThJtaMW9YfS0Vz/a9KT9cxBf+8O8Q+yspvgsh3fg==", "license": "MIT", - "peer": true, "dependencies": { "tslib": "^2.3.0" }, @@ -609,7 +604,6 @@ "resolved": "https://registry.npmjs.org/@angular/platform-browser/-/platform-browser-20.3.11.tgz", "integrity": "sha512-hh+8O8m4QzYYlQr9WGew472P37GF1u64NF3HfHmUKJ0xSqqTOHfpni3utev8upJAFJXBKOUZETgeHu2JRcGavg==", "license": "MIT", - "peer": true, "dependencies": { "tslib": "^2.3.0" }, @@ -632,7 +626,6 @@ "resolved": "https://registry.npmjs.org/@angular/router/-/router-20.3.11.tgz", "integrity": "sha512-kuv7Yso7GY3tfRtQN0kW4v2Or4NUEBdjxTz5C8YuAhGDpiKXxDNkXzFliYTVWpJkr3EkTuR9mt9IAc+wxof3Pw==", "license": "MIT", - "peer": true, "dependencies": { "tslib": "^2.3.0" }, @@ -714,7 +707,6 @@ "integrity": "sha512-yDBHV9kQNcr2/sUr9jghVyz9C3Y5G2zUM2H2lo+9mKv4sFgbA8s8Z9t8D1jiTkGoO/NoIfKMyKWr4s6CN23ZwQ==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@ampproject/remapping": "^2.2.0", "@babel/code-frame": "^7.27.1", @@ -1656,7 +1648,6 @@ "integrity": "sha512-nqhDw2ZcAUrKNPwhjinJny903bRhI0rQhiDz1LksjeRxqa36i3l75+4iXbOy0rlDpLJGxqtgoPavQjmmyS5UJw==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@inquirer/checkbox": "^4.2.1", "@inquirer/confirm": "^5.1.14", @@ -2516,7 +2507,6 @@ "resolved": "https://registry.npmjs.org/@nestjs/common/-/common-11.1.9.tgz", "integrity": "sha512-zDntUTReRbAThIfSp3dQZ9kKqI+LjgLp5YZN5c1bgNRDuoeLySAoZg46Bg1a+uV8TMgIRziHocglKGNzr6l+bQ==", "license": "MIT", - "peer": true, "dependencies": { "file-type": "21.1.0", "iterare": "1.2.1", @@ -4280,7 +4270,6 @@ "resolved": "https://registry.npmjs.org/axios/-/axios-1.13.2.tgz", "integrity": "sha512-VPk9ebNqPcy5lRGuSlKx752IlDatOjT9paPlm8A7yOuW2Fbvp4X3JznJtT4f0GzGLLiWE9W8onz51SqLYwzGaA==", "license": "MIT", - "peer": true, "dependencies": { "follow-redirects": "^1.15.6", "form-data": "^4.0.4", @@ -4448,7 +4437,6 @@ } ], "license": "MIT", - "peer": true, "dependencies": { "baseline-browser-mapping": "^2.8.25", "caniuse-lite": "^1.0.30001754", @@ -5647,7 +5635,6 @@ "integrity": "sha512-DT9ck5YIRU+8GYzzU5kT3eHGA5iL+1Zd0EutOmTE9Dtk+Tvuzd23VBU+ec7HPNSTxXYO55gPV/hq4pSBJDjFpA==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "accepts": "^2.0.0", "body-parser": "^2.2.0", @@ -6903,7 +6890,6 @@ "integrity": "sha512-j1n1IuTX1VQjIy3tT7cyGbX7nvQOsFLoIqobZv4ttI5axP923gA44zUj6miiA6R5Aoms4sEGVIIcucXUbRI14g==", "devOptional": true, "license": "Apache-2.0", - "peer": true, "dependencies": { "copy-anything": "^2.0.1", "parse-node-version": "^1.0.1", @@ -7191,7 +7177,6 @@ "integrity": "sha512-SL0JY3DaxylDuo/MecFeiC+7pedM0zia33zl0vcjgwcq1q1FWWF1To9EIauPbl8GbMCU0R2e0uJ8bZunhYKD2g==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "cli-truncate": "^4.0.0", "colorette": "^2.0.20", @@ -8847,8 +8832,7 @@ "version": "0.2.2", "resolved": "https://registry.npmjs.org/reflect-metadata/-/reflect-metadata-0.2.2.tgz", "integrity": "sha512-urBwgfrvVP/eAyXx4hluJivBKzuEbSQs9rKWCrCkbSxNv8mxPcUZKeuoF3Uy4mJl3Lwprp6yy5/39VWigZ4K6Q==", - "license": "Apache-2.0", - "peer": true + "license": "Apache-2.0" }, "node_modules/require-directory": { "version": "2.1.1", @@ -8996,7 +8980,6 @@ "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.8.2.tgz", "integrity": "sha512-dhKf903U/PQZY6boNNtAGdWbG85WAbjT/1xYoZIC7FAY0yWapOBQVsVrDl58W86//e1VpMNBtRV4MaXfdMySFA==", "license": "Apache-2.0", - "peer": true, "dependencies": { "tslib": "^2.1.0" } @@ -9033,7 +9016,6 @@ "integrity": "sha512-9GUyuksjw70uNpb1MTYWsH9MQHOHY6kwfnkafC24+7aOMZn9+rVMBxRbLvw756mrBFbIsFg6Xw9IkR2Fnn3k+Q==", "devOptional": true, "license": "MIT", - "peer": true, "dependencies": { "chokidar": "^4.0.0", "immutable": "^5.0.2", @@ -9782,8 +9764,7 @@ "version": "2.8.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz", "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==", - "license": "0BSD", - "peer": true + "license": "0BSD" }, "node_modules/tuf-js": { "version": "3.1.0", @@ -9833,7 +9814,6 @@ "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", "dev": true, "license": "Apache-2.0", - "peer": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" @@ -9994,7 +9974,6 @@ "resolved": "https://registry.npmjs.org/vite/-/vite-7.1.11.tgz", "integrity": "sha512-uzcxnSDVjAopEUjljkWh8EIrg6tlzrjFUfMcR1EVsRDGwf/ccef0qQPRyOrROwhrTDaApueq+ja+KLPlzR/zdg==", "license": "MIT", - "peer": true, "dependencies": { "esbuild": "^0.25.0", "fdir": "^6.5.0", @@ -10382,7 +10361,6 @@ "integrity": "sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ==", "dev": true, "license": "MIT", - "peer": true, "funding": { "url": "https://github.com/sponsors/colinhacks" } @@ -10401,8 +10379,7 @@ "version": "0.15.1", "resolved": "https://registry.npmjs.org/zone.js/-/zone.js-0.15.1.tgz", "integrity": "sha512-XE96n56IQpJM7NAoXswY3XRLcWFW83xe0BiAOeMD7K5k5xecOeul3Qcpx6GqEeeHNkW5DWL5zOyTbEfB4eti8w==", - "license": "MIT", - "peer": true + "license": "MIT" } } } diff --git a/src/app/components/supplier-form/supplier-form.html b/src/app/components/supplier-form/supplier-form.html index 1b7e80d..8702c8d 100644 --- a/src/app/components/supplier-form/supplier-form.html +++ b/src/app/components/supplier-form/supplier-form.html @@ -1,4 +1,4 @@ -
+ @@ -54,13 +54,4 @@ - - - Produits - - - - - -
diff --git a/src/app/components/supplier-form/supplier-form.ts b/src/app/components/supplier-form/supplier-form.ts index 87895f2..b51f003 100644 --- a/src/app/components/supplier-form/supplier-form.ts +++ b/src/app/components/supplier-form/supplier-form.ts @@ -1,9 +1,10 @@ -import { Component } from '@angular/core'; +import {Component, input} from '@angular/core'; 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 {FormControl, FormGroup, ReactiveFormsModule, Validators} from "@angular/forms"; +import {GetSupplierDto} from "../../services/api"; @Component({ selector: 'app-supplier-form', @@ -28,18 +29,8 @@ export class SupplierForm { address: new FormControl(null, [Validators.required]), city: new FormControl(null, [Validators.required]), deliveryDelay: new FormControl(null, [Validators.required]), - product: new FormControl(null, [Validators.required]), }) + supplier= input.required() - submitForm() { - // Pour annuler si le formulaire est invalide - if (this.supplierForm.invalid) return; - - // Pour obtenir la valeur du formulaire - console.log(this.supplierForm.getRawValue()) - - // Pour vider le formulaire - this.supplierForm.reset() - } } diff --git a/src/app/components/supplier-table/supplier-table.html b/src/app/components/supplier-table/supplier-table.html index b26448e..7a9cb69 100644 --- a/src/app/components/supplier-table/supplier-table.html +++ b/src/app/components/supplier-table/supplier-table.html @@ -1,61 +1,63 @@ - + - + Nom - email - Téléphone - Adresse - Ville - Délai Moyen - Produits - Action + Prénom + Email + Anniversaire + Emprunt + Action - - @for (data of basicTable.data; track data) { + + @for (supplier of suppliers(); track supplier.id) { - {{data.name}} - {{data.email}} - {{data.phone}} - {{data.address}}, {{data.zipCode}} - {{data.city}} - {{data.deliveryDelay}} + {{ supplier.name }} + {{ supplier.phone }} + {{ supplier.email }} + {{ supplier.address}} + {{ supplier.zipCode}} + {{ supplier.city}} + {{ supplier.deliveryDelay}} - -
- - - - Nom - Référence - Prix - - - - @for (product of data.products; track product) { - - {{product.name}} - {{product.reference}} - xx.x€ - - } - - -
+ + + + + Produits + Nom + Référence + Prix + + + + @for (product of supplier.products; track product.id) { + + {{ product.name }} + {{ product.references }} + Price ??? + + } + + -
- - - +
+ -
- -
+
} + + diff --git a/src/app/components/supplier-table/supplier-table.ts b/src/app/components/supplier-table/supplier-table.ts index e6f9d25..03bd41c 100644 --- a/src/app/components/supplier-table/supplier-table.ts +++ b/src/app/components/supplier-table/supplier-table.ts @@ -1,13 +1,14 @@ -import { Component } from '@angular/core'; +import {Component, inject, signal, viewChild} from '@angular/core'; import {ModalNav} from "../modal-nav/modal-nav"; import {NzDividerComponent} from "ng-zorro-antd/divider"; import {NzIconDirective} from "ng-zorro-antd/icon"; import {NzTableComponent} from "ng-zorro-antd/table"; import {ModalButton} from "../modal-button/modal-button"; -import {DatePipe} from "@angular/common"; import {SupplierForm} from "../supplier-form/supplier-form"; -import {SupplierInfo} from "../../interfaces/supplier.interface"; -import {DelivererForm} from "../deliverer-form/deliverer-form"; +import {GetSupplierDto, SuppliersService} from "../../services/api"; +import {NzNotificationService} from "ng-zorro-antd/notification"; +import {firstValueFrom} from "rxjs"; +import {format} from "date-fns"; @Component({ selector: 'app-supplier-table', @@ -24,111 +25,91 @@ import {DelivererForm} from "../deliverer-form/deliverer-form"; }) export class SupplierTable { - listOfSupplier: SupplierInfo[] = [ - { - name: "PyroNova", - email: "contact@pyronova.com", - phone: "+33 1 45 23 67 89", - address: "12 Rue des Artisans", - zipCode: "69003", - city: "Lyon", - deliveryDelay: 4, - products: [] - }, - { - name: "FX Industries", - email: "sales@fxindus.com", - phone: "+33 2 41 22 90 10", - address: "118 Avenue Lumière", - zipCode: "49000", - city: "Angers", - deliveryDelay: 6, - products: [] - }, - { - name: "EuroFire", - email: "info@eurofire.eu", - phone: "+33 1 80 22 11 77", - address: "2 Avenue de l’Europe", - zipCode: "75012", - city: "Paris", - deliveryDelay: 3, - products: [] - }, - { - name: "FlashEffect", - email: "contact@flasheffect.fr", - phone: "+33 4 72 81 91 22", - address: "44 Rue Centrale", - zipCode: "69007", - city: "Lyon", - deliveryDelay: 5, - products: [] - }, - { - name: "StageLight FX", - email: "support@stagelightfx.com", - phone: "+33 5 55 74 99 31", - address: "99 Boulevard du Progrès", - zipCode: "31000", - city: "Toulouse", - deliveryDelay: 7, - products: [] - }, - { - name: "NovaSpark", - email: "hello@novaspark.fr", - phone: "+33 3 29 55 11 88", - address: "7 Rue de la Source", - zipCode: "54000", - city: "Nancy", - deliveryDelay: 4, - products: [] - }, - { - name: "FXWare", - email: "contact@fxware.eu", - phone: "+33 4 75 55 66 44", - address: "123 Route du Nord", - zipCode: "38000", - city: "Grenoble", - deliveryDelay: 6, - products: [] - }, - { - name: "PyroSet", - email: "info@pyroset.com", - phone: "+33 1 61 73 55 00", - address: "5 Chemin des Prés", - zipCode: "95000", - city: "Cergy", - deliveryDelay: 2, - products: [] - }, - { - name: "SkyFX", - email: "support@skyfx.fr", - phone: "+33 6 55 88 22 11", - address: "1 Rue du Ciel", - zipCode: "33000", - city: "Bordeaux", - deliveryDelay: 5, - products: [] - }, - { - name: "SparkLab", - email: "sales@sparklab.eu", - phone: "+33 2 33 55 77 12", - address: "33 Rue du Port", - zipCode: "14000", - city: "Caen", - deliveryDelay: 4, - products: [] - } - ]; + private suppliersService = inject(SuppliersService); + private notificationService = inject(NzNotificationService) + suppliers = signal([]); + suppliersLoading = signal(false); + updateSupplier = viewChild.required('supplierForm'); + modal = viewChild.required('modalNav'); - delete() { - return + async ngOnInit() { + await this.fetchSuppliers(); } -} + async fetchSuppliers() { + this.suppliersLoading.set(true) + + try { + const suppliers = await firstValueFrom(this.suppliersService.getAllSuppliersEndpoint()) + this.suppliers.set(suppliers); + } catch (e) { + 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(); + } + + async edit(id: number, updateSupplierComponent: SupplierForm) { + if (updateSupplierComponent.supplierForm.invalid) { + 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é' + ) + } catch (e) { + this.notificationService.error( + 'Erreur', + 'Erreur lors de la modification' + ) + } + } + + selectedSupplier: GetSupplierDto | null = null; + openEditModal(supplier: GetSupplierDto) { + this.selectedSupplier = { ...supplier }; + this.modal().showModal(); + } + + async onModalOk(supplierId: number, updateSupplierComponent: SupplierForm, modal: ModalNav) { + if (!this.selectedSupplier) return; + + await this.edit(supplierId, updateSupplierComponent); + updateSupplierComponent.supplierForm.reset(); + modal.isVisible = false; + await this.fetchSuppliers(); + } + + onModalCancel(modal: ModalNav) { + modal.isVisible = false; + } +} \ No newline at end of file diff --git a/src/app/services/api/.openapi-generator/FILES b/src/app/services/api/.openapi-generator/FILES index 72ed5fa..3d6d1ae 100644 --- a/src/app/services/api/.openapi-generator/FILES +++ b/src/app/services/api/.openapi-generator/FILES @@ -1,4 +1,5 @@ .gitignore +.openapi-generator-ignore README.md api.base.service.ts api.module.ts diff --git a/src/app/services/api/api.base.service.ts b/src/app/services/api/api.base.service.ts index 34531a6..1e0f210 100644 --- a/src/app/services/api/api.base.service.ts +++ b/src/app/services/api/api.base.service.ts @@ -12,7 +12,7 @@ import { CustomHttpParameterCodec } from './encoder'; import { Configuration } from './configuration'; export class BaseService { - protected basePath = 'https://localhost:44379'; + protected basePath = 'http://localhost:5298'; public defaultHeaders = new HttpHeaders(); public configuration: Configuration; public encoder: HttpParameterCodec; diff --git a/src/app/services/api/model/get-supplier-dto.ts b/src/app/services/api/model/get-supplier-dto.ts index 35345b0..378eb06 100644 --- a/src/app/services/api/model/get-supplier-dto.ts +++ b/src/app/services/api/model/get-supplier-dto.ts @@ -7,6 +7,7 @@ * https://openapi-generator.tech * Do not edit the class manually. */ +import { GetProductDto } from './get-product-dto'; export interface GetSupplierDto { @@ -18,5 +19,6 @@ export interface GetSupplierDto { zipCode?: string | null; city?: string | null; deliveryDelay?: number; + products?: Array | null; }