Add moveFiles option to attach/merge and per-book delete in duplicate merger (#2833)
* Add moveFiles option to attach/merge and per-book delete in duplicate merger * Remove single-format restriction from attach-to-book action
This commit is contained in:
@@ -915,11 +915,10 @@ export class BookBrowserComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
}
|
||||
|
||||
attachFilesToBook(): void {
|
||||
// Get selected books that are single-file books (no alternative formats)
|
||||
const currentState = this.bookService.getCurrentBookState();
|
||||
const selectedBookIds = Array.from(this.selectedBooks);
|
||||
const sourceBooks = (currentState.books || []).filter(book =>
|
||||
selectedBookIds.includes(book.id) && !book.alternativeFormats?.length
|
||||
selectedBookIds.includes(book.id)
|
||||
);
|
||||
|
||||
if (sourceBooks.length === 0) {
|
||||
@@ -957,14 +956,13 @@ export class BookBrowserComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
|
||||
const currentState = this.bookService.getCurrentBookState();
|
||||
const selectedBookIds = Array.from(this.selectedBooks);
|
||||
const eligibleBooks = (currentState.books || []).filter(book =>
|
||||
selectedBookIds.includes(book.id) && !book.alternativeFormats?.length
|
||||
const selectedBooks = (currentState.books || []).filter(book =>
|
||||
selectedBookIds.includes(book.id)
|
||||
);
|
||||
|
||||
if (eligibleBooks.length === 0) return false;
|
||||
if (selectedBooks.length === 0) return false;
|
||||
|
||||
// Check if all eligible books are from the same library
|
||||
const libraryIds = new Set(eligibleBooks.map(b => b.libraryId));
|
||||
const libraryIds = new Set(selectedBooks.map(b => b.libraryId));
|
||||
return libraryIds.size === 1;
|
||||
}
|
||||
|
||||
|
||||
+9
-9
@@ -70,16 +70,16 @@
|
||||
</p-autocomplete>
|
||||
</div>
|
||||
|
||||
<!-- Delete Source Book(s) Option -->
|
||||
<!-- Options -->
|
||||
<div class="delete-option">
|
||||
<p-checkbox
|
||||
[(ngModel)]="deleteSourceBooks"
|
||||
[(ngModel)]="moveFiles"
|
||||
[binary]="true"
|
||||
inputId="deleteSourceBooks"
|
||||
inputId="moveFiles"
|
||||
[disabled]="isAttaching">
|
||||
</p-checkbox>
|
||||
<label for="deleteSourceBooks" class="delete-label">
|
||||
{{ isBulkMode ? t('deleteSourceBulk') : t('deleteSource') }}
|
||||
<label for="moveFiles" class="delete-label">
|
||||
{{ t('moveFilesLabel') }}
|
||||
</label>
|
||||
</div>
|
||||
|
||||
@@ -87,12 +87,12 @@
|
||||
<div class="warning-message">
|
||||
<i class="pi pi-info-circle"></i>
|
||||
<div class="warning-text">
|
||||
<p>{{ isBulkMode ? t('warningMoveBulk') : t('warningMove') }}</p>
|
||||
@if (deleteSourceBooks) {
|
||||
<p>{{ isBulkMode ? t('warningDeleteBulk') : t('warningDelete') }}</p>
|
||||
@if (moveFiles) {
|
||||
<p>{{ isBulkMode ? t('warningMoveBulk') : t('warningMove') }}</p>
|
||||
} @else {
|
||||
<p>{{ isBulkMode ? t('warningKeepBulk') : t('warningKeep') }}</p>
|
||||
<p>{{ isBulkMode ? t('warningNoMoveBulk') : t('warningNoMove') }}</p>
|
||||
}
|
||||
<p>{{ isBulkMode ? t('warningDeleteBulk') : t('warningDelete') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
+13
-3
@@ -11,6 +11,7 @@ import { BookFileService } from '../../service/book-file.service';
|
||||
import { Book } from '../../model/book.model';
|
||||
import { MessageService } from 'primeng/api';
|
||||
import { TranslocoDirective, TranslocoPipe, TranslocoService } from '@jsverse/transloco';
|
||||
import { AppSettingsService } from '../../../../shared/service/app-settings.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-book-file-attacher',
|
||||
@@ -29,7 +30,7 @@ import { TranslocoDirective, TranslocoPipe, TranslocoService } from '@jsverse/tr
|
||||
export class BookFileAttacherComponent implements OnInit, OnDestroy {
|
||||
sourceBooks: Book[] = [];
|
||||
targetBook: Book | null = null;
|
||||
deleteSourceBooks = true;
|
||||
moveFiles = false;
|
||||
isAttaching = false;
|
||||
searchQuery = '';
|
||||
filteredBooks: Book[] = [];
|
||||
@@ -38,6 +39,7 @@ export class BookFileAttacherComponent implements OnInit, OnDestroy {
|
||||
private allBooks: Book[] = [];
|
||||
|
||||
private readonly t = inject(TranslocoService);
|
||||
private readonly appSettingsService = inject(AppSettingsService);
|
||||
|
||||
constructor(
|
||||
private dialogRef: DynamicDialogRef,
|
||||
@@ -60,6 +62,14 @@ export class BookFileAttacherComponent implements OnInit, OnDestroy {
|
||||
return;
|
||||
}
|
||||
|
||||
this.appSettingsService.appSettings$.pipe(
|
||||
filter(settings => !!settings),
|
||||
take(1),
|
||||
takeUntil(this.destroy$)
|
||||
).subscribe(settings => {
|
||||
this.moveFiles = settings!.metadataPersistenceSettings?.moveFilesToLibraryPattern ?? false;
|
||||
});
|
||||
|
||||
// Get the library ID from first source book (all should be same library)
|
||||
const libraryId = this.sourceBooks[0].libraryId;
|
||||
const sourceBookIds = new Set(this.sourceBooks.map(b => b.id));
|
||||
@@ -136,12 +146,12 @@ export class BookFileAttacherComponent implements OnInit, OnDestroy {
|
||||
this.bookFileService.attachBookFiles(
|
||||
this.targetBook.id,
|
||||
sourceBookIds,
|
||||
this.deleteSourceBooks
|
||||
this.moveFiles
|
||||
).pipe(
|
||||
takeUntil(this.destroy$)
|
||||
).subscribe({
|
||||
next: () => {
|
||||
this.dialogRef.close({ success: true, deletedSourceBooks: this.deleteSourceBooks });
|
||||
this.dialogRef.close({ success: true });
|
||||
},
|
||||
error: () => {
|
||||
this.isAttaching = false;
|
||||
|
||||
+37
-4
@@ -78,12 +78,12 @@
|
||||
<div class="action-bar-right">
|
||||
<div class="delete-option">
|
||||
<p-checkbox
|
||||
[(ngModel)]="deleteSourceBooks"
|
||||
[(ngModel)]="moveFiles"
|
||||
[binary]="true"
|
||||
inputId="deleteSource"
|
||||
inputId="moveFiles"
|
||||
[disabled]="isMerging">
|
||||
</p-checkbox>
|
||||
<label for="deleteSource">{{ t('deleteSource') }}</label>
|
||||
<label for="moveFiles">{{ 'book.fileAttacher.moveFilesLabel' | transloco }}</label>
|
||||
</div>
|
||||
@if (activeGroups.length > 0) {
|
||||
<p-button
|
||||
@@ -140,6 +140,9 @@
|
||||
<div class="group-header">
|
||||
<span class="group-label">{{ t('groupLabel', { index: pageFirst + $index + 1 }) }}</span>
|
||||
<p-tag [value]="getMatchReasonLabel(group.matchReason)" [severity]="getMatchReasonSeverity(group.matchReason)"></p-tag>
|
||||
@if (hasSameFormatConflict(group)) {
|
||||
<p-tag [value]="t('sameFormatWarning')" severity="warn" icon="pi pi-exclamation-triangle"></p-tag>
|
||||
}
|
||||
<div class="group-actions">
|
||||
<p-button
|
||||
[label]="t('merge')"
|
||||
@@ -149,6 +152,17 @@
|
||||
(click)="mergeGroup(group)"
|
||||
[disabled]="isMerging">
|
||||
</p-button>
|
||||
@if (getDeleteSelectedCount(group) > 0) {
|
||||
<p-button
|
||||
[label]="t('deleteSelected', { count: getDeleteSelectedCount(group) })"
|
||||
icon="pi pi-trash"
|
||||
size="small"
|
||||
severity="danger"
|
||||
[outlined]="true"
|
||||
(click)="deleteGroup(group)"
|
||||
[disabled]="isMerging">
|
||||
</p-button>
|
||||
}
|
||||
<p-button
|
||||
[label]="t('dismiss')"
|
||||
icon="pi pi-times"
|
||||
@@ -162,7 +176,16 @@
|
||||
</div>
|
||||
<div class="group-books">
|
||||
@for (book of group.books; track book.id) {
|
||||
<div class="book-row" [class.selected-target]="book.id === group.selectedTargetBookId" (click)="group.selectedTargetBookId = book.id">
|
||||
<div class="book-row" [class.selected-target]="book.id === group.selectedTargetBookId" [class.marked-for-deletion]="group.selectedForDeletion.has(book.id)">
|
||||
@if (book.id !== group.selectedTargetBookId) {
|
||||
<p-checkbox
|
||||
[binary]="true"
|
||||
[ngModel]="group.selectedForDeletion.has(book.id)"
|
||||
(onChange)="toggleDeleteSelection(group, book.id)"
|
||||
[disabled]="isMerging"
|
||||
class="delete-checkbox">
|
||||
</p-checkbox>
|
||||
}
|
||||
<img class="book-cover"
|
||||
[src]="urlHelper.getThumbnailUrl(book.id, book.metadata?.coverUpdatedOn)"
|
||||
[alt]="book.metadata?.title || ''"
|
||||
@@ -179,13 +202,23 @@
|
||||
@if (getFileCount(book) > 1) {
|
||||
<span class="file-count">{{ t('fileCount', { count: getFileCount(book) }) }}</span>
|
||||
}
|
||||
@if (book.primaryFile?.fileSizeKb) {
|
||||
<span class="file-detail">{{ formatFileSize(book.primaryFile?.fileSizeKb) }}</span>
|
||||
}
|
||||
</div>
|
||||
@if (book.primaryFile?.fileName) {
|
||||
<div class="book-file-path" [title]="getBookFilePath(book)">
|
||||
<i class="pi pi-file"></i>
|
||||
{{ getBookFilePath(book) }}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
<div class="book-select">
|
||||
<p-radioButton
|
||||
[name]="'target-' + group.suggestedTargetBookId"
|
||||
[value]="book.id"
|
||||
[(ngModel)]="group.selectedTargetBookId"
|
||||
(onClick)="onTargetChange(group)"
|
||||
[disabled]="isMerging">
|
||||
</p-radioButton>
|
||||
@if (book.id === group.selectedTargetBookId) {
|
||||
|
||||
+30
@@ -190,6 +190,14 @@
|
||||
background: var(--p-highlight-background);
|
||||
}
|
||||
|
||||
&.marked-for-deletion {
|
||||
background: color-mix(in srgb, var(--p-red-500) 8%, transparent);
|
||||
}
|
||||
|
||||
.delete-checkbox {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.book-cover {
|
||||
width: 36px;
|
||||
height: 52px;
|
||||
@@ -244,6 +252,28 @@
|
||||
font-size: 0.75rem;
|
||||
color: var(--p-text-muted-color);
|
||||
}
|
||||
|
||||
.file-detail {
|
||||
font-size: 0.75rem;
|
||||
color: var(--p-text-muted-color);
|
||||
}
|
||||
}
|
||||
|
||||
.book-file-path {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.25rem;
|
||||
font-size: 0.75rem;
|
||||
color: var(--p-text-muted-color);
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
margin-top: 0.125rem;
|
||||
|
||||
i {
|
||||
font-size: 0.6875rem;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+90
-5
@@ -8,18 +8,21 @@ import {SelectButton} from 'primeng/selectbutton';
|
||||
import {ProgressBar} from 'primeng/progressbar';
|
||||
import {Tag} from 'primeng/tag';
|
||||
import {Paginator} from 'primeng/paginator';
|
||||
import {Subject, takeUntil} from 'rxjs';
|
||||
import {filter, Subject, take, takeUntil} from 'rxjs';
|
||||
import {BookFileService} from '../../service/book-file.service';
|
||||
import {BookService} from '../../service/book.service';
|
||||
import {Book, DuplicateDetectionRequest, DuplicateGroup} from '../../model/book.model';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {ConfirmationService, MessageService} from 'primeng/api';
|
||||
import {TranslocoDirective, TranslocoPipe, TranslocoService} from '@jsverse/transloco';
|
||||
import {UrlHelperService} from '../../../../shared/service/url-helper.service';
|
||||
import {AppSettingsService} from '../../../../shared/service/app-settings.service';
|
||||
|
||||
type PresetMode = 'strict' | 'balanced' | 'aggressive' | 'custom';
|
||||
|
||||
interface DisplayGroup extends DuplicateGroup {
|
||||
selectedTargetBookId: number;
|
||||
dismissed: boolean;
|
||||
selectedForDeletion: Set<number>;
|
||||
}
|
||||
|
||||
@Component({
|
||||
@@ -54,7 +57,7 @@ export class DuplicateMergerComponent implements OnInit, OnDestroy {
|
||||
isScanning = false;
|
||||
isMerging = false;
|
||||
hasScanned = false;
|
||||
deleteSourceBooks = true;
|
||||
moveFiles = false;
|
||||
mergeProgress = 0;
|
||||
mergeTotal = 0;
|
||||
|
||||
@@ -66,14 +69,26 @@ export class DuplicateMergerComponent implements OnInit, OnDestroy {
|
||||
|
||||
private destroy$ = new Subject<void>();
|
||||
private readonly bookFileService = inject(BookFileService);
|
||||
private readonly bookService = inject(BookService);
|
||||
private readonly messageService = inject(MessageService);
|
||||
private readonly confirmationService = inject(ConfirmationService);
|
||||
private readonly dialogRef = inject(DynamicDialogRef);
|
||||
private readonly config = inject(DynamicDialogConfig);
|
||||
private readonly t = inject(TranslocoService);
|
||||
readonly urlHelper = inject(UrlHelperService);
|
||||
private readonly appSettingsService = inject(AppSettingsService);
|
||||
|
||||
ngOnInit(): void {
|
||||
this.libraryId = this.config.data.libraryId;
|
||||
|
||||
this.appSettingsService.appSettings$.pipe(
|
||||
filter(settings => !!settings),
|
||||
take(1),
|
||||
takeUntil(this.destroy$)
|
||||
).subscribe(settings => {
|
||||
this.moveFiles = settings!.metadataPersistenceSettings?.moveFilesToLibraryPattern ?? false;
|
||||
});
|
||||
|
||||
this.presetOptions = [
|
||||
{label: this.t.translate('book.duplicateMerger.presetStrict'), value: 'strict'},
|
||||
{label: this.t.translate('book.duplicateMerger.presetBalanced'), value: 'balanced'},
|
||||
@@ -147,6 +162,7 @@ export class DuplicateMergerComponent implements OnInit, OnDestroy {
|
||||
...g,
|
||||
selectedTargetBookId: g.suggestedTargetBookId,
|
||||
dismissed: false,
|
||||
selectedForDeletion: new Set<number>(),
|
||||
}));
|
||||
this.isScanning = false;
|
||||
this.hasScanned = true;
|
||||
@@ -207,6 +223,32 @@ export class DuplicateMergerComponent implements OnInit, OnDestroy {
|
||||
return this.t.translate(`book.duplicateMerger.reason.${reason}`);
|
||||
}
|
||||
|
||||
hasSameFormatConflict(group: DisplayGroup): boolean {
|
||||
const formats = new Set<string>();
|
||||
for (const book of group.books) {
|
||||
if (book.primaryFile?.bookType) {
|
||||
if (formats.has(book.primaryFile.bookType)) return true;
|
||||
formats.add(book.primaryFile.bookType);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
getBookFilePath(book: Book): string {
|
||||
const subPath = book.primaryFile?.fileSubPath;
|
||||
const fileName = book.primaryFile?.fileName || '';
|
||||
if (subPath) return `${subPath}/${fileName}`;
|
||||
return fileName;
|
||||
}
|
||||
|
||||
formatFileSize(sizeKb?: number): string {
|
||||
if (!sizeKb) return '';
|
||||
if (sizeKb < 1024) return `${sizeKb} KB`;
|
||||
const sizeMb = sizeKb / 1024;
|
||||
if (sizeMb < 1024) return `${sizeMb.toFixed(1)} MB`;
|
||||
return `${(sizeMb / 1024).toFixed(2)} GB`;
|
||||
}
|
||||
|
||||
getMatchReasonSeverity(reason: string): "success" | "info" | "warn" | "danger" | "secondary" | "contrast" {
|
||||
switch (reason) {
|
||||
case 'ISBN':
|
||||
@@ -223,6 +265,22 @@ export class DuplicateMergerComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
}
|
||||
|
||||
onTargetChange(group: DisplayGroup): void {
|
||||
group.selectedForDeletion.delete(group.selectedTargetBookId);
|
||||
}
|
||||
|
||||
toggleDeleteSelection(group: DisplayGroup, bookId: number): void {
|
||||
if (group.selectedForDeletion.has(bookId)) {
|
||||
group.selectedForDeletion.delete(bookId);
|
||||
} else {
|
||||
group.selectedForDeletion.add(bookId);
|
||||
}
|
||||
}
|
||||
|
||||
getDeleteSelectedCount(group: DisplayGroup): number {
|
||||
return group.selectedForDeletion.size;
|
||||
}
|
||||
|
||||
dismissGroup(group: DisplayGroup): void {
|
||||
group.dismissed = true;
|
||||
if (this.pagedGroups.length === 0 && this.pageFirst > 0) {
|
||||
@@ -240,7 +298,7 @@ export class DuplicateMergerComponent implements OnInit, OnDestroy {
|
||||
|
||||
group.dismissed = true;
|
||||
try {
|
||||
await this.bookFileService.attachBookFiles(targetId, sourceIds, this.deleteSourceBooks)
|
||||
await this.bookFileService.attachBookFiles(targetId, sourceIds, this.moveFiles)
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
.toPromise();
|
||||
} catch {
|
||||
@@ -277,7 +335,7 @@ export class DuplicateMergerComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
try {
|
||||
await this.bookFileService.attachBookFiles(targetId, sourceIds, this.deleteSourceBooks)
|
||||
await this.bookFileService.attachBookFiles(targetId, sourceIds, this.moveFiles)
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
.toPromise();
|
||||
group.dismissed = true;
|
||||
@@ -306,6 +364,33 @@ export class DuplicateMergerComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
}
|
||||
|
||||
deleteGroup(group: DisplayGroup): void {
|
||||
const idsToDelete = Array.from(group.selectedForDeletion);
|
||||
if (idsToDelete.length === 0) return;
|
||||
|
||||
this.confirmationService.confirm({
|
||||
message: this.t.translate('book.duplicateMerger.confirm.deleteMessage', {count: idsToDelete.length}),
|
||||
header: this.t.translate('book.duplicateMerger.confirm.deleteHeader'),
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
acceptLabel: this.t.translate('common.yes'),
|
||||
rejectLabel: this.t.translate('common.no'),
|
||||
acceptButtonProps: {severity: 'danger'},
|
||||
accept: () => {
|
||||
this.bookService.deleteBooks(new Set(idsToDelete)).pipe(
|
||||
takeUntil(this.destroy$)
|
||||
).subscribe({
|
||||
next: () => {
|
||||
group.books = group.books.filter(b => !group.selectedForDeletion.has(b.id));
|
||||
group.selectedForDeletion.clear();
|
||||
if (group.books.length <= 1) {
|
||||
group.dismissed = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
closeDialog(): void {
|
||||
this.dialogRef.close();
|
||||
}
|
||||
|
||||
@@ -212,21 +212,17 @@ export class BookFileService {
|
||||
return this.http.post<DuplicateGroup[]>(`${this.url}/duplicates`, request);
|
||||
}
|
||||
|
||||
attachBookFiles(targetBookId: number, sourceBookIds: number[], deleteSourceBooks: boolean): Observable<Book> {
|
||||
attachBookFiles(targetBookId: number, sourceBookIds: number[], moveFiles: boolean): Observable<Book> {
|
||||
return this.http.post<Book>(`${this.url}/${targetBookId}/attach-file`, {
|
||||
sourceBookIds,
|
||||
deleteSourceBooks
|
||||
moveFiles
|
||||
}).pipe(
|
||||
tap(updatedBook => {
|
||||
const currentState = this.bookStateService.getCurrentBookState();
|
||||
const sourceIdSet = new Set(sourceBookIds);
|
||||
let updatedBooks = (currentState.books || []).map(book =>
|
||||
book.id === targetBookId ? updatedBook : book
|
||||
);
|
||||
|
||||
if (deleteSourceBooks) {
|
||||
const sourceIdSet = new Set(sourceBookIds);
|
||||
updatedBooks = updatedBooks.filter(book => !sourceIdSet.has(book.id));
|
||||
}
|
||||
).filter(book => !sourceIdSet.has(book.id));
|
||||
|
||||
this.bookStateService.updateBookState({
|
||||
...currentState,
|
||||
|
||||
Reference in New Issue
Block a user