add bitacora page, self-hosted fonts/icons, review fixes for the install package
This commit is contained in:
@@ -4,87 +4,83 @@ import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatToolbarModule } from '@angular/material/toolbar';
|
||||
import { forkJoin, interval, startWith, switchMap } from 'rxjs';
|
||||
import { apiErrorMessage } from '../connect/api/api.types';
|
||||
import { Dominio, EstadoRecalculo, IntentoImportacion, ReportesApi } from './reportes.api';
|
||||
import { EMPTY, catchError, forkJoin, interval, startWith, switchMap } from 'rxjs';
|
||||
import { Domain, apiErrorMessage } from '../connect/api/api.types';
|
||||
import { DOMAINS } from '../connect/state/connect-workspace.store';
|
||||
import { ImportAttempt, RecomputeStatus, ReportsApi } from './reportes.api';
|
||||
|
||||
const DOMINIOS: { id: Dominio; nombre: string }[] = [
|
||||
{ id: 'cacu', nombre: 'Cáncer cervicouterino' },
|
||||
{ id: 'cama', nombre: 'Cáncer de mama' },
|
||||
{ id: 'tea', nombre: 'Trastorno del espectro autista' },
|
||||
];
|
||||
|
||||
const ESTADOS: Record<string, string> = {
|
||||
const STATUS_LABELS: Record<string, string> = {
|
||||
sin_correr: 'Pendiente de cálculo', en_curso: 'En proceso de cálculo', ok: 'Actualizado', error: 'Error en el cálculo',
|
||||
};
|
||||
|
||||
const RESULTADOS: Record<string, string> = {
|
||||
const OUTCOME_LABELS: Record<string, string> = {
|
||||
completada: 'Completada', solicitud_invalida: 'Solicitud inválida',
|
||||
rechazada_por_la_base: 'Rechazada por la base', fallida: 'Fallida',
|
||||
};
|
||||
|
||||
/**
|
||||
* The "Bitácora" page (route `/bitacora`): what happened to every import
|
||||
* attempt, in aggregates only, and whether each domain's indicators are up
|
||||
* to date with what was loaded. Refreshes itself every 15 seconds.
|
||||
*/
|
||||
/** The import log page (`/bitacora`): import attempts in aggregate and the indicator status per domain. */
|
||||
@Component({
|
||||
selector: 'app-reportes-page',
|
||||
imports: [DatePipe, DecimalPipe, KeyValuePipe, MatButtonModule, MatIconModule, MatToolbarModule],
|
||||
templateUrl: './reportes-page.html',
|
||||
styleUrl: './reportes-page.scss',
|
||||
})
|
||||
export class ReportesPage implements OnInit {
|
||||
private readonly api = inject(ReportesApi);
|
||||
export class ReportsPage implements OnInit {
|
||||
private readonly api = inject(ReportsApi);
|
||||
private readonly destroyRef = inject(DestroyRef);
|
||||
|
||||
readonly dominios = DOMINIOS;
|
||||
readonly estados = signal<Record<Dominio, EstadoRecalculo> | null>(null);
|
||||
readonly intentos = signal<IntentoImportacion[]>([]);
|
||||
readonly abierto = signal<string | null>(null);
|
||||
readonly domains = DOMAINS;
|
||||
readonly statuses = signal<Record<Domain, RecomputeStatus> | null>(null);
|
||||
readonly attempts = signal<ImportAttempt[]>([]);
|
||||
readonly expanded = signal<string | null>(null);
|
||||
readonly error = signal<string | null>(null);
|
||||
|
||||
ngOnInit(): void {
|
||||
interval(15000)
|
||||
.pipe(
|
||||
startWith(0),
|
||||
switchMap(() => forkJoin({ estados: this.api.indicadores(), log: this.api.importaciones() })),
|
||||
// Errors are handled per poll so one failed request doesn't stop the refresh.
|
||||
switchMap(() =>
|
||||
forkJoin({ statuses: this.api.indicatorStatus(), log: this.api.importLog() }).pipe(
|
||||
catchError((err) => {
|
||||
this.error.set(apiErrorMessage(err, 'No se pudo leer la bitácora.'));
|
||||
return EMPTY;
|
||||
}),
|
||||
),
|
||||
),
|
||||
takeUntilDestroyed(this.destroyRef),
|
||||
)
|
||||
.subscribe({
|
||||
next: ({ estados, log }) => {
|
||||
this.estados.set(estados);
|
||||
this.intentos.set(log.intentos);
|
||||
this.error.set(null);
|
||||
},
|
||||
error: (err) => this.error.set(apiErrorMessage(err, 'No se pudo leer la bitácora.')),
|
||||
.subscribe(({ statuses, log }) => {
|
||||
this.statuses.set(statuses);
|
||||
this.attempts.set(log.intentos);
|
||||
this.error.set(null);
|
||||
});
|
||||
}
|
||||
|
||||
estadoTexto(estado: EstadoRecalculo): string {
|
||||
return estado.pendiente && estado.estado !== 'en_curso' ? 'En espera de cálculo' : ESTADOS[estado.estado] ?? estado.estado;
|
||||
statusLabel(status: RecomputeStatus): string {
|
||||
return status.pendiente && status.estado !== 'en_curso' ? 'En espera de cálculo' : STATUS_LABELS[status.estado] ?? status.estado;
|
||||
}
|
||||
|
||||
resultadoTexto(resultado: string): string {
|
||||
return RESULTADOS[resultado] ?? resultado;
|
||||
outcomeLabel(outcome: string): string {
|
||||
return OUTCOME_LABELS[outcome] ?? outcome;
|
||||
}
|
||||
|
||||
recalcular(dominio: Dominio): void {
|
||||
this.api.recalcular(dominio).subscribe({
|
||||
next: () => this.estados.update((e) => (e ? { ...e, [dominio]: { ...e[dominio], pendiente: true } } : e)),
|
||||
recompute(domain: Domain): void {
|
||||
this.api.recompute(domain).subscribe({
|
||||
next: () => this.statuses.update((s) => (s ? { ...s, [domain]: { ...s[domain], pendiente: true } } : s)),
|
||||
error: (err) => this.error.set(apiErrorMessage(err, 'No se pudo solicitar el recálculo.')),
|
||||
});
|
||||
}
|
||||
|
||||
alternar(id: string): void {
|
||||
this.abierto.update((actual) => (actual === id ? null : id));
|
||||
toggle(id: string): void {
|
||||
this.expanded.update((current) => (current === id ? null : id));
|
||||
}
|
||||
|
||||
camposConProblemas(intento: IntentoImportacion) {
|
||||
return intento.fuentes.flatMap((fuente) =>
|
||||
Object.entries(fuente.campos)
|
||||
.filter(([, campo]) => campo.errores || campo.vacios)
|
||||
.map(([nombre, campo]) => ({ destino: fuente.destino, nombre, campo })),
|
||||
fieldsWithProblems(attempt: ImportAttempt) {
|
||||
return attempt.fuentes.flatMap((source) =>
|
||||
Object.entries(source.campos)
|
||||
.filter(([, field]) => field.errores || field.vacios)
|
||||
.map(([name, field]) => ({ target: source.destino, name, field })),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user