From c311298811517341329a3736c13994542768eb65 Mon Sep 17 00:00:00 2001 From: Joel Wetzell Date: Sun, 17 May 2026 16:35:41 -0500 Subject: [PATCH] make processors drag and droppable within their own route --- src/app/components/processor/processor.html | 44 +++++++++++++++++++++ src/app/components/processor/processor.ts | 12 +++++- src/app/components/route/route.html | 7 +++- src/app/components/route/route.ts | 39 +++++++++++++++--- 4 files changed, 95 insertions(+), 7 deletions(-) diff --git a/src/app/components/processor/processor.html b/src/app/components/processor/processor.html index 42f9c85..a76c390 100644 --- a/src/app/components/processor/processor.html +++ b/src/app/components/processor/processor.html @@ -6,6 +6,14 @@ }} border-solid w-fit h-full" >
+ @if (inDragList()) { +
+ drag_indicator +
+ }
{{ schema()?.title || processor()?.type }}
@@ -28,4 +36,40 @@ }
+ +
+
+
+ @if (inDragList()) { +
+ drag_indicator +
+ } +
+ {{ schema()?.title || processor()?.type }} +
+
+
+
+ +
+
+
+
+ {{ schema()?.title || processor()?.type }} +
+
+
+
} diff --git a/src/app/components/processor/processor.ts b/src/app/components/processor/processor.ts index 2d4accd..574840d 100644 --- a/src/app/components/processor/processor.ts +++ b/src/app/components/processor/processor.ts @@ -4,10 +4,18 @@ import { SchemaService } from '../../services/schema'; import { MatIconModule } from '@angular/material/icon'; import { ParamsFormComponent } from '../params-form/params-form'; import { ReactiveFormsModule } from '@angular/forms'; +import { CdkDragHandle, CdkDragPlaceholder, CdkDragPreview } from '@angular/cdk/drag-drop'; @Component({ selector: 'app-processor', - imports: [MatIconModule, ParamsFormComponent, ReactiveFormsModule], + imports: [ + MatIconModule, + ParamsFormComponent, + ReactiveFormsModule, + CdkDragHandle, + CdkDragPreview, + CdkDragPlaceholder, + ], templateUrl: './processor.html', styleUrl: './processor.css', }) @@ -16,6 +24,8 @@ export class ProcessorComponent { processor = model(); delete = output(); + inDragList = input(false); + params = computed(() => this.processor()!.params); schema = computed(() => { diff --git a/src/app/components/route/route.html b/src/app/components/route/route.html index 7143102..e17d46f 100644 --- a/src/app/components/route/route.html +++ b/src/app/components/route/route.html @@ -63,7 +63,11 @@
Processors
@if (processors() !== undefined && processors()!.length > 0) { -
+
@for (processor of processors(); track $index; let i = $index) {
} diff --git a/src/app/components/route/route.ts b/src/app/components/route/route.ts index 1a438a4..70db1c8 100644 --- a/src/app/components/route/route.ts +++ b/src/app/components/route/route.ts @@ -1,17 +1,24 @@ +import { + CdkDrag, + CdkDragDrop, + CdkDropList, + moveItemInArray +} from '@angular/cdk/drag-drop'; +import { JsonPipe } from '@angular/common'; import { Component, computed, inject, input, model, output, signal } from '@angular/core'; import { FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms'; import { MatFormFieldModule } from '@angular/material/form-field'; import { MatIconModule } from '@angular/material/icon'; import { MatMenuModule } from '@angular/material/menu'; -import { ProcessorConfig, RouteConfig } from '../../models/config'; -import { SchemaService } from '../../services/schema'; -import { JsonPipe } from '@angular/common'; -import { ProcessorComponent } from '../processor/processor'; import { MatSnackBar } from '@angular/material/snack-bar'; import { MatTooltipModule } from '@angular/material/tooltip'; -import { EventsService } from '../../services/events'; import { debounceTime, tap } from 'rxjs'; +import { ProcessorConfig, RouteConfig } from '../../models/config'; import { ConfigService } from '../../services/config'; +import { EventsService } from '../../services/events'; +import { ListsService } from '../../services/lists'; +import { SchemaService } from '../../services/schema'; +import { ProcessorComponent } from '../processor/processor'; @Component({ selector: 'app-route', @@ -23,6 +30,8 @@ import { ConfigService } from '../../services/config'; JsonPipe, ProcessorComponent, MatTooltipModule, + CdkDrag, + CdkDropList, ], templateUrl: './route.html', styleUrl: './route.css', @@ -69,6 +78,7 @@ export class RouteComponent { private snackBar = inject(MatSnackBar); private eventsService = inject(EventsService); private configService = inject(ConfigService); + public listsService = inject(ListsService); indicatorColor = signal('gray'); @@ -167,4 +177,23 @@ export class RouteComponent { duration: 3000, }); } + + drop(event: CdkDragDrop) { + // TODO(jwetzell): support moving between routes + if (event.previousContainer === event.container) { + const processors = this.route()?.processors; + if (processors !== undefined) { + moveItemInArray(processors, event.previousIndex, event.currentIndex); + this.route.update((route) => { + if (route) { + return { + ...route, + processors: [...processors], + }; + } + return route; + }); + } + } + } }