Add task management panel with live task status and controls (#1322)
This commit is contained in:
@@ -15,6 +15,7 @@ import {DuplicateFileNotification} from './shared/websocket/model/duplicate-file
|
||||
import {DuplicateFileService} from './shared/websocket/duplicate-file.service';
|
||||
import {Subscription} from 'rxjs';
|
||||
import {DownloadProgressDialogComponent} from './shared/components/download-progress-dialog/download-progress-dialog.component';
|
||||
import {TaskService, TaskProgressPayload} from './settings/task-management/task.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-root',
|
||||
@@ -35,6 +36,7 @@ export class AppComponent implements OnInit, OnDestroy {
|
||||
private metadataProgressService = inject(MetadataProgressService);
|
||||
private bookdropFileService = inject(BookdropFileService);
|
||||
private duplicateFileService = inject(DuplicateFileService);
|
||||
private taskService = inject(TaskService);
|
||||
private appConfigService = inject(AppConfigService); // Keep it here to ensure the service is initialized
|
||||
|
||||
ngOnInit(): void {
|
||||
@@ -90,6 +92,12 @@ export class AppComponent implements OnInit, OnDestroy {
|
||||
this.bookdropFileService.handleIncomingFile(notification);
|
||||
})
|
||||
);
|
||||
this.subscriptions.push(
|
||||
this.rxStompService.watch('/user/queue/task-progress').subscribe(msg => {
|
||||
const progress = JSON.parse(msg.body) as TaskProgressPayload;
|
||||
this.taskService.handleTaskProgress(progress);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
|
||||
@@ -36,7 +36,7 @@ export class LibraryCreatorComponent implements OnInit {
|
||||
defaultBookFormat: BookFileType | undefined = undefined;
|
||||
|
||||
readonly scanModeOptions = [
|
||||
{label: 'Each file is a book', value: 'FILE_AS_BOOK'},
|
||||
{label: 'Each file is a book (Recommended)', value: 'FILE_AS_BOOK'},
|
||||
{label: 'Each folder is a book with extras', value: 'FOLDER_AS_BOOK'}
|
||||
];
|
||||
|
||||
|
||||
@@ -31,6 +31,9 @@
|
||||
<p-tab [value]="SettingsTab.AuthenticationSettings">
|
||||
<i class="pi pi-lock"></i> Authentication
|
||||
</p-tab>
|
||||
<p-tab [value]="SettingsTab.Tasks">
|
||||
<i class="pi pi-list-check"></i> Tasks
|
||||
</p-tab>
|
||||
}
|
||||
<p-tab [value]="SettingsTab.OpdsV2">
|
||||
<i class="pi pi-globe"></i> OPDS
|
||||
@@ -68,6 +71,9 @@
|
||||
<p-tabpanel [value]="SettingsTab.AuthenticationSettings">
|
||||
<app-authentication-settings></app-authentication-settings>
|
||||
</p-tabpanel>
|
||||
<p-tabpanel [value]="SettingsTab.Tasks">
|
||||
<app-task-management></app-task-management>
|
||||
</p-tabpanel>
|
||||
}
|
||||
<p-tabpanel [value]="SettingsTab.OpdsV2">
|
||||
<app-opds-settings-v2></app-opds-settings-v2>
|
||||
|
||||
@@ -15,6 +15,7 @@ import {DeviceSettingsComponent} from './device-settings-component/device-settin
|
||||
import {FileNamingPatternComponent} from './file-naming-pattern/file-naming-pattern.component';
|
||||
import {OpdsSettingsV2} from './opds-settings-v2/opds-settings-v2';
|
||||
import {LibraryMetadataSettingsComponent} from './library-metadata-settings-component/library-metadata-settings.component';
|
||||
import {TaskManagementComponent} from './task-management/task-management.component';
|
||||
|
||||
export enum SettingsTab {
|
||||
ReaderSettings = 'reader',
|
||||
@@ -27,7 +28,8 @@ export enum SettingsTab {
|
||||
LibraryMetadataSettings = 'metadata-library',
|
||||
ApplicationSettings = 'application',
|
||||
AuthenticationSettings = 'authentication',
|
||||
OpdsV2 = 'opds'
|
||||
OpdsV2 = 'opds',
|
||||
Tasks = 'tasks',
|
||||
}
|
||||
|
||||
@Component({
|
||||
@@ -49,7 +51,8 @@ export enum SettingsTab {
|
||||
DeviceSettingsComponent,
|
||||
FileNamingPatternComponent,
|
||||
OpdsSettingsV2,
|
||||
LibraryMetadataSettingsComponent
|
||||
LibraryMetadataSettingsComponent,
|
||||
TaskManagementComponent
|
||||
],
|
||||
templateUrl: './settings.component.html',
|
||||
styleUrl: './settings.component.scss'
|
||||
|
||||
@@ -0,0 +1,273 @@
|
||||
<div class="main-container enclosing-container">
|
||||
<div class="settings-header">
|
||||
<h2 class="settings-title">
|
||||
<i class="pi pi-list-check"></i>
|
||||
Task Management
|
||||
</h2>
|
||||
<p class="settings-description">
|
||||
Monitor and manage system tasks including cache operations, library scanning, and other background processes.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="settings-content">
|
||||
<div class="preferences-section">
|
||||
<div class="section-header">
|
||||
<div class="section-header-content">
|
||||
<h3 class="section-title">
|
||||
<i class="pi pi-cog"></i>
|
||||
Active Tasks
|
||||
</h3>
|
||||
<p-button
|
||||
label="Refresh"
|
||||
icon="pi pi-refresh"
|
||||
size="small"
|
||||
outlined
|
||||
[loading]="loading"
|
||||
(onClick)="loadTasks()">
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (loading && tasks.length === 0) {
|
||||
<div class="loading-container">
|
||||
<i class="pi pi-spin pi-spinner"></i>
|
||||
<span>Loading tasks...</span>
|
||||
</div>
|
||||
}
|
||||
|
||||
@for (task of tasks; track task.type) {
|
||||
@if (task.type === TaskType.CLEAR_CBX_CACHE || task.type === TaskType.CLEAR_PDF_CACHE) {
|
||||
<div class="settings-card" [class.compact]="!isTaskRunning(task)">
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<div class="task-title-section">
|
||||
<div class="title-with-status">
|
||||
<label class="setting-label">{{ getTaskDisplayName(task.type) }}</label>
|
||||
@if (!isTaskRunning(task) && task.id) {
|
||||
<span class="last-run-badge">[{{ getLastRunMessage(task) }}<span class="sep">|</span><span class="status-dot" [ngClass]="getLastRunInfoClass(task.status)"></span><span
|
||||
class="status-text">{{ getLastRunInfoClass(task.status) === 'success' ? 'Success' : getLastRunInfoClass(task.status) === 'error' ? 'Error' : getLastRunInfoClass(task.status) === 'warning' ? 'Warning' : 'Info' }}]</span></span>
|
||||
}
|
||||
</div>
|
||||
@if (!isTaskRunning(task)) {
|
||||
<p class="setting-description compact">
|
||||
{{ getTaskDescription(task.type) }}
|
||||
</p>
|
||||
}
|
||||
@if (!isTaskRunning(task) && hasMetadata(task)) {
|
||||
<div class="task-metadata prominent">
|
||||
@if (task.metadata.currentCacheSize) {
|
||||
<span class="metadata-item prominent">
|
||||
<i class="pi pi-database"></i>
|
||||
Current cache size:
|
||||
<span class="cache-size-value">{{ task.metadata.currentCacheSize }}</span>
|
||||
</span>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
<div class="task-actions">
|
||||
@if (isTaskRunning(task) && !isTaskStale(task)) {
|
||||
<p-badge
|
||||
value="In Progress"
|
||||
severity="info">
|
||||
</p-badge>
|
||||
}
|
||||
@if (isTaskStale(task)) {
|
||||
<p-badge
|
||||
value="Stale"
|
||||
severity="warn">
|
||||
</p-badge>
|
||||
}
|
||||
@if (canExecuteTask(task) || isTaskStale(task)) {
|
||||
<p-button
|
||||
label="Clear Cache"
|
||||
icon="pi pi-trash"
|
||||
size="small"
|
||||
severity="warn"
|
||||
(onClick)="executeTask(task)">
|
||||
</p-button>
|
||||
}
|
||||
@if (canCancelTask(task) && !isTaskStale(task)) {
|
||||
<p-button
|
||||
label="Cancel"
|
||||
icon="pi pi-times"
|
||||
size="small"
|
||||
severity="danger"
|
||||
outlined
|
||||
(onClick)="cancelTask(task)">
|
||||
</p-button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (isTaskRunning(task)) {
|
||||
<div class="task-details" [class.stale]="isTaskStale(task)">
|
||||
@if (isTaskStale(task)) {
|
||||
<div class="task-info-row stale-warning">
|
||||
<span class="task-info-label">
|
||||
<i class="pi pi-exclamation-triangle"></i>
|
||||
Warning:
|
||||
</span>
|
||||
<span class="task-info-value warning-text">
|
||||
This task appears to be stuck. No updates received for over 10 minutes.
|
||||
</span>
|
||||
</div>
|
||||
}
|
||||
@if (task.message || isTaskStale(task)) {
|
||||
<div class="task-info-row">
|
||||
<span class="task-info-label">Status:</span>
|
||||
<span class="task-info-value">{{ getTaskStatusMessage(task) }}</span>
|
||||
</div>
|
||||
}
|
||||
@if (task.progressPercentage !== null) {
|
||||
<div class="task-info-row">
|
||||
<span class="task-info-label">Progress:</span>
|
||||
<div class="progress-container">
|
||||
<p-progressbar [value]="task.progressPercentage"></p-progressbar>
|
||||
<span class="progress-text">{{ task.progressPercentage }}%</span>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
@if (task.updatedAt) {
|
||||
<div class="task-info-row">
|
||||
<span class="task-info-label">Started:</span>
|
||||
<span class="task-info-value">{{ formatDate(task.updatedAt) }}</span>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<p class="setting-description expanded">
|
||||
<i class="pi pi-info-circle"></i>
|
||||
{{ getTaskDescription(task.type) }}
|
||||
</p>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (task.type === TaskType.RE_SCAN_LIBRARY) {
|
||||
<div class="settings-card" [class.compact]="!isTaskRunning(task)">
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<div class="task-title-section">
|
||||
<div class="title-with-status">
|
||||
<label class="setting-label">{{ getTaskDisplayName(task.type) }}</label>
|
||||
@if (!isTaskRunning(task) && task.id) {
|
||||
<span class="last-run-badge">[{{ getLastRunMessage(task) }}<span class="sep">|</span><span class="status-dot" [ngClass]="getLastRunInfoClass(task.status)"></span><span
|
||||
class="status-text">{{ getLastRunInfoClass(task.status) === 'success' ? 'Success' : getLastRunInfoClass(task.status) === 'error' ? 'Error' : getLastRunInfoClass(task.status) === 'warning' ? 'Warning' : 'Info' }}]</span></span>
|
||||
}
|
||||
</div>
|
||||
<p class="setting-description compact always-visible">
|
||||
{{ getTaskDescription(task.type) }}
|
||||
</p>
|
||||
@if (!isTaskRunning(task)) {
|
||||
<div class="task-options">
|
||||
<div class="option-group">
|
||||
<label class="option-label">Metadata Replace Mode:</label>
|
||||
<p-select
|
||||
[options]="metadataReplaceOptions"
|
||||
[(ngModel)]="selectedMetadataReplaceMode"
|
||||
placeholder="Select mode"
|
||||
class="metadata-select">
|
||||
</p-select>
|
||||
<p class="option-description">
|
||||
{{ getMetadataReplaceDescription(selectedMetadataReplaceMode) }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
<div class="task-actions">
|
||||
@if (isTaskRunning(task) && !isTaskStale(task)) {
|
||||
<p-badge
|
||||
value="In Progress"
|
||||
severity="info">
|
||||
</p-badge>
|
||||
}
|
||||
@if (isTaskStale(task)) {
|
||||
<p-badge
|
||||
value="Stale"
|
||||
severity="warn">
|
||||
</p-badge>
|
||||
}
|
||||
@if (canExecuteTask(task) || isTaskStale(task)) {
|
||||
<p-button
|
||||
label="Start Rescan"
|
||||
icon="pi pi-sync"
|
||||
size="small"
|
||||
severity="success"
|
||||
(onClick)="executeTask(task)">
|
||||
</p-button>
|
||||
}
|
||||
@if (canCancelTask(task) && !isTaskStale(task)) {
|
||||
<p-button
|
||||
label="Cancel"
|
||||
icon="pi pi-times"
|
||||
size="small"
|
||||
severity="danger"
|
||||
outlined
|
||||
(onClick)="cancelTask(task)">
|
||||
</p-button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
@if (isTaskRunning(task)) {
|
||||
<div class="task-details" [class.stale]="isTaskStale(task)">
|
||||
@if (isTaskStale(task)) {
|
||||
<div class="task-info-row stale-warning">
|
||||
<span class="task-info-label">
|
||||
<i class="pi pi-exclamation-triangle"></i>
|
||||
Warning:
|
||||
</span>
|
||||
<span class="task-info-value warning-text">
|
||||
This task appears to be stuck. No updates received for over 10 minutes.
|
||||
</span>
|
||||
</div>
|
||||
}
|
||||
@if (task.message || isTaskStale(task)) {
|
||||
<div class="task-info-row">
|
||||
<span class="task-info-label">Status:</span>
|
||||
<span class="task-info-value">{{ getTaskStatusMessage(task) }}</span>
|
||||
</div>
|
||||
}
|
||||
@if (task.progressPercentage !== null) {
|
||||
<div class="task-info-row">
|
||||
<span class="task-info-label">Progress:</span>
|
||||
<div class="progress-container">
|
||||
<p-progressbar [value]="task.progressPercentage"></p-progressbar>
|
||||
<span class="progress-text">{{ task.progressPercentage }}%</span>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
@if (task.updatedAt) {
|
||||
<div class="task-info-row">
|
||||
<span class="task-info-label">Started:</span>
|
||||
<span class="task-info-value">{{ formatDate(task.updatedAt) }}</span>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
@if (!loading && tasks.length === 0) {
|
||||
<div class="settings-card">
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="no-tasks-message">
|
||||
<i class="pi pi-check-circle"></i>
|
||||
<span>No tasks available</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,500 @@
|
||||
.main-container {
|
||||
width: 100%;
|
||||
padding: 1rem;
|
||||
height: calc(100dvh - 10.5rem);
|
||||
overflow-y: auto;
|
||||
border-width: 1px;
|
||||
border-radius: 0.5rem;
|
||||
|
||||
@media (min-width: 768px) {
|
||||
height: calc(100dvh - 11.65rem);
|
||||
}
|
||||
}
|
||||
|
||||
.enclosing-container {
|
||||
border-color: var(--p-content-border-color);
|
||||
background: var(--p-content-background);
|
||||
}
|
||||
|
||||
.settings-header {
|
||||
margin-top: 1rem;
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.settings-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
font-size: 1.25rem;
|
||||
font-weight: 700;
|
||||
color: var(--p-text-color);
|
||||
margin: 0 0 0.75rem 0;
|
||||
|
||||
.pi {
|
||||
color: var(--p-primary-color);
|
||||
font-size: 1.25rem;
|
||||
}
|
||||
}
|
||||
|
||||
.settings-description {
|
||||
color: var(--p-text-muted-color);
|
||||
font-size: 0.875rem;
|
||||
line-height: 1.5;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.settings-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2rem;
|
||||
}
|
||||
|
||||
.preferences-section {
|
||||
@media (min-width: 768px) {
|
||||
padding: 0 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
.section-header {
|
||||
margin-bottom: 1rem;
|
||||
|
||||
.section-header-content {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
flex-wrap: wrap;
|
||||
gap: 1rem;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.section-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
font-size: 1.125rem;
|
||||
font-weight: 600;
|
||||
color: var(--p-text-color);
|
||||
margin: 0;
|
||||
|
||||
.pi {
|
||||
color: var(--p-primary-color);
|
||||
}
|
||||
}
|
||||
|
||||
.settings-card {
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
border-radius: 8px;
|
||||
background: var(--p-content-background);
|
||||
padding: 1.25rem 1.5rem 1.25rem 1.5rem;
|
||||
margin-bottom: 1rem;
|
||||
transition: all 0.2s ease;
|
||||
|
||||
&.compact {
|
||||
padding: 1.25rem 1.5rem 1.25rem 1.5rem;
|
||||
}
|
||||
|
||||
&:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.setting-item {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 2rem;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
.setting-info {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
|
||||
.setting-label {
|
||||
display: block;
|
||||
font-weight: 600;
|
||||
color: var(--p-text-color);
|
||||
font-size: 1rem;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.title-with-status {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
flex-wrap: wrap;
|
||||
|
||||
.setting-label {
|
||||
margin-bottom: 0;
|
||||
line-height: 1.2;
|
||||
}
|
||||
}
|
||||
|
||||
.setting-label-row {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
flex-wrap: wrap;
|
||||
gap: 1rem;
|
||||
|
||||
.task-title-section {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.task-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.setting-description {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 0.5rem;
|
||||
color: var(--p-text-muted-color);
|
||||
font-size: 0.875rem;
|
||||
line-height: 1.5;
|
||||
margin: 0;
|
||||
|
||||
&.compact {
|
||||
font-size: 0.875rem;
|
||||
color: var(--p-text-muted-color);
|
||||
margin-top: 0.5rem;
|
||||
}
|
||||
|
||||
&.expanded {
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
.pi {
|
||||
color: var(--p-primary-color);
|
||||
margin-top: 0.125rem;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.setting-description.always-visible {
|
||||
min-height: 1.5em;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
.task-details {
|
||||
margin-bottom: 1rem;
|
||||
margin-top: 1rem;
|
||||
padding: 1rem;
|
||||
background: var(--p-surface-800);
|
||||
border-radius: 6px;
|
||||
border: 1px solid var(--p-surface-500);
|
||||
|
||||
&:empty {
|
||||
display: none;
|
||||
}
|
||||
|
||||
&.stale {
|
||||
border-color: var(--p-yellow-500);
|
||||
background: var(--p-yellow-50);
|
||||
}
|
||||
}
|
||||
|
||||
.task-info-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
margin-bottom: 0.5rem;
|
||||
|
||||
&:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
&.stale-warning {
|
||||
padding: 0.5rem;
|
||||
background: var(--p-yellow-100);
|
||||
border-radius: 4px;
|
||||
border: 1px solid var(--p-yellow-300);
|
||||
margin-bottom: 0.75rem;
|
||||
|
||||
.task-info-label {
|
||||
color: var(--p-yellow-700);
|
||||
font-weight: 600;
|
||||
|
||||
.pi {
|
||||
color: var(--p-yellow-600);
|
||||
margin-right: 0.25rem;
|
||||
}
|
||||
}
|
||||
|
||||
.warning-text {
|
||||
color: var(--p-yellow-800);
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.task-info-label {
|
||||
font-weight: 500;
|
||||
color: var(--p-text-color);
|
||||
min-width: 80px;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.task-info-value {
|
||||
color: var(--p-text-muted-color);
|
||||
font-size: 0.875rem;
|
||||
font-family: monospace;
|
||||
}
|
||||
|
||||
.progress-container {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
flex: 1;
|
||||
|
||||
.progress-text {
|
||||
font-size: 0.875rem;
|
||||
color: var(--p-text-muted-color);
|
||||
min-width: 40px;
|
||||
}
|
||||
}
|
||||
|
||||
.last-run-badge {
|
||||
font-size: 0.875rem;
|
||||
padding: 0;
|
||||
border-radius: 0;
|
||||
font-weight: 500;
|
||||
white-space: nowrap;
|
||||
line-height: 1.2;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
color: var(--p-text-muted-color);
|
||||
background: transparent;
|
||||
border: none;
|
||||
|
||||
.sep {
|
||||
color: var(--p-text-muted-color);
|
||||
margin: 0 0.25rem;
|
||||
font-size: 0.875rem;
|
||||
line-height: 1.2;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.status-dot {
|
||||
width: 0.5rem;
|
||||
height: 0.5rem;
|
||||
border-radius: 50%;
|
||||
display: inline-block;
|
||||
flex-shrink: 0;
|
||||
background: var(--p-surface-400);
|
||||
}
|
||||
|
||||
.status-text {
|
||||
font-size: 0.75rem;
|
||||
color: var(--p-text-muted-color);
|
||||
font-weight: 600;
|
||||
text-transform: capitalize;
|
||||
}
|
||||
|
||||
& .status-dot.success,
|
||||
&.success .status-dot {
|
||||
background: var(--p-green-500);
|
||||
}
|
||||
|
||||
& .status-dot.error,
|
||||
&.error .status-dot {
|
||||
background: var(--p-red-500);
|
||||
}
|
||||
|
||||
& .status-dot.warning,
|
||||
&.warning .status-dot {
|
||||
background: var(--p-yellow-500);
|
||||
}
|
||||
|
||||
& .status-dot.info,
|
||||
&.info .status-dot {
|
||||
background: var(--p-blue-500);
|
||||
}
|
||||
}
|
||||
|
||||
.last-run-info {
|
||||
margin-top: 0.5rem;
|
||||
padding: 0.5rem 0.75rem;
|
||||
background: var(--p-surface-800);
|
||||
border-radius: 4px;
|
||||
border-left: 3px solid var(--p-green-500);
|
||||
|
||||
&.success {
|
||||
border-left-color: var(--p-green-500);
|
||||
background: var(--p-green-50);
|
||||
}
|
||||
|
||||
&.error {
|
||||
border-left-color: var(--p-red-500);
|
||||
background: var(--p-red-50);
|
||||
}
|
||||
|
||||
&.warning {
|
||||
border-left-color: var(--p-yellow-500);
|
||||
background: var(--p-yellow-50);
|
||||
}
|
||||
|
||||
&.info {
|
||||
border-left-color: var(--p-blue-500);
|
||||
background: var(--p-blue-50);
|
||||
}
|
||||
|
||||
.last-run-text {
|
||||
font-size: 0.875rem;
|
||||
color: var(--p-text-muted-color);
|
||||
font-style: italic;
|
||||
}
|
||||
}
|
||||
|
||||
.task-metadata {
|
||||
margin-bottom: 1rem;
|
||||
|
||||
&.prominent {
|
||||
margin-top: 0.75rem;
|
||||
margin-bottom: 0;
|
||||
|
||||
.metadata-item {
|
||||
&.prominent {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
font-size: 0.9rem;
|
||||
font-weight: 500;
|
||||
color: var(--p-text-color);
|
||||
background: var(--p-highlight-bg);
|
||||
border: 1px solid var(--p-highlight-border);
|
||||
padding: 0.25rem 0 0.25rem 0;
|
||||
border-radius: 6px;
|
||||
margin-top: 0.5rem;
|
||||
|
||||
.pi {
|
||||
color: var(--p-primary-color);
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.cache-size-value {
|
||||
font-size: 1rem;
|
||||
color: var(--p-primary-color);
|
||||
font-weight: 600;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.no-tasks-message {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 0.5rem;
|
||||
color: var(--p-text-muted-color);
|
||||
font-style: italic;
|
||||
padding: 2rem;
|
||||
|
||||
.pi {
|
||||
color: var(--p-green-500);
|
||||
font-size: 1.25rem;
|
||||
}
|
||||
}
|
||||
|
||||
.loading-container {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 0.75rem;
|
||||
padding: 3rem;
|
||||
color: var(--p-text-muted-color);
|
||||
|
||||
.pi-spinner {
|
||||
font-size: 1.25rem;
|
||||
color: var(--p-primary-color);
|
||||
}
|
||||
}
|
||||
|
||||
.task-options {
|
||||
margin-top: 1rem;
|
||||
margin-bottom: 0;
|
||||
padding: 1rem;
|
||||
background: var(--p-surface-800);
|
||||
border-radius: 6px;
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
}
|
||||
|
||||
.option-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
|
||||
.option-label {
|
||||
font-weight: 500;
|
||||
color: var(--p-text-color);
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.option-description {
|
||||
color: var(--p-text-muted-color);
|
||||
font-size: 0.875rem;
|
||||
line-height: 1.4;
|
||||
margin: 0.25rem 0 0;
|
||||
}
|
||||
}
|
||||
|
||||
:host ::ng-deep .metadata-select {
|
||||
width: 100%;
|
||||
max-width: 400px;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.setting-label-row {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 0.75rem;
|
||||
|
||||
.task-title-section {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.task-actions {
|
||||
align-self: stretch;
|
||||
justify-content: flex-start;
|
||||
}
|
||||
}
|
||||
|
||||
.title-with-status {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.task-info-row {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 0.25rem;
|
||||
}
|
||||
|
||||
.progress-container {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
:host ::ng-deep .metadata-select {
|
||||
max-width: none;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,281 @@
|
||||
import {Component, inject, OnDestroy, OnInit} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {Button} from 'primeng/button';
|
||||
import {Badge} from 'primeng/badge';
|
||||
import {ProgressBar} from 'primeng/progressbar';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {Select} from 'primeng/select';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {MetadataReplaceMode, Task, TASK_TYPE_CONFIG, TaskCreateRequest, TaskProgressPayload, TaskService, TaskStatus, TaskType} from './task.service';
|
||||
import {finalize, Subscription} from 'rxjs';
|
||||
|
||||
@Component({
|
||||
selector: 'app-task-management',
|
||||
standalone: true,
|
||||
imports: [
|
||||
CommonModule,
|
||||
Button,
|
||||
Badge,
|
||||
ProgressBar,
|
||||
Select,
|
||||
FormsModule
|
||||
],
|
||||
templateUrl: './task-management.component.html',
|
||||
styleUrl: './task-management.component.scss'
|
||||
})
|
||||
export class TaskManagementComponent implements OnInit, OnDestroy {
|
||||
private messageService = inject(MessageService);
|
||||
private taskService = inject(TaskService);
|
||||
|
||||
tasks: Task[] = [];
|
||||
loading = false;
|
||||
private subscription?: Subscription;
|
||||
|
||||
metadataReplaceOptions = [
|
||||
{label: 'Replace Missing Only (Recommended)', value: MetadataReplaceMode.REPLACE_MISSING},
|
||||
{label: 'Replace All Metadata', value: MetadataReplaceMode.REPLACE_ALL}
|
||||
];
|
||||
selectedMetadataReplaceMode: MetadataReplaceMode = MetadataReplaceMode.REPLACE_MISSING;
|
||||
|
||||
ngOnInit(): void {
|
||||
this.loadTasks();
|
||||
this.subscribeToTaskProgress();
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.subscription?.unsubscribe();
|
||||
}
|
||||
|
||||
private subscribeToTaskProgress(): void {
|
||||
this.subscription = this.taskService.taskProgress$.subscribe(progress => {
|
||||
if (progress) {
|
||||
this.updateTaskWithProgress(progress);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private updateTaskWithProgress(progress: TaskProgressPayload): void {
|
||||
const taskIndex = this.tasks.findIndex(task => task.id === progress.taskId);
|
||||
if (taskIndex !== -1) {
|
||||
this.tasks[taskIndex] = {
|
||||
...this.tasks[taskIndex],
|
||||
status: progress.taskStatus,
|
||||
progressPercentage: progress.progress,
|
||||
message: progress.message,
|
||||
updatedAt: new Date().toISOString()
|
||||
};
|
||||
|
||||
if (progress.taskStatus === TaskStatus.COMPLETED || progress.taskStatus === TaskStatus.FAILED) {
|
||||
setTimeout(() => this.loadTasks(), 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
loadTasks(): void {
|
||||
this.loading = true;
|
||||
this.taskService.getLatestTasksForEachType()
|
||||
.pipe(finalize(() => this.loading = false))
|
||||
.subscribe({
|
||||
next: (response) => {
|
||||
this.tasks = response.tasks;
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Error loading tasks:', error);
|
||||
this.showMessage('error', 'Error', 'Failed to load tasks');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getTaskDisplayName(type: string): string {
|
||||
const taskNames: Record<string, string> = {
|
||||
'CLEAR_CBX_CACHE': 'Clear CBX Cache',
|
||||
'CLEAR_PDF_CACHE': 'Clear PDF Cache',
|
||||
'RE_SCAN_LIBRARY': 'Refresh Metadata from Library Files'
|
||||
};
|
||||
return taskNames[type] || type.replace(/_/g, ' ').toLowerCase().replace(/\b\w/g, l => l.toUpperCase());
|
||||
}
|
||||
|
||||
getTaskDescription(type: string): string {
|
||||
const descriptions: Record<string, string> = {
|
||||
'CLEAR_CBX_CACHE': 'Clears the cached images for CBX files to free up disk space.',
|
||||
'CLEAR_PDF_CACHE': 'Clears the cached images for PDF files to free up disk space.',
|
||||
'RE_SCAN_LIBRARY': 'Scans the library folders to read metadata from existing book files and update the database accordingly. Existing metadata in the database may be overwritten during this process.'
|
||||
};
|
||||
return descriptions[type] || 'System maintenance task.';
|
||||
}
|
||||
|
||||
canExecuteTask(task: Task): boolean {
|
||||
return this.canRunTask(task) || this.isTaskStale(task);
|
||||
}
|
||||
|
||||
executeTask(task: Task): void {
|
||||
this.runTask(task.type);
|
||||
}
|
||||
|
||||
canRunTask(task: Task): boolean {
|
||||
return !task.status || task.status === TaskStatus.COMPLETED || task.status === TaskStatus.FAILED || task.status === TaskStatus.CANCELLED;
|
||||
}
|
||||
|
||||
canCancelTask(task: Task): boolean {
|
||||
return task.status === TaskStatus.IN_PROGRESS || task.status === TaskStatus.PENDING;
|
||||
}
|
||||
|
||||
runTask(type: string): void {
|
||||
if (!this.canRunTask(this.getTaskByType(type)) && !this.isTaskStale(this.getTaskByType(type))) {
|
||||
this.showMessage('warn', 'Task Already Running', 'This task is already in progress or pending.');
|
||||
return;
|
||||
}
|
||||
|
||||
let options = null;
|
||||
|
||||
if (type === TaskType.RE_SCAN_LIBRARY) {
|
||||
options = {
|
||||
metadataReplaceMode: this.selectedMetadataReplaceMode
|
||||
};
|
||||
}
|
||||
|
||||
this.runTaskWithOptions(type, options);
|
||||
}
|
||||
|
||||
private runTaskWithOptions(type: string, options: any): void {
|
||||
const request: TaskCreateRequest = {
|
||||
taskType: type as TaskType,
|
||||
options: options
|
||||
};
|
||||
|
||||
const isAsync = TASK_TYPE_CONFIG[type as TaskType]?.async || false;
|
||||
|
||||
this.taskService.startTask(request).subscribe({
|
||||
next: (response) => {
|
||||
if (isAsync) {
|
||||
this.showMessage('info', 'Task Queued', `${this.getTaskDisplayName(type)} has been queued and will run in the background.`);
|
||||
} else {
|
||||
if (response.status === TaskStatus.COMPLETED) {
|
||||
this.showMessage('success', 'Task Completed', `${this.getTaskDisplayName(type)} has been completed successfully.`);
|
||||
} else if (response.status === TaskStatus.FAILED) {
|
||||
this.showMessage('error', 'Task Failed', response.message || `${this.getTaskDisplayName(type)} failed to complete.`);
|
||||
} else {
|
||||
this.showMessage('success', 'Task Started', `${this.getTaskDisplayName(type)} has been started successfully.`);
|
||||
}
|
||||
}
|
||||
this.loadTasks();
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Error starting task:', error);
|
||||
this.showMessage('error', 'Error', `Failed to start ${this.getTaskDisplayName(type)}.`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
cancelTask(task: Task): void {
|
||||
if (!task.id) {
|
||||
this.showMessage('error', 'Error', 'Cannot cancel task without ID.');
|
||||
return;
|
||||
}
|
||||
|
||||
this.taskService.cancelTask(task.id).subscribe({
|
||||
next: (response) => {
|
||||
if (response.cancelled) {
|
||||
this.showMessage('success', 'Task Cancelled', response.message || 'Task has been cancelled successfully.');
|
||||
this.loadTasks(); // Refresh the task list
|
||||
} else {
|
||||
this.showMessage('error', 'Cancellation Failed', response.message || 'Failed to cancel the task.');
|
||||
}
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Error cancelling task:', error);
|
||||
this.showMessage('error', 'Error', 'Failed to cancel the task. The task may already be completed or failed.');
|
||||
// Refresh tasks in case the task actually completed
|
||||
this.loadTasks();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
formatDate(dateString: string): string {
|
||||
const date = new Date(dateString);
|
||||
return date.toLocaleString();
|
||||
}
|
||||
|
||||
hasMetadata(task: Task): boolean {
|
||||
return task.metadata && Object.keys(task.metadata).length > 0;
|
||||
}
|
||||
|
||||
isTaskRunning(task: Task): boolean {
|
||||
return task.status === TaskStatus.IN_PROGRESS || task.status === TaskStatus.PENDING;
|
||||
}
|
||||
|
||||
isTaskStale(task: Task): boolean {
|
||||
if (!task.updatedAt || !this.isTaskRunning(task)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const lastUpdate = new Date(task.updatedAt);
|
||||
const now = new Date();
|
||||
const timeDiff = now.getTime() - lastUpdate.getTime();
|
||||
const minutesDiff = timeDiff / (1000 * 60);
|
||||
|
||||
return minutesDiff > 2;
|
||||
}
|
||||
|
||||
getTaskStatusMessage(task: Task): string {
|
||||
if (this.isTaskStale(task)) {
|
||||
return 'Task appears to be stuck. You may need to cancel it.';
|
||||
}
|
||||
return task.message || 'Task is running...';
|
||||
}
|
||||
|
||||
getLastRunInfoClass(status: string | null): string {
|
||||
if (status === 'COMPLETED') return 'success';
|
||||
if (status === 'FAILED') return 'error';
|
||||
if (status === 'CANCELLED') return 'warning';
|
||||
return 'info';
|
||||
}
|
||||
|
||||
getLastRunMessage(task: Task): string {
|
||||
const timeText = task.completedAt ? this.formatDate(task.completedAt) :
|
||||
task.updatedAt ? this.formatDate(task.updatedAt) : '';
|
||||
|
||||
if (task.status === 'COMPLETED') {
|
||||
return `Last completed: ${timeText}`;
|
||||
} else if (task.status === 'FAILED') {
|
||||
return `Failed: ${timeText}`;
|
||||
} else if (task.status === 'CANCELLED') {
|
||||
return `Cancelled: ${timeText}`;
|
||||
}
|
||||
|
||||
return timeText ? `Last run: ${timeText}` : 'Not run yet';
|
||||
}
|
||||
|
||||
getMetadataReplaceDescription(mode: MetadataReplaceMode): string {
|
||||
const descriptions: Record<MetadataReplaceMode, string> = {
|
||||
[MetadataReplaceMode.REPLACE_ALL]: 'Replace all existing metadata with data from files, even if metadata already exists in the database.',
|
||||
[MetadataReplaceMode.REPLACE_MISSING]: 'Only update metadata that is missing or empty in the database, preserving existing metadata.'
|
||||
};
|
||||
return descriptions[mode];
|
||||
}
|
||||
|
||||
private getTaskByType(type: string): Task {
|
||||
return this.tasks.find(task => task.type === type) || {
|
||||
id: null,
|
||||
type,
|
||||
status: null,
|
||||
progressPercentage: null,
|
||||
message: null,
|
||||
createdAt: null,
|
||||
updatedAt: null,
|
||||
completedAt: null,
|
||||
metadata: {}
|
||||
};
|
||||
}
|
||||
|
||||
private showMessage(severity: 'success' | 'info' | 'warn' | 'error', summary: string, detail: string): void {
|
||||
this.messageService.add({
|
||||
severity,
|
||||
summary,
|
||||
detail
|
||||
});
|
||||
}
|
||||
|
||||
protected readonly TaskType = TaskType;
|
||||
protected readonly MetadataReplaceMode = MetadataReplaceMode;
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
import {inject, Injectable} from '@angular/core';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {BehaviorSubject, Observable} from 'rxjs';
|
||||
import {API_CONFIG} from '../../config/api-config';
|
||||
|
||||
export enum TaskType {
|
||||
CLEAR_CBX_CACHE = 'CLEAR_CBX_CACHE',
|
||||
CLEAR_PDF_CACHE = 'CLEAR_PDF_CACHE',
|
||||
RE_SCAN_LIBRARY = 'RE_SCAN_LIBRARY'
|
||||
}
|
||||
|
||||
export const TASK_TYPE_CONFIG: Record<TaskType, { parallel: boolean; async: boolean }> = {
|
||||
[TaskType.CLEAR_CBX_CACHE]: {parallel: false, async: false},
|
||||
[TaskType.CLEAR_PDF_CACHE]: {parallel: false, async: false},
|
||||
[TaskType.RE_SCAN_LIBRARY]: {parallel: false, async: true}
|
||||
};
|
||||
|
||||
export enum MetadataReplaceMode {
|
||||
REPLACE_ALL = 'REPLACE_ALL',
|
||||
REPLACE_MISSING = 'REPLACE_MISSING'
|
||||
}
|
||||
|
||||
export interface LibraryRescanOptions {
|
||||
metadataReplaceMode?: MetadataReplaceMode;
|
||||
}
|
||||
|
||||
export interface TaskCreateRequest {
|
||||
taskType: TaskType;
|
||||
options?: LibraryRescanOptions | null;
|
||||
}
|
||||
|
||||
export interface TaskCreateResponse {
|
||||
id?: string;
|
||||
type: string;
|
||||
status: TaskStatus;
|
||||
message?: string;
|
||||
createdAt?: string;
|
||||
}
|
||||
|
||||
export interface TaskStatusResponse {
|
||||
tasks: Task[];
|
||||
}
|
||||
|
||||
export enum TaskStatus {
|
||||
ACCEPTED = 'ACCEPTED',
|
||||
IN_PROGRESS = 'IN_PROGRESS',
|
||||
COMPLETED = 'COMPLETED',
|
||||
FAILED = 'FAILED',
|
||||
CANCELLED = 'CANCELLED',
|
||||
PENDING = 'PENDING'
|
||||
}
|
||||
|
||||
export interface TaskMetadata {
|
||||
currentCacheSizeBytes?: number;
|
||||
currentCacheSize?: string;
|
||||
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
export interface Task {
|
||||
id: string | null;
|
||||
type: string;
|
||||
status: string | null;
|
||||
progressPercentage: number | null;
|
||||
message: string | null;
|
||||
createdAt: string | null;
|
||||
updatedAt: string | null;
|
||||
completedAt: string | null;
|
||||
metadata: TaskMetadata;
|
||||
}
|
||||
|
||||
export interface TaskCancelResponse {
|
||||
taskId: string;
|
||||
cancelled: boolean;
|
||||
message: string;
|
||||
}
|
||||
|
||||
export interface TaskProgressPayload {
|
||||
taskId: string;
|
||||
taskType: string;
|
||||
message: string;
|
||||
progress: number; // 0-100 percentage
|
||||
taskStatus: TaskStatus;
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class TaskService {
|
||||
private http = inject(HttpClient);
|
||||
private readonly baseUrl = `${API_CONFIG.BASE_URL}/api/v2/tasks`;
|
||||
|
||||
private taskProgressSubject = new BehaviorSubject<TaskProgressPayload | null>(null);
|
||||
public taskProgress$ = this.taskProgressSubject.asObservable();
|
||||
|
||||
startTask(request: TaskCreateRequest): Observable<TaskCreateResponse> {
|
||||
return this.http.post<TaskCreateResponse>(this.baseUrl, request);
|
||||
}
|
||||
|
||||
getLatestTasksForEachType(): Observable<TaskStatusResponse> {
|
||||
return this.http.get<TaskStatusResponse>(`${this.baseUrl}/latest`);
|
||||
}
|
||||
|
||||
cancelTask(taskId: string): Observable<TaskCancelResponse> {
|
||||
return this.http.delete<TaskCancelResponse>(`${this.baseUrl}/${taskId}`);
|
||||
}
|
||||
|
||||
handleTaskProgress(progress: TaskProgressPayload): void {
|
||||
this.taskProgressSubject.next(progress);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user