feat(bookdrop): add full pagination support with select-all and metadata caching
- Implemented backend pagination for Bookdrop file review - Updated finalizeImport logic to support select-all with excluded IDs - Handled partial metadata submission from frontend - Refactored chunk processing and logging for clarity - Enhanced frontend Bookdrop UI with paginated selection, metadata sync, and virtual scroll compatibility - Improved UX for bulk finalize and discard actions
This commit is contained in:
committed by
Aditya Chandel
parent
6fb458dc33
commit
f69110c164
+1
-1
@@ -1,5 +1,5 @@
|
||||
@if (fetchedMetadata) {
|
||||
<form [formGroup]="metadataForm" class="flex flex-col h-[30rem] w-full">
|
||||
<form [formGroup]="metadataForm" class="flex flex-col h-[35rem] w-full">
|
||||
<div class="flex-grow overflow-auto">
|
||||
<div class="relative flex items-center justify-between pb-3">
|
||||
<div class="absolute left-1/2 transform -translate-x-1/2 flex items-center pl-24">
|
||||
|
||||
+105
-70
@@ -10,28 +10,30 @@
|
||||
</div>
|
||||
|
||||
@if (loading) {
|
||||
|
||||
<div class="absolute inset-0 flex items-center justify-center z-50 rounded-xl">
|
||||
<div class="flex flex-col items-center space-y-3">
|
||||
<p-progressSpinner styleClass="w-8 h-8" strokeWidth="4"/>
|
||||
<span class="text-gray-300">
|
||||
Loading Bookdrop files. Please wait...
|
||||
</span>
|
||||
<span class="text-gray-300">Loading Bookdrop files. Please wait...</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
} @else {
|
||||
|
||||
<div class="px-6 pb-2">
|
||||
@if (saving) {
|
||||
<div class="absolute inset-0 bg-black bg-opacity-50 flex flex-col items-center justify-center z-50 rounded-xl space-y-3">
|
||||
<p-progressSpinner styleClass="w-8 h-8" strokeWidth="4"/>
|
||||
<div class="bg-gray-900/90 px-4 py-2 rounded-md">
|
||||
<span class="text-sm text-gray-200 text-center">
|
||||
Organizing and moving files to their designated libraries. Please wait...
|
||||
</span>
|
||||
<span class="text-sm text-gray-200 text-center">
|
||||
Organizing and moving files to their designated libraries. Please wait...
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (bookdropFileUis.length !== 0) {
|
||||
|
||||
<div class="flex gap-2 items-center px-1 pb-4 w-full">
|
||||
<label for="uploadPatternInput" class="text-sm text-gray-300 font-medium">File Naming Pattern:</label>
|
||||
<input
|
||||
@@ -42,17 +44,16 @@
|
||||
type="text"
|
||||
pInputText
|
||||
[(ngModel)]="uploadPattern"
|
||||
placeholder="e.g., {title} - {authors}"
|
||||
/>
|
||||
placeholder="e.g., {title} - {authors}"/>
|
||||
<i
|
||||
class="pi pi-info-circle text-blue-500 cursor-help"
|
||||
pTooltip="Sets the filename pattern used when moving files from bookdrop folder to the library, using metadata placeholders like {title}, {authors}, etc."
|
||||
tooltipPosition="top"
|
||||
style="font-size: 1rem; margin-left: 0.25rem;"
|
||||
></i>
|
||||
style="font-size: 1rem; margin-left: 0.25rem;"></i>
|
||||
</div>
|
||||
|
||||
<div class="flex justify-between items-center gap-4 px-1">
|
||||
|
||||
<div class="flex gap-4 items-center">
|
||||
<span class="text-sm text-gray-300 font-medium">Library for All Files:</span>
|
||||
<p-select
|
||||
@@ -109,6 +110,7 @@
|
||||
pTooltip="For all files, replace current metadata with fetched metadata, excluding cover images"
|
||||
tooltipPosition="top">
|
||||
</p-button>
|
||||
|
||||
<p-button
|
||||
size="small"
|
||||
outlined
|
||||
@@ -123,6 +125,7 @@
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="flex-1 overflow-y-auto px-6 space-y-2 pb-4">
|
||||
@if (bookdropFileUis.length === 0) {
|
||||
<div class="h-full w-full flex items-center justify-center text-gray-400 italic py-8">
|
||||
@@ -130,68 +133,60 @@
|
||||
</div>
|
||||
} @else {
|
||||
@for (file of bookdropFileUis; track file) {
|
||||
|
||||
<div class="flex flex-col">
|
||||
<div class="flex items-center gap-4 custom-border rounded-xl px-4 py-2">
|
||||
|
||||
@if (file.file.fetchedMetadata) {
|
||||
<i
|
||||
class="pi pi-circle-fill"
|
||||
style="color: green; font-size: 0.75rem"
|
||||
pTooltip="Fetched metadata is available."
|
||||
tooltipPosition="top">
|
||||
</i>
|
||||
} @else {
|
||||
<i
|
||||
class="pi pi-circle-fill"
|
||||
style="color: darkorange; font-size: 0.75rem"
|
||||
pTooltip="No fetched metadata available."
|
||||
tooltipPosition="top">
|
||||
</i>
|
||||
}
|
||||
<p-checkbox
|
||||
[binary]="true"
|
||||
[(ngModel)]="file.selected"
|
||||
(ngModelChange)="toggleFileSelection(file.file.id, $event)">
|
||||
</p-checkbox>
|
||||
|
||||
<i
|
||||
class="pi pi-circle-fill"
|
||||
[ngStyle]="{'color': file.file.fetchedMetadata ? 'green' : 'darkorange'}"
|
||||
style="font-size: 0.75rem"
|
||||
pTooltip="{{file.file.fetchedMetadata ? 'Fetched metadata is available.' : 'No fetched metadata available.'}}"
|
||||
tooltipPosition="top">
|
||||
</i>
|
||||
|
||||
@if (file.metadataForm.get('thumbnailUrl')?.value) {
|
||||
<img
|
||||
[src]="file.metadataForm.get('thumbnailUrl')?.value"
|
||||
alt="Cover"
|
||||
title="Original cover"
|
||||
(click)="file.showDetails = !file.showDetails"
|
||||
class="w-6 h-8 flex-shrink-0 rounded-sm object-cover cursor-pointer transition-transform duration-200 hover:scale-105 hover:shadow-md"
|
||||
/>
|
||||
class="w-6 h-8 rounded-sm object-cover cursor-pointer hover:scale-105 hover:shadow-md transition-transform duration-200"
|
||||
(click)="file.showDetails = !file.showDetails"/>
|
||||
}
|
||||
|
||||
@if (file.file.fetchedMetadata?.thumbnailUrl) {
|
||||
<img
|
||||
[src]="file.file.fetchedMetadata?.thumbnailUrl"
|
||||
alt="Cover"
|
||||
alt="Fetched Cover"
|
||||
title="Fetched cover"
|
||||
(click)="file.showDetails = !file.showDetails"
|
||||
class="w-6 h-8 flex-shrink-0 rounded-sm object-cover cursor-pointer transition-transform duration-200 hover:scale-105 hover:shadow-md"
|
||||
/>
|
||||
class="w-6 h-8 rounded-sm object-cover cursor-pointer hover:scale-105 hover:shadow-md transition-transform duration-200"
|
||||
(click)="file.showDetails = !file.showDetails"/>
|
||||
}
|
||||
|
||||
<div class="flex-1 font-medium text-sm truncate" (click)="file.showDetails = !file.showDetails">
|
||||
{{ file.file.fileName }}
|
||||
</div>
|
||||
|
||||
@if (copiedFlags[file.file.id]) {
|
||||
<i
|
||||
class="pi pi-check-circle text-green-500"
|
||||
pTooltip="Fetched metadata has been applied."
|
||||
tooltipPosition="top">
|
||||
</i>
|
||||
} @else if (!file.file.fetchedMetadata) {
|
||||
<i
|
||||
class="pi pi-check-circle text-blue-500"
|
||||
pTooltip="No fetched metadata available. Original metadata will used."
|
||||
tooltipPosition="top">
|
||||
</i>
|
||||
} @else {
|
||||
<i
|
||||
class="pi pi-exclamation-triangle text-red-500"
|
||||
pTooltip="Fetched metadata hasn’t been applied yet. You can open the metadata picker using the dropdown on the right, or skip and keep the original metadata."
|
||||
tooltipPosition="top">
|
||||
</i>
|
||||
}
|
||||
<i
|
||||
class="pi"
|
||||
[ngClass]="{
|
||||
'pi-check-circle text-green-500': copiedFlags[file.file.id],
|
||||
'pi-check-circle text-blue-500': !file.file.fetchedMetadata,
|
||||
'pi-exclamation-triangle text-red-500': file.file.fetchedMetadata && !copiedFlags[file.file.id]
|
||||
}"
|
||||
[pTooltip]="copiedFlags[file.file.id]
|
||||
? 'Fetched metadata has been applied.'
|
||||
: !file.file.fetchedMetadata
|
||||
? 'No fetched metadata available. Original metadata will be used.'
|
||||
: 'Fetched metadata hasn’t been applied yet. Open metadata picker to review.'"
|
||||
tooltipPosition="top">
|
||||
</i>
|
||||
|
||||
<p-select
|
||||
size="small"
|
||||
@@ -223,12 +218,9 @@
|
||||
</p-button>
|
||||
</div>
|
||||
|
||||
|
||||
@if (file.showDetails) {
|
||||
<app-bookdrop-file-metadata-picker-component
|
||||
class="px-12 py-8 custom-border1"
|
||||
style="transition: opacity 0.3s ease"
|
||||
#metadataPicker
|
||||
[originalMetadata]="file.file.originalMetadata"
|
||||
[fetchedMetadata]="file.file.fetchedMetadata!"
|
||||
[metadataForm]="file.metadataForm"
|
||||
@@ -242,29 +234,72 @@
|
||||
}
|
||||
}
|
||||
</div>
|
||||
|
||||
<p-divider></p-divider>
|
||||
<div class="pb-4 px-6 gap-4 flex justify-end">
|
||||
@if (bookdropFileUis.length !== 0) {
|
||||
|
||||
<div class="pb-2 px-4 flex items-center justify-between gap-4">
|
||||
|
||||
<div class="flex gap-4 items-center min-w-[160px] justify-start">
|
||||
@if (bookdropFileUis.length > 0) {
|
||||
<p-button
|
||||
label="Select All"
|
||||
icon="pi pi-check-square"
|
||||
severity="info"
|
||||
(click)="selectAll(true)"
|
||||
outlined
|
||||
pTooltip="Select all files across all pages you have navigated"
|
||||
tooltipPosition="top">
|
||||
</p-button>
|
||||
|
||||
<p-button
|
||||
label="Clear All"
|
||||
icon="pi pi-times-circle"
|
||||
severity="warn"
|
||||
(click)="selectAll(false)"
|
||||
outlined
|
||||
pTooltip="Deselect all files across all pages you have navigated"
|
||||
tooltipPosition="top">
|
||||
</p-button>
|
||||
} @else {
|
||||
<div class="min-w-[160px]"></div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<!-- Center container: paginator, flex-grow and centered -->
|
||||
<div class="flex-grow flex justify-center">
|
||||
<p-paginator
|
||||
[rows]="pageSize"
|
||||
[totalRecords]="totalRecords"
|
||||
[first]="currentPage * pageSize"
|
||||
(onPageChange)="loadPage($event.page ?? 0)"
|
||||
[showCurrentPageReport]="true"
|
||||
currentPageReportTemplate="Showing files {first} - {last} of {totalRecords}">
|
||||
</p-paginator>
|
||||
</div>
|
||||
|
||||
<!-- Right container: fixed width, right aligned -->
|
||||
<div class="flex gap-4 items-center min-w-[200px] justify-end">
|
||||
<p-button
|
||||
label="Delete Files"
|
||||
[label]="'Delete ' + selectedCount + ' File' + (selectedCount !== 1 ? 's' : '')"
|
||||
icon="pi pi-times"
|
||||
severity="danger"
|
||||
[disabled]="!hasSelectedFiles"
|
||||
outlined
|
||||
pTooltip="Permanently delete all Bookdrop files and discard any changes"
|
||||
tooltipPosition="top"
|
||||
(click)="confirmDelete()">
|
||||
(click)="confirmDelete()"
|
||||
pTooltip="Permanently delete selected Bookdrop files and discard any changes"
|
||||
tooltipPosition="top">
|
||||
</p-button>
|
||||
}
|
||||
<p-button
|
||||
[label]="saving ? ('Finalizing ' + selectedCount + ' File' + (selectedCount !== 1 ? 's' : '') + '...') : ('Finalize ' + selectedCount + ' File' + (selectedCount !== 1 ? 's' : ''))"
|
||||
[icon]="saving ? 'pi pi-spin pi-spinner' : 'pi pi-save'"
|
||||
severity="success"
|
||||
outlined
|
||||
[disabled]="!canFinalize || saving"
|
||||
(click)="confirmFinalize()"
|
||||
pTooltip="Move selected files into the chosen library and subpath">
|
||||
</p-button>
|
||||
</div>
|
||||
|
||||
<p-button
|
||||
[label]="saving ? 'Finalize Imports...' : 'Finalize Imports'"
|
||||
[icon]="saving ? 'pi pi-spin pi-spinner' : 'pi pi-save'"
|
||||
severity="success"
|
||||
outlined
|
||||
pTooltip="This will move all staged files into the selected library and subpath."
|
||||
(click)="confirmFinalize()"
|
||||
[disabled]="!canFinalize || saving">
|
||||
</p-button>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
+278
-113
@@ -25,6 +25,9 @@ import {BookdropFinalizeResultDialogComponent} from '../bookdrop-finalize-result
|
||||
import {DialogService} from 'primeng/dynamicdialog';
|
||||
import {BookMetadata} from '../../book/model/book.model';
|
||||
import {UrlHelperService} from '../../utilities/service/url-helper.service';
|
||||
import {Checkbox} from 'primeng/checkbox';
|
||||
import {NgClass, NgStyle} from '@angular/common';
|
||||
import {Paginator} from 'primeng/paginator';
|
||||
|
||||
export interface BookdropFileUI {
|
||||
file: BookdropFile;
|
||||
@@ -53,7 +56,10 @@ export interface BookdropFileUI {
|
||||
Tooltip,
|
||||
Divider,
|
||||
InputText,
|
||||
|
||||
Checkbox,
|
||||
NgStyle,
|
||||
NgClass,
|
||||
Paginator,
|
||||
],
|
||||
})
|
||||
export class BookdropFileReviewComponent implements OnInit {
|
||||
@@ -64,28 +70,32 @@ export class BookdropFileReviewComponent implements OnInit {
|
||||
private readonly dialogService = inject(DialogService);
|
||||
private readonly appSettingsService = inject(AppSettingsService);
|
||||
private readonly messageService = inject(MessageService);
|
||||
private readonly urlHelper = inject(UrlHelperService);
|
||||
|
||||
@ViewChildren('metadataPicker') metadataPickers!: QueryList<BookdropFileMetadataPickerComponent>;
|
||||
|
||||
appSettings$: Observable<AppSettings | null> = this.appSettingsService.appSettings$;
|
||||
|
||||
uploadPattern = '';
|
||||
defaultLibraryId: string | null = null;
|
||||
defaultPathId: string | null = null;
|
||||
bookdropFileUis: BookdropFileUI[] = [];
|
||||
libraries: Library[] = [];
|
||||
bookdropFileUis: BookdropFileUI[] = [];
|
||||
fileUiCache: Record<number, BookdropFileUI> = {};
|
||||
copiedFlags: Record<number, boolean> = {};
|
||||
loading = true;
|
||||
saving = false;
|
||||
appSettings$: Observable<AppSettings | null> = this.appSettingsService.appSettings$;
|
||||
|
||||
protected urlHelper = inject(UrlHelperService);
|
||||
pageSize = 50;
|
||||
totalRecords = 0;
|
||||
currentPage = 0;
|
||||
|
||||
selectAllAcrossPages = false;
|
||||
excludedFiles = new Set<number>();
|
||||
|
||||
ngOnInit(): void {
|
||||
this.bookdropFileService.getPendingFiles()
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe(files => {
|
||||
this.bookdropFileUis = files.map(file => this.createFileUI(file));
|
||||
this.loading = false;
|
||||
});
|
||||
this.loading = true;
|
||||
this.loadPage(0);
|
||||
|
||||
this.libraryService.libraryState$
|
||||
.pipe(filter(state => !!state?.loaded), take(1))
|
||||
@@ -101,14 +111,82 @@ export class BookdropFileReviewComponent implements OnInit {
|
||||
}
|
||||
|
||||
get libraryOptions() {
|
||||
if (!this.libraries) return [];
|
||||
return this.libraries.map(lib => ({label: lib.name, value: String(lib.id ?? '')}));
|
||||
}
|
||||
|
||||
get selectedLibraryPaths() {
|
||||
if (!this.libraries) return [];
|
||||
const selectedLibrary = this.libraries.find(lib => String(lib.id) === this.defaultLibraryId);
|
||||
return selectedLibrary?.paths.map(path => ({label: path.path, value: String(path.id ?? '')})) ?? [];
|
||||
}
|
||||
|
||||
get canApplyDefaults(): boolean {
|
||||
return !!(this.defaultLibraryId && this.defaultPathId);
|
||||
}
|
||||
|
||||
get canFinalize(): boolean {
|
||||
if (this.selectAllAcrossPages) {
|
||||
return (this.totalRecords - this.excludedFiles.size) > 0 && this.areAllSelectedHaveLibraryAndPath();
|
||||
}
|
||||
const selectedFiles = this.bookdropFileUis.filter(f => f.selected);
|
||||
if (selectedFiles.length === 0) return false;
|
||||
return selectedFiles.every(f => f.selectedLibraryId && f.selectedPathId);
|
||||
}
|
||||
|
||||
get hasSelectedFiles(): boolean {
|
||||
if (this.selectAllAcrossPages) {
|
||||
return this.totalRecords > this.excludedFiles.size;
|
||||
} else {
|
||||
return Object.values(this.fileUiCache).some(file => file.selected);
|
||||
}
|
||||
}
|
||||
|
||||
get selectedCount(): number {
|
||||
if (this.selectAllAcrossPages) {
|
||||
return this.totalRecords - this.excludedFiles.size;
|
||||
} else {
|
||||
return Object.values(this.fileUiCache).filter(file => file.selected).length;
|
||||
}
|
||||
}
|
||||
|
||||
loadPage(page: number): void {
|
||||
this.bookdropFileService.getPendingFiles(page, this.pageSize)
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe({
|
||||
next: response => {
|
||||
this.bookdropFileUis = response.content.map(file => {
|
||||
const cached = this.fileUiCache[file.id];
|
||||
if (cached) {
|
||||
cached.file = file;
|
||||
return cached;
|
||||
} else {
|
||||
const fresh = this.createFileUI(file);
|
||||
|
||||
if (this.defaultLibraryId) {
|
||||
const selectedLib = this.libraries.find(l => String(l.id) === this.defaultLibraryId);
|
||||
const selectedPaths = selectedLib?.paths ?? [];
|
||||
fresh.selectedLibraryId = this.defaultLibraryId;
|
||||
fresh.availablePaths = selectedPaths.map(p => ({id: String(p.id ?? ''), name: p.path}));
|
||||
fresh.selectedPathId = this.defaultPathId ?? null;
|
||||
}
|
||||
|
||||
this.fileUiCache[file.id] = fresh;
|
||||
return fresh;
|
||||
}
|
||||
});
|
||||
this.totalRecords = response.totalElements;
|
||||
this.currentPage = page;
|
||||
this.loading = false;
|
||||
this.syncCurrentPageSelection();
|
||||
},
|
||||
error: err => {
|
||||
console.error('Error loading files:', err);
|
||||
this.loading = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onLibraryChange(file: BookdropFileUI): void {
|
||||
const lib = this.libraries.find(l => String(l.id) === file.selectedLibraryId);
|
||||
file.availablePaths = lib?.paths.map(p => ({id: String(p.id ?? ''), name: p.path})) ?? [];
|
||||
@@ -120,27 +198,23 @@ export class BookdropFileReviewComponent implements OnInit {
|
||||
}
|
||||
|
||||
applyDefaultsToAll(): void {
|
||||
if (!this.defaultLibraryId) return;
|
||||
if (!this.defaultLibraryId || !this.libraries) return;
|
||||
|
||||
const selectedLib = this.libraries.find(l => String(l.id) === this.defaultLibraryId);
|
||||
const selectedPaths = selectedLib?.paths ?? [];
|
||||
|
||||
for (const file of this.bookdropFileUis) {
|
||||
Object.values(this.fileUiCache).forEach(file => {
|
||||
file.selectedLibraryId = this.defaultLibraryId;
|
||||
file.availablePaths = selectedPaths.map(path => ({id: String(path.id), name: path.path}));
|
||||
file.selectedPathId = this.defaultPathId ?? null;
|
||||
}
|
||||
}
|
||||
|
||||
get canApplyDefaults(): boolean {
|
||||
return !!(this.defaultLibraryId && this.defaultPathId);
|
||||
});
|
||||
}
|
||||
|
||||
copyAll(includeThumbnail: boolean): void {
|
||||
for (const fileUi of this.bookdropFileUis) {
|
||||
Object.values(this.fileUiCache).forEach(fileUi => {
|
||||
const fetched = fileUi.file.fetchedMetadata;
|
||||
const form = fileUi.metadataForm;
|
||||
if (!fetched) continue;
|
||||
if (!fetched) return;
|
||||
for (const key of Object.keys(fetched)) {
|
||||
if (!includeThumbnail && key === 'thumbnailUrl') continue;
|
||||
const value = fetched[key as keyof typeof fetched];
|
||||
@@ -150,11 +224,11 @@ export class BookdropFileReviewComponent implements OnInit {
|
||||
}
|
||||
}
|
||||
this.onMetadataCopied(fileUi.file.id, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
resetAll(): void {
|
||||
for (const fileUi of this.bookdropFileUis) {
|
||||
Object.values(this.fileUiCache).forEach(fileUi => {
|
||||
const original = fileUi.file.originalMetadata;
|
||||
fileUi.metadataForm.patchValue({
|
||||
title: original.title || null,
|
||||
@@ -163,40 +237,75 @@ export class BookdropFileReviewComponent implements OnInit {
|
||||
categories: [...(original.categories ?? [])].sort(),
|
||||
publisher: original.publisher || null,
|
||||
publishedDate: original.publishedDate || null,
|
||||
isbn10: original.isbn10 || null,
|
||||
isbn13: original.isbn13 || null,
|
||||
description: original.description || null,
|
||||
pageCount: original.pageCount || null,
|
||||
language: original.language || null,
|
||||
asin: original.asin || null,
|
||||
amazonRating: original.amazonRating || null,
|
||||
amazonReviewCount: original.amazonReviewCount || null,
|
||||
goodreadsId: original.goodreadsId || null,
|
||||
goodreadsRating: original.goodreadsRating || null,
|
||||
goodreadsReviewCount: original.goodreadsReviewCount || null,
|
||||
hardcoverId: original.hardcoverId || null,
|
||||
hardcoverRating: original.hardcoverRating || null,
|
||||
hardcoverReviewCount: original.hardcoverReviewCount || null,
|
||||
googleId: original.googleId || null,
|
||||
seriesName: original.seriesName || null,
|
||||
seriesNumber: original.seriesNumber || null,
|
||||
seriesTotal: original.seriesTotal || null,
|
||||
isbn10: original.isbn10 ?? null,
|
||||
isbn13: original.isbn13 ?? null,
|
||||
description: original.description ?? null,
|
||||
pageCount: original.pageCount ?? null,
|
||||
language: original.language ?? null,
|
||||
asin: original.asin ?? null,
|
||||
amazonRating: original.amazonRating ?? null,
|
||||
amazonReviewCount: original.amazonReviewCount ?? null,
|
||||
goodreadsId: original.goodreadsId ?? null,
|
||||
goodreadsRating: original.goodreadsRating ?? null,
|
||||
goodreadsReviewCount: original.goodreadsReviewCount ?? null,
|
||||
hardcoverId: original.hardcoverId ?? null,
|
||||
hardcoverRating: original.hardcoverRating ?? null,
|
||||
hardcoverReviewCount: original.hardcoverReviewCount ?? null,
|
||||
googleId: original.googleId ?? null,
|
||||
seriesName: original.seriesName ?? null,
|
||||
seriesNumber: original.seriesNumber ?? null,
|
||||
seriesTotal: original.seriesTotal ?? null,
|
||||
thumbnailUrl: this.urlHelper.getBookdropCoverUrl(fileUi.file.id),
|
||||
});
|
||||
fileUi.copiedFields = {};
|
||||
fileUi.savedFields = {};
|
||||
}
|
||||
});
|
||||
this.copiedFlags = {};
|
||||
}
|
||||
|
||||
get canFinalize(): boolean {
|
||||
return this.bookdropFileUis.length > 0 &&
|
||||
this.bookdropFileUis.every(file => file.selectedLibraryId && file.selectedPathId);
|
||||
selectAll(selected: boolean): void {
|
||||
if (selected) {
|
||||
this.selectAllAcrossPages = true;
|
||||
this.excludedFiles.clear();
|
||||
Object.values(this.fileUiCache).forEach(file => file.selected = true);
|
||||
this.bookdropFileUis.forEach(file => file.selected = true);
|
||||
} else {
|
||||
this.selectAllAcrossPages = false;
|
||||
this.excludedFiles.clear();
|
||||
Object.values(this.fileUiCache).forEach(file => file.selected = false);
|
||||
this.bookdropFileUis.forEach(file => file.selected = false);
|
||||
}
|
||||
}
|
||||
|
||||
toggleFileSelection(fileId: number, selected: boolean): void {
|
||||
if (this.selectAllAcrossPages) {
|
||||
if (!selected) {
|
||||
this.excludedFiles.add(fileId);
|
||||
} else {
|
||||
this.excludedFiles.delete(fileId);
|
||||
}
|
||||
const cachedFile = this.fileUiCache[fileId];
|
||||
if (cachedFile) cachedFile.selected = selected;
|
||||
} else {
|
||||
const cachedFile = this.fileUiCache[fileId];
|
||||
if (cachedFile) cachedFile.selected = selected;
|
||||
}
|
||||
this.syncCurrentPageSelection();
|
||||
}
|
||||
|
||||
confirmFinalize(): void {
|
||||
const selectedCount = this.selectedCount;
|
||||
if (selectedCount === 0) {
|
||||
this.messageService.add({
|
||||
severity: 'warn',
|
||||
summary: 'No files selected',
|
||||
detail: 'Please select files to finalize.',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
this.confirmationService.confirm({
|
||||
message: 'Are you sure you want to finalize the import?',
|
||||
message: `Are you sure you want to finalize the import of ${selectedCount} file${selectedCount !== 1 ? 's' : ''}?`,
|
||||
header: 'Confirm Finalize',
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
acceptLabel: 'Yes',
|
||||
@@ -205,9 +314,123 @@ export class BookdropFileReviewComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
confirmDelete(): void {
|
||||
const selectedCount = this.selectedCount;
|
||||
if (selectedCount === 0) {
|
||||
this.messageService.add({
|
||||
severity: 'warn',
|
||||
summary: 'No files selected',
|
||||
detail: 'Please select files to delete.',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
this.confirmationService.confirm({
|
||||
message: `Are you sure you want to delete ${selectedCount} selected Bookdrop file${selectedCount !== 1 ? 's' : ''}? This action cannot be undone.`,
|
||||
header: 'Confirm Delete',
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
accept: () => {
|
||||
const payload: any = {
|
||||
selectAll: this.selectAllAcrossPages,
|
||||
};
|
||||
|
||||
if (this.selectAllAcrossPages) {
|
||||
payload.excludedIds = Array.from(this.excludedFiles);
|
||||
} else {
|
||||
payload.selectedIds = Object.values(this.fileUiCache)
|
||||
.filter(file => file.selected)
|
||||
.map(file => file.file.id);
|
||||
}
|
||||
|
||||
this.bookdropFileService.discardFiles(payload).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Files Deleted',
|
||||
detail: 'Selected Bookdrop files were deleted successfully.',
|
||||
});
|
||||
|
||||
const toDelete = Object.values(this.fileUiCache).filter(file => {
|
||||
return this.selectAllAcrossPages
|
||||
? !this.excludedFiles.has(file.file.id)
|
||||
: file.selected;
|
||||
});
|
||||
toDelete.forEach(file => delete this.fileUiCache[file.file.id]);
|
||||
|
||||
this.selectAllAcrossPages = false;
|
||||
this.excludedFiles.clear();
|
||||
this.loadPage(this.currentPage);
|
||||
},
|
||||
error: (err) => {
|
||||
console.error('Error deleting files:', err);
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Delete Failed',
|
||||
detail: 'An error occurred while deleting Bookdrop files.',
|
||||
});
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
private areAllSelectedHaveLibraryAndPath(): boolean {
|
||||
return Object.values(this.fileUiCache).every(file => {
|
||||
if (this.selectAllAcrossPages) {
|
||||
if (this.excludedFiles.has(file.file.id)) return true;
|
||||
return file.selectedLibraryId != null && file.selectedPathId != null;
|
||||
} else {
|
||||
if (!file.selected) return true;
|
||||
return file.selectedLibraryId != null && file.selectedPathId != null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private syncCurrentPageSelection(): void {
|
||||
if (this.selectAllAcrossPages) {
|
||||
this.bookdropFileUis.forEach(fileUi => {
|
||||
fileUi.selected = !this.excludedFiles.has(fileUi.file.id);
|
||||
const cachedFile = this.fileUiCache[fileUi.file.id];
|
||||
if (cachedFile) cachedFile.selected = fileUi.selected;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private finalizeImport(): void {
|
||||
this.saving = true;
|
||||
const payload = this.buildFinalizePayload();
|
||||
|
||||
const selectedFiles = Object.values(this.fileUiCache).filter(file => {
|
||||
if (this.selectAllAcrossPages) {
|
||||
return !this.excludedFiles.has(file.file.id);
|
||||
} else {
|
||||
return file.selected;
|
||||
}
|
||||
});
|
||||
|
||||
const files = selectedFiles.map(fileUi => {
|
||||
const rawMetadata = fileUi.metadataForm.value;
|
||||
const metadata = {...rawMetadata};
|
||||
|
||||
if (metadata.thumbnailUrl?.includes('/api/bookdrop/')) {
|
||||
delete metadata.thumbnailUrl;
|
||||
}
|
||||
|
||||
return {
|
||||
fileId: fileUi.file.id,
|
||||
libraryId: Number(fileUi.selectedLibraryId),
|
||||
pathId: Number(fileUi.selectedPathId),
|
||||
metadata,
|
||||
};
|
||||
});
|
||||
|
||||
const payload: BookdropFinalizePayload = {
|
||||
uploadPattern: this.uploadPattern,
|
||||
selectAll: this.selectAllAcrossPages,
|
||||
excludedIds: this.selectAllAcrossPages ? Array.from(this.excludedFiles) : undefined,
|
||||
defaultLibraryId: this.defaultLibraryId ? Number(this.defaultLibraryId) : undefined,
|
||||
defaultPathId: this.defaultPathId ? Number(this.defaultPathId) : undefined,
|
||||
files,
|
||||
};
|
||||
|
||||
this.bookdropFileService.finalizeImport(payload).subscribe({
|
||||
next: (result: BookdropFinalizeResult) => {
|
||||
@@ -224,12 +447,18 @@ export class BookdropFileReviewComponent implements OnInit {
|
||||
modal: true,
|
||||
closable: true,
|
||||
closeOnEscape: true,
|
||||
data: {
|
||||
results: result.results
|
||||
}
|
||||
data: {results: result.results},
|
||||
});
|
||||
|
||||
this.reloadPendingFiles();
|
||||
const finalizedIds = new Set(files.map(f => f.fileId));
|
||||
Object.keys(this.fileUiCache).forEach(idStr => {
|
||||
const id = Number(idStr);
|
||||
if (finalizedIds.has(id)) delete this.fileUiCache[id];
|
||||
});
|
||||
|
||||
this.selectAllAcrossPages = false;
|
||||
this.excludedFiles.clear();
|
||||
this.loadPage(this.currentPage);
|
||||
},
|
||||
error: (err) => {
|
||||
console.error('Error finalizing import:', err);
|
||||
@@ -243,70 +472,6 @@ export class BookdropFileReviewComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
private buildFinalizePayload(): BookdropFinalizePayload {
|
||||
return {
|
||||
uploadPattern: this.uploadPattern,
|
||||
files: this.bookdropFileUis.map((fileUi, index) => {
|
||||
const rawMetadata = this.bookdropFileUis[index].metadataForm.value;
|
||||
const metadata = {...rawMetadata};
|
||||
if (metadata.thumbnailUrl?.includes('/api/bookdrop/')) {
|
||||
delete metadata.thumbnailUrl;
|
||||
}
|
||||
return {
|
||||
fileId: fileUi.file.id,
|
||||
libraryId: Number(fileUi.selectedLibraryId),
|
||||
pathId: Number(fileUi.selectedPathId),
|
||||
metadata,
|
||||
};
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
private reloadPendingFiles(): void {
|
||||
this.loading = true;
|
||||
this.bookdropFileService.getPendingFiles()
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe({
|
||||
next: files => {
|
||||
this.bookdropFileUis = files.map(file => this.createFileUI(file));
|
||||
this.loading = false;
|
||||
this.saving = false;
|
||||
},
|
||||
error: err => {
|
||||
console.error('Error loading pending files:', err);
|
||||
this.loading = false;
|
||||
this.saving = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
confirmDelete(): void {
|
||||
this.confirmationService.confirm({
|
||||
message: 'Are you sure you want to delete all Bookdrop files? This action cannot be undone.',
|
||||
header: 'Confirm Delete',
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
accept: () => {
|
||||
this.bookdropFileService.discardAllFile().subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Files Deleted',
|
||||
detail: 'All Bookdrop files were deleted successfully.',
|
||||
});
|
||||
this.reloadPendingFiles();
|
||||
},
|
||||
error: (err) => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Delete Failed',
|
||||
detail: 'An error occurred while deleting Bookdrop files.',
|
||||
});
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
private createMetadataForm(original: BookMetadata, bookdropFileId: number): FormGroup {
|
||||
return new FormGroup({
|
||||
title: new FormControl(original.title ?? ''),
|
||||
|
||||
@@ -12,7 +12,11 @@ export enum BookdropFileStatus {
|
||||
|
||||
export interface BookdropFinalizePayload {
|
||||
uploadPattern: string;
|
||||
files: {
|
||||
selectAll?: boolean;
|
||||
excludedIds?: number[];
|
||||
defaultLibraryId?: number;
|
||||
defaultPathId?: number;
|
||||
files?: {
|
||||
fileId: number;
|
||||
libraryId: number;
|
||||
pathId: number;
|
||||
@@ -43,22 +47,27 @@ export interface BookdropFinalizeResult {
|
||||
results: BookdropFileResult[];
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export interface Page<T> {
|
||||
content: T[];
|
||||
totalElements: number;
|
||||
totalPages: number;
|
||||
number: number;
|
||||
}
|
||||
|
||||
@Injectable({providedIn: 'root'})
|
||||
export class BookdropFileTaskService {
|
||||
private readonly url = `${API_CONFIG.BASE_URL}/api/bookdrop`;
|
||||
private http = inject(HttpClient);
|
||||
|
||||
getPendingFiles(): Observable<BookdropFile[]> {
|
||||
return this.http.get<BookdropFile[]>(`${this.url}/files?status=pending`);
|
||||
getPendingFiles(page: number = 0, size: number = 50): Observable<Page<BookdropFile>> {
|
||||
return this.http.get<Page<BookdropFile>>(`${this.url}/files?status=pending&page=${page}&size=${size}`);
|
||||
}
|
||||
|
||||
finalizeImport(payload: BookdropFinalizePayload): Observable<BookdropFinalizeResult> {
|
||||
return this.http.post<BookdropFinalizeResult>(`${this.url}/imports/finalize`, payload);
|
||||
}
|
||||
|
||||
discardAllFile(): Observable<void> {
|
||||
return this.http.delete<void>(`${this.url}/files`);
|
||||
discardFiles(payload: { selectAll: boolean; excludedIds?: number[]; selectedIds?: number[] }): Observable<void> {
|
||||
return this.http.post<void>(`${this.url}/files/discard`, payload);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user