integration layer; merge work on indicators from forks with existing ingestion pipeline
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
<h2 mat-dialog-title>{{ data.title }}</h2>
|
||||
<mat-dialog-content class="correction">
|
||||
<div class="correction__viewer">
|
||||
<app-pdf-page-viewer
|
||||
[file]="data.file"
|
||||
[pageNumber]="page()"
|
||||
[pageCount]="pageCount()"
|
||||
(pageNumberChange)="page.set($event)"
|
||||
(regionDrawn)="onRegionDrawn($event)"
|
||||
></app-pdf-page-viewer>
|
||||
</div>
|
||||
|
||||
<aside class="correction__side">
|
||||
<p class="correction__hint">
|
||||
Selecciona un campo y dibuja un recuadro sobre el valor en el PDF. El texto leído llena el campo — puedes
|
||||
corregirlo a mano antes de guardar.
|
||||
@if (extracting()) {
|
||||
<mat-progress-spinner diameter="16" mode="indeterminate" class="correction__spinner"></mat-progress-spinner>
|
||||
}
|
||||
</p>
|
||||
|
||||
@for (field of data.fields; track field.name) {
|
||||
<div class="correction__field" [class.correction__field--active]="activeField() === field.name">
|
||||
<button
|
||||
mat-stroked-button
|
||||
type="button"
|
||||
class="correction__pick"
|
||||
(click)="selectField(field.name)"
|
||||
[attr.aria-pressed]="activeField() === field.name"
|
||||
>
|
||||
<mat-icon aria-hidden="true">crop</mat-icon>{{ field.label }}
|
||||
</button>
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic" class="correction__input">
|
||||
<input matInput [value]="values()[field.name]" (input)="setValue(field.name, $any($event.target).value)" />
|
||||
</mat-form-field>
|
||||
</div>
|
||||
}
|
||||
</aside>
|
||||
</mat-dialog-content>
|
||||
<mat-dialog-actions align="end">
|
||||
<button mat-button type="button" mat-dialog-close>Cancelar</button>
|
||||
<button mat-flat-button type="button" [disabled]="!canSave()" (click)="save()">Guardar corrección</button>
|
||||
</mat-dialog-actions>
|
||||
@@ -0,0 +1,57 @@
|
||||
.correction {
|
||||
display: grid;
|
||||
gap: var(--space-4);
|
||||
grid-template-columns: minmax(0, 1fr) 300px;
|
||||
max-height: 78vh;
|
||||
}
|
||||
|
||||
.correction__viewer {
|
||||
min-width: 0;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.correction__side {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--space-3);
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.correction__hint {
|
||||
align-items: center;
|
||||
color: var(--mat-sys-on-surface-variant);
|
||||
display: flex;
|
||||
font: var(--mat-sys-body-small);
|
||||
gap: var(--space-2);
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.correction__spinner {
|
||||
flex: none;
|
||||
}
|
||||
|
||||
.correction__field {
|
||||
border: 1px solid var(--mat-sys-outline-variant);
|
||||
border-radius: var(--mat-sys-corner-medium);
|
||||
padding: var(--space-2);
|
||||
}
|
||||
|
||||
.correction__field--active {
|
||||
border-color: var(--color-primary);
|
||||
box-shadow: inset 0 0 0 1px var(--color-primary);
|
||||
}
|
||||
|
||||
.correction__pick {
|
||||
margin-bottom: var(--space-2);
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.correction__input {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
@media (max-width: 960px) {
|
||||
.correction {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
import { Component, computed, inject, signal } from '@angular/core';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
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 { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
|
||||
import { MatSnackBar, MatSnackBarModule } from '@angular/material/snack-bar';
|
||||
import { apiErrorMessage } from '../../../connect/api/api.types';
|
||||
import { PdfSourceApi } from '../../../connect/api/pdf-source.api';
|
||||
import { PdfPageViewer } from '../../../connect/components/pdf-page-viewer/pdf-page-viewer';
|
||||
import { DrawnRegionBox } from '../../../connect/components/pdf-page-viewer/region-draw-overlay.directive';
|
||||
|
||||
export interface OcrCorrectionField {
|
||||
name: string;
|
||||
label: string;
|
||||
}
|
||||
|
||||
export interface OcrCorrectionDialogData {
|
||||
title: string;
|
||||
/** The row's stored PDF, already fetched by the caller and wrapped as a browser File. */
|
||||
file: File;
|
||||
fields: OcrCorrectionField[];
|
||||
currentValues: Record<string, unknown>;
|
||||
}
|
||||
|
||||
export interface OcrCorrectionResult {
|
||||
values: Record<string, string>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Manual correction of an OCR row. The user picks a field and draws a box
|
||||
* over its value on the stored PDF; the text read from that box fills an
|
||||
* editable input. What gets saved is the input's value, so a bad read can
|
||||
* be fixed by hand.
|
||||
*/
|
||||
@Component({
|
||||
selector: 'app-ocr-correction-dialog',
|
||||
imports: [
|
||||
MatButtonModule,
|
||||
MatDialogModule,
|
||||
MatFormFieldModule,
|
||||
MatIconModule,
|
||||
MatInputModule,
|
||||
MatProgressSpinnerModule,
|
||||
MatSnackBarModule,
|
||||
PdfPageViewer,
|
||||
],
|
||||
templateUrl: './ocr-correction-dialog.html',
|
||||
styleUrl: './ocr-correction-dialog.scss',
|
||||
})
|
||||
export class OcrCorrectionDialog {
|
||||
readonly data = inject<OcrCorrectionDialogData>(MAT_DIALOG_DATA);
|
||||
private readonly dialogRef = inject<MatDialogRef<OcrCorrectionDialog, OcrCorrectionResult>>(MatDialogRef);
|
||||
private readonly pdfApi = inject(PdfSourceApi);
|
||||
private readonly snackBar = inject(MatSnackBar);
|
||||
|
||||
readonly page = signal(1);
|
||||
readonly pageCount = signal(1);
|
||||
readonly activeField = signal<string | null>(this.data.fields[0]?.name ?? null);
|
||||
readonly extracting = signal(false);
|
||||
|
||||
readonly values = signal<Record<string, string>>(
|
||||
Object.fromEntries(
|
||||
this.data.fields.map((field) => [
|
||||
field.name,
|
||||
this.data.currentValues[field.name] == null ? '' : String(this.data.currentValues[field.name]),
|
||||
]),
|
||||
),
|
||||
);
|
||||
|
||||
readonly canSave = computed(() => Object.values(this.values()).some((value) => value.trim() !== ''));
|
||||
|
||||
constructor() {
|
||||
this.pdfApi.detect(this.data.file).subscribe({
|
||||
next: (detection) => this.pageCount.set(detection.page_count || 1),
|
||||
error: () => this.pageCount.set(1),
|
||||
});
|
||||
}
|
||||
|
||||
selectField(name: string): void {
|
||||
this.activeField.set(name);
|
||||
}
|
||||
|
||||
setValue(name: string, value: string): void {
|
||||
this.values.update((values) => ({ ...values, [name]: value }));
|
||||
}
|
||||
|
||||
onRegionDrawn(box: DrawnRegionBox): void {
|
||||
const field = this.activeField();
|
||||
if (!field) return;
|
||||
this.extracting.set(true);
|
||||
this.pdfApi
|
||||
.extractRegions(this.data.file, [{ target_field: field, page_numbers: [this.page()], bbox: [box.x0, box.y0, box.x1, box.y1] }], null)
|
||||
.subscribe({
|
||||
next: (result) => {
|
||||
this.extracting.set(false);
|
||||
const extracted = result.rows[0]?.[field];
|
||||
if (extracted != null && String(extracted).trim() !== '') {
|
||||
this.setValue(field, String(extracted));
|
||||
} else {
|
||||
this.snackBar.open('No se encontró texto en la región marcada — edita el campo a mano.', 'OK', { duration: 4000 });
|
||||
}
|
||||
},
|
||||
error: (error) => {
|
||||
this.extracting.set(false);
|
||||
this.snackBar.open(apiErrorMessage(error, 'No se pudo leer esa región.'), 'OK', { duration: 4000 });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
save(): void {
|
||||
const values = Object.fromEntries(Object.entries(this.values()).filter(([, value]) => value.trim() !== ''));
|
||||
this.dialogRef.close({ values });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user