2982d482bf
A Histórico tab between Resumen and Seguimiento, for CaMa only: monthly or semestral interval, how many periods to show, and a custom period dialog. Counts are stacked, rates draw their confidence band and medians their quartile band; suppressed periods are shaded and listed, and a rate over no denominator or a median over no observations is no value. Five charts use published indicators; the three whose indicator the catalog does not publish are drawn as pending panels. (cherry picked from commit 268d7443e0a89da8d6bc67ecb2b5db2715236f93)
59 lines
3.2 KiB
TypeScript
59 lines
3.2 KiB
TypeScript
import { Component, computed, inject, signal } from '@angular/core';
|
|
import { MatButtonModule } from '@angular/material/button';
|
|
import { MatCheckboxModule } from '@angular/material/checkbox';
|
|
import { MAT_DIALOG_DATA, MatDialogModule, MatDialogRef } from '@angular/material/dialog';
|
|
import { etiquetaPeriodo } from './indicadores-historico-figures';
|
|
import { TipoPeriodo } from './indicadores.models';
|
|
|
|
export interface PeriodosDialogoDatos { tipo: TipoPeriodo; periodos: readonly string[]; elegidos: readonly string[]; }
|
|
|
|
// The periods of the chosen analysis interval, by year. Closes with the chosen ones, oldest first, or with nothing if cancelled.
|
|
@Component({
|
|
selector: 'app-indicadores-historico-periodos',
|
|
imports: [MatButtonModule, MatCheckboxModule, MatDialogModule],
|
|
template: `
|
|
<h2 mat-dialog-title>Elegir {{ datos.tipo === 'mes' ? 'meses' : 'semestres' }}</h2>
|
|
<mat-dialog-content>
|
|
<div class="acciones">
|
|
<button type="button" mat-button (click)="elegidos.set(todos)">Elegir todos</button>
|
|
<button type="button" mat-button (click)="elegidos.set([])">Quitar todos</button>
|
|
</div>
|
|
@for (grupo of anios; track grupo.anio) {
|
|
<fieldset>
|
|
<legend>{{ grupo.anio }}</legend>
|
|
@for (periodo of grupo.periodos; track periodo) {
|
|
<mat-checkbox [checked]="elegidos().includes(periodo)" (change)="alternar(periodo)">{{ etiqueta(periodo) }}</mat-checkbox>
|
|
}
|
|
</fieldset>
|
|
}
|
|
</mat-dialog-content>
|
|
<mat-dialog-actions align="end">
|
|
<span class="cuenta" role="status">{{ cuenta() }}</span>
|
|
<button type="button" mat-button mat-dialog-close>Cancelar</button>
|
|
<button type="button" mat-flat-button [disabled]="!elegidos().length" (click)="aplicar()">Aplicar</button>
|
|
</mat-dialog-actions>
|
|
`,
|
|
styles: `
|
|
.acciones { display: flex; gap: .5rem; margin-bottom: .5rem; }
|
|
fieldset { display: grid; grid-template-columns: repeat(auto-fill, minmax(8rem, 1fr)); gap: 0 .5rem; margin: 0 0 .75rem; padding: .25rem .5rem; border: 1px solid var(--issste-border); border-radius: var(--issste-radius); }
|
|
legend { padding-inline: .25rem; font-weight: 600; }
|
|
.cuenta { margin-inline-end: auto; padding-inline-start: .75rem; font: var(--mat-sys-body-medium); }
|
|
`,
|
|
})
|
|
export class IndicadoresHistoricoPeriodos {
|
|
readonly datos = inject<PeriodosDialogoDatos>(MAT_DIALOG_DATA);
|
|
private readonly dialogo = inject<MatDialogRef<IndicadoresHistoricoPeriodos, string[]>>(MatDialogRef);
|
|
readonly etiqueta = etiquetaPeriodo;
|
|
readonly todos = [...this.datos.periodos];
|
|
readonly elegidos = signal<readonly string[]>(this.datos.elegidos);
|
|
readonly anios = [...new Set(this.todos.map(p => p.slice(0, 4)))].map(anio => ({ anio, periodos: this.todos.filter(p => p.startsWith(anio)) }));
|
|
readonly cuenta = computed(() => {
|
|
const n = this.elegidos().length, mes = this.datos.tipo === 'mes';
|
|
return n === 1 ? (mes ? '1 mes elegido' : '1 semestre elegido') : `${n} ${mes ? 'meses elegidos' : 'semestres elegidos'}`;
|
|
});
|
|
alternar(periodo: string) {
|
|
this.elegidos.update(actual => actual.includes(periodo) ? actual.filter(p => p !== periodo) : [...actual, periodo]);
|
|
}
|
|
aplicar() { this.dialogo.close(this.todos.filter(p => this.elegidos().includes(p))); }
|
|
}
|