From b22f16809db669e7fafbea841aa2403000ffef41 Mon Sep 17 00:00:00 2001 From: louis-19041904 Date: Fri, 17 Jul 2026 14:45:46 +0200 Subject: [PATCH] feat(jobs): add job deletion with confirmation --- .../src/app/modules/jobs/jobs.component.html | 21 +++++ .../src/app/modules/jobs/jobs.component.scss | 4 + webapp/src/app/modules/jobs/jobs.component.ts | 81 +++++++++++++++++-- .../confirmation-dialog.component.scss | 2 + 4 files changed, 100 insertions(+), 8 deletions(-) diff --git a/webapp/src/app/modules/jobs/jobs.component.html b/webapp/src/app/modules/jobs/jobs.component.html index 2ecae548..dd974e7b 100644 --- a/webapp/src/app/modules/jobs/jobs.component.html +++ b/webapp/src/app/modules/jobs/jobs.component.html @@ -154,5 +154,26 @@ (click)="openScheduleDialog(row)"> edit_calendar + diff --git a/webapp/src/app/modules/jobs/jobs.component.scss b/webapp/src/app/modules/jobs/jobs.component.scss index a7f3598b..ca8c94e5 100644 --- a/webapp/src/app/modules/jobs/jobs.component.scss +++ b/webapp/src/app/modules/jobs/jobs.component.scss @@ -200,6 +200,10 @@ mat-paginator { gap: 4px; } +.delete-action:not(:disabled) { + color: #b91c1c; +} + .actions-header { display: grid; grid-template-columns: 40px 1fr 40px; diff --git a/webapp/src/app/modules/jobs/jobs.component.ts b/webapp/src/app/modules/jobs/jobs.component.ts index ed047dd3..3c0058cf 100644 --- a/webapp/src/app/modules/jobs/jobs.component.ts +++ b/webapp/src/app/modules/jobs/jobs.component.ts @@ -71,6 +71,7 @@ export class JobsComponent implements OnInit { protected readonly tasks = signal([]); protected readonly dockerHealth = signal(null); protected readonly dockerHealthLoading = signal(false); + protected readonly deletingTaskIds = signal>(new Set()); protected readonly statusMeta = statusMeta; protected readonly formatScheduleCron = formatScheduleCron; @@ -182,8 +183,8 @@ export class JobsComponent implements OnInit { })); this.snackBar.open(`„${task.name}“ wurde gestartet.`, 'OK', { duration: 3000, - horizontalPosition: 'right', - verticalPosition: 'top', + horizontalPosition: 'center', + verticalPosition: 'bottom', }); this.refreshTasks(); }, @@ -220,8 +221,8 @@ export class JobsComponent implements OnInit { : `„${task.name}“ war bereits beendet.`; this.snackBar.open(message, 'OK', { duration: 3000, - horizontalPosition: 'right', - verticalPosition: 'top', + horizontalPosition: 'center', + verticalPosition: 'bottom', }); this.refreshTasks(); }, @@ -278,8 +279,8 @@ export class JobsComponent implements OnInit { this.updateTask(result.taskId, () => updatedTask); this.snackBar.open('Zeitplan wurde gespeichert.', 'OK', { duration: 3000, - horizontalPosition: 'right', - verticalPosition: 'top', + horizontalPosition: 'center', + verticalPosition: 'bottom', }); }, error: (error) => @@ -291,6 +292,34 @@ export class JobsComponent implements OnInit { }); } + protected confirmDeleteTask(task: BackgroundJobTask): void { + if ( + ['running', 'stopping'].includes(task.status) || + this.deletingTaskIds().has(task.id) + ) { + return; + } + + import('../../shared/ui/confirmation-dialog/confirmation-dialog.component').then( + ({ ConfirmationDialogComponent }) => { + const dialogRef = this.dialog.open(ConfirmationDialogComponent, { + width: '520px', + maxWidth: 'calc(100vw - 32px)', + data: { + title: 'Job löschen', + message: `Möchtest Du „${task.name}“ wirklich löschen? Alle Laufdaten und gespeicherten Logs werden dauerhaft gelöscht.`, + confirmText: 'Löschen', + cancelText: 'Abbrechen', + }, + }); + + dialogRef.afterClosed().subscribe((confirmed) => { + if (confirmed) this.deleteTask(task); + }); + }, + ); + } + private updateTask( id: number, updater: (task: BackgroundJobTask) => BackgroundJobTask, @@ -300,6 +329,42 @@ export class JobsComponent implements OnInit { ); } + private deleteTask(task: BackgroundJobTask): void { + this.deletingTaskIds.update((ids) => new Set(ids).add(task.id)); + + this.backgroundJobsService.deleteBackgroundJobTask(task.id).subscribe({ + next: () => { + this.finishDeletingTask(task.id); + this.tasks.update((tasks) => + tasks.filter((current) => current.id !== task.id), + ); + this.snackBar.open(`„${task.name}“ wurde gelöscht.`, 'OK', { + duration: 3000, + horizontalPosition: 'center', + verticalPosition: 'bottom', + }); + this.refreshTasks(); + }, + error: (error) => { + this.finishDeletingTask(task.id); + this.showError( + error.status === 409 + ? `„${task.name}“ läuft noch und kann nicht gelöscht werden.` + : `„${task.name}“ konnte nicht gelöscht werden.`, + ); + this.refreshTasks(); + }, + }); + } + + private finishDeletingTask(taskId: number): void { + this.deletingTaskIds.update((ids) => { + const updated = new Set(ids); + updated.delete(taskId); + return updated; + }); + } + private setTasksPreservingPendingStops(tasks: BackgroundJobTask[]): void { this.tasks.set( tasks.map((task) => @@ -313,8 +378,8 @@ export class JobsComponent implements OnInit { private showError(message: string): void { this.snackBar.open(message, 'OK', { duration: 5000, - horizontalPosition: 'right', - verticalPosition: 'top', + horizontalPosition: 'center', + verticalPosition: 'bottom', }); } } diff --git a/webapp/src/app/shared/ui/confirmation-dialog/confirmation-dialog.component.scss b/webapp/src/app/shared/ui/confirmation-dialog/confirmation-dialog.component.scss index 1dd84db8..a459ffda 100644 --- a/webapp/src/app/shared/ui/confirmation-dialog/confirmation-dialog.component.scss +++ b/webapp/src/app/shared/ui/confirmation-dialog/confirmation-dialog.component.scss @@ -1,4 +1,6 @@ .action { + justify-content: center; + button { min-width: 150px; }