87 lines
3.1 KiB
TypeScript
87 lines
3.1 KiB
TypeScript
import { CdkDrag, CdkDragDrop, DragDropModule } from '@angular/cdk/drag-drop';
|
|
import { Component, inject, output } from '@angular/core';
|
|
import { MatSnackBar } from '@angular/material/snack-bar';
|
|
import { MatBadgeModule } from '@angular/material/badge';
|
|
import { MatButtonModule } from '@angular/material/button';
|
|
import { MatDividerModule } from '@angular/material/divider';
|
|
import { MatExpansionModule } from '@angular/material/expansion';
|
|
import { MatIconModule } from '@angular/material/icon';
|
|
import { MatListModule } from '@angular/material/list';
|
|
import { MatMenuModule } from '@angular/material/menu';
|
|
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
|
|
import { MatTooltipModule } from '@angular/material/tooltip';
|
|
import { 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 } from '../../state/connect-workspace.store';
|
|
import { FileDropzone } from '../file-dropzone/file-dropzone';
|
|
|
|
/** Payload of a "use this table" request: a table, optionally already aimed at an entity. */
|
|
export interface TableUse {
|
|
table: SourceTable;
|
|
target?: TargetMeta;
|
|
}
|
|
|
|
/**
|
|
* The workspace's left pane: every
|
|
* connection with its tables (drag a table onto the canvas, or straight
|
|
* onto a destination entity below, to create a flow) and the destination
|
|
* schema of the current domain, with how many flows feed each entity.
|
|
*/
|
|
@Component({
|
|
selector: 'app-connections-panel',
|
|
imports: [
|
|
DragDropModule,
|
|
FileDropzone,
|
|
MatBadgeModule,
|
|
MatButtonModule,
|
|
MatDividerModule,
|
|
MatExpansionModule,
|
|
MatIconModule,
|
|
MatListModule,
|
|
MatMenuModule,
|
|
MatProgressSpinnerModule,
|
|
MatTooltipModule,
|
|
],
|
|
templateUrl: './connections-panel.html',
|
|
styleUrl: './connections-panel.scss',
|
|
})
|
|
export class ConnectionsPanel {
|
|
readonly store = inject(ConnectWorkspaceStore);
|
|
private readonly snackBar = inject(MatSnackBar);
|
|
|
|
readonly addConnection = output<void>();
|
|
readonly useTable = output<TableUse>();
|
|
readonly addQuery = output<SqlConnection>();
|
|
readonly drawRegions = output<PdfConnection>();
|
|
|
|
/** Table lists are drag *sources* only. */
|
|
readonly nothingEnters = () => false;
|
|
readonly onlyTables = (drag: CdkDrag) => drag.data instanceof SourceTable;
|
|
|
|
isSql(connection: DataConnection): connection is SqlConnection {
|
|
return connection instanceof SqlConnection;
|
|
}
|
|
|
|
isPdf(connection: DataConnection): connection is PdfConnection {
|
|
return connection instanceof PdfConnection;
|
|
}
|
|
|
|
flowCount(table: SourceTable): number {
|
|
return this.store.flowsOf(table).length;
|
|
}
|
|
|
|
onFilesDropped(files: File[]): void {
|
|
const rejected = this.store.addFiles(files);
|
|
if (rejected.length) {
|
|
this.snackBar.open(`Formato no soportado: ${rejected.map((file) => file.name).join(', ')}`, 'OK', { duration: 5000 });
|
|
}
|
|
}
|
|
|
|
onDropOnTarget(event: CdkDragDrop<TargetMeta>): void {
|
|
const table = event.item.data;
|
|
if (table instanceof SourceTable) this.useTable.emit({ table, target: event.container.data });
|
|
}
|
|
}
|