preliminary release
This commit is contained in:
@@ -10,29 +10,30 @@ import { MatInputModule } from '@angular/material/input';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatSelectModule } from '@angular/material/select';
|
||||
import { MatProgressBarModule } from '@angular/material/progress-bar';
|
||||
import { ConnectedPosition, Overlay, OverlayModule } from '@angular/cdk/overlay';
|
||||
import { catchError, map, of, startWith, Subject, switchMap, takeUntil } from 'rxjs';
|
||||
import { Dominio, DOMINIOS, isDominio, Indicador, Tema } from './indicadores.models';
|
||||
import { IndicadoresService } from './indicadores.service';
|
||||
import { applyGlobal, domainTypes, GlobalFilterState, IndicadoresMemory, pending, validDraft } from './indicadores-memory';
|
||||
import { IndicadorPeriodFilters } from './indicador-period-filters';
|
||||
import { IndicadorCatalogCard } from './indicador-catalog-card';
|
||||
import { KPI_BY_DOMAIN } from './indicadores-kpi';
|
||||
import { CACU_RESULTADO_KPI, KPI_BY_DOMAIN } from './indicadores-kpi';
|
||||
import { IndicadorKpiPanel } from './indicador-kpi-panel';
|
||||
import { IndicadorKpiCard } from './indicador-kpi-card';
|
||||
import { figureApplied, independentFigurePeriods } from './indicadores-figure-selection';
|
||||
import { indicatorIdentity } from './indicadores-identities';
|
||||
import { identityElementId, indicatorIdentity } from './indicadores-identities';
|
||||
import { emptyAvailability, IndicadoresPeriodos } from './indicadores-periodos';
|
||||
import { httpMessage } from './indicadores-http';
|
||||
import { IndicadoresInitialPeriod } from './indicadores-initial-period';
|
||||
import { IndicadoresDefinitions } from './indicadores-definitions';
|
||||
import { IndicadoresTracking } from './indicadores-tracking';
|
||||
import { IndicadoresNumericSummary } from './indicadores-numeric-summary';
|
||||
import { IndicadorNavegacionItem, IndicadoresNavegacionPanel } from './indicadores-navegacion-panel';
|
||||
|
||||
type DashboardSection = 'resumen' | 'seguimiento' | 'datos';
|
||||
|
||||
@Component({
|
||||
selector: 'app-indicadores-page',
|
||||
imports: [RouterLink, FormsModule, MatButtonModule, MatCardModule, MatFormFieldModule, MatInputModule, MatIconModule, MatSelectModule, MatProgressBarModule, IndicadorCatalogCard, IndicadorKpiPanel, IndicadorKpiCard, IndicadorPeriodFilters, IndicadoresDefinitions, IndicadoresTracking, IndicadoresNumericSummary],
|
||||
imports: [RouterLink, FormsModule, MatButtonModule, MatCardModule, MatFormFieldModule, MatInputModule, MatIconModule, MatSelectModule, MatProgressBarModule, OverlayModule, IndicadorCatalogCard, IndicadorKpiPanel, IndicadorKpiCard, IndicadorPeriodFilters, IndicadoresDefinitions, IndicadoresTracking, IndicadoresNavegacionPanel],
|
||||
templateUrl: './indicadores-page.html',
|
||||
styleUrl: './indicadores-page.scss',
|
||||
})
|
||||
@@ -43,8 +44,14 @@ export class IndicadoresPage {
|
||||
{ id: 'datos', label: 'Datos y definiciones' },
|
||||
];
|
||||
readonly activeSection = signal<DashboardSection>('resumen');
|
||||
readonly fichaPacienteAbierta = signal(false);
|
||||
setFichaPacienteAbierta(open: boolean) {
|
||||
this.fichaPacienteAbierta.set(open);
|
||||
if (open) this.closeGraphicNavigation(false, false);
|
||||
}
|
||||
changeSection(section: DashboardSection) {
|
||||
if (!this.sections.some(item => item.id === section) || this.activeSection() === section) return;
|
||||
if (section !== 'resumen') this.closeGraphicNavigation(false, false);
|
||||
this.activeSection.set(section);
|
||||
// Retain views, filters and Plotly hosts; only visible regions authorize loading.
|
||||
if (section !== 'resumen') for (const card of this.graphicCards()) card.setVisible(false);
|
||||
@@ -65,6 +72,26 @@ export class IndicadoresPage {
|
||||
private readonly element = inject<ElementRef<HTMLElement>>(ElementRef);
|
||||
private readonly injector = inject(Injector);
|
||||
private readonly searchInput = viewChild<ElementRef<HTMLInputElement>>('searchInput');
|
||||
private readonly overlay = inject(Overlay);
|
||||
readonly navigationScrollStrategy = this.overlay.scrollStrategies.reposition();
|
||||
readonly navigationPositions: ConnectedPosition[] = [
|
||||
{ originX: 'start', originY: 'center', overlayX: 'start', overlayY: 'center' },
|
||||
{ originX: 'start', originY: 'top', overlayX: 'start', overlayY: 'top' },
|
||||
{ originX: 'start', originY: 'bottom', overlayX: 'start', overlayY: 'bottom' },
|
||||
{ originX: 'end', originY: 'center', overlayX: 'end', overlayY: 'center' },
|
||||
];
|
||||
readonly navigationOpen = signal(false);
|
||||
readonly navigationClosing = signal(false);
|
||||
readonly navigationAttached = computed(() => this.navigationOpen() || this.navigationClosing());
|
||||
readonly navigationKeyboard = signal(false);
|
||||
private readonly navigationPanel = viewChild(IndicadoresNavegacionPanel);
|
||||
private navigationHoverTimer?: ReturnType<typeof setTimeout>;
|
||||
private navigationAnimationTimer?: ReturnType<typeof setTimeout>;
|
||||
private navigationPointerInside = false;
|
||||
// Removing the overlay can generate pointerenter on the button under a stationary cursor.
|
||||
private navigationHoverDismissed = false;
|
||||
readonly navigationItems = computed<readonly IndicadorNavegacionItem[]>(() =>
|
||||
this.searchResults().items.map(item => ({ key: indicatorIdentity(this.dominio, item.id), titulo: item.titulo })));
|
||||
private readonly graphicCards = viewChildren(IndicadorCatalogCard);
|
||||
private readonly observedRegions = new Map<Element, IndicadorCatalogCard>();
|
||||
private renderedCards: readonly IndicadorCatalogCard[] = [];
|
||||
@@ -241,12 +268,36 @@ export class IndicadoresPage {
|
||||
private readonly route = inject(ActivatedRoute, { optional: true });
|
||||
readonly dominios = DOMINIOS;
|
||||
dominio: Dominio = 'tea';
|
||||
readonly domainLabels: Record<Dominio, string> = { tea: 'TEA', cacu: 'CaCu', cama: 'CaMa' };
|
||||
readonly domainLabels: Record<Dominio, string> = { tea: 'TEA', cacu: 'cáncer cervicouterino', cama: 'CaMa' };
|
||||
// At the start of the header line.
|
||||
readonly domainTitles: Record<Dominio, string> = { ...this.domainLabels, cacu: 'Cáncer cervicouterino' };
|
||||
// Short form for the domain-switcher buttons (our shell's own nav, see the
|
||||
// template comment above it) -- `domainLabels`/`domainTitles` are prose-length.
|
||||
readonly domainNavLabels: Record<Dominio, string> = { tea: 'TEA', cacu: 'CaCu', cama: 'CaMa' };
|
||||
readonly kpisByDomain = KPI_BY_DOMAIN;
|
||||
figureApplied(item: Indicador) { return figureApplied(this.dominio, item.id, this.filters!.applied); }
|
||||
independentPeriods(item: Indicador) { return independentFigurePeriods(this.dominio, item.id); }
|
||||
kpiIndicator(id: string) { return this.catalog().find(item => item.id === id); }
|
||||
kpiIndicator(id: string) {
|
||||
const published = this.catalog().find(item => item.id === id);
|
||||
if (published) return published;
|
||||
// The lab partner is deliberately hidden from some catalogs, as in the paired figure.
|
||||
// Reuse its established periodicity, without assigning the diagnosis version to lab data.
|
||||
if (this.dominio === 'cacu' && id === CACU_RESULTADO_KPI.id) {
|
||||
const diagnosis = this.catalog().find(item => item.id === 'cacu_dias_toma_diagnostico');
|
||||
if (diagnosis) return { id, titulo: CACU_RESULTADO_KPI.title, contrato: diagnosis.contrato,
|
||||
figuras: [], tipos_periodo: diagnosis.tipos_periodo };
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
get availableKpis() { return this.kpisByDomain[this.dominio].filter(definition => this.catalog().some(item => item.id === definition.id)); }
|
||||
get opportunityKpis() {
|
||||
const definitions = this.availableKpis;
|
||||
if (this.dominio !== 'cacu' || (!definitions.length && !this.catalog().some(item => item.id === CACU_RESULTADO_KPI.id))) return definitions;
|
||||
// Keep the established KPI definitions and initial-period anchor intact.
|
||||
const diagnosis = definitions.findIndex(item => item.id === 'cacu_dias_toma_diagnostico');
|
||||
return [...definitions.slice(0, diagnosis < 0 ? definitions.length : diagnosis), CACU_RESULTADO_KPI,
|
||||
...definitions.slice(diagnosis < 0 ? definitions.length : diagnosis)];
|
||||
}
|
||||
private readonly catalogRequests = new Subject<void>();
|
||||
readonly catalog = signal<Indicador[]>([]);
|
||||
readonly searchQuery = signal('');
|
||||
@@ -302,8 +353,117 @@ export class IndicadoresPage {
|
||||
this.changeDetector.markForCheck();
|
||||
}
|
||||
cardIdentity(item: Indicador) { return indicatorIdentity(this.dominio, item.id); }
|
||||
cardElementId(item: Indicador) { return identityElementId(this.cardIdentity(item)); }
|
||||
get showGraphicNavigation() {
|
||||
return this.activeSection() === 'resumen' && !this.fichaPacienteAbierta() && !this.catalogLoading()
|
||||
&& !this.catalogError() && !this.initialPeriodBlocked && this.navigationItems().length > 0;
|
||||
}
|
||||
toggleGraphicNavigation(event?: MouseEvent) {
|
||||
if (!this.showGraphicNavigation) return;
|
||||
if (this.navigationOpen()) this.closeGraphicNavigation(false);
|
||||
else this.openGraphicNavigation(event?.detail === 0);
|
||||
}
|
||||
private openGraphicNavigation(keyboard = false) {
|
||||
if (!this.showGraphicNavigation) return;
|
||||
this.clearNavigationTimers();
|
||||
this.navigationHoverDismissed = false;
|
||||
this.navigationKeyboard.set(keyboard);
|
||||
this.navigationClosing.set(false);
|
||||
this.navigationOpen.set(true);
|
||||
if (keyboard) afterNextRender(() => {
|
||||
if (this.navigationOpen() && this.navigationKeyboard()) this.navigationPanel()?.focusFirstOption();
|
||||
}, { injector: this.injector });
|
||||
}
|
||||
navigationTriggerKeydown(event: KeyboardEvent) {
|
||||
if (event.key !== 'Enter' && event.key !== ' ') return;
|
||||
event.preventDefault();
|
||||
this.openGraphicNavigation(true);
|
||||
}
|
||||
navigationPointerEnter(event: PointerEvent) {
|
||||
if (this.navigationHoverDismissed || !this.navigationCanHover(event)) return;
|
||||
this.navigationPointerInside = true;
|
||||
if (this.navigationHoverTimer !== undefined) clearTimeout(this.navigationHoverTimer);
|
||||
this.navigationHoverTimer = undefined;
|
||||
if (!this.navigationOpen()) this.openGraphicNavigation();
|
||||
}
|
||||
navigationPointerMove(event: PointerEvent) {
|
||||
if (!this.navigationHoverDismissed || !this.navigationCanHover(event)) return;
|
||||
this.navigationHoverDismissed = false;
|
||||
this.navigationPointerEnter(event);
|
||||
}
|
||||
private navigationCanHover(event: PointerEvent) {
|
||||
return event.pointerType === 'mouse' && this.document.defaultView?.matchMedia?.('(hover: hover) and (pointer: fine)').matches;
|
||||
}
|
||||
navigationPointerLeave(event: PointerEvent) {
|
||||
if (!this.navigationCanHover(event)) return;
|
||||
this.navigationPointerInside = false;
|
||||
this.scheduleNavigationClose();
|
||||
}
|
||||
navigationFocusOut() { this.scheduleNavigationClose(); }
|
||||
private scheduleNavigationClose() {
|
||||
if (!this.navigationOpen()) return;
|
||||
if (this.navigationHoverTimer !== undefined) clearTimeout(this.navigationHoverTimer);
|
||||
this.navigationHoverTimer = setTimeout(() => {
|
||||
this.navigationHoverTimer = undefined;
|
||||
if (!this.navigationPointerInside && !this.navigationPanel()?.containsFocus()) this.closeGraphicNavigation(false);
|
||||
}, 230);
|
||||
}
|
||||
navigationOverlayKeydown(event: KeyboardEvent) {
|
||||
if (event.key !== 'Escape') return;
|
||||
event.preventDefault();
|
||||
this.closeGraphicNavigation();
|
||||
}
|
||||
private clearNavigationTimers() {
|
||||
if (this.navigationHoverTimer !== undefined) clearTimeout(this.navigationHoverTimer);
|
||||
if (this.navigationAnimationTimer !== undefined) clearTimeout(this.navigationAnimationTimer);
|
||||
this.navigationHoverTimer = this.navigationAnimationTimer = undefined;
|
||||
}
|
||||
closeGraphicNavigation(restoreFocus = true, animate = true) {
|
||||
const wasOpen = this.navigationOpen();
|
||||
this.clearNavigationTimers();
|
||||
this.navigationHoverDismissed ||= wasOpen;
|
||||
this.navigationPointerInside = false;
|
||||
this.navigationKeyboard.set(false);
|
||||
this.navigationOpen.set(false);
|
||||
const reducedMotion = this.document.defaultView?.matchMedia?.('(prefers-reduced-motion: reduce)').matches;
|
||||
this.navigationClosing.set(animate && wasOpen && !reducedMotion);
|
||||
if (this.navigationClosing()) this.navigationAnimationTimer = setTimeout(() => {
|
||||
this.navigationAnimationTimer = undefined;
|
||||
this.navigationClosing.set(false);
|
||||
}, 180);
|
||||
if (wasOpen && restoreFocus && this.showGraphicNavigation) {
|
||||
this.element.nativeElement.querySelector<HTMLButtonElement>('.graphic-navigation-trigger')?.focus({ preventScroll: true });
|
||||
}
|
||||
}
|
||||
closeGraphicNavigationFromOutside(event: MouseEvent) {
|
||||
const target = event.target;
|
||||
const trigger = this.element.nativeElement.querySelector<HTMLButtonElement>('.graphic-navigation-trigger');
|
||||
if (target instanceof Node && trigger?.contains(target)) return;
|
||||
this.closeGraphicNavigation(false);
|
||||
}
|
||||
selectGraphicNavigation(key: string) {
|
||||
if (!this.navigationItems().some(item => item.key === key)) {
|
||||
this.closeGraphicNavigation(false);
|
||||
return;
|
||||
}
|
||||
this.closeGraphicNavigation(false, false);
|
||||
afterNextRender(() => this.scrollToIndicator(key), { injector: this.injector });
|
||||
}
|
||||
private scrollToIndicator(key: string) {
|
||||
if (this.activeSection() !== 'resumen' || this.fichaPacienteAbierta()
|
||||
|| !this.navigationItems().some(item => item.key === key)) return;
|
||||
const target = this.document.getElementById(identityElementId(key));
|
||||
const grid = this.element.nativeElement.querySelector('.catalog-grid');
|
||||
if (!target || !grid?.contains(target)) return;
|
||||
const reducedMotion = this.document.defaultView?.matchMedia?.('(prefers-reduced-motion: reduce)').matches;
|
||||
target.scrollIntoView({ behavior: reducedMotion ? 'instant' : 'smooth', block: 'start' });
|
||||
target.querySelector('h2')?.focus({ preventScroll: true });
|
||||
}
|
||||
constructor() {
|
||||
afterEveryRender(() => this.syncVisibility());
|
||||
afterEveryRender(() => {
|
||||
this.syncVisibility();
|
||||
if (!this.showGraphicNavigation && (this.navigationAttached() || this.navigationHoverTimer !== undefined)) this.closeGraphicNavigation(false, false);
|
||||
});
|
||||
const browser = this.document.defaultView;
|
||||
if (typeof IntersectionObserver !== 'undefined') {
|
||||
browser?.addEventListener('scroll', this.viewportChanged, { passive: true });
|
||||
@@ -312,6 +472,7 @@ export class IndicadoresPage {
|
||||
this.destroyRef.onDestroy(() => {
|
||||
this.filtersEdited();
|
||||
this.visibilityDestroyed = true;
|
||||
this.closeGraphicNavigation(false, false);
|
||||
this.clearVisibility();
|
||||
this.sizeObserver?.disconnect();
|
||||
this.sizeTargets.clear();
|
||||
@@ -326,6 +487,7 @@ export class IndicadoresPage {
|
||||
return this.periodService.dominio(this.dominio, this.catalog());
|
||||
}), takeUntilDestroyed(this.destroyRef)).subscribe(state => this.availability.set(state));
|
||||
this.catalogRequests.pipe(startWith(undefined), switchMap(() => {
|
||||
this.closeGraphicNavigation(false, false);
|
||||
this.cancelInitialPeriod.next();
|
||||
this.initialPeriodState.set('ready');
|
||||
this.clearVisibility();
|
||||
@@ -347,6 +509,7 @@ export class IndicadoresPage {
|
||||
}
|
||||
changeDominio(dominio: Dominio) {
|
||||
if (!isDominio(dominio) || dominio === this.dominio) return;
|
||||
this.closeGraphicNavigation(false, false);
|
||||
this.activeSection.set('resumen');
|
||||
this.searchQuery.set('');
|
||||
this.filtersEdited();
|
||||
|
||||
Reference in New Issue
Block a user