Files
WebApp/src/app/app.ts
T
Angel Capetillo Zavala d761a6fb1a feat(shell): indicators header with the platform title and a domain selector
On /indicadores/<dominio> the header shows «Plataforma de Indicadores» and a menu button with the current domain (TEA, CaCu, Cáncer de mama) that links to the other two through the router. Institutional routes keep their breadcrumb header.

(cherry picked from commit 79a18fd7a8ed1a3a58201e7cc24c9692b53dbc47)
2026-11-12 01:43:27 -06:00

44 lines
2.0 KiB
TypeScript

import { Component, computed, inject } from '@angular/core';
import { toSignal } from '@angular/core/rxjs-interop';
import { ActivatedRoute, NavigationEnd, Router, RouterLink, RouterOutlet } from '@angular/router';
import { MatButtonModule } from '@angular/material/button';
import { MatMenuModule } from '@angular/material/menu';
import { filter, map } from 'rxjs';
import { Dominio, DOMINIOS } from './features/indicadores/indicadores.models';
@Component({
imports: [RouterLink, RouterOutlet, MatButtonModule, MatMenuModule],
selector: 'app-root',
styleUrl: './app.scss',
templateUrl: './app.html',
})
export class App {
private readonly router = inject(Router);
private readonly route = inject(ActivatedRoute);
private readonly leafRouteData = toSignal(
this.router.events.pipe(
filter((event) => event instanceof NavigationEnd),
map(() => {
let route = this.route;
while (route.firstChild) route = route.firstChild;
return route.snapshot.data;
}),
),
{ initialValue: {} as Record<string, unknown> },
);
/** Full-height workspace routes (`data.workspace`) drop the marketing footer. */
readonly workspace = computed(() => !!this.leafRouteData()['workspace']);
readonly breadcrumb = computed(() => this.leafRouteData()['breadcrumb'] as string | undefined);
protected readonly title = 'Plataforma de Indicadores';
protected readonly domainLabels: Record<Dominio, string> = { tea: 'TEA', cacu: 'CaCu', cama: 'Cáncer de mama' };
private readonly url = toSignal(this.router.events.pipe(
filter((event) => event instanceof NavigationEnd), map(event => event.urlAfterRedirects)), { initialValue: this.router.url });
/** On an indicators page the header names its domain and switches to the others. */
protected readonly activeDomain = computed(() =>
DOMINIOS.find(domain => new RegExp(`^/indicadores/${domain}(?:[/?#]|$)`).test(this.url())));
protected readonly otherDomains = computed(() => DOMINIOS.filter(domain => domain !== this.activeDomain()));
}