integration layer; merge work on indicators from forks with existing ingestion pipeline
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
<h2 mat-dialog-title>Dibujar regiones · {{ connection.label }}</h2>
|
||||
<mat-dialog-content class="regions">
|
||||
<div class="regions__viewer">
|
||||
<app-pdf-page-viewer
|
||||
[file]="connection.file"
|
||||
[pageNumber]="page()"
|
||||
[pageCount]="pageCount"
|
||||
[regions]="regions()"
|
||||
(pageNumberChange)="page.set($event)"
|
||||
(regionDrawn)="onRegionDrawn($event)"
|
||||
(regionRemove)="remove($event)"
|
||||
></app-pdf-page-viewer>
|
||||
</div>
|
||||
|
||||
<aside class="regions__side">
|
||||
<mat-form-field appearance="outline" class="regions__name">
|
||||
<mat-label>Nombre de la tabla</mat-label>
|
||||
<input matInput [value]="name()" (input)="name.set($any($event.target).value)" />
|
||||
</mat-form-field>
|
||||
|
||||
<p class="regions__hint">
|
||||
Arrastra sobre la página para marcar cada columna. Cada región se vuelve una columna de origen: nómbrala (se
|
||||
sugieren los campos de la base) y luego mapéala como cualquier otra tabla.
|
||||
@if (connection.detection()?.has_text_layer === false) {
|
||||
<br /><strong>Documento escaneado:</strong> el texto se leerá por OCR.
|
||||
}
|
||||
</p>
|
||||
|
||||
@for (region of regions(); track $index) {
|
||||
<div class="region" [class.region--invalid]="duplicateNames().has(region.target_field)">
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic" class="region__name">
|
||||
<mat-label>Columna</mat-label>
|
||||
<input
|
||||
matInput
|
||||
#nameInput
|
||||
[value]="region.target_field"
|
||||
[matAutocomplete]="auto"
|
||||
(change)="rename(region, nameInput.value)"
|
||||
(keydown.enter)="rename(region, nameInput.value)"
|
||||
/>
|
||||
<mat-autocomplete #auto="matAutocomplete" (optionSelected)="rename(region, $event.option.value)">
|
||||
@for (option of suggestionsFor(nameInput.value); track option) {
|
||||
<mat-option [value]="option">{{ option }}</mat-option>
|
||||
}
|
||||
</mat-autocomplete>
|
||||
</mat-form-field>
|
||||
<div class="region__meta">
|
||||
<mat-checkbox
|
||||
[checked]="region.page_numbers.length === pageCount && pageCount > 1"
|
||||
[disabled]="pageCount === 1"
|
||||
(change)="setAllPages(region, $event.checked)"
|
||||
>
|
||||
Todas las páginas
|
||||
</mat-checkbox>
|
||||
<span class="region__pages">{{ pagesLabel(region) }}</span>
|
||||
<button mat-icon-button type="button" (click)="remove(region)" [attr.aria-label]="'Quitar ' + region.target_field">
|
||||
<mat-icon aria-hidden="true">delete</mat-icon>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
} @empty {
|
||||
<p class="regions__empty"><mat-icon aria-hidden="true">crop_free</mat-icon>Aún no hay regiones.</p>
|
||||
}
|
||||
@if (duplicateNames().size > 0) {
|
||||
<p class="regions__error" role="alert">Cada columna necesita un nombre único.</p>
|
||||
}
|
||||
</aside>
|
||||
</mat-dialog-content>
|
||||
<mat-dialog-actions align="end">
|
||||
<button mat-button mat-dialog-close type="button">Cancelar</button>
|
||||
<button mat-flat-button type="button" [disabled]="!canAccept()" (click)="accept()">
|
||||
Agregar tabla ({{ regions().length }} columnas)
|
||||
</button>
|
||||
</mat-dialog-actions>
|
||||
@@ -0,0 +1,72 @@
|
||||
.regions {
|
||||
display: grid;
|
||||
gap: var(--space-4);
|
||||
grid-template-columns: minmax(0, 1fr) 340px;
|
||||
max-height: 78vh;
|
||||
}
|
||||
|
||||
.regions__viewer {
|
||||
min-width: 0;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.regions__side {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--space-2);
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.regions__name {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.regions__hint,
|
||||
.regions__empty {
|
||||
color: var(--mat-sys-on-surface-variant);
|
||||
font: var(--mat-sys-body-small);
|
||||
margin: 0 0 var(--space-2);
|
||||
}
|
||||
|
||||
.regions__empty {
|
||||
align-items: center;
|
||||
display: flex;
|
||||
gap: var(--space-2);
|
||||
}
|
||||
|
||||
.region {
|
||||
border: 1px solid var(--mat-sys-outline-variant);
|
||||
border-radius: var(--mat-sys-corner-medium);
|
||||
padding: var(--space-2) var(--space-2) 0;
|
||||
}
|
||||
|
||||
.region--invalid {
|
||||
border-color: var(--mat-sys-error);
|
||||
}
|
||||
|
||||
.region__name {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.region__meta {
|
||||
align-items: center;
|
||||
display: flex;
|
||||
gap: var(--space-1);
|
||||
}
|
||||
|
||||
.region__pages {
|
||||
color: var(--mat-sys-on-surface-variant);
|
||||
flex: 1;
|
||||
font: var(--mat-sys-body-small);
|
||||
}
|
||||
|
||||
.regions__error {
|
||||
color: var(--mat-sys-error);
|
||||
font: var(--mat-sys-body-small);
|
||||
}
|
||||
|
||||
@media (max-width: 960px) {
|
||||
.regions {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
import { Component, computed, inject, signal } from '@angular/core';
|
||||
import { MatAutocompleteModule } from '@angular/material/autocomplete';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatCheckboxModule } from '@angular/material/checkbox';
|
||||
import { MAT_DIALOG_DATA, MatDialogModule, MatDialogRef } from '@angular/material/dialog';
|
||||
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatInputModule } from '@angular/material/input';
|
||||
import { RegionSpec } from '../../api/api.types';
|
||||
import { PdfConnection } from '../../domain/pdf-source';
|
||||
import { PdfPageViewer } from '../pdf-page-viewer/pdf-page-viewer';
|
||||
import { DrawnRegionBox } from '../pdf-page-viewer/region-draw-overlay.directive';
|
||||
|
||||
export interface PdfRegionsDialogData {
|
||||
connection: PdfConnection;
|
||||
/** Destination field names in the current domain, suggested as column names. */
|
||||
fieldNames: string[];
|
||||
}
|
||||
|
||||
export interface PdfRegionsResult {
|
||||
name: string;
|
||||
regions: RegionSpec[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw one box per column over the rendered page (a column of a scanned
|
||||
* table, a form field); each box becomes a named source column, read by
|
||||
* OCR (or from the text layer when the page has one) and aligned into rows
|
||||
* across all boxes on the page. "Todas las páginas" repeats a box on every
|
||||
* page, which suits multi-page reports with a fixed layout.
|
||||
*/
|
||||
@Component({
|
||||
selector: 'app-pdf-regions-dialog',
|
||||
imports: [
|
||||
MatAutocompleteModule,
|
||||
MatButtonModule,
|
||||
MatCheckboxModule,
|
||||
MatDialogModule,
|
||||
MatFormFieldModule,
|
||||
MatIconModule,
|
||||
MatInputModule,
|
||||
PdfPageViewer,
|
||||
],
|
||||
templateUrl: './pdf-regions-dialog.html',
|
||||
styleUrl: './pdf-regions-dialog.scss',
|
||||
})
|
||||
export class PdfRegionsDialog {
|
||||
readonly data = inject<PdfRegionsDialogData>(MAT_DIALOG_DATA);
|
||||
private readonly dialogRef = inject<MatDialogRef<PdfRegionsDialog, PdfRegionsResult>>(MatDialogRef);
|
||||
|
||||
readonly connection = this.data.connection;
|
||||
readonly pageCount = this.connection.detection()?.page_count ?? 1;
|
||||
readonly page = signal(1);
|
||||
readonly regions = signal<RegionSpec[]>([]);
|
||||
readonly name = signal(`Regiones ${this.connection.tables().filter((t) => t.removable).length + 1}`);
|
||||
|
||||
readonly duplicateNames = computed(() => {
|
||||
const names = this.regions().map((region) => region.target_field.trim());
|
||||
return new Set(names.filter((name, index) => !name || names.indexOf(name) !== index));
|
||||
});
|
||||
|
||||
readonly canAccept = computed(() => this.regions().length > 0 && this.duplicateNames().size === 0 && !!this.name().trim());
|
||||
|
||||
onRegionDrawn(box: DrawnRegionBox): void {
|
||||
const taken = new Set(this.regions().map((region) => region.target_field));
|
||||
let index = this.regions().length + 1;
|
||||
while (taken.has(`columna_${index}`)) index++;
|
||||
this.regions.update((regions) => [
|
||||
...regions,
|
||||
{ target_field: `columna_${index}`, page_numbers: [this.page()], bbox: [box.x0, box.y0, box.x1, box.y1] },
|
||||
]);
|
||||
}
|
||||
|
||||
rename(region: RegionSpec, value: string): void {
|
||||
// Committed on change/Enter, not per keystroke: replacing the region
|
||||
// object while typing re-renders the row and drops the input's focus.
|
||||
this.regions.update((regions) => regions.map((r) => (r === region ? { ...r, target_field: value } : r)));
|
||||
}
|
||||
|
||||
setAllPages(region: RegionSpec, allPages: boolean): void {
|
||||
const pages = allPages ? Array.from({ length: this.pageCount }, (_, i) => i + 1) : [this.page()];
|
||||
this.regions.update((regions) => regions.map((r) => (r === region ? { ...r, page_numbers: pages } : r)));
|
||||
}
|
||||
|
||||
remove(region: RegionSpec): void {
|
||||
this.regions.update((regions) => regions.filter((r) => r !== region));
|
||||
}
|
||||
|
||||
suggestionsFor(value: string): string[] {
|
||||
const term = value.trim().toLowerCase();
|
||||
return this.data.fieldNames.filter((name) => !term || name.toLowerCase().includes(term)).slice(0, 30);
|
||||
}
|
||||
|
||||
pagesLabel(region: RegionSpec): string {
|
||||
return region.page_numbers.length === this.pageCount && this.pageCount > 1
|
||||
? `${this.pageCount} págs.`
|
||||
: `pág. ${region.page_numbers.join(', ')}`;
|
||||
}
|
||||
|
||||
accept(): void {
|
||||
this.dialogRef.close({
|
||||
name: this.name().trim(),
|
||||
regions: this.regions().map((region) => ({ ...region, target_field: region.target_field.trim() })),
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user