feat(logs): add run dropdown, visible scrollbar and download button
This commit is contained in:
@@ -1,12 +1,29 @@
|
||||
<h2 mat-dialog-title>Logs · {{ data.task.name }}</h2>
|
||||
|
||||
<mat-dialog-content>
|
||||
@if (runId == null) {
|
||||
@if (runs().length === 0 && !runsLoading()) {
|
||||
<p class="no-logs">Für diesen Job liegt noch kein Lauf vor.</p>
|
||||
} @else {
|
||||
<mat-form-field appearance="outline" class="run-select">
|
||||
<mat-label>Lauf auswählen</mat-label>
|
||||
<mat-select
|
||||
[value]="selectedRunId()"
|
||||
(selectionChange)="onRunSelected($event.value)">
|
||||
@for (run of runs(); track run.id) {
|
||||
<mat-option [value]="run.id">
|
||||
#{{ run.id }} · {{ statusMeta(run.status!).label }} ·
|
||||
{{ run.started_at | date: 'dd.MM.yyyy HH:mm' }}
|
||||
@if (run.exit_code != null) {
|
||||
· Exit {{ run.exit_code }}
|
||||
}
|
||||
</mat-option>
|
||||
}
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
|
||||
<div class="logs-header">
|
||||
<div class="run-meta">
|
||||
<span>Letzter Lauf #{{ runId }}</span>
|
||||
<span>Lauf #{{ selectedRunId() }}</span>
|
||||
@if (runStatus()) {
|
||||
<span
|
||||
class="task-status"
|
||||
@@ -15,15 +32,26 @@
|
||||
{{ statusMeta(runStatus()!).label }}
|
||||
</span>
|
||||
}
|
||||
<span class="logs-hint">zeigt letzte 200 Zeilen</span>
|
||||
</div>
|
||||
<div class="logs-actions">
|
||||
<button
|
||||
mat-stroked-button
|
||||
type="button"
|
||||
[disabled]="selectedRunId() == null"
|
||||
(click)="downloadLogs()">
|
||||
<mat-icon>download</mat-icon>
|
||||
Herunterladen
|
||||
</button>
|
||||
<button
|
||||
mat-stroked-button
|
||||
type="button"
|
||||
[disabled]="loading()"
|
||||
(click)="loadLogs()">
|
||||
<mat-icon>refresh</mat-icon>
|
||||
Aktualisieren
|
||||
</button>
|
||||
</div>
|
||||
<button
|
||||
mat-stroked-button
|
||||
type="button"
|
||||
[disabled]="loading()"
|
||||
(click)="loadLogs()">
|
||||
<mat-icon>refresh</mat-icon>
|
||||
Aktualisieren
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="logs-panel">
|
||||
|
||||
@@ -19,6 +19,12 @@
|
||||
color: #64748b;
|
||||
}
|
||||
|
||||
.logs-actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.task-status {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
@@ -61,6 +67,28 @@
|
||||
min-height: 120px;
|
||||
max-height: 55vh;
|
||||
overflow: auto;
|
||||
scrollbar-width: thin;
|
||||
scrollbar-color: #64748b #1e293b;
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-track {
|
||||
background: #1e293b;
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-thumb {
|
||||
background: #64748b;
|
||||
border-radius: 6px;
|
||||
border: 3px solid #0f172a;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-thumb:hover {
|
||||
background: #94a3b8;
|
||||
}
|
||||
|
||||
pre {
|
||||
margin: 0;
|
||||
@@ -84,6 +112,16 @@
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.run-select {
|
||||
width: 100%;
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.logs-hint {
|
||||
color: #94a3b8;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.logs-header {
|
||||
flex-direction: column;
|
||||
|
||||
@@ -6,9 +6,11 @@ import {
|
||||
MatDialogModule,
|
||||
MatDialogRef,
|
||||
} from '@angular/material/dialog';
|
||||
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
|
||||
import { BackgroundJobsService, BackgroundJobTask } from '../../../api';
|
||||
import { MatSelectModule } from '@angular/material/select';
|
||||
import { BackgroundJobsService, BackgroundJobTask, JobRun } from '../../../api';
|
||||
import { statusMeta } from '../jobs.utils';
|
||||
|
||||
export interface JobLogsDialogData {
|
||||
@@ -21,8 +23,10 @@ export interface JobLogsDialogData {
|
||||
CommonModule,
|
||||
MatButtonModule,
|
||||
MatDialogModule,
|
||||
MatFormFieldModule,
|
||||
MatIconModule,
|
||||
MatProgressSpinnerModule,
|
||||
MatSelectModule,
|
||||
],
|
||||
templateUrl: './job-logs-dialog.component.html',
|
||||
styleUrl: './job-logs-dialog.component.scss',
|
||||
@@ -34,8 +38,12 @@ export class JobLogsDialogComponent implements OnInit {
|
||||
protected readonly data = inject<JobLogsDialogData>(MAT_DIALOG_DATA);
|
||||
|
||||
protected readonly statusMeta = statusMeta;
|
||||
protected readonly runId = this.data.task.last_run?.id ?? null;
|
||||
|
||||
protected readonly runs = signal<JobRun[]>([]);
|
||||
protected readonly runsLoading = signal(false);
|
||||
protected readonly selectedRunId = signal<number | null>(
|
||||
this.data.task.last_run?.id ?? null,
|
||||
);
|
||||
protected readonly loading = signal(false);
|
||||
protected readonly logs = signal<string>('');
|
||||
protected readonly runStatus = signal<string | null>(
|
||||
@@ -43,14 +51,46 @@ export class JobLogsDialogComponent implements OnInit {
|
||||
);
|
||||
|
||||
ngOnInit(): void {
|
||||
this.loadRuns();
|
||||
if (this.selectedRunId() != null) {
|
||||
this.loadLogs();
|
||||
}
|
||||
}
|
||||
|
||||
protected loadRuns(): void {
|
||||
this.runsLoading.set(true);
|
||||
this.backgroundJobsService
|
||||
.getBackgroundJobTaskRuns(this.data.task.id, 50)
|
||||
.subscribe({
|
||||
next: (runs) => {
|
||||
this.runs.set(runs);
|
||||
this.runsLoading.set(false);
|
||||
if (this.selectedRunId() == null && runs.length > 0) {
|
||||
this.selectRun(runs[0]);
|
||||
}
|
||||
},
|
||||
error: () => this.runsLoading.set(false),
|
||||
});
|
||||
}
|
||||
|
||||
protected selectRun(run: JobRun): void {
|
||||
if (run.id == null) return;
|
||||
this.selectedRunId.set(run.id);
|
||||
this.runStatus.set(run.status ?? null);
|
||||
this.loadLogs();
|
||||
}
|
||||
|
||||
protected onRunSelected(runId: number): void {
|
||||
const run = this.runs().find((item) => item.id === runId);
|
||||
if (run) this.selectRun(run);
|
||||
}
|
||||
|
||||
protected loadLogs(): void {
|
||||
if (this.runId == null) return;
|
||||
const runId = this.selectedRunId();
|
||||
if (runId == null) return;
|
||||
|
||||
this.loading.set(true);
|
||||
this.backgroundJobsService.getBackgroundJobRunLogs(this.runId).subscribe({
|
||||
this.backgroundJobsService.getBackgroundJobRunLogs(runId).subscribe({
|
||||
next: (result) => {
|
||||
this.logs.set(result.logs || 'Keine Logs vorhanden.');
|
||||
this.runStatus.set(result.status);
|
||||
@@ -63,6 +103,21 @@ export class JobLogsDialogComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
protected downloadLogs(): void {
|
||||
const runId = this.selectedRunId();
|
||||
if (runId == null) return;
|
||||
|
||||
const run = this.runs().find((item) => item.id === runId);
|
||||
const text = run?.logs ?? this.logs();
|
||||
const blob = new Blob([text], { type: 'text/plain;charset=utf-8' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const anchor = document.createElement('a');
|
||||
anchor.href = url;
|
||||
anchor.download = `${this.data.task.command ?? 'job'}-run-${runId}.log`;
|
||||
anchor.click();
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
protected close(): void {
|
||||
this.dialogRef.close();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user