Improve notifications to display live progress for ongoing batch metadata fetches (#1242)
This commit is contained in:
-43
@@ -1,43 +0,0 @@
|
||||
<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>
|
||||
-7
@@ -1,7 +0,0 @@
|
||||
.live-border {
|
||||
background: var(--card-background);
|
||||
border: 1px solid var(--primary-color);
|
||||
border-radius: 0.5rem;
|
||||
|
||||
}
|
||||
|
||||
-84
@@ -1,84 +0,0 @@
|
||||
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';
|
||||
}
|
||||
}
|
||||
}
|
||||
+51
-18
@@ -4,12 +4,29 @@
|
||||
<div class="task-card p-4">
|
||||
|
||||
<div class="flex items-center justify-between mb-2">
|
||||
<p class="text-sm font-semibold text-[var(--primary-color)]">Metadata Fetch Task</p>
|
||||
<p-tag
|
||||
[value]="getStatusLabel(task.value.status)"
|
||||
[severity]="getTagSeverity(task.value.status)"
|
||||
class="text-xs"
|
||||
></p-tag>
|
||||
<div class="flex items-center gap-2">
|
||||
<p class="text-sm font-semibold text-[var(--primary-color)]">Metadata Fetch Task</p>
|
||||
</div>
|
||||
<div class="flex items-center gap-1">
|
||||
@if (task.value.review) {
|
||||
<p-tag
|
||||
value="Review"
|
||||
severity="warn"
|
||||
class="text-xs">
|
||||
</p-tag>
|
||||
} @else {
|
||||
<p-tag
|
||||
value="Auto"
|
||||
severity="success"
|
||||
class="text-xs">
|
||||
</p-tag>
|
||||
}
|
||||
<p-tag
|
||||
[value]="getStatusLabel(task.value.status)"
|
||||
[severity]="getTagSeverity(task.value.status)"
|
||||
class="text-xs"
|
||||
></p-tag>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="task-message text-gray-200">
|
||||
@@ -29,27 +46,43 @@
|
||||
|
||||
@if (task.value.status === 'COMPLETED' || task.value.status === 'ERROR') {
|
||||
<div class="action-buttons mt-4 flex justify-end gap-2">
|
||||
<p-button
|
||||
label="Review"
|
||||
severity="info"
|
||||
icon="pi pi-search"
|
||||
size="small"
|
||||
outlined
|
||||
(click)="reviewTask(task.key)">
|
||||
</p-button>
|
||||
@if (task.value.review) {
|
||||
<p-button
|
||||
label="Review"
|
||||
severity="info"
|
||||
icon="pi pi-search"
|
||||
size="small"
|
||||
outlined
|
||||
(click)="reviewTask(task.key)">
|
||||
</p-button>
|
||||
}
|
||||
|
||||
<p-button
|
||||
label="Discard"
|
||||
[label]="task.value.review ? 'Discard' : 'Dismiss'"
|
||||
icon="pi pi-times"
|
||||
severity="danger"
|
||||
[severity]="task.value.review ? 'danger' : 'secondary'"
|
||||
size="small"
|
||||
pTooltip="Deletes the fetched metadata"
|
||||
tooltipPosition="top"
|
||||
[pTooltip]="task.value.review ? 'Preserve current metadata, discard new fetched metadata' : ''"
|
||||
[tooltipPosition]="task.value.review ? 'top' : undefined"
|
||||
outlined
|
||||
(click)="clearTask(task.key)">
|
||||
</p-button>
|
||||
</div>
|
||||
} @else if (task.value.status === 'IN_PROGRESS') {
|
||||
<div class="action-buttons mt-4 flex justify-end gap-2">
|
||||
<p-button
|
||||
label="Cancel"
|
||||
icon="pi pi-stop"
|
||||
severity="danger"
|
||||
size="small"
|
||||
pTooltip="Cancel this task"
|
||||
tooltipPosition="top"
|
||||
outlined
|
||||
(click)="cancelTask(task.key)">
|
||||
</p-button>
|
||||
</div>
|
||||
}
|
||||
|
||||
</div>
|
||||
|
||||
@if (idx < Object.keys(activeTasks).length - 1) {
|
||||
|
||||
+6
@@ -26,3 +26,9 @@
|
||||
text-align: right;
|
||||
margin-top: 0.75rem;
|
||||
}
|
||||
|
||||
.review-indicator {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
+38
-6
@@ -7,15 +7,13 @@ import {ButtonModule} from 'primeng/button';
|
||||
import {Divider} from 'primeng/divider';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {DialogService} from 'primeng/dynamicdialog';
|
||||
import {MessageService} from 'primeng/api';
|
||||
|
||||
import {
|
||||
MetadataBatchProgressNotification,
|
||||
MetadataBatchStatus,
|
||||
MetadataBatchStatusLabels
|
||||
} from '../../model/metadata-batch-progress.model';
|
||||
import {MetadataBatchProgressNotification, MetadataBatchStatus, MetadataBatchStatusLabels} from '../../model/metadata-batch-progress.model';
|
||||
import {MetadataProgressService} from '../../service/metadata-progress-service';
|
||||
import {MetadataReviewDialogComponent} from '../../../metadata/metadata-review-dialog-component/metadata-review-dialog-component';
|
||||
import {MetadataTaskService} from '../../../book/service/metadata-task';
|
||||
import {TaskService} from '../../../shared/services/task.service';
|
||||
import {Tag} from 'primeng/tag';
|
||||
|
||||
@Component({
|
||||
@@ -32,6 +30,8 @@ export class MetadataProgressWidgetComponent implements OnInit, OnDestroy {
|
||||
private dialogService = inject(DialogService);
|
||||
private metadataProgressService = inject(MetadataProgressService);
|
||||
private metadataTaskService = inject(MetadataTaskService);
|
||||
private taskService = inject(TaskService);
|
||||
private messageService = inject(MessageService);
|
||||
|
||||
private lastUpdateMap = new Map<string, number>();
|
||||
private timeoutHandles = new Map<string, any>();
|
||||
@@ -87,7 +87,9 @@ export class MetadataProgressWidgetComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
getProgressPercent(task: MetadataBatchProgressNotification): number {
|
||||
return task.total > 0 ? Math.round((task.completed / task.total) * 100) : 0;
|
||||
if (task.total <= 0) return 0;
|
||||
if (task.status === 'COMPLETED') return 100;
|
||||
return Math.round((task.completed / task.total) * 100);
|
||||
}
|
||||
|
||||
clearTask(taskId: string): void {
|
||||
@@ -110,6 +112,36 @@ export class MetadataProgressWidgetComponent implements OnInit, OnDestroy {
|
||||
});
|
||||
}
|
||||
|
||||
cancelTask(taskId: string): void {
|
||||
this.taskService.cancelTask(taskId).subscribe({
|
||||
next: () => {
|
||||
const task = this.activeTasks[taskId];
|
||||
if (task) {
|
||||
this.activeTasks[taskId] = {
|
||||
...task,
|
||||
status: MetadataBatchStatus.ERROR,
|
||||
message: 'Task cancelled by user'
|
||||
};
|
||||
this.activeTasks = {...this.activeTasks};
|
||||
}
|
||||
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Cancellation Scheduled',
|
||||
detail: 'Task cancellation has been successfully scheduled'
|
||||
});
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Failed to cancel task:', error);
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Cancel Failed',
|
||||
detail: 'Failed to cancel the task. Please try again.'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
|
||||
-3
@@ -3,9 +3,6 @@
|
||||
@if (hasDuplicateFiles$ | async) {
|
||||
<app-duplicate-files-notification/>
|
||||
}
|
||||
@if (hasActiveTasks$ | async) {
|
||||
<app-live-task-event-box/>
|
||||
}
|
||||
@if (hasMetadataTasks$ | async) {
|
||||
<app-metadata-progress-widget/>
|
||||
}
|
||||
|
||||
-8
@@ -1,9 +1,7 @@
|
||||
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';
|
||||
@@ -15,7 +13,6 @@ import {DuplicateFileService} from '../../../shared/websocket/duplicate-file.ser
|
||||
selector: 'app-unified-notification-popover-component',
|
||||
imports: [
|
||||
LiveNotificationBoxComponent,
|
||||
LiveTaskEventBoxComponent,
|
||||
MetadataProgressWidgetComponent,
|
||||
AsyncPipe,
|
||||
BookdropFilesWidgetComponent,
|
||||
@@ -29,7 +26,6 @@ export class UnifiedNotificationBoxComponent {
|
||||
metadataProgressService = inject(MetadataProgressService);
|
||||
bookdropFileService = inject(BookdropFileService);
|
||||
duplicateFileService = inject(DuplicateFileService);
|
||||
taskEventService = inject(TaskEventService);
|
||||
|
||||
hasMetadataTasks$ = this.metadataProgressService.activeTasks$.pipe(
|
||||
map(tasks => Object.keys(tasks).length > 0)
|
||||
@@ -40,8 +36,4 @@ export class UnifiedNotificationBoxComponent {
|
||||
hasDuplicateFiles$ = this.duplicateFileService.duplicateFiles$.pipe(
|
||||
map(files => files && files.length > 0)
|
||||
);
|
||||
|
||||
hasActiveTasks$ = this.taskEventService.tasks$.pipe(
|
||||
map(tasks => tasks.length > 0)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -16,4 +16,5 @@ export interface MetadataBatchProgressNotification {
|
||||
total: number;
|
||||
message: string;
|
||||
status: MetadataBatchStatus;
|
||||
review: boolean;
|
||||
}
|
||||
|
||||
@@ -23,11 +23,11 @@ export class MetadataProgressService implements OnDestroy {
|
||||
constructor() {
|
||||
const sub = this.userService.userState$
|
||||
.pipe(
|
||||
filter(user => !!user),
|
||||
filter(userState => !!userState?.user),
|
||||
take(1)
|
||||
)
|
||||
.subscribe(user => {
|
||||
if (!this.hasMetadataPermissions(user)) {
|
||||
.subscribe(userState => {
|
||||
if (!this.hasMetadataPermissions(userState.user)) {
|
||||
return;
|
||||
}
|
||||
const activeTasksSub = this.metadataTaskService.getActiveTasks().subscribe({
|
||||
@@ -67,7 +67,7 @@ export class MetadataProgressService implements OnDestroy {
|
||||
}
|
||||
|
||||
private hasMetadataPermissions(user: any): boolean {
|
||||
return user?.permissions?.admin || user?.permissions?.canEditMetadata;
|
||||
return !!(user?.permissions?.admin || user?.permissions?.canEditMetadata);
|
||||
}
|
||||
|
||||
private initializeActiveTasks(tasks: MetadataBatchProgressNotification[]): void {
|
||||
|
||||
Reference in New Issue
Block a user