Introduce per-library settings for metadata fetching (#1239)
This commit is contained in:
+89
@@ -0,0 +1,89 @@
|
||||
<div class="main-container enclosing-container">
|
||||
<div class="settings-header">
|
||||
<h2 class="settings-title">
|
||||
<i class="pi pi-database"></i>
|
||||
Library Metadata Configuration
|
||||
</h2>
|
||||
<p class="settings-description">
|
||||
Configure metadata fetch behavior for your libraries. Set global defaults and create library-specific overrides to control how book metadata is retrieved from different providers.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="settings-content">
|
||||
<div class="preferences-section">
|
||||
<div class="section-header">
|
||||
<h3 class="section-title">
|
||||
<i class="pi pi-globe"></i>
|
||||
Default Metadata Settings
|
||||
</h3>
|
||||
<p class="section-description">
|
||||
Set global default provider priorities for book metadata fields. These settings apply to all libraries unless overridden below.
|
||||
BookLore tries providers from left to right (1st → 2nd → 3rd → 4th priority) for each book field until it finds data.
|
||||
The system checks your 1st priority provider first - if that provider doesn't have the specific field (like description or author),
|
||||
it automatically moves to your 2nd priority, then 3rd, and finally 4th. Leave a priority empty to skip it entirely.
|
||||
For example, if Amazon (1st) has no description but Google Books (2nd) does, Google's description will be used.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="settings-card">
|
||||
<app-metadata-advanced-fetch-options
|
||||
[currentMetadataOptions]="defaultMetadataOptions"
|
||||
[submitButtonLabel]="'Save Default Settings'"
|
||||
(metadataOptionsSubmitted)="onDefaultMetadataOptionsSubmitted($event)">
|
||||
</app-metadata-advanced-fetch-options>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="preferences-section">
|
||||
<div class="section-header">
|
||||
<h3 class="section-title">
|
||||
<i class="pi pi-book"></i>
|
||||
Library-Specific Overrides
|
||||
</h3>
|
||||
<p class="section-description">
|
||||
Override the default priority settings for specific libraries. For example, you might prefer Amazon for fiction but Google Books for technical books. Each library can have its own provider priority order while falling back to defaults for unspecified fields.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="settings-card">
|
||||
@if (libraries$ | async; as libraries) {
|
||||
<p-accordion>
|
||||
@for (library of libraries; track trackByLibrary($index, library); let i = $index) {
|
||||
<p-accordion-panel [value]="i">
|
||||
<p-accordion-header>
|
||||
<div class="accordion-header-content">
|
||||
<div class="library-info">
|
||||
<i [class]="'pi pi-' + library.icon" class="library-icon"></i>
|
||||
<span class="library-name">{{ library.name }}</span>
|
||||
<span class="dot-separator">•</span>
|
||||
@if (hasLibraryOverride(library.id!)) {
|
||||
<span class="override-indicator custom">
|
||||
<i class="pi pi-check-circle"></i>
|
||||
Custom Settings
|
||||
</span>
|
||||
} @else {
|
||||
<span class="default-indicator default">
|
||||
<i class="pi pi-globe"></i>
|
||||
Default Settings
|
||||
</span>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</p-accordion-header>
|
||||
<p-accordion-content>
|
||||
<div class="accordion-content-wrapper">
|
||||
<app-metadata-advanced-fetch-options
|
||||
[currentMetadataOptions]="getLibraryOptions(library.id!)"
|
||||
[submitButtonLabel]="'Save ' + library.name + ' Settings'"
|
||||
(metadataOptionsSubmitted)="onLibraryMetadataOptionsSubmitted(library.id!, $event)">
|
||||
</app-metadata-advanced-fetch-options>
|
||||
</div>
|
||||
</p-accordion-content>
|
||||
</p-accordion-panel>
|
||||
}
|
||||
</p-accordion>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
+235
@@ -0,0 +1,235 @@
|
||||
.main-container {
|
||||
width: 100%;
|
||||
padding: 1rem;
|
||||
height: calc(100dvh - 10.5rem);
|
||||
overflow-y: auto;
|
||||
border-width: 1px;
|
||||
border-radius: 0.5rem;
|
||||
|
||||
@media (min-width: 768px) {
|
||||
height: calc(100dvh - 11.65rem);
|
||||
}
|
||||
}
|
||||
|
||||
.enclosing-container {
|
||||
border-color: var(--p-content-border-color);
|
||||
background: var(--p-content-background);
|
||||
}
|
||||
|
||||
.settings-header {
|
||||
margin-top: 1rem;
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.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 {
|
||||
color: var(--p-text-muted-color);
|
||||
font-size: 0.875rem;
|
||||
line-height: 1.5;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.settings-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2rem;
|
||||
}
|
||||
|
||||
.preferences-section {
|
||||
@media (min-width: 768px) {
|
||||
padding: 0 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
.section-header {
|
||||
margin-bottom: 1rem;
|
||||
|
||||
.section-description {
|
||||
color: var(--p-text-muted-color);
|
||||
font-size: 0.875rem;
|
||||
line-height: 1.5;
|
||||
margin: 0.5rem 0 0 0;
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 0.5rem;
|
||||
|
||||
.pi {
|
||||
color: var(--p-primary-color);
|
||||
margin-top: 0.125rem;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.section-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
font-size: 1.125rem;
|
||||
font-weight: 600;
|
||||
color: var(--p-text-color);
|
||||
margin: 0 0 0.5rem 0;
|
||||
|
||||
.pi {
|
||||
color: var(--p-primary-color);
|
||||
}
|
||||
}
|
||||
|
||||
.settings-card {
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
border-radius: 8px;
|
||||
background: var(--p-content-background);
|
||||
padding: 1.5rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1.5rem;
|
||||
|
||||
app-metadata-advanced-fetch-options {
|
||||
display: block;
|
||||
width: 100%;
|
||||
|
||||
::ng-deep {
|
||||
> div,
|
||||
> .container,
|
||||
> .main-container {
|
||||
margin: 0 !important;
|
||||
padding: 0 !important;
|
||||
border: none !important;
|
||||
background: transparent !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
:host ::ng-deep {
|
||||
.p-accordion {
|
||||
.p-accordion-panel {
|
||||
margin-bottom: 0.5rem;
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
border-radius: 6px;
|
||||
overflow: hidden;
|
||||
|
||||
&:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.p-accordion-header {
|
||||
background: var(--p-surface-100);
|
||||
border: none;
|
||||
border-radius: 0;
|
||||
|
||||
&:hover {
|
||||
background: var(--p-surface-200);
|
||||
}
|
||||
|
||||
.p-accordion-header-content {
|
||||
width: 100%;
|
||||
padding: 1rem 1.25rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
}
|
||||
|
||||
.p-accordion-content {
|
||||
border: none;
|
||||
border-top: 1px solid var(--p-content-border-color);
|
||||
|
||||
.p-accordion-content-content {
|
||||
padding: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.accordion-header-content {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
gap: 1rem;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
}
|
||||
|
||||
.library-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
|
||||
.library-icon {
|
||||
font-size: 1.2rem;
|
||||
color: var(--p-primary-color);
|
||||
}
|
||||
|
||||
.library-name {
|
||||
font-weight: 600;
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
.dot-separator {
|
||||
color: var(--p-text-muted-color);
|
||||
font-weight: bold;
|
||||
font-size: 0.875rem;
|
||||
margin: 0 0.25rem;
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
.override-indicator,
|
||||
.default-indicator {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.375rem;
|
||||
font-size: 0.875rem;
|
||||
font-weight: 500;
|
||||
|
||||
&.custom {
|
||||
color: var(--p-green-500);
|
||||
}
|
||||
|
||||
&.default {
|
||||
color: var(--p-blue-500);
|
||||
}
|
||||
|
||||
i {
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.accordion-content-wrapper {
|
||||
padding: 1.5rem;
|
||||
|
||||
app-metadata-advanced-fetch-options {
|
||||
display: block;
|
||||
width: 100%;
|
||||
|
||||
::ng-deep {
|
||||
> div,
|
||||
> .container,
|
||||
> .main-container {
|
||||
margin: 0 !important;
|
||||
padding: 0 !important;
|
||||
border: none !important;
|
||||
background: transparent !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+213
@@ -0,0 +1,213 @@
|
||||
import {Component, inject, OnInit} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {Observable} from 'rxjs';
|
||||
import {map} from 'rxjs/operators';
|
||||
import {AccordionModule} from 'primeng/accordion';
|
||||
import {MessageService} from 'primeng/api';
|
||||
|
||||
import {Library} from '../../book/model/library.model';
|
||||
import {LibraryService} from '../../book/service/library.service';
|
||||
import {MetadataRefreshOptions} from '../../metadata/model/request/metadata-refresh-options.model';
|
||||
import {MetadataAdvancedFetchOptionsComponent} from '../../metadata/metadata-options-dialog/metadata-advanced-fetch-options/metadata-advanced-fetch-options.component';
|
||||
import {AppSettings, AppSettingKey} from '../../core/model/app-settings.model';
|
||||
import {AppSettingsService} from '../../core/service/app-settings.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-library-metadata-settings-component',
|
||||
standalone: true,
|
||||
imports: [CommonModule, FormsModule, MetadataAdvancedFetchOptionsComponent, AccordionModule],
|
||||
templateUrl: './library-metadata-settings.component.html',
|
||||
styleUrls: ['./library-metadata-settings.component.scss']
|
||||
})
|
||||
export class LibraryMetadataSettingsComponent implements OnInit {
|
||||
private libraryService = inject(LibraryService);
|
||||
private appSettingsService = inject(AppSettingsService);
|
||||
private messageService = inject(MessageService);
|
||||
|
||||
libraries$: Observable<Library[]> = this.libraryService.libraryState$.pipe(
|
||||
map(state => state.libraries || [])
|
||||
);
|
||||
|
||||
defaultMetadataOptions: MetadataRefreshOptions = this.getDefaultMetadataOptions();
|
||||
libraryMetadataOptions: { [libraryId: number]: MetadataRefreshOptions } = {};
|
||||
|
||||
ngOnInit() {
|
||||
this.appSettingsService.appSettings$.subscribe(appSettings => {
|
||||
if (appSettings) {
|
||||
this.defaultMetadataOptions = appSettings.defaultMetadataRefreshOptions;
|
||||
this.initializeLibraryOptions(appSettings);
|
||||
this.updateLibraryOptionsFromSettings(appSettings);
|
||||
}
|
||||
});
|
||||
|
||||
this.libraries$.subscribe(libraries => {
|
||||
libraries.forEach(library => {
|
||||
if (library.id && !this.libraryMetadataOptions[library.id]) {
|
||||
const libraryOptions = this.getLibrarySpecificOptions(library.id);
|
||||
if (libraryOptions) {
|
||||
this.libraryMetadataOptions[library.id] = libraryOptions;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
onDefaultMetadataOptionsSubmitted(options: MetadataRefreshOptions) {
|
||||
this.defaultMetadataOptions = options;
|
||||
this.saveDefaultMetadataOptions(options);
|
||||
}
|
||||
|
||||
onLibraryMetadataOptionsSubmitted(libraryId: number, options: MetadataRefreshOptions) {
|
||||
this.libraryMetadataOptions[libraryId] = {...options, libraryId};
|
||||
this.saveLibraryMetadataOptions();
|
||||
}
|
||||
|
||||
hasLibraryOverride(libraryId: number): boolean {
|
||||
return libraryId in this.libraryMetadataOptions;
|
||||
}
|
||||
|
||||
getLibraryOptions(libraryId: number): MetadataRefreshOptions {
|
||||
return this.libraryMetadataOptions[libraryId] || {...this.defaultMetadataOptions, libraryId};
|
||||
}
|
||||
|
||||
trackByLibrary(index: number, library: Library): number | undefined {
|
||||
return library.id;
|
||||
}
|
||||
|
||||
private saveDefaultMetadataOptions(options: MetadataRefreshOptions) {
|
||||
const settingsToSave = [
|
||||
{
|
||||
key: AppSettingKey.QUICK_BOOK_MATCH,
|
||||
newValue: options
|
||||
}
|
||||
];
|
||||
|
||||
this.appSettingsService.saveSettings(settingsToSave).subscribe({
|
||||
next: () => {
|
||||
this.showMessage('success', 'Settings Saved', 'Default metadata options have been saved successfully.');
|
||||
this.updateLibrariesUsingDefaults();
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Error saving default metadata options:', error);
|
||||
this.showMessage('error', 'Save Failed', 'Failed to save default metadata options. Please try again.');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private saveLibraryMetadataOptions() {
|
||||
const libraryOptionsArray = Object.values(this.libraryMetadataOptions).filter(option =>
|
||||
option.libraryId !== null && option.libraryId !== undefined
|
||||
);
|
||||
|
||||
const settingsToSave = [
|
||||
{
|
||||
key: AppSettingKey.LIBRARY_METADATA_REFRESH_OPTIONS,
|
||||
newValue: libraryOptionsArray
|
||||
}
|
||||
];
|
||||
|
||||
this.appSettingsService.saveSettings(settingsToSave).subscribe({
|
||||
next: () => {
|
||||
this.showMessage('success', 'Settings Saved', 'Library metadata options have been saved successfully.');
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Error saving library metadata options:', error);
|
||||
this.showMessage('error', 'Save Failed', 'Failed to save library metadata options. Please try again.');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private updateLibrariesUsingDefaults() {
|
||||
Object.keys(this.libraryMetadataOptions).forEach(libraryIdStr => {
|
||||
const libraryId = parseInt(libraryIdStr, 10);
|
||||
if (!this.hasLibrarySpecificOptionsInSettings(libraryId)) {
|
||||
delete this.libraryMetadataOptions[libraryId];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private showMessage(severity: 'success' | 'error', summary: string, detail: string) {
|
||||
this.messageService.add({
|
||||
severity,
|
||||
summary,
|
||||
detail,
|
||||
life: 5000
|
||||
});
|
||||
}
|
||||
|
||||
private initializeLibraryOptions(appSettings: AppSettings) {
|
||||
if (appSettings?.libraryMetadataRefreshOptions) {
|
||||
appSettings.libraryMetadataRefreshOptions.forEach(option => {
|
||||
if (option.libraryId) {
|
||||
this.libraryMetadataOptions[option.libraryId] = option;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private updateLibraryOptionsFromSettings(appSettings: AppSettings) {
|
||||
Object.keys(this.libraryMetadataOptions).forEach(libraryIdStr => {
|
||||
const libraryId = parseInt(libraryIdStr, 10);
|
||||
if (!this.hasLibrarySpecificOptions(libraryId)) {
|
||||
this.libraryMetadataOptions[libraryId] = {...this.defaultMetadataOptions};
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private hasLibrarySpecificOptions(libraryId: number): boolean {
|
||||
return libraryId in this.libraryMetadataOptions;
|
||||
}
|
||||
|
||||
private hasLibrarySpecificOptionsInSettings(libraryId: number): boolean {
|
||||
let hasOptions = false;
|
||||
this.appSettingsService.appSettings$.subscribe(settings => {
|
||||
hasOptions = settings?.libraryMetadataRefreshOptions?.some(
|
||||
option => option.libraryId === libraryId
|
||||
) || false;
|
||||
}).unsubscribe();
|
||||
|
||||
return hasOptions;
|
||||
}
|
||||
|
||||
private getLibrarySpecificOptions(libraryId: number): MetadataRefreshOptions | null {
|
||||
let libraryOptions: MetadataRefreshOptions | null = null;
|
||||
this.appSettingsService.appSettings$.subscribe(settings => {
|
||||
libraryOptions = settings?.libraryMetadataRefreshOptions?.find(
|
||||
option => option.libraryId === libraryId
|
||||
) || null;
|
||||
}).unsubscribe();
|
||||
|
||||
return libraryOptions;
|
||||
}
|
||||
|
||||
private getDefaultMetadataOptions(): MetadataRefreshOptions {
|
||||
return {
|
||||
libraryId: null,
|
||||
allP1: null,
|
||||
allP2: null,
|
||||
allP3: null,
|
||||
allP4: null,
|
||||
refreshCovers: false,
|
||||
mergeCategories: false,
|
||||
reviewBeforeApply: false,
|
||||
fieldOptions: {
|
||||
title: {p1: null, p2: null, p3: null, p4: null},
|
||||
subtitle: {p1: null, p2: null, p3: null, p4: null},
|
||||
description: {p1: null, p2: null, p3: null, p4: null},
|
||||
authors: {p1: null, p2: null, p3: null, p4: null},
|
||||
publisher: {p1: null, p2: null, p3: null, p4: null},
|
||||
publishedDate: {p1: null, p2: null, p3: null, p4: null},
|
||||
seriesName: {p1: null, p2: null, p3: null, p4: null},
|
||||
seriesNumber: {p1: null, p2: null, p3: null, p4: null},
|
||||
seriesTotal: {p1: null, p2: null, p3: null, p4: null},
|
||||
isbn13: {p1: null, p2: null, p3: null, p4: null},
|
||||
isbn10: {p1: null, p2: null, p3: null, p4: null},
|
||||
language: {p1: null, p2: null, p3: null, p4: null},
|
||||
categories: {p1: null, p2: null, p3: null, p4: null},
|
||||
cover: {p1: null, p2: null, p3: null, p4: null}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user