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:
+120
@@ -0,0 +1,120 @@
|
||||
<ng-container *transloco="let t; prefix: 'bookdrop.bulkEdit'">
|
||||
<div class="bulk-edit-container">
|
||||
<div class="info-banner">
|
||||
<i class="pi pi-info-circle"></i>
|
||||
<span [innerHTML]="t('infoBanner', { fileCount: fileCount })"></span>
|
||||
</div>
|
||||
|
||||
<p-divider></p-divider>
|
||||
|
||||
<div class="fields-section">
|
||||
<h4>{{ t('textFieldsTitle') }}</h4>
|
||||
<div class="field-grid">
|
||||
@for (field of textFields; track field.name) {
|
||||
<div class="field-row">
|
||||
<p-checkbox
|
||||
[binary]="true"
|
||||
[ngModel]="isFieldEnabled(field.name)"
|
||||
(ngModelChange)="toggleField(field.name)"
|
||||
[ariaLabel]="t('enableField', { label: field.label })">
|
||||
</p-checkbox>
|
||||
<label class="field-label" [attr.for]="field.controlName">{{ field.label }}</label>
|
||||
<input
|
||||
pInputText
|
||||
[formControl]="getControl(field.controlName)"
|
||||
[attr.id]="field.controlName"
|
||||
[attr.aria-label]="field.label"
|
||||
class="field-input"/>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p-divider></p-divider>
|
||||
|
||||
<div class="fields-section">
|
||||
<h4>{{ t('numberFieldsTitle') }}</h4>
|
||||
<div class="field-grid">
|
||||
@for (field of numberFields; track field.name) {
|
||||
<div class="field-row">
|
||||
<p-checkbox
|
||||
[binary]="true"
|
||||
[ngModel]="isFieldEnabled(field.name)"
|
||||
(ngModelChange)="toggleField(field.name)"
|
||||
[ariaLabel]="t('enableField', { label: field.label })">
|
||||
</p-checkbox>
|
||||
<label class="field-label" [attr.for]="field.controlName">{{ field.label }}</label>
|
||||
<input
|
||||
pInputText
|
||||
type="number"
|
||||
[formControl]="getControl(field.controlName)"
|
||||
[attr.id]="field.controlName"
|
||||
[attr.aria-label]="field.label"
|
||||
class="field-input field-input-small"/>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p-divider></p-divider>
|
||||
|
||||
<div class="fields-section">
|
||||
<div class="section-header">
|
||||
<h4>{{ t('arrayFieldsTitle') }}</h4>
|
||||
<div class="merge-toggle">
|
||||
<span class="merge-label" id="merge-mode-label">{{ t('modeLabel') }}</span>
|
||||
<p-selectButton
|
||||
[options]="mergeOptions"
|
||||
[(ngModel)]="mergeArrays"
|
||||
optionLabel="label"
|
||||
optionValue="value"
|
||||
ariaLabelledBy="merge-mode-label">
|
||||
</p-selectButton>
|
||||
</div>
|
||||
</div>
|
||||
<p class="helper-text"><i class="pi pi-info-circle"></i> {{ t('helperText') }}</p>
|
||||
<div class="field-grid">
|
||||
@for (field of chipFields; track field.name) {
|
||||
<div class="field-row">
|
||||
<p-checkbox
|
||||
[binary]="true"
|
||||
[ngModel]="isFieldEnabled(field.name)"
|
||||
(ngModelChange)="toggleField(field.name)"
|
||||
[ariaLabel]="t('enableField', { label: field.label })">
|
||||
</p-checkbox>
|
||||
<label class="field-label" [attr.for]="field.controlName">{{ field.label }}</label>
|
||||
<p-autoComplete
|
||||
[formControl]="getControl(field.controlName)"
|
||||
[multiple]="true"
|
||||
[suggestions]="[]"
|
||||
[forceSelection]="false"
|
||||
[typeahead]="false"
|
||||
[dropdown]="false"
|
||||
[ariaLabel]="field.label"
|
||||
(onBlur)="onAutoCompleteBlur(field.name, $event)"
|
||||
class="field-input">
|
||||
</p-autoComplete>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p-divider></p-divider>
|
||||
|
||||
<div class="dialog-footer">
|
||||
<p-button
|
||||
[label]="'common.cancel' | transloco"
|
||||
icon="pi pi-times"
|
||||
severity="secondary"
|
||||
(click)="cancel()">
|
||||
</p-button>
|
||||
<p-button
|
||||
[label]="t('applyToSelected')"
|
||||
icon="pi pi-check"
|
||||
severity="success"
|
||||
[disabled]="!hasEnabledFields"
|
||||
(click)="apply()">
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
+104
@@ -0,0 +1,104 @@
|
||||
.bulk-edit-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
padding: 0 1rem;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.helper-text {
|
||||
font-size: 0.875rem;
|
||||
color: var(--text-color-secondary);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
margin: 0;
|
||||
padding: 0.5rem 0;
|
||||
|
||||
i {
|
||||
font-size: 1rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.info-banner {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
padding: 0.75rem 1rem;
|
||||
background: rgba(59, 130, 246, 0.08);
|
||||
border: 1px solid var(--p-primary-color);
|
||||
border-radius: 6px;
|
||||
color: var(--p-text-color);
|
||||
|
||||
i {
|
||||
font-size: 1.25rem;
|
||||
color: var(--p-primary-color);
|
||||
}
|
||||
}
|
||||
|
||||
.fields-section {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
|
||||
h4 {
|
||||
margin: 0;
|
||||
font-size: 0.9rem;
|
||||
font-weight: 600;
|
||||
color: var(--p-text-secondary-color);
|
||||
}
|
||||
}
|
||||
|
||||
.section-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.merge-toggle {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
|
||||
.merge-label {
|
||||
font-size: 0.85rem;
|
||||
color: var(--p-text-secondary-color);
|
||||
}
|
||||
}
|
||||
|
||||
.field-grid {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.field-row {
|
||||
display: grid;
|
||||
grid-template-columns: auto 6rem 1fr;
|
||||
gap: 0.75rem;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.field-label {
|
||||
font-size: 0.9rem;
|
||||
font-weight: 500;
|
||||
color: var(--p-text-color);
|
||||
}
|
||||
|
||||
.field-input {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.field-input-small {
|
||||
max-width: 120px;
|
||||
}
|
||||
|
||||
.dialog-footer {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 0.75rem;
|
||||
padding-top: 0.5rem;
|
||||
}
|
||||
+175
@@ -0,0 +1,175 @@
|
||||
import {Component, inject, OnInit, ChangeDetectorRef} from '@angular/core';
|
||||
import {FormControl, FormGroup, FormsModule, ReactiveFormsModule} from '@angular/forms';
|
||||
import {DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {Button} from 'primeng/button';
|
||||
import {Checkbox} from 'primeng/checkbox';
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
import {AutoComplete} from 'primeng/autocomplete';
|
||||
import {Divider} from 'primeng/divider';
|
||||
import {SelectButton} from 'primeng/selectbutton';
|
||||
import {BookMetadata} from '../../../book/model/book.model';
|
||||
import {TranslocoDirective, TranslocoPipe, TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
export interface BulkEditResult {
|
||||
fields: Partial<BookMetadata>;
|
||||
enabledFields: Set<string>;
|
||||
mergeArrays: boolean;
|
||||
}
|
||||
|
||||
interface BulkEditField {
|
||||
name: string;
|
||||
label: string;
|
||||
type: 'text' | 'chips' | 'number';
|
||||
controlName: string;
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-bookdrop-bulk-edit-dialog',
|
||||
standalone: true,
|
||||
imports: [
|
||||
ReactiveFormsModule,
|
||||
FormsModule,
|
||||
Button,
|
||||
Checkbox,
|
||||
InputText,
|
||||
AutoComplete,
|
||||
Divider,
|
||||
SelectButton,
|
||||
TranslocoDirective,
|
||||
TranslocoPipe,
|
||||
],
|
||||
templateUrl: './bookdrop-bulk-edit-dialog.component.html',
|
||||
styleUrl: './bookdrop-bulk-edit-dialog.component.scss'
|
||||
})
|
||||
export class BookdropBulkEditDialogComponent implements OnInit {
|
||||
|
||||
private readonly dialogRef = inject(DynamicDialogRef);
|
||||
private readonly config = inject(DynamicDialogConfig);
|
||||
private readonly cdr = inject(ChangeDetectorRef);
|
||||
private readonly t = inject(TranslocoService);
|
||||
|
||||
fileCount: number = 0;
|
||||
mergeArrays = true;
|
||||
|
||||
enabledFields = new Set<string>();
|
||||
|
||||
bulkEditForm = new FormGroup({
|
||||
seriesName: new FormControl(''),
|
||||
seriesTotal: new FormControl<number | null>(null),
|
||||
authors: new FormControl<string[]>([]),
|
||||
publisher: new FormControl(''),
|
||||
language: new FormControl(''),
|
||||
categories: new FormControl<string[]>([]),
|
||||
moods: new FormControl<string[]>([]),
|
||||
tags: new FormControl<string[]>([]),
|
||||
});
|
||||
|
||||
textFields: BulkEditField[] = [
|
||||
{name: 'seriesName', label: this.t.translate('bookdrop.bulkEdit.seriesName'), type: 'text', controlName: 'seriesName'},
|
||||
{name: 'publisher', label: this.t.translate('bookdrop.bulkEdit.publisher'), type: 'text', controlName: 'publisher'},
|
||||
{name: 'language', label: this.t.translate('bookdrop.bulkEdit.language'), type: 'text', controlName: 'language'},
|
||||
];
|
||||
|
||||
numberFields: BulkEditField[] = [
|
||||
{name: 'seriesTotal', label: this.t.translate('bookdrop.bulkEdit.seriesTotal'), type: 'number', controlName: 'seriesTotal'},
|
||||
];
|
||||
|
||||
chipFields: BulkEditField[] = [
|
||||
{name: 'authors', label: this.t.translate('bookdrop.bulkEdit.authors'), type: 'chips', controlName: 'authors'},
|
||||
{name: 'categories', label: this.t.translate('bookdrop.bulkEdit.genres'), type: 'chips', controlName: 'categories'},
|
||||
{name: 'moods', label: this.t.translate('bookdrop.bulkEdit.moods'), type: 'chips', controlName: 'moods'},
|
||||
{name: 'tags', label: this.t.translate('bookdrop.bulkEdit.tags'), type: 'chips', controlName: 'tags'},
|
||||
];
|
||||
|
||||
mergeOptions = [
|
||||
{label: this.t.translate('bookdrop.bulkEdit.mergeOption'), value: true},
|
||||
{label: this.t.translate('bookdrop.bulkEdit.replaceOption'), value: false},
|
||||
];
|
||||
|
||||
ngOnInit(): void {
|
||||
this.fileCount = this.config.data?.fileCount ?? 0;
|
||||
this.setupFormValueChangeListeners();
|
||||
}
|
||||
|
||||
private setupFormValueChangeListeners(): void {
|
||||
Object.keys(this.bulkEditForm.controls).forEach(fieldName => {
|
||||
const control = this.bulkEditForm.get(fieldName);
|
||||
control?.valueChanges.subscribe(value => {
|
||||
const hasValue = Array.isArray(value) ? value.length > 0 : (value !== null && value !== '' && value !== undefined);
|
||||
if (hasValue && !this.enabledFields.has(fieldName)) {
|
||||
this.enabledFields.add(fieldName);
|
||||
this.cdr.detectChanges();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
onAutoCompleteBlur(fieldName: string, event: Event): void {
|
||||
const target = event.target as HTMLInputElement;
|
||||
const inputValue = target?.value?.trim();
|
||||
if (inputValue) {
|
||||
const control = this.bulkEditForm.get(fieldName);
|
||||
const currentValue = (control?.value as string[]) || [];
|
||||
if (!currentValue.includes(inputValue)) {
|
||||
control?.setValue([...currentValue, inputValue]);
|
||||
}
|
||||
if (target) {
|
||||
target.value = '';
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.enabledFields.has(fieldName)) {
|
||||
const control = this.bulkEditForm.get(fieldName);
|
||||
const value = control?.value;
|
||||
if (Array.isArray(value) && value.length > 0) {
|
||||
this.enabledFields.add(fieldName);
|
||||
this.cdr.detectChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
toggleField(fieldName: string): void {
|
||||
if (this.enabledFields.has(fieldName)) {
|
||||
this.enabledFields.delete(fieldName);
|
||||
} else {
|
||||
this.enabledFields.add(fieldName);
|
||||
}
|
||||
}
|
||||
|
||||
isFieldEnabled(fieldName: string): boolean {
|
||||
return this.enabledFields.has(fieldName);
|
||||
}
|
||||
|
||||
getControl(controlName: string): FormControl {
|
||||
return this.bulkEditForm.get(controlName) as FormControl;
|
||||
}
|
||||
|
||||
get hasEnabledFields(): boolean {
|
||||
return this.enabledFields.size > 0;
|
||||
}
|
||||
|
||||
cancel(): void {
|
||||
this.dialogRef.close(null);
|
||||
}
|
||||
|
||||
apply(): void {
|
||||
const formValue = this.bulkEditForm.value;
|
||||
const fields: Partial<BookMetadata> = {};
|
||||
|
||||
this.enabledFields.forEach(fieldName => {
|
||||
const value = formValue[fieldName as keyof typeof formValue];
|
||||
|
||||
if (value !== undefined && value !== null) {
|
||||
(fields as Record<string, unknown>)[fieldName] = value;
|
||||
}
|
||||
});
|
||||
|
||||
const result: BulkEditResult = {
|
||||
fields,
|
||||
enabledFields: new Set(this.enabledFields),
|
||||
mergeArrays: this.mergeArrays,
|
||||
};
|
||||
|
||||
this.dialogRef.close(result);
|
||||
}
|
||||
}
|
||||
+546
@@ -0,0 +1,546 @@
|
||||
<ng-container *transloco="let t; prefix: 'bookdrop.metadataPicker'">
|
||||
@if (fetchedMetadata && fetchedMetadata.title) {
|
||||
<form [formGroup]="metadataForm" class="metapicker">
|
||||
<div class="form-scroll">
|
||||
<div class="column-headers">
|
||||
<div class="column-label current">
|
||||
<span>{{ t('fileData') }}</span>
|
||||
</div>
|
||||
<div class="column-actions">
|
||||
<button
|
||||
type="button"
|
||||
class="p-button p-button-outlined p-button-sm p-button-icon-only"
|
||||
[pTooltip]="t('copyMissingTooltip')"
|
||||
tooltipPosition="bottom"
|
||||
(click)="copyMissing()"
|
||||
>
|
||||
<span class="p-button-icon pi pi-angle-left"></span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="p-button p-button-outlined p-button-sm p-button-icon-only"
|
||||
[pTooltip]="t('overwriteAllTooltip')"
|
||||
tooltipPosition="bottom"
|
||||
(click)="copyAll()"
|
||||
>
|
||||
<span class="p-button-icon pi pi-angle-double-left"></span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="p-button p-button-outlined p-button-sm p-button-icon-only p-button-warn"
|
||||
[pTooltip]="t('resetAllTooltip')"
|
||||
tooltipPosition="bottom"
|
||||
(click)="confirmReset()"
|
||||
>
|
||||
<span class="p-button-icon pi pi-refresh"></span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="column-label fetched">
|
||||
<span>{{ t('fetchedData') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="metacontent">
|
||||
<div class="meta-row field-thumbnail">
|
||||
<label class="field-label"></label>
|
||||
<div class="thumbnail-row">
|
||||
<div class="thumbnail-column">
|
||||
@if (metadataForm.get('thumbnailUrl')?.value) {
|
||||
<p-image
|
||||
class="thumbnail"
|
||||
[src]="metadataForm.get('thumbnailUrl')?.value"
|
||||
alt="Image"
|
||||
appendTo="body"
|
||||
lazyLoad
|
||||
[preview]="true"
|
||||
[ngClass]="{
|
||||
'changed': isValueCopied('thumbnailUrl'),
|
||||
}"
|
||||
></p-image>
|
||||
}
|
||||
@else {
|
||||
<div class="thumbnail no-cover-text">{{ t('noCoverImage') }}</div>
|
||||
}
|
||||
<input type="hidden" id="thumbnailUrl" formControlName="thumbnailUrl"/>
|
||||
</div>
|
||||
<p-button
|
||||
size="small"
|
||||
[icon]="isValueSaved('thumbnailUrl') ? 'pi pi-check' : (isValueCopied('thumbnailUrl') ? 'pi pi-refresh' : 'pi pi-angle-left')"
|
||||
[outlined]="true"
|
||||
class="arrow-button"
|
||||
[severity]="isValueCopied('thumbnailUrl') ? 'warn' : null"
|
||||
[disabled]="!isFetchedDifferent('thumbnailUrl') && !isValueCopied('thumbnailUrl')"
|
||||
(click)="isValueCopied('thumbnailUrl') ? resetField('thumbnailUrl') : copyFetchedToCurrent('thumbnailUrl')"
|
||||
/>
|
||||
<div class="thumbnail-column">
|
||||
@if (fetchedMetadata.thumbnailUrl) {
|
||||
<p-image
|
||||
class="thumbnail"
|
||||
[src]="fetchedMetadata.thumbnailUrl!"
|
||||
alt="Image"
|
||||
appendTo="body"
|
||||
lazyLoad
|
||||
[preview]="true"
|
||||
></p-image>
|
||||
}
|
||||
@else {
|
||||
<div class="thumbnail no-cover-text">{{ t('coverImageNotFound') }}</div>
|
||||
}
|
||||
<input type="hidden" [value]="fetchedMetadata.thumbnailUrl" readonly/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@for (field of metadataFieldsTop; track field) {
|
||||
<div class="meta-row field-{{field.controlName}}">
|
||||
<label for="{{field.controlName}}" class="field-label">{{ field.label }}</label>
|
||||
<div class="meta-fields">
|
||||
<input
|
||||
pSize="small"
|
||||
fluid
|
||||
pInputText
|
||||
id="{{field.controlName}}"
|
||||
formControlName="{{field.controlName}}"
|
||||
class="dest"
|
||||
[ngClass]="{
|
||||
'changed': isValueChanged(field.controlName),
|
||||
}"
|
||||
/>
|
||||
<p-button
|
||||
size="small"
|
||||
[icon]="isValueSaved(field.controlName) ? 'pi pi-check' : (isValueChanged(field.controlName) || !fetchedMetadata[field.fetchedKey] ? 'pi pi-refresh' : 'pi pi-angle-left')"
|
||||
[outlined]="true"
|
||||
[ngClass]="{
|
||||
'nosrc' : !fetchedMetadata[field.fetchedKey]
|
||||
}"
|
||||
class="arrow-button"
|
||||
[severity]="isValueChanged(field.controlName) ? 'warn' : null"
|
||||
[disabled]="!isFetchedDifferent(field.controlName) && !isValueChanged(field.controlName)"
|
||||
(click)="isValueChanged(field.controlName) ? resetField(field.controlName) : copyFetchedToCurrent(field.controlName)"
|
||||
/>
|
||||
@if (fetchedMetadata[field.fetchedKey]) {
|
||||
<input
|
||||
pSize="small"
|
||||
pInputText
|
||||
[value]="fetchedMetadata[field.fetchedKey] ?? null"
|
||||
class="src"
|
||||
disabled
|
||||
[ngClass]="{
|
||||
'diff': isFetchedDifferent(field.controlName),
|
||||
}"
|
||||
/>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
@for (field of metadataPublishDate; track field) {
|
||||
<div class="meta-row field-{{field.controlName}}">
|
||||
<label for="{{field.controlName}}" class="field-label">{{ field.label }}</label>
|
||||
<div class="meta-fields">
|
||||
<p-datepicker
|
||||
size="small"
|
||||
fluid
|
||||
inputId="{{field.controlName}}"
|
||||
formControlName="{{field.controlName}}"
|
||||
dataType="string"
|
||||
dateFormat="yy-mm-dd"
|
||||
[keepInvalid]="true"
|
||||
[showIcon]="true"
|
||||
[iconDisplay]="'input'"
|
||||
appendTo="body"
|
||||
class="dest"
|
||||
[ngClass]="{
|
||||
'changed': isValueChanged(field.controlName),
|
||||
}">
|
||||
</p-datepicker>
|
||||
<p-button
|
||||
size="small"
|
||||
[icon]="isValueSaved(field.controlName) ? 'pi pi-check' : (isValueChanged(field.controlName) || !fetchedMetadata[field.fetchedKey] ? 'pi pi-refresh' : 'pi pi-angle-left')"
|
||||
[outlined]="true"
|
||||
[ngClass]="{
|
||||
'nosrc' : !fetchedMetadata[field.fetchedKey]
|
||||
}"
|
||||
class="arrow-button"
|
||||
[severity]="isValueChanged(field.controlName) ? 'warn' : null"
|
||||
[disabled]="!isFetchedDifferent(field.controlName) && !isValueChanged(field.controlName)"
|
||||
(click)="isValueChanged(field.controlName) ? resetField(field.controlName) : copyFetchedToCurrent(field.controlName)"
|
||||
/>
|
||||
@if (fetchedMetadata[field.fetchedKey]) {
|
||||
<input
|
||||
pSize="small"
|
||||
pInputText
|
||||
[value]="fetchedMetadata[field.fetchedKey] ?? null"
|
||||
class="src"
|
||||
disabled
|
||||
[ngClass]="{
|
||||
'diff': isFetchedDifferent(field.controlName),
|
||||
}"
|
||||
/>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
@for (field of metadataChips; track field) {
|
||||
<div class="meta-row field-{{field.controlName}}">
|
||||
<label for="{{field.controlName}}" class="field-label">{{ field.label }}</label>
|
||||
<div class="meta-fields">
|
||||
@if (field.controlName === 'authors') {
|
||||
<div class="author-chips-container dest full-width"
|
||||
cdkDropList cdkDropListOrientation="mixed"
|
||||
(cdkDropListDropped)="dropAuthor($event)"
|
||||
[ngClass]="{ 'changed': isValueChanged('authors') }">
|
||||
@for (author of metadataForm.get('authors')!.value; track $index) {
|
||||
<span class="author-chip" [class.main-author]="$index === 0" cdkDrag>
|
||||
@if ($index === 0) { <span class="main-author-badge">m</span> }
|
||||
{{ author }}
|
||||
<i class="pi pi-times author-chip-remove" (click)="removeAuthor($index)"></i>
|
||||
</span>
|
||||
}
|
||||
<p-autoComplete
|
||||
class="author-add-input"
|
||||
[(ngModel)]="authorInputValue"
|
||||
[ngModelOptions]="{ standalone: true }"
|
||||
size="small"
|
||||
[forceSelection]="false"
|
||||
[dropdown]="false"
|
||||
(onKeyUp)="onAuthorInputKeyUp($event)"
|
||||
(onSelect)="onAuthorInputSelect($event)"
|
||||
placeholder="Add author..."
|
||||
/>
|
||||
</div>
|
||||
} @else {
|
||||
<p-autoComplete
|
||||
size="small"
|
||||
formControlName="{{field.controlName}}"
|
||||
[multiple]="true"
|
||||
[typeahead]="false"
|
||||
[dropdown]="false"
|
||||
[forceSelection]="false"
|
||||
class="dest full-width"
|
||||
[ngClass]="{
|
||||
'changed': isValueChanged(field.controlName),
|
||||
}"
|
||||
(onBlur)="onAutoCompleteBlur(field.controlName, $event)"
|
||||
/>
|
||||
}
|
||||
<p-button
|
||||
size="small"
|
||||
[icon]="isValueSaved(field.controlName) ? 'pi pi-check' : (isValueChanged(field.controlName) || !fetchedMetadata[field.fetchedKey] ? 'pi pi-refresh' : 'pi pi-angle-left')"
|
||||
[outlined]="true"
|
||||
[ngClass]="{
|
||||
'nosrc' : !fetchedMetadata[field.fetchedKey]
|
||||
}"
|
||||
class="arrow-button"
|
||||
[severity]="isValueChanged(field.controlName) ? 'warn' : null"
|
||||
[disabled]="!isFetchedDifferent(field.controlName) && !isValueChanged(field.controlName)"
|
||||
(click)="isValueChanged(field.controlName) ? resetField(field.controlName) : copyFetchedToCurrent(field.controlName)"
|
||||
/>
|
||||
@if (fetchedMetadata[field.fetchedKey]) {
|
||||
<p-autoComplete
|
||||
size="small"
|
||||
[ngModel]="fetchedMetadata[field.fetchedKey] ?? []"
|
||||
[ngModelOptions]="{standalone:true}"
|
||||
[disabled]="true"
|
||||
[multiple]="true"
|
||||
[typeahead]="false"
|
||||
[dropdown]="false"
|
||||
[forceSelection]="false"
|
||||
class="src full-width"
|
||||
[ngClass]="{
|
||||
'diff': isFetchedDifferent(field.controlName),
|
||||
}"
|
||||
/>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
@for (field of metadataDescription; track field) {
|
||||
<div class="meta-row field-{{field.controlName}}">
|
||||
<label for="{{field.controlName}}" class="field-label">{{ field.label }}</label>
|
||||
<div class="meta-fields">
|
||||
<textarea
|
||||
pTextarea
|
||||
rows="4"
|
||||
pSize="small"
|
||||
id="{{field.controlName}}"
|
||||
formControlName="{{field.controlName}}"
|
||||
class="dest"
|
||||
[ngClass]="{
|
||||
'changed': isValueChanged(field.controlName),
|
||||
}"
|
||||
></textarea>
|
||||
<p-button
|
||||
size="small"
|
||||
[icon]="isValueSaved(field.controlName) ? 'pi pi-check' : (isValueChanged(field.controlName) || !fetchedMetadata[field.fetchedKey] ? 'pi pi-refresh' : 'pi pi-angle-left')"
|
||||
[outlined]="true"
|
||||
[ngClass]="{
|
||||
'nosrc' : !fetchedMetadata[field.fetchedKey]
|
||||
}"
|
||||
class="arrow-button"
|
||||
[severity]="isValueChanged(field.controlName) ? 'warn' : null"
|
||||
[disabled]="!isFetchedDifferent(field.controlName) && !isValueChanged(field.controlName)"
|
||||
(click)="isValueChanged(field.controlName) ? resetField(field.controlName) : copyFetchedToCurrent(field.controlName)"
|
||||
/>
|
||||
@if (fetchedMetadata[field.fetchedKey]) {
|
||||
<textarea
|
||||
pTextarea
|
||||
rows="4"
|
||||
pSize="small"
|
||||
[value]="fetchedMetadata[field.fetchedKey] ?? null"
|
||||
class="src"
|
||||
disabled
|
||||
[ngClass]="{
|
||||
'diff': isFetchedDifferent(field.controlName),
|
||||
}"
|
||||
></textarea>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
@for (field of metadataFieldsBottom; track field) {
|
||||
<div class="meta-row field-{{field.controlName}}">
|
||||
<label for="{{field.controlName}}" class="field-label">{{ field.label }}</label>
|
||||
<div class="meta-fields">
|
||||
<input
|
||||
pInputText
|
||||
pSize="small"
|
||||
id="{{field.controlName}}"
|
||||
formControlName="{{field.controlName}}"
|
||||
class="dest"
|
||||
[ngClass]="{
|
||||
'changed': isValueChanged(field.controlName),
|
||||
}"
|
||||
/>
|
||||
<p-button
|
||||
size="small"
|
||||
[icon]="isValueSaved(field.controlName) ? 'pi pi-check' : (isValueChanged(field.controlName) || !fetchedMetadata[field.fetchedKey] ? 'pi pi-refresh' : 'pi pi-angle-left')"
|
||||
[outlined]="true"
|
||||
[ngClass]="{
|
||||
'nosrc' : !fetchedMetadata[field.fetchedKey]
|
||||
}"
|
||||
class="arrow-button"
|
||||
[severity]="isValueChanged(field.controlName) ? 'warn' : null"
|
||||
[disabled]="!isFetchedDifferent(field.controlName) && !isValueChanged(field.controlName)"
|
||||
(click)="isValueChanged(field.controlName) ? resetField(field.controlName) : copyFetchedToCurrent(field.controlName)"
|
||||
/>
|
||||
@if (fetchedMetadata[field.fetchedKey]) {
|
||||
<input
|
||||
pInputText
|
||||
pSize="small"
|
||||
[value]="fetchedMetadata[field.fetchedKey] ?? null"
|
||||
class="src"
|
||||
disabled
|
||||
[ngClass]="{
|
||||
'diff': isFetchedDifferent(field.controlName),
|
||||
}"
|
||||
/>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
} @else {
|
||||
<form [formGroup]="metadataForm" class="metaeditor">
|
||||
<div class="form-scroll">
|
||||
<div class="metaheader">
|
||||
<p class="missingmd">
|
||||
{{ t('unableToFetchMetadata') }}
|
||||
</p>
|
||||
<p-button
|
||||
size="small"
|
||||
severity="warn"
|
||||
icon="pi pi-refresh"
|
||||
[outlined]="true"
|
||||
[pTooltip]="t('resetAllTooltip')"
|
||||
tooltipPosition="left"
|
||||
(onClick)="confirmReset()"
|
||||
></p-button>
|
||||
</div>
|
||||
<div class="metabody">
|
||||
<div class="editor-thumbnail-wrapper">
|
||||
<div class="editor-thumbnail-inner field-thumbnail">
|
||||
<img
|
||||
[src]="metadataForm.get('thumbnailUrl')?.value"
|
||||
alt="Book Thumbnail"
|
||||
class="thumbnail editor-thumbnail-img"
|
||||
/>
|
||||
<input type="hidden" id="thumbnailUrl" formControlName="thumbnailUrl"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="metacontent editor-metacontent">
|
||||
@for (field of metadataFieldsTop; track field) {
|
||||
<div class="meta-row field-{{field.controlName}}">
|
||||
<label for="{{field.controlName}}" class="field-label field-label--fixed">{{ field.label }}</label>
|
||||
<div class="field-input-row">
|
||||
<input
|
||||
pSize="small"
|
||||
fluid
|
||||
pInputText
|
||||
id="{{field.controlName}}"
|
||||
formControlName="{{field.controlName}}"
|
||||
[ngClass]="{
|
||||
'changed': isValueChanged(field.controlName),
|
||||
}"
|
||||
/>
|
||||
<p-button
|
||||
size="small"
|
||||
icon="pi pi-refresh"
|
||||
[outlined]="true"
|
||||
class="arrow-button"
|
||||
severity="warn"
|
||||
[disabled]="!isValueChanged(field.controlName)"
|
||||
(click)="resetField(field.controlName)"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@for (field of metadataPublishDate; track field) {
|
||||
<div class="meta-row field-{{field.controlName}}">
|
||||
<label for="{{field.controlName}}" class="field-label field-label--fixed">{{ field.label }}</label>
|
||||
<div class="field-input-row">
|
||||
<p-datepicker
|
||||
size="small"
|
||||
fluid
|
||||
inputId="{{field.controlName}}"
|
||||
formControlName="{{field.controlName}}"
|
||||
dataType="string"
|
||||
dateFormat="yy-mm-dd"
|
||||
[keepInvalid]="true"
|
||||
[showIcon]="true"
|
||||
[iconDisplay]="'input'"
|
||||
appendTo="body"
|
||||
class="full-width"
|
||||
[ngClass]="{
|
||||
'changed': isValueChanged(field.controlName),
|
||||
}">
|
||||
</p-datepicker>
|
||||
<p-button
|
||||
size="small"
|
||||
icon="pi pi-refresh"
|
||||
[outlined]="true"
|
||||
class="arrow-button"
|
||||
severity="warn"
|
||||
[disabled]="!isValueChanged(field.controlName)"
|
||||
(click)="resetField(field.controlName)"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@for (field of metadataChips; track field) {
|
||||
<div class="meta-row field-{{field.controlName}}">
|
||||
<label for="{{field.controlName}}" class="field-label field-label--fixed">{{ field.label }}</label>
|
||||
<div class="field-input-row">
|
||||
@if (field.controlName === 'authors') {
|
||||
<div class="author-chips-container full-width"
|
||||
cdkDropList cdkDropListOrientation="mixed"
|
||||
(cdkDropListDropped)="dropAuthor($event)"
|
||||
[ngClass]="{ 'changed': isValueChanged('authors') }">
|
||||
@for (author of metadataForm.get('authors')!.value; track $index) {
|
||||
<span class="author-chip" [class.main-author]="$index === 0" cdkDrag>
|
||||
@if ($index === 0) { <span class="main-author-badge">m</span> }
|
||||
{{ author }}
|
||||
<i class="pi pi-times author-chip-remove" (click)="removeAuthor($index)"></i>
|
||||
</span>
|
||||
}
|
||||
<p-autoComplete
|
||||
class="author-add-input"
|
||||
[(ngModel)]="authorInputValue"
|
||||
[ngModelOptions]="{ standalone: true }"
|
||||
size="small"
|
||||
[forceSelection]="false"
|
||||
[dropdown]="false"
|
||||
(onKeyUp)="onAuthorInputKeyUp($event)"
|
||||
(onSelect)="onAuthorInputSelect($event)"
|
||||
placeholder="Add author..."
|
||||
/>
|
||||
</div>
|
||||
} @else {
|
||||
<p-autoComplete
|
||||
size="small"
|
||||
formControlName="{{field.controlName}}"
|
||||
[multiple]="true"
|
||||
[typeahead]="false"
|
||||
[dropdown]="false"
|
||||
[forceSelection]="false"
|
||||
class="full-width"
|
||||
[ngClass]="{
|
||||
'changed': isValueChanged(field.controlName),
|
||||
}"
|
||||
(onBlur)="onAutoCompleteBlur(field.controlName, $event)"
|
||||
/>
|
||||
}
|
||||
<p-button
|
||||
size="small"
|
||||
icon="pi pi-refresh"
|
||||
[outlined]="true"
|
||||
class="arrow-button"
|
||||
severity="warn"
|
||||
[disabled]="!isValueChanged(field.controlName)"
|
||||
(click)="resetField(field.controlName)"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@for (field of metadataDescription; track field) {
|
||||
<div class="meta-row field-{{field.controlName}}">
|
||||
<label for="{{field.controlName}}" class="field-label field-label--fixed">{{ field.label }}</label>
|
||||
<div class="field-input-row">
|
||||
<textarea
|
||||
pTextarea
|
||||
fluid
|
||||
rows="4"
|
||||
pSize="small"
|
||||
id="{{field.controlName}}"
|
||||
formControlName="{{field.controlName}}"
|
||||
[ngClass]="{
|
||||
'changed': isValueChanged(field.controlName),
|
||||
}"
|
||||
></textarea>
|
||||
<p-button
|
||||
size="small"
|
||||
icon="pi pi-refresh"
|
||||
[outlined]="true"
|
||||
class="arrow-button"
|
||||
severity="warn"
|
||||
[disabled]="!isValueChanged(field.controlName)"
|
||||
(click)="resetField(field.controlName)"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@for (field of metadataFieldsBottom; track field) {
|
||||
<div class="meta-row field-{{field.controlName}}">
|
||||
<label for="{{field.controlName}}" class="field-label field-label--fixed">{{ field.label }}</label>
|
||||
<div class="field-input-row">
|
||||
<input
|
||||
pSize="small"
|
||||
fluid
|
||||
pInputText
|
||||
id="{{field.controlName}}"
|
||||
formControlName="{{field.controlName}}"
|
||||
[ngClass]="{
|
||||
'changed': isValueChanged(field.controlName),
|
||||
}"
|
||||
/>
|
||||
<p-button
|
||||
size="small"
|
||||
icon="pi pi-refresh"
|
||||
[outlined]="true"
|
||||
class="arrow-button"
|
||||
severity="warn"
|
||||
[disabled]="!isValueChanged(field.controlName)"
|
||||
(click)="resetField(field.controlName)"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
}
|
||||
</ng-container>
|
||||
+486
@@ -0,0 +1,486 @@
|
||||
.thumbnail {
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 0.5rem;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
||||
margin: 0 auto 1rem;
|
||||
}
|
||||
|
||||
::ng-deep .metapicker .thumbnail {
|
||||
img {
|
||||
border-radius: 0.5rem;
|
||||
max-height: 14rem;
|
||||
max-width: 10em;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.metapicker div.thumbnail {
|
||||
background-color: var(--p-inputtext-disabled-background);
|
||||
color: var(--p-inputtext-disabled-color);
|
||||
width: 9rem;
|
||||
height: 14rem;
|
||||
padding: 1rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
::ng-deep .metaeditor img.thumbnail {
|
||||
border-radius: 0.5rem;
|
||||
max-width: 100%;
|
||||
max-height: 100%;
|
||||
height: auto;
|
||||
width: auto;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
max-height: 14em;
|
||||
}
|
||||
}
|
||||
|
||||
.metaeditor .arrow-button {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.thumbnail.changed,
|
||||
input.changed,
|
||||
textarea.changed,
|
||||
::ng-deep p-datepicker.changed input,
|
||||
::ng-deep p-autocomplete.changed ul.p-autocomplete-input-multiple {
|
||||
border: 1px solid var(--p-button-outlined-warn-border-color) !important;
|
||||
}
|
||||
|
||||
::ng-deep .p-inputchips {
|
||||
width: 100% !important;
|
||||
}
|
||||
|
||||
::ng-deep .p-autocomplete .p-chip .p-chip-label {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
::ng-deep .p-autocomplete-input-chip {
|
||||
width: 2rem;
|
||||
}
|
||||
|
||||
.metapicker, .metaeditor {
|
||||
box-sizing: border-box;
|
||||
display: flex;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.metapicker {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.form-scroll {
|
||||
flex-grow: 1;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.field-label {
|
||||
font-size: 0.875rem;
|
||||
|
||||
@media (min-width: 768px) {
|
||||
width: 8rem;
|
||||
}
|
||||
}
|
||||
|
||||
.field-label--fixed {
|
||||
width: 8rem;
|
||||
}
|
||||
|
||||
.column-headers {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 1rem;
|
||||
border-bottom: 1px dotted var(--border-color);
|
||||
|
||||
@media (min-width: 768px) {
|
||||
&::before {
|
||||
content: '';
|
||||
min-width: 8rem;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.column-label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex: 1;
|
||||
color: var(--text-color-secondary);
|
||||
font-size: 0.875rem;
|
||||
|
||||
&.current {
|
||||
justify-content: flex-end;
|
||||
padding-right: 1rem;
|
||||
}
|
||||
|
||||
&.fetched {
|
||||
justify-content: flex-start;
|
||||
padding-left: 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
.column-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 0.5rem;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.thumbnail-row {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.thumbnail-column {
|
||||
display: flex;
|
||||
width: 50%;
|
||||
}
|
||||
|
||||
.no-cover-text {
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.full-width {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.metabody {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 1rem;
|
||||
|
||||
@media (min-width: 768px) {
|
||||
flex-direction: row;
|
||||
}
|
||||
}
|
||||
|
||||
.editor-thumbnail-wrapper {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: center;
|
||||
|
||||
@media (min-width: 768px) {
|
||||
width: 20%;
|
||||
height: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.editor-thumbnail-inner {
|
||||
width: 100%;
|
||||
|
||||
@media (min-width: 768px) {
|
||||
height: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.editor-thumbnail-img {
|
||||
width: 100%;
|
||||
object-fit: contain;
|
||||
|
||||
@media (min-width: 768px) {
|
||||
height: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.editor-metacontent {
|
||||
@media (min-width: 768px) {
|
||||
width: 80%;
|
||||
}
|
||||
}
|
||||
|
||||
.field-input-row {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.metapicker label,
|
||||
.metaeditor label,
|
||||
.missingmd {
|
||||
color: var(--text-color-secondary);
|
||||
}
|
||||
|
||||
::ng-deep .metapicker {
|
||||
.dest, .src {
|
||||
width: calc(50% - 2rem);
|
||||
}
|
||||
|
||||
.arrow-button {
|
||||
margin: auto 1rem;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.arrow-button.nosrc button[disabled] {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
input.diff,
|
||||
textarea.diff,
|
||||
.p-autocomplete.diff .p-chip-label {
|
||||
color: var(--p-primary-color) !important;
|
||||
}
|
||||
|
||||
.src .p-chip.p-disabled {
|
||||
color: var(--p-inputtext-disabled-color) !important;
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.src .p-chip-remove-icon {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.src li.p-autocomplete-input-chip {
|
||||
width: 1px;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
.metaheader {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
border-bottom: 1px dotted var(--border-color);
|
||||
padding: 1rem;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.metacontent {
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.metaeditor .metacontent {
|
||||
padding: 0 0 0 1rem;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
::ng-deep button {
|
||||
border-left-width: 0;
|
||||
border-radius: 0 6px 6px 0;
|
||||
|
||||
&:disabled {
|
||||
opacity: 1;
|
||||
border-color: var(--p-inputtext-border-color) !important;
|
||||
|
||||
span {
|
||||
opacity: 0.6;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
::ng-deep input,
|
||||
::ng-deep ul,
|
||||
textarea {
|
||||
border-radius: 6px 0 0 6px;
|
||||
}
|
||||
|
||||
.field-authors,
|
||||
.field-categories,
|
||||
.field-moods,
|
||||
.field-tags {
|
||||
::ng-deep button {
|
||||
line-height: 2em;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.metadata-status {
|
||||
&.copied {
|
||||
color: rgb(34, 197, 94);
|
||||
}
|
||||
|
||||
&.no-metadata {
|
||||
color: rgb(59, 130, 246);
|
||||
}
|
||||
|
||||
&.not-applied {
|
||||
color: rgb(239, 68, 68);
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.metapicker .metacontent,
|
||||
.metaeditor .metabody {
|
||||
padding-left: 3.25rem;
|
||||
}
|
||||
}
|
||||
|
||||
.meta-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-bottom: 0.5em;
|
||||
|
||||
label {
|
||||
margin: auto 0;
|
||||
}
|
||||
}
|
||||
|
||||
.meta-fields {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
|
||||
}
|
||||
|
||||
.field-description .meta-fields {
|
||||
align-items: stretch;
|
||||
|
||||
.src {
|
||||
resize: none;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.meta-row {
|
||||
flex-wrap: wrap;
|
||||
margin-bottom: 1em;
|
||||
|
||||
label {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.metapicker {
|
||||
.field-thumbnail label {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.field-title,
|
||||
.field-subtitle,
|
||||
.field-publisher,
|
||||
.field-authors,
|
||||
.field-categories,
|
||||
.field-moods,
|
||||
.field-tags,
|
||||
.field-description,
|
||||
.field-seriesName {
|
||||
.meta-fields {
|
||||
flex-wrap: wrap;
|
||||
justify-content: space-between;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.dest {
|
||||
flex: 1 !important;
|
||||
width: auto !important;
|
||||
margin: 0 0 2px 0;
|
||||
|
||||
&:not(:only-child) {
|
||||
border-radius: 6px 0 0 6px;
|
||||
|
||||
::ng-deep ul {
|
||||
border-radius: 6px 0 0 6px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.arrow-button {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
::ng-deep button {
|
||||
border-left-width: 0;
|
||||
border-radius: 0 6px 6px 0;
|
||||
}
|
||||
|
||||
.src {
|
||||
width: 100% !important;
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.field-authors,
|
||||
.field-categories,
|
||||
.field-moods,
|
||||
.field-tags {
|
||||
::ng-deep button {
|
||||
line-height: 2em;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.author-chips-container {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 0.375rem;
|
||||
padding: 0.375rem;
|
||||
min-height: 2.25rem;
|
||||
border: 1px solid var(--p-inputtext-border-color);
|
||||
border-radius: 6px;
|
||||
background: var(--p-inputtext-background);
|
||||
}
|
||||
|
||||
.author-add-input {
|
||||
flex: 1 1 6rem;
|
||||
min-width: 6rem;
|
||||
|
||||
::ng-deep input {
|
||||
border: none !important;
|
||||
background: transparent !important;
|
||||
padding: 0.25rem;
|
||||
box-shadow: none !important;
|
||||
outline: none !important;
|
||||
}
|
||||
}
|
||||
|
||||
.author-chip {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.25rem;
|
||||
padding: 0.25rem 0.5rem;
|
||||
border-radius: 1rem;
|
||||
background: var(--p-chip-background);
|
||||
color: var(--p-chip-color);
|
||||
font-size: 0.875rem;
|
||||
cursor: grab;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.main-author-badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 1rem;
|
||||
height: 1rem;
|
||||
border-radius: 50%;
|
||||
background: var(--p-primary-color);
|
||||
color: var(--p-primary-contrast-color);
|
||||
font-size: 0.6rem;
|
||||
font-weight: 700;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.author-chip-remove {
|
||||
font-size: 0.65rem;
|
||||
cursor: pointer;
|
||||
opacity: 0.6;
|
||||
padding: 0.15rem;
|
||||
&:hover { opacity: 1; }
|
||||
}
|
||||
|
||||
.cdk-drag-preview {
|
||||
box-sizing: border-box;
|
||||
border-radius: 1rem;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
.cdk-drag-placeholder {
|
||||
opacity: 0.4;
|
||||
}
|
||||
|
||||
.cdk-drag-animating {
|
||||
transition: transform 200ms ease;
|
||||
}
|
||||
+226
@@ -0,0 +1,226 @@
|
||||
import {Component, DestroyRef, effect, EventEmitter, inject, Input, OnInit, Output} from '@angular/core';
|
||||
import {FormGroup, FormsModule, ReactiveFormsModule} from '@angular/forms';
|
||||
import {Button} from 'primeng/button';
|
||||
import {NgClass} from '@angular/common';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
import {BookMetadata} from '../../../book/model/book.model';
|
||||
import {UrlHelperService} from '../../../../shared/service/url-helper.service';
|
||||
import {Textarea} from 'primeng/textarea';
|
||||
import {AutoComplete} from 'primeng/autocomplete';
|
||||
import {Image} from 'primeng/image';
|
||||
import {LazyLoadImageModule} from 'ng-lazyload-image';
|
||||
import {ConfirmationService} from 'primeng/api';
|
||||
import {CdkDragDrop, CdkDropList, CdkDrag, moveItemInArray} from '@angular/cdk/drag-drop';
|
||||
import {AutoCompleteSelectEvent} from 'primeng/autocomplete';
|
||||
import {DatePicker} from 'primeng/datepicker';
|
||||
import {ALL_METADATA_FIELDS, getArrayFields, getBottomFields, getTextareaFields, MetadataFieldConfig} from '../../../../shared/metadata';
|
||||
import {MetadataUtilsService} from '../../../../shared/metadata';
|
||||
import {MetadataProviderSpecificFields} from '../../../../shared/model/app-settings.model';
|
||||
import {AppSettingsService} from '../../../../shared/service/app-settings.service';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
@Component({
|
||||
selector: 'app-bookdrop-file-metadata-picker-component',
|
||||
imports: [
|
||||
ReactiveFormsModule,
|
||||
Button,
|
||||
Tooltip,
|
||||
InputText,
|
||||
NgClass,
|
||||
FormsModule,
|
||||
Textarea,
|
||||
AutoComplete,
|
||||
Image,
|
||||
LazyLoadImageModule,
|
||||
DatePicker,
|
||||
TranslocoDirective,
|
||||
CdkDropList,
|
||||
CdkDrag,
|
||||
],
|
||||
templateUrl: './bookdrop-file-metadata-picker.component.html',
|
||||
styleUrl: './bookdrop-file-metadata-picker.component.scss'
|
||||
})
|
||||
export class BookdropFileMetadataPickerComponent implements OnInit {
|
||||
|
||||
private readonly confirmationService = inject(ConfirmationService);
|
||||
private readonly metadataUtils = inject(MetadataUtilsService);
|
||||
protected readonly urlHelper = inject(UrlHelperService);
|
||||
private readonly appSettingsService = inject(AppSettingsService);
|
||||
private readonly destroyRef = inject(DestroyRef);
|
||||
private readonly t = inject(TranslocoService);
|
||||
|
||||
@Input() fetchedMetadata!: BookMetadata;
|
||||
@Input() originalMetadata?: BookMetadata;
|
||||
@Input() metadataForm!: FormGroup;
|
||||
@Input() copiedFields: Record<string, boolean> = {};
|
||||
@Input() savedFields: Record<string, boolean> = {};
|
||||
@Input() bookdropFileId!: number;
|
||||
|
||||
@Output() metadataCopied = new EventEmitter<boolean>();
|
||||
|
||||
authorInputValue = '';
|
||||
|
||||
private enabledProviderFields: MetadataProviderSpecificFields | null = null;
|
||||
|
||||
metadataFieldsTop: MetadataFieldConfig[] = ALL_METADATA_FIELDS.filter(f =>
|
||||
['title', 'subtitle', 'publisher'].includes(f.controlName)
|
||||
);
|
||||
|
||||
metadataPublishDate: MetadataFieldConfig[] = ALL_METADATA_FIELDS.filter(f =>
|
||||
f.controlName === 'publishedDate'
|
||||
);
|
||||
|
||||
metadataChips: MetadataFieldConfig[] = getArrayFields();
|
||||
|
||||
metadataDescription: MetadataFieldConfig[] = getTextareaFields();
|
||||
|
||||
metadataFieldsBottom: MetadataFieldConfig[] = getBottomFields();
|
||||
|
||||
private readonly syncProviderFieldsEffect = effect(() => {
|
||||
const settings = this.appSettingsService.appSettings();
|
||||
if (settings?.metadataProviderSpecificFields) {
|
||||
this.enabledProviderFields = settings.metadataProviderSpecificFields;
|
||||
this.metadataFieldsBottom = getBottomFields(this.enabledProviderFields);
|
||||
}
|
||||
});
|
||||
|
||||
ngOnInit(): void {
|
||||
}
|
||||
|
||||
copyMissing(): void {
|
||||
this.metadataUtils.copyMissingFields(
|
||||
this.fetchedMetadata,
|
||||
this.metadataForm,
|
||||
this.copiedFields,
|
||||
(field) => this.copyFetchedToCurrent(field)
|
||||
);
|
||||
}
|
||||
|
||||
copyAll(includeCover: boolean = true): void {
|
||||
const excludeFields = includeCover ? ['bookId'] : ['thumbnailUrl', 'bookId'];
|
||||
this.metadataUtils.copyAllFields(
|
||||
this.fetchedMetadata,
|
||||
this.metadataForm,
|
||||
(field) => this.copyFetchedToCurrent(field),
|
||||
excludeFields
|
||||
);
|
||||
}
|
||||
|
||||
copyFetchedToCurrent(field: string): void {
|
||||
if (this.metadataUtils.copyFieldToForm(field, this.fetchedMetadata, this.metadataForm, this.copiedFields)) {
|
||||
this.metadataCopied.emit(true);
|
||||
}
|
||||
}
|
||||
|
||||
isValueChanged(field: string): boolean {
|
||||
return this.metadataUtils.isValueChanged(field, this.metadataForm, this.originalMetadata);
|
||||
}
|
||||
|
||||
isFetchedDifferent(field: string): boolean {
|
||||
return this.metadataUtils.isFetchedDifferent(field, this.metadataForm, this.fetchedMetadata);
|
||||
}
|
||||
|
||||
isValueCopied(field: string): boolean {
|
||||
return this.copiedFields[field];
|
||||
}
|
||||
|
||||
isValueSaved(field: string): boolean {
|
||||
return this.savedFields[field];
|
||||
}
|
||||
|
||||
resetField(field: string): void {
|
||||
this.metadataUtils.resetField(field, this.metadataForm, this.originalMetadata, this.copiedFields);
|
||||
if (field === 'thumbnailUrl') {
|
||||
this.metadataForm.get('thumbnailUrl')?.setValue(this.urlHelper.getBookdropCoverUrl(this.bookdropFileId));
|
||||
}
|
||||
}
|
||||
|
||||
dropAuthor(event: CdkDragDrop<string[]>) {
|
||||
const authors = [...(this.metadataForm.get('authors')?.value ?? [])];
|
||||
moveItemInArray(authors, event.previousIndex, event.currentIndex);
|
||||
this.metadataForm.get('authors')?.setValue(authors);
|
||||
this.metadataForm.get('authors')?.markAsDirty();
|
||||
}
|
||||
|
||||
removeAuthor(index: number) {
|
||||
const authors = [...(this.metadataForm.get('authors')?.value ?? [])];
|
||||
authors.splice(index, 1);
|
||||
this.metadataForm.get('authors')?.setValue(authors);
|
||||
this.metadataForm.get('authors')?.markAsDirty();
|
||||
}
|
||||
|
||||
onAuthorInputKeyUp(event: KeyboardEvent) {
|
||||
if (event.key === 'Enter') {
|
||||
const value = this.authorInputValue?.trim();
|
||||
if (value) {
|
||||
const authors = this.metadataForm.get('authors')?.value || [];
|
||||
if (!authors.includes(value)) {
|
||||
this.metadataForm.get('authors')?.setValue([...authors, value]);
|
||||
this.metadataForm.get('authors')?.markAsDirty();
|
||||
}
|
||||
this.authorInputValue = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onAuthorInputSelect(event: AutoCompleteSelectEvent) {
|
||||
const authors = (this.metadataForm.get('authors')?.value as string[]) || [];
|
||||
const value = event.value as string;
|
||||
if (!authors.includes(value)) {
|
||||
this.metadataForm.get('authors')?.setValue([...authors, value]);
|
||||
this.metadataForm.get('authors')?.markAsDirty();
|
||||
}
|
||||
setTimeout(() => this.authorInputValue = '');
|
||||
}
|
||||
|
||||
onAutoCompleteBlur(fieldName: string, event: Event): void {
|
||||
const target = event.target as HTMLInputElement;
|
||||
const inputValue = target?.value?.trim();
|
||||
if (inputValue) {
|
||||
const currentValue = this.metadataForm.get(fieldName)?.value || [];
|
||||
const values = Array.isArray(currentValue) ? currentValue :
|
||||
typeof currentValue === 'string' && currentValue ? currentValue.split(',').map((v: string) => v.trim()) : [];
|
||||
if (!values.includes(inputValue)) {
|
||||
values.push(inputValue);
|
||||
this.metadataForm.get(fieldName)?.setValue(values);
|
||||
}
|
||||
if (target) {
|
||||
target.value = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
confirmReset(): void {
|
||||
this.confirmationService.confirm({
|
||||
message: this.t.translate('bookdrop.metadataPicker.confirmResetMessage'),
|
||||
header: this.t.translate('bookdrop.metadataPicker.confirmResetHeader'),
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
acceptButtonStyleClass: 'p-button-danger',
|
||||
accept: () => this.resetAll()
|
||||
});
|
||||
}
|
||||
|
||||
resetAll(): void {
|
||||
if (this.originalMetadata) {
|
||||
const patchData: Record<string, unknown> = {};
|
||||
|
||||
for (const field of ALL_METADATA_FIELDS) {
|
||||
const key = field.controlName as keyof BookMetadata;
|
||||
const value = this.originalMetadata[key];
|
||||
|
||||
if (field.type === 'array') {
|
||||
patchData[field.controlName] = [...(value as string[] ?? [])].sort();
|
||||
} else {
|
||||
patchData[field.controlName] = value ?? null;
|
||||
}
|
||||
}
|
||||
|
||||
patchData['thumbnailUrl'] = this.urlHelper.getBookdropCoverUrl(this.bookdropFileId);
|
||||
|
||||
this.metadataForm.patchValue(patchData);
|
||||
}
|
||||
this.copiedFields = {};
|
||||
this.metadataCopied.emit(false);
|
||||
}
|
||||
}
|
||||
+349
@@ -0,0 +1,349 @@
|
||||
<ng-container *transloco="let t; prefix: 'bookdrop.fileReview'">
|
||||
<div class="main-card">
|
||||
<div class="header">
|
||||
<div class="header-content">
|
||||
<h2>
|
||||
{{ t('title') }}
|
||||
<a href="https://grimmory.org/docs/bookdrop" target="_blank" rel="noopener noreferrer">
|
||||
<i
|
||||
class="pi pi-external-link external-link-icon"
|
||||
[pTooltip]="t('viewDocumentationTooltip')"
|
||||
tooltipPosition="top"></i>
|
||||
</a>
|
||||
</h2>
|
||||
<p [innerHTML]="t('description')"></p>
|
||||
</div>
|
||||
|
||||
<div class="header-actions">
|
||||
<p-button
|
||||
[label]="t('rescan')"
|
||||
size="small"
|
||||
icon="pi pi-refresh"
|
||||
severity="primary"
|
||||
outlined
|
||||
(click)="rescanBookdrop()"
|
||||
[pTooltip]="t('rescanTooltip')"
|
||||
tooltipPosition="top">
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
@if (loading) {
|
||||
|
||||
<div class="loading-overlay">
|
||||
<div class="loading-content">
|
||||
<p-progressSpinner strokeWidth="4"/>
|
||||
<span>{{ t('loadingMessage') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
} @else {
|
||||
|
||||
<div class="controls-section">
|
||||
@if (saving) {
|
||||
<div class="saving-overlay">
|
||||
<p-progressSpinner strokeWidth="4"/>
|
||||
<div class="saving-message">
|
||||
<span>
|
||||
{{ t('savingMessage') }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (bookdropFileUis.length !== 0) {
|
||||
<div class="controls-row">
|
||||
<div class="action-buttons">
|
||||
<p-inputgroup class="importmetadata" [ngClass]="!hasSelectedFiles ? 'disabled' : ''">
|
||||
<p-button
|
||||
size="small"
|
||||
outlined
|
||||
severity="info"
|
||||
[label]="t('importMetadata')"
|
||||
icon="pi pi-copy"
|
||||
[disabled]="!hasSelectedFiles"
|
||||
(click)="copyMetadata()"
|
||||
[pTooltip]="t('importMetadataTooltip')"
|
||||
tooltipPosition="top">
|
||||
</p-button>
|
||||
<p-inputgroup-addon [pTooltip]="t('includeCoversTooltip')" tooltipPosition="top">
|
||||
<p-checkbox
|
||||
inputId="includecovers"
|
||||
[disabled]="!hasSelectedFiles"
|
||||
[binary]="true"
|
||||
[(ngModel)]="includeCoversOnCopy">
|
||||
</p-checkbox>
|
||||
<label for="includecovers"><i class="pi pi-image icon-padding-left"></i></label>
|
||||
</p-inputgroup-addon>
|
||||
</p-inputgroup>
|
||||
|
||||
<p-button
|
||||
size="small"
|
||||
class="bulkedit"
|
||||
outlined
|
||||
severity="help"
|
||||
[label]="t('bulkEdit')"
|
||||
icon="pi pi-pencil"
|
||||
[disabled]="!hasSelectedFiles"
|
||||
(click)="openBulkEditDialog()"
|
||||
[pTooltip]="t('bulkEditTooltip')"
|
||||
tooltipPosition="top">
|
||||
</p-button>
|
||||
|
||||
<p-button
|
||||
size="small"
|
||||
class="extractpattern"
|
||||
outlined
|
||||
severity="warn"
|
||||
[label]="t('extractPattern')"
|
||||
icon="pi pi-sliders-h"
|
||||
[disabled]="!hasSelectedFiles"
|
||||
(click)="openPatternExtractDialog()"
|
||||
[pTooltip]="t('extractPatternTooltip')"
|
||||
tooltipPosition="top">
|
||||
</p-button>
|
||||
</div>
|
||||
|
||||
<div class="default-controls">
|
||||
<i class="pi pi-book"
|
||||
[pTooltip]="t('specifyLibraryTooltip')"
|
||||
tooltipPosition="left"></i>
|
||||
|
||||
<p-select
|
||||
size="small"
|
||||
[options]="libraryOptions"
|
||||
optionLabel="label"
|
||||
optionValue="value"
|
||||
[placeholder]="t('libraryPlaceholder')"
|
||||
appendTo="body"
|
||||
[(ngModel)]="defaultLibraryId">
|
||||
</p-select>
|
||||
|
||||
<p-select
|
||||
size="small"
|
||||
[options]="selectedLibraryPaths"
|
||||
optionLabel="label"
|
||||
optionValue="value"
|
||||
[placeholder]="t('subpathPlaceholder')"
|
||||
appendTo="body"
|
||||
[(ngModel)]="defaultPathId">
|
||||
</p-select>
|
||||
|
||||
<p-button
|
||||
size="small"
|
||||
icon="pi pi-check"
|
||||
severity="info"
|
||||
[disabled]="!canApplyDefaults"
|
||||
(click)="applyLibraryDefaults()"
|
||||
[pTooltip]="t('applyLibraryTooltip')"
|
||||
tooltipPosition="top">
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="content-area">
|
||||
@if (bookdropFileUis.length === 0) {
|
||||
<div class="empty-state">
|
||||
{{ t('emptyState') }}
|
||||
</div>
|
||||
} @else {
|
||||
@for (file of bookdropFileUis; track file) {
|
||||
|
||||
<div class="file-item">
|
||||
<div class="file-row" [ngClass]="file.showDetails ? ' expanded' : ''">
|
||||
<p-checkbox
|
||||
[binary]="true"
|
||||
[(ngModel)]="file.selected"
|
||||
(ngModelChange)="toggleFileSelection(file.file.id, $event)">
|
||||
</p-checkbox>
|
||||
|
||||
@if (file.metadataForm.get('thumbnailUrl')?.value) {
|
||||
<img
|
||||
[src]="file.metadataForm.get('thumbnailUrl')?.value"
|
||||
alt="Cover"
|
||||
[title]="t('originalCoverTitle')"
|
||||
class="cover-image"
|
||||
(click)="file.showDetails = !file.showDetails"/>
|
||||
} @else {
|
||||
<div [title]="t('noCoverFoundTitle')" class="cover-image cover-placeholder">?</div>
|
||||
}
|
||||
|
||||
@if (file.file.fetchedMetadata?.thumbnailUrl) {
|
||||
<img
|
||||
[src]="file.file.fetchedMetadata?.thumbnailUrl"
|
||||
alt="Fetched Cover"
|
||||
[title]="t('fetchedCoverTitle')"
|
||||
class="cover-image"
|
||||
(click)="file.showDetails = !file.showDetails"/>
|
||||
} @else {
|
||||
<div [title]="t('noCoverFetchedTitle')" class="cover-image cover-placeholder">?</div>
|
||||
}
|
||||
|
||||
<div class="file-name" (click)="file.showDetails = !file.showDetails">
|
||||
{{ file.file.fileName }}
|
||||
</div>
|
||||
|
||||
<div class="file-library">
|
||||
<i
|
||||
class="pi metadata-status"
|
||||
[ngClass]="{
|
||||
'pi-check-circle copied': copiedFlags[file.file.id],
|
||||
'pi-check-circle no-metadata': !file.file.fetchedMetadata,
|
||||
'pi-exclamation-triangle not-applied': file.file.fetchedMetadata && !copiedFlags[file.file.id]
|
||||
}"
|
||||
[pTooltip]="copiedFlags[file.file.id]
|
||||
? t('metadataAppliedTooltip')
|
||||
: (!file.file.fetchedMetadata || !file.file.fetchedMetadata.title)
|
||||
? t('noMetadataTooltip')
|
||||
: t('metadataNotAppliedTooltip')"
|
||||
tooltipPosition="top">
|
||||
</i>
|
||||
|
||||
<p-select
|
||||
size="small"
|
||||
[options]="libraryOptions"
|
||||
optionLabel="label"
|
||||
optionValue="value"
|
||||
[placeholder]="t('libraryPlaceholder')"
|
||||
class="library-select"
|
||||
appendTo="body"
|
||||
[(ngModel)]="file.selectedLibraryId"
|
||||
(onChange)="onLibraryChange(file)">
|
||||
</p-select>
|
||||
|
||||
<p-select
|
||||
size="small"
|
||||
[options]="file.availablePaths"
|
||||
optionLabel="name"
|
||||
optionValue="id"
|
||||
[placeholder]="t('subpathPlaceholder')"
|
||||
class="path-select"
|
||||
appendTo="body"
|
||||
[(ngModel)]="file.selectedPathId">
|
||||
</p-select>
|
||||
|
||||
<p-button
|
||||
size="small"
|
||||
[variant]="file.file.fetchedMetadata?.title ? undefined : 'outlined'"
|
||||
[icon]="file.showDetails ? 'pi pi-chevron-up' : 'pi pi-chevron-down'"
|
||||
(click)="file.showDetails = !file.showDetails"
|
||||
[pTooltip]="file.showDetails
|
||||
? t('hideMetadataTooltip')
|
||||
: file.file.fetchedMetadata?.title
|
||||
? t('reviewMetadataTooltip')
|
||||
: t('showMetadataTooltip')"
|
||||
tooltipPosition="left">
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (file.showDetails) {
|
||||
<app-bookdrop-file-metadata-picker-component
|
||||
class="details-section"
|
||||
[originalMetadata]="file.file.originalMetadata"
|
||||
[fetchedMetadata]="file.file.fetchedMetadata!"
|
||||
[metadataForm]="file.metadataForm"
|
||||
[copiedFields]="file.copiedFields"
|
||||
[savedFields]="file.savedFields"
|
||||
[bookdropFileId]="file.file.id"
|
||||
(metadataCopied)="onMetadataCopied(file.file.id, $event)">
|
||||
</app-bookdrop-file-metadata-picker-component>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@if (!loading) {
|
||||
<p-divider></p-divider>
|
||||
|
||||
<div class="footer">
|
||||
|
||||
<div class="footer-left">
|
||||
@if (bookdropFileUis.length > 0) {
|
||||
<p-inputgroup class="selectall">
|
||||
<p-inputgroup-addon>
|
||||
<label class="selected-count-label" [pTooltip]="t('selectedCountTooltip')" tooltipPosition="top">{{ selectedCount }}</label>
|
||||
</p-inputgroup-addon>
|
||||
<p-button
|
||||
[label]="t('selectAll')"
|
||||
icon="pi pi-check-square"
|
||||
severity="info"
|
||||
(click)="selectAll(true)"
|
||||
outlined
|
||||
[pTooltip]="t('selectAllTooltip')"
|
||||
tooltipPosition="top">
|
||||
</p-button>
|
||||
</p-inputgroup>
|
||||
|
||||
<p-button
|
||||
[label]="t('clear')"
|
||||
icon="pi pi-times-circle"
|
||||
severity="warn"
|
||||
[disabled]="!hasSelectedFiles"
|
||||
(click)="selectAll(false)"
|
||||
outlined
|
||||
[pTooltip]="t('clearTooltip')"
|
||||
tooltipPosition="top">
|
||||
</p-button>
|
||||
} @else {
|
||||
<div class="spacer"></div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@if (totalRecords > pageSize) {
|
||||
<div class="footer-center">
|
||||
<p-paginator
|
||||
[rows]="pageSize"
|
||||
[totalRecords]="totalRecords"
|
||||
[first]="currentPage * pageSize"
|
||||
(onPageChange)="loadPage($event.page ?? 0)"
|
||||
[showJumpToPageDropdown]="true"
|
||||
[showPageLinks]="false"
|
||||
[showFirstLastIcon]="false"
|
||||
currentPageReportTemplate="Page {currentPage} of {totalPages}">
|
||||
</p-paginator>
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="footer-right">
|
||||
<p-button
|
||||
[label]="t('reset')"
|
||||
icon="pi pi-refresh"
|
||||
severity="warn"
|
||||
[disabled]="!hasSelectedFiles"
|
||||
outlined
|
||||
(click)="confirmReset()"
|
||||
[pTooltip]="t('resetTooltip')"
|
||||
tooltipPosition="top">
|
||||
</p-button>
|
||||
<p-button
|
||||
[label]="t('delete')"
|
||||
icon="pi pi-times"
|
||||
severity="danger"
|
||||
[disabled]="!hasSelectedFiles"
|
||||
outlined
|
||||
(click)="confirmDelete()"
|
||||
[pTooltip]="t('deleteTooltip')"
|
||||
tooltipPosition="top">
|
||||
</p-button>
|
||||
<p-button
|
||||
[label]="t('finalize')"
|
||||
[icon]="saving ? 'pi pi-spin pi-spinner' : 'pi pi-save'"
|
||||
severity="success"
|
||||
outlined
|
||||
[disabled]="!canFinalize || saving"
|
||||
(click)="confirmFinalize()"
|
||||
[pTooltip]="t('finalizeTooltip')"
|
||||
tooltipPosition="top">
|
||||
</p-button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</ng-container>
|
||||
+447
@@ -0,0 +1,447 @@
|
||||
.main-card {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: calc(100dvh - 6.1rem);
|
||||
border-radius: 0.75rem;
|
||||
overflow: hidden;
|
||||
background: var(--card-background);
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
|
||||
@media (max-width: 768px) {
|
||||
height: calc(100dvh - 4.4rem);
|
||||
border-radius: 0;
|
||||
border-width: 1px 0 0;
|
||||
}
|
||||
}
|
||||
|
||||
.header {
|
||||
padding: 1.5rem;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
border-bottom: 1px solid var(--p-content-border-color);
|
||||
gap: 1rem;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
padding: 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
.header-content {
|
||||
h2 {
|
||||
font-size: 1.25rem;
|
||||
font-weight: 600;
|
||||
padding-bottom: 0.25rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
p {
|
||||
font-size: 0.875rem;
|
||||
color: rgb(156, 163, 175);
|
||||
|
||||
strong {
|
||||
color: var(--primary-color);
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
flex-shrink: 1;
|
||||
|
||||
p {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.header-actions {
|
||||
@media (max-width: 768px) {
|
||||
display: flex;
|
||||
}
|
||||
}
|
||||
|
||||
.external-link-icon {
|
||||
color: rgb(2, 132, 199);
|
||||
cursor: pointer;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.card-body {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
flex-direction: column;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.loading-overlay {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
z-index: 50;
|
||||
border-radius: 0.75rem;
|
||||
}
|
||||
|
||||
.loading-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
|
||||
> * + * {
|
||||
margin-top: 0.75rem;
|
||||
}
|
||||
|
||||
span {
|
||||
color: var(--text-color-secondary);
|
||||
}
|
||||
|
||||
p-progressSpinner {
|
||||
width: 2rem;
|
||||
height: 2rem;
|
||||
}
|
||||
}
|
||||
|
||||
.controls-section {
|
||||
padding: 1rem;
|
||||
margin: 0;
|
||||
border-bottom: 1px solid var(--p-content-border-color);
|
||||
}
|
||||
|
||||
.saving-overlay {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
z-index: 50;
|
||||
border-radius: 0.75rem;
|
||||
|
||||
> * + * {
|
||||
margin-top: 0.75rem;
|
||||
}
|
||||
|
||||
p-progressSpinner {
|
||||
width: 2rem;
|
||||
height: 2rem;
|
||||
}
|
||||
}
|
||||
|
||||
.saving-message {
|
||||
background: rgba(17, 24, 39, 0.9);
|
||||
padding: 0.5rem 1rem;
|
||||
border-radius: 0.375rem;
|
||||
|
||||
span {
|
||||
font-size: 0.875rem;
|
||||
color: rgb(229, 231, 235);
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
|
||||
.controls-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
flex-wrap: wrap;
|
||||
|
||||
label {
|
||||
font-size: 0.875rem;
|
||||
color: var(--text-color-secondary);
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
|
||||
.default-controls {
|
||||
display: flex;
|
||||
flex-grow: 1;
|
||||
gap: 1rem;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
|
||||
p-select {
|
||||
width: 8rem;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
width: 100%;
|
||||
|
||||
label {
|
||||
display: none;
|
||||
}
|
||||
|
||||
p-select {
|
||||
flex-basis: 50%;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
::ng-deep .p-select-overlay {
|
||||
@media (max-width: 768px) {
|
||||
max-width: 70vw;
|
||||
|
||||
.p-select-option {
|
||||
white-space: normal;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.default-controls i.pi {
|
||||
color: var(--p-button-outlined-info-color);
|
||||
}
|
||||
|
||||
p-inputgroup-addon {
|
||||
background-color: transparent;
|
||||
border-color: var(--p-button-outlined-info-border-color) !important;
|
||||
color: var(--p-button-outlined-info-color);
|
||||
padding: 0 0.5em;
|
||||
|
||||
label {
|
||||
display: flex;
|
||||
color: var(--p-button-outlined-info-color) !important;
|
||||
}
|
||||
}
|
||||
|
||||
p-inputgroup.disabled {
|
||||
p-inputgroup-addon {
|
||||
opacity: var(--p-disabled-opacity) !important;
|
||||
}
|
||||
}
|
||||
|
||||
.action-buttons {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
align-items: center;
|
||||
|
||||
@media (max-width: 640px) {
|
||||
flex-wrap: wrap;
|
||||
width: 100%;
|
||||
|
||||
p-inputgroup.importmetadata {
|
||||
width: 100%;
|
||||
|
||||
p-button {
|
||||
flex-grow: 1;
|
||||
|
||||
::ng-deep button {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
p-button.bulkedit, p-button.extractpattern {
|
||||
width: calc(50% - 0.5rem);
|
||||
|
||||
::ng-deep button {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.content-area {
|
||||
flex: 1;
|
||||
padding: 0 0 1px;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: rgb(156, 163, 175);
|
||||
font-style: italic;
|
||||
padding: 2rem 0;
|
||||
}
|
||||
|
||||
.file-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.file-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
padding: 1rem;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.file-row.expanded {
|
||||
border-bottom-style: dotted;
|
||||
}
|
||||
|
||||
.status-indicator {
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
|
||||
.cover-image {
|
||||
width: 1.5rem;
|
||||
height: 2rem;
|
||||
border-radius: 0.125rem;
|
||||
object-fit: cover;
|
||||
cursor: pointer;
|
||||
transition: transform 0.2s;
|
||||
|
||||
&:hover {
|
||||
transform: scale(1.05);
|
||||
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
display: none !important;
|
||||
}
|
||||
}
|
||||
|
||||
div.cover-image {
|
||||
display: block;
|
||||
background-color: rgba(255, 255, 255, 0.1);
|
||||
text-align: center;
|
||||
line-height: 2rem;
|
||||
}
|
||||
|
||||
.file-name {
|
||||
flex: 1;
|
||||
font-weight: 500;
|
||||
font-size: 0.875rem;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: wrap;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
max-width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.metadata-status {
|
||||
&.copied {
|
||||
color: rgb(34, 197, 94);
|
||||
}
|
||||
|
||||
&.no-metadata {
|
||||
color: rgb(59, 130, 246);
|
||||
}
|
||||
|
||||
&.not-applied {
|
||||
color: rgb(239, 68, 68);
|
||||
}
|
||||
}
|
||||
|
||||
.file-library {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
justify-content: flex-end;
|
||||
align-items: center;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.library-select,
|
||||
.path-select {
|
||||
width: 8rem;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
flex-basis: 50%;
|
||||
}
|
||||
}
|
||||
|
||||
.details-section {
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
.footer, .footer-mobile {
|
||||
padding: 1rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.footer {
|
||||
@media (max-width: 768px) {
|
||||
flex-wrap: wrap;
|
||||
|
||||
::ng-deep .p-button-label {
|
||||
display: none;
|
||||
}
|
||||
|
||||
::ng-deep .p-button {
|
||||
width: var(--p-button-icon-only-width);
|
||||
padding-inline-start: 0;
|
||||
padding-inline-end: 0;
|
||||
gap: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.footer-left,
|
||||
.footer-right {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.footer-left {
|
||||
justify-content: flex-start;
|
||||
|
||||
@media (max-width: 540px) {
|
||||
order: 2;
|
||||
}
|
||||
}
|
||||
|
||||
.footer-right {
|
||||
justify-content: flex-end;
|
||||
|
||||
@media (max-width: 540px) {
|
||||
order: 3;
|
||||
}
|
||||
}
|
||||
|
||||
.footer-center {
|
||||
flex-grow: 1;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
|
||||
.p-paginator {
|
||||
flex-wrap: nowrap;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
::ng-deep .p-paginator .p-paginator-jtp-dropdown span {
|
||||
font-size: var(--p-select-sm-font-size);
|
||||
padding-block: var(--p-select-sm-padding-y);
|
||||
padding-inline: var(--p-select-sm-padding-x);
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 540px) {
|
||||
order: 1;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
.spacer {
|
||||
min-width: 10rem;
|
||||
}
|
||||
|
||||
.icon-padding-left {
|
||||
padding-left: 0.5rem;
|
||||
}
|
||||
|
||||
.cover-placeholder {
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.selected-count-label {
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
+856
@@ -0,0 +1,856 @@
|
||||
import {Component, DestroyRef, inject, OnInit, QueryList, ViewChildren} from '@angular/core';
|
||||
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
||||
import {startWith, tap} from 'rxjs/operators';
|
||||
import {PageTitleService} from "../../../../shared/service/page-title.service";
|
||||
|
||||
import {BookdropFile, BookdropFinalizePayload, BookdropFinalizeResult, BookdropService, FileExtractionResult, BulkEditRequest as BackendBulkEditRequest, BulkEditResult as BackendBulkEditResult} from '../../service/bookdrop.service';
|
||||
import {LibraryService} from '../../../book/service/library.service';
|
||||
import {Library} from '../../../book/model/library.model';
|
||||
|
||||
import {ProgressSpinner} from 'primeng/progressspinner';
|
||||
import {FormControl, FormGroup, FormsModule} from '@angular/forms';
|
||||
import {Button} from 'primeng/button';
|
||||
import {Select} from 'primeng/select';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {Divider} from 'primeng/divider';
|
||||
import {ConfirmationService, MessageService} from 'primeng/api';
|
||||
import {Subscription} from 'rxjs';
|
||||
import {InputGroup} from 'primeng/inputgroup';
|
||||
import {InputGroupAddonModule} from 'primeng/inputgroupaddon';
|
||||
|
||||
import {AppSettingsService} from '../../../../shared/service/app-settings.service';
|
||||
import {BookMetadata} from '../../../book/model/book.model';
|
||||
import {UrlHelperService} from '../../../../shared/service/url-helper.service';
|
||||
import {Checkbox} from 'primeng/checkbox';
|
||||
import {NgClass} from '@angular/common';
|
||||
import {Paginator} from 'primeng/paginator';
|
||||
import {ActivatedRoute} from '@angular/router';
|
||||
import {BookdropFileMetadataPickerComponent} from '../bookdrop-file-metadata-picker/bookdrop-file-metadata-picker.component';
|
||||
import {BookdropBulkEditDialogComponent, BulkEditResult} from '../bookdrop-bulk-edit-dialog/bookdrop-bulk-edit-dialog.component';
|
||||
import {BookdropPatternExtractDialogComponent} from '../bookdrop-pattern-extract-dialog/bookdrop-pattern-extract-dialog.component';
|
||||
import {DialogLauncherService} from '../../../../shared/services/dialog-launcher.service';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
export interface BookdropFileUI {
|
||||
file: BookdropFile;
|
||||
metadataForm: FormGroup;
|
||||
copiedFields: Record<string, boolean>;
|
||||
savedFields: Record<string, boolean>;
|
||||
selected: boolean;
|
||||
showDetails: boolean;
|
||||
selectedLibraryId: string | null;
|
||||
selectedPathId: string | null;
|
||||
availablePaths: { id: string; name: string }[];
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-bookdrop-file-review-component',
|
||||
standalone: true,
|
||||
templateUrl: './bookdrop-file-review.component.html',
|
||||
styleUrl: './bookdrop-file-review.component.scss',
|
||||
imports: [
|
||||
ProgressSpinner,
|
||||
FormsModule,
|
||||
Button,
|
||||
Select,
|
||||
BookdropFileMetadataPickerComponent,
|
||||
Tooltip,
|
||||
Divider,
|
||||
Checkbox,
|
||||
NgClass,
|
||||
Paginator,
|
||||
InputGroup,
|
||||
InputGroupAddonModule,
|
||||
TranslocoDirective,
|
||||
],
|
||||
})
|
||||
export class BookdropFileReviewComponent implements OnInit {
|
||||
private readonly bookdropService = inject(BookdropService);
|
||||
private readonly libraryService = inject(LibraryService);
|
||||
private readonly confirmationService = inject(ConfirmationService);
|
||||
private readonly destroyRef = inject(DestroyRef);
|
||||
private readonly dialogLauncherService = inject(DialogLauncherService);
|
||||
private readonly appSettingsService = inject(AppSettingsService);
|
||||
private readonly messageService = inject(MessageService);
|
||||
private readonly urlHelper = inject(UrlHelperService);
|
||||
private readonly activatedRoute = inject(ActivatedRoute);
|
||||
private readonly pageTitle = inject(PageTitleService);
|
||||
private readonly t = inject(TranslocoService);
|
||||
|
||||
@ViewChildren('metadataPicker') metadataPickers!: QueryList<BookdropFileMetadataPickerComponent>;
|
||||
|
||||
private routerSub!: Subscription;
|
||||
|
||||
uploadPattern = '';
|
||||
_defaultLibraryId: string | null = null;
|
||||
|
||||
defaultPathId: string | null = null;
|
||||
bookdropFileUis: BookdropFileUI[] = [];
|
||||
fileUiCache: Record<number, BookdropFileUI> = {};
|
||||
copiedFlags: Record<number, boolean> = {};
|
||||
loading = true;
|
||||
saving = false;
|
||||
includeCoversOnCopy = true;
|
||||
|
||||
pageSize = 50;
|
||||
totalRecords = 0;
|
||||
currentPage = 0;
|
||||
|
||||
selectAllAcrossPages = false;
|
||||
excludedFiles = new Set<number>();
|
||||
|
||||
ngOnInit(): void {
|
||||
this.pageTitle.setPageTitle(this.t.translate('bookdrop.fileReview.title'));
|
||||
|
||||
this.activatedRoute.queryParams
|
||||
.pipe(startWith({}), tap(() => {
|
||||
this.loading = true;
|
||||
this.loadPage(0);
|
||||
}))
|
||||
.subscribe();
|
||||
|
||||
const settings = this.appSettingsService.appSettings();
|
||||
if (settings) {
|
||||
this.uploadPattern = settings.uploadPattern ?? '';
|
||||
}
|
||||
}
|
||||
|
||||
get defaultLibraryId() {
|
||||
return this._defaultLibraryId;
|
||||
}
|
||||
|
||||
set defaultLibraryId(value: string | null) {
|
||||
this._defaultLibraryId = value;
|
||||
|
||||
const selected = this.libraries.find((lib) => lib?.id && String(lib.id) === value)
|
||||
|
||||
if (selected && selected.paths.length === 1) {
|
||||
this.defaultPathId = String(selected.paths[0].id)
|
||||
}
|
||||
}
|
||||
|
||||
get libraries(): Library[] {
|
||||
return this.libraryService.libraries();
|
||||
}
|
||||
|
||||
get libraryOptions() {
|
||||
if (!this.libraries) return [];
|
||||
return this.libraries.map(lib => ({label: lib.name, value: String(lib.id ?? '')}));
|
||||
}
|
||||
|
||||
get selectedLibraryPaths() {
|
||||
if (!this.libraries) return [];
|
||||
const selectedLibrary = this.libraries.find(lib => String(lib.id) === this.defaultLibraryId);
|
||||
return selectedLibrary?.paths.map(path => ({label: path.path, value: String(path.id ?? '')})) ?? [];
|
||||
}
|
||||
|
||||
get canApplyDefaults(): boolean {
|
||||
return !!(this.defaultLibraryId && this.defaultPathId);
|
||||
}
|
||||
|
||||
get canFinalize(): boolean {
|
||||
if (this.selectAllAcrossPages) {
|
||||
return (this.totalRecords - this.excludedFiles.size) > 0 && this.areAllSelectedHaveLibraryAndPath();
|
||||
}
|
||||
const selectedFiles = this.bookdropFileUis.filter(f => f.selected);
|
||||
if (selectedFiles.length === 0) return false;
|
||||
return selectedFiles.every(f => f.selectedLibraryId && f.selectedPathId);
|
||||
}
|
||||
|
||||
get hasSelectedFiles(): boolean {
|
||||
if (this.selectAllAcrossPages) {
|
||||
return this.totalRecords > this.excludedFiles.size;
|
||||
} else {
|
||||
return Object.values(this.fileUiCache).some(file => file.selected);
|
||||
}
|
||||
}
|
||||
|
||||
get selectedCount(): number {
|
||||
if (this.selectAllAcrossPages) {
|
||||
return this.totalRecords - this.excludedFiles.size;
|
||||
} else {
|
||||
return Object.values(this.fileUiCache).filter(file => file.selected).length;
|
||||
}
|
||||
}
|
||||
|
||||
loadPage(page: number): void {
|
||||
this.bookdropService.getPendingFiles(page, this.pageSize)
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe({
|
||||
next: response => {
|
||||
this.bookdropFileUis = response.content.map(file => {
|
||||
const cached = this.fileUiCache[file.id];
|
||||
if (cached) {
|
||||
cached.file = file;
|
||||
return cached;
|
||||
} else {
|
||||
const fresh = this.createFileUI(file);
|
||||
|
||||
if (this.defaultLibraryId) {
|
||||
const selectedLib = this.libraries.find(l => String(l.id) === this.defaultLibraryId);
|
||||
const selectedPaths = selectedLib?.paths ?? [];
|
||||
fresh.selectedLibraryId = this.defaultLibraryId;
|
||||
fresh.availablePaths = selectedPaths.map(p => ({id: String(p.id ?? ''), name: p.path}));
|
||||
fresh.selectedPathId = this.defaultPathId ?? null;
|
||||
}
|
||||
|
||||
this.fileUiCache[file.id] = fresh;
|
||||
return fresh;
|
||||
}
|
||||
});
|
||||
this.totalRecords = response.page.totalElements;
|
||||
this.currentPage = page;
|
||||
this.loading = false;
|
||||
this.syncCurrentPageSelection();
|
||||
},
|
||||
error: err => {
|
||||
console.error('Error loading files:', err);
|
||||
this.loading = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private async loadAllPagesIntoCache(): Promise<void> {
|
||||
const totalPages = Math.ceil(this.totalRecords / this.pageSize);
|
||||
const pagePromises: Promise<void>[] = [];
|
||||
|
||||
for (let page = 0; page < totalPages; page++) {
|
||||
const promise = new Promise<void>((resolve, reject) => {
|
||||
this.bookdropService.getPendingFiles(page, this.pageSize)
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe({
|
||||
next: response => {
|
||||
response.content.forEach(file => {
|
||||
if (!this.fileUiCache[file.id]) {
|
||||
const fresh = this.createFileUI(file);
|
||||
|
||||
if (this.defaultLibraryId) {
|
||||
const selectedLib = this.libraries.find(l => String(l.id) === this.defaultLibraryId);
|
||||
const selectedPaths = selectedLib?.paths ?? [];
|
||||
fresh.selectedLibraryId = this.defaultLibraryId;
|
||||
fresh.availablePaths = selectedPaths.map(p => ({id: String(p.id ?? ''), name: p.path}));
|
||||
fresh.selectedPathId = this.defaultPathId ?? null;
|
||||
}
|
||||
|
||||
this.fileUiCache[file.id] = fresh;
|
||||
}
|
||||
});
|
||||
resolve();
|
||||
},
|
||||
error: err => {
|
||||
console.error('Error loading page:', err);
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
pagePromises.push(promise);
|
||||
}
|
||||
|
||||
await Promise.all(pagePromises);
|
||||
}
|
||||
|
||||
onLibraryChange(file: BookdropFileUI): void {
|
||||
const lib = this.libraries.find(l => String(l.id) === file.selectedLibraryId);
|
||||
file.availablePaths = lib?.paths.map(p => ({id: String(p.id ?? ''), name: p.path})) ?? [];
|
||||
file.selectedPathId = file.availablePaths.length === 1 ? file.availablePaths[0].id : null;
|
||||
}
|
||||
|
||||
onMetadataCopied(fileId: number, copied: boolean): void {
|
||||
this.copiedFlags[fileId] = copied;
|
||||
}
|
||||
|
||||
applyLibraryDefaults(): void {
|
||||
if (!this.defaultLibraryId || !this.libraries) return;
|
||||
|
||||
const selectedLib = this.libraries.find(l => String(l.id) === this.defaultLibraryId);
|
||||
const selectedPaths = selectedLib?.paths ?? [];
|
||||
|
||||
this.getSelectedFiles().map(fileUi => {
|
||||
const cachedfUi = this.fileUiCache[fileUi.file.id];
|
||||
cachedfUi.selectedLibraryId = this.defaultLibraryId;
|
||||
cachedfUi.availablePaths = selectedPaths.map(path => ({id: String(path.id), name: path.path}));
|
||||
cachedfUi.selectedPathId = this.defaultPathId ?? null;
|
||||
});
|
||||
}
|
||||
|
||||
copyMetadata(): void {
|
||||
this.getSelectedFiles().forEach(fileUi => {
|
||||
const cachedfUi = this.fileUiCache[fileUi.file.id];
|
||||
const fetched = cachedfUi.file.fetchedMetadata;
|
||||
const form = cachedfUi.metadataForm;
|
||||
if (!fetched) return;
|
||||
for (const key of Object.keys(fetched)) {
|
||||
if (!this.includeCoversOnCopy && key === 'thumbnailUrl') continue;
|
||||
const value = fetched[key as keyof typeof fetched];
|
||||
if (value != null) {
|
||||
form.get(key)?.setValue(value);
|
||||
cachedfUi.copiedFields[key] = true;
|
||||
}
|
||||
}
|
||||
this.onMetadataCopied(cachedfUi.file.id, true);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
resetMetadata(): void {
|
||||
const selectedFiles = this.getSelectedFiles();
|
||||
|
||||
selectedFiles.forEach(fileUi => {
|
||||
const original = fileUi.file.originalMetadata;
|
||||
fileUi.metadataForm.patchValue({
|
||||
title: original?.title || null,
|
||||
subtitle: original?.subtitle || null,
|
||||
authors: [...(original?.authors ?? [])].sort(),
|
||||
categories: [...(original?.categories ?? [])].sort(),
|
||||
moods: [...(original?.moods ?? [])].sort(),
|
||||
tags: [...(original?.tags ?? [])].sort(),
|
||||
publisher: original?.publisher || null,
|
||||
publishedDate: original?.publishedDate || null,
|
||||
isbn10: original?.isbn10 ?? null,
|
||||
isbn13: original?.isbn13 ?? null,
|
||||
description: original?.description ?? null,
|
||||
pageCount: original?.pageCount ?? null,
|
||||
language: original?.language ?? null,
|
||||
asin: original?.asin ?? null,
|
||||
amazonRating: original?.amazonRating ?? null,
|
||||
amazonReviewCount: original?.amazonReviewCount ?? null,
|
||||
goodreadsId: original?.goodreadsId ?? null,
|
||||
goodreadsRating: original?.goodreadsRating ?? null,
|
||||
goodreadsReviewCount: original?.goodreadsReviewCount ?? null,
|
||||
hardcoverId: original?.hardcoverId ?? null,
|
||||
hardcoverBookId: original?.hardcoverBookId ?? null,
|
||||
hardcoverRating: original?.hardcoverRating ?? null,
|
||||
hardcoverReviewCount: original?.hardcoverReviewCount ?? null,
|
||||
lubimyczytacId: original?.lubimyczytacId ?? null,
|
||||
lubimyczytacRating: original?.lubimyczytacRating ?? null,
|
||||
googleId: original?.googleId ?? null,
|
||||
comicvineId: original?.comicvineId ?? null,
|
||||
ranobedbId: original?.ranobedbId ?? null,
|
||||
ranobedbRating: original?.ranobedbRating ?? null,
|
||||
seriesName: original?.seriesName ?? null,
|
||||
seriesNumber: original?.seriesNumber ?? null,
|
||||
seriesTotal: original?.seriesTotal ?? null,
|
||||
thumbnailUrl: this.urlHelper.getBookdropCoverUrl(fileUi.file.id),
|
||||
});
|
||||
fileUi.copiedFields = {};
|
||||
fileUi.savedFields = {};
|
||||
this.copiedFlags[fileUi.file.id] = false;
|
||||
});
|
||||
}
|
||||
|
||||
selectAll(selected: boolean): void {
|
||||
if (selected) {
|
||||
this.selectAllAcrossPages = true;
|
||||
this.excludedFiles.clear();
|
||||
Object.values(this.fileUiCache).forEach(file => file.selected = true);
|
||||
this.bookdropFileUis.forEach(file => file.selected = true);
|
||||
} else {
|
||||
this.selectAllAcrossPages = false;
|
||||
this.excludedFiles.clear();
|
||||
Object.values(this.fileUiCache).forEach(file => file.selected = false);
|
||||
this.bookdropFileUis.forEach(file => file.selected = false);
|
||||
}
|
||||
}
|
||||
|
||||
toggleFileSelection(fileId: number, selected: boolean): void {
|
||||
if (this.selectAllAcrossPages) {
|
||||
if (!selected) {
|
||||
this.excludedFiles.add(fileId);
|
||||
} else {
|
||||
this.excludedFiles.delete(fileId);
|
||||
}
|
||||
const cachedFile = this.fileUiCache[fileId];
|
||||
if (cachedFile) cachedFile.selected = selected;
|
||||
} else {
|
||||
const cachedFile = this.fileUiCache[fileId];
|
||||
if (cachedFile) cachedFile.selected = selected;
|
||||
}
|
||||
this.syncCurrentPageSelection();
|
||||
}
|
||||
|
||||
confirmReset(): void {
|
||||
const selectedCount = this.selectedCount;
|
||||
if (selectedCount === 0) {
|
||||
this.messageService.add({
|
||||
severity: 'warn',
|
||||
summary: this.t.translate('bookdrop.fileReview.toast.noFilesSelectedSummary'),
|
||||
detail: this.t.translate('bookdrop.fileReview.toast.noFilesResetDetail'),
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
this.confirmationService.confirm({
|
||||
message: this.t.translate('bookdrop.fileReview.toast.confirmResetMessage'),
|
||||
header: this.t.translate('bookdrop.fileReview.toast.confirmResetHeader'),
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
acceptLabel: this.t.translate('bookdrop.fileReview.toast.confirmResetAccept'),
|
||||
rejectLabel: this.t.translate('common.cancel'),
|
||||
rejectButtonProps: {
|
||||
severity: 'secondary',
|
||||
outlined: true
|
||||
},
|
||||
acceptButtonProps: {
|
||||
severity: 'danger',
|
||||
outlined: true
|
||||
},
|
||||
accept: () => this.resetMetadata()
|
||||
});
|
||||
}
|
||||
|
||||
confirmFinalize(): void {
|
||||
const selectedCount = this.selectedCount;
|
||||
if (selectedCount === 0) {
|
||||
this.messageService.add({
|
||||
severity: 'warn',
|
||||
summary: this.t.translate('bookdrop.fileReview.toast.noFilesSelectedSummary'),
|
||||
detail: this.t.translate('bookdrop.fileReview.toast.noFilesFinalizeDetail'),
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
this.confirmationService.confirm({
|
||||
message: this.t.translate('bookdrop.fileReview.toast.confirmFinalizeMessage', {count: selectedCount}),
|
||||
header: this.t.translate('bookdrop.fileReview.toast.confirmFinalizeHeader'),
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
acceptLabel: this.t.translate('bookdrop.fileReview.toast.confirmFinalizeAccept'),
|
||||
rejectLabel: this.t.translate('common.cancel'),
|
||||
rejectButtonProps: {
|
||||
severity: 'secondary',
|
||||
outlined: true
|
||||
},
|
||||
acceptButtonProps: {
|
||||
severity: 'success',
|
||||
outlined: true
|
||||
},
|
||||
acceptIcon: 'pi pi-check',
|
||||
accept: () => this.finalizeImport(),
|
||||
});
|
||||
}
|
||||
|
||||
confirmDelete(): void {
|
||||
const selectedCount = this.selectedCount;
|
||||
if (selectedCount === 0) {
|
||||
this.messageService.add({
|
||||
severity: 'warn',
|
||||
summary: this.t.translate('bookdrop.fileReview.toast.noFilesSelectedSummary'),
|
||||
detail: this.t.translate('bookdrop.fileReview.toast.noFilesDeleteDetail'),
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
this.confirmationService.confirm({
|
||||
message: this.t.translate('bookdrop.fileReview.toast.confirmDeleteMessage', {count: selectedCount}),
|
||||
header: this.t.translate('bookdrop.fileReview.toast.confirmDeleteHeader'),
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
acceptLabel: this.t.translate('bookdrop.fileReview.toast.confirmDeleteAccept'),
|
||||
rejectLabel: this.t.translate('common.cancel'),
|
||||
rejectButtonProps: {
|
||||
severity: 'secondary',
|
||||
outlined: true
|
||||
},
|
||||
acceptButtonProps: {
|
||||
severity: 'danger',
|
||||
outlined: true
|
||||
},
|
||||
accept: () => {
|
||||
const payload: { selectAll: boolean; excludedIds?: number[]; selectedIds?: number[] } = {
|
||||
selectAll: this.selectAllAcrossPages,
|
||||
};
|
||||
|
||||
if (this.selectAllAcrossPages) {
|
||||
payload.excludedIds = Array.from(this.excludedFiles);
|
||||
} else {
|
||||
payload.selectedIds = Object.values(this.fileUiCache)
|
||||
.filter(file => file.selected)
|
||||
.map(file => file.file.id);
|
||||
}
|
||||
|
||||
this.bookdropService.discardFiles(payload).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('bookdrop.fileReview.toast.filesDeletedSummary'),
|
||||
detail: this.t.translate('bookdrop.fileReview.toast.filesDeletedDetail'),
|
||||
});
|
||||
|
||||
this.getSelectedFiles().forEach(file => delete this.fileUiCache[file.file.id]);
|
||||
|
||||
this.selectAllAcrossPages = false;
|
||||
this.excludedFiles.clear();
|
||||
this.loadPage(this.currentPage);
|
||||
},
|
||||
error: (err) => {
|
||||
console.error('Error deleting files:', err);
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('bookdrop.fileReview.toast.deleteFailedSummary'),
|
||||
detail: this.t.translate('bookdrop.fileReview.toast.deleteFailedDetail'),
|
||||
});
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
private areAllSelectedHaveLibraryAndPath(): boolean {
|
||||
return Object.values(this.fileUiCache).every(file => {
|
||||
if (this.selectAllAcrossPages) {
|
||||
if (this.excludedFiles.has(file.file.id)) return true;
|
||||
return file.selectedLibraryId != null && file.selectedPathId != null;
|
||||
} else {
|
||||
if (!file.selected) return true;
|
||||
return file.selectedLibraryId != null && file.selectedPathId != null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private syncCurrentPageSelection(): void {
|
||||
if (this.selectAllAcrossPages) {
|
||||
this.bookdropFileUis.forEach(fileUi => {
|
||||
fileUi.selected = !this.excludedFiles.has(fileUi.file.id);
|
||||
const cachedFile = this.fileUiCache[fileUi.file.id];
|
||||
if (cachedFile) cachedFile.selected = fileUi.selected;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private finalizeImport(): void {
|
||||
this.saving = true;
|
||||
|
||||
const selectedFiles = this.getSelectedFiles();
|
||||
|
||||
const files = selectedFiles.map(fileUi => {
|
||||
const rawMetadata = fileUi.metadataForm.value;
|
||||
const metadata = {...rawMetadata};
|
||||
|
||||
if (metadata.thumbnailUrl?.includes('/api/v1/media/bookdrop')) {
|
||||
delete metadata.thumbnailUrl;
|
||||
}
|
||||
|
||||
return {
|
||||
fileId: fileUi.file.id,
|
||||
libraryId: Number(fileUi.selectedLibraryId),
|
||||
pathId: Number(fileUi.selectedPathId),
|
||||
metadata,
|
||||
};
|
||||
});
|
||||
|
||||
const payload: BookdropFinalizePayload = {
|
||||
selectAll: this.selectAllAcrossPages,
|
||||
excludedIds: this.selectAllAcrossPages ? Array.from(this.excludedFiles) : undefined,
|
||||
defaultLibraryId: this.defaultLibraryId ? Number(this.defaultLibraryId) : undefined,
|
||||
defaultPathId: this.defaultPathId ? Number(this.defaultPathId) : undefined,
|
||||
files,
|
||||
};
|
||||
|
||||
this.bookdropService.finalizeImport(payload).subscribe({
|
||||
next: (result: BookdropFinalizeResult) => {
|
||||
this.saving = false;
|
||||
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('bookdrop.fileReview.toast.importCompleteSummary'),
|
||||
detail: this.t.translate('bookdrop.fileReview.toast.importCompleteDetail'),
|
||||
});
|
||||
|
||||
this.dialogLauncherService.openBookdropFinalizeResultDialog(result);
|
||||
|
||||
const finalizedIds = new Set(files.map(f => f.fileId));
|
||||
Object.keys(this.fileUiCache).forEach(idStr => {
|
||||
const id = Number(idStr);
|
||||
if (finalizedIds.has(id)) delete this.fileUiCache[id];
|
||||
});
|
||||
|
||||
this.selectAllAcrossPages = false;
|
||||
this.excludedFiles.clear();
|
||||
this.loadPage(this.currentPage);
|
||||
},
|
||||
error: (err) => {
|
||||
console.error('Error finalizing import:', err);
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('bookdrop.fileReview.toast.importFailedSummary'),
|
||||
detail: this.t.translate('bookdrop.fileReview.toast.importFailedDetail'),
|
||||
});
|
||||
this.saving = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private createMetadataForm(original: BookMetadata | undefined, bookdropFileId: number): FormGroup {
|
||||
return new FormGroup({
|
||||
title: new FormControl(original?.title ?? ''),
|
||||
subtitle: new FormControl(original?.subtitle ?? ''),
|
||||
authors: new FormControl([...(original?.authors ?? [])].sort()),
|
||||
categories: new FormControl([...(original?.categories ?? [])].sort()),
|
||||
moods: new FormControl([...(original?.moods ?? [])].sort()),
|
||||
tags: new FormControl([...(original?.tags ?? [])].sort()),
|
||||
publisher: new FormControl(original?.publisher ?? ''),
|
||||
publishedDate: new FormControl(original?.publishedDate ?? ''),
|
||||
isbn10: new FormControl(original?.isbn10 ?? ''),
|
||||
isbn13: new FormControl(original?.isbn13 ?? ''),
|
||||
description: new FormControl(original?.description ?? ''),
|
||||
pageCount: new FormControl(original?.pageCount ?? ''),
|
||||
language: new FormControl(original?.language ?? ''),
|
||||
asin: new FormControl(original?.asin ?? ''),
|
||||
amazonRating: new FormControl(original?.amazonRating ?? ''),
|
||||
amazonReviewCount: new FormControl(original?.amazonReviewCount ?? ''),
|
||||
goodreadsId: new FormControl(original?.goodreadsId ?? ''),
|
||||
goodreadsRating: new FormControl(original?.goodreadsRating ?? ''),
|
||||
goodreadsReviewCount: new FormControl(original?.goodreadsReviewCount ?? ''),
|
||||
hardcoverId: new FormControl(original?.hardcoverId ?? ''),
|
||||
hardcoverBookId: new FormControl(original?.hardcoverBookId ?? ''),
|
||||
hardcoverRating: new FormControl(original?.hardcoverRating ?? ''),
|
||||
hardcoverReviewCount: new FormControl(original?.hardcoverReviewCount ?? ''),
|
||||
lubimyczytacId: new FormControl(original?.lubimyczytacId ?? ''),
|
||||
lubimyczytacRating: new FormControl(original?.lubimyczytacRating ?? ''),
|
||||
ranobedbId: new FormControl(original?.ranobedbId ?? ''),
|
||||
ranobedbRating: new FormControl(original?.ranobedbRating ?? ''),
|
||||
googleId: new FormControl(original?.googleId ?? ''),
|
||||
comicvineId: new FormControl(original?.comicvineId ?? ''),
|
||||
seriesName: new FormControl(original?.seriesName ?? ''),
|
||||
seriesNumber: new FormControl(original?.seriesNumber ?? ''),
|
||||
seriesTotal: new FormControl(original?.seriesTotal ?? ''),
|
||||
thumbnailUrl: new FormControl(this.urlHelper.getBookdropCoverUrl(bookdropFileId)),
|
||||
});
|
||||
}
|
||||
|
||||
private createFileUI(file: BookdropFile): BookdropFileUI {
|
||||
const metadataForm = this.createMetadataForm(file.originalMetadata, file.id);
|
||||
return {
|
||||
file,
|
||||
selected: false,
|
||||
showDetails: false,
|
||||
selectedLibraryId: null,
|
||||
selectedPathId: null,
|
||||
availablePaths: [],
|
||||
metadataForm,
|
||||
copiedFields: {},
|
||||
savedFields: {}
|
||||
};
|
||||
}
|
||||
|
||||
rescanBookdrop() {
|
||||
this.bookdropService.rescan().subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('bookdrop.fileReview.toast.rescanTriggeredSummary'),
|
||||
detail: this.t.translate('bookdrop.fileReview.toast.rescanTriggeredDetail'),
|
||||
});
|
||||
},
|
||||
error: (err) => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('bookdrop.fileReview.toast.rescanFailedSummary'),
|
||||
detail: this.t.translate('bookdrop.fileReview.toast.rescanFailedDetail'),
|
||||
});
|
||||
console.error(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
openBulkEditDialog(): void {
|
||||
const selectedFiles = this.getSelectedFiles();
|
||||
const totalCount = this.selectAllAcrossPages
|
||||
? this.totalRecords - this.excludedFiles.size
|
||||
: selectedFiles.length;
|
||||
|
||||
if (totalCount === 0) {
|
||||
this.messageService.add({
|
||||
severity: 'warn',
|
||||
summary: this.t.translate('bookdrop.fileReview.toast.noFilesSelectedSummary'),
|
||||
detail: this.t.translate('bookdrop.fileReview.toast.noFilesBulkEditDetail'),
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const dialogRef = this.dialogLauncherService.openDialog(BookdropBulkEditDialogComponent, {
|
||||
header: this.t.translate('bookdrop.fileReview.toast.bulkEditDialogHeader', {count: totalCount}),
|
||||
width: '600px',
|
||||
modal: true,
|
||||
closable: true,
|
||||
data: {fileCount: totalCount},
|
||||
});
|
||||
|
||||
dialogRef?.onClose.subscribe((result: BulkEditResult | null) => {
|
||||
if (result) {
|
||||
this.applyBulkMetadataViaBackend(result);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
openPatternExtractDialog(): void {
|
||||
const selectedFiles = this.getSelectedFiles();
|
||||
const totalCount = this.selectAllAcrossPages
|
||||
? this.totalRecords - this.excludedFiles.size
|
||||
: selectedFiles.length;
|
||||
|
||||
if (totalCount === 0) {
|
||||
this.messageService.add({
|
||||
severity: 'warn',
|
||||
summary: this.t.translate('bookdrop.fileReview.toast.noFilesSelectedSummary'),
|
||||
detail: this.t.translate('bookdrop.fileReview.toast.noFilesExtractDetail'),
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const sampleFiles = selectedFiles.slice(0, 5).map(f => f.file.fileName);
|
||||
const selectedIds = selectedFiles.map(f => f.file.id);
|
||||
|
||||
const dialogRef = this.dialogLauncherService.openDialog(BookdropPatternExtractDialogComponent, {
|
||||
header: this.t.translate('bookdrop.fileReview.toast.extractMetadataDialogHeader'),
|
||||
width: '700px',
|
||||
modal: true,
|
||||
closable: true,
|
||||
data: {
|
||||
sampleFiles,
|
||||
fileCount: totalCount,
|
||||
selectAll: this.selectAllAcrossPages,
|
||||
excludedIds: Array.from(this.excludedFiles),
|
||||
selectedIds,
|
||||
},
|
||||
});
|
||||
|
||||
dialogRef?.onClose.subscribe((result: { results: FileExtractionResult[] } | null) => {
|
||||
if (result?.results) {
|
||||
this.applyExtractedMetadata(result.results);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private getSelectedFiles(): BookdropFileUI[] {
|
||||
return Object.values(this.fileUiCache).filter(file => {
|
||||
if (this.selectAllAcrossPages) {
|
||||
return !this.excludedFiles.has(file.file.id);
|
||||
}
|
||||
return file.selected;
|
||||
});
|
||||
}
|
||||
|
||||
private async applyBulkMetadataViaBackend(result: BulkEditResult): Promise<void> {
|
||||
if (this.selectAllAcrossPages) {
|
||||
try {
|
||||
await this.loadAllPagesIntoCache();
|
||||
} catch (err) {
|
||||
console.error('Error loading pages into cache:', err);
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('bookdrop.fileReview.toast.bulkEditFailedSummary'),
|
||||
detail: this.t.translate('bookdrop.fileReview.toast.bulkEditCacheFailedDetail'),
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const selectedFiles = this.getSelectedFiles();
|
||||
const selectedIds = selectedFiles.map(f => f.file.id);
|
||||
|
||||
this.applyBulkMetadataToUI(result, selectedFiles);
|
||||
|
||||
const enabledFieldsArray = Array.from(result.enabledFields);
|
||||
|
||||
const payload: BackendBulkEditRequest = {
|
||||
fields: result.fields,
|
||||
enabledFields: enabledFieldsArray,
|
||||
mergeArrays: result.mergeArrays,
|
||||
selectAll: this.selectAllAcrossPages,
|
||||
excludedIds: this.selectAllAcrossPages ? Array.from(this.excludedFiles) : undefined,
|
||||
selectedIds: !this.selectAllAcrossPages ? selectedIds : undefined,
|
||||
};
|
||||
|
||||
this.bookdropService.bulkEditMetadata(payload).subscribe({
|
||||
next: (backendResult: BackendBulkEditResult) => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('bookdrop.fileReview.toast.bulkEditAppliedSummary'),
|
||||
detail: this.t.translate('bookdrop.fileReview.toast.bulkEditAppliedDetail', {success: backendResult.successfullyUpdated, total: backendResult.totalFiles}),
|
||||
});
|
||||
},
|
||||
error: (err) => {
|
||||
console.error('Error applying bulk edit:', err);
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('bookdrop.fileReview.toast.bulkEditFailedSummary'),
|
||||
detail: this.t.translate('bookdrop.fileReview.toast.bulkEditFailedDetail'),
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
private applyBulkMetadataToUI(result: BulkEditResult, selectedFiles: BookdropFileUI[]): void {
|
||||
selectedFiles.forEach(fileUi => {
|
||||
result.enabledFields.forEach(fieldName => {
|
||||
const value = result.fields[fieldName as keyof BookMetadata];
|
||||
if (value === undefined || value === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Array.isArray(value) && value.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const control = fileUi.metadataForm.get(fieldName);
|
||||
if (!control) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (result.mergeArrays && Array.isArray(value)) {
|
||||
const currentValue = control.value || [];
|
||||
const merged = [...new Set([...currentValue, ...value])];
|
||||
control.setValue(merged);
|
||||
} else {
|
||||
control.setValue(value);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private async applyExtractedMetadata(results: FileExtractionResult[]): Promise<void> {
|
||||
if (this.selectAllAcrossPages) {
|
||||
try {
|
||||
await this.loadAllPagesIntoCache();
|
||||
} catch (err) {
|
||||
console.error('Error loading pages into cache:', err);
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('bookdrop.fileReview.toast.patternExtractionCacheFailedSummary'),
|
||||
detail: this.t.translate('bookdrop.fileReview.toast.patternExtractionCacheFailedDetail'),
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
let appliedCount = 0;
|
||||
|
||||
results.forEach(result => {
|
||||
if (!result.success || !result.extractedMetadata) {
|
||||
return;
|
||||
}
|
||||
|
||||
const fileUi = this.fileUiCache[result.fileId];
|
||||
if (!fileUi) {
|
||||
return;
|
||||
}
|
||||
|
||||
Object.entries(result.extractedMetadata).forEach(([key, value]) => {
|
||||
if (value === null || value === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
const control = fileUi.metadataForm.get(key);
|
||||
if (control) {
|
||||
control.setValue(value);
|
||||
}
|
||||
});
|
||||
|
||||
appliedCount++;
|
||||
});
|
||||
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('bookdrop.fileReview.toast.patternExtractionAppliedSummary'),
|
||||
detail: this.t.translate('bookdrop.fileReview.toast.patternExtractionAppliedDetail', {count: appliedCount}),
|
||||
});
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
<ng-container *transloco="let t; prefix: 'bookdrop.filesWidget'">
|
||||
<div class="staging-border">
|
||||
<div class="widget-row">
|
||||
|
||||
<div class="widget-info">
|
||||
<p class="widget-title">{{ t('title') }}</p>
|
||||
<p class="widget-count">{{ pendingCount }}</p>
|
||||
@if (lastUpdatedAt) {
|
||||
<p class="widget-date">
|
||||
{{ t('lastUpdated') }} {{ lastUpdatedAt | date: 'short' }}
|
||||
</p>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="widget-actions">
|
||||
<p-button
|
||||
size="small"
|
||||
outlined
|
||||
severity="info"
|
||||
(click)="openReviewDialog()">
|
||||
{{ t('reviewBtn') }}
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
.staging-border {
|
||||
background: var(--card-background);
|
||||
border: 1px solid var(--primary-color);
|
||||
border-radius: 0.5rem;
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.widget-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.widget-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.widget-title {
|
||||
font-weight: 700;
|
||||
color: #d4d4d8;
|
||||
}
|
||||
|
||||
.widget-count {
|
||||
font-size: 1.125rem;
|
||||
font-weight: 700;
|
||||
color: var(--primary-color);
|
||||
}
|
||||
|
||||
.widget-date {
|
||||
font-size: 0.75rem;
|
||||
color: #a1a1aa;
|
||||
margin-top: 0.25rem;
|
||||
}
|
||||
|
||||
.widget-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
import {Component, inject, OnDestroy, OnInit} from '@angular/core';
|
||||
import {Subject} from 'rxjs';
|
||||
import {takeUntil} from 'rxjs/operators';
|
||||
import {BookdropFileNotification, BookdropFileService} from '../../service/bookdrop-file.service';
|
||||
import {DatePipe} from '@angular/common';
|
||||
import {Router} from '@angular/router';
|
||||
import {Button} from 'primeng/button';
|
||||
import {TranslocoDirective} from '@jsverse/transloco';
|
||||
|
||||
@Component({
|
||||
selector: 'app-bookdrop-files-widget-component',
|
||||
standalone: true,
|
||||
templateUrl: './bookdrop-files-widget.component.html',
|
||||
styleUrl: './bookdrop-files-widget.component.scss',
|
||||
imports: [
|
||||
DatePipe,
|
||||
Button,
|
||||
TranslocoDirective
|
||||
]
|
||||
})
|
||||
export class BookdropFilesWidgetComponent implements OnInit, OnDestroy {
|
||||
pendingCount = 0;
|
||||
totalCount = 0;
|
||||
lastUpdatedAt?: string;
|
||||
|
||||
private destroy$ = new Subject<void>();
|
||||
private bookdropFileService = inject(BookdropFileService);
|
||||
private router = inject(Router);
|
||||
|
||||
ngOnInit(): void {
|
||||
this.bookdropFileService.summary$
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
.subscribe((summary: BookdropFileNotification) => {
|
||||
this.pendingCount = summary.pendingCount;
|
||||
this.totalCount = summary.totalCount;
|
||||
this.lastUpdatedAt = summary.lastUpdatedAt;
|
||||
});
|
||||
}
|
||||
|
||||
openReviewDialog(): void {
|
||||
this.router.navigate(['/bookdrop'], {queryParams: {reload: Date.now()}});
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
}
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
<ng-container *transloco="let t; prefix: 'bookdrop.finalizeResult'">
|
||||
<div class="import-result-container">
|
||||
<div class="panel-header">
|
||||
<div class="header-icon-wrapper">
|
||||
<i class="pi pi-file-import header-icon"></i>
|
||||
</div>
|
||||
<div class="header-text">
|
||||
<h2 class="panel-title">{{ t('panelTitle') }}</h2>
|
||||
<p class="panel-description">{{ t('panelDescription') }}</p>
|
||||
</div>
|
||||
<p-button
|
||||
icon="pi pi-times"
|
||||
[rounded]="true"
|
||||
[text]="true"
|
||||
severity="secondary"
|
||||
(click)="ref.close()"
|
||||
class="close-button">
|
||||
</p-button>
|
||||
</div>
|
||||
|
||||
<div class="dialog-content">
|
||||
<div class="stats-grid">
|
||||
<div class="stat-card">
|
||||
<div class="stat-value total">{{ result.totalFiles }}</div>
|
||||
<div class="stat-label">{{ t('totalFiles') }}</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-value success">{{ result.successfullyImported }}</div>
|
||||
<div class="stat-label">{{ t('successfullyImported') }}</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-value failed">{{ result.failed }}</div>
|
||||
<div class="stat-label">{{ t('failed') }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="processed-info">
|
||||
<div class="processed-label">{{ t('processedAt') }}</div>
|
||||
<div class="processed-time">{{ result.processedAt | date:'medium' }}</div>
|
||||
</div>
|
||||
|
||||
<div class="results-list">
|
||||
<ul class="file-list">
|
||||
@for (r of result.results; track r) {
|
||||
<li
|
||||
class="file-item"
|
||||
[ngClass]="{
|
||||
'success': r.success,
|
||||
'error': !r.success
|
||||
}">
|
||||
<i
|
||||
class="pi status-icon"
|
||||
[ngClass]="{
|
||||
'pi-check-circle': r.success,
|
||||
'pi-times-circle': !r.success
|
||||
}">
|
||||
</i>
|
||||
|
||||
<div class="file-details">
|
||||
<span class="file-name">{{ r.fileName }}</span>
|
||||
<span class="file-message">{{ r.message }}</span>
|
||||
</div>
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
+146
@@ -0,0 +1,146 @@
|
||||
@use '../../../../shared/styles/panel-shared' as panel;
|
||||
|
||||
.import-result-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
max-width: 700px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.panel-header {
|
||||
@include panel.panel-header;
|
||||
}
|
||||
|
||||
.dialog-content {
|
||||
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);
|
||||
}
|
||||
|
||||
.stats-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
gap: 1rem;
|
||||
margin-bottom: 1.5rem;
|
||||
|
||||
@media (max-width: 480px) {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
.stat-card {
|
||||
text-align: center;
|
||||
padding: 1rem;
|
||||
background: var(--overlay-background);
|
||||
border-radius: 8px;
|
||||
|
||||
.stat-value {
|
||||
font-size: 1.875rem;
|
||||
font-weight: 700;
|
||||
margin-bottom: 0.25rem;
|
||||
|
||||
&.total {
|
||||
color: var(--primary-color);
|
||||
}
|
||||
|
||||
&.success {
|
||||
color: #22c55e;
|
||||
}
|
||||
|
||||
&.failed {
|
||||
color: #ef4444;
|
||||
}
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
font-size: 0.875rem;
|
||||
font-weight: 500;
|
||||
color: var(--text-secondary-color);
|
||||
}
|
||||
}
|
||||
|
||||
.processed-info {
|
||||
text-align: center;
|
||||
padding: 1rem;
|
||||
border-top: 1px solid var(--border-color);
|
||||
margin-bottom: 1rem;
|
||||
|
||||
.processed-label {
|
||||
font-size: 0.875rem;
|
||||
color: var(--text-secondary-color);
|
||||
margin-bottom: 0.25rem;
|
||||
}
|
||||
|
||||
.processed-time {
|
||||
font-size: 1rem;
|
||||
font-family: monospace;
|
||||
color: var(--text-color);
|
||||
}
|
||||
}
|
||||
|
||||
.results-list {
|
||||
max-height: 350px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.file-list {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.file-item {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 0.75rem;
|
||||
padding: 0.75rem;
|
||||
border-radius: 8px;
|
||||
border: 1px solid;
|
||||
transition: all 0.2s ease;
|
||||
|
||||
&.success {
|
||||
background: rgba(34, 197, 94, 0.1);
|
||||
border-color: rgba(34, 197, 94, 0.4);
|
||||
|
||||
.status-icon {
|
||||
color: #22c55e;
|
||||
}
|
||||
}
|
||||
|
||||
&.error {
|
||||
background: rgba(239, 68, 68, 0.1);
|
||||
border-color: rgba(239, 68, 68, 0.4);
|
||||
|
||||
.status-icon {
|
||||
color: #ef4444;
|
||||
}
|
||||
}
|
||||
|
||||
.status-icon {
|
||||
font-size: 1.25rem;
|
||||
margin-top: 0.125rem;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.file-details {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
.file-name {
|
||||
font-weight: 500;
|
||||
font-size: 0.875rem;
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
.file-message {
|
||||
font-size: 0.875rem;
|
||||
color: var(--text-secondary-color);
|
||||
}
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
import {Component, OnDestroy} from '@angular/core';
|
||||
import {DatePipe, NgClass} from '@angular/common';
|
||||
import {BookdropFinalizeResult} from '../../service/bookdrop.service';
|
||||
import {DynamicDialogConfig, DynamicDialogRef} from "primeng/dynamicdialog";
|
||||
import {Button} from 'primeng/button';
|
||||
import {TranslocoDirective} from '@jsverse/transloco';
|
||||
|
||||
@Component({
|
||||
selector: 'app-bookdrop-finalize-result-dialog',
|
||||
imports: [
|
||||
NgClass,
|
||||
DatePipe,
|
||||
Button,
|
||||
TranslocoDirective
|
||||
],
|
||||
templateUrl: './bookdrop-finalize-result-dialog.component.html',
|
||||
styleUrl: './bookdrop-finalize-result-dialog.component.scss'
|
||||
})
|
||||
export class BookdropFinalizeResultDialogComponent implements OnDestroy {
|
||||
|
||||
result: BookdropFinalizeResult;
|
||||
|
||||
constructor(public ref: DynamicDialogRef, public config: DynamicDialogConfig) {
|
||||
this.result = config.data.result;
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.ref?.close();
|
||||
}
|
||||
}
|
||||
+122
@@ -0,0 +1,122 @@
|
||||
<ng-container *transloco="let t; prefix: 'bookdrop.patternExtract'">
|
||||
<div class="pattern-extract-container">
|
||||
<div class="info-banner">
|
||||
<i class="pi pi-info-circle"></i>
|
||||
<span [innerHTML]="t('infoBanner', { fileCount: fileCount })"></span>
|
||||
</div>
|
||||
|
||||
<p-divider></p-divider>
|
||||
|
||||
<div class="pattern-section">
|
||||
<h4>{{ t('patternTitle') }}</h4>
|
||||
<div class="pattern-input-row">
|
||||
<input
|
||||
#patternInput
|
||||
pInputText
|
||||
[formControl]="patternControl"
|
||||
[placeholder]="t('patternPlaceholder')"
|
||||
id="pattern-input"
|
||||
[attr.aria-label]="t('patternAriaLabel')"
|
||||
class="pattern-input"
|
||||
(input)="previewPattern()"/>
|
||||
<p-button
|
||||
icon="pi pi-eye"
|
||||
[label]="t('preview')"
|
||||
severity="secondary"
|
||||
[disabled]="!hasValidPattern"
|
||||
[ariaLabel]="t('previewAriaLabel')"
|
||||
(click)="previewPattern()">
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="placeholders-section">
|
||||
<h4>{{ t('availablePlaceholdersTitle') }}</h4>
|
||||
<div class="placeholder-chips">
|
||||
@for (placeholder of availablePlaceholders; track placeholder.name) {
|
||||
<p-chip
|
||||
[label]="getPlaceholderLabel(placeholder.name)"
|
||||
[pTooltip]="getPlaceholderTooltip(placeholder)"
|
||||
tooltipPosition="top"
|
||||
class="placeholder-chip"
|
||||
(click)="insertPlaceholder(placeholder.name)">
|
||||
</p-chip>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="common-patterns-section">
|
||||
<h4>{{ t('commonPatternsTitle') }}</h4>
|
||||
<div class="common-pattern-buttons">
|
||||
@for (commonPattern of commonPatterns; track commonPattern.pattern) {
|
||||
<p-button
|
||||
[label]="getCommonPatternLabel(commonPattern.labelKey)"
|
||||
severity="secondary"
|
||||
size="small"
|
||||
outlined
|
||||
(click)="applyCommonPattern(commonPattern.pattern)">
|
||||
</p-button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p-divider></p-divider>
|
||||
|
||||
@if (previewResults.length > 0) {
|
||||
<div class="preview-section">
|
||||
<h4>{{ t('previewTitle') }}</h4>
|
||||
<div class="preview-list">
|
||||
@for (preview of previewResults; track preview.fileName) {
|
||||
<div class="preview-item" [ngClass]="getPreviewClass(preview)">
|
||||
<div class="preview-filename">
|
||||
<i class="pi"
|
||||
[ngClass]="getPreviewIconClass(preview)"
|
||||
[pTooltip]="getErrorTooltip(preview)"
|
||||
tooltipPosition="top"
|
||||
[tooltipOptions]="{showDelay: 300}"></i>
|
||||
<span>{{ preview.fileName }}</span>
|
||||
</div>
|
||||
@if (preview.success) {
|
||||
<div class="preview-extracted">
|
||||
@for (entry of getPreviewEntries(preview); track entry.key) {
|
||||
<div class="extracted-field">
|
||||
<span class="field-name">{{ entry.key }}:</span>
|
||||
<span class="field-value">{{ entry.value }}</span>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
} @else {
|
||||
<div class="preview-error">{{ getErrorMessage(preview) }}</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p-divider></p-divider>
|
||||
}
|
||||
|
||||
<div class="dialog-footer">
|
||||
@if (isExtracting) {
|
||||
<div class="extracting-indicator">
|
||||
<p-progressSpinner strokeWidth="4" [style]="spinnerStyle"></p-progressSpinner>
|
||||
<span>{{ t('extractingMessage') }}</span>
|
||||
</div>
|
||||
}
|
||||
<p-button
|
||||
[label]="'common.cancel' | transloco"
|
||||
icon="pi pi-times"
|
||||
severity="secondary"
|
||||
[disabled]="isExtracting"
|
||||
(click)="cancel()">
|
||||
</p-button>
|
||||
<p-button
|
||||
[label]="t('extractAndApply')"
|
||||
icon="pi pi-check"
|
||||
severity="success"
|
||||
[disabled]="!hasValidPattern || isExtracting"
|
||||
(click)="extract()">
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
+175
@@ -0,0 +1,175 @@
|
||||
.pattern-extract-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
padding: 0 1rem;
|
||||
max-height: 70vh;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
padding: 0;
|
||||
max-height: 95vh;
|
||||
}
|
||||
}
|
||||
|
||||
.info-banner {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 0.75rem;
|
||||
padding: 0.75rem 1rem;
|
||||
background: rgba(59, 130, 246, 0.08);
|
||||
border: 1px solid var(--p-primary-color);
|
||||
border-radius: 6px;
|
||||
color: var(--p-text-color);
|
||||
|
||||
i {
|
||||
font-size: 1.25rem;
|
||||
color: var(--p-primary-color);
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
code {
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
padding: 0.1rem 0.3rem;
|
||||
border-radius: 4px;
|
||||
font-family: monospace;
|
||||
}
|
||||
}
|
||||
|
||||
.pattern-section,
|
||||
.placeholders-section,
|
||||
.common-patterns-section,
|
||||
.preview-section {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
|
||||
h4 {
|
||||
margin: 0;
|
||||
font-size: 0.9rem;
|
||||
font-weight: 600;
|
||||
color: var(--p-text-secondary-color);
|
||||
}
|
||||
}
|
||||
|
||||
.pattern-input-row {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.pattern-input {
|
||||
flex: 1;
|
||||
font-family: monospace;
|
||||
}
|
||||
|
||||
.placeholder-chips {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
:host ::ng-deep .placeholder-chip {
|
||||
cursor: pointer;
|
||||
font-family: monospace;
|
||||
font-size: 0.85rem;
|
||||
|
||||
&:hover {
|
||||
background-color: var(--p-primary-color);
|
||||
color: var(--p-primary-contrast-color);
|
||||
}
|
||||
}
|
||||
|
||||
.common-pattern-buttons {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.preview-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
max-height: 200px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.preview-item {
|
||||
padding: 0.75rem;
|
||||
border-radius: 6px;
|
||||
border: 1px solid var(--p-surface-300);
|
||||
|
||||
&.preview-success {
|
||||
background-color: rgba(76, 175, 80, 0.1);
|
||||
border-color: rgba(76, 175, 80, 0.3);
|
||||
}
|
||||
|
||||
&.preview-failure {
|
||||
background-color: rgba(244, 67, 54, 0.1);
|
||||
border-color: rgba(244, 67, 54, 0.3);
|
||||
}
|
||||
}
|
||||
|
||||
.preview-filename {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
font-weight: 500;
|
||||
margin-bottom: 0.5rem;
|
||||
|
||||
i {
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.pi-check-circle {
|
||||
color: #4caf50;
|
||||
}
|
||||
|
||||
.pi-times-circle {
|
||||
color: #f44336;
|
||||
}
|
||||
}
|
||||
|
||||
.preview-extracted {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.5rem 1rem;
|
||||
padding-left: 1.5rem;
|
||||
}
|
||||
|
||||
.extracted-field {
|
||||
display: flex;
|
||||
gap: 0.25rem;
|
||||
font-size: 0.85rem;
|
||||
|
||||
.field-name {
|
||||
color: var(--p-text-secondary-color);
|
||||
}
|
||||
|
||||
.field-value {
|
||||
font-weight: 500;
|
||||
color: var(--p-primary-color);
|
||||
}
|
||||
}
|
||||
|
||||
.preview-error {
|
||||
padding-left: 1.5rem;
|
||||
font-size: 0.85rem;
|
||||
color: var(--p-text-secondary-color);
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.dialog-footer {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
padding-top: 0.5rem;
|
||||
}
|
||||
|
||||
.extracting-indicator {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
margin-right: auto;
|
||||
color: var(--p-text-secondary-color);
|
||||
}
|
||||
+309
@@ -0,0 +1,309 @@
|
||||
import {Component, ElementRef, inject, OnInit, ViewChild} from '@angular/core';
|
||||
import {FormControl, FormGroup, ReactiveFormsModule, Validators} from '@angular/forms';
|
||||
import {DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {Button} from 'primeng/button';
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
import {Divider} from 'primeng/divider';
|
||||
import {Chip} from 'primeng/chip';
|
||||
import {ProgressSpinner} from 'primeng/progressspinner';
|
||||
import {BookdropService, PatternExtractResult} from '../../service/bookdrop.service';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {NgClass} from '@angular/common';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {TranslocoDirective, TranslocoPipe, TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
interface PatternPlaceholder {
|
||||
name: string;
|
||||
descriptionKey: string;
|
||||
exampleKey: string;
|
||||
}
|
||||
|
||||
interface PreviewResult {
|
||||
fileName: string;
|
||||
success: boolean;
|
||||
preview: Record<string, string>;
|
||||
errorMessage?: string;
|
||||
}
|
||||
|
||||
const PLACEHOLDER_KEY_MAP: Record<string, string> = {
|
||||
'*': 'wildcard',
|
||||
'SeriesName': 'seriesName',
|
||||
'Title': 'title',
|
||||
'Subtitle': 'subtitle',
|
||||
'Authors': 'authors',
|
||||
'SeriesNumber': 'seriesNumber',
|
||||
'Published': 'published',
|
||||
'Publisher': 'publisher',
|
||||
'Language': 'language',
|
||||
'SeriesTotal': 'seriesTotal',
|
||||
'ISBN10': 'isbn10',
|
||||
'ISBN13': 'isbn13',
|
||||
'ASIN': 'asin',
|
||||
};
|
||||
|
||||
@Component({
|
||||
selector: 'app-bookdrop-pattern-extract-dialog',
|
||||
standalone: true,
|
||||
imports: [
|
||||
ReactiveFormsModule,
|
||||
Button,
|
||||
InputText,
|
||||
Divider,
|
||||
Chip,
|
||||
ProgressSpinner,
|
||||
NgClass,
|
||||
Tooltip,
|
||||
TranslocoDirective,
|
||||
TranslocoPipe,
|
||||
],
|
||||
templateUrl: './bookdrop-pattern-extract-dialog.component.html',
|
||||
styleUrl: './bookdrop-pattern-extract-dialog.component.scss'
|
||||
})
|
||||
export class BookdropPatternExtractDialogComponent implements OnInit {
|
||||
|
||||
private readonly dialogRef = inject(DynamicDialogRef);
|
||||
private readonly config = inject(DynamicDialogConfig);
|
||||
private readonly bookdropService = inject(BookdropService);
|
||||
private readonly messageService = inject(MessageService);
|
||||
private readonly t = inject(TranslocoService);
|
||||
|
||||
@ViewChild('patternInput', {static: false}) patternInput?: ElementRef<HTMLInputElement>;
|
||||
|
||||
fileCount = 0;
|
||||
selectAll = false;
|
||||
excludedIds: number[] = [];
|
||||
selectedIds: number[] = [];
|
||||
|
||||
isExtracting = false;
|
||||
previewResults: PreviewResult[] = [];
|
||||
|
||||
spinnerStyle = {width: '24px', height: '24px'};
|
||||
|
||||
patternForm = new FormGroup({
|
||||
pattern: new FormControl('', Validators.required),
|
||||
});
|
||||
|
||||
availablePlaceholders: PatternPlaceholder[] = [
|
||||
{name: '*', descriptionKey: 'placeholders.wildcard', exampleKey: 'placeholderExamples.wildcard'},
|
||||
{name: 'SeriesName', descriptionKey: 'placeholders.seriesName', exampleKey: 'placeholderExamples.seriesName'},
|
||||
{name: 'Title', descriptionKey: 'placeholders.title', exampleKey: 'placeholderExamples.title'},
|
||||
{name: 'Subtitle', descriptionKey: 'placeholders.subtitle', exampleKey: 'placeholderExamples.subtitle'},
|
||||
{name: 'Authors', descriptionKey: 'placeholders.authors', exampleKey: 'placeholderExamples.authors'},
|
||||
{name: 'SeriesNumber', descriptionKey: 'placeholders.seriesNumber', exampleKey: 'placeholderExamples.seriesNumber'},
|
||||
{name: 'Published', descriptionKey: 'placeholders.published', exampleKey: 'placeholderExamples.published'},
|
||||
{name: 'Publisher', descriptionKey: 'placeholders.publisher', exampleKey: 'placeholderExamples.publisher'},
|
||||
{name: 'Language', descriptionKey: 'placeholders.language', exampleKey: 'placeholderExamples.language'},
|
||||
{name: 'SeriesTotal', descriptionKey: 'placeholders.seriesTotal', exampleKey: 'placeholderExamples.seriesTotal'},
|
||||
{name: 'ISBN10', descriptionKey: 'placeholders.isbn10', exampleKey: 'placeholderExamples.isbn10'},
|
||||
{name: 'ISBN13', descriptionKey: 'placeholders.isbn13', exampleKey: 'placeholderExamples.isbn13'},
|
||||
{name: 'ASIN', descriptionKey: 'placeholders.asin', exampleKey: 'placeholderExamples.asin'},
|
||||
];
|
||||
|
||||
commonPatterns = [
|
||||
{labelKey: 'commonPatternLabels.authorTitle', pattern: '{Authors} - {Title}'},
|
||||
{labelKey: 'commonPatternLabels.titleAuthor', pattern: '{Title} - {Authors}'},
|
||||
{labelKey: 'commonPatternLabels.titleYear', pattern: '{Title} ({Published:yyyy})'},
|
||||
{labelKey: 'commonPatternLabels.authorTitleYear', pattern: '{Authors} - {Title} ({Published:yyyy})'},
|
||||
{labelKey: 'commonPatternLabels.seriesNumber', pattern: '{SeriesName} #{SeriesNumber}'},
|
||||
{labelKey: 'commonPatternLabels.seriesChapter', pattern: '{SeriesName} - Chapter {SeriesNumber}'},
|
||||
{labelKey: 'commonPatternLabels.seriesVol', pattern: '{SeriesName} - Vol {SeriesNumber}'},
|
||||
{labelKey: 'commonPatternLabels.tagSeriesChapter', pattern: '[*] {SeriesName} - Chapter {SeriesNumber}'},
|
||||
{labelKey: 'commonPatternLabels.titleByAuthor', pattern: '{Title} by {Authors}'},
|
||||
{labelKey: 'commonPatternLabels.seriesVTotal', pattern: '{SeriesName} v{SeriesNumber} (of {SeriesTotal})'},
|
||||
];
|
||||
|
||||
ngOnInit(): void {
|
||||
this.fileCount = this.config.data?.fileCount ?? 0;
|
||||
this.selectAll = this.config.data?.selectAll ?? false;
|
||||
this.excludedIds = this.config.data?.excludedIds ?? [];
|
||||
this.selectedIds = this.config.data?.selectedIds ?? [];
|
||||
}
|
||||
|
||||
insertPlaceholder(placeholderName: string): void {
|
||||
const patternControl = this.patternForm.get('pattern');
|
||||
const currentPattern = patternControl?.value ?? '';
|
||||
const inputElement = this.patternInput?.nativeElement;
|
||||
|
||||
const textToInsert = placeholderName === '*' ? '*' : `{${placeholderName}}`;
|
||||
|
||||
const patternToModify = placeholderName === '*'
|
||||
? currentPattern
|
||||
: this.removeExistingPlaceholder(currentPattern, placeholderName);
|
||||
|
||||
if (inputElement) {
|
||||
const cursorPosition = this.calculateCursorPosition(inputElement, currentPattern, patternToModify);
|
||||
const newPattern = this.insertTextAtCursor(patternToModify, textToInsert, cursorPosition);
|
||||
|
||||
patternControl?.setValue(newPattern);
|
||||
this.focusInputAfterInsertion(inputElement, cursorPosition, textToInsert.length);
|
||||
} else {
|
||||
patternControl?.setValue(patternToModify + textToInsert);
|
||||
}
|
||||
|
||||
this.previewPattern();
|
||||
}
|
||||
|
||||
private removeExistingPlaceholder(pattern: string, placeholderName: string): string {
|
||||
const existingPlaceholderRegex = new RegExp(`\\{${placeholderName}(?::[^}]*)?\\}`, 'g');
|
||||
return pattern.replace(existingPlaceholderRegex, '');
|
||||
}
|
||||
|
||||
private calculateCursorPosition(inputElement: HTMLInputElement, originalPattern: string, modifiedPattern: string): number {
|
||||
let cursorPosition = inputElement.selectionStart ?? modifiedPattern.length;
|
||||
|
||||
if (originalPattern !== modifiedPattern) {
|
||||
const existingPlaceholderRegex = new RegExp(`\\{\\w+(?::[^}]*)?\\}`, 'g');
|
||||
const matchBefore = originalPattern.substring(0, cursorPosition).match(existingPlaceholderRegex);
|
||||
if (matchBefore) {
|
||||
cursorPosition -= matchBefore.reduce((sum, match) => sum + match.length, 0);
|
||||
}
|
||||
cursorPosition = Math.max(0, cursorPosition);
|
||||
}
|
||||
|
||||
return cursorPosition;
|
||||
}
|
||||
|
||||
private insertTextAtCursor(pattern: string, text: string, cursorPosition: number): string {
|
||||
const textBefore = pattern.substring(0, cursorPosition);
|
||||
const textAfter = pattern.substring(cursorPosition);
|
||||
return textBefore + text + textAfter;
|
||||
}
|
||||
|
||||
private focusInputAfterInsertion(inputElement: HTMLInputElement, cursorPosition: number, insertedTextLength: number): void {
|
||||
setTimeout(() => {
|
||||
const newCursorPosition = cursorPosition + insertedTextLength;
|
||||
inputElement.setSelectionRange(newCursorPosition, newCursorPosition);
|
||||
inputElement.focus();
|
||||
}, 0);
|
||||
}
|
||||
|
||||
applyCommonPattern(pattern: string): void {
|
||||
this.patternForm.get('pattern')?.setValue(pattern);
|
||||
this.previewPattern();
|
||||
}
|
||||
|
||||
previewPattern(): void {
|
||||
const pattern = this.patternForm.get('pattern')?.value;
|
||||
if (!pattern) {
|
||||
this.previewResults = [];
|
||||
return;
|
||||
}
|
||||
|
||||
const request = {
|
||||
pattern,
|
||||
selectAll: this.selectAll,
|
||||
excludedIds: this.excludedIds,
|
||||
selectedIds: this.selectedIds,
|
||||
preview: true
|
||||
};
|
||||
|
||||
this.bookdropService.extractFromPattern(request).subscribe({
|
||||
next: (result) => {
|
||||
this.previewResults = result.results.map(r => ({
|
||||
fileName: r.fileName,
|
||||
success: r.success,
|
||||
preview: r.extractedMetadata || {},
|
||||
errorMessage: r.errorMessage
|
||||
}));
|
||||
},
|
||||
error: () => {
|
||||
this.previewResults = [];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
cancel(): void {
|
||||
this.dialogRef.close(null);
|
||||
}
|
||||
|
||||
extract(): void {
|
||||
const pattern = this.patternForm.get('pattern')?.value;
|
||||
if (!pattern) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.isExtracting = true;
|
||||
|
||||
const payload = {
|
||||
pattern,
|
||||
selectAll: this.selectAll,
|
||||
excludedIds: this.excludedIds,
|
||||
selectedIds: this.selectedIds,
|
||||
preview: false,
|
||||
};
|
||||
|
||||
this.bookdropService.extractFromPattern(payload).subscribe({
|
||||
next: (result: PatternExtractResult) => {
|
||||
this.isExtracting = false;
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('bookdrop.patternExtract.toast.extractionCompleteSummary'),
|
||||
detail: this.t.translate('bookdrop.patternExtract.toast.extractionCompleteDetail', {
|
||||
success: result.successfullyExtracted,
|
||||
total: result.totalFiles
|
||||
}),
|
||||
});
|
||||
this.dialogRef.close(result);
|
||||
},
|
||||
error: (err) => {
|
||||
this.isExtracting = false;
|
||||
console.error('Pattern extraction failed:', err);
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('bookdrop.patternExtract.toast.extractionFailedSummary'),
|
||||
detail: this.t.translate('bookdrop.patternExtract.toast.extractionFailedDetail'),
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
get hasValidPattern(): boolean {
|
||||
const pattern: string = this.patternForm.get('pattern')?.value ?? '';
|
||||
if (!this.patternForm.valid || !pattern) {
|
||||
return false;
|
||||
}
|
||||
const placeholderRegex = /\{[a-zA-Z0-9_]+(?::[^{}]+)?\}|\*/;
|
||||
return placeholderRegex.test(pattern);
|
||||
}
|
||||
|
||||
get patternControl(): FormControl {
|
||||
return this.patternForm.get('pattern') as FormControl;
|
||||
}
|
||||
|
||||
getPlaceholderLabel(name: string): string {
|
||||
return name === '*' ? '*' : `{${name}}`;
|
||||
}
|
||||
|
||||
getPlaceholderTooltip(placeholder: PatternPlaceholder): string {
|
||||
const description = this.t.translate(`bookdrop.patternExtract.${placeholder.descriptionKey}`);
|
||||
const example = this.t.translate(`bookdrop.patternExtract.${placeholder.exampleKey}`);
|
||||
return `${description} (e.g., ${example})`;
|
||||
}
|
||||
|
||||
getCommonPatternLabel(labelKey: string): string {
|
||||
return this.t.translate(`bookdrop.patternExtract.${labelKey}`);
|
||||
}
|
||||
|
||||
getPreviewClass(preview: PreviewResult): Record<string, boolean> {
|
||||
return {
|
||||
'preview-success': preview.success,
|
||||
'preview-failure': !preview.success
|
||||
};
|
||||
}
|
||||
|
||||
getPreviewIconClass(preview: PreviewResult): string {
|
||||
return preview.success ? 'pi-check-circle' : 'pi-times-circle';
|
||||
}
|
||||
|
||||
getPreviewEntries(preview: PreviewResult): {key: string; value: string}[] {
|
||||
return Object.entries(preview.preview).map(([key, value]) => ({key, value}));
|
||||
}
|
||||
|
||||
getErrorMessage(preview: PreviewResult): string {
|
||||
return preview.errorMessage || this.t.translate('bookdrop.patternExtract.patternDidNotMatch');
|
||||
}
|
||||
|
||||
getErrorTooltip(preview: PreviewResult): string {
|
||||
return preview.success ? '' : (preview.errorMessage || this.t.translate('bookdrop.patternExtract.patternDidNotMatchStructure'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import {inject, Injectable} from '@angular/core';
|
||||
import {API_CONFIG} from '../../../core/config/api-config';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {Observable} from 'rxjs';
|
||||
import {BookdropFileNotification} from './bookdrop-file.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class BookdropFileApiService {
|
||||
|
||||
private readonly url = `${API_CONFIG.BASE_URL}/api/v1/bookdrop`;
|
||||
private http = inject(HttpClient);
|
||||
|
||||
getNotification(): Observable<BookdropFileNotification> {
|
||||
return this.http.get<BookdropFileNotification>(`${this.url}/notification`);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
import {effect, inject, Injectable, OnDestroy} from '@angular/core';
|
||||
import {BehaviorSubject, Subscription} from 'rxjs';
|
||||
import {map} from 'rxjs/operators';
|
||||
import {BookdropFileApiService} from './bookdrop-file-api.service';
|
||||
import {AuthService} from '../../../shared/service/auth.service';
|
||||
import {UserService} from '../../settings/user-management/user.service';
|
||||
|
||||
export interface BookdropFileNotification {
|
||||
pendingCount: number;
|
||||
totalCount: number;
|
||||
lastUpdatedAt?: string;
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class BookdropFileService implements OnDestroy {
|
||||
private summarySubject = new BehaviorSubject<BookdropFileNotification>({
|
||||
pendingCount: 0,
|
||||
totalCount: 0
|
||||
});
|
||||
|
||||
summary$ = this.summarySubject.asObservable();
|
||||
|
||||
hasPendingFiles$ = this.summary$.pipe(
|
||||
map(summary => summary.pendingCount > 0)
|
||||
);
|
||||
|
||||
private apiService = inject(BookdropFileApiService);
|
||||
private authService = inject(AuthService);
|
||||
private subscriptions = new Subscription();
|
||||
private userService = inject(UserService);
|
||||
private hasInitialized = false;
|
||||
|
||||
constructor() {
|
||||
effect(() => {
|
||||
const user = this.userService.currentUser();
|
||||
if (this.hasInitialized || !user) {
|
||||
return;
|
||||
}
|
||||
this.hasInitialized = true;
|
||||
|
||||
if ((user.permissions.admin || user.permissions.canAccessBookdrop) && this.authService.token()) {
|
||||
this.refresh();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
handleIncomingFile(summary: BookdropFileNotification): void {
|
||||
this.summarySubject.next(summary);
|
||||
}
|
||||
|
||||
refresh(): void {
|
||||
const sub = this.apiService.getNotification().subscribe({
|
||||
next: summary => this.summarySubject.next(summary),
|
||||
error: err => console.warn('Failed to refresh bookdrop file summary:', err)
|
||||
});
|
||||
this.subscriptions.add(sub);
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.subscriptions.unsubscribe();
|
||||
this.summarySubject.complete();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
import {inject, Injectable} from '@angular/core';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {Observable} from 'rxjs';
|
||||
import {BookMetadata} from '../../book/model/book.model';
|
||||
import {API_CONFIG} from '../../../core/config/api-config';
|
||||
|
||||
export enum BookdropFileStatus {
|
||||
ACCEPTED = 'ACCEPTED',
|
||||
REJECTED = 'REJECTED',
|
||||
}
|
||||
|
||||
export interface BookdropFinalizePayload {
|
||||
selectAll?: boolean;
|
||||
excludedIds?: number[];
|
||||
defaultLibraryId?: number;
|
||||
defaultPathId?: number;
|
||||
files?: {
|
||||
fileId: number;
|
||||
libraryId: number;
|
||||
pathId: number;
|
||||
metadata: BookMetadata;
|
||||
}[];
|
||||
}
|
||||
|
||||
export interface BookdropFile {
|
||||
showDetails: boolean;
|
||||
id: number;
|
||||
fileName: string;
|
||||
filePath: string;
|
||||
fileSize: number;
|
||||
originalMetadata?: BookMetadata;
|
||||
fetchedMetadata?: BookMetadata;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
status: BookdropFileStatus;
|
||||
}
|
||||
|
||||
export interface BookdropFileResult {
|
||||
fileName: string;
|
||||
success: boolean;
|
||||
message: string;
|
||||
}
|
||||
|
||||
export interface BookdropFinalizeResult {
|
||||
totalFiles: number;
|
||||
successfullyImported: number;
|
||||
failed: number;
|
||||
processedAt: string;
|
||||
results: BookdropFileResult[];
|
||||
}
|
||||
|
||||
export interface Page<T> {
|
||||
content: T[];
|
||||
page: {
|
||||
totalElements: number;
|
||||
totalPages: number;
|
||||
number: number;
|
||||
size: number;
|
||||
};
|
||||
}
|
||||
|
||||
export interface PatternExtractRequest {
|
||||
pattern: string;
|
||||
selectAll?: boolean;
|
||||
excludedIds?: number[];
|
||||
selectedIds?: number[];
|
||||
preview?: boolean;
|
||||
}
|
||||
|
||||
export interface FileExtractionResult {
|
||||
fileId: number;
|
||||
fileName: string;
|
||||
success: boolean;
|
||||
extractedMetadata?: BookMetadata;
|
||||
errorMessage?: string;
|
||||
}
|
||||
|
||||
export interface PatternExtractResult {
|
||||
totalFiles: number;
|
||||
successfullyExtracted: number;
|
||||
failed: number;
|
||||
results: FileExtractionResult[];
|
||||
}
|
||||
|
||||
export interface BulkEditRequest {
|
||||
fields: Partial<BookMetadata>;
|
||||
enabledFields: string[];
|
||||
mergeArrays: boolean;
|
||||
selectAll?: boolean;
|
||||
excludedIds?: number[];
|
||||
selectedIds?: number[];
|
||||
}
|
||||
|
||||
export interface BulkEditResult {
|
||||
totalFiles: number;
|
||||
successfullyUpdated: number;
|
||||
failed: number;
|
||||
}
|
||||
|
||||
@Injectable({providedIn: 'root'})
|
||||
export class BookdropService {
|
||||
private readonly url = `${API_CONFIG.BASE_URL}/api/v1/bookdrop`;
|
||||
private http = inject(HttpClient);
|
||||
|
||||
getPendingFiles(page: number = 0, size: number = 50): Observable<Page<BookdropFile>> {
|
||||
return this.http.get<Page<BookdropFile>>(`${this.url}/files?status=pending&page=${page}&size=${size}`);
|
||||
}
|
||||
|
||||
finalizeImport(payload: BookdropFinalizePayload): Observable<BookdropFinalizeResult> {
|
||||
return this.http.post<BookdropFinalizeResult>(`${this.url}/imports/finalize`, payload);
|
||||
}
|
||||
|
||||
discardFiles(payload: { selectAll: boolean; excludedIds?: number[]; selectedIds?: number[] }): Observable<void> {
|
||||
return this.http.post<void>(`${this.url}/files/discard`, payload);
|
||||
}
|
||||
|
||||
rescan(): Observable<void> {
|
||||
return this.http.post<void>(`${this.url}/rescan`, {});
|
||||
}
|
||||
|
||||
extractFromPattern(payload: PatternExtractRequest): Observable<PatternExtractResult> {
|
||||
return this.http.post<PatternExtractResult>(`${this.url}/files/extract-pattern`, payload);
|
||||
}
|
||||
|
||||
bulkEditMetadata(payload: BulkEditRequest): Observable<BulkEditResult> {
|
||||
return this.http.post<BulkEditResult>(`${this.url}/files/bulk-edit`, payload);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user