Implement live progress tracking for bulk metadata refresh (remaining books, status, cancel support)

This commit is contained in:
aditya.chandel
2025-08-10 00:28:20 -06:00
committed by Aditya Chandel
parent 2c078716bf
commit b1508493cf
23 changed files with 586 additions and 112 deletions
@@ -1,4 +1,4 @@
<div class="flex flex-col px-4 py-6 live-border">
<p class="text-sm text-gray-400">{{ latestNotification.timestamp }}</p>
<p>{{ latestNotification.message }}</p>
<div class="flex flex-col p-4 space-y-2 live-border">
<p class="text-xs text-zinc-400">{{ latestNotification.timestamp }}</p>
<p class="font-normal text-zinc-200">{{ latestNotification.message }}</p>
</div>
@@ -1,6 +1,6 @@
import {Component, inject} from '@angular/core';
import {LogNotification} from '../../../shared/websocket/model/log-notification.model';
import {NotificationEventService} from '../../../shared/websocket/notification-event.service';
import {LogNotification} from '../../../shared/websocket/model/log-notification.model';
@Component({
selector: 'app-live-notification-box',
@@ -0,0 +1,43 @@
<div class="flex flex-col p-4 live-border">
@if (tasks$ | async; as tasks) {
@if (tasks.length === 0) {
<div class="text-center text-zinc-400">
<p class="text-sm">No active tasks</p>
</div>
} @else {
@for (task of tasks; track task.taskId; let i = $index) {
@if (i > 0) {
<div class="border-t border-zinc-700 my-4"></div>
}
<div class="flex flex-col space-y-1.5">
<p class="text-xs text-zinc-400">{{ task.timestamp }}</p>
<div class="flex flex-col space-y-0.5">
<div class="flex justify-between items-center">
<div class="flex items-center space-x-1.5">
<span class="px-1.5 py-0.5 text-xs rounded-xl font-bold" [class]="getStatusClasses(task.status)">
{{ getStatusText(task.status) }}
</span>
@if (task.title) {
<h4 class="font-bold text-zinc-200">Task: {{ task.title }}</h4>
}
</div>
<div class="flex items-center space-x-1">
@if (task.status === TaskStatus.IN_PROGRESS && task.cancellable) {
<p-button
(onClick)="cancelTask(task.taskId)" icon="pi pi-ban" severity="danger" size="small" rounded text>
</p-button>
}
<p-button
(onClick)="removeTask(task.taskId)" icon="pi pi-times" severity="secondary" size="small" rounded text>
</p-button>
</div>
</div>
<p class="font-normal text-zinc-300">{{ task.message }}</p>
</div>
</div>
}
}
}
</div>
@@ -0,0 +1,6 @@
.live-border {
background: var(--card-background);
border: 1px solid var(--primary-color);
border-radius: 0.5rem;
}
@@ -0,0 +1,84 @@
import {Component, inject} from '@angular/core';
import {CommonModule} from '@angular/common';
import {TaskMessage, TaskStatus} from '../../../shared/websocket/model/log-notification.model';
import {TaskEventService} from '../../../shared/websocket/task-event.service';
import {TaskService} from '../../../shared/services/task.service';
import {Observable, take} from 'rxjs';
import {Button} from 'primeng/button';
import {MessageService} from 'primeng/api';
@Component({
selector: 'app-live-task-event-box',
standalone: true,
imports: [CommonModule, Button],
templateUrl: './live-task-event-box.component.html',
styleUrls: ['./live-task-event-box.component.scss'],
host: {
class: 'config-panel'
}
})
export class LiveTaskEventBoxComponent {
tasks$: Observable<TaskMessage[]>;
TaskStatus = TaskStatus;
private taskEventService = inject(TaskEventService);
private taskService = inject(TaskService);
private messageService = inject(MessageService);
constructor() {
this.tasks$ = this.taskEventService.tasks$;
}
cancelTask(taskId: string): void {
this.taskService.cancelTask(taskId).pipe(take(1)).subscribe({
next: (response) => {
this.messageService.add({
severity: 'success',
summary: 'Success',
detail: `Task cancellation scheduled`
});
},
error: (error) => {
this.messageService.add({
severity: 'error',
summary: 'Cancellation failed',
detail: error.error?.error || 'Failed to cancel task'
});
}
});
}
removeTask(taskId: string): void {
this.taskEventService.removeTask(taskId);
}
getStatusClasses(status: TaskStatus): string {
switch (status) {
case TaskStatus.IN_PROGRESS:
return 'bg-blue-700 text-zinc-100';
case TaskStatus.COMPLETED:
return 'bg-green-700 text-zinc-100';
case TaskStatus.FAILED:
return 'bg-red-700 text-zinc-100';
case TaskStatus.CANCELLED:
return 'bg-gray-700 text-zinc-100';
default:
return 'bg-zinc-700 text-zinc-100';
}
}
getStatusText(status: TaskStatus): string {
switch (status) {
case TaskStatus.IN_PROGRESS:
return 'Running';
case TaskStatus.COMPLETED:
return 'Completed';
case TaskStatus.FAILED:
return 'Failed';
case TaskStatus.CANCELLED:
return 'Cancelled';
default:
return 'Unknown';
}
}
}
@@ -1,5 +1,8 @@
<div class="metadata-progress-box flex flex-col w-[25rem] max-h-[60vh] overflow-y-auto">
<div class="metadata-progress-box flex gap-4 flex-col w-[25rem] max-h-[60vh] overflow-y-auto">
<app-live-notification-box/>
@if (hasActiveTasks$ | async) {
<app-live-task-event-box/>
}
@if (hasMetadataTasks$ | async) {
<app-metadata-progress-widget/>
}
@@ -1,7 +1,9 @@
import {Component, inject} from '@angular/core';
import {LiveNotificationBoxComponent} from '../live-notification-box/live-notification-box.component';
import {LiveTaskEventBoxComponent} from '../live-task-event-box/live-task-event-box.component';
import {MetadataProgressWidgetComponent} from '../metadata-progress-widget-component/metadata-progress-widget-component';
import {MetadataProgressService} from '../../service/metadata-progress-service';
import {TaskEventService} from '../../../shared/websocket/task-event.service';
import {map} from 'rxjs/operators';
import {AsyncPipe} from '@angular/common';
import {BookdropFilesWidgetComponent} from '../../../bookdrop/bookdrop-files-widget-component/bookdrop-files-widget.component';
@@ -11,6 +13,7 @@ import {BookdropFileService} from '../../../bookdrop/bookdrop-file.service';
selector: 'app-unified-notification-popover-component',
imports: [
LiveNotificationBoxComponent,
LiveTaskEventBoxComponent,
MetadataProgressWidgetComponent,
AsyncPipe,
BookdropFilesWidgetComponent
@@ -22,10 +25,15 @@ import {BookdropFileService} from '../../../bookdrop/bookdrop-file.service';
export class UnifiedNotificationBoxComponent {
metadataProgressService = inject(MetadataProgressService);
bookdropFileService = inject(BookdropFileService);
taskEventService = inject(TaskEventService);
hasMetadataTasks$ = this.metadataProgressService.activeTasks$.pipe(
map(tasks => Object.keys(tasks).length > 0)
);
hasPendingBookdropFiles$ = this.bookdropFileService.hasPendingFiles$;
hasActiveTasks$ = this.taskEventService.tasks$.pipe(
map(tasks => tasks.length > 0)
);
}