feat(sidecar): add sidecar JSON metadata file support (#2657)
Co-authored-by: acx10 <acx10@users.noreply.github.com>
This commit is contained in:
@@ -111,32 +111,54 @@
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="form-section collapsible">
|
||||
<section class="form-section">
|
||||
<div class="section-header">
|
||||
<i class="pi pi-cog"></i>
|
||||
<span>Options</span>
|
||||
</div>
|
||||
|
||||
<div class="options-grid">
|
||||
<div class="option-item">
|
||||
<div class="options-list">
|
||||
<div class="option-row">
|
||||
<div class="option-label">
|
||||
<span>Watch folders</span>
|
||||
<i
|
||||
class="pi pi-question-circle info-icon"
|
||||
pTooltip="Automatically detect new books added to folders"
|
||||
tooltipPosition="right"
|
||||
tooltipPosition="top"
|
||||
></i>
|
||||
</div>
|
||||
<p-toggleswitch [(ngModel)]="watch" />
|
||||
</div>
|
||||
|
||||
<div class="option-item format-priority-option">
|
||||
<div class="option-row">
|
||||
<div class="option-label">
|
||||
<span>Metadata source</span>
|
||||
<i
|
||||
class="pi pi-question-circle info-icon"
|
||||
pTooltip="Choose where to read metadata from when scanning books"
|
||||
tooltipPosition="top"
|
||||
></i>
|
||||
</div>
|
||||
<p-select
|
||||
[(ngModel)]="metadataSource"
|
||||
[options]="metadataSourceOptions"
|
||||
optionLabel="label"
|
||||
optionValue="value"
|
||||
placeholder="Select source"
|
||||
class="metadata-source-select"
|
||||
appendTo="body"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="option-divider"></div>
|
||||
|
||||
<div class="option-row option-row-stacked">
|
||||
<div class="option-label">
|
||||
<span>Format priority</span>
|
||||
<i
|
||||
class="pi pi-question-circle info-icon"
|
||||
pTooltip="Drag to set preferred format when a book has multiple files"
|
||||
tooltipPosition="right"
|
||||
pTooltip="Drag to reorder preferred format when a book has multiple files"
|
||||
tooltipPosition="top"
|
||||
></i>
|
||||
</div>
|
||||
<div
|
||||
@@ -156,59 +178,56 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="option-item allowed-formats-option">
|
||||
<div class="option-row">
|
||||
<div class="option-label">
|
||||
<span>Allowed formats</span>
|
||||
<i
|
||||
class="pi pi-question-circle info-icon"
|
||||
pTooltip="Select which book formats this library should accept. Files of other formats will be ignored during scans."
|
||||
tooltipPosition="right"
|
||||
pTooltip="Select which book formats to include in scans"
|
||||
tooltipPosition="top"
|
||||
></i>
|
||||
</div>
|
||||
|
||||
<div class="allowed-formats-container">
|
||||
<div class="allow-all-toggle">
|
||||
<p-checkbox
|
||||
[(ngModel)]="allowAllFormats"
|
||||
[binary]="true"
|
||||
inputId="allowAll"
|
||||
(onChange)="onAllowAllFormatsChange()"
|
||||
/>
|
||||
<label for="allowAll" class="allow-all-label">Allow all formats</label>
|
||||
</div>
|
||||
|
||||
@if (!allowAllFormats) {
|
||||
<div class="format-checkboxes">
|
||||
@for (format of allBookFormats; track format.type) {
|
||||
<div class="format-checkbox-item" [class.has-warning]="getFormatWarning(format.type)">
|
||||
<p-checkbox
|
||||
[ngModel]="isFormatSelected(format.type)"
|
||||
[binary]="true"
|
||||
[inputId]="'format-' + format.type"
|
||||
(onChange)="onFormatCheckboxChange(format.type, $event.checked)"
|
||||
/>
|
||||
<label [for]="'format-' + format.type" class="format-checkbox-label">
|
||||
{{ format.label }}
|
||||
</label>
|
||||
@if (getFormatWarning(format.type); as warning) {
|
||||
<i
|
||||
class="pi pi-exclamation-triangle warning-icon"
|
||||
[pTooltip]="warning"
|
||||
tooltipPosition="top"
|
||||
></i>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
@if (hasAnyFormatWarning()) {
|
||||
<div class="format-warning-message">
|
||||
<i class="pi pi-info-circle"></i>
|
||||
<span>Deselected formats with existing books will not be affected, but won't appear in future scans</span>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
<div class="allow-all-toggle">
|
||||
<p-checkbox
|
||||
[(ngModel)]="allowAllFormats"
|
||||
[binary]="true"
|
||||
inputId="allowAll"
|
||||
(onChange)="onAllowAllFormatsChange()"
|
||||
/>
|
||||
<label for="allowAll" class="allow-all-label">Allow all</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (!allowAllFormats) {
|
||||
<div class="format-checkboxes">
|
||||
@for (format of allBookFormats; track format.type) {
|
||||
<div class="format-checkbox-item" [class.has-warning]="getFormatWarning(format.type)">
|
||||
<p-checkbox
|
||||
[ngModel]="isFormatSelected(format.type)"
|
||||
[binary]="true"
|
||||
[inputId]="'format-' + format.type"
|
||||
(onChange)="onFormatCheckboxChange(format.type, $event.checked)"
|
||||
/>
|
||||
<label [for]="'format-' + format.type" class="format-checkbox-label">
|
||||
{{ format.label }}
|
||||
</label>
|
||||
@if (getFormatWarning(format.type); as warning) {
|
||||
<i
|
||||
class="pi pi-exclamation-triangle warning-icon"
|
||||
[pTooltip]="warning"
|
||||
tooltipPosition="top"
|
||||
></i>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
@if (hasAnyFormatWarning()) {
|
||||
<div class="format-warning-message">
|
||||
<i class="pi pi-info-circle"></i>
|
||||
<span>Deselected formats won't appear in future scans</span>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
@@ -388,61 +388,63 @@
|
||||
}
|
||||
|
||||
// Options section
|
||||
.options-grid {
|
||||
.options-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1.5rem;
|
||||
padding: 1.25rem;
|
||||
gap: 1rem;
|
||||
padding: 1rem 1.25rem;
|
||||
background: var(--ground-background);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.option-item {
|
||||
.option-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
justify-content: space-between;
|
||||
gap: 1rem;
|
||||
|
||||
p-toggleswitch {
|
||||
--p-toggleswitch-checked-background: var(--p-green-500);
|
||||
--p-toggleswitch-checked-hover-background: var(--p-green-600);
|
||||
}
|
||||
|
||||
&.format-priority-option,
|
||||
&.allowed-formats-option {
|
||||
&.option-row-stacked {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 0.625rem;
|
||||
}
|
||||
}
|
||||
|
||||
.option-label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.375rem;
|
||||
font-size: 0.9rem;
|
||||
font-weight: 500;
|
||||
color: var(--text-color);
|
||||
.option-divider {
|
||||
height: 1px;
|
||||
background: var(--border-color);
|
||||
margin: 0.25rem 0;
|
||||
}
|
||||
|
||||
.info-icon {
|
||||
font-size: 0.9rem;
|
||||
color: var(--p-blue-400);
|
||||
cursor: help;
|
||||
transition: color 0.2s ease;
|
||||
.option-label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.375rem;
|
||||
font-size: 0.875rem;
|
||||
font-weight: 500;
|
||||
color: var(--text-color);
|
||||
|
||||
&:hover {
|
||||
color: var(--primary-color);
|
||||
}
|
||||
.info-icon {
|
||||
font-size: 0.8rem;
|
||||
color: var(--text-secondary-color);
|
||||
opacity: 0.6;
|
||||
cursor: help;
|
||||
transition: opacity 0.2s ease;
|
||||
|
||||
&:hover {
|
||||
opacity: 1;
|
||||
color: var(--primary-color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Allowed formats
|
||||
.allowed-formats-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.875rem;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.allow-all-toggle {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
@@ -458,8 +460,8 @@
|
||||
.format-checkboxes {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.75rem 1.25rem;
|
||||
padding: 0.75rem;
|
||||
gap: 0.625rem 1.25rem;
|
||||
padding: 0.875rem;
|
||||
background: var(--card-background);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 6px;
|
||||
@@ -469,10 +471,10 @@
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.375rem;
|
||||
min-width: 100px;
|
||||
min-width: 90px;
|
||||
|
||||
.format-checkbox-label {
|
||||
font-size: 0.8rem;
|
||||
font-size: 0.8125rem;
|
||||
color: var(--text-color);
|
||||
cursor: pointer;
|
||||
}
|
||||
@@ -480,7 +482,7 @@
|
||||
.warning-icon {
|
||||
font-size: 0.75rem;
|
||||
color: var(--p-orange-400);
|
||||
margin-left: 0.25rem;
|
||||
margin-left: 0.125rem;
|
||||
}
|
||||
|
||||
&.has-warning {
|
||||
@@ -490,20 +492,24 @@
|
||||
}
|
||||
}
|
||||
|
||||
::ng-deep .metadata-source-select {
|
||||
min-width: 150px;
|
||||
}
|
||||
|
||||
.format-warning-message {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
padding: 0.625rem 0.75rem;
|
||||
background: rgba(234, 179, 8, 0.1);
|
||||
border: 1px solid var(--p-orange-400);
|
||||
border-radius: 6px;
|
||||
font-size: 0.8rem;
|
||||
font-size: 0.75rem;
|
||||
color: var(--p-orange-400);
|
||||
|
||||
i {
|
||||
flex-shrink: 0;
|
||||
margin-top: 0.125rem;
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -511,7 +517,7 @@
|
||||
.format-chips {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.625rem;
|
||||
gap: 0.5rem;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
@@ -519,7 +525,7 @@
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
padding: 0.5rem 0.75rem;
|
||||
padding: 0.4rem 0.625rem;
|
||||
background: var(--card-background);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 6px;
|
||||
@@ -544,17 +550,15 @@
|
||||
}
|
||||
|
||||
.chip-label {
|
||||
font-size: 0.8rem;
|
||||
font-size: 0.8125rem;
|
||||
font-weight: 500;
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
.drag-indicator {
|
||||
font-size: 0.875rem;
|
||||
font-size: 0.75rem;
|
||||
color: var(--text-secondary-color);
|
||||
opacity: 0.7;
|
||||
padding: 0.25rem;
|
||||
margin: -0.25rem;
|
||||
opacity: 0.5;
|
||||
cursor: grab;
|
||||
|
||||
&:hover {
|
||||
@@ -668,15 +672,4 @@
|
||||
}
|
||||
}
|
||||
|
||||
.format-chips {
|
||||
gap: 0.375rem;
|
||||
}
|
||||
|
||||
.format-chip {
|
||||
padding: 0.375rem 0.5rem;
|
||||
|
||||
.chip-label {
|
||||
font-size: 0.6875rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import {Router} from '@angular/router';
|
||||
import {LibraryService} from '../book/service/library.service';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
import {Library} from '../book/model/library.model';
|
||||
import {Library, MetadataSource} from '../book/model/library.model';
|
||||
import {BookType} from '../book/model/book.model';
|
||||
import {ToggleSwitch} from 'primeng/toggleswitch';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
@@ -17,12 +17,13 @@ import {switchMap} from 'rxjs/operators';
|
||||
import {map} from 'rxjs';
|
||||
import {CdkDragDrop, DragDropModule, moveItemInArray} from '@angular/cdk/drag-drop';
|
||||
import {Checkbox} from 'primeng/checkbox';
|
||||
import {Select} from 'primeng/select';
|
||||
|
||||
@Component({
|
||||
selector: 'app-library-creator',
|
||||
standalone: true,
|
||||
templateUrl: './library-creator.component.html',
|
||||
imports: [FormsModule, InputText, ToggleSwitch, Tooltip, Button, IconDisplayComponent, DragDropModule, Checkbox],
|
||||
imports: [FormsModule, InputText, ToggleSwitch, Tooltip, Button, IconDisplayComponent, DragDropModule, Checkbox, Select],
|
||||
styleUrl: './library-creator.component.scss'
|
||||
})
|
||||
export class LibraryCreatorComponent implements OnInit {
|
||||
@@ -38,6 +39,15 @@ export class LibraryCreatorComponent implements OnInit {
|
||||
allowAllFormats: boolean = true;
|
||||
selectedAllowedFormats: Set<BookType> = new Set();
|
||||
formatCounts: Record<string, number> = {};
|
||||
metadataSource: MetadataSource = 'EMBEDDED';
|
||||
|
||||
readonly metadataSourceOptions = [
|
||||
{label: 'Embedded Only', value: 'EMBEDDED', description: 'Use only embedded file metadata'},
|
||||
{label: 'Sidecar Only', value: 'SIDECAR', description: 'Use only sidecar JSON files'},
|
||||
{label: 'Prefer Sidecar', value: 'PREFER_SIDECAR', description: 'Use sidecar if available, fallback to embedded'},
|
||||
{label: 'Prefer Embedded', value: 'PREFER_EMBEDDED', description: 'Use embedded if available, fallback to sidecar'},
|
||||
{label: 'None', value: 'NONE', description: 'Don\'t read metadata from files'}
|
||||
];
|
||||
|
||||
readonly allBookFormats: {type: BookType, label: string}[] = [
|
||||
{type: 'EPUB', label: 'EPUB'},
|
||||
@@ -100,6 +110,10 @@ export class LibraryCreatorComponent implements OnInit {
|
||||
this.selectedAllowedFormats = new Set(this.allBookFormats.map(f => f.type));
|
||||
}
|
||||
|
||||
if (this.library.metadataSource) {
|
||||
this.metadataSource = this.library.metadataSource;
|
||||
}
|
||||
|
||||
this.libraryService.getBookCountsByFormat(this.library.id!).subscribe(counts => {
|
||||
this.formatCounts = counts;
|
||||
});
|
||||
@@ -219,7 +233,8 @@ export class LibraryCreatorComponent implements OnInit {
|
||||
paths: this.folders.map(folder => ({path: folder})),
|
||||
watch: this.watch,
|
||||
formatPriority: this.formatPriority.map(f => f.type),
|
||||
allowedFormats: this.allowAllFormats ? [] : Array.from(this.selectedAllowedFormats)
|
||||
allowedFormats: this.allowAllFormats ? [] : Array.from(this.selectedAllowedFormats),
|
||||
metadataSource: this.metadataSource
|
||||
};
|
||||
|
||||
if (this.mode === 'edit') {
|
||||
|
||||
Reference in New Issue
Block a user