feat(jobs): add job deletion with confirmation
LocationBasedServices/smartguide/pipeline/head This commit looks good
LocationBasedServices/smartguide/pipeline/head This commit looks good
This commit is contained in:
@@ -154,5 +154,26 @@
|
||||
(click)="openScheduleDialog(row)">
|
||||
<mat-icon>edit_calendar</mat-icon>
|
||||
</button>
|
||||
<button
|
||||
mat-icon-button
|
||||
type="button"
|
||||
class="delete-action"
|
||||
aria-label="Job löschen"
|
||||
matTooltip="Job löschen"
|
||||
matTooltipPosition="above"
|
||||
[disabled]="
|
||||
row.status === 'running' ||
|
||||
row.status === 'stopping' ||
|
||||
deletingTaskIds().has(row.id)
|
||||
"
|
||||
(click)="confirmDeleteTask(row)">
|
||||
@if (deletingTaskIds().has(row.id)) {
|
||||
<mat-progress-spinner
|
||||
diameter="18"
|
||||
mode="indeterminate"></mat-progress-spinner>
|
||||
} @else {
|
||||
<mat-icon>delete</mat-icon>
|
||||
}
|
||||
</button>
|
||||
</div>
|
||||
</ng-template>
|
||||
|
||||
@@ -200,6 +200,10 @@ mat-paginator {
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.delete-action:not(:disabled) {
|
||||
color: #b91c1c;
|
||||
}
|
||||
|
||||
.actions-header {
|
||||
display: grid;
|
||||
grid-template-columns: 40px 1fr 40px;
|
||||
|
||||
@@ -71,6 +71,7 @@ export class JobsComponent implements OnInit {
|
||||
protected readonly tasks = signal<BackgroundJobTask[]>([]);
|
||||
protected readonly dockerHealth = signal<DockerHealth | null>(null);
|
||||
protected readonly dockerHealthLoading = signal(false);
|
||||
protected readonly deletingTaskIds = signal<ReadonlySet<number>>(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',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
.action {
|
||||
justify-content: center;
|
||||
|
||||
button {
|
||||
min-width: 150px;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user