integration layer; merge work on indicators from forks with existing ingestion pipeline
This commit is contained in:
@@ -0,0 +1,138 @@
|
||||
<h2 mat-dialog-title class="gallery__title">
|
||||
@if (view() !== 'catalog') {
|
||||
<button mat-icon-button type="button" (click)="back()" aria-label="Volver a los conectores">
|
||||
<mat-icon aria-hidden="true">arrow_back</mat-icon>
|
||||
</button>
|
||||
}
|
||||
<span>{{ view() === 'catalog' ? 'Obtener datos' : entry()?.name }}</span>
|
||||
</h2>
|
||||
|
||||
<mat-dialog-content class="gallery__content">
|
||||
@switch (view()) {
|
||||
@case ('catalog') {
|
||||
<div class="gallery">
|
||||
<mat-nav-list class="gallery__categories" aria-label="Categorías de conectores">
|
||||
@for (item of visibleCategories(); track item.id) {
|
||||
<a mat-list-item [activated]="category() === item.id" (click)="category.set(item.id)" role="button">
|
||||
<mat-icon matListItemIcon aria-hidden="true">{{ item.icon }}</mat-icon>
|
||||
<span matListItemTitle>{{ item.label }}</span>
|
||||
</a>
|
||||
}
|
||||
</mat-nav-list>
|
||||
|
||||
<section class="gallery__main">
|
||||
<mat-form-field appearance="outline" class="gallery__search" subscriptSizing="dynamic">
|
||||
<mat-icon matPrefix aria-hidden="true">search</mat-icon>
|
||||
<mat-label>Buscar conector</mat-label>
|
||||
<input matInput (input)="onSearch($event)" />
|
||||
</mat-form-field>
|
||||
|
||||
@if (catalogError(); as error) {
|
||||
<p class="db-test db-test--error" role="alert"><mat-icon aria-hidden="true">error</mat-icon>{{ error }}</p>
|
||||
}
|
||||
<div class="gallery__grid" role="list">
|
||||
@for (item of visibleEntries(); track item.id) {
|
||||
<button
|
||||
type="button"
|
||||
class="connector-card"
|
||||
matRipple
|
||||
role="listitem"
|
||||
[disabled]="!item.available"
|
||||
[matTooltip]="item.available ? '' : 'No disponible en este servidor'"
|
||||
(click)="pick(item)"
|
||||
>
|
||||
<mat-icon class="connector-card__icon" aria-hidden="true">{{ item.icon }}</mat-icon>
|
||||
<span class="connector-card__name">{{ item.name }}</span>
|
||||
<span class="connector-card__description">{{ item.description }}</span>
|
||||
</button>
|
||||
} @empty {
|
||||
<p class="gallery__empty">Ningún conector coincide con la búsqueda.</p>
|
||||
}
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
}
|
||||
|
||||
@case ('files') {
|
||||
<p class="gallery__hint">
|
||||
@switch (entry()?.connector?.kind) {
|
||||
@case ('document') {
|
||||
Agrega todos los documentos juntos: reportes, formatos o notas en PDF o imagen. Se separan por paciente aunque
|
||||
uno ocupe varias páginas o varios archivos, y los campos se extraen del texto, incluido el texto libre.
|
||||
}
|
||||
@case ('edf') {
|
||||
Agrega todos los registros juntos; cada archivo será una fila con los datos del estudio y el archivo original.
|
||||
}
|
||||
@default {
|
||||
Puedes agregar varios archivos a la vez; cada uno se convierte en una conexión y sus tablas (las hojas de un
|
||||
libro de Excel, las tablas de un PDF) quedan disponibles para mapear.
|
||||
}
|
||||
}
|
||||
</p>
|
||||
<app-file-dropzone [accept]="entry()?.connector?.extensions ?? []" [multiple]="true" (filesChange)="files.set($event)"></app-file-dropzone>
|
||||
}
|
||||
|
||||
@case ('database') {
|
||||
<p class="gallery__hint">
|
||||
Solo lectura: la conexión se abre en modo de solo lectura y únicamente se permiten consultas SELECT.
|
||||
</p>
|
||||
@if (engine() === 'url') {
|
||||
<form [formGroup]="urlForm" class="db-form" (ngSubmit)="connectDatabase()">
|
||||
<mat-form-field appearance="outline" class="db-form__wide">
|
||||
<mat-label>Cadena de conexión</mat-label>
|
||||
<input matInput formControlName="url" placeholder="postgresql+psycopg2://usuario:contraseña@host:5432/base" autocomplete="off" />
|
||||
<mat-hint>Formato SQLAlchemy: dialecto+driver://usuario:contraseña@host:puerto/base</mat-hint>
|
||||
</mat-form-field>
|
||||
</form>
|
||||
} @else {
|
||||
<form [formGroup]="serverForm" class="db-form" (ngSubmit)="connectDatabase()">
|
||||
<mat-form-field appearance="outline" class="db-form__host">
|
||||
<mat-label>Servidor</mat-label>
|
||||
<input matInput formControlName="host" placeholder="10.0.10.41" autocomplete="off" />
|
||||
</mat-form-field>
|
||||
<mat-form-field appearance="outline" class="db-form__port">
|
||||
<mat-label>Puerto</mat-label>
|
||||
<input matInput type="number" formControlName="port" />
|
||||
<mat-hint>Predeterminado: {{ serverEngine()?.default_port }}</mat-hint>
|
||||
</mat-form-field>
|
||||
<mat-form-field appearance="outline" class="db-form__wide">
|
||||
<mat-label>Base de datos</mat-label>
|
||||
<input matInput formControlName="database" autocomplete="off" />
|
||||
</mat-form-field>
|
||||
<mat-form-field appearance="outline">
|
||||
<mat-label>Usuario</mat-label>
|
||||
<input matInput formControlName="user" autocomplete="off" />
|
||||
</mat-form-field>
|
||||
<mat-form-field appearance="outline">
|
||||
<mat-label>Contraseña</mat-label>
|
||||
<input matInput type="password" formControlName="password" autocomplete="new-password" />
|
||||
</mat-form-field>
|
||||
</form>
|
||||
}
|
||||
|
||||
@if (testing()) {
|
||||
<mat-progress-bar mode="indeterminate" aria-label="Probando conexión"></mat-progress-bar>
|
||||
}
|
||||
@if (testResult(); as result) {
|
||||
<p class="db-test" [class.db-test--error]="!result.ok" role="status">
|
||||
<mat-icon aria-hidden="true">{{ result.ok ? 'check_circle' : 'error' }}</mat-icon>{{ result.message }}
|
||||
</p>
|
||||
}
|
||||
}
|
||||
}
|
||||
</mat-dialog-content>
|
||||
|
||||
<mat-dialog-actions align="end">
|
||||
<button mat-button mat-dialog-close type="button">Cancelar</button>
|
||||
@if (view() === 'files') {
|
||||
<button mat-flat-button type="button" [disabled]="files().length === 0" (click)="connectFiles()">
|
||||
Conectar {{ files().length > 1 ? files().length + ' archivos' : '' }}
|
||||
</button>
|
||||
}
|
||||
@if (view() === 'database') {
|
||||
<button mat-stroked-button type="button" [disabled]="testing()" (click)="testConnection()">
|
||||
<mat-icon aria-hidden="true">network_check</mat-icon>Probar conexión
|
||||
</button>
|
||||
<button mat-flat-button type="button" [disabled]="databaseFormInvalid" (click)="connectDatabase()">Conectar</button>
|
||||
}
|
||||
</mat-dialog-actions>
|
||||
@@ -0,0 +1,120 @@
|
||||
.gallery__title {
|
||||
align-items: center;
|
||||
display: flex;
|
||||
gap: var(--space-2);
|
||||
}
|
||||
|
||||
.gallery__content {
|
||||
min-height: 420px;
|
||||
}
|
||||
|
||||
.gallery {
|
||||
display: grid;
|
||||
gap: var(--space-4);
|
||||
grid-template-columns: 200px 1fr;
|
||||
}
|
||||
|
||||
.gallery__categories {
|
||||
border-right: 1px solid var(--mat-sys-outline-variant);
|
||||
padding-right: var(--space-2);
|
||||
}
|
||||
|
||||
.gallery__search {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.gallery__grid {
|
||||
display: grid;
|
||||
gap: var(--space-3);
|
||||
grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
|
||||
margin-top: var(--space-3);
|
||||
}
|
||||
|
||||
.connector-card {
|
||||
align-items: flex-start;
|
||||
background: var(--mat-sys-surface);
|
||||
border: 1px solid var(--mat-sys-outline-variant);
|
||||
border-radius: var(--mat-sys-corner-medium);
|
||||
color: var(--mat-sys-on-surface);
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
font: inherit;
|
||||
gap: var(--space-1);
|
||||
min-height: 118px;
|
||||
padding: var(--space-4);
|
||||
position: relative;
|
||||
text-align: left;
|
||||
transition: border-color 0.15s ease, box-shadow 0.15s ease;
|
||||
|
||||
&:hover,
|
||||
&:focus-visible {
|
||||
border-color: var(--mat-sys-primary);
|
||||
box-shadow: var(--mat-sys-level1);
|
||||
outline: none;
|
||||
}
|
||||
}
|
||||
|
||||
.connector-card__icon {
|
||||
color: var(--mat-sys-primary);
|
||||
margin-bottom: var(--space-1);
|
||||
}
|
||||
|
||||
.connector-card__name {
|
||||
font: var(--mat-sys-title-small);
|
||||
}
|
||||
|
||||
.connector-card__description {
|
||||
color: var(--mat-sys-on-surface-variant);
|
||||
font: var(--mat-sys-body-small);
|
||||
}
|
||||
|
||||
.gallery__hint {
|
||||
color: var(--mat-sys-on-surface-variant);
|
||||
font: var(--mat-sys-body-medium);
|
||||
margin: 0 0 var(--space-4);
|
||||
max-width: 720px;
|
||||
}
|
||||
|
||||
.gallery__empty {
|
||||
color: var(--mat-sys-on-surface-variant);
|
||||
}
|
||||
|
||||
.db-form {
|
||||
display: grid;
|
||||
gap: 0 var(--space-4);
|
||||
grid-template-columns: 1fr 1fr;
|
||||
}
|
||||
|
||||
.db-form__wide {
|
||||
grid-column: 1 / -1;
|
||||
}
|
||||
|
||||
.db-test {
|
||||
align-items: center;
|
||||
color: var(--mat-sys-primary);
|
||||
display: flex;
|
||||
gap: var(--space-2);
|
||||
margin: var(--space-3) 0 0;
|
||||
|
||||
&.db-test--error {
|
||||
color: var(--mat-sys-error);
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 720px) {
|
||||
.gallery {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
.gallery__categories {
|
||||
border-right: 0;
|
||||
}
|
||||
.db-form {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
.connector-card:disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.55;
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
import { Component, computed, inject, signal } from '@angular/core';
|
||||
import { FormBuilder, ReactiveFormsModule, Validators } from '@angular/forms';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { 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 { MatListModule } from '@angular/material/list';
|
||||
import { MatProgressBarModule } from '@angular/material/progress-bar';
|
||||
import { MatRippleModule } from '@angular/material/core';
|
||||
import { MatTooltipModule } from '@angular/material/tooltip';
|
||||
import { toSignal } from '@angular/core/rxjs-interop';
|
||||
import { catchError, of } from 'rxjs';
|
||||
import { ConnectorInfo, SqlConnectionRef, SqlEngineInfo, apiErrorMessage } from '../../api/api.types';
|
||||
import { ConnectorsApi } from '../../api/connectors.api';
|
||||
import { SourceGateway } from '../../api/source-gateway';
|
||||
import { connectionsFor } from '../../domain/connection-registry';
|
||||
import { GALLERY_CATEGORIES, GalleryCategory, GalleryEntry, galleryEntries } from '../../domain/connector-catalog';
|
||||
import { DataConnection } from '../../domain/data-source';
|
||||
import { SqlConnection } from '../../domain/sql-source';
|
||||
import { describeSqlServer, describeSqlUrl } from '../../domain/sql-url';
|
||||
import { FileDropzone } from '../file-dropzone/file-dropzone';
|
||||
|
||||
type View = 'catalog' | 'files' | 'database';
|
||||
|
||||
/**
|
||||
* "Obtener datos": pick a connector from the gallery (as reported by the
|
||||
* server), then drop files or fill a database connection form. Closes
|
||||
* with the new, not yet loaded, `DataConnection`s.
|
||||
*/
|
||||
@Component({
|
||||
selector: 'app-connector-gallery-dialog',
|
||||
imports: [
|
||||
FileDropzone,
|
||||
MatButtonModule,
|
||||
MatDialogModule,
|
||||
MatFormFieldModule,
|
||||
MatIconModule,
|
||||
MatInputModule,
|
||||
MatListModule,
|
||||
MatProgressBarModule,
|
||||
MatRippleModule,
|
||||
MatTooltipModule,
|
||||
ReactiveFormsModule,
|
||||
],
|
||||
templateUrl: './connector-gallery-dialog.html',
|
||||
styleUrl: './connector-gallery-dialog.scss',
|
||||
})
|
||||
export class ConnectorGalleryDialog {
|
||||
private readonly dialogRef = inject<MatDialogRef<ConnectorGalleryDialog, DataConnection[]>>(MatDialogRef);
|
||||
private readonly gateway = inject(SourceGateway);
|
||||
private readonly formBuilder = inject(FormBuilder);
|
||||
|
||||
readonly categories = GALLERY_CATEGORIES;
|
||||
readonly category = signal<GalleryCategory>('all');
|
||||
readonly search = signal('');
|
||||
readonly view = signal<View>('catalog');
|
||||
readonly entry = signal<GalleryEntry | null>(null);
|
||||
readonly catalogError = signal<string | null>(null);
|
||||
|
||||
private readonly connectors = toSignal(
|
||||
inject(ConnectorsApi)
|
||||
.list()
|
||||
.pipe(
|
||||
catchError((error) => {
|
||||
this.catalogError.set(apiErrorMessage(error, 'No se pudo consultar los conectores del servidor.'));
|
||||
return of([] as ConnectorInfo[]);
|
||||
}),
|
||||
),
|
||||
{ initialValue: [] as ConnectorInfo[] },
|
||||
);
|
||||
private readonly entries = computed(() => galleryEntries(this.connectors()));
|
||||
|
||||
readonly visibleEntries = computed(() => {
|
||||
const term = this.search().trim().toLowerCase();
|
||||
return this.entries().filter(
|
||||
(entry) =>
|
||||
(this.category() === 'all' || entry.category === this.category()) &&
|
||||
(!term || entry.name.toLowerCase().includes(term) || entry.description.toLowerCase().includes(term)),
|
||||
);
|
||||
});
|
||||
readonly visibleCategories = computed(() =>
|
||||
this.categories.filter((c) => c.id === 'all' || this.entries().some((entry) => entry.category === c.id)),
|
||||
);
|
||||
|
||||
// -- files --
|
||||
readonly files = signal<File[]>([]);
|
||||
|
||||
// -- database --
|
||||
readonly serverForm = this.formBuilder.nonNullable.group({
|
||||
host: ['', Validators.required],
|
||||
port: [null as number | null],
|
||||
database: ['', Validators.required],
|
||||
user: [''],
|
||||
password: [''],
|
||||
});
|
||||
readonly urlForm = this.formBuilder.nonNullable.group({ url: ['', Validators.required] });
|
||||
readonly testing = signal(false);
|
||||
readonly testResult = signal<{ ok: boolean; message: string } | null>(null);
|
||||
|
||||
readonly engine = computed(() => this.entry()?.engine ?? null);
|
||||
readonly serverEngine = computed(() => {
|
||||
const engine = this.engine();
|
||||
return engine && engine !== 'url' ? engine : null;
|
||||
});
|
||||
|
||||
pick(entry: GalleryEntry): void {
|
||||
if (!entry.available) return;
|
||||
this.entry.set(entry);
|
||||
this.testResult.set(null);
|
||||
this.view.set(entry.engine ? 'database' : 'files');
|
||||
}
|
||||
|
||||
back(): void {
|
||||
this.view.set('catalog');
|
||||
this.files.set([]);
|
||||
}
|
||||
|
||||
onSearch(event: Event): void {
|
||||
this.search.set((event.target as HTMLInputElement).value);
|
||||
}
|
||||
|
||||
testConnection(): void {
|
||||
const ref = this.connectionRef();
|
||||
if (!ref) return;
|
||||
this.testing.set(true);
|
||||
this.testResult.set(null);
|
||||
this.gateway.sql.testConnection(ref).subscribe({
|
||||
next: (response) => {
|
||||
this.testing.set(false);
|
||||
this.testResult.set({ ok: true, message: `Conexión correcta (${response.dialect}).` });
|
||||
},
|
||||
error: (error) => {
|
||||
this.testing.set(false);
|
||||
this.testResult.set({ ok: false, message: apiErrorMessage(error, 'No se pudo conectar.') });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
connectFiles(): void {
|
||||
const entry = this.entry();
|
||||
if (entry) this.dialogRef.close(connectionsFor(entry.connector.kind, this.files()));
|
||||
}
|
||||
|
||||
connectDatabase(): void {
|
||||
const ref = this.connectionRef();
|
||||
if (!ref) return;
|
||||
this.dialogRef.close([new SqlConnection(ref, this.connectionLabel(), this.serverEngine()?.default_schema ?? undefined)]);
|
||||
}
|
||||
|
||||
get databaseFormInvalid(): boolean {
|
||||
return this.engine() === 'url' ? this.urlForm.invalid : this.serverForm.invalid;
|
||||
}
|
||||
|
||||
private connectionRef(): SqlConnectionRef | null {
|
||||
const engine = this.engine();
|
||||
if (!engine) return null;
|
||||
if (engine === 'url') {
|
||||
this.urlForm.markAllAsTouched();
|
||||
return this.urlForm.valid ? { connection_string: this.urlForm.getRawValue().url.trim() } : null;
|
||||
}
|
||||
this.serverForm.markAllAsTouched();
|
||||
if (this.serverForm.invalid) return null;
|
||||
return { server: { engine: engine.id, ...this.serverForm.getRawValue() } };
|
||||
}
|
||||
|
||||
private connectionLabel(): string {
|
||||
const engine = this.engine();
|
||||
if (engine === 'url') return describeSqlUrl(this.urlForm.getRawValue().url);
|
||||
return describeSqlServer({ engine: engine as SqlEngineInfo, ...this.serverForm.getRawValue() });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user