+ Para personal técnico: el nodo completo como lo guarda la plataforma.
+ @if (guided(d)) {
+ Si cambia su fuente aquí, deja de editarse con el asistente.
+ }
Si cambia algo aquí, la fuente deja de editarse con ayuda.
- }
-
- }
- @if (conceptMap(d); as cm) {
-
- }
+
+
Vista previa
@if (preview(); as rows) {
diff --git a/src/app/conectar/conectar.scss b/src/app/conectar/conectar.scss
index 83c9ff4..b0e74e4 100644
--- a/src/app/conectar/conectar.scss
+++ b/src/app/conectar/conectar.scss
@@ -140,3 +140,55 @@ h2 {
color: var(--color-success, #2e7d32);
}
}
+
+// The canvas's nodes: the kind small on top, the name below in two lines at most.
+:host ::ng-deep default-node {
+ box-sizing: border-box;
+ overflow: hidden;
+ padding: 4px 10px;
+ display: flex;
+ align-items: center;
+}
+:host ::ng-deep .node-caption {
+ min-width: 0;
+ width: 100%;
+ line-height: 1.2;
+}
+:host ::ng-deep .node-caption .kind {
+ display: block;
+ font-size: 10px;
+ color: var(--color-text-secondary);
+ white-space: nowrap;
+ overflow: hidden;
+ text-overflow: ellipsis;
+}
+:host ::ng-deep .node-caption .name {
+ display: -webkit-box;
+ -webkit-line-clamp: 2;
+ -webkit-box-orient: vertical;
+ overflow: hidden;
+ font-size: 12px;
+ font-weight: 500;
+ overflow-wrap: anywhere;
+}
+.panel-tabs {
+ margin-top: var(--space-2);
+}
+.panel-tabs .hint {
+ color: var(--color-text-secondary);
+ font-size: 12px;
+ margin: var(--space-3) 0;
+}
+.raw textarea {
+ font-family: monospace;
+ font-size: 12px;
+}
+.error {
+ color: var(--mat-sys-error);
+ font-size: 13px;
+}
+
+// Fields in the panel keep their hints clear of the next field's label.
+:host ::ng-deep .panel mat-form-field {
+ margin-bottom: var(--space-3);
+}
diff --git a/src/app/conectar/conectar.ts b/src/app/conectar/conectar.ts
index 3b6f5db..d63e95f 100644
--- a/src/app/conectar/conectar.ts
+++ b/src/app/conectar/conectar.ts
@@ -1,5 +1,13 @@
import { HttpErrorResponse } from '@angular/common/http';
-import { Component, computed, inject, resource, signal, WritableSignal } from '@angular/core';
+import {
+ Component,
+ computed,
+ effect,
+ inject,
+ resource,
+ signal,
+ WritableSignal,
+} from '@angular/core';
import { FormsModule, ReactiveFormsModule, UntypedFormGroup } from '@angular/forms';
import { MatButtonModule } from '@angular/material/button';
import { MatFormFieldModule } from '@angular/material/form-field';
@@ -7,7 +15,7 @@ import { MatIconModule } from '@angular/material/icon';
import { MatInputModule } from '@angular/material/input';
import { MatListModule } from '@angular/material/list';
import { MatDialog } from '@angular/material/dialog';
-import { MatSlideToggleModule } from '@angular/material/slide-toggle';
+import { MatTabsModule } from '@angular/material/tabs';
import { MatTableModule } from '@angular/material/table';
import { MatTooltipModule } from '@angular/material/tooltip';
import { FormlyFieldConfig, FormlyForm, provideFormlyCore } from '@ngx-formly/core';
@@ -57,21 +65,21 @@ export const KINDS: Record = {
read: 'Leer documentos',
route: 'Separar por tipo',
map: 'Traducir códigos',
- extract: 'Sacar datos',
+ extract: 'Extraer datos',
fhir: 'Leer FHIR',
- join: 'Juntar',
+ join: 'Unir',
link: 'Identificar a la persona',
target: 'Guardar en la plataforma',
};
export const HELP: Record = {
source: 'De dónde vienen los datos: una base de datos, una carpeta, la nube o una API.',
- read: 'Saca el texto de cada documento (PDF, Word, escaneos con OCR).',
+ read: 'Extrae el texto de cada documento (PDF, Word, escaneos con OCR).',
route:
'Deja pasar solo los documentos o filas que cumplen una condición; por ejemplo, las citologías.',
map: 'Cambia los códigos del hospital por los de la plataforma, con una tabla de equivalencias.',
- extract: 'Toma de cada documento los datos de un estudio: fechas, resultados, nombres.',
- fhir: 'Lee paquetes FHIR que un sistema envió y saca de ellos los estudios.',
- join: 'Junta dos entradas que hablan de lo mismo; por ejemplo, un resultado con su orden.',
+ extract: 'Extrae de cada documento los datos de un estudio: fechas, resultados, nombres.',
+ fhir: 'Lee los paquetes FHIR que envía un sistema y extrae sus estudios.',
+ join: 'Une dos entradas que se refieren al mismo registro; por ejemplo, un resultado con su orden.',
link: 'Reconoce a qué paciente pertenece cada registro, aunque su nombre venga escrito distinto.',
target: 'Guarda los estudios ya revisados en la plataforma.',
};
@@ -90,7 +98,7 @@ const ID = /^[a-z][a-z0-9_]*$/;
MatIconModule,
MatInputModule,
MatListModule,
- MatSlideToggleModule,
+ MatTabsModule,
MatTableModule,
MatTooltipModule,
Vflow,
@@ -107,8 +115,9 @@ export class Conectar {
private readonly dialog = inject(MatDialog);
protected readonly kinds = Object.entries(KINDS) as [Kind, string][];
protected readonly help = HELP;
- /** The raw form of a source drawn with the dialog ("Avanzado"). */
- protected readonly advanced = signal(false);
+ /** "Avanzado": the selected node as JSON, as edited and not applied yet. */
+ protected readonly rawDraft = signal(undefined);
+ protected readonly rawError = signal('');
protected readonly list = resource({ loader: () => this.api.invoke(pipelines) });
private readonly schema = resource({ loader: () => this.api.invoke(schema) });
@@ -132,6 +141,20 @@ export class Conectar {
return !!run && !['SUCCESS', 'FAILURE', 'CANCELED'].includes(run.status);
});
+ /** What the node forms share: each entity's fields by their titles (the catalog's). */
+ protected readonly formOptions = { formState: { fields: {} as Record } };
+ private readonly titles = effect(() => {
+ const entities = (this.schema.value()?.['entities'] ?? {}) as Record<
+ string,
+ { properties?: Record }
+ >;
+ this.formOptions.formState.fields = Object.fromEntries(
+ Object.entries(entities).map(([e, s]) => [
+ e,
+ Object.fromEntries(Object.entries(s.properties ?? {}).map(([f, p]) => [f, p.title ?? f])),
+ ]),
+ );
+ });
protected form = new UntypedFormGroup({});
protected model: Record = {};
/** The selected node's form, generated from its kind's JSON Schema. */
@@ -264,7 +287,8 @@ export class Conectar {
);
this.form = new UntypedFormGroup({});
this.preview.set(undefined);
- this.advanced.set(false);
+ this.rawDraft.set(undefined);
+ this.rawError.set('');
}
/** A source the dialog drew (its answers make its dlt fields). */
@@ -279,13 +303,46 @@ export class Conectar {
const values = Object.fromEntries(
Object.entries(model).filter(([, v]) => v !== undefined && v !== null),
);
- if (this.advanced()) delete values['guided']; // drawn by hand from here on
this.update(
id,
(d) => ({ ...values, id: d.id, kind: d.kind, inputs: d.inputs }) as unknown as Doc,
);
}
+ /** The node as the platform keeps it (its place on the canvas aside). */
+ protected raw(d: Doc): string {
+ const { position, ...rest } = d as Doc & { position?: unknown };
+ return JSON.stringify(rest, null, 2);
+ }
+
+ /** "Aplicar": the edited JSON becomes the node. Its kind stays; its id changes with the
+ * Id field (so the arrows follow). A source whose dlt fields change is drawn by hand from
+ * then on (unless a catalog type makes it exactly: the platform reads it back). */
+ protected applyRaw(): void {
+ const d = this.doc();
+ const text = this.rawDraft();
+ if (!d || text === undefined) return;
+ let parsed: Record;
+ try {
+ parsed = JSON.parse(text);
+ } catch {
+ this.rawError.set('El texto no es JSON válido.');
+ return;
+ }
+ if (parsed['kind'] !== d.kind) {
+ this.rawError.set(`El tipo del nodo es «${d.kind}» y no cambia aquí.`);
+ return;
+ }
+ if (d.kind === 'source') {
+ const dlt = ['source', 'args', 'resource', 'then'] as const;
+ const before = d as unknown as Record;
+ if (dlt.some((k) => JSON.stringify(parsed[k]) !== JSON.stringify(before[k])))
+ delete parsed['guided'];
+ }
+ this.update(d.id, () => ({ ...parsed, id: d.id, kind: d.kind }) as unknown as Doc);
+ this.select(d.id);
+ }
+
protected rename(to: string): void {
const from = this.selected();
if (!from || from === to || !ID.test(to) || this.docs().some((d) => d.id === to)) return;
@@ -363,7 +420,7 @@ export class Conectar {
? await this.api.invoke(sourcePreview, { limit: 20, body: doc as Source })
: await this.api.invoke(nodeRows, { pipeline_id: id, node_id: doc.id, limit: 50 });
this.preview.set(rows);
- this.message.set(rows.length ? '' : 'Sin filas todavía: ejecute la canalización.');
+ this.message.set(rows.length ? '' : 'Sin filas: ejecute la canalización.');
} catch (e) {
this.message.set(problem(e));
}
@@ -389,7 +446,14 @@ export class Conectar {
}
function text(d: Doc): string {
- return `${KINDS[d.kind ?? 'source']} · ${d.label || d.id}`;
+ // ngx-vflow draws a node's text as HTML: the kind above, the name below (two lines at
+ // most; the whole of it on hover). The name is the operator's text, so it is escaped.
+ const kind = KINDS[d.kind ?? 'source'];
+ const name = escape(d.label || d.id);
+ return (
+ `
` +
+ `${kind}${name}
`
+ );
}
/** Each node's distance from the sources: its column when it has no saved position. */
@@ -416,3 +480,10 @@ function problem(e: unknown): string {
}
return String(e);
}
+
+function escape(text: string): string {
+ return text.replace(
+ /[&<>"']/g,
+ (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[c]!,
+ );
+}
diff --git a/src/app/conectar/schema-form.spec.ts b/src/app/conectar/schema-form.spec.ts
index da73b01..04bc403 100644
--- a/src/app/conectar/schema-form.spec.ts
+++ b/src/app/conectar/schema-form.spec.ts
@@ -16,6 +16,12 @@ const PIPELINE = {
when: { type: 'array', items: { $ref: '#/$defs/Condition' } },
resource: { anyOf: [{ type: 'string' }, { type: 'null' }], title: 'Resource' },
values: { type: 'object', additionalProperties: { type: 'string' }, title: 'Values' },
+ on: {
+ type: 'array',
+ items: { type: 'array', prefixItems: [{ type: 'string' }, { type: 'string' }] },
+ },
+ extra: { type: 'object', title: 'Extra' },
+ source: { type: 'string', advanced: true },
},
},
},
@@ -25,7 +31,7 @@ describe('node forms from the pipeline schema', () => {
const schema = nodeSchema(PIPELINE, 'route') as any;
it('leaves out what the canvas edits', () => {
- expect(Object.keys(schema.properties)).toEqual(['when', 'resource', 'values']);
+ expect(Object.keys(schema.properties)).toEqual(['when', 'resource', 'values', 'on']);
expect(schema.required).toEqual(['when']);
});
@@ -34,7 +40,13 @@ describe('node forms from the pipeline schema', () => {
expect(schema.properties.resource.type).toBe('string');
});
- it('edits maps as JSON', () => {
- expect(schema.properties.values.widget.formlyConfig.type).toBe('json');
+ it('edits maps of texts and pairs as rows', () => {
+ expect(schema.properties.values.widget.formlyConfig.type).toBe('map');
+ expect(schema.properties.on.widget.formlyConfig.type).toBe('pairs');
+ });
+
+ it('leaves JSON-only values and advanced fields to the "Avanzado" tab', () => {
+ expect(schema.properties.extra).toBeUndefined();
+ expect(schema.properties.source).toBeUndefined();
});
});
diff --git a/src/app/conectar/schema-form.ts b/src/app/conectar/schema-form.ts
index c0599db..10e5328 100644
--- a/src/app/conectar/schema-form.ts
+++ b/src/app/conectar/schema-form.ts
@@ -3,6 +3,7 @@ import { MatButtonModule } from '@angular/material/button';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatIconModule } from '@angular/material/icon';
import { MatInputModule } from '@angular/material/input';
+import { MatSelectModule } from '@angular/material/select';
import { ReactiveFormsModule } from '@angular/forms';
import {
ConfigOption,
@@ -27,11 +28,29 @@ export function nodeSchema(pipeline: Schema, kind: string): Schema {
)!;
const node = structuredClone(defs[name]);
for (const field of CANVAS_FIELDS) delete node.properties?.[field];
- node.required = (node.required ?? []).filter((f) => !CANVAS_FIELDS.includes(f));
+ // The panel says what the kind does (in Spanish); the class's own docstring is for code.
+ delete node.title;
+ delete node.description;
+ // What a guided dialog fills, or what only JSON can say, is for the "Avanzado" tab.
+ for (const [field, value] of Object.entries(node.properties ?? {})) {
+ const simple = simplify(value as Schema, defs) as Schema & { widget?: unknown };
+ if ((value as { advanced?: boolean }).advanced || isJson(simple))
+ delete node.properties![field];
+ }
+ node.required = (node.required ?? []).filter(
+ (f) => !CANVAS_FIELDS.includes(f) && f in (node.properties ?? {}),
+ );
delete node.additionalProperties;
return simplify(node, defs);
}
+function isJson(schema: Schema): boolean {
+ return (
+ (schema as { widget?: { formlyConfig?: { type?: string } } }).widget?.formlyConfig?.type ===
+ 'json'
+ );
+}
+
function simplify(schema: Schema, defs: Record): Schema {
if (schema.$ref) {
const { $ref, ...rest } = schema;
@@ -45,6 +64,34 @@ function simplify(schema: Schema, defs: Record): Schema {
return simplify({ ...kept[0], ...rest }, defs);
}
}
+ const values = schema.additionalProperties as Schema | boolean | undefined;
+ if (
+ schema.type === 'object' &&
+ !schema.properties &&
+ typeof values === 'object' &&
+ values.type === 'string'
+ ) {
+ const byField = (schema as { keys?: string }).keys === 'field';
+ return {
+ title: schema.title,
+ description: schema.description,
+ default: schema.default,
+ widget: { formlyConfig: { type: 'map', props: { fieldKeys: byField } } },
+ } as Schema;
+ }
+ const pair = schema.items as Schema | undefined;
+ if (
+ schema.type === 'array' &&
+ (pair?.prefixItems as Schema[] | undefined)?.length === 2 &&
+ (pair!.prefixItems as Schema[]).every((p) => p.type === 'string')
+ ) {
+ return {
+ title: schema.title,
+ description: schema.description,
+ default: schema.default,
+ widget: { formlyConfig: { type: 'pairs' } },
+ } as Schema;
+ }
const isMap = schema.type === 'object' && !schema.properties;
const isTuple =
schema.type === 'array' &&
@@ -117,7 +164,7 @@ export class ArrayType extends FieldArrayType {}
imports: [MatFormFieldModule, MatInputModule, ReactiveFormsModule],
template: `
- {{ props.label }} (JSON)
+ {{ props.label }}
}
+ @case ('columns') {
+
+ {{ f.label }}
+
+ @for (c of columnOptions(name); track c) {
+ {{ c }}
+ }
+
+ {{
+ columnOptions(name).length ? f.help : 'Pulse «Probar conexión» para ver las columnas.'
+ }}
+
+ }
@case ('folder') {
@@ -319,7 +338,7 @@
@if (t.detail) {
- Lo que respondió el sistema
+ Respuesta de la fuente
{{ t.detail }}
}
diff --git a/src/app/conectar/source-dialog.ts b/src/app/conectar/source-dialog.ts
index a7a7b7e..1483d95 100644
--- a/src/app/conectar/source-dialog.ts
+++ b/src/app/conectar/source-dialog.ts
@@ -204,6 +204,16 @@ export class SourceDialog {
}
/** The tables a database listed, for its table field. */
+ /** A list answer (the columns picked), as a list. */
+ protected listed(name: string): string[] {
+ const v = this.value(name);
+ return Array.isArray(v) ? (v as string[]) : [];
+ }
+ /** The columns to pick from: the first rows', and those already picked. */
+ protected columnOptions(name: string): string[] {
+ return [...new Set([...this.columns(), ...this.listed(name)])];
+ }
+
protected tables(): string[] {
return this.tableList();
}