Add ability to move books across libraries (#1210)
This commit is contained in:
@@ -73,7 +73,7 @@ export class BookDialogHelperService {
|
||||
});
|
||||
}
|
||||
|
||||
openMultibookMetadataEditerDialog(bookIds: Set<number>): DynamicDialogRef {
|
||||
openMultibookMetadataEditorDialog(bookIds: Set<number>): DynamicDialogRef {
|
||||
return this.dialogService.open(MultiBookMetadataEditorComponent, {
|
||||
header: 'Bulk Edit Metadata',
|
||||
showHeader: false,
|
||||
@@ -96,12 +96,16 @@ export class BookDialogHelperService {
|
||||
return this.dialogService.open(FileMoverComponent, {
|
||||
header: `Organize Book Files (${count} book${count !== 1 ? 's' : ''})`,
|
||||
showHeader: true,
|
||||
maximizable: true,
|
||||
modal: true,
|
||||
closable: true,
|
||||
closeOnEscape: false,
|
||||
dismissableMask: false,
|
||||
style: {
|
||||
width: '90vw'
|
||||
width: '85vw',
|
||||
height: '80vh',
|
||||
maxHeight: '95vh',
|
||||
maxWidth: '97.5vw'
|
||||
},
|
||||
data: {
|
||||
bookIds: selectedBooks
|
||||
|
||||
@@ -345,7 +345,7 @@
|
||||
icon="pi pi-arrows-h"
|
||||
severity="info"
|
||||
(click)="moveFiles()"
|
||||
pTooltip="Move Books"
|
||||
pTooltip="Organize Files"
|
||||
tooltipPosition="top">
|
||||
</p-button>
|
||||
}
|
||||
|
||||
@@ -558,7 +558,7 @@ export class BookBrowserComponent implements OnInit {
|
||||
}
|
||||
|
||||
multiBookEditMetadata(): void {
|
||||
this.dialogHelperService.openMultibookMetadataEditerDialog(this.selectedBooks);
|
||||
this.dialogHelperService.openMultibookMetadataEditorDialog(this.selectedBooks);
|
||||
}
|
||||
|
||||
moveFiles() {
|
||||
|
||||
@@ -26,6 +26,7 @@ import {take, takeUntil} from 'rxjs/operators';
|
||||
import {readStatusLabels} from '../book-filter/book-filter.component';
|
||||
import {ResetProgressTypes} from '../../../../shared/constants/reset-progress-type';
|
||||
import {ReadStatusHelper} from '../../../helpers/read-status.helper';
|
||||
import {BookDialogHelperService} from '../BookDialogHelperService';
|
||||
|
||||
@Component({
|
||||
selector: 'app-book-card',
|
||||
@@ -63,6 +64,7 @@ export class BookCardComponent implements OnInit, OnChanges, OnDestroy {
|
||||
private router = inject(Router);
|
||||
protected urlHelper = inject(UrlHelperService);
|
||||
private confirmationService = inject(ConfirmationService);
|
||||
private bookDialogHelperService = inject(BookDialogHelperService);
|
||||
|
||||
private userPermissions: any;
|
||||
private metadataCenterViewMode: 'route' | 'dialog' = 'route';
|
||||
@@ -370,6 +372,13 @@ export class BookCardComponent implements OnInit, OnChanges, OnDestroy {
|
||||
label: 'More Actions',
|
||||
icon: 'pi pi-ellipsis-h',
|
||||
items: [
|
||||
{
|
||||
label: 'Organize File',
|
||||
icon: 'pi pi-arrows-h',
|
||||
command: () => {
|
||||
this.bookDialogHelperService.openFileMoverDialog(new Set([this.book.id]));
|
||||
}
|
||||
},
|
||||
{
|
||||
label: 'Read Status',
|
||||
icon: 'pi pi-book',
|
||||
|
||||
+2
-2
@@ -456,7 +456,7 @@
|
||||
@if (userState.user!.permissions.canEditMetadata || userState.user!.permissions.admin) {
|
||||
@if (refreshMenuItems$ | async; as refreshItems) {
|
||||
<p-splitbutton
|
||||
[label]="isAutoFetching ? 'Fetching...' : 'Auto Fetch'"
|
||||
[label]="isAutoFetching ? 'Fetching...' : 'Fetch Metadata'"
|
||||
[icon]="isAutoFetching ? 'pi pi-spin pi-spinner' : 'pi pi-bolt'"
|
||||
[outlined]="true"
|
||||
[model]="refreshItems"
|
||||
@@ -470,7 +470,7 @@
|
||||
}
|
||||
@if (userState.user!.permissions.canDeleteBook || userState.user!.permissions.admin) {
|
||||
@if (otherItems$ | async; as otherItems) {
|
||||
<p-button icon="pi pi-ellipsis-v" outlined severity="danger" (click)="entitymenu.toggle($event)"></p-button>
|
||||
<p-button icon="pi pi-ellipsis-v" outlined severity="primary" (click)="entitymenu.toggle($event)"></p-button>
|
||||
<p-tieredMenu #entitymenu [model]="otherItems" [popup]="true" appendTo="body"></p-tieredMenu>
|
||||
}
|
||||
}
|
||||
|
||||
+15
-1
@@ -37,6 +37,7 @@ import {ProgressSpinner} from 'primeng/progressspinner';
|
||||
import {TieredMenu} from 'primeng/tieredmenu';
|
||||
import {AdditionalFileUploaderComponent} from '../../../book/components/additional-file-uploader/additional-file-uploader.component';
|
||||
import {Image} from 'primeng/image';
|
||||
import {BookDialogHelperService} from '../../../book/components/book-browser/BookDialogHelperService';
|
||||
|
||||
@Component({
|
||||
selector: 'app-metadata-viewer',
|
||||
@@ -58,6 +59,8 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
|
||||
protected urlHelper = inject(UrlHelperService);
|
||||
protected userService = inject(UserService);
|
||||
private confirmationService = inject(ConfirmationService);
|
||||
private bookDialogHelperService = inject(BookDialogHelperService);
|
||||
|
||||
private router = inject(Router);
|
||||
private destroyRef = inject(DestroyRef);
|
||||
private dialogRef?: DynamicDialogRef;
|
||||
@@ -112,7 +115,7 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
|
||||
filter((book): book is Book => book !== null),
|
||||
map((book): MenuItem[] => [
|
||||
{
|
||||
label: 'Granular Refresh',
|
||||
label: 'Advanced Fetch',
|
||||
icon: 'pi pi-database',
|
||||
command: () => {
|
||||
this.dialogService.open(MetadataFetchOptionsComponent, {
|
||||
@@ -200,6 +203,13 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
|
||||
});
|
||||
},
|
||||
},
|
||||
{
|
||||
label: 'Organize Files',
|
||||
icon: 'pi pi-arrows-h',
|
||||
command: () => {
|
||||
this.openFileMoverDialog(book.id);
|
||||
},
|
||||
},
|
||||
{
|
||||
label: 'Delete Book',
|
||||
icon: 'pi pi-trash',
|
||||
@@ -803,6 +813,10 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
|
||||
this.editDateFinished = null;
|
||||
}
|
||||
|
||||
openFileMoverDialog(bookId: number): void {
|
||||
this.bookDialogHelperService.openFileMoverDialog(new Set([bookId]));
|
||||
}
|
||||
|
||||
protected readonly ResetProgressTypes = ResetProgressTypes;
|
||||
protected readonly ReadStatus = ReadStatus;
|
||||
}
|
||||
|
||||
+39
-7
@@ -1,4 +1,4 @@
|
||||
<div class="p-fluid px-4 py-2 rounded-xl flex flex-col h-[800px]">
|
||||
<div class="p-fluid px-4 py-2 rounded-xl flex flex-col h-full">
|
||||
|
||||
<div class="px-4 mx-2 mb-4 py-3 rounded-lg border border-[var(--border-color)] transition-all">
|
||||
<p class="text-[var(--primary-color)] font-semibold mb-1">
|
||||
@@ -6,16 +6,16 @@
|
||||
</p>
|
||||
<div class="text-sm text-gray-300 space-y-3">
|
||||
<p>
|
||||
Your files will be automatically renamed and organized based on your library's naming rules.
|
||||
Check the preview below to see how your files will look, then click <span class="font-semibold text-green-400">Move Files</span> to organize them.
|
||||
Your files will be automatically renamed, organized, and can be moved between libraries based on your preferences.
|
||||
Check the preview below to see how your files will look, select target libraries if needed, then click <span class="font-semibold text-green-400">Move Files</span> to organize them.
|
||||
</p>
|
||||
<p>
|
||||
<i class="pi pi-lightbulb text-blue-400 mr-1"></i>
|
||||
<span class="text-blue-300">Want to change how files are named? Go to <strong>Settings → File Naming Pattern</strong></span>
|
||||
<span class="text-blue-300">Want to change how files are named? Go to <strong>Settings → File Naming Pattern</strong>. Each library can have its own naming pattern!</span>
|
||||
</p>
|
||||
<p class="text-yellow-500 font-medium flex items-center gap-2">
|
||||
<i class="pi pi-exclamation-triangle text-yellow-400"></i>
|
||||
This will actually move and rename files on your computer, make sure you're happy with the preview first!
|
||||
This will actually move and rename files on your computer across different library folders. Make sure you're happy with the preview first!
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -52,6 +52,23 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex gap-4 mb-4 px-2 items-center">
|
||||
<div class="flex items-center gap-3">
|
||||
<label class="text-sm font-medium text-gray-300">Set all files to:</label>
|
||||
<p-select
|
||||
[options]="availableLibraries"
|
||||
[(ngModel)]="defaultTargetLibraryId"
|
||||
optionLabel="name"
|
||||
optionValue="id"
|
||||
placeholder="Select default library"
|
||||
(onChange)="onDefaultLibraryChange()"
|
||||
class="min-w-[200px]"
|
||||
size="small"
|
||||
appendTo="body"
|
||||
></p-select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex-grow overflow-y-auto">
|
||||
<p-table
|
||||
[value]="filePreviews"
|
||||
@@ -62,6 +79,7 @@
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Current Path</th>
|
||||
<th>Target Library</th>
|
||||
<th></th>
|
||||
<th>New Path</th>
|
||||
</tr>
|
||||
@@ -71,13 +89,27 @@
|
||||
<td class="text-center">{{ preview.bookId }}</td>
|
||||
<td class="w-auto">
|
||||
<p>
|
||||
<span class="text-gray-400 select-none">{{ preview.libraryPathPrefix }}/</span><span class="text-gray-200">{{ preview.relativeOriginalPath }}</span>
|
||||
<span class="text-gray-400 select-none">{{ preview.currentLibraryName }}/</span><span class="text-gray-200">{{ preview.relativeOriginalPath }}</span>
|
||||
</p>
|
||||
</td>
|
||||
<td class="w-auto">
|
||||
<p-select
|
||||
[options]="availableLibraries"
|
||||
[(ngModel)]="preview.targetLibraryId"
|
||||
optionLabel="name"
|
||||
optionValue="id"
|
||||
placeholder="Select Library"
|
||||
(onChange)="onLibraryChange(preview)"
|
||||
[disabled]="preview.isMoved"
|
||||
class="w-full"
|
||||
appendTo="body"
|
||||
size="small"
|
||||
></p-select>
|
||||
</td>
|
||||
<td class="w-auto text-[var(--primary-color)] text-center">→</td>
|
||||
<td class="w-auto">
|
||||
<p>
|
||||
<span class="text-gray-400 select-none">{{ preview.libraryPathPrefix }}/</span><span class="text-gray-200">{{ preview.relativeNewPath }}</span>
|
||||
<span class="text-gray-400 select-none">{{ preview.targetLibraryName }}/</span><span class="text-gray-200">{{ preview.relativeNewPath }}</span>
|
||||
</p>
|
||||
</td>
|
||||
<td class="w-auto text-center">
|
||||
|
||||
+124
-53
@@ -13,11 +13,25 @@ import {Book} from '../../../book/model/book.model';
|
||||
import {FileMoveRequest, FileOperationsService} from '../../service/file-operations-service';
|
||||
import {LibraryService} from "../../../book/service/library.service";
|
||||
import {AppSettingsService} from '../../../core/service/app-settings.service';
|
||||
import {Select} from 'primeng/select';
|
||||
|
||||
interface FilePreview {
|
||||
bookId: number;
|
||||
originalPath: string;
|
||||
relativeOriginalPath: string;
|
||||
currentLibraryId: number | null;
|
||||
currentLibraryName: string;
|
||||
targetLibraryId: number | null;
|
||||
targetLibraryName: string;
|
||||
newPath: string;
|
||||
relativeNewPath: string;
|
||||
isMoved?: boolean;
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-file-mover-component',
|
||||
standalone: true,
|
||||
imports: [Button, FormsModule, TableModule, Divider],
|
||||
imports: [Button, FormsModule, TableModule, Divider, Select],
|
||||
templateUrl: './file-mover-component.html',
|
||||
styleUrl: './file-mover-component.scss'
|
||||
})
|
||||
@@ -44,11 +58,14 @@ export class FileMoverComponent implements OnDestroy {
|
||||
|
||||
bookIds: Set<number> = new Set();
|
||||
books: Book[] = [];
|
||||
filePreviews: { originalPath: string; newPath: string; isMoved?: boolean }[] = [];
|
||||
availableLibraries: { id: number | null; name: string }[] = [];
|
||||
filePreviews: FilePreview[] = [];
|
||||
defaultTargetLibraryId: number | null = null;
|
||||
|
||||
constructor() {
|
||||
this.bookIds = new Set(this.config.data?.bookIds ?? []);
|
||||
this.books = this.bookService.getBooksByIdsFromState([...this.bookIds]);
|
||||
this.loadAvailableLibraries();
|
||||
this.loadDefaultPattern();
|
||||
}
|
||||
|
||||
@@ -116,6 +133,16 @@ export class FileMoverComponent implements OnDestroy {
|
||||
});
|
||||
}
|
||||
|
||||
private loadAvailableLibraries(): void {
|
||||
this.libraryService.libraryState$.pipe(
|
||||
filter(state => state.loaded && state.libraries != null),
|
||||
take(1),
|
||||
takeUntil(this.destroy$)
|
||||
).subscribe(state => {
|
||||
this.availableLibraries = state.libraries?.map(lib => ({id: lib.id ?? null, name: lib.name})) || [];
|
||||
});
|
||||
}
|
||||
|
||||
applyPattern(): void {
|
||||
this.filePreviews = this.books.map(book => {
|
||||
const meta = book.metadata!;
|
||||
@@ -124,67 +151,107 @@ export class FileMoverComponent implements OnDestroy {
|
||||
const fileSubPath = book.fileSubPath ? `${book.fileSubPath.replace(/\/+$/g, '')}/` : '';
|
||||
|
||||
const relativeOriginalPath = `${fileSubPath}${fileName}`;
|
||||
const libraryPathPrefix =
|
||||
book.libraryPath?.id != null
|
||||
? this.libraryService.getLibraryPathById(book.libraryPath.id)?.replace(/\/+$/g, '') ?? ''
|
||||
: '';
|
||||
const originalPath = `${libraryPathPrefix}/${relativeOriginalPath}`.replace(/\/\/+/g, '/');
|
||||
|
||||
const bookLibraryId =
|
||||
book.libraryId ??
|
||||
book.libraryPath?.id ??
|
||||
(book as any).library?.id ??
|
||||
null;
|
||||
const libraryPattern = this.libraryPatterns.find(p => p.libraryId === bookLibraryId);
|
||||
const pattern = libraryPattern?.pattern || this.defaultMovePattern;
|
||||
const currentLibraryId = book.libraryId ?? book.libraryPath?.id ?? (book as any).library?.id ?? null;
|
||||
const currentLibraryName = this.getLibraryNameById(currentLibraryId);
|
||||
|
||||
const values: Record<string, string> = {
|
||||
authors: this.sanitize(meta.authors?.join(', ') || 'Unknown Author'),
|
||||
title: this.sanitize(meta.title || 'Untitled'),
|
||||
year: this.formatYear(meta.publishedDate),
|
||||
series: this.sanitize(meta.seriesName || ''),
|
||||
seriesIndex: this.formatSeriesIndex(meta.seriesNumber ?? undefined),
|
||||
language: this.sanitize(meta.language || ''),
|
||||
publisher: this.sanitize(meta.publisher || ''),
|
||||
isbn: this.sanitize(meta.isbn13 || meta.isbn10 || ''),
|
||||
currentFilename: this.sanitize(fileName)
|
||||
// Initially set target library to current library
|
||||
const targetLibraryId = currentLibraryId;
|
||||
const targetLibraryName = currentLibraryName;
|
||||
|
||||
const preview: FilePreview = {
|
||||
bookId: book.id,
|
||||
originalPath: this.getFullPath(currentLibraryId, relativeOriginalPath),
|
||||
relativeOriginalPath,
|
||||
currentLibraryId,
|
||||
currentLibraryName,
|
||||
targetLibraryId,
|
||||
targetLibraryName,
|
||||
newPath: '',
|
||||
relativeNewPath: ''
|
||||
};
|
||||
|
||||
let newPath: string;
|
||||
this.updatePreviewPaths(preview, book);
|
||||
return preview;
|
||||
});
|
||||
}
|
||||
|
||||
if (!pattern?.trim()) {
|
||||
newPath = `${fileSubPath}${fileName}`;
|
||||
} else {
|
||||
newPath = pattern.replace(/<([^<>]+)>/g, (_, block) => {
|
||||
const placeholders = [...block.matchAll(/{(.*?)}/g)].map(m => m[1]);
|
||||
const allHaveValues = placeholders.every(key => values[key]?.trim());
|
||||
return allHaveValues
|
||||
? block.replace(/{(.*?)}/g, (_: string, key: string) => values[key] ?? '')
|
||||
: '';
|
||||
});
|
||||
onDefaultLibraryChange(): void {
|
||||
this.filePreviews.forEach(preview => {
|
||||
if (!preview.isMoved) {
|
||||
preview.targetLibraryId = this.defaultTargetLibraryId;
|
||||
preview.targetLibraryName = this.getLibraryNameById(this.defaultTargetLibraryId);
|
||||
|
||||
newPath = newPath.replace(/{(.*?)}/g, (_, key) => values[key] ?? '');
|
||||
|
||||
if (!newPath.endsWith(extension)) {
|
||||
newPath += extension;
|
||||
const book = this.books.find(b => b.id === preview.bookId);
|
||||
if (book) {
|
||||
this.updatePreviewPaths(preview, book);
|
||||
}
|
||||
}
|
||||
|
||||
const relativeNewPath = newPath;
|
||||
const fullNewPath = `${libraryPathPrefix}/${relativeNewPath}`.replace(/\/\/+/g, '/');
|
||||
|
||||
return {
|
||||
bookId: book.id,
|
||||
originalPath,
|
||||
relativeOriginalPath,
|
||||
libraryPathPrefix,
|
||||
newPath: fullNewPath,
|
||||
relativeNewPath
|
||||
};
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
onLibraryChange(preview: FilePreview): void {
|
||||
preview.targetLibraryName = this.getLibraryNameById(preview.targetLibraryId);
|
||||
const book = this.books.find(b => b.id === preview.bookId);
|
||||
if (book) {
|
||||
this.updatePreviewPaths(preview, book);
|
||||
}
|
||||
}
|
||||
|
||||
private updatePreviewPaths(preview: FilePreview, book: Book): void {
|
||||
const meta = book.metadata!;
|
||||
const fileName = book.fileName ?? '';
|
||||
const extension = fileName.match(/\.[^.]+$/)?.[0] ?? '';
|
||||
|
||||
const libraryPattern = this.libraryPatterns.find(p => p.libraryId === preview.targetLibraryId);
|
||||
const pattern = libraryPattern?.pattern || this.defaultMovePattern;
|
||||
|
||||
const values: Record<string, string> = {
|
||||
authors: this.sanitize(meta.authors?.join(', ') || 'Unknown Author'),
|
||||
title: this.sanitize(meta.title || 'Untitled'),
|
||||
year: this.formatYear(meta.publishedDate),
|
||||
series: this.sanitize(meta.seriesName || ''),
|
||||
seriesIndex: this.formatSeriesIndex(meta.seriesNumber ?? undefined),
|
||||
language: this.sanitize(meta.language || ''),
|
||||
publisher: this.sanitize(meta.publisher || ''),
|
||||
isbn: this.sanitize(meta.isbn13 || meta.isbn10 || ''),
|
||||
currentFilename: this.sanitize(fileName)
|
||||
};
|
||||
|
||||
let newPath: string;
|
||||
|
||||
if (!pattern?.trim()) {
|
||||
newPath = fileName;
|
||||
} else {
|
||||
newPath = pattern.replace(/<([^<>]+)>/g, (_, block) => {
|
||||
const placeholders = [...block.matchAll(/{(.*?)}/g)].map(m => m[1]);
|
||||
const allHaveValues = placeholders.every(key => values[key]?.trim());
|
||||
return allHaveValues
|
||||
? block.replace(/{(.*?)}/g, (_: string, key: string) => values[key] ?? '')
|
||||
: '';
|
||||
});
|
||||
|
||||
newPath = newPath.replace(/{(.*?)}/g, (_, key) => values[key] ?? '');
|
||||
|
||||
if (!newPath.endsWith(extension)) {
|
||||
newPath += extension;
|
||||
}
|
||||
}
|
||||
|
||||
preview.relativeNewPath = newPath;
|
||||
preview.newPath = this.getFullPath(preview.targetLibraryId, newPath);
|
||||
}
|
||||
|
||||
private getLibraryNameById(libraryId: number | null): string {
|
||||
if (libraryId === null) return 'Unknown Library';
|
||||
return this.availableLibraries.find(lib => lib.id === libraryId)?.name || 'Unknown Library';
|
||||
}
|
||||
|
||||
private getFullPath(libraryId: number | null, relativePath: string): string {
|
||||
const libraryPath = libraryId ? this.libraryService.getLibraryPathById(libraryId)?.replace(/\/+$/g, '') : '';
|
||||
return libraryPath ? `${libraryPath}/${relativePath}`.replace(/\/\/+/g, '/') : relativePath;
|
||||
}
|
||||
|
||||
get movedFileCount(): number {
|
||||
return this.filePreviews.filter(p => p.isMoved).length;
|
||||
}
|
||||
@@ -211,7 +278,11 @@ export class FileMoverComponent implements OnDestroy {
|
||||
this.loading = true;
|
||||
|
||||
const request: FileMoveRequest = {
|
||||
bookIds: [...this.bookIds]
|
||||
bookIds: [...this.bookIds],
|
||||
moves: this.filePreviews.map(preview => ({
|
||||
bookId: preview.bookId,
|
||||
targetLibraryId: preview.targetLibraryId
|
||||
}))
|
||||
};
|
||||
|
||||
this.fileOperationsService.moveFiles(request).pipe(
|
||||
|
||||
@@ -5,6 +5,10 @@ import {API_CONFIG} from '../../config/api-config';
|
||||
|
||||
export interface FileMoveRequest {
|
||||
bookIds: number[];
|
||||
moves: {
|
||||
bookId: number;
|
||||
targetLibraryId: number | null;
|
||||
}[];
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
|
||||
Reference in New Issue
Block a user