diff --git a/src/app/components/author-table/author-table.html b/src/app/components/author-table/author-table.html
index be4e7c5..539f33d 100644
--- a/src/app/components/author-table/author-table.html
+++ b/src/app/components/author-table/author-table.html
@@ -41,7 +41,7 @@
|
-
+
@@ -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 8b2db78..61a2f6b 100644
--- a/src/app/components/author-table/author-table.ts
+++ b/src/app/components/author-table/author-table.ts
@@ -1,4 +1,4 @@
-import {Component, inject, OnInit, signal} from '@angular/core';
+import {Component, inject, OnInit, signal, viewChild} from '@angular/core';
import {Modal} from "../modal/modal";
import {AuthorsService, GetAuthorDto} from "../../services/api";
import {NzNotificationService} from "ng-zorro-antd/notification";
@@ -25,16 +25,16 @@ 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');
+ modal = viewChild.required('modalIcon');
async ngOnInit() {
- await this.fetchauthors();
+ await this.fetchAuthors();
}
- async fetchauthors() {
+ async fetchAuthors() {
this.authorsLoading.set(true)
try {
@@ -64,6 +64,49 @@ export class AuthorTable implements OnInit {
'Impossible de supprimer la ligne'
)
}
- await this.fetchauthors();
+ await this.fetchAuthors();
+ }
+
+ async edit(id: number, updateAuthorComponent: UpdateAuthor) {
+ if (updateAuthorComponent.updateAuthorForm.invalid) {
+ this.notificationService.error(
+ 'Erreur',
+ 'Erreur d\'écriture dans le formulaire'
+ )
+ return;
+ }
+
+ try {
+ const authors = updateAuthorComponent.updateAuthorForm.getRawValue();
+
+ await firstValueFrom(this.authorsService.updateAuthorEndpoint(id, authors))
+
+ this.notificationService.success(
+ 'Success',
+ 'Auteur modifié'
+ )
+ } catch (e) {
+ this.notificationService.error(
+ 'Erreur',
+ 'Erreur lors de la modification'
+ )
+ }
+ }
+
+ selectedAuthor: GetAuthorDto | null = null;
+ openEditModal(author: GetAuthorDto) {
+ this.selectedAuthor = { ...author };
+ this.modal().showModal();
+ }
+
+ async onModalOk(authorId: number, updateAuthorComponent: UpdateAuthor, modal: ModalIcon) {
+ await this.edit(authorId, updateAuthorComponent);
+ updateAuthorComponent.updateAuthorForm.reset();
+ modal.isVisible = false;
+ 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 bb2a7db..0164d6c 100644
--- a/src/app/components/book-table/book-table.html
+++ b/src/app/components/book-table/book-table.html
@@ -15,12 +15,12 @@
| {{ book.title}} |
{{ book.isbn }} |
- {{ book.bookAuthorName }} {{ book.bookAuthorFirstName }} |
+ {{ book.bookAuthorFirstName }} {{ book.bookAuthorName }} |
{{ book.releaseYear}} |
|
-
+
@@ -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 e972efe..75e0f54 100644
--- a/src/app/components/book-table/book-table.ts
+++ b/src/app/components/book-table/book-table.ts
@@ -1,4 +1,4 @@
-import {Component, inject, OnInit, signal} from '@angular/core'; // Importation de la fonction input() et des components
+import {Component, inject, OnInit, signal, viewChild} from '@angular/core'; // Importation de la fonction input() et des components
import {BooksService, GetBookDto} from "../../services/api";
import {NzNotificationService} from "ng-zorro-antd/notification";
import {firstValueFrom} from "rxjs";
@@ -20,19 +20,20 @@ import {NzIconDirective} from "ng-zorro-antd/icon";
templateUrl: './book-table.html',
styleUrl: './book-table.css',
})
+
export class BookTable implements OnInit {
private booksService = inject(BooksService);
private notificationService = inject(NzNotificationService)
-
books = signal([]);
-
booksLoading = signal(false);
+ updateBook = viewChild.required('updateBook');
+ modal = viewChild.required('modalIcon');
async ngOnInit() {
- await this.fetchbooks();
+ await this.fetchBooks();
}
- async fetchbooks() {
+ async fetchBooks() {
this.booksLoading.set(true)
try {
@@ -63,6 +64,51 @@ export class BookTable implements OnInit {
'Impossible de supprimer la ligne'
)
}
- await this.fetchbooks();
+ await this.fetchBooks();
+ }
+
+ async edit(id: number, updateBookComponent: UpdateBook) {
+ if (updateBookComponent.updateBookForm.invalid) {
+ this.notificationService.error(
+ 'Erreur',
+ 'Erreur d\'écriture dans le formulaire'
+ )
+ return;
+ }
+
+ try {
+ const books = updateBookComponent.updateBookForm.getRawValue();
+
+ await firstValueFrom(this.booksService.updateBookEndpoint(id, books))
+ console.log("Payload envoyé :", books);
+
+ this.notificationService.success(
+ 'Success',
+ 'Livre modifié'
+ )
+ } catch (e) {
+ this.notificationService.error(
+ 'Erreur',
+ 'Erreur lors de la modification'
+ )
+ }
+ }
+
+ selectedBook: GetBookDto | null = null;
+ openEditModal(book: GetBookDto) {
+ 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;
+ await this.fetchBooks();
+ }
+
+ onModalCancel(modal: ModalIcon) {
+ modal.isVisible = false;
}
}
+
diff --git a/src/app/components/update-author/update-author.html b/src/app/components/update-author/update-author.html
index 00188de..9f61d5c 100644
--- a/src/app/components/update-author/update-author.html
+++ b/src/app/components/update-author/update-author.html
@@ -1,4 +1,4 @@
-
\ No newline at end of file
diff --git a/src/app/components/update-book/update-book.ts b/src/app/components/update-book/update-book.ts
index fe1eebf..bf98f91 100644
--- a/src/app/components/update-book/update-book.ts
+++ b/src/app/components/update-book/update-book.ts
@@ -1,31 +1,52 @@
-import { Component } from '@angular/core';
+import {Component, inject, input, OnInit, signal} from '@angular/core';
import {NzFormModule} from "ng-zorro-antd/form";
import {FormControl, FormGroup, ReactiveFormsModule, Validators} from "@angular/forms";
import {NzInputDirective} from "ng-zorro-antd/input";
-import {NzDatePickerComponent} from "ng-zorro-antd/date-picker";
+import {GetBookDto, GetAuthorDto, AuthorsService} from "../../services/api";
+import {firstValueFrom} from "rxjs";
+import {NzNotificationService} from "ng-zorro-antd/notification";
+import {NzOptionComponent, NzSelectComponent} from "ng-zorro-antd/select";
@Component({
selector: 'app-update-book',
- imports: [NzFormModule, ReactiveFormsModule, NzInputDirective, NzDatePickerComponent],
+ imports: [NzFormModule, ReactiveFormsModule, NzInputDirective, NzSelectComponent, NzOptionComponent],
templateUrl: './update-book.html',
styleUrl: './update-book.css',
})
-export class UpdateBook {
+export class UpdateBook implements OnInit {
updateBookForm = new FormGroup({
title: new FormControl(null, [Validators.required]),
isbn: new FormControl(null, [Validators.required]),
- releaseYear: new FormControl(null, [Validators.required]),
- author: new FormControl(null, [Validators.required])
+ releaseYear: new FormControl(null, [Validators.required]),
+ authorId: new FormControl(null, Validators.required)
})
- submitForm() {
- // Pour annuler si le formulaire est invalide
- if (this.updateBookForm.invalid) return;
+ private authorsService = inject(AuthorsService);
+ private notificationService = inject(NzNotificationService);
+ authors = signal([]);
+ book = input.required()
- // Pour obtenir la valeur du formulaire
- console.log(this.updateBookForm.getRawValue())
+ async fetchAuthors() {
+ try {
+ const authors = await firstValueFrom(this.authorsService.getAllAuthorsEndpoint());
+ this.authors.set(authors);
+ } catch (e) {
+ this.notificationService.error('Erreur', 'Impossible de récupérer les auteurs');
+ }
+ }
- // Pour vider le formulaire
- this.updateBookForm.reset()
+ async ngOnInit() {
+ await this.fetchAuthors();
+ }
+
+ ngOnChanges() {
+ if (this.book) {
+ this.updateBookForm.patchValue({
+ title: this.book().title,
+ isbn: this.book().isbn,
+ releaseYear: this.book().releaseYear,
+ authorId: this.book().authorId
+ });
+ }
}
}
diff --git a/src/app/components/update-loan/update-loan.html b/src/app/components/update-loan/update-loan.html
index 975fb53..5093113 100644
--- a/src/app/components/update-loan/update-loan.html
+++ b/src/app/components/update-loan/update-loan.html
@@ -1,4 +1,4 @@
- |
-
-
+
@@ -55,7 +53,7 @@
diff --git a/src/app/components/user-table/user-table.ts b/src/app/components/user-table/user-table.ts
index c6a37ff..9d46a4f 100644
--- a/src/app/components/user-table/user-table.ts
+++ b/src/app/components/user-table/user-table.ts
@@ -10,7 +10,6 @@ import {NzDividerComponent} from "ng-zorro-antd/divider";
import {ModalIcon} from "../modal-icon/modal-icon";
import {NzIconDirective} from "ng-zorro-antd/icon";
import {format} from "date-fns";
-import {CreateUser} from "../create-user/create-user";
@Component({
selector: 'app-user-table',
@@ -69,23 +68,6 @@ export class UserTable implements OnInit {
await this.fetchUsers();
}
- selectedUser: GetUserDto | null = null;
- openEditModal(user: GetUserDto) {
- this.selectedUser = { ...user };
- this.modal().showModal();
- }
-
- async onModalOk(userId: number, updateUserComponent: UpdateUser, modal: ModalIcon) {
- await this.edit(userId, updateUserComponent);
- updateUserComponent.updateUserForm.reset();
- modal.isVisible = false;
- await this.fetchUsers();
- }
-
- onModalCancel(modal: ModalIcon) {
- modal.isVisible = false;
- }
-
async edit(id: number, updateUserComponent: UpdateUser) {
if (updateUserComponent.updateUserForm.invalid) {
this.notificationService.error(
@@ -115,4 +97,21 @@ export class UserTable implements OnInit {
)
}
}
+
+ selectedUser: GetUserDto | null = null;
+ openEditModal(user: GetUserDto) {
+ this.selectedUser = { ...user };
+ this.modal().showModal();
+ }
+
+ async onModalOk(userId: number, updateUserComponent: UpdateUser, modal: ModalIcon) {
+ await this.edit(userId, updateUserComponent);
+ updateUserComponent.updateUserForm.reset();
+ modal.isVisible = false;
+ await this.fetchUsers();
+ }
+
+ onModalCancel(modal: ModalIcon) {
+ modal.isVisible = false;
+ }
}
| |