feat(jobs): add edit dialog with hover pencil in the name column
This commit is contained in:
@@ -58,9 +58,21 @@
|
||||
|
||||
<ng-template #taskNameTmp let-row>
|
||||
<div class="task-name-cell">
|
||||
<strong>{{ row.name }}</strong>
|
||||
<span class="task-description">{{ row.description }}</span>
|
||||
<code class="task-index">{{ row.target_index }}</code>
|
||||
<button
|
||||
type="button"
|
||||
class="edit-name-action"
|
||||
aria-label="Job bearbeiten"
|
||||
matTooltip="Job bearbeiten"
|
||||
matTooltipPosition="above"
|
||||
[disabled]="row.status === 'running' || row.status === 'stopping'"
|
||||
(click)="openEditDialog(row)">
|
||||
<mat-icon>edit</mat-icon>
|
||||
</button>
|
||||
<div class="task-name-text">
|
||||
<strong>{{ row.name }}</strong>
|
||||
<span class="task-description">{{ row.description }}</span>
|
||||
<code class="task-index">{{ row.target_index }}</code>
|
||||
</div>
|
||||
</div>
|
||||
</ng-template>
|
||||
|
||||
|
||||
@@ -95,10 +95,50 @@ mat-paginator {
|
||||
}
|
||||
|
||||
.task-name-cell {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
min-width: 220px;
|
||||
}
|
||||
|
||||
.task-name-text {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
min-width: 220px;
|
||||
}
|
||||
|
||||
.edit-name-action {
|
||||
flex: 0 0 auto;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
padding: 0;
|
||||
border: none;
|
||||
background: none;
|
||||
cursor: pointer;
|
||||
color: #64748b;
|
||||
opacity: 0;
|
||||
transition: opacity 0.15s ease;
|
||||
|
||||
.mat-icon {
|
||||
font-size: 18px;
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
line-height: 18px;
|
||||
}
|
||||
}
|
||||
|
||||
.task-name-cell:hover .edit-name-action,
|
||||
.edit-name-action:focus-visible {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.edit-name-action[disabled] {
|
||||
cursor: not-allowed;
|
||||
color: #cbd5e1;
|
||||
}
|
||||
|
||||
.task-description {
|
||||
|
||||
@@ -42,6 +42,10 @@ import {
|
||||
JobLogsDialogData,
|
||||
} from './job-logs-dialog/job-logs-dialog.component';
|
||||
import { TaskCreateDialogComponent } from './task-create-dialog/task-create-dialog.component';
|
||||
import {
|
||||
TaskEditDialogComponent,
|
||||
TaskEditDialogData,
|
||||
} from './task-edit-dialog/task-edit-dialog.component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-jobs',
|
||||
@@ -279,6 +283,31 @@ export class JobsComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
protected openEditDialog(task: BackgroundJobTask): void {
|
||||
if (['running', 'stopping'].includes(task.status)) return;
|
||||
|
||||
const dialogRef = this.dialog.open<
|
||||
TaskEditDialogComponent,
|
||||
TaskEditDialogData,
|
||||
BackgroundJobTask | undefined
|
||||
>(TaskEditDialogComponent, {
|
||||
width: '560px',
|
||||
maxWidth: 'calc(100vw - 32px)',
|
||||
data: { task },
|
||||
});
|
||||
|
||||
dialogRef.afterClosed().subscribe((updatedTask) => {
|
||||
if (!updatedTask) return;
|
||||
|
||||
this.updateTask(updatedTask.id, () => updatedTask);
|
||||
this.snackBar.open(`„${updatedTask.name}“ wurde gespeichert.`, 'OK', {
|
||||
duration: 3000,
|
||||
horizontalPosition: 'center',
|
||||
verticalPosition: 'bottom',
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
protected openScheduleDialog(task: BackgroundJobTask): void {
|
||||
const dialogRef = this.dialog.open<
|
||||
TaskScheduleDialogComponent,
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
<h2 mat-dialog-title>Job bearbeiten</h2>
|
||||
|
||||
<mat-dialog-content>
|
||||
<p class="edit-name">{{ data.task.name }}</p>
|
||||
|
||||
<form class="edit-form" [formGroup]="form">
|
||||
<mat-form-field appearance="outline">
|
||||
<mat-label>Befehl</mat-label>
|
||||
<input
|
||||
matInput
|
||||
formControlName="command"
|
||||
placeholder="python sync.py --stats" />
|
||||
<mat-icon
|
||||
matSuffix
|
||||
class="field-info"
|
||||
matTooltip="Wird beim Start direkt im Container ausgeführt — wie in einem Terminal, z.B. „python sync.py --update-keywords --target-index docker-job_test“. Leer = Standard-Befehl des Images."
|
||||
>info_outline</mat-icon
|
||||
>
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field appearance="outline">
|
||||
<mat-label>Image</mat-label>
|
||||
<input matInput formControlName="image" />
|
||||
<mat-icon
|
||||
matSuffix
|
||||
class="field-info"
|
||||
matTooltip="Vorausgefüllt ist das Standard-Image mit allen Background-Job-Skripten — im Normalfall einfach so lassen. Nur ändern, wenn der Job ein eigenes Docker-Image nutzen soll; eigene Images erhalten die INSE-Zugangsdaten (Elasticsearch/LLM) nicht automatisch."
|
||||
>info_outline</mat-icon
|
||||
>
|
||||
<mat-hint>Im Normalfall unverändert lassen.</mat-hint>
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field appearance="outline">
|
||||
<mat-label>Beschreibung (optional)</mat-label>
|
||||
<textarea matInput rows="2" formControlName="description"></textarea>
|
||||
<mat-icon
|
||||
matSuffix
|
||||
class="field-info"
|
||||
matTooltip="Freitext für die Job-Tabelle: Was macht der Job, was sollte man vor dem Start wissen?"
|
||||
>info_outline</mat-icon
|
||||
>
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field appearance="outline">
|
||||
<mat-label>Ziel-Index (optional)</mat-label>
|
||||
<input matInput formControlName="targetIndex" />
|
||||
<mat-icon
|
||||
matSuffix
|
||||
class="field-info"
|
||||
matTooltip="Reine Anzeige-Info in der Tabelle. In welchen Index der Job wirklich schreibt, bestimmt allein der Befehl (z.B. --target-index / --output-index)."
|
||||
>info_outline</mat-icon
|
||||
>
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field appearance="outline">
|
||||
<mat-label>Umgebungsvariablen (optional)</mat-label>
|
||||
<textarea
|
||||
matInput
|
||||
rows="3"
|
||||
formControlName="env"
|
||||
placeholder="KEY=value"></textarea>
|
||||
<mat-icon
|
||||
matSuffix
|
||||
class="field-info"
|
||||
matTooltip="Zusätzliche Umgebungsvariablen für den Container, eine pro Zeile im Format KEY=value. Das Standard-Image bekommt die INSE-Zugangsdaten (Elasticsearch/LLM) automatisch — hier ist nur Spezielles nötig."
|
||||
>info_outline</mat-icon
|
||||
>
|
||||
<mat-hint>Eine Variable pro Zeile im Format KEY=value.</mat-hint>
|
||||
@if (form.controls.env.hasError('invalidEnv')) {
|
||||
<mat-error>Ungültige Zeile — Format: KEY=value.</mat-error>
|
||||
}
|
||||
</mat-form-field>
|
||||
</form>
|
||||
|
||||
@if (serverError()) {
|
||||
<p class="server-error">{{ serverError() }}</p>
|
||||
}
|
||||
</mat-dialog-content>
|
||||
|
||||
<mat-dialog-actions align="end">
|
||||
<button mat-button type="button" (click)="close()">Abbrechen</button>
|
||||
<button
|
||||
mat-flat-button
|
||||
color="primary"
|
||||
type="button"
|
||||
[disabled]="saving()"
|
||||
(click)="submit()">
|
||||
<mat-icon>save</mat-icon>
|
||||
Speichern
|
||||
</button>
|
||||
</mat-dialog-actions>
|
||||
@@ -0,0 +1,29 @@
|
||||
.edit-name {
|
||||
margin: 0 0 16px;
|
||||
font-weight: 600;
|
||||
color: var(--sg-text, #101a3d);
|
||||
}
|
||||
|
||||
.edit-form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
min-width: 400px;
|
||||
}
|
||||
|
||||
.field-info {
|
||||
color: #94a3b8;
|
||||
cursor: help;
|
||||
}
|
||||
|
||||
.server-error {
|
||||
margin: 8px 0 0;
|
||||
color: #b3261e;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.edit-form {
|
||||
min-width: 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { Component, inject, signal } from '@angular/core';
|
||||
import { FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import {
|
||||
MAT_DIALOG_DATA,
|
||||
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 { MatTooltipModule } from '@angular/material/tooltip';
|
||||
import { BackgroundJobTask, BackgroundJobsService } from '../../../api';
|
||||
|
||||
const ENV_LINE_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*=.*$/;
|
||||
|
||||
const DEFAULT_JOB_IMAGE = 'docker.nes.uni-due.de/inse/background-jobs:latest';
|
||||
|
||||
export interface TaskEditDialogData {
|
||||
task: BackgroundJobTask;
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-task-edit-dialog',
|
||||
imports: [
|
||||
CommonModule,
|
||||
ReactiveFormsModule,
|
||||
MatButtonModule,
|
||||
MatDialogModule,
|
||||
MatFormFieldModule,
|
||||
MatIconModule,
|
||||
MatInputModule,
|
||||
MatTooltipModule,
|
||||
],
|
||||
templateUrl: './task-edit-dialog.component.html',
|
||||
styleUrl: './task-edit-dialog.component.scss',
|
||||
standalone: true,
|
||||
})
|
||||
export class TaskEditDialogComponent {
|
||||
private readonly dialogRef =
|
||||
inject<
|
||||
MatDialogRef<TaskEditDialogComponent, BackgroundJobTask | undefined>
|
||||
>(MatDialogRef);
|
||||
private readonly backgroundJobsService = inject(BackgroundJobsService);
|
||||
protected readonly data = inject<TaskEditDialogData>(MAT_DIALOG_DATA);
|
||||
|
||||
protected readonly saving = signal(false);
|
||||
protected readonly serverError = signal('');
|
||||
|
||||
protected readonly form = new FormGroup({
|
||||
description: new FormControl(this.data.task.description, {
|
||||
nonNullable: true,
|
||||
}),
|
||||
targetIndex: new FormControl(this.data.task.target_index, {
|
||||
nonNullable: true,
|
||||
}),
|
||||
command: new FormControl(this.data.task.command ?? '', {
|
||||
nonNullable: true,
|
||||
}),
|
||||
image: new FormControl(this.data.task.image, { nonNullable: true }),
|
||||
env: new FormControl(this.envToText(this.data.task.env), {
|
||||
nonNullable: true,
|
||||
}),
|
||||
});
|
||||
|
||||
protected submit(): void {
|
||||
this.serverError.set('');
|
||||
const value = this.form.getRawValue();
|
||||
|
||||
const env = this.parseEnv(value.env);
|
||||
if (env === undefined) return;
|
||||
|
||||
// The default image is stored as null so the job keeps following the
|
||||
// backend-configured image if it ever changes.
|
||||
const image = value.image.trim();
|
||||
|
||||
this.saving.set(true);
|
||||
this.backgroundJobsService
|
||||
.updateBackgroundJobTask(this.data.task.id, {
|
||||
description: value.description.trim(),
|
||||
target_index: value.targetIndex.trim(),
|
||||
image: !image || image === DEFAULT_JOB_IMAGE ? null : image,
|
||||
command: value.command.trim() || null,
|
||||
env,
|
||||
})
|
||||
.subscribe({
|
||||
next: (task) => this.dialogRef.close(task),
|
||||
error: (error) => {
|
||||
this.saving.set(false);
|
||||
const detail = error?.error?.detail;
|
||||
this.serverError.set(
|
||||
typeof detail === 'string'
|
||||
? detail
|
||||
: 'Der Job konnte nicht gespeichert werden.',
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
protected close(): void {
|
||||
this.dialogRef.close();
|
||||
}
|
||||
|
||||
private envToText(env: { [key: string]: string }): string {
|
||||
return Object.entries(env)
|
||||
.map(([key, value]) => `${key}=${value}`)
|
||||
.join('\n');
|
||||
}
|
||||
|
||||
private parseEnv(text: string): { [key: string]: string } | undefined {
|
||||
const env: { [key: string]: string } = {};
|
||||
for (const line of text.split('\n')) {
|
||||
const trimmed = line.trim();
|
||||
if (!trimmed) continue;
|
||||
if (!ENV_LINE_PATTERN.test(trimmed)) {
|
||||
this.form.controls.env.setErrors({ invalidEnv: true });
|
||||
this.form.controls.env.markAsTouched();
|
||||
return undefined;
|
||||
}
|
||||
const separatorIndex = trimmed.indexOf('=');
|
||||
env[trimmed.slice(0, separatorIndex)] = trimmed.slice(separatorIndex + 1);
|
||||
}
|
||||
return env;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user