feat(jobs): allow renaming a job in the edit dialog
This commit is contained in:
@@ -99,6 +99,7 @@ class JobDefinitionCreateRequest(BaseModel):
|
||||
|
||||
|
||||
class JobDefinitionUpdateRequest(BaseModel):
|
||||
name: Optional[str] = None
|
||||
image: Optional[str] = None
|
||||
command: Optional[str] = None
|
||||
env: Optional[dict[str, str]] = None
|
||||
|
||||
@@ -183,6 +183,26 @@ def update_task(
|
||||
detail=f"Invalid cron expression: '{changes['schedule']}'.",
|
||||
)
|
||||
|
||||
if "name" in changes:
|
||||
name = (changes["name"] or "").strip()
|
||||
if not name:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
||||
detail="Task name must not be empty.",
|
||||
)
|
||||
duplicate = session.exec(
|
||||
select(JobDefinition).where(
|
||||
JobDefinition.name == name,
|
||||
JobDefinition.id != definition_id,
|
||||
)
|
||||
).first()
|
||||
if duplicate:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_409_CONFLICT,
|
||||
detail=f"A task named '{name}' already exists.",
|
||||
)
|
||||
changes["name"] = name
|
||||
|
||||
definition = _get_definition(session, definition_id)
|
||||
for key, value in changes.items():
|
||||
setattr(definition, key, value)
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
export interface JobDefinitionUpdateRequest {
|
||||
name?: string | null;
|
||||
image?: string | null;
|
||||
command?: string | null;
|
||||
env?: { [key: string]: string } | null;
|
||||
|
||||
@@ -1,9 +1,21 @@
|
||||
<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>Name</mat-label>
|
||||
<input matInput formControlName="name" />
|
||||
<mat-icon
|
||||
matSuffix
|
||||
class="field-info"
|
||||
matTooltip="Eindeutiger Anzeigename des Jobs, z.B. „News-Themen-Mapping (Testlauf)“."
|
||||
>info_outline</mat-icon
|
||||
>
|
||||
@if (form.controls.name.invalid) {
|
||||
<mat-error>Bitte einen Namen eingeben.</mat-error>
|
||||
}
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field appearance="outline">
|
||||
<mat-label>Befehl</mat-label>
|
||||
<textarea
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
.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;
|
||||
|
||||
// Give the first field's floating label room so it is not clipped by the
|
||||
// dialog title above it.
|
||||
padding-top: 6px;
|
||||
}
|
||||
|
||||
// Long commands / image names should wrap and stay fully readable, and the
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { Component, inject, signal } from '@angular/core';
|
||||
import { FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms';
|
||||
import {
|
||||
FormControl,
|
||||
FormGroup,
|
||||
ReactiveFormsModule,
|
||||
Validators,
|
||||
} from '@angular/forms';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import {
|
||||
MAT_DIALOG_DATA,
|
||||
@@ -49,6 +54,10 @@ export class TaskEditDialogComponent {
|
||||
protected readonly serverError = signal('');
|
||||
|
||||
protected readonly form = new FormGroup({
|
||||
name: new FormControl(this.data.task.name, {
|
||||
nonNullable: true,
|
||||
validators: [Validators.required],
|
||||
}),
|
||||
description: new FormControl(this.data.task.description, {
|
||||
nonNullable: true,
|
||||
}),
|
||||
@@ -68,6 +77,12 @@ export class TaskEditDialogComponent {
|
||||
this.serverError.set('');
|
||||
const value = this.form.getRawValue();
|
||||
|
||||
const name = value.name.trim();
|
||||
if (!name) {
|
||||
this.form.controls.name.markAsTouched();
|
||||
return;
|
||||
}
|
||||
|
||||
const env = this.parseEnv(value.env);
|
||||
if (env === undefined) return;
|
||||
|
||||
@@ -78,6 +93,7 @@ export class TaskEditDialogComponent {
|
||||
this.saving.set(true);
|
||||
this.backgroundJobsService
|
||||
.updateBackgroundJobTask(this.data.task.id, {
|
||||
name,
|
||||
description: value.description.trim(),
|
||||
target_index: value.targetIndex.trim(),
|
||||
image: !image || image === DEFAULT_JOB_IMAGE ? null : image,
|
||||
|
||||
Reference in New Issue
Block a user