feat(web): resolver al salir del campo el socio y los códigos de línea escritos a mano
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4b35aa6bfd
commit
cafe4bc035
9 files changed
+232
-4
No files matched your search
@@ -8,9 +8,11 @@ import {
|
||||
inject,
|
||||
input,
|
||||
model,
|
||||
output,
|
||||
signal,
|
||||
} from '@angular/core';
|
||||
import { formatNumber, parseDecimal } from '../../core/format';
|
||||
import { SlLookupApi } from '../../core/sl/sl-lookup';
|
||||
import type { ListRow } from '../list/list.types';
|
||||
import { ValueHelp } from '../value-help/value-help';
|
||||
import type { GridColumn, GridLine, GridMultiAdd } from './grid.types';
|
||||
@@ -43,6 +45,8 @@ export class LinesGrid {
|
||||
readonly recalc = input<((line: GridLine, changedKey: string) => GridLine) | undefined>(undefined);
|
||||
readonly multiAdd = input<GridMultiAdd>();
|
||||
readonly addLabel = input('Añadir línea');
|
||||
/** Avisos de la grilla (ej. un código escrito que no existe), para la barra de estado del formulario. */
|
||||
readonly notice = output<string>();
|
||||
|
||||
private readonly host = inject<ElementRef<HTMLElement>>(ElementRef);
|
||||
private readonly injector = inject(Injector);
|
||||
@@ -94,7 +98,36 @@ export class LinesGrid {
|
||||
this.update(row, column.key, value);
|
||||
input.value = formatNumber(value, column.decimals);
|
||||
} else if (text !== String(line[column.key] ?? '')) {
|
||||
this.update(row, column.key, text);
|
||||
if (column.lookup && text.trim() !== '') void this.resolveTyped(row, column, input, text.trim());
|
||||
else this.update(row, column.key, text);
|
||||
}
|
||||
}
|
||||
|
||||
/** Códigos que se están buscando (Enter y `change` confirman la misma celda: una sola consulta). */
|
||||
private readonly resolving = new Set<string>();
|
||||
|
||||
/**
|
||||
* Un código escrito a mano se busca en la misma lista que abre "…" y completa la línea igual que
|
||||
* al elegirlo (descripción del artículo, etc.). Si no existe, se avisa y la celda vuelve a su valor.
|
||||
*/
|
||||
private async resolveTyped(row: number, column: GridColumn, input: HTMLInputElement, code: string): Promise<void> {
|
||||
const lookup = column.lookup!;
|
||||
const id = `${row}:${column.key}:${code}`;
|
||||
if (this.resolving.has(id)) return;
|
||||
this.resolving.add(id);
|
||||
try {
|
||||
const found = await this.injector.get(SlLookupApi).find(lookup.config, code);
|
||||
const line = this.lines()[row];
|
||||
if (!line) return;
|
||||
if (found) this.replace(row, lookup.apply(found, line), column.key);
|
||||
else {
|
||||
input.value = this.cellText(line, column);
|
||||
this.notice.emit(`No existe «${code}» en ${lookup.config.title.toLowerCase()}.`);
|
||||
}
|
||||
} catch {
|
||||
this.notice.emit('No se pudo comprobar el código.');
|
||||
} finally {
|
||||
this.resolving.delete(id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user