89 lines
2.8 KiB
TypeScript
89 lines
2.8 KiB
TypeScript
import {Component, inject, OnInit, signal} from '@angular/core';
|
|
import {NzTableComponent} from "ng-zorro-antd/table";
|
|
import {ModalButton} from "../modal-button/modal-button";
|
|
import {ModalNav} from "../modal-nav/modal-nav";
|
|
import {NzDividerComponent} from "ng-zorro-antd/divider";
|
|
import {NzIconDirective} from "ng-zorro-antd/icon";
|
|
import {QuotationForm} from "../quotation-form/quotation-form";
|
|
import {GetQuotationDto, QuotationsService} from "../../services/api";
|
|
import {NzNotificationService} from "ng-zorro-antd/notification";
|
|
import {firstValueFrom} from "rxjs";
|
|
import {FileService} from "../../services/file.service";
|
|
|
|
@Component({
|
|
selector: 'app-quotation-table',
|
|
imports: [
|
|
ModalButton,
|
|
ModalNav,
|
|
NzDividerComponent,
|
|
NzIconDirective,
|
|
NzTableComponent,
|
|
QuotationForm,
|
|
],
|
|
templateUrl: './quotation-table.html',
|
|
styleUrl: './quotation-table.css',
|
|
})
|
|
|
|
export class QuotationTable implements OnInit {
|
|
private quotationsService = inject(QuotationsService);
|
|
private notificationService = inject(NzNotificationService);
|
|
private fileService = inject(FileService);
|
|
quotations = signal<GetQuotationDto[]>([]);
|
|
quotationsLoading = signal<boolean>(false);
|
|
|
|
async ngOnInit() {
|
|
await this.fetchQuotations();
|
|
}
|
|
|
|
async fetchQuotations() {
|
|
this.quotationsLoading.set(true)
|
|
|
|
try {
|
|
const quotations = await firstValueFrom(this.quotationsService.getAllQuotationEndpoint())
|
|
this.quotations.set(quotations);
|
|
} catch (e) {
|
|
this.notificationService.error(
|
|
'Erreur',
|
|
'Erreur de communication avec l\'API'
|
|
)
|
|
}
|
|
this.quotationsLoading.set(false)
|
|
}
|
|
|
|
async delete(quotation:number) {
|
|
this.quotationsLoading.set(true)
|
|
try {
|
|
await firstValueFrom(this.quotationsService.deleteQuotationEndpoint(quotation))
|
|
this.notificationService.success(
|
|
'Success',
|
|
'Suppression effectuée'
|
|
)
|
|
} catch (e) {
|
|
this.notificationService.error(
|
|
'Erreur',
|
|
'Impossible de supprimer la ligne'
|
|
)
|
|
}
|
|
this.quotationsLoading.set(false)
|
|
await this.fetchQuotations();
|
|
}
|
|
|
|
async export(quotationId: number){
|
|
this.quotationsLoading.set(true)
|
|
try {
|
|
const pdf = await firstValueFrom(
|
|
this.quotationsService.getQuotationPdfEndpoint(quotationId, "response")
|
|
);
|
|
this.fileService.downloadBlob(pdf)
|
|
} catch (e) {
|
|
console.error(e);
|
|
this.notificationService.error(
|
|
'Erreur',
|
|
'Impossible de générer un PDF'
|
|
);
|
|
}
|
|
this.quotationsLoading.set(false)
|
|
}
|
|
}
|
|
|