From d661e62b0e1a1a9dd1e9e06514be452de8edf855 Mon Sep 17 00:00:00 2001 From: Cristiano Date: Tue, 2 Dec 2025 09:07:41 +0100 Subject: [PATCH] changed --- .../components/author-table/author-table.html | 2 +- .../components/author-table/author-table.ts | 22 +++++------ src/app/components/book-table/book-table.html | 2 +- src/app/components/book-table/book-table.ts | 23 +++++------- .../components/create-book/create-book.html | 2 +- src/app/components/create-book/create-book.ts | 3 -- .../components/create-loan/create-loan.html | 4 +- src/app/components/create-loan/create-loan.ts | 3 -- src/app/components/loan-table/loan-table.html | 2 +- src/app/components/loan-table/loan-table.ts | 37 +++++++++---------- .../components/update-author/update-author.ts | 5 ++- src/app/components/user-table/user-table.html | 2 +- src/app/components/user-table/user-table.ts | 25 ++++++------- 13 files changed, 58 insertions(+), 74 deletions(-) diff --git a/src/app/components/author-table/author-table.html b/src/app/components/author-table/author-table.html index b0a5001..2d5039a 100644 --- a/src/app/components/author-table/author-table.html +++ b/src/app/components/author-table/author-table.html @@ -54,7 +54,7 @@ diff --git a/src/app/components/author-table/author-table.ts b/src/app/components/author-table/author-table.ts index 61a2f6b..5fcf7d2 100644 --- a/src/app/components/author-table/author-table.ts +++ b/src/app/components/author-table/author-table.ts @@ -25,6 +25,7 @@ import {NzIconDirective} from "ng-zorro-antd/icon"; export class AuthorTable implements OnInit { private authorsService = inject(AuthorsService); private notificationService = inject(NzNotificationService) + authors = signal([]); authorsLoading = signal(false); updateAuthor = viewChild.required('updateAuthor'); @@ -51,9 +52,9 @@ export class AuthorTable implements OnInit { this.authorsLoading.set(false) } - async delete(author:number) { + async delete(id) { try { - await firstValueFrom(this.authorsService.deleteAuthorEndpoint(author)) + await firstValueFrom(this.authorsService.deleteAuthorEndpoint(id)) this.notificationService.success( 'Success', 'Suppression effectuée' @@ -67,8 +68,8 @@ export class AuthorTable implements OnInit { await this.fetchAuthors(); } - async edit(id: number, updateAuthorComponent: UpdateAuthor) { - if (updateAuthorComponent.updateAuthorForm.invalid) { + async edit(id) { + if (this.updateAuthor().updateAuthorForm.invalid) { this.notificationService.error( 'Erreur', 'Erreur d\'écriture dans le formulaire' @@ -77,7 +78,7 @@ export class AuthorTable implements OnInit { } try { - const authors = updateAuthorComponent.updateAuthorForm.getRawValue(); + const authors = this.updateAuthor().updateAuthorForm.getRawValue(); await firstValueFrom(this.authorsService.updateAuthorEndpoint(id, authors)) @@ -99,14 +100,9 @@ export class AuthorTable implements OnInit { this.modal().showModal(); } - async onModalOk(authorId: number, updateAuthorComponent: UpdateAuthor, modal: ModalIcon) { - await this.edit(authorId, updateAuthorComponent); - updateAuthorComponent.updateAuthorForm.reset(); - modal.isVisible = false; + async onModalOk(authorId) { + await this.edit(authorId); + this.updateAuthor().updateAuthorForm.reset(); await this.fetchAuthors(); } - - onModalCancel(modal: ModalIcon) { - modal.isVisible = false; - } } diff --git a/src/app/components/book-table/book-table.html b/src/app/components/book-table/book-table.html index 8362f5c..857a8f1 100644 --- a/src/app/components/book-table/book-table.html +++ b/src/app/components/book-table/book-table.html @@ -32,7 +32,7 @@ \ No newline at end of file diff --git a/src/app/components/book-table/book-table.ts b/src/app/components/book-table/book-table.ts index 064d8f8..de5e727 100644 --- a/src/app/components/book-table/book-table.ts +++ b/src/app/components/book-table/book-table.ts @@ -24,6 +24,7 @@ import {NzIconDirective} from "ng-zorro-antd/icon"; export class BookTable implements OnInit { private booksService = inject(BooksService); private notificationService = inject(NzNotificationService) + books = signal([]); booksLoading = signal(false); updateBook = viewChild.required('updateBook'); @@ -51,9 +52,9 @@ export class BookTable implements OnInit { this.booksLoading.set(false) } - async delete(book:number) { + async delete(bookId) { try { - await firstValueFrom(this.booksService.deleteBookEndpoint(book)) + await firstValueFrom(this.booksService.deleteBookEndpoint(bookId)) this.notificationService.success( 'Success', 'Suppression effectuée' @@ -67,8 +68,8 @@ export class BookTable implements OnInit { await this.fetchBooks(); } - async edit(id: number, updateBookComponent: UpdateBook) { - if (updateBookComponent.updateBookForm.invalid) { + async edit(id) { + if (this.updateBook().updateBookForm.invalid) { this.notificationService.error( 'Erreur', 'Erreur d\'écriture dans le formulaire' @@ -77,7 +78,7 @@ export class BookTable implements OnInit { } try { - const books = updateBookComponent.updateBookForm.getRawValue(); + const books = this.updateBook().updateBookForm.getRawValue(); await firstValueFrom(this.booksService.updateBookEndpoint(id, books)) console.log("Payload envoyé :", books); @@ -95,20 +96,16 @@ export class BookTable implements OnInit { } selectedBook: GetBookDto | null = null; - openEditModal(book: GetBookDto) { + openEditModal(book) { this.selectedBook = { ...book }; this.modal().showModal(); } - async onModalOk(bookId: number, updateBookComponent: UpdateBook, modal: ModalIcon) { - await this.edit(bookId, updateBookComponent); - updateBookComponent.updateBookForm.reset(); - modal.isVisible = false; + async onModalOk(bookId) { + await this.edit(bookId); + this.updateBook().updateBookForm.reset(); await this.fetchBooks(); } - onModalCancel(modal: ModalIcon) { - modal.isVisible = false; - } } diff --git a/src/app/components/create-book/create-book.html b/src/app/components/create-book/create-book.html index 4f8ab5f..7726c8a 100644 --- a/src/app/components/create-book/create-book.html +++ b/src/app/components/create-book/create-book.html @@ -25,7 +25,7 @@ - + @for (author of authors(); track author.id) { } diff --git a/src/app/components/create-book/create-book.ts b/src/app/components/create-book/create-book.ts index 19098d4..b00b672 100644 --- a/src/app/components/create-book/create-book.ts +++ b/src/app/components/create-book/create-book.ts @@ -38,7 +38,4 @@ export class CreateBook implements OnInit { await this.fetchAuthors(); } - filterAuthor(input: string, option: any) { - return option.nzLabel.toLowerCase().includes(input.toLowerCase()); - } } diff --git a/src/app/components/create-loan/create-loan.html b/src/app/components/create-loan/create-loan.html index 2216db8..5f4b071 100644 --- a/src/app/components/create-loan/create-loan.html +++ b/src/app/components/create-loan/create-loan.html @@ -5,7 +5,7 @@ - + @for (user of users(); track user.id) { } @@ -19,7 +19,7 @@ - + @for (book of books(); track book.id) { } diff --git a/src/app/components/create-loan/create-loan.ts b/src/app/components/create-loan/create-loan.ts index d45d75c..bf14d1e 100644 --- a/src/app/components/create-loan/create-loan.ts +++ b/src/app/components/create-loan/create-loan.ts @@ -61,7 +61,4 @@ export class CreateLoan implements OnInit { await this.fetchBooks(); } - filter(input: string, option: any) { - return option.nzLabel.toLowerCase().includes(input.toLowerCase()); - } } diff --git a/src/app/components/loan-table/loan-table.html b/src/app/components/loan-table/loan-table.html index 7db9b23..684536f 100644 --- a/src/app/components/loan-table/loan-table.html +++ b/src/app/components/loan-table/loan-table.html @@ -36,7 +36,7 @@ \ No newline at end of file diff --git a/src/app/components/loan-table/loan-table.ts b/src/app/components/loan-table/loan-table.ts index 1173314..52d2b32 100644 --- a/src/app/components/loan-table/loan-table.ts +++ b/src/app/components/loan-table/loan-table.ts @@ -11,7 +11,7 @@ import {NzIconDirective} from "ng-zorro-antd/icon"; import {format} from "date-fns"; @Component({ - selector: 'app-loan-table', + selector: 'app-loan-table', imports: [ DatePipe, NzTableComponent, @@ -20,14 +20,15 @@ import {format} from "date-fns"; ModalIcon, NzIconDirective, ], - templateUrl: './loan-table.html', - styleUrl: './loan-table.css', + templateUrl: './loan-table.html', + styleUrl: './loan-table.css', }) export class LoanTable implements OnInit { private loansService = inject(LoansService); private notificationService = inject(NzNotificationService) loans = signal([]); loansLoading = signal(false); + updateLoan = viewChild.required('updateLoan'); modal = viewChild.required('modalIcon'); @@ -68,8 +69,8 @@ export class LoanTable implements OnInit { await this.fetchLoans(); } - async edit(id: number, updateLoanComponent: UpdateLoan) { - if (updateLoanComponent.updateLoanForm.invalid) { + async edit(id) { + if (this.updateLoan().updateLoanForm.invalid) { this.notificationService.error( 'Erreur', 'Erreur d\'écriture dans le formulaire' @@ -78,20 +79,20 @@ export class LoanTable implements OnInit { } try { - const plannedDate = updateLoanComponent.updateLoanForm.get('plannedReturningDate').value; + const plannedDate = this.updateLoan().updateLoanForm.get('plannedReturningDate').value; const plannedDateResult = format(plannedDate, 'yyyy-MM-dd'); - const effectiveDate = updateLoanComponent.updateLoanForm.get('effectiveReturningDate').value; + const effectiveDate = this.updateLoan().updateLoanForm.get('effectiveReturningDate').value; const effectiveDateResult = format(effectiveDate, 'yyyy-MM-dd'); - const loans = updateLoanComponent.updateLoanForm.getRawValue(); + const loans = this.updateLoan().updateLoanForm.getRawValue(); loans.plannedReturningDate = plannedDateResult; loans.effectiveReturningDate = effectiveDateResult; const updatedLoanDto = { id: this.selectedLoan.id, - bookId: updateLoanComponent.updateLoanForm.get('bookId').value, - userId: updateLoanComponent.updateLoanForm.get('userId').value, + bookId: this.updateLoan().updateLoanForm.get('bookId').value, + userId: this.updateLoan().updateLoanForm.get('userId').value, date: this.selectedLoan.date, plannedReturningDate: loans.plannedReturningDate, effectiveReturningDate: loans.effectiveReturningDate @@ -111,7 +112,7 @@ export class LoanTable implements OnInit { } } - async validationDate(loanId: number) { + async validationDate(loanId ) { try { const PatchLoanValue = { @@ -142,19 +143,17 @@ export class LoanTable implements OnInit { } selectedLoan: GetLoanDto | null = null; - openEditModal(loan: GetLoanDto) { + + openEditModal(loan) { this.selectedLoan = { ...loan }; this.modal().showModal(); } - async onModalOk(loanId: number, updateLoanComponent: UpdateLoan, modal: ModalIcon) { - await this.edit(loanId, updateLoanComponent); - updateLoanComponent.updateLoanForm.reset(); - modal.isVisible = false; + async onModalOk(loanId) { + await this.edit(loanId); + this.updateLoan().updateLoanForm.reset(); await this.fetchLoans(); } - onModalCancel(modal: ModalIcon) { - modal.isVisible = false; - } + } diff --git a/src/app/components/update-author/update-author.ts b/src/app/components/update-author/update-author.ts index d90e408..65b94d7 100644 --- a/src/app/components/update-author/update-author.ts +++ b/src/app/components/update-author/update-author.ts @@ -1,4 +1,4 @@ -import {Component, input} from '@angular/core'; +import {Component, input, OnChanges, OnInit} from '@angular/core'; import {FormControl, FormGroup, FormsModule, ReactiveFormsModule, Validators} from "@angular/forms"; import {NzColDirective, NzRowDirective} from "ng-zorro-antd/grid"; import {NzFormControlComponent, NzFormDirective, NzFormItemComponent, NzFormLabelComponent} from "ng-zorro-antd/form"; @@ -21,13 +21,14 @@ import {NzInputDirective} from "ng-zorro-antd/input"; templateUrl: './update-author.html', styleUrl: './update-author.css', }) -export class UpdateAuthor { +export class UpdateAuthor implements OnChanges { updateAuthorForm = new FormGroup({ name: new FormControl(null, [Validators.required]), firstName: new FormControl(null, [Validators.required]) }) author = input.required() + ngOnChanges() { if (this.author) { this.updateAuthorForm.patchValue({ diff --git a/src/app/components/user-table/user-table.html b/src/app/components/user-table/user-table.html index 620ebbb..0df8545 100644 --- a/src/app/components/user-table/user-table.html +++ b/src/app/components/user-table/user-table.html @@ -53,7 +53,7 @@ diff --git a/src/app/components/user-table/user-table.ts b/src/app/components/user-table/user-table.ts index 85aba68..047dd2d 100644 --- a/src/app/components/user-table/user-table.ts +++ b/src/app/components/user-table/user-table.ts @@ -1,4 +1,4 @@ -import {Component, inject, input, OnInit, signal, viewChild} from '@angular/core'; +import {Component, inject,OnInit, signal, viewChild} from '@angular/core'; import {NzTableComponent} from "ng-zorro-antd/table"; import {Modal} from "../modal/modal"; import {DatePipe} from "@angular/common"; @@ -28,6 +28,7 @@ import {format} from "date-fns"; export class UserTable implements OnInit { private usersService = inject(UsersService); private notificationService = inject(NzNotificationService) + users = signal([]); usersLoading = signal(false); updateUser = viewChild.required('updateUser'); @@ -52,9 +53,9 @@ export class UserTable implements OnInit { this.usersLoading.set(false) } - async delete(user:number) { + async delete(userId) { try { - await firstValueFrom(this.usersService.deleteUserEndpoint(user)) + await firstValueFrom(this.usersService.deleteUserEndpoint(userId)) this.notificationService.success( 'Success', 'Suppression effectuée' @@ -68,8 +69,8 @@ export class UserTable implements OnInit { await this.fetchUsers(); } - async edit(id: number, updateUserComponent: UpdateUser) { - if (updateUserComponent.updateUserForm.invalid) { + async edit(id) { + if (this.updateUser().updateUserForm.invalid) { this.notificationService.error( 'Erreur', 'Erreur d\'écriture dans le formulaire' @@ -78,10 +79,10 @@ export class UserTable implements OnInit { } try { - const rawDate = updateUserComponent.updateUserForm.get('birthDate').value; + const rawDate = this.updateUser().updateUserForm.get('birthDate').value; const birthDate = format(rawDate, 'yyyy-MM-dd'); - const users = updateUserComponent.updateUserForm.getRawValue(); + const users = this.updateUser().updateUserForm.getRawValue(); users.birthDate = birthDate; await firstValueFrom(this.usersService.updateUserEndpoint(id, users)) @@ -104,14 +105,10 @@ export class UserTable implements OnInit { this.modal().showModal(); } - async onModalOk(userId: number, updateUserComponent: UpdateUser, modal: ModalIcon) { - await this.edit(userId, updateUserComponent); - updateUserComponent.updateUserForm.reset(); - modal.isVisible = false; + async onModalOk(userId) { + await this.edit(userId); + this.updateUser().updateUserForm.reset(); await this.fetchUsers(); } - onModalCancel(modal: ModalIcon) { - modal.isVisible = false; - } }