refactor(frontend): rename booklore-ui to frontend
- Frontend path: - rename the tracked Angular app tree from `booklore-ui/` to `frontend/` - preserve file contents during the move so this commit stays focused on the path change itself - Frontend docs: - update the moved frontend README and contribution guide where they refer to the renamed folder - keep those edits limited to path references introduced by the directory rename
This commit is contained in:
+248
@@ -0,0 +1,248 @@
|
||||
<ng-container *transloco="let t; prefix: 'book.duplicateMerger'">
|
||||
<div class="duplicate-merger-container">
|
||||
<div class="panel-header">
|
||||
<div class="header-icon-wrapper">
|
||||
<i class="pi pi-copy header-icon"></i>
|
||||
</div>
|
||||
<div class="header-text">
|
||||
<h2 class="panel-title">{{ t('title') }}</h2>
|
||||
<p class="panel-description">{{ t('description') }}</p>
|
||||
</div>
|
||||
<p-button
|
||||
icon="pi pi-times"
|
||||
[rounded]="true"
|
||||
[text]="true"
|
||||
severity="secondary"
|
||||
(click)="closeDialog()"
|
||||
class="close-button">
|
||||
</p-button>
|
||||
</div>
|
||||
|
||||
<div class="dialog-content">
|
||||
<!-- Preset Mode Selector -->
|
||||
<div class="preset-section">
|
||||
<p-selectButton
|
||||
[options]="presetOptions"
|
||||
[(ngModel)]="presetMode"
|
||||
(onChange)="onPresetChange()"
|
||||
optionLabel="label"
|
||||
optionValue="value"
|
||||
[disabled]="isScanning || isMerging">
|
||||
</p-selectButton>
|
||||
</div>
|
||||
|
||||
<!-- Advanced Toggles -->
|
||||
<div class="advanced-section">
|
||||
<button class="advanced-toggle" (click)="showAdvanced = !showAdvanced">
|
||||
<i class="pi" [class.pi-chevron-right]="!showAdvanced" [class.pi-chevron-down]="showAdvanced"></i>
|
||||
{{ t('advanced') }}
|
||||
</button>
|
||||
|
||||
@if (showAdvanced) {
|
||||
<div class="signal-checkboxes">
|
||||
<div class="signal-checkbox">
|
||||
<p-checkbox [(ngModel)]="matchByIsbn" [binary]="true" inputId="isbn" (onChange)="onSignalToggle()" [disabled]="isScanning || isMerging"></p-checkbox>
|
||||
<label for="isbn">{{ t('signalIsbn') }}</label>
|
||||
</div>
|
||||
<div class="signal-checkbox">
|
||||
<p-checkbox [(ngModel)]="matchByExternalId" [binary]="true" inputId="externalId" (onChange)="onSignalToggle()" [disabled]="isScanning || isMerging"></p-checkbox>
|
||||
<label for="externalId">{{ t('signalExternalId') }}</label>
|
||||
</div>
|
||||
<div class="signal-checkbox">
|
||||
<p-checkbox [(ngModel)]="matchByTitleAuthor" [binary]="true" inputId="titleAuthor" (onChange)="onSignalToggle()" [disabled]="isScanning || isMerging"></p-checkbox>
|
||||
<label for="titleAuthor">{{ t('signalTitleAuthor') }}</label>
|
||||
</div>
|
||||
<div class="signal-checkbox">
|
||||
<p-checkbox [(ngModel)]="matchByDirectory" [binary]="true" inputId="directory" (onChange)="onSignalToggle()" [disabled]="isScanning || isMerging"></p-checkbox>
|
||||
<label for="directory">{{ t('signalDirectory') }}</label>
|
||||
</div>
|
||||
<div class="signal-checkbox">
|
||||
<p-checkbox [(ngModel)]="matchByFilename" [binary]="true" inputId="filename" (onChange)="onSignalToggle()" [disabled]="isScanning || isMerging"></p-checkbox>
|
||||
<label for="filename">{{ t('signalFilename') }}</label>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<!-- Action Bar -->
|
||||
<div class="action-bar">
|
||||
<div class="action-bar-left">
|
||||
<p-button
|
||||
[label]="t('scan')"
|
||||
icon="pi pi-search"
|
||||
(click)="scan()"
|
||||
[disabled]="!canScan"
|
||||
[loading]="isScanning">
|
||||
</p-button>
|
||||
</div>
|
||||
<div class="action-bar-right">
|
||||
<div class="delete-option">
|
||||
<p-checkbox
|
||||
[(ngModel)]="moveFiles"
|
||||
[binary]="true"
|
||||
inputId="moveFiles"
|
||||
[disabled]="isMerging">
|
||||
</p-checkbox>
|
||||
<label for="moveFiles">{{ 'book.fileAttacher.moveFilesLabel' | transloco }}</label>
|
||||
</div>
|
||||
@if (activeGroups.length > 0) {
|
||||
<p-button
|
||||
[label]="t('mergeAll', { count: activeGroups.length })"
|
||||
icon="pi pi-check-circle"
|
||||
severity="success"
|
||||
(click)="mergeAll()"
|
||||
[disabled]="isMerging"
|
||||
[loading]="isMerging">
|
||||
</p-button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Merge Progress -->
|
||||
@if (isMerging) {
|
||||
<p-progressBar [value]="mergeTotal > 0 ? (mergeProgress / mergeTotal) * 100 : 0" [showValue]="false"></p-progressBar>
|
||||
}
|
||||
|
||||
<!-- Help Text -->
|
||||
@if (hasScanned && activeGroups.length > 0) {
|
||||
<div class="help-text">
|
||||
<i class="pi pi-info-circle"></i>
|
||||
<span>{{ t('helpText') }}</span>
|
||||
</div>
|
||||
}
|
||||
|
||||
<!-- Results Area -->
|
||||
<div class="results-area">
|
||||
@if (isScanning) {
|
||||
<div class="empty-state">
|
||||
<i class="pi pi-spin pi-spinner"></i>
|
||||
<p>{{ t('scanning') }}</p>
|
||||
</div>
|
||||
} @else if (!hasScanned) {
|
||||
<div class="empty-state">
|
||||
<i class="pi pi-search"></i>
|
||||
<p>{{ t('scanPrompt') }}</p>
|
||||
</div>
|
||||
} @else if (activeGroups.length === 0 && groups.length === 0) {
|
||||
<div class="empty-state">
|
||||
<i class="pi pi-check-circle"></i>
|
||||
<p>{{ t('noDuplicates') }}</p>
|
||||
</div>
|
||||
} @else if (activeGroups.length === 0 && groups.length > 0) {
|
||||
<div class="empty-state">
|
||||
<i class="pi pi-check-circle"></i>
|
||||
<p>{{ t('allMerged') }}</p>
|
||||
</div>
|
||||
} @else {
|
||||
<div class="groups-list">
|
||||
@for (group of pagedGroups; track group.suggestedTargetBookId) {
|
||||
<div class="duplicate-group">
|
||||
<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')"
|
||||
icon="pi pi-check"
|
||||
size="small"
|
||||
severity="success"
|
||||
(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"
|
||||
size="small"
|
||||
severity="secondary"
|
||||
[outlined]="true"
|
||||
(click)="dismissGroup(group)"
|
||||
[disabled]="isMerging">
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="group-books">
|
||||
@for (book of group.books; track 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 || ''"
|
||||
loading="lazy"/>
|
||||
<div class="book-info">
|
||||
<div class="book-title">{{ book.metadata?.title || ('book.fileAttacher.unknownTitle' | transloco) }}</div>
|
||||
@if (book.metadata?.authors?.length) {
|
||||
<div class="book-authors">{{ book.metadata?.authors?.join(', ') }}</div>
|
||||
}
|
||||
<div class="book-formats">
|
||||
@for (format of getBookFormats(book); track format) {
|
||||
<span class="format-badge">{{ format }}</span>
|
||||
}
|
||||
@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) {
|
||||
<span class="target-label">{{ t('target') }}</span>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@if (activeGroups.length > pageSize) {
|
||||
<p-paginator
|
||||
[rows]="pageSize"
|
||||
[totalRecords]="activeGroups.length"
|
||||
[first]="pageFirst"
|
||||
(onPageChange)="onPageChange($event)"
|
||||
[rowsPerPageOptions]="[10, 20, 50]">
|
||||
</p-paginator>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
+338
@@ -0,0 +1,338 @@
|
||||
@use '../../../../shared/styles/panel-shared' as panel;
|
||||
|
||||
.duplicate-merger-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.panel-header {
|
||||
@include panel.panel-header;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.dialog-content {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
min-height: 0;
|
||||
padding: 1.5rem;
|
||||
background: var(--card-background);
|
||||
border: 1px solid var(--border-color);
|
||||
border-top: none;
|
||||
border-radius: 0 0 10px 10px;
|
||||
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.preset-section {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.advanced-section {
|
||||
.advanced-toggle {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
background: none;
|
||||
border: none;
|
||||
color: var(--p-text-muted-color);
|
||||
font-size: 0.875rem;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
padding: 0.25rem 0;
|
||||
|
||||
&:hover {
|
||||
color: var(--p-text-color);
|
||||
}
|
||||
|
||||
i {
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
}
|
||||
|
||||
.signal-checkboxes {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.75rem 1.5rem;
|
||||
padding: 0.75rem 0 0 0;
|
||||
}
|
||||
|
||||
.signal-checkbox {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
|
||||
label {
|
||||
font-size: 0.875rem;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.action-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 1rem;
|
||||
padding: 0.75rem 0;
|
||||
border-top: 1px solid var(--border-color);
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
|
||||
.action-bar-left {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.action-bar-right {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.delete-option {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
|
||||
label {
|
||||
font-size: 0.875rem;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.results-area {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 3rem 1rem;
|
||||
color: var(--p-text-muted-color);
|
||||
gap: 0.75rem;
|
||||
|
||||
i {
|
||||
font-size: 2.5rem;
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 0;
|
||||
font-size: 0.9375rem;
|
||||
}
|
||||
}
|
||||
|
||||
.groups-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.duplicate-group {
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
|
||||
.group-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
padding: 0.5rem 0.75rem;
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
|
||||
.group-label {
|
||||
font-weight: 600;
|
||||
font-size: 0.8125rem;
|
||||
color: var(--p-text-muted-color);
|
||||
}
|
||||
|
||||
.group-actions {
|
||||
margin-left: auto;
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
.group-books {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
|
||||
.book-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
padding: 0.625rem 0.75rem;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.1s;
|
||||
|
||||
&:not(:last-child) {
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
&:hover {
|
||||
background: var(--p-content-hover-background);
|
||||
}
|
||||
|
||||
&.selected-target {
|
||||
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;
|
||||
flex-shrink: 0;
|
||||
border-radius: 3px;
|
||||
object-fit: cover;
|
||||
background: var(--p-surface-200);
|
||||
}
|
||||
|
||||
.book-info {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.0625rem;
|
||||
|
||||
.book-title {
|
||||
font-weight: 600;
|
||||
font-size: 0.875rem;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.book-authors {
|
||||
font-size: 0.8125rem;
|
||||
color: var(--p-text-muted-color);
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.book-formats {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.25rem;
|
||||
margin-top: 0.125rem;
|
||||
|
||||
.format-badge {
|
||||
display: inline-block;
|
||||
font-size: 0.625rem;
|
||||
font-weight: 700;
|
||||
padding: 0.0625rem 0.3125rem;
|
||||
border-radius: 3px;
|
||||
background: var(--p-primary-100);
|
||||
color: var(--p-primary-700);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.02em;
|
||||
}
|
||||
|
||||
.file-count {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.book-select {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.375rem;
|
||||
flex-shrink: 0;
|
||||
|
||||
.target-label {
|
||||
font-size: 0.6875rem;
|
||||
color: var(--p-primary-color);
|
||||
text-transform: uppercase;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.03em;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.help-text {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 0.5rem;
|
||||
padding: 0.625rem 0.75rem;
|
||||
font-size: 0.8125rem;
|
||||
color: var(--p-text-muted-color);
|
||||
background: var(--p-content-hover-background);
|
||||
border-radius: 6px;
|
||||
line-height: 1.4;
|
||||
|
||||
i {
|
||||
flex-shrink: 0;
|
||||
margin-top: 0.125rem;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
}
|
||||
|
||||
:host-context(.p-dark) {
|
||||
.book-row .book-cover {
|
||||
background: var(--p-surface-700);
|
||||
}
|
||||
|
||||
.book-row .book-formats .format-badge {
|
||||
background: rgba(var(--p-primary-500-rgb, 99, 102, 241), 0.15);
|
||||
color: var(--p-primary-400);
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.action-bar {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
|
||||
.action-bar-right {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
}
|
||||
|
||||
.duplicate-group .group-header {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
}
|
||||
+394
@@ -0,0 +1,394 @@
|
||||
import {Component, inject, OnDestroy, OnInit} from '@angular/core';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {Button} from 'primeng/button';
|
||||
import {Checkbox} from 'primeng/checkbox';
|
||||
import {RadioButton} from 'primeng/radiobutton';
|
||||
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 {BookFileService} from '../../service/book-file.service';
|
||||
import {BookService} from '../../service/book.service';
|
||||
import {Book, DuplicateDetectionRequest, DuplicateGroup} from '../../model/book.model';
|
||||
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({
|
||||
selector: 'app-duplicate-merger',
|
||||
standalone: true,
|
||||
imports: [
|
||||
FormsModule,
|
||||
Button,
|
||||
Checkbox,
|
||||
RadioButton,
|
||||
SelectButton,
|
||||
ProgressBar,
|
||||
Tag,
|
||||
Paginator,
|
||||
TranslocoDirective,
|
||||
TranslocoPipe,
|
||||
],
|
||||
templateUrl: './duplicate-merger.component.html',
|
||||
styleUrls: ['./duplicate-merger.component.scss']
|
||||
})
|
||||
export class DuplicateMergerComponent implements OnInit, OnDestroy {
|
||||
libraryId!: number;
|
||||
presetMode: PresetMode = 'balanced';
|
||||
showAdvanced = false;
|
||||
|
||||
matchByIsbn = true;
|
||||
matchByExternalId = true;
|
||||
matchByTitleAuthor = true;
|
||||
matchByDirectory = false;
|
||||
matchByFilename = false;
|
||||
|
||||
isScanning = false;
|
||||
isMerging = false;
|
||||
hasScanned = false;
|
||||
moveFiles = false;
|
||||
mergeProgress = 0;
|
||||
mergeTotal = 0;
|
||||
|
||||
groups: DisplayGroup[] = [];
|
||||
presetOptions: { label: string; value: PresetMode }[] = [];
|
||||
|
||||
pageFirst = 0;
|
||||
pageSize = 20;
|
||||
|
||||
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;
|
||||
|
||||
const settings = this.appSettingsService.appSettings();
|
||||
if (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'},
|
||||
{label: this.t.translate('book.duplicateMerger.presetAggressive'), value: 'aggressive'},
|
||||
{label: this.t.translate('book.duplicateMerger.presetCustom'), value: 'custom'},
|
||||
];
|
||||
this.applyPreset('balanced');
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
}
|
||||
|
||||
onPresetChange(): void {
|
||||
if (this.presetMode !== 'custom') {
|
||||
this.applyPreset(this.presetMode);
|
||||
}
|
||||
}
|
||||
|
||||
onSignalToggle(): void {
|
||||
this.presetMode = 'custom';
|
||||
}
|
||||
|
||||
applyPreset(mode: PresetMode): void {
|
||||
switch (mode) {
|
||||
case 'strict':
|
||||
this.matchByIsbn = true;
|
||||
this.matchByExternalId = true;
|
||||
this.matchByTitleAuthor = false;
|
||||
this.matchByDirectory = false;
|
||||
this.matchByFilename = false;
|
||||
break;
|
||||
case 'balanced':
|
||||
this.matchByIsbn = true;
|
||||
this.matchByExternalId = true;
|
||||
this.matchByTitleAuthor = true;
|
||||
this.matchByDirectory = false;
|
||||
this.matchByFilename = false;
|
||||
break;
|
||||
case 'aggressive':
|
||||
this.matchByIsbn = true;
|
||||
this.matchByExternalId = true;
|
||||
this.matchByTitleAuthor = true;
|
||||
this.matchByDirectory = true;
|
||||
this.matchByFilename = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
scan(): void {
|
||||
this.isScanning = true;
|
||||
this.hasScanned = false;
|
||||
this.groups = [];
|
||||
this.pageFirst = 0;
|
||||
|
||||
const request: DuplicateDetectionRequest = {
|
||||
libraryId: this.libraryId,
|
||||
matchByIsbn: this.matchByIsbn,
|
||||
matchByExternalId: this.matchByExternalId,
|
||||
matchByTitleAuthor: this.matchByTitleAuthor,
|
||||
matchByDirectory: this.matchByDirectory,
|
||||
matchByFilename: this.matchByFilename,
|
||||
};
|
||||
|
||||
this.bookFileService.findDuplicates(request).pipe(
|
||||
takeUntil(this.destroy$)
|
||||
).subscribe({
|
||||
next: (groups) => {
|
||||
this.groups = groups.map(g => ({
|
||||
...g,
|
||||
selectedTargetBookId: g.suggestedTargetBookId,
|
||||
dismissed: false,
|
||||
selectedForDeletion: new Set<number>(),
|
||||
}));
|
||||
this.isScanning = false;
|
||||
this.hasScanned = true;
|
||||
},
|
||||
error: (err) => {
|
||||
this.isScanning = false;
|
||||
this.hasScanned = true;
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('book.duplicateMerger.toast.scanFailedSummary'),
|
||||
detail: err?.error?.message || this.t.translate('book.duplicateMerger.toast.scanFailedDetail'),
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get activeGroups(): DisplayGroup[] {
|
||||
return this.groups.filter(g => !g.dismissed);
|
||||
}
|
||||
|
||||
get pagedGroups(): DisplayGroup[] {
|
||||
return this.activeGroups.slice(this.pageFirst, this.pageFirst + this.pageSize);
|
||||
}
|
||||
|
||||
get canScan(): boolean {
|
||||
return !this.isScanning && !this.isMerging &&
|
||||
(this.matchByIsbn || this.matchByExternalId || this.matchByTitleAuthor ||
|
||||
this.matchByDirectory || this.matchByFilename);
|
||||
}
|
||||
|
||||
onPageChange(event: any): void {
|
||||
this.pageFirst = event.first;
|
||||
this.pageSize = event.rows;
|
||||
}
|
||||
|
||||
getBookFormats(book: Book): string[] {
|
||||
const formats: string[] = [];
|
||||
if (book.primaryFile?.bookType) {
|
||||
formats.push(book.primaryFile.bookType);
|
||||
}
|
||||
if (book.alternativeFormats) {
|
||||
for (const alt of book.alternativeFormats) {
|
||||
if (alt.bookType) {
|
||||
formats.push(alt.bookType);
|
||||
}
|
||||
}
|
||||
}
|
||||
return formats;
|
||||
}
|
||||
|
||||
getFileCount(book: Book): number {
|
||||
let count = book.primaryFile ? 1 : 0;
|
||||
count += book.alternativeFormats?.length ?? 0;
|
||||
return count;
|
||||
}
|
||||
|
||||
getMatchReasonLabel(reason: string): string {
|
||||
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':
|
||||
case 'EXTERNAL_ID':
|
||||
return 'success';
|
||||
case 'TITLE_AUTHOR':
|
||||
return 'info';
|
||||
case 'DIRECTORY':
|
||||
return 'warn';
|
||||
case 'FILENAME':
|
||||
return 'secondary';
|
||||
default:
|
||||
return 'info';
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
this.pageFirst = Math.max(0, this.pageFirst - this.pageSize);
|
||||
}
|
||||
}
|
||||
|
||||
async mergeGroup(group: DisplayGroup): Promise<void> {
|
||||
const targetId = group.selectedTargetBookId;
|
||||
const sourceIds = group.books
|
||||
.filter(b => b.id !== targetId)
|
||||
.map(b => b.id);
|
||||
|
||||
if (sourceIds.length === 0) return;
|
||||
|
||||
group.dismissed = true;
|
||||
try {
|
||||
await this.bookFileService.attachBookFiles(targetId, sourceIds, this.moveFiles)
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
.toPromise();
|
||||
} catch {
|
||||
group.dismissed = false;
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('book.duplicateMerger.toast.mergeFailedSummary'),
|
||||
detail: this.t.translate('book.duplicateMerger.toast.mergeFailedDetail'),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async mergeAll(): Promise<void> {
|
||||
const toMerge = this.activeGroups;
|
||||
if (toMerge.length === 0) return;
|
||||
|
||||
this.isMerging = true;
|
||||
this.mergeTotal = toMerge.length;
|
||||
this.mergeProgress = 0;
|
||||
|
||||
let successCount = 0;
|
||||
let failCount = 0;
|
||||
|
||||
for (const group of toMerge) {
|
||||
const targetId = group.selectedTargetBookId;
|
||||
const sourceIds = group.books
|
||||
.filter(b => b.id !== targetId)
|
||||
.map(b => b.id);
|
||||
|
||||
if (sourceIds.length === 0) {
|
||||
group.dismissed = true;
|
||||
this.mergeProgress++;
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
await this.bookFileService.attachBookFiles(targetId, sourceIds, this.moveFiles)
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
.toPromise();
|
||||
group.dismissed = true;
|
||||
successCount++;
|
||||
} catch {
|
||||
failCount++;
|
||||
}
|
||||
this.mergeProgress++;
|
||||
}
|
||||
|
||||
this.isMerging = false;
|
||||
|
||||
if (successCount > 0) {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('book.duplicateMerger.toast.mergeSuccessSummary'),
|
||||
detail: this.t.translate('book.duplicateMerger.toast.mergeSuccessDetail', {count: successCount}),
|
||||
});
|
||||
}
|
||||
if (failCount > 0) {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('book.duplicateMerger.toast.mergeFailedSummary'),
|
||||
detail: this.t.translate('book.duplicateMerger.toast.mergePartialDetail', {success: successCount, failed: failCount}),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user