This commit is contained in:
Cristiano
2025-12-02 09:07:41 +01:00
parent 4b3faa236d
commit d661e62b0e
13 changed files with 58 additions and 74 deletions

View File

@@ -54,7 +54,7 @@
</nz-table>
<div class="hidden">
<app-modal-icon #modalIcon nameIcon="edit" [name]="'Modifier'" (ok)="onModalOk(selectedAuthor.id, updateAuthor, modalIcon)" (cancel)="onModalCancel(modalIcon)">
<app-modal-icon #modalIcon nameIcon="edit" [name]="'Modifier'" (ok)="onModalOk(selectedAuthor.id)">
<app-update-author #updateAuthor [author]="selectedAuthor"></app-update-author>
</app-modal-icon>
</div>

View File

@@ -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<GetAuthorDto[]>([]);
authorsLoading = signal<boolean>(false);
updateAuthor = viewChild.required<UpdateAuthor>('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;
}
}

View File

@@ -32,7 +32,7 @@
</nz-table>
<div class="hidden">
<app-modal-icon #modalIcon nameIcon="edit" [name]="'Modifier'" (ok)="onModalOk(selectedBook.id, updateBook, modalIcon)" (cancel)="onModalCancel(modalIcon)">
<app-modal-icon #modalIcon nameIcon="edit" [name]="'Modifier'" (ok)="onModalOk(selectedBook.id)">
<app-update-book #updateBook [book]="selectedBook"></app-update-book>
</app-modal-icon>
</div>

View File

@@ -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<GetBookDto[]>([]);
booksLoading = signal<boolean>(false);
updateBook = viewChild.required<UpdateBook>('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;
}
}

View File

@@ -25,7 +25,7 @@
</nz-form-label>
<nz-form-control nzSpan="40" nzErrorTip="Ce champ est requis">
<nz-select formControlName="authorId" [nzPlaceHolder]="'Choisir un auteur'" nzShowSearch [nzFilterOption]="filterAuthor">
<nz-select formControlName="authorId" [nzPlaceHolder]="'Choisir un auteur'">
@for (author of authors(); track author.id) {
<nz-option [nzValue]="author.id" [nzLabel]="author.firstName + ' ' + author.name"></nz-option>
}

View File

@@ -38,7 +38,4 @@ export class CreateBook implements OnInit {
await this.fetchAuthors();
}
filterAuthor(input: string, option: any) {
return option.nzLabel.toLowerCase().includes(input.toLowerCase());
}
}

View File

@@ -5,7 +5,7 @@
</nz-form-label>
<nz-form-control nzSpan="40" nzErrorTip="Ce champ est requis">
<nz-select formControlName="userId" [nzPlaceHolder]="'Choisir un utilisateur'" nzShowSearch [nzFilterOption]="filter">
<nz-select formControlName="userId" [nzPlaceHolder]="'Choisir un utilisateur'">
@for (user of users(); track user.id) {
<nz-option [nzValue]="user.id" [nzLabel]="user.firstName + ' ' + user.name"></nz-option>
}
@@ -19,7 +19,7 @@
</nz-form-label>
<nz-form-control nzSpan="40" nzErrorTip="Ce champ est requis">
<nz-select formControlName="bookId" [nzPlaceHolder]="'Choisir un livre'" nzShowSearch [nzFilterOption]="filter">
<nz-select formControlName="bookId" [nzPlaceHolder]="'Choisir un livre'">
@for (book of books(); track book.id) {
<nz-option [nzValue]="book.id" [nzLabel]="book.title"></nz-option>
}

View File

@@ -61,7 +61,4 @@ export class CreateLoan implements OnInit {
await this.fetchBooks();
}
filter(input: string, option: any) {
return option.nzLabel.toLowerCase().includes(input.toLowerCase());
}
}

View File

@@ -36,7 +36,7 @@
</nz-table>
<div class="hidden">
<app-modal-icon #modalIcon nameIcon="edit" [name]="'Modifier'" (ok)="onModalOk(selectedLoan.id, updateLoan, modalIcon)" (cancel)="onModalCancel(modalIcon)">
<app-modal-icon #modalIcon nameIcon="edit" [name]="'Modifier'" (ok)="onModalOk(selectedLoan.id)">
<app-update-loan #updateLoan [loan]="selectedLoan"></app-update-loan>
</app-modal-icon>
</div>

View File

@@ -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<GetLoanDto[]>([]);
loansLoading = signal<boolean>(false);
updateLoan = viewChild.required<UpdateLoan>('updateLoan');
modal = viewChild.required<ModalIcon>('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;
}
}

View File

@@ -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<string>(null, [Validators.required]),
firstName: new FormControl<string>(null, [Validators.required])
})
author = input.required<GetAuthorDto>()
ngOnChanges() {
if (this.author) {
this.updateAuthorForm.patchValue({

View File

@@ -53,7 +53,7 @@
</nz-table>
<div class="hidden">
<app-modal-icon #modalIcon nameIcon="edit" [name]="'Modifier'" (ok)="onModalOk(selectedUser.id, updateUser, modalIcon)" (cancel)="onModalCancel(modalIcon)">
<app-modal-icon #modalIcon nameIcon="edit" [name]="'Modifier'" (ok)="onModalOk(selectedUser.id)">
<app-update-user #updateUser [user]="selectedUser"></app-update-user>
</app-modal-icon>
</div>

View File

@@ -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<GetUserDto[]>([]);
usersLoading = signal<boolean>(false);
updateUser = viewChild.required<UpdateUser>('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;
}
}