preliminary release
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
import { DatePipe, DecimalPipe, KeyValuePipe } from '@angular/common';
|
||||
import { Component, DestroyRef, OnInit, inject, signal } from '@angular/core';
|
||||
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';
|
||||
|
||||
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> = {
|
||||
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> = {
|
||||
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.
|
||||
*/
|
||||
@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);
|
||||
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 error = signal<string | null>(null);
|
||||
|
||||
ngOnInit(): void {
|
||||
interval(15000)
|
||||
.pipe(
|
||||
startWith(0),
|
||||
switchMap(() => forkJoin({ estados: this.api.indicadores(), log: this.api.importaciones() })),
|
||||
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.')),
|
||||
});
|
||||
}
|
||||
|
||||
estadoTexto(estado: EstadoRecalculo): string {
|
||||
return estado.pendiente && estado.estado !== 'en_curso' ? 'En espera de cálculo' : ESTADOS[estado.estado] ?? estado.estado;
|
||||
}
|
||||
|
||||
resultadoTexto(resultado: string): string {
|
||||
return RESULTADOS[resultado] ?? resultado;
|
||||
}
|
||||
|
||||
recalcular(dominio: Dominio): void {
|
||||
this.api.recalcular(dominio).subscribe({
|
||||
next: () => this.estados.update((e) => (e ? { ...e, [dominio]: { ...e[dominio], pendiente: true } } : e)),
|
||||
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));
|
||||
}
|
||||
|
||||
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 })),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user