feat(ui): incorporar selector de figuras KPI y fijacion de indicadores
This commit is contained in:
@@ -16,13 +16,15 @@ import { IndicadoresService } from './indicadores.service';
|
||||
import { applyGlobal, domainTypes, GlobalFilterState, IndicadoresMemory } from './indicadores-memory';
|
||||
import { IndicadorPeriodFilters } from './indicador-period-filters';
|
||||
import { IndicadorCatalogCard } from './indicador-catalog-card';
|
||||
import { KPI_BY_DOMAIN } from './indicadores-kpi';
|
||||
import { IndicadorKpiPanel } from './indicador-kpi-panel';
|
||||
import { IndicadorKpiCard } from './indicador-kpi-card';
|
||||
import { indicatorIdentity } from './indicadores-identities';
|
||||
import { httpMessage } from './indicadores-http';
|
||||
|
||||
@Component({
|
||||
selector: 'app-indicadores-page',
|
||||
imports: [RouterLink, FormsModule, MatButtonModule, MatCardModule, MatFormFieldModule, MatInputModule, MatIconModule, MatSelectModule, MatProgressBarModule, IndicadorCatalogCard, IndicadorKpiCard, IndicadorPeriodFilters],
|
||||
imports: [RouterLink, FormsModule, MatButtonModule, MatCardModule, MatFormFieldModule, MatInputModule, MatIconModule, MatSelectModule, MatProgressBarModule, IndicadorCatalogCard, IndicadorKpiCard, IndicadorKpiPanel, IndicadorPeriodFilters],
|
||||
templateUrl: './indicadores-page.html',
|
||||
styleUrl: './indicadores-page.scss',
|
||||
})
|
||||
@@ -162,9 +164,18 @@ export class IndicadoresPage {
|
||||
this.searchInput()?.nativeElement.focus({ preventScroll: true });
|
||||
}
|
||||
changeSearchQuery(query: string) {
|
||||
const focused = this.document.activeElement;
|
||||
this.preserveCardFocus();
|
||||
this.searchQuery.set(query);
|
||||
this.confirmation = undefined;
|
||||
}
|
||||
isPinned(item: Indicador) { return this.memory.isPinned(this.dominio, item.id); }
|
||||
togglePinned(item: Indicador) {
|
||||
this.preserveCardFocus();
|
||||
this.memory.togglePinned(this.dominio, item.id);
|
||||
this.confirmation = undefined;
|
||||
}
|
||||
private preserveCardFocus() {
|
||||
const focused = this.document.activeElement;
|
||||
if (focused instanceof HTMLElement && this.element.nativeElement.contains(focused)
|
||||
&& focused.closest('app-indicador-catalog-card')) {
|
||||
// Moving a retained view can blur its control. Restore only that connected control,
|
||||
@@ -184,11 +195,11 @@ export class IndicadoresPage {
|
||||
readonly dominios = DOMINIOS;
|
||||
dominio: Dominio = 'tea';
|
||||
readonly domainLabels: Record<Dominio, string> = { tea: 'TEA', cacu: 'CaCu', cama: 'CaMa' };
|
||||
// Presentation samples only. Each domain can replace its own future configuration.
|
||||
readonly kpiPreviewsByDomain: Record<Dominio, readonly { id: string; title: string }[]> = {
|
||||
readonly kpisByDomain = KPI_BY_DOMAIN;
|
||||
kpiIndicator(id: string) { return this.catalog().find(item => item.id === id); }
|
||||
// TEA has no approved KPI definitions; its previews never request data.
|
||||
readonly kpiPreviewsByDomain: { tea: readonly { id: string; title: string }[] } = {
|
||||
tea: [{ id: 'preview-1', title: 'Indicador destacado 1' }, { id: 'preview-2', title: 'Indicador destacado 2' }],
|
||||
cacu: [{ id: 'preview-1', title: 'Indicador destacado 1' }, { id: 'preview-2', title: 'Indicador destacado 2' }],
|
||||
cama: [{ id: 'preview-1', title: 'Indicador destacado 1' }, { id: 'preview-2', title: 'Indicador destacado 2' }],
|
||||
};
|
||||
private readonly catalogRequests = new Subject<void>();
|
||||
readonly catalog = signal<Indicador[]>([]);
|
||||
@@ -197,14 +208,18 @@ export class IndicadoresPage {
|
||||
readonly searchResults = computed(() => {
|
||||
const items = this.catalog();
|
||||
const query = this.normalizeSearch(this.searchQuery());
|
||||
if (!query) return { items, active: false, count: 0 };
|
||||
const prioritize = (group: Indicador[]) => [
|
||||
...group.filter(item => this.isPinned(item)),
|
||||
...group.filter(item => !this.isPinned(item)),
|
||||
];
|
||||
if (!query) return { items: prioritize(items), active: false, count: 0 };
|
||||
const matches: Indicador[] = [];
|
||||
const remaining: Indicador[] = [];
|
||||
for (const item of items) {
|
||||
const matchesQuery = [item.titulo, item.id].some(value => this.normalizeSearch(value).includes(query));
|
||||
(matchesQuery ? matches : remaining).push(item);
|
||||
}
|
||||
return { items: matches.length ? [...matches, ...remaining] : items, active: true, count: matches.length };
|
||||
return { items: [...prioritize(matches), ...prioritize(remaining)], active: true, count: matches.length };
|
||||
});
|
||||
private normalizeSearch(value: string) {
|
||||
return value.normalize('NFD').replace(/\p{M}/gu, '').toLowerCase().trim();
|
||||
|
||||
Reference in New Issue
Block a user