import {Component, inject, OnInit, signal} from '@angular/core'; import {Modal} from "../modal/modal"; import {AuthorsService, GetAuthorDto} from "../../services/api"; import {NzNotificationService} from "ng-zorro-antd/notification"; import {firstValueFrom} from "rxjs"; import {NzTableComponent} from "ng-zorro-antd/table"; import {NzDividerComponent} from "ng-zorro-antd/divider"; import {UpdateAuthor} from "../update-author/update-author"; import {ModalIcon} from "../modal-icon/modal-icon"; import {NzIconDirective} from "ng-zorro-antd/icon"; @Component({ selector: 'app-author-table', imports: [ Modal, NzTableComponent, NzDividerComponent, UpdateAuthor, ModalIcon, NzIconDirective ], templateUrl: './author-table.html', styleUrl: './author-table.css', }) export class AuthorTable implements OnInit { private authorsService = inject(AuthorsService); private notificationService = inject(NzNotificationService) authors = signal([]); authorsLoading = signal(false); async ngOnInit() { await this.fetchauthors(); } async fetchauthors() { this.authorsLoading.set(true) try { const authors = await firstValueFrom(this.authorsService.getAllAuthorsEndpoint()); this.authors.set(authors); } catch (e) { this.notificationService.error( 'Erreur', 'Erreur de communication avec l\'API' ) } this.authorsLoading.set(false) } async delete(author:number) { try { await firstValueFrom(this.authorsService.deleteAuthorEndpoint(author)) this.notificationService.success( 'Success', 'Suppression effectuée' ) } catch (e) { this.notificationService.error( 'Erreur', 'Impossible de supprimer la ligne' ) } await this.fetchauthors(); } }