integration layer; merge work on indicators from forks with existing ingestion pipeline
This commit is contained in:
@@ -0,0 +1,157 @@
|
||||
import { DragDropModule } from '@angular/cdk/drag-drop';
|
||||
import { DecimalPipe } from '@angular/common';
|
||||
import { Component, Injector, inject, signal } from '@angular/core';
|
||||
import { MatBadgeModule } from '@angular/material/badge';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatButtonToggleModule } from '@angular/material/button-toggle';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { MatPaginatorIntl } from '@angular/material/paginator';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatSidenavModule } from '@angular/material/sidenav';
|
||||
import { MatSnackBar, MatSnackBarModule } from '@angular/material/snack-bar';
|
||||
import { MatToolbarModule } from '@angular/material/toolbar';
|
||||
import { MatTooltipModule } from '@angular/material/tooltip';
|
||||
import { Domain, TargetMeta } from '../../api/api.types';
|
||||
import { DataConnection, SourceTable } from '../../domain/data-source';
|
||||
import { PdfConnection } from '../../domain/pdf-source';
|
||||
import { SqlConnection } from '../../domain/sql-source';
|
||||
import { ConnectWorkspaceStore, DOMAINS } from '../../state/connect-workspace.store';
|
||||
import { ConnectionsPanel, TableUse } from '../connections-panel/connections-panel';
|
||||
import { ConnectorGalleryDialog } from '../connector-gallery-dialog/connector-gallery-dialog';
|
||||
import { DatabaseExplorerData, DatabaseExplorerDialog } from '../database-explorer-dialog/database-explorer-dialog';
|
||||
import { FlowCanvas } from '../flow-canvas/flow-canvas';
|
||||
import { FlowEditor } from '../flow-editor/flow-editor';
|
||||
import { LoadDialog, LoadDialogResult } from '../load-dialog/load-dialog';
|
||||
import { NewFlowDialog, NewFlowDialogData } from '../new-flow-dialog/new-flow-dialog';
|
||||
import { PdfRegionsDialog, PdfRegionsDialogData, PdfRegionsResult } from '../pdf-regions-dialog/pdf-regions-dialog';
|
||||
import { SpanishPaginatorIntl } from '../shared/spanish-paginator-intl';
|
||||
import { SqlQueryDialog, SqlQueryResult } from '../sql-query-dialog/sql-query-dialog';
|
||||
|
||||
/**
|
||||
* The "Conectar datos" workspace (route `/conectar`): connections pane on
|
||||
* the left, composition canvas + selected flow's editor in the middle, a
|
||||
* toolbar for the batch-level actions, a status bar. Owns the workspace
|
||||
* store (one per visit) and the dialogs; everything else is delegated to
|
||||
* the child components and the store.
|
||||
*/
|
||||
@Component({
|
||||
selector: 'app-connect-page',
|
||||
imports: [
|
||||
ConnectionsPanel,
|
||||
DecimalPipe,
|
||||
DragDropModule,
|
||||
FlowCanvas,
|
||||
FlowEditor,
|
||||
MatBadgeModule,
|
||||
MatButtonModule,
|
||||
MatButtonToggleModule,
|
||||
MatIconModule,
|
||||
MatSidenavModule,
|
||||
MatSnackBarModule,
|
||||
MatToolbarModule,
|
||||
MatTooltipModule,
|
||||
],
|
||||
// Workspace-scoped (the lazy chunk), including for dialogs opened with
|
||||
// this page's injector.
|
||||
providers: [ConnectWorkspaceStore, { provide: MatPaginatorIntl, useClass: SpanishPaginatorIntl }],
|
||||
templateUrl: './connect-page.html',
|
||||
styleUrl: './connect-page.scss',
|
||||
})
|
||||
export class ConnectPage {
|
||||
readonly store = inject(ConnectWorkspaceStore);
|
||||
private readonly dialog = inject(MatDialog);
|
||||
private readonly snackBar = inject(MatSnackBar);
|
||||
private readonly injector = inject(Injector);
|
||||
|
||||
readonly domains = DOMAINS;
|
||||
readonly paneOpen = signal(true);
|
||||
readonly validatingAll = signal(false);
|
||||
|
||||
setDomain(domain: Domain): void {
|
||||
this.store.setDomain(domain);
|
||||
}
|
||||
|
||||
openGallery(): void {
|
||||
this.dialog
|
||||
.open<ConnectorGalleryDialog, void, DataConnection[]>(ConnectorGalleryDialog, { width: '960px', maxWidth: '96vw', autoFocus: false })
|
||||
.afterClosed()
|
||||
.subscribe((connections) => connections?.forEach((connection) => this.store.addConnection(connection)));
|
||||
}
|
||||
|
||||
useTable({ table, target }: TableUse): void {
|
||||
if (target) {
|
||||
this.store.createFlow(table, target);
|
||||
return;
|
||||
}
|
||||
this.dialog
|
||||
.open<NewFlowDialog, NewFlowDialogData, TargetMeta>(NewFlowDialog, {
|
||||
width: '560px',
|
||||
maxWidth: '96vw',
|
||||
data: { table, targets: this.store.targets(), existingTargets: this.store.flowsByTarget() },
|
||||
})
|
||||
.afterClosed()
|
||||
.subscribe((chosen) => chosen && this.store.createFlow(table, chosen));
|
||||
}
|
||||
|
||||
onTableDropped(table: SourceTable): void {
|
||||
this.useTable({ table });
|
||||
}
|
||||
|
||||
addQuery(connection: SqlConnection): void {
|
||||
this.dialog
|
||||
.open<SqlQueryDialog, SqlConnection, SqlQueryResult>(SqlQueryDialog, { data: connection, maxWidth: '96vw' })
|
||||
.afterClosed()
|
||||
.subscribe((result) => {
|
||||
if (!result) return;
|
||||
const table = connection.addQuery(result.name, result.query);
|
||||
this.useTable({ table });
|
||||
});
|
||||
}
|
||||
|
||||
drawRegions(connection: PdfConnection): void {
|
||||
const fieldNames = [...new Set(this.store.targets().flatMap((target) => target.fields.map((field) => field.name)))].sort();
|
||||
this.dialog
|
||||
.open<PdfRegionsDialog, PdfRegionsDialogData, PdfRegionsResult>(PdfRegionsDialog, {
|
||||
data: { connection, fieldNames },
|
||||
width: '1280px',
|
||||
maxWidth: '98vw',
|
||||
autoFocus: false,
|
||||
// Drawn regions are real work: Escape (which also dismisses the
|
||||
// name autocomplete) must not discard them; only "Cancelar" does.
|
||||
disableClose: true,
|
||||
})
|
||||
.afterClosed()
|
||||
.subscribe((result) => {
|
||||
if (!result) return;
|
||||
const table = connection.addRegions(result.name, result.regions);
|
||||
this.useTable({ table });
|
||||
});
|
||||
}
|
||||
|
||||
async validateAll(): Promise<void> {
|
||||
this.validatingAll.set(true);
|
||||
await this.store.validateAll();
|
||||
this.validatingAll.set(false);
|
||||
const { errors } = this.store.summary();
|
||||
this.snackBar.open(errors ? `Validación terminada: ${errors} fila(s) con errores.` : 'Validación terminada: sin errores.', 'OK', {
|
||||
duration: 4000,
|
||||
});
|
||||
}
|
||||
|
||||
openLoad(): void {
|
||||
this.dialog
|
||||
.open<LoadDialog, void, LoadDialogResult>(LoadDialog, { width: '920px', maxWidth: '96vw', injector: this.injector, autoFocus: false })
|
||||
.afterClosed()
|
||||
.subscribe((result) => result === 'explore' && this.openExplorer());
|
||||
}
|
||||
|
||||
openExplorer(initial?: string): void {
|
||||
const flow = this.store.selectedFlow();
|
||||
this.dialog.open<DatabaseExplorerDialog, DatabaseExplorerData>(DatabaseExplorerDialog, {
|
||||
injector: this.injector,
|
||||
width: '1280px',
|
||||
maxWidth: '98vw',
|
||||
data: { targets: this.store.targets(), initial: initial ?? flow?.target.key },
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user