Feature: Exportar Excel
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
import { Component, signal } from '@angular/core';
|
||||
import { MatDialogModule, MatDialogRef } from '@angular/material/dialog';
|
||||
import { Component, inject, InjectionToken, signal } from '@angular/core';
|
||||
import { MAT_DIALOG_DATA, MatDialogModule, MatDialogRef } from '@angular/material/dialog';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import type { AnalysisResult } from './dashboard.mock';
|
||||
import { exportExcel } from './exports/excel-export';
|
||||
|
||||
export type ExportFormat = 'pdf' | 'excel';
|
||||
export const EXCEL_EXPORT = new InjectionToken<typeof exportExcel>('EXCEL_EXPORT', { factory: () => exportExcel });
|
||||
|
||||
@Component({
|
||||
imports: [MatDialogModule, MatIconModule],
|
||||
@@ -12,9 +15,34 @@ export type ExportFormat = 'pdf' | 'excel';
|
||||
})
|
||||
export class ExportResultsDialog {
|
||||
readonly selection = signal<ExportFormat | null>(null);
|
||||
readonly generating = signal(false);
|
||||
readonly error = signal(false);
|
||||
private readonly result = inject<AnalysisResult>(MAT_DIALOG_DATA);
|
||||
private readonly runExcelExport = inject(EXCEL_EXPORT);
|
||||
|
||||
constructor(private readonly dialogRef: MatDialogRef<ExportResultsDialog>) {}
|
||||
|
||||
select(format: ExportFormat): void { this.selection.set(format); }
|
||||
close(): void { this.dialogRef.close(); }
|
||||
select(format: ExportFormat): void {
|
||||
if (this.generating()) return;
|
||||
this.selection.set(format);
|
||||
this.error.set(false);
|
||||
}
|
||||
|
||||
close(): void { if (!this.generating()) this.dialogRef.close(); }
|
||||
|
||||
async submit(): Promise<void> {
|
||||
if (this.generating() || this.selection() !== 'excel') return;
|
||||
this.generating.set(true);
|
||||
this.error.set(false);
|
||||
this.dialogRef.disableClose = true;
|
||||
try {
|
||||
await this.runExcelExport(this.result);
|
||||
this.dialogRef.close();
|
||||
} catch {
|
||||
this.error.set(true);
|
||||
} finally {
|
||||
this.generating.set(false);
|
||||
this.dialogRef.disableClose = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user