Organize code

This commit is contained in:
aditya.chandel
2025-10-12 02:09:57 -06:00
parent 7c9bd56f63
commit 4453115149
50 changed files with 30 additions and 30 deletions
@@ -9,9 +9,9 @@ import {AppSettingsService} from '../../../../shared/service/app-settings.servic
import {Tab, TabList, TabPanel, TabPanels, Tabs,} from 'primeng/tabs';
import {DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog';
import {BookMetadataHostService} from '../../../../shared/service/book-metadata-host-service';
import {MetadataViewerComponent} from './metadata-viewer-component/metadata-viewer.component';
import {MetadataEditorComponent} from './metadata-editor-component/metadata-editor.component';
import {MetadataSearcherComponent} from './metadata-searcher-component/metadata-searcher.component';
import {MetadataViewerComponent} from './metadata-viewer/metadata-viewer.component';
import {MetadataEditorComponent} from './metadata-editor/metadata-editor.component';
import {MetadataSearcherComponent} from './metadata-searcher/metadata-searcher.component';
@Component({
selector: 'app-book-metadata-center',
@@ -23,7 +23,7 @@ import {Textarea} from "primeng/textarea";
import {IftaLabel} from "primeng/iftalabel";
import {Image} from "primeng/image";
import {LazyLoadImageModule} from "ng-lazyload-image";
import {CoverSearchComponent} from '../../cover-search-component/cover-search.component';
import {CoverSearchComponent} from '../../cover-search/cover-search.component';
@Component({
selector: "app-metadata-editor",
@@ -16,7 +16,7 @@ import {BehaviorSubject, combineLatest, Observable, Subject, Subscription, takeU
import {distinctUntilChanged, filter, switchMap} from 'rxjs/operators';
import {ActivatedRoute} from '@angular/router';
import {AsyncPipe} from '@angular/common';
import {MetadataPickerComponent} from '../metadata-picker-component/metadata-picker.component';
import {MetadataPickerComponent} from '../metadata-picker/metadata-picker.component';
@Component({
selector: 'app-metadata-searcher',
@@ -36,7 +36,7 @@ import {AdditionalFileUploaderComponent} from '../../../../book/components/addit
import {Image} from 'primeng/image';
import {BookDialogHelperService} from '../../../../book/components/book-browser/BookDialogHelperService';
import {TagColor, TagComponent} from '../../../../../shared/components/tag/tag.component';
import {MetadataFetchOptionsComponent} from '../../metadata-options-dialog/metadata-fetch-options-component/metadata-fetch-options.component';
import {MetadataFetchOptionsComponent} from '../../metadata-options-dialog/metadata-fetch-options/metadata-fetch-options.component';
import {BookNotesComponent} from '../../../../book/components/book-notes/book-notes-component';
@Component({
@@ -0,0 +1,364 @@
<div class="main-container enclosing-container">
<div class="settings-header">
<h2 class="settings-title">
<i class="pi pi-sitemap"></i>
Metadata Manager
<app-external-doc-link docType="metadataManager"></app-external-doc-link>
</h2>
<p class="settings-description">
Organize, merge, split, rename, and standardize authors, genres, moods, and tags across your library.
</p>
</div>
<div class="settings-content">
<p-tabs [(value)]="activeTab">
<p-tablist>
@for (tab of tabConfigs; track tab.type) {
<p-tab [value]="tab.type">
<i class="pi {{ tab.icon }}"></i> {{ tab.label }}s ({{ getMetadataItems(tab.type).length }})
</p-tab>
}
</p-tablist>
<p-tabpanels>
@for (tab of tabConfigs; track tab.type) {
<p-tabpanel [value]="tab.type">
<div class="section-header">
<p-iconfield class="search-input">
<p-inputicon class="pi pi-search"/>
<input
pInputText
type="text"
#tableFilter
(input)="filterGlobal($event, dataTable)"
[placeholder]="tab.placeholder"/>
</p-iconfield>
<div class="actions">
<p-button
label="Clear Selection"
icon="pi pi-times"
[disabled]="getSelectedItems(tab.type).length === 0"
(onClick)="clearSelection(tab.type)"
severity="secondary"
size="small"
outlined></p-button>
<p-button
label="Delete Selected"
icon="pi pi-trash"
[disabled]="getSelectedItems(tab.type).length === 0"
(onClick)="openDeleteDialog(tab.type)"
severity="danger"
size="small"
outlined></p-button>
<p-button
label="Merge/Split Selected"
icon="pi pi-sitemap"
[disabled]="getSelectedItems(tab.type).length < 2"
(onClick)="openMergeDialog(tab.type)"
severity="success"
size="small"
outlined></p-button>
</div>
</div>
<div class="table-card">
<p-table
#dataTable
[value]="getMetadataItems(tab.type)"
[loading]="loading"
[globalFilterFields]="['value']"
[paginator]="true"
[rows]="50"
[rowsPerPageOptions]="[25, 50, 100]"
[scrollable]="true"
scrollHeight="flex">
<ng-template pTemplate="header">
<tr>
<th style="width: 3rem">
<div class="header-content">
<p-checkbox
[binary]="true"
[ngModel]="getSelectAll(tab.selectAllKey)"
(ngModelChange)="setSelectAll(tab.selectAllKey, $event); toggleAll(tab.type, $event, dataTable.filteredValue || dataTable.value)"></p-checkbox>
</div>
</th>
<th pSortableColumn="value">
<div class="header-content">
<i class="pi {{ tab.icon }}"></i>
<span>{{ tab.label }}</span>
<p-sortIcon field="value"></p-sortIcon>
</div>
</th>
<th pSortableColumn="count">
<div class="header-content">
<i class="pi pi-book"></i>
<span>Books</span>
<p-sortIcon field="count"></p-sortIcon>
</div>
</th>
<th class="actions-header">
<div class="header-content">
<i class="pi pi-cog"></i>
<span>Actions</span>
</div>
</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-item>
<tr>
<td>
<p-checkbox
[(ngModel)]="item.selected"
[binary]="true"
(ngModelChange)="onRowSelect(tab.type)"></p-checkbox>
</td>
<td>
<span class="clickable-cell" (click)="onMetadataClick(tab.type, item.value)">
{{ item.value }}
</span>
</td>
<td>{{ item.count }}</td>
<td class="actions-cell">
<p-button
icon="pi pi-filter"
severity="info"
size="small"
[outlined]="true"
[rounded]="true"
pTooltip="Select similar"
(onClick)="selectSimilar(tab.type, item.value)"></p-button>
<p-button
icon="pi pi-pencil"
severity="secondary"
size="small"
[outlined]="true"
[rounded]="true"
pTooltip="Rename/Split"
(onClick)="openRenameDialog(tab.type, item)"></p-button>
<p-button
icon="pi pi-trash"
severity="danger"
size="small"
[outlined]="true"
[rounded]="true"
pTooltip="Delete"
(onClick)="openDeleteDialog(tab.type, item)"></p-button>
</td>
</tr>
</ng-template>
</p-table>
</div>
</p-tabpanel>
}
</p-tabpanels>
</p-tabs>
</div>
<p-dialog
header="Merge/Split {{ currentMergeType | titlecase }}"
[(visible)]="showMergeDialog"
[modal]="true"
styleClass="user-dialog"
[style]="{width: '50rem'}">
<div class="dialog-form">
<p>You are merging/splitting {{ getSelectedItems(currentMergeType).length }} {{ currentMergeType }}:</p>
<ul class="selected-items">
@for (item of getSelectedItems(currentMergeType); track item.value) {
<li>
• {{ item.value }} <span class="count">({{ item.count }} books)</span>
</li>
}
</ul>
<div class="form-field">
<label for="mergeTarget">Target Value{{ isSingleValueField(currentMergeType) ? '' : '(s)' }}:</label>
<input
id="mergeTarget"
type="text"
pInputText
[(ngModel)]="mergeTarget"
class="w-full"
[placeholder]="isSingleValueField(currentMergeType) ? 'e.g., English' : 'e.g., Fiction, Mystery, Thriller'"/>
@if (isSingleValueField(currentMergeType)) {
<small class="help-text">
<strong>How it works:</strong><br/>
• Enter the standardized value you want all selected items to merge into<br/>
• All books with any of the selected {{ currentMergeType }} will be updated to use this single value<br/>
<br/>
<strong>Example:</strong> When merging "En", "English", "en-US"<br/>
• Enter "English" → All books will have their {{ currentMergeType.slice(0, -1) }} merged to "English"<br/>
<br/>
<strong>Note:</strong> Each book can only have one {{ currentMergeType.slice(0, -1) }}, so only enter one target value.
</small>
} @else {
<small class="help-text">
<strong>How it works:</strong><br/>
• Enter a single value to merge all selected {{ currentMergeType }} into one<br/>
• Enter multiple values separated by commas to split into multiple {{ currentMergeType }}<br/>
<br/>
<strong>Example:</strong> When merging/splitting "Sci-Fi", "SciFi", "Science Fiction"<br/>
• Merge: Enter "Science Fiction" → All books get one standardized tag<br/>
• Split: Enter "Science Fiction, Sci-Fi" → All books get both the formal name and common abbreviation
</small>
}
</div>
@if (mergingInProgress) {
<div class="processing-note">
<i class="pi pi-info-circle"></i>
<span>This process may take longer if "Write to file" is enabled in the settings.</span>
</div>
}
</div>
<ng-template pTemplate="footer">
<div class="dialog-actions">
<p-button
label="Cancel"
icon="pi pi-times"
(onClick)="showMergeDialog = false"
[disabled]="mergingInProgress"
severity="secondary"
outlined></p-button>
<p-button
[label]="mergingInProgress ? 'Processing...' : 'Confirm'"
[icon]="mergingInProgress ? 'pi pi-spin pi-spinner' : 'pi pi-check'"
[loading]="mergingInProgress"
[disabled]="mergingInProgress"
(onClick)="confirmMerge()"
severity="success"></p-button>
</div>
</ng-template>
</p-dialog>
<p-dialog
header="Rename/Split {{ currentMergeType | titlecase }}"
[(visible)]="showRenameDialog"
[modal]="true"
styleClass="user-dialog"
[style]="{width: '40rem'}">
<div class="dialog-form">
<p>You are renaming/splitting:</p>
<div class="current-value">
<strong>{{ currentRenameItem?.value }}</strong>
<span class="count">({{ currentRenameItem?.count }} books)</span>
</div>
<div class="form-field">
<label for="renameTarget">New Name(s):</label>
<input
id="renameTarget"
type="text"
pInputText
[(ngModel)]="renameTarget"
class="w-full"
[placeholder]="isSingleValueField(currentMergeType) ? 'e.g., Mystery' : 'e.g., Mystery, Detective'"
(keyup.enter)="confirmRename()"/>
@if (isSingleValueField(currentMergeType)) {
<small class="help-text">
<strong>How it works:</strong><br/>
• Enter a new value to rename this {{ currentMergeType.slice(0, -1) }}<br/>
<br/>
<strong>Note:</strong> Each book can only have one {{ currentMergeType.slice(0, -1) }}, so splitting into multiple values is not allowed.
</small>
} @else {
<small class="help-text">
<strong>How it works:</strong><br/>
• Enter a single value to rename the {{ currentMergeType.slice(0, -1) }}<br/>
• Enter multiple values separated by commas to split into multiple {{ currentMergeType }}<br/>
<br/>
<strong>Example:</strong> When renaming/splitting "Mystery & Detective"<br/>
• Rename: Enter "Mystery" → Renames to just "Mystery"<br/>
• Split: Enter "Mystery, Detective" → Splits into two separate {{ currentMergeType }}
</small>
}
</div>
@if (mergingInProgress) {
<div class="processing-note">
<i class="pi pi-info-circle"></i>
<span>This process may take some time if "Write to file" is enabled in settings.</span>
</div>
}
</div>
<ng-template pTemplate="footer">
<div class="dialog-actions">
<p-button
label="Cancel"
icon="pi pi-times"
(onClick)="showRenameDialog = false"
[disabled]="mergingInProgress"
severity="secondary"
outlined></p-button>
<p-button
[label]="mergingInProgress ? 'Processing...' : 'Confirm'"
[icon]="mergingInProgress ? 'pi pi-spin pi-spinner' : 'pi pi-check'"
[loading]="mergingInProgress"
[disabled]="mergingInProgress"
(onClick)="confirmRename()"
severity="success"></p-button>
</div>
</ng-template>
</p-dialog>
<p-dialog
header="Delete {{ currentMergeType | titlecase }}"
[(visible)]="showDeleteDialog"
[modal]="true"
styleClass="user-dialog"
[style]="{width: '40rem'}">
<div class="dialog-form">
<div class="warning-message">
<i class="pi pi-exclamation-triangle"></i>
<p>You are about to delete {{ currentDeleteItem ? '1' : getSelectedItems(currentMergeType).length }} {{ currentMergeType }}:</p>
</div>
@if (currentDeleteItem) {
<div class="current-value">
<strong>{{ currentDeleteItem.value }}</strong>
<span class="count">({{ currentDeleteItem.count }} books)</span>
</div>
} @else {
<ul class="selected-items">
@for (item of getSelectedItems(currentMergeType); track item.value) {
<li>
• {{ item.value }} <span class="count">({{ item.count }} books)</span>
</li>
}
</ul>
}
<div class="delete-info">
<p><strong>What will happen:</strong></p>
<ul>
<li>The {{ currentMergeType.slice(0, -1) }} will be removed from all affected books</li>
<li>This action cannot be undone</li>
<li>Total books affected: <strong>{{ currentDeleteItem ? currentDeleteItem.count : getTotalAffectedBooks(getSelectedItems(currentMergeType)) }}</strong></li>
</ul>
</div>
@if (deletingInProgress) {
<div class="processing-note">
<i class="pi pi-info-circle"></i>
<span>This process may take some time if "Write to file" is enabled in settings.</span>
</div>
}
</div>
<ng-template pTemplate="footer">
<div class="dialog-actions">
<p-button
label="Cancel"
icon="pi pi-times"
(onClick)="showDeleteDialog = false"
[disabled]="deletingInProgress"
severity="secondary"
outlined></p-button>
<p-button
[label]="deletingInProgress ? 'Deleting...' : 'Delete'"
[icon]="deletingInProgress ? 'pi pi-spin pi-spinner' : 'pi pi-trash'"
[loading]="deletingInProgress"
[disabled]="deletingInProgress"
(onClick)="confirmDelete()"
severity="danger"></p-button>
</div>
</ng-template>
</p-dialog>
</div>
@@ -0,0 +1,449 @@
.metadata-manager {
padding: 1.5rem;
display: flex;
flex-direction: column;
height: 100%;
h2 {
margin-bottom: 0.5rem;
}
.description {
color: var(--text-color-secondary);
margin-bottom: 1.5rem;
}
.table-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 1rem;
gap: 1rem;
.actions {
display: flex;
gap: 0.5rem;
}
}
.table-container {
display: flex;
flex-direction: column;
flex: 1;
min-height: 0;
}
::ng-deep {
.p-tabs {
display: flex;
flex-direction: column;
flex: 1;
min-height: 0;
}
.p-tabpanels {
flex: 1;
min-height: 0;
display: flex;
flex-direction: column;
}
.p-tabpanel {
display: none;
&.p-tabpanel-active {
display: flex;
flex-direction: column;
height: 100%;
flex: 1;
}
}
.p-datatable-tbody > tr > td {
padding-top: 0.5rem;
padding-bottom: 0.5rem;
vertical-align: top;
}
.p-datatable-table {
align-self: flex-start;
width: 100%;
}
.p-datatable-thead > tr > th .header-content {
display: flex;
align-items: center;
gap: 0.5rem;
}
}
}
.merge-dialog-content {
.selected-items {
max-height: 200px;
overflow-y: auto;
margin: 1rem 0;
padding-left: 1.5rem;
li {
margin-bottom: 0.5rem;
.count {
color: var(--text-color-secondary);
font-size: 0.875rem;
}
}
}
.field {
margin-top: 1.5rem;
label {
display: block;
margin-bottom: 0.5rem;
font-weight: 600;
}
small {
display: block;
margin-top: 0.5rem;
color: var(--text-color-secondary);
}
}
}
.main-container {
width: 100%;
padding: 1rem;
height: calc(100dvh - 10.5rem);
border-width: 1px;
border-radius: 0.5rem;
display: flex;
flex-direction: column;
@media (min-width: 768px) {
height: calc(100dvh - 6.125rem);
}
}
.enclosing-container {
border-color: var(--p-content-border-color);
background: var(--p-content-background);
}
.settings-header {
margin-top: 1rem;
flex-shrink: 0;
}
.settings-title {
display: flex;
align-items: center;
gap: 0.75rem;
font-size: 1.25rem;
font-weight: 700;
color: var(--p-text-color);
margin: 0 0 0.75rem 0;
.pi {
color: var(--p-primary-color);
font-size: 1.25rem;
}
}
.settings-description {
opacity: 0.7;
font-size: 0.875rem;
line-height: 1.5;
margin-bottom: 1rem;
}
.settings-content {
display: flex;
flex-direction: column;
gap: 1rem;
flex: 1;
min-height: 0;
overflow-y: auto;
@media (min-width: 768px) {
padding: 0.5rem 1rem 0 1rem;
}
}
.section-header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 1rem;
margin-bottom: 1rem;
flex-shrink: 0;
.actions {
display: flex;
gap: 0.5rem;
flex-shrink: 0;
}
}
.section-title-group {
display: flex;
align-items: center;
justify-content: flex-end;
margin-bottom: 1rem;
.actions {
display: flex;
gap: 0.5rem;
}
}
.search-input {
flex: 1;
max-width: 400px;
}
.table-card {
border: 1px solid rgba(128, 128, 128, 0.2);
border-radius: 8px;
overflow: hidden;
background: var(--surface-ground);
display: flex;
flex-direction: column;
flex: 1;
min-height: 0;
.p-datatable {
display: flex;
flex-direction: column;
height: 100%;
.p-datatable-wrapper {
flex: 1;
overflow-y: auto;
display: flex;
flex-direction: column;
align-items: flex-start;
}
.p-paginator {
border-top: 1px solid var(--p-datatable-body-cell-border-color);
}
}
}
.actions-header {
min-width: 120px;
.header-content {
justify-content: center;
}
}
.actions-cell {
display: flex;
gap: 0.5rem;
align-items: center;
justify-content: center;
p-button {
display: inline-flex;
}
}
.clickable-cell {
cursor: pointer;
transition: color 0.2s;
&:hover {
color: var(--p-primary-color);
text-decoration: underline;
}
}
::ng-deep {
.p-tabs {
display: flex;
flex-direction: column;
flex: 1;
min-height: 0;
}
.p-tabpanels {
flex: 1;
min-height: 0;
display: flex;
flex-direction: column;
}
.p-tabpanel {
display: none;
&.p-tabpanel-active {
display: flex;
flex-direction: column;
height: 100%;
flex: 1;
}
}
.p-datatable-tbody > tr > td {
padding-top: 0.5rem;
padding-bottom: 0.5rem;
vertical-align: top;
}
.p-datatable-table {
align-self: flex-start;
width: 100%;
}
.p-datatable-thead > tr > th .header-content {
display: flex;
align-items: center;
gap: 0.5rem;
}
}
.user-dialog {
.p-dialog-content {
padding: 1.5rem;
}
.p-dialog-footer {
padding: 1rem 1.5rem;
}
}
.dialog-form {
display: flex;
flex-direction: column;
gap: 1.5rem;
.warning-message {
display: flex;
align-items: center;
gap: 0.75rem;
padding: 1rem;
background: rgba(251, 146, 60, 0.15);
border: 1px solid var(--p-orange-500);
border-radius: 8px;
color: var(--p-text-color);
.pi-exclamation-triangle {
font-size: 1.5rem;
color: var(--p-orange-500);
}
p {
margin: 0;
font-weight: 500;
}
}
.delete-info {
padding: 1rem;
background: var(--surface-ground);
border-radius: 8px;
border: 1px solid rgba(128, 128, 128, 0.2);
p {
margin: 0 0 0.5rem 0;
font-weight: 600;
color: var(--p-text-color);
}
ul {
margin: 0;
padding-left: 1.5rem;
list-style-type: disc;
li {
margin-bottom: 0.25rem;
color: var(--p-text-color);
strong {
color: var(--p-primary-color);
}
}
}
}
.selected-items {
max-height: 200px;
overflow-y: auto;
margin: 0;
padding-left: 1.5rem;
li {
margin-bottom: 0.5rem;
color: var(--p-text-color);
.count {
opacity: 0.7;
font-size: 0.875rem;
}
}
}
.current-value {
padding: 1rem;
background: var(--surface-ground);
border: 1px solid rgba(128, 128, 128, 0.2);
border-radius: 8px;
margin-bottom: 1.5rem;
display: flex;
align-items: center;
gap: 0.5rem;
strong {
font-size: 1.1rem;
color: var(--p-primary-color);
}
.count {
opacity: 0.7;
font-size: 0.9rem;
}
}
.form-field {
display: flex;
flex-direction: column;
gap: 0.5rem;
label {
font-weight: 600;
color: var(--p-text-color);
font-size: 0.875rem;
}
small {
opacity: 0.7;
}
}
}
.dialog-actions {
display: flex;
justify-content: flex-end;
gap: 0.75rem;
}
.processing-note {
display: flex;
align-items: center;
gap: 0.5rem;
padding: 0.75rem;
margin-top: 1rem;
border-left: 3px solid #f59e0b;
border-top: 1px solid #f59e0b;
border-bottom: 1px solid #f59e0b;
border-right: 1px solid #f59e0b;
border-radius: 4px;
font-size: 0.875rem;
i {
font-size: 1rem;
}
}
@@ -0,0 +1,590 @@
import {Component, inject, OnDestroy, OnInit} from '@angular/core';
import {CommonModule} from '@angular/common';
import {Tab, TabList, TabPanel, TabPanels, Tabs} from 'primeng/tabs';
import {TableModule} from 'primeng/table';
import {ButtonModule} from 'primeng/button';
import {CheckboxModule} from 'primeng/checkbox';
import {InputTextModule} from 'primeng/inputtext';
import {DialogModule} from 'primeng/dialog';
import {ConfirmDialogModule} from 'primeng/confirmdialog';
import {ConfirmationService, MessageService} from 'primeng/api';
import {BookService} from '../../../book/service/book.service';
import {Book} from '../../../book/model/book.model';
import {FormsModule} from '@angular/forms';
import {Tooltip} from 'primeng/tooltip';
import {IconField} from 'primeng/iconfield';
import {InputIcon} from 'primeng/inputicon';
import {ActivatedRoute, Router} from '@angular/router';
import {Subscription} from 'rxjs';
import {ExternalDocLinkComponent} from '../../../../shared/components/external-doc-link/external-doc-link.component';
interface MetadataItem {
value: string;
count: number;
bookIds: number[];
selected: boolean;
}
type MetadataType = 'authors' | 'categories' | 'moods' | 'tags' | 'series' | 'publishers' | 'languages';
interface TabConfig {
type: MetadataType;
label: string;
placeholder: string;
selectAllKey: 'selectAllAuthors' | 'selectAllCategories' | 'selectAllMoods' | 'selectAllTags' | 'selectAllSeries' | 'selectAllPublishers' | 'selectAllLanguages';
icon: string;
}
@Component({
selector: 'app-metadata-manager',
standalone: true,
imports: [
CommonModule,
FormsModule,
Tabs,
TableModule,
ButtonModule,
CheckboxModule,
InputTextModule,
DialogModule,
ConfirmDialogModule,
TabList,
Tab,
TabPanels,
TabPanel,
Tooltip,
IconField,
InputIcon,
ExternalDocLinkComponent
],
providers: [ConfirmationService],
templateUrl: './metadata-manager.component.html',
styleUrls: ['./metadata-manager.component.scss']
})
export class MetadataManagerComponent implements OnInit, OnDestroy {
private bookService = inject(BookService);
private messageService = inject(MessageService);
private confirmationService = inject(ConfirmationService);
private router = inject(Router);
private route = inject(ActivatedRoute);
private routeSub!: Subscription;
authors: MetadataItem[] = [];
categories: MetadataItem[] = [];
moods: MetadataItem[] = [];
tags: MetadataItem[] = [];
series: MetadataItem[] = [];
publishers: MetadataItem[] = [];
languages: MetadataItem[] = [];
selectAllAuthors = false;
selectAllCategories = false;
selectAllMoods = false;
selectAllTags = false;
selectAllSeries = false;
selectAllPublishers = false;
selectAllLanguages = false;
loading = false;
mergingInProgress = false;
deletingInProgress = false;
showMergeDialog = false;
showRenameDialog = false;
showDeleteDialog = false;
mergeTarget = '';
renameTarget = '';
currentMergeType: MetadataType = 'authors';
currentRenameItem: MetadataItem | null = null;
currentDeleteItem: MetadataItem | null = null;
private validTabs: MetadataType[] = ['authors', 'categories', 'moods', 'tags', 'series', 'publishers', 'languages'];
private _activeTab: MetadataType = 'authors';
get activeTab(): MetadataType {
return this._activeTab;
}
set activeTab(value: MetadataType) {
this._activeTab = value;
this.router.navigate([], {
relativeTo: this.route,
queryParams: {tab: value},
queryParamsHandling: 'merge'
});
}
tabConfigs: TabConfig[] = [
{type: 'authors', label: 'Author', placeholder: 'Search authors...', selectAllKey: 'selectAllAuthors', icon: 'pi-user'},
{type: 'categories', label: 'Genre', placeholder: 'Search genres...', selectAllKey: 'selectAllCategories', icon: 'pi-tag'},
{type: 'moods', label: 'Mood', placeholder: 'Search moods...', selectAllKey: 'selectAllMoods', icon: 'pi-heart'},
{type: 'tags', label: 'Tag', placeholder: 'Search tags...', selectAllKey: 'selectAllTags', icon: 'pi-tags'},
{type: 'series', label: 'Series', placeholder: 'Search series...', selectAllKey: 'selectAllSeries', icon: 'pi-book'},
{type: 'publishers', label: 'Publisher', placeholder: 'Search publishers...', selectAllKey: 'selectAllPublishers', icon: 'pi-building'},
{type: 'languages', label: 'Language', placeholder: 'Search languages...', selectAllKey: 'selectAllLanguages', icon: 'pi-globe'}
];
ngOnInit() {
this.loadMetadata();
this.routeSub = this.route.queryParams.subscribe(params => {
const tabParam = params['tab'] as MetadataType;
if (this.validTabs.includes(tabParam)) {
this._activeTab = tabParam;
} else {
this._activeTab = 'authors';
this.router.navigate([], {
relativeTo: this.route,
queryParams: {tab: this._activeTab},
queryParamsHandling: 'merge',
replaceUrl: true
});
}
});
}
ngOnDestroy(): void {
this.routeSub.unsubscribe();
}
loadMetadata() {
this.loading = true;
this.bookService.bookState$.subscribe(state => {
if (state.loaded && state.books) {
this.extractMetadata(state.books);
this.loading = false;
}
});
}
private extractMetadata(books: Book[]) {
const authorsMap = new Map<string, Set<number>>();
const categoriesMap = new Map<string, Set<number>>();
const moodsMap = new Map<string, Set<number>>();
const tagsMap = new Map<string, Set<number>>();
const seriesMap = new Map<string, Set<number>>();
const publishersMap = new Map<string, Set<number>>();
const languagesMap = new Map<string, Set<number>>();
books.forEach(book => {
if (book.metadata) {
this.addToMap(authorsMap, book.metadata.authors, book.id);
this.addToMap(categoriesMap, book.metadata.categories, book.id);
this.addToMap(moodsMap, book.metadata.moods, book.id);
this.addToMap(tagsMap, book.metadata.tags, book.id);
if (book.metadata.seriesName) {
this.addToMap(seriesMap, [book.metadata.seriesName], book.id);
}
if (book.metadata.publisher) {
this.addToMap(publishersMap, [book.metadata.publisher], book.id);
}
if (book.metadata.language) {
this.addToMap(languagesMap, [book.metadata.language], book.id);
}
}
});
this.authors = this.mapToItems(authorsMap);
this.categories = this.mapToItems(categoriesMap);
this.moods = this.mapToItems(moodsMap);
this.tags = this.mapToItems(tagsMap);
this.series = this.mapToItems(seriesMap);
this.publishers = this.mapToItems(publishersMap);
this.languages = this.mapToItems(languagesMap);
}
private addToMap(map: Map<string, Set<number>>, values: string[] | undefined, bookId: number) {
if (!values) return;
values.forEach(value => {
if (!map.has(value)) {
map.set(value, new Set());
}
map.get(value)!.add(bookId);
});
}
private mapToItems(map: Map<string, Set<number>>): MetadataItem[] {
return Array.from(map.entries())
.map(([value, bookIds]) => ({
value,
count: bookIds.size,
bookIds: Array.from(bookIds),
selected: false
}))
.sort((a, b) => b.count - a.count);
}
getSelectedItems(type: MetadataType): MetadataItem[] {
return this[type].filter(item => item.selected);
}
openMergeDialog(type: MetadataType) {
const selected = this.getSelectedItems(type);
if (selected.length < 2) {
this.messageService.add({
severity: 'warn',
summary: 'Invalid Selection',
detail: 'Please select at least 2 items to merge.'
});
return;
}
this.currentMergeType = type;
this.mergeTarget = selected[0].value;
this.showMergeDialog = true;
}
openRenameDialog(type: MetadataType, item: MetadataItem) {
this.currentMergeType = type;
this.currentRenameItem = item;
this.renameTarget = item.value;
this.showRenameDialog = true;
}
openDeleteDialog(type: MetadataType, item?: MetadataItem) {
if (item) {
this.currentMergeType = type;
this.currentDeleteItem = item;
this.showDeleteDialog = true;
} else {
const selected = this.getSelectedItems(type);
if (selected.length === 0) {
this.messageService.add({
severity: 'warn',
summary: 'Invalid Selection',
detail: 'Please select at least 1 item to delete.'
});
return;
}
this.currentMergeType = type;
this.currentDeleteItem = null;
this.showDeleteDialog = true;
}
}
confirmRename() {
if (!this.currentRenameItem || !this.renameTarget.trim()) {
this.messageService.add({
severity: 'warn',
summary: 'Invalid Target',
detail: 'Please enter a valid name.'
});
return;
}
const targetValues = this.renameTarget.split(',').map(v => v.trim()).filter(v => v.length > 0);
if (targetValues.length === 0) {
this.messageService.add({
severity: 'warn',
summary: 'Invalid Target',
detail: 'Please enter at least one valid target value.'
});
return;
}
if (this.isSingleValueField(this.currentMergeType) && targetValues.length > 1) {
this.messageService.add({
severity: 'warn',
summary: 'Invalid Target',
detail: `Each book can only have one ${this.currentMergeType.slice(0, -1)}. Please enter only one value.`
});
return;
}
if (targetValues.length === 1 && targetValues[0] === this.currentRenameItem.value) {
this.showRenameDialog = false;
return;
}
this.performRename(targetValues);
}
private performRename(targetValues: string[]) {
if (!this.currentRenameItem) return;
const oldValue = this.currentRenameItem.value;
const affectedBooks = this.currentRenameItem.count;
const action = targetValues.length === 1 ? 'renamed' : 'split';
const resultText = targetValues.length === 1
? `"${targetValues[0]}"`
: `${targetValues.length} values`;
this.loading = true;
this.mergingInProgress = true;
this.bookService.consolidateMetadata(this.currentMergeType, targetValues, [oldValue]).subscribe({
next: () => {
this.messageService.add({
severity: 'success',
summary: `${action === 'renamed' ? 'Rename' : 'Split'} Successful`,
detail: `Successfully ${action} "${oldValue}" ${action === 'renamed' ? 'to' : 'into'} ${resultText}. ${affectedBooks} book${affectedBooks > 1 ? 's' : ''} updated.`,
life: 5000
});
this.showRenameDialog = false;
this.currentRenameItem = null;
this.renameTarget = '';
this.mergingInProgress = false;
this.loading = false;
this.loadMetadata();
},
error: (error) => {
this.messageService.add({
severity: 'error',
summary: `${action === 'renamed' ? 'Rename' : 'Split'} Failed`,
detail: error?.error?.message || `An error occurred during ${action === 'renamed' ? 'rename' : 'split'}.`
});
this.loading = false;
this.mergingInProgress = false;
}
});
}
confirmMerge() {
const selected = this.getSelectedItems(this.currentMergeType);
if (!this.mergeTarget.trim()) {
this.messageService.add({
severity: 'warn',
summary: 'Invalid Target',
detail: 'Please enter a target value for merging.'
});
return;
}
const targetValues = this.mergeTarget.split(',').map(v => v.trim()).filter(v => v.length > 0);
if (targetValues.length === 0) {
this.messageService.add({
severity: 'warn',
summary: 'Invalid Target',
detail: 'Please enter at least one valid target value.'
});
return;
}
if (this.isSingleValueField(this.currentMergeType) && targetValues.length > 1) {
this.messageService.add({
severity: 'warn',
summary: 'Invalid Target',
detail: `Each book can only have one ${this.currentMergeType.slice(0, -1)}. Please enter only one target value to standardize to.`
});
return;
}
this.performMerge(targetValues);
}
private performMerge(targetValues: string[]) {
const selected = this.getSelectedItems(this.currentMergeType);
const valuesToMerge = selected.map(s => s.value);
const affectedBooks = this.getTotalAffectedBooks(selected);
const operation = targetValues.length === 1 ? 'merge' : 'merge/split';
const operationPast = targetValues.length === 1 ? 'merged' : 'merged/split';
this.loading = true;
this.mergingInProgress = true;
this.bookService.consolidateMetadata(this.currentMergeType, targetValues, valuesToMerge).subscribe({
next: () => {
this.messageService.add({
severity: 'success',
summary: `${operation === 'merge' ? 'Merge' : 'Merge/Split'} Successful`,
detail: `Successfully ${operationPast} ${selected.length} ${this.currentMergeType} into ${targetValues.length} value(s). ${affectedBooks} book${affectedBooks > 1 ? 's' : ''} updated.`,
life: 5000
});
this.showMergeDialog = false;
this.mergeTarget = '';
this.clearSelection(this.currentMergeType);
this.mergingInProgress = false;
this.loading = false;
this.loadMetadata();
},
error: (error) => {
this.messageService.add({
severity: 'error',
summary: `${operation === 'merge' ? 'Merge' : 'Merge/Split'} Failed`,
detail: error?.error?.message || `An error occurred during ${operation}.`
});
this.loading = false;
this.mergingInProgress = false;
}
});
}
confirmDelete() {
const itemsToDelete = this.currentDeleteItem
? [this.currentDeleteItem.value]
: this.getSelectedItems(this.currentMergeType).map(item => item.value);
if (itemsToDelete.length === 0) {
this.messageService.add({
severity: 'warn',
summary: 'Invalid Selection',
detail: 'Please select at least one item to delete.'
});
return;
}
this.performDelete(itemsToDelete);
}
private performDelete(valuesToDelete: string[]) {
const itemCount = valuesToDelete.length;
const affectedBooks = this.currentDeleteItem
? this.currentDeleteItem.count
: this.getTotalAffectedBooks(this.getSelectedItems(this.currentMergeType));
this.loading = true;
this.deletingInProgress = true;
this.bookService.deleteMetadata(this.currentMergeType, valuesToDelete).subscribe({
next: () => {
this.messageService.add({
severity: 'success',
summary: 'Delete Successful',
detail: `Successfully deleted ${itemCount} ${this.currentMergeType.slice(0, -1)}${itemCount > 1 ? 's' : ''}. ${affectedBooks} book${affectedBooks > 1 ? 's' : ''} updated.`,
life: 5000
});
this.showDeleteDialog = false;
this.currentDeleteItem = null;
this.clearSelection(this.currentMergeType);
this.deletingInProgress = false;
this.loading = false;
this.loadMetadata();
},
error: (error) => {
this.messageService.add({
severity: 'error',
summary: 'Delete Failed',
detail: error?.error?.message || 'An error occurred during deletion.'
});
this.loading = false;
this.deletingInProgress = false;
}
});
}
getMetadataItems(type: MetadataType): MetadataItem[] {
return this[type];
}
getSelectAll(key: TabConfig['selectAllKey']): boolean {
return this[key];
}
setSelectAll(key: TabConfig['selectAllKey'], value: boolean) {
this[key] = value;
}
toggleAll(type: MetadataType, checked: boolean, filteredItems?: MetadataItem[]) {
const itemsToToggle = filteredItems || this[type];
itemsToToggle.forEach(item => item.selected = checked);
this.updateSelectAllState(type);
}
private updateSelectAllState(type: MetadataType) {
const allItems = this[type];
const allSelected = allItems.length > 0 && allItems.every(item => item.selected);
switch (type) {
case 'authors':
this.selectAllAuthors = allSelected;
break;
case 'categories':
this.selectAllCategories = allSelected;
break;
case 'moods':
this.selectAllMoods = allSelected;
break;
case 'tags':
this.selectAllTags = allSelected;
break;
case 'series':
this.selectAllSeries = allSelected;
break;
case 'publishers':
this.selectAllPublishers = allSelected;
break;
case 'languages':
this.selectAllLanguages = allSelected;
break;
}
}
onRowSelect(type: MetadataType) {
this.updateSelectAllState(type);
}
clearSelection(type: MetadataType) {
this[type].forEach(item => item.selected = false);
switch (type) {
case 'authors':
this.selectAllAuthors = false;
break;
case 'categories':
this.selectAllCategories = false;
break;
case 'moods':
this.selectAllMoods = false;
break;
case 'tags':
this.selectAllTags = false;
break;
case 'series':
this.selectAllSeries = false;
break;
case 'publishers':
this.selectAllPublishers = false;
break;
case 'languages':
this.selectAllLanguages = false;
break;
}
}
selectSimilar(type: MetadataType, value: string) {
const normalized = value.toLowerCase().trim();
this[type].forEach(item => {
const itemNormalized = item.value.toLowerCase().trim();
item.selected = itemNormalized.includes(normalized) || normalized.includes(itemNormalized);
});
}
filterGlobal(event: any, dt: any) {
dt.filterGlobal(event.target.value, 'contains');
}
onMetadataClick(type: MetadataType, value: string): void {
const filterKeyMap: Record<MetadataType, string> = {
authors: 'author',
categories: 'category',
moods: 'mood',
tags: 'tag',
series: 'series',
publishers: 'publisher',
languages: 'language'
};
this.navigateToFilteredBooks(filterKeyMap[type], value);
}
navigateToFilteredBooks(filterKey: string, filterValue: string): void {
this.router.navigate(['/all-books'], {
queryParams: {
view: 'grid',
sort: 'title',
direction: 'asc',
sidebar: true,
filter: `${filterKey}:${filterValue}`
}
});
}
protected isSingleValueField(type: MetadataType): boolean {
return type === 'series' || type === 'publishers' || type === 'languages';
}
protected getTotalAffectedBooks(items: MetadataItem[]): number {
const uniqueBookIds = new Set<number>();
items.forEach(item => {
item.bookIds.forEach(bookId => uniqueBookIds.add(bookId));
});
return uniqueBookIds.size;
}
}
@@ -6,7 +6,7 @@ import {MetadataRefreshOptions} from '../../../model/request/metadata-refresh-op
import {BookService} from '../../../../book/service/book.service';
import {AppSettingsService} from '../../../../../shared/service/app-settings.service';
import {filter, take} from 'rxjs/operators';
import {MetadataAdvancedFetchOptionsComponent} from '../metadata-advanced-fetch-options-component/metadata-advanced-fetch-options.component';
import {MetadataAdvancedFetchOptionsComponent} from '../metadata-advanced-fetch-options/metadata-advanced-fetch-options.component';
@Component({
selector: 'app-metadata-fetch-options',
@@ -13,7 +13,7 @@ import {ProgressBar} from 'primeng/progressbar';
import {Tooltip} from 'primeng/tooltip';
import {MetadataProgressService} from '../../../../shared/service/metadata-progress-service';
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
import {MetadataPickerComponent} from '../book-metadata-center-component/metadata-picker-component/metadata-picker.component';
import {MetadataPickerComponent} from '../book-metadata-center/metadata-picker/metadata-picker.component';
@Component({
selector: 'app-metadata-review-dialog-component',
@@ -6,8 +6,8 @@ import {BookService} from '../../../book/service/book.service';
import {BehaviorSubject, combineLatest, Observable, Subject} from 'rxjs';
import {UserService} from '../../../settings/user-management/user.service';
import {distinctUntilChanged, filter, map, shareReplay, switchMap, takeUntil} from 'rxjs/operators';
import {MetadataSearcherComponent} from '../book-metadata-center-component/metadata-searcher-component/metadata-searcher.component';
import {MetadataEditorComponent} from '../book-metadata-center-component/metadata-editor-component/metadata-editor.component';
import {MetadataEditorComponent} from '../book-metadata-center/metadata-editor/metadata-editor.component';
import {MetadataSearcherComponent} from '../book-metadata-center/metadata-searcher/metadata-searcher.component';
@Component({
selector: 'app-multi-book-metadata-editor-component',
@@ -9,7 +9,7 @@ import {BookService} from '../../../book/service/book.service';
import {AppSettingsService} from '../../../../shared/service/app-settings.service';
import {Book} from '../../../book/model/book.model';
import {FormsModule} from '@angular/forms';
import {MetadataFetchOptionsComponent} from '../metadata-options-dialog/metadata-fetch-options-component/metadata-fetch-options.component';
import {MetadataFetchOptionsComponent} from '../metadata-options-dialog/metadata-fetch-options/metadata-fetch-options.component';
@Component({
selector: 'app-multi-book-metadata-fetch-component',