feat(ui): incorporar selector de figuras KPI y fijacion de indicadores
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { inject, Injectable } from '@angular/core';
|
||||
import { HttpClient, HttpParams } from '@angular/common/http';
|
||||
import { map } from 'rxjs';
|
||||
import { Dominio, FigureSelection, Indicador, parsePeriodos, PlotlyFigure, requireDominio } from './indicadores.models';
|
||||
import { Dominio, IndicadorDatos, FigureSelection, Indicador, parsePeriodos, PlotlyFigure, requireDominio } from './indicadores.models';
|
||||
|
||||
function record(value: unknown): value is Record<string, unknown> {
|
||||
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
||||
@@ -26,6 +26,24 @@ export class IndicadoresService {
|
||||
return value as Indicador[];
|
||||
}));
|
||||
}
|
||||
datos(dominio: Dominio, indicador: string, tipo: 'semestre' | 'mes', periodos?: string[]) {
|
||||
const domain = requireDominio(dominio);
|
||||
if (periodos && (!periodos.length || parsePeriodos(periodos.join(','), tipo) === null)) {
|
||||
throw new Error('Periodos inválidos');
|
||||
}
|
||||
let params = new HttpParams();
|
||||
if (periodos) params = params.set('periodos', [...new Set(periodos)].join(','));
|
||||
return this.http.get<unknown>(`/${domain}/indicadores/${encodeURIComponent(indicador)}/datos`, { params }).pipe(map(value => {
|
||||
if (!record(value) || value['id'] !== indicador || typeof value['contrato'] !== 'string'
|
||||
|| !['mes', 'semestre'].includes(value['tipo_periodo'] as string)
|
||||
|| !Array.isArray(value['periodos']) || !value['periodos'].every(p => typeof p === 'string')
|
||||
|| !Array.isArray(value['filas']) || !value['filas'].every(record)
|
||||
|| (value['notas'] !== undefined && (!Array.isArray(value['notas']) || !value['notas'].every(n => typeof n === 'string')))) {
|
||||
throw new Error('Respuesta de datos inválida');
|
||||
}
|
||||
return value as unknown as IndicadorDatos;
|
||||
}));
|
||||
}
|
||||
figura(selection: FigureSelection) {
|
||||
const dominio = requireDominio(selection.dominio ?? 'tea');
|
||||
if (selection.periodos !== undefined) {
|
||||
|
||||
Reference in New Issue
Block a user