Improve Angular project structure and code organization (#1328)
This commit is contained in:
+246
@@ -0,0 +1,246 @@
|
||||
@if (fetchedMetadata) {
|
||||
<form [formGroup]="metadataForm" class="flex flex-col h-[35rem] w-full">
|
||||
<div class="flex-grow overflow-auto">
|
||||
<div class="relative flex items-center justify-between pb-3">
|
||||
<div class="absolute left-1/2 transform -translate-x-1/2 flex items-center pl-24">
|
||||
<p class="pr-6">Current Metadata</p>
|
||||
<div>
|
||||
<p-button
|
||||
severity="success"
|
||||
icon="pi pi-angle-left"
|
||||
class="mx-2"
|
||||
[outlined]="true"
|
||||
pTooltip="Move all missing fields"
|
||||
tooltipPosition="bottom"
|
||||
(onClick)="copyMissing()"
|
||||
></p-button>
|
||||
<p-button
|
||||
severity="success"
|
||||
icon="pi pi-angle-double-left"
|
||||
class="mx-2"
|
||||
[outlined]="true"
|
||||
pTooltip="Move all fields"
|
||||
tooltipPosition="bottom"
|
||||
(onClick)="copyAll()"
|
||||
></p-button>
|
||||
</div>
|
||||
<p class="pl-6">Fetched Metadata</p>
|
||||
</div>
|
||||
<div class="ml-auto">
|
||||
<p-button
|
||||
severity="danger"
|
||||
icon="pi pi-refresh"
|
||||
label="Reset"
|
||||
[outlined]="true"
|
||||
pTooltip="Reset all fields to original values"
|
||||
tooltipPosition="bottom"
|
||||
(onClick)="resetAll()"
|
||||
></p-button>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<div class="flex items-center py-1">
|
||||
<label class="w-[6.5%]"></label>
|
||||
<div class="flex w-full items-center justify-center">
|
||||
<p-image class="thumbnail" [src]="metadataForm.get('thumbnailUrl')?.value" alt="Image" appendTo="body" lazyLoad [preview]="true"></p-image>
|
||||
<input type="hidden" id="thumbnailUrl" formControlName="thumbnailUrl" class="!w-1/2"/>
|
||||
<p-button
|
||||
[icon]="isValueSaved('thumbnailUrl') ? 'pi pi-check' : (hoveredFields['thumbnailUrl'] && isValueCopied('thumbnailUrl') ? 'pi pi-times' : 'pi pi-arrow-left')"
|
||||
[outlined]="true"
|
||||
[ngClass]="
|
||||
{
|
||||
'green-outlined-button': isValueCopied('thumbnailUrl') && !hoveredFields['thumbnailUrl'],
|
||||
'red-outlined-button': isValueCopied('thumbnailUrl') && hoveredFields['thumbnailUrl']
|
||||
}"
|
||||
class="arrow-button"
|
||||
(click)="hoveredFields['thumbnailUrl'] && isValueCopied('thumbnailUrl') ? resetField('thumbnailUrl') : copyFetchedToCurrent('thumbnailUrl')"
|
||||
(mouseenter)="onMouseEnter('thumbnailUrl')"
|
||||
(mouseleave)="onMouseLeave('thumbnailUrl')"/>
|
||||
<input type="hidden" [value]="fetchedMetadata.thumbnailUrl" class="!w-1/2" readonly/>
|
||||
<p-image class="thumbnail" [src]="fetchedMetadata.thumbnailUrl!" alt="Image" appendTo="body" lazyLoad [preview]="true"></p-image>
|
||||
</div>
|
||||
</div>
|
||||
@for (field of metadataFieldsTop; track field) {
|
||||
<div class="flex items-center py-1">
|
||||
<label for="{{field.controlName}}" class="w-[6.5%]">{{ field.label }}</label>
|
||||
<div class="flex w-full">
|
||||
<input
|
||||
pSize="small"
|
||||
fluid
|
||||
pInputText
|
||||
id="{{field.controlName}}"
|
||||
formControlName="{{field.controlName}}"
|
||||
class="!w-1/2"
|
||||
[ngClass]="{
|
||||
'outlined-input-green': isValueCopied(field.controlName) && !hoveredFields[field.controlName],
|
||||
}"
|
||||
/>
|
||||
<p-button
|
||||
[icon]="isValueSaved(field.controlName) ? 'pi pi-check' : (hoveredFields[field.controlName] && isValueCopied(field.controlName) ? 'pi pi-times' : 'pi pi-arrow-left')"
|
||||
[outlined]="true"
|
||||
[ngClass]="
|
||||
{
|
||||
'green-outlined-button': isValueCopied(field.controlName) && !hoveredFields[field.controlName],
|
||||
'red-outlined-button': isValueCopied(field.controlName) && hoveredFields[field.controlName]
|
||||
}"
|
||||
class="arrow-button"
|
||||
(click)="hoveredFields[field.controlName] && isValueCopied(field.controlName) ? resetField(field.controlName) : copyFetchedToCurrent(field.controlName)"
|
||||
(mouseenter)="onMouseEnter(field.controlName)"
|
||||
(mouseleave)="onMouseLeave(field.controlName)"/>
|
||||
<input pSize="small" pInputText [value]="fetchedMetadata[field.fetchedKey] ?? null" class="!w-1/2" readonly/>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
@for (field of metadataChips; track field) {
|
||||
<div class="flex items-center py-1">
|
||||
<label for="{{field.controlName}}" class="w-[6.5%]">{{ field.label }}</label>
|
||||
<div class="flex w-full items-center">
|
||||
<div class="w-full"
|
||||
[ngClass]="{
|
||||
'outlined-input-green': isValueCopied(field.controlName) && !hoveredFields[field.controlName],
|
||||
}">
|
||||
<p-autoComplete formControlName="{{field.controlName}}" [multiple]="true" [typeahead]="false" [dropdown]="false" [forceSelection]="false" styleClass="w-full" (onBlur)="onAutoCompleteBlur(field.controlName, $event)"></p-autoComplete>
|
||||
</div>
|
||||
<p-button
|
||||
[icon]="isValueSaved(field.controlName) ? 'pi pi-check' : (hoveredFields[field.controlName] && isValueCopied(field.controlName) ? 'pi pi-times' : 'pi pi-arrow-left')"
|
||||
[outlined]="true"
|
||||
[ngClass]="
|
||||
{
|
||||
'green-outlined-button': isValueCopied(field.controlName) && !hoveredFields[field.controlName],
|
||||
'red-outlined-button': isValueCopied(field.controlName) && hoveredFields[field.controlName]
|
||||
}"
|
||||
class="arrow-button"
|
||||
(click)="hoveredFields[field.controlName] && isValueCopied(field.controlName) ? resetField(field.controlName) : copyFetchedToCurrent(field.controlName)"
|
||||
(mouseenter)="onMouseEnter(field.controlName)"
|
||||
(mouseleave)="onMouseLeave(field.controlName)"/>
|
||||
|
||||
<div class="w-full">
|
||||
<p-autoComplete
|
||||
[ngModel]="fetchedMetadata[field.fetchedKey] ?? []"
|
||||
[ngModelOptions]="{ standalone: true }"
|
||||
[disabled]="true"
|
||||
[multiple]="true" [typeahead]="false" [dropdown]="false" [forceSelection]="false" styleClass="w-full">
|
||||
</p-autoComplete>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
@for (field of metadataDescription; track field) {
|
||||
<div class="flex items-center py-1">
|
||||
<label for="{{field.controlName}}" class="w-[6.5%]">{{ field.label }}</label>
|
||||
<div class="flex w-full items-center">
|
||||
<textarea rows="2" pTextarea id="{{field.controlName}}" formControlName="{{field.controlName}}" class="!w-1/2"
|
||||
[ngClass]="{
|
||||
'outlined-input-green': isValueCopied(field.controlName) && !hoveredFields[field.controlName],
|
||||
}"
|
||||
></textarea>
|
||||
<p-button
|
||||
[icon]="isValueSaved(field.controlName) ? 'pi pi-check' : (hoveredFields[field.controlName] && isValueCopied(field.controlName) ? 'pi pi-times' : 'pi pi-arrow-left')"
|
||||
[outlined]="true"
|
||||
[ngClass]="
|
||||
{
|
||||
'green-outlined-button': isValueCopied(field.controlName) && !hoveredFields[field.controlName],
|
||||
'red-outlined-button': isValueCopied(field.controlName) && hoveredFields[field.controlName]
|
||||
}"
|
||||
class="arrow-button"
|
||||
(click)="hoveredFields[field.controlName] && isValueCopied(field.controlName) ? resetField(field.controlName) : copyFetchedToCurrent(field.controlName)"
|
||||
(mouseenter)="onMouseEnter(field.controlName)"
|
||||
(mouseleave)="onMouseLeave(field.controlName)"/>
|
||||
<textarea rows="2" pInputText [value]="fetchedMetadata[field.fetchedKey] ?? null" class="!w-1/2" readonly></textarea>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
@for (field of metadataFieldsBottom; track field) {
|
||||
<div class="flex items-center py-1">
|
||||
<label for="{{field.controlName}}" class="w-[6.5%]">{{ field.label }}</label>
|
||||
<div class="flex w-full">
|
||||
<input pInputText pSize="small" id="{{field.controlName}}" formControlName="{{field.controlName}}" class="!w-1/2"
|
||||
[ngClass]="{
|
||||
'outlined-input-green': isValueCopied(field.controlName) && !hoveredFields[field.controlName],
|
||||
}"
|
||||
/>
|
||||
<p-button
|
||||
[icon]="isValueSaved(field.controlName) ? 'pi pi-check' : (hoveredFields[field.controlName] && isValueCopied(field.controlName) ? 'pi pi-times' : 'pi pi-arrow-left')"
|
||||
[outlined]="true"
|
||||
[ngClass]="
|
||||
{
|
||||
'green-outlined-button': isValueCopied(field.controlName) && !hoveredFields[field.controlName],
|
||||
'red-outlined-button': isValueCopied(field.controlName) && hoveredFields[field.controlName]
|
||||
}"
|
||||
class="arrow-button"
|
||||
(click)="hoveredFields[field.controlName] && isValueCopied(field.controlName) ? resetField(field.controlName) : copyFetchedToCurrent(field.controlName)"
|
||||
(mouseenter)="onMouseEnter(field.controlName)"
|
||||
(mouseleave)="onMouseLeave(field.controlName)"/>
|
||||
<input pInputText pSize="small" [value]="fetchedMetadata[field.fetchedKey] ?? null" class="!w-1/2" readonly/>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
} @else {
|
||||
<form [formGroup]="metadataForm" class="flex h-[30rem] w-full">
|
||||
<div class="flex-grow overflow-auto pr-4">
|
||||
<p class="pb-2">Current Metadata:</p>
|
||||
|
||||
@for (field of metadataFieldsTop; track field) {
|
||||
<div class="flex items-center py-1">
|
||||
<label for="{{field.controlName}}" class="w-[15%]">{{ field.label }}</label>
|
||||
<div class="flex w-full">
|
||||
<input
|
||||
pSize="small"
|
||||
fluid
|
||||
pInputText
|
||||
id="{{field.controlName}}"
|
||||
formControlName="{{field.controlName}}"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@for (field of metadataChips; track field) {
|
||||
<div class="flex items-center py-1">
|
||||
<label for="{{field.controlName}}" class="w-[15%]">{{ field.label }}</label>
|
||||
<div class="flex w-full">
|
||||
<p-autoComplete formControlName="{{field.controlName}}" [multiple]="true" [typeahead]="false" [dropdown]="false" [forceSelection]="false" styleClass="w-full" (onBlur)="onAutoCompleteBlur(field.controlName, $event)"></p-autoComplete>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@for (field of metadataDescription; track field) {
|
||||
<div class="flex items-center py-1">
|
||||
<label for="{{field.controlName}}" class="w-[15%]">{{ field.label }}</label>
|
||||
<div class="flex w-full">
|
||||
<textarea fluid rows="2" pTextarea id="{{field.controlName}}" formControlName="{{field.controlName}}"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@for (field of metadataFieldsBottom; track field) {
|
||||
<div class="flex items-center py-1">
|
||||
<label for="{{field.controlName}}" class="w-[15%]">{{ field.label }}</label>
|
||||
<div class="flex w-full">
|
||||
<input
|
||||
fluid
|
||||
pInputText
|
||||
pSize="small"
|
||||
id="{{field.controlName}}"
|
||||
formControlName="{{field.controlName}}"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="w-[20%] h-full flex items-start justify-center p-4">
|
||||
<div class="w-full h-full">
|
||||
<img
|
||||
[src]="metadataForm.get('thumbnailUrl')?.value"
|
||||
alt="Book Thumbnail"
|
||||
class="w-full h-full object-contain"
|
||||
/>
|
||||
<input type="hidden" id="thumbnailUrl" formControlName="thumbnailUrl"/>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
.thumbnail {
|
||||
width: 10.46875rem;
|
||||
height: 14.65625rem;
|
||||
border-radius: 0.5rem;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
||||
margin-left: 2.5rem;
|
||||
margin-right: 2.5rem;
|
||||
}
|
||||
|
||||
.arrow-button {
|
||||
padding-left: 1rem;
|
||||
padding-right: 1rem;
|
||||
}
|
||||
|
||||
.green-outlined-button {
|
||||
--p-button-outlined-primary-border-color: forestgreen;
|
||||
--p-button-outlined-primary-color: forestgreen;
|
||||
}
|
||||
|
||||
.red-outlined-button {
|
||||
--p-button-outlined-primary-border-color: #E32636;
|
||||
--p-button-outlined-primary-color: #E32636;
|
||||
}
|
||||
|
||||
.outlined-input-green {
|
||||
border: 0.75px solid forestgreen !important;
|
||||
}
|
||||
|
||||
::ng-deep .p-inputchips {
|
||||
width: 100% !important;
|
||||
}
|
||||
+204
@@ -0,0 +1,204 @@
|
||||
import {Component, EventEmitter, inject, Input, 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';
|
||||
|
||||
@Component({
|
||||
selector: 'app-bookdrop-file-metadata-picker-component',
|
||||
imports: [
|
||||
ReactiveFormsModule,
|
||||
Button,
|
||||
Tooltip,
|
||||
InputText,
|
||||
NgClass,
|
||||
FormsModule,
|
||||
Textarea,
|
||||
AutoComplete,
|
||||
Image,
|
||||
LazyLoadImageModule
|
||||
],
|
||||
templateUrl: './bookdrop-file-metadata-picker.component.html',
|
||||
styleUrl: './bookdrop-file-metadata-picker.component.scss'
|
||||
})
|
||||
export class BookdropFileMetadataPickerComponent {
|
||||
|
||||
@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>();
|
||||
|
||||
|
||||
metadataFieldsTop = [
|
||||
{label: 'Title', controlName: 'title', fetchedKey: 'title'},
|
||||
{label: 'Subtitle', controlName: 'subtitle', fetchedKey: 'subtitle'},
|
||||
{label: 'Publisher', controlName: 'publisher', fetchedKey: 'publisher'},
|
||||
{label: 'Published', controlName: 'publishedDate', fetchedKey: 'publishedDate'}
|
||||
];
|
||||
|
||||
metadataChips = [
|
||||
{label: 'Authors', controlName: 'authors', lockedKey: 'authorsLocked', fetchedKey: 'authors'},
|
||||
{label: 'Genres', controlName: 'categories', lockedKey: 'categoriesLocked', fetchedKey: 'categories'},
|
||||
{label: 'Moods', controlName: 'moods', lockedKey: 'moodsLocked', fetchedKey: 'moods'},
|
||||
{label: 'Tags', controlName: 'tags', lockedKey: 'tagsLocked', fetchedKey: 'tags'},
|
||||
];
|
||||
|
||||
metadataDescription = [
|
||||
{label: 'Description', controlName: 'description', lockedKey: 'descriptionLocked', fetchedKey: 'description'},
|
||||
];
|
||||
|
||||
metadataFieldsBottom = [
|
||||
{label: 'Series', controlName: 'seriesName', lockedKey: 'seriesNameLocked', fetchedKey: 'seriesName'},
|
||||
{label: 'Book #', controlName: 'seriesNumber', lockedKey: 'seriesNumberLocked', fetchedKey: 'seriesNumber'},
|
||||
{label: 'Total Books', controlName: 'seriesTotal', lockedKey: 'seriesTotalLocked', fetchedKey: 'seriesTotal'},
|
||||
{label: 'Language', controlName: 'language', lockedKey: 'languageLocked', fetchedKey: 'language'},
|
||||
{label: 'ISBN-10', controlName: 'isbn10', lockedKey: 'isbn10Locked', fetchedKey: 'isbn10'},
|
||||
{label: 'ISBN-13', controlName: 'isbn13', lockedKey: 'isbn13Locked', fetchedKey: 'isbn13'},
|
||||
{label: 'ASIN', controlName: 'asin', lockedKey: 'asinLocked', fetchedKey: 'asin'},
|
||||
{label: 'Amz Reviews', controlName: 'amazonReviewCount', lockedKey: 'amazonReviewCountLocked', fetchedKey: 'amazonReviewCount'},
|
||||
{label: 'Amz Rating', controlName: 'amazonRating', lockedKey: 'amazonRatingLocked', fetchedKey: 'amazonRating'},
|
||||
{label: 'GR ID', controlName: 'goodreadsId', lockedKey: 'goodreadsIdLocked', fetchedKey: 'goodreadsId'},
|
||||
{label: 'GR Reviews', controlName: 'goodreadsReviewCount', lockedKey: 'goodreadsReviewCountLocked', fetchedKey: 'goodreadsReviewCount'},
|
||||
{label: 'GR Rating', controlName: 'goodreadsRating', lockedKey: 'goodreadsRatingLocked', fetchedKey: 'goodreadsRating'},
|
||||
{label: 'HC ID', controlName: 'hardcoverId', lockedKey: 'hardcoverIdLocked', fetchedKey: 'hardcoverId'},
|
||||
{label: 'HC Reviews', controlName: 'hardcoverReviewCount', lockedKey: 'hardcoverReviewCountLocked', fetchedKey: 'hardcoverReviewCount'},
|
||||
{label: 'HC Rating', controlName: 'hardcoverRating', lockedKey: 'hardcoverRatingLocked', fetchedKey: 'hardcoverRating'},
|
||||
{label: 'Google ID', controlName: 'googleId', lockedKey: 'googleIdLocked', fetchedKey: 'googleIdRating'},
|
||||
{label: 'Comicvine ID', controlName: 'comicvineId', lockedKey: 'comicvineIdLocked', fetchedKey: 'comicvineId'},
|
||||
{label: 'Pages', controlName: 'pageCount', lockedKey: 'pageCountLocked', fetchedKey: 'pageCount'}
|
||||
];
|
||||
|
||||
protected urlHelper = inject(UrlHelperService);
|
||||
|
||||
copyMissing(): void {
|
||||
Object.keys(this.fetchedMetadata).forEach((field) => {
|
||||
const isLocked = this.metadataForm.get(`${field}Locked`)?.value;
|
||||
const currentValue = this.metadataForm.get(field)?.value;
|
||||
const fetchedValue = this.fetchedMetadata[field];
|
||||
|
||||
const isEmpty = Array.isArray(currentValue)
|
||||
? currentValue.length === 0
|
||||
: !currentValue;
|
||||
|
||||
if (!isLocked && isEmpty && fetchedValue) {
|
||||
this.copyFetchedToCurrent(field);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
copyAll() {
|
||||
if (this.fetchedMetadata) {
|
||||
Object.keys(this.fetchedMetadata).forEach((field) => {
|
||||
if (this.fetchedMetadata[field] && field !== 'thumbnailUrl') {
|
||||
this.copyFetchedToCurrent(field);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
copyFetchedToCurrent(field: string): void {
|
||||
const value = this.fetchedMetadata[field];
|
||||
if (value && !this.copiedFields[field]) {
|
||||
this.metadataForm.get(field)?.setValue(value);
|
||||
this.copiedFields[field] = true;
|
||||
this.highlightCopiedInput(field);
|
||||
this.metadataCopied.emit(true);
|
||||
}
|
||||
}
|
||||
|
||||
highlightCopiedInput(field: string): void {
|
||||
this.copiedFields[field] = true;
|
||||
}
|
||||
|
||||
isValueCopied(field: string): boolean {
|
||||
return this.copiedFields[field];
|
||||
}
|
||||
|
||||
isValueSaved(field: string): boolean {
|
||||
return this.savedFields[field];
|
||||
}
|
||||
|
||||
hoveredFields: { [key: string]: boolean } = {};
|
||||
|
||||
onMouseEnter(controlName: string): void {
|
||||
if (this.isValueCopied(controlName) && !this.isValueSaved(controlName)) {
|
||||
this.hoveredFields[controlName] = true;
|
||||
}
|
||||
}
|
||||
|
||||
onMouseLeave(controlName: string): void {
|
||||
this.hoveredFields[controlName] = false;
|
||||
}
|
||||
|
||||
resetField(field: string) {
|
||||
this.metadataForm.get(field)?.setValue(this.originalMetadata?.[field]);
|
||||
this.copiedFields[field] = false;
|
||||
this.hoveredFields[field] = false;
|
||||
if (field === 'thumbnailUrl') {
|
||||
this.metadataForm.get('thumbnailUrl')?.setValue(this.urlHelper.getBookdropCoverUrl(this.bookdropFileId));
|
||||
}
|
||||
}
|
||||
|
||||
onAutoCompleteBlur(fieldName: string, event: any) {
|
||||
const inputValue = event.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);
|
||||
}
|
||||
event.target.value = '';
|
||||
}
|
||||
}
|
||||
|
||||
resetAll() {
|
||||
if (this.originalMetadata) {
|
||||
this.metadataForm.patchValue({
|
||||
title: this.originalMetadata.title || null,
|
||||
subtitle: this.originalMetadata.subtitle || null,
|
||||
authors: [...(this.originalMetadata.authors ?? [])].sort(),
|
||||
categories: [...(this.originalMetadata.categories ?? [])].sort(),
|
||||
moods: [...(this.originalMetadata.moods ?? [])].sort(),
|
||||
tags: [...(this.originalMetadata.tags ?? [])].sort(),
|
||||
publisher: this.originalMetadata.publisher || null,
|
||||
publishedDate: this.originalMetadata.publishedDate || null,
|
||||
isbn10: this.originalMetadata.isbn10 || null,
|
||||
isbn13: this.originalMetadata.isbn13 || null,
|
||||
description: this.originalMetadata.description || null,
|
||||
pageCount: this.originalMetadata.pageCount || null,
|
||||
language: this.originalMetadata.language || null,
|
||||
asin: this.originalMetadata.asin || null,
|
||||
amazonRating: this.originalMetadata.amazonRating || null,
|
||||
amazonReviewCount: this.originalMetadata.amazonReviewCount || null,
|
||||
goodreadsId: this.originalMetadata.goodreadsId || null,
|
||||
goodreadsRating: this.originalMetadata.goodreadsRating || null,
|
||||
goodreadsReviewCount: this.originalMetadata.goodreadsReviewCount || null,
|
||||
hardcoverId: this.originalMetadata.hardcoverId || null,
|
||||
hardcoverRating: this.originalMetadata.hardcoverRating || null,
|
||||
hardcoverReviewCount: this.originalMetadata.hardcoverReviewCount || null,
|
||||
googleId: this.originalMetadata.googleId || null,
|
||||
comicvineId: this.originalMetadata.comicvineId || null,
|
||||
seriesName: this.originalMetadata.seriesName || null,
|
||||
seriesNumber: this.originalMetadata.seriesNumber || null,
|
||||
seriesTotal: this.originalMetadata.seriesTotal || null,
|
||||
thumbnailUrl: this.urlHelper.getBookdropCoverUrl(this.bookdropFileId),
|
||||
});
|
||||
}
|
||||
this.copiedFields = {};
|
||||
this.hoveredFields = {};
|
||||
this.metadataCopied.emit(false);
|
||||
}
|
||||
}
|
||||
+308
@@ -0,0 +1,308 @@
|
||||
<div class="overflow-x-auto">
|
||||
<div class="flex flex-col h-[calc(100dvh-6.1rem)] rounded-xl bg-[var(--card-background)] space-y-4 min-w-[100rem]">
|
||||
<div class="px-4 md:px-6 pt-6 pb-4 flex flex-col md:flex-row md:items-center md:justify-between">
|
||||
<div>
|
||||
<h2 class="text-xl font-semibold pb-1 flex items-center gap-2">
|
||||
Review Bookdrop Files
|
||||
<a href="https://booklore-app.github.io/booklore-docs/docs/bookdrop" target="_blank" rel="noopener noreferrer">
|
||||
<i
|
||||
class="pi pi-external-link text-sky-600 cursor-pointer"
|
||||
style="font-size: 0.9rem"
|
||||
pTooltip="View documentation"
|
||||
tooltipPosition="top"></i>
|
||||
</a>
|
||||
</h2>
|
||||
<p class="text-sm text-gray-400">
|
||||
These files were uploaded to the
|
||||
<strong class="text-[var(--primary-color)]">Bookdrop Folder</strong>.
|
||||
Review their fetched metadata, assign a library and subpath, and finalize where they belong in your collection.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="mt-4 md:mt-0">
|
||||
<p-button
|
||||
label="Rescan Bookdrop"
|
||||
icon="pi pi-refresh"
|
||||
severity="primary"
|
||||
outlined
|
||||
(click)="rescanBookdrop()"
|
||||
pTooltip="Manually trigger a rescan of the Bookdrop folder"
|
||||
tooltipPosition="top">
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (loading) {
|
||||
|
||||
<div class="absolute inset-0 flex items-center justify-center z-50 rounded-xl">
|
||||
<div class="flex flex-col items-center space-y-3">
|
||||
<p-progressSpinner class="w-8 h-8" strokeWidth="4"/>
|
||||
<span class="text-gray-300">Loading Bookdrop files. Please wait...</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
} @else {
|
||||
|
||||
<div class="px-6 pb-2">
|
||||
@if (saving) {
|
||||
<div class="absolute inset-0 bg-black bg-opacity-50 flex flex-col items-center justify-center z-50 rounded-xl space-y-3">
|
||||
<p-progressSpinner class="w-8 h-8" strokeWidth="4"/>
|
||||
<div class="bg-gray-900/90 px-4 py-2 rounded-md">
|
||||
<span class="text-sm text-gray-200 text-center">
|
||||
Organizing and moving files to their designated libraries. Please wait...
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (bookdropFileUis.length !== 0) {
|
||||
<div class="flex justify-between items-center gap-4 px-1">
|
||||
|
||||
<div class="flex gap-4 items-center">
|
||||
<span class="text-sm text-gray-300 font-medium">Library for All Files:</span>
|
||||
<p-select
|
||||
size="small"
|
||||
[options]="libraryOptions"
|
||||
optionLabel="label"
|
||||
optionValue="value"
|
||||
placeholder="Select Default Library"
|
||||
class="min-w-[8rem] max-w-[16rem]"
|
||||
[(ngModel)]="defaultLibraryId">
|
||||
</p-select>
|
||||
|
||||
<span class="text-sm text-gray-300 font-medium">Subpath for All Files:</span>
|
||||
<p-select
|
||||
size="small"
|
||||
[options]="selectedLibraryPaths"
|
||||
optionLabel="label"
|
||||
optionValue="value"
|
||||
placeholder="Select Default Subpath"
|
||||
class="min-w-[8rem] max-w-[16rem]"
|
||||
[(ngModel)]="defaultPathId">
|
||||
</p-select>
|
||||
|
||||
<p-button
|
||||
size="small"
|
||||
label="Apply to All"
|
||||
icon="pi pi-check"
|
||||
[disabled]="!canApplyDefaults"
|
||||
(click)="applyDefaultsToAll()"
|
||||
pTooltip="Apply selected library and subpath to all files"
|
||||
tooltipPosition="top">
|
||||
</p-button>
|
||||
</div>
|
||||
|
||||
<div class="flex gap-4">
|
||||
<p-button
|
||||
size="small"
|
||||
outlined
|
||||
severity="info"
|
||||
label="Apply (w/ Cover)"
|
||||
icon="pi pi-copy"
|
||||
(click)="copyAll(true)"
|
||||
pTooltip="For all files, replace current metadata with fetched metadata, including cover images"
|
||||
tooltipPosition="top">
|
||||
</p-button>
|
||||
|
||||
<p-button
|
||||
size="small"
|
||||
outlined
|
||||
severity="info"
|
||||
label="Apply (no Cover)"
|
||||
icon="pi pi-copy"
|
||||
(click)="copyAll(false)"
|
||||
pTooltip="For all files, replace current metadata with fetched metadata, excluding cover images"
|
||||
tooltipPosition="top">
|
||||
</p-button>
|
||||
|
||||
<p-button
|
||||
size="small"
|
||||
outlined
|
||||
severity="warn"
|
||||
label="Reset"
|
||||
icon="pi pi-refresh"
|
||||
(click)="resetAll()"
|
||||
pTooltip="Reset all metadata changes"
|
||||
tooltipPosition="left">
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="flex-1 overflow-y-auto px-4 md:px-6 pt-4 space-y-2 pb-4">
|
||||
@if (bookdropFileUis.length === 0) {
|
||||
<div class="h-full w-full flex items-center justify-center text-gray-400 italic py-8">
|
||||
No bookdrop files to review.
|
||||
</div>
|
||||
} @else {
|
||||
@for (file of bookdropFileUis; track file) {
|
||||
|
||||
<div class="flex flex-col">
|
||||
<div class="flex items-center gap-4 custom-border rounded-xl px-4 py-2">
|
||||
|
||||
<p-checkbox
|
||||
[binary]="true"
|
||||
[(ngModel)]="file.selected"
|
||||
(ngModelChange)="toggleFileSelection(file.file.id, $event)">
|
||||
</p-checkbox>
|
||||
|
||||
<i
|
||||
class="pi pi-circle-fill"
|
||||
[ngStyle]="{'color': file.file.fetchedMetadata ? 'green' : 'darkorange'}"
|
||||
style="font-size: 0.75rem"
|
||||
pTooltip="{{file.file.fetchedMetadata ? 'Fetched metadata is available.' : 'No fetched metadata available.'}}"
|
||||
tooltipPosition="top">
|
||||
</i>
|
||||
|
||||
@if (file.metadataForm.get('thumbnailUrl')?.value) {
|
||||
<img
|
||||
[src]="file.metadataForm.get('thumbnailUrl')?.value"
|
||||
alt="Cover"
|
||||
title="Original cover"
|
||||
class="w-6 h-8 rounded-sm object-cover cursor-pointer hover:scale-105 hover:shadow-md transition-transform duration-200"
|
||||
(click)="file.showDetails = !file.showDetails"/>
|
||||
}
|
||||
|
||||
@if (file.file.fetchedMetadata?.thumbnailUrl) {
|
||||
<img
|
||||
[src]="file.file.fetchedMetadata?.thumbnailUrl"
|
||||
alt="Fetched Cover"
|
||||
title="Fetched cover"
|
||||
class="w-6 h-8 rounded-sm object-cover cursor-pointer hover:scale-105 hover:shadow-md transition-transform duration-200"
|
||||
(click)="file.showDetails = !file.showDetails"/>
|
||||
}
|
||||
|
||||
<div class="flex-1 font-medium text-sm truncate" (click)="file.showDetails = !file.showDetails">
|
||||
{{ file.file.fileName }}
|
||||
</div>
|
||||
|
||||
<i
|
||||
class="pi"
|
||||
[ngClass]="{
|
||||
'pi-check-circle text-green-500': copiedFlags[file.file.id],
|
||||
'pi-check-circle text-blue-500': !file.file.fetchedMetadata,
|
||||
'pi-exclamation-triangle text-red-500': file.file.fetchedMetadata && !copiedFlags[file.file.id]
|
||||
}"
|
||||
[pTooltip]="copiedFlags[file.file.id]
|
||||
? 'Fetched metadata has been applied.'
|
||||
: !file.file.fetchedMetadata
|
||||
? 'No fetched metadata available. Original metadata will be used.'
|
||||
: 'Fetched metadata hasn’t been applied yet. Open metadata picker to review.'"
|
||||
tooltipPosition="top">
|
||||
</i>
|
||||
|
||||
<p-select
|
||||
size="small"
|
||||
[options]="libraryOptions"
|
||||
optionLabel="label"
|
||||
optionValue="value"
|
||||
placeholder="Select Library"
|
||||
class="min-w-[8rem] max-w-[16rem]"
|
||||
[(ngModel)]="file.selectedLibraryId"
|
||||
(onChange)="onLibraryChange(file)">
|
||||
</p-select>
|
||||
|
||||
<p-select
|
||||
size="small"
|
||||
[options]="file.availablePaths"
|
||||
optionLabel="name"
|
||||
optionValue="id"
|
||||
placeholder="Select Subpath"
|
||||
class="min-w-[8rem] max-w-[16rem]"
|
||||
appendTo="body"
|
||||
[(ngModel)]="file.selectedPathId">
|
||||
</p-select>
|
||||
|
||||
<p-button
|
||||
size="small"
|
||||
[icon]="file.showDetails ? 'pi pi-chevron-up' : 'pi pi-chevron-down'"
|
||||
(click)="file.showDetails = !file.showDetails"
|
||||
tooltipPosition="top">
|
||||
</p-button>
|
||||
</div>
|
||||
|
||||
@if (file.showDetails) {
|
||||
<app-bookdrop-file-metadata-picker-component
|
||||
class="px-12 py-8 custom-border1"
|
||||
[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>
|
||||
|
||||
<p-divider></p-divider>
|
||||
|
||||
<div class="pb-2 px-4 flex items-center justify-between gap-4">
|
||||
|
||||
<div class="flex gap-4 items-center min-w-[160px] justify-start">
|
||||
@if (bookdropFileUis.length > 0) {
|
||||
<p-button
|
||||
label="Select All"
|
||||
icon="pi pi-check-square"
|
||||
severity="info"
|
||||
(click)="selectAll(true)"
|
||||
outlined
|
||||
pTooltip="Select all files across all pages you have navigated"
|
||||
tooltipPosition="top">
|
||||
</p-button>
|
||||
|
||||
<p-button
|
||||
label="Clear All"
|
||||
icon="pi pi-times-circle"
|
||||
severity="warn"
|
||||
(click)="selectAll(false)"
|
||||
outlined
|
||||
pTooltip="Deselect all files across all pages you have navigated"
|
||||
tooltipPosition="top">
|
||||
</p-button>
|
||||
} @else {
|
||||
<div class="min-w-[160px]"></div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="flex-grow flex justify-center">
|
||||
<p-paginator
|
||||
[rows]="pageSize"
|
||||
[totalRecords]="totalRecords"
|
||||
[first]="currentPage * pageSize"
|
||||
(onPageChange)="loadPage($event.page ?? 0)"
|
||||
[showCurrentPageReport]="true"
|
||||
currentPageReportTemplate="Showing files {first} - {last} of {totalRecords}">
|
||||
</p-paginator>
|
||||
</div>
|
||||
|
||||
<div class="flex gap-4 items-center min-w-[200px] justify-end">
|
||||
<p-button
|
||||
[label]="'Delete ' + selectedCount + ' File' + (selectedCount !== 1 ? 's' : '')"
|
||||
icon="pi pi-times"
|
||||
severity="danger"
|
||||
[disabled]="!hasSelectedFiles"
|
||||
outlined
|
||||
(click)="confirmDelete()"
|
||||
pTooltip="Permanently delete selected Bookdrop files and discard any changes"
|
||||
tooltipPosition="top">
|
||||
</p-button>
|
||||
<p-button
|
||||
[label]="saving ? ('Finalizing ' + selectedCount + ' File' + (selectedCount !== 1 ? 's' : '') + '...') : ('Finalize ' + selectedCount + ' File' + (selectedCount !== 1 ? 's' : ''))"
|
||||
[icon]="saving ? 'pi pi-spin pi-spinner' : 'pi pi-save'"
|
||||
severity="success"
|
||||
outlined
|
||||
[disabled]="!canFinalize || saving"
|
||||
(click)="confirmFinalize()"
|
||||
pTooltip="Move selected files into the chosen library and subpath">
|
||||
</p-button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
.custom-border {
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 10px 10px 0px 0px;
|
||||
}
|
||||
|
||||
.custom-border1 {
|
||||
border-left: 1px solid var(--border-color);
|
||||
border-right: 1px solid var(--border-color);
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
border-top: none;
|
||||
border-radius: 0px 0px 10px 10px;
|
||||
}
|
||||
+561
@@ -0,0 +1,561 @@
|
||||
import {Component, DestroyRef, inject, OnInit, QueryList, ViewChildren} from '@angular/core';
|
||||
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
||||
import {filter, startWith, take, tap} from 'rxjs/operators';
|
||||
|
||||
import {BookdropFile, BookdropFinalizePayload, BookdropFinalizeResult, BookdropService} 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 {Observable, Subscription} from 'rxjs';
|
||||
|
||||
import {AppSettings} from '../../../../shared/model/app-settings.model';
|
||||
import {AppSettingsService} from '../../../../shared/service/app-settings.service';
|
||||
import {DialogService} from 'primeng/dynamicdialog';
|
||||
import {BookMetadata} from '../../../book/model/book.model';
|
||||
import {UrlHelperService} from '../../../../shared/service/url-helper.service';
|
||||
import {Checkbox} from 'primeng/checkbox';
|
||||
import {NgClass, NgStyle} 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 {BookdropFinalizeResultDialogComponent} from '../bookdrop-finalize-result-dialog/bookdrop-finalize-result-dialog-component';
|
||||
|
||||
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,
|
||||
NgStyle,
|
||||
NgClass,
|
||||
Paginator,
|
||||
],
|
||||
})
|
||||
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 dialogService = inject(DialogService);
|
||||
private readonly appSettingsService = inject(AppSettingsService);
|
||||
private readonly messageService = inject(MessageService);
|
||||
private readonly urlHelper = inject(UrlHelperService);
|
||||
private readonly activatedRoute = inject(ActivatedRoute);
|
||||
|
||||
@ViewChildren('metadataPicker') metadataPickers!: QueryList<BookdropFileMetadataPickerComponent>;
|
||||
|
||||
appSettings$: Observable<AppSettings | null> = this.appSettingsService.appSettings$;
|
||||
private routerSub!: Subscription;
|
||||
|
||||
uploadPattern = '';
|
||||
_defaultLibraryId: string | null = null;
|
||||
|
||||
defaultPathId: string | null = null;
|
||||
libraries: Library[] = [];
|
||||
bookdropFileUis: BookdropFileUI[] = [];
|
||||
fileUiCache: Record<number, BookdropFileUI> = {};
|
||||
copiedFlags: Record<number, boolean> = {};
|
||||
loading = true;
|
||||
saving = false;
|
||||
|
||||
pageSize = 50;
|
||||
totalRecords = 0;
|
||||
currentPage = 0;
|
||||
|
||||
selectAllAcrossPages = false;
|
||||
excludedFiles = new Set<number>();
|
||||
|
||||
ngOnInit(): void {
|
||||
this.activatedRoute.queryParams
|
||||
.pipe(startWith({}), tap(() => {
|
||||
this.loading = true;
|
||||
this.loadPage(0);
|
||||
}))
|
||||
.subscribe();
|
||||
|
||||
this.libraryService.libraryState$
|
||||
.pipe(filter(state => !!state?.loaded), take(1))
|
||||
.subscribe(state => {
|
||||
this.libraries = state.libraries ?? [];
|
||||
});
|
||||
|
||||
this.appSettings$
|
||||
.pipe(filter(Boolean), take(1))
|
||||
.subscribe(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 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.totalElements;
|
||||
this.currentPage = page;
|
||||
this.loading = false;
|
||||
this.syncCurrentPageSelection();
|
||||
},
|
||||
error: err => {
|
||||
console.error('Error loading files:', err);
|
||||
this.loading = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
applyDefaultsToAll(): void {
|
||||
if (!this.defaultLibraryId || !this.libraries) return;
|
||||
|
||||
const selectedLib = this.libraries.find(l => String(l.id) === this.defaultLibraryId);
|
||||
const selectedPaths = selectedLib?.paths ?? [];
|
||||
|
||||
Object.values(this.fileUiCache).forEach(file => {
|
||||
file.selectedLibraryId = this.defaultLibraryId;
|
||||
file.availablePaths = selectedPaths.map(path => ({id: String(path.id), name: path.path}));
|
||||
file.selectedPathId = this.defaultPathId ?? null;
|
||||
});
|
||||
}
|
||||
|
||||
copyAll(includeThumbnail: boolean): void {
|
||||
Object.values(this.fileUiCache).forEach(fileUi => {
|
||||
const fetched = fileUi.file.fetchedMetadata;
|
||||
const form = fileUi.metadataForm;
|
||||
if (!fetched) return;
|
||||
for (const key of Object.keys(fetched)) {
|
||||
if (!includeThumbnail && key === 'thumbnailUrl') continue;
|
||||
const value = fetched[key as keyof typeof fetched];
|
||||
if (value != null) {
|
||||
form.get(key)?.setValue(value);
|
||||
fileUi.copiedFields[key] = true;
|
||||
}
|
||||
}
|
||||
this.onMetadataCopied(fileUi.file.id, true);
|
||||
});
|
||||
}
|
||||
|
||||
resetAll(): void {
|
||||
Object.values(this.fileUiCache).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,
|
||||
hardcoverRating: original?.hardcoverRating ?? null,
|
||||
hardcoverReviewCount: original?.hardcoverReviewCount ?? null,
|
||||
googleId: original?.googleId ?? null,
|
||||
comicvineId: original?.comicvineId ?? 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 = {};
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
confirmFinalize(): void {
|
||||
const selectedCount = this.selectedCount;
|
||||
if (selectedCount === 0) {
|
||||
this.messageService.add({
|
||||
severity: 'warn',
|
||||
summary: 'No files selected',
|
||||
detail: 'Please select files to finalize.',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
this.confirmationService.confirm({
|
||||
message: `Are you sure you want to finalize the import of ${selectedCount} file${selectedCount !== 1 ? 's' : ''}?`,
|
||||
header: 'Confirm Finalize',
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
acceptLabel: 'Yes',
|
||||
rejectLabel: 'Cancel',
|
||||
accept: () => this.finalizeImport(),
|
||||
});
|
||||
}
|
||||
|
||||
confirmDelete(): void {
|
||||
const selectedCount = this.selectedCount;
|
||||
if (selectedCount === 0) {
|
||||
this.messageService.add({
|
||||
severity: 'warn',
|
||||
summary: 'No files selected',
|
||||
detail: 'Please select files to delete.',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
this.confirmationService.confirm({
|
||||
message: `Are you sure you want to delete ${selectedCount} selected Bookdrop file${selectedCount !== 1 ? 's' : ''}? This action cannot be undone.`,
|
||||
header: 'Confirm Delete',
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
accept: () => {
|
||||
const payload: any = {
|
||||
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: 'Files Deleted',
|
||||
detail: 'Selected Bookdrop files were deleted successfully.',
|
||||
});
|
||||
|
||||
const toDelete = Object.values(this.fileUiCache).filter(file => {
|
||||
return this.selectAllAcrossPages
|
||||
? !this.excludedFiles.has(file.file.id)
|
||||
: file.selected;
|
||||
});
|
||||
toDelete.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: 'Delete Failed',
|
||||
detail: 'An error occurred while deleting Bookdrop files.',
|
||||
});
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
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 = Object.values(this.fileUiCache).filter(file => {
|
||||
if (this.selectAllAcrossPages) {
|
||||
return !this.excludedFiles.has(file.file.id);
|
||||
} else {
|
||||
return file.selected;
|
||||
}
|
||||
});
|
||||
|
||||
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: 'Import Complete',
|
||||
detail: 'Import process finished. See details below.',
|
||||
});
|
||||
|
||||
this.dialogService.open(BookdropFinalizeResultDialogComponent, {
|
||||
header: 'Import Summary',
|
||||
modal: true,
|
||||
closable: true,
|
||||
closeOnEscape: true,
|
||||
data: {result: 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: 'Import Failed',
|
||||
detail: 'Some files could not be moved. Please check the console for more details.',
|
||||
});
|
||||
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 ?? ''),
|
||||
hardcoverRating: new FormControl(original?.hardcoverRating ?? ''),
|
||||
hardcoverReviewCount: new FormControl(original?.hardcoverReviewCount ?? ''),
|
||||
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: 'Rescan Triggered',
|
||||
detail: 'Bookdrop rescan has been started successfully.',
|
||||
});
|
||||
},
|
||||
error: (err) => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Rescan Failed',
|
||||
detail: 'Unable to trigger bookdrop rescan. Please try again.',
|
||||
});
|
||||
console.error(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
<div class="staging-border p-4 rounded">
|
||||
<div class="flex justify-between items-center">
|
||||
|
||||
<div class="flex flex-col justify-center">
|
||||
<p class="text font-bold text-zinc-300">Pending Bookdrop Files</p>
|
||||
<p class="text-lg font-bold text-primary">{{ pendingCount }}</p>
|
||||
@if (lastUpdatedAt) {
|
||||
<p class="text-xs text-zinc-400 mt-1">
|
||||
Last updated: {{ lastUpdatedAt | date: 'short' }}
|
||||
</p>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="flex items-center">
|
||||
<p-button
|
||||
size="small"
|
||||
outlined
|
||||
severity="info"
|
||||
(click)="openReviewDialog()">
|
||||
Review
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
.staging-border {
|
||||
background: var(--card-background);
|
||||
border: 1px solid var(--primary-color);
|
||||
border-radius: 0.5rem;
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
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';
|
||||
|
||||
@Component({
|
||||
selector: 'app-bookdrop-files-widget-component',
|
||||
standalone: true,
|
||||
templateUrl: './bookdrop-files-widget.component.html',
|
||||
styleUrl: './bookdrop-files-widget.component.scss',
|
||||
imports: [
|
||||
DatePipe,
|
||||
Button
|
||||
]
|
||||
})
|
||||
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();
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
<div class="max-w-3xl mx-auto">
|
||||
<div class="mb-8">
|
||||
<div class="p-6 bg-zinc-800/50 rounded-xl border border-zinc-500">
|
||||
<div class="grid grid-cols-3 gap-6 mb-6">
|
||||
<div class="text-center p-4 bg-zinc-700/30 rounded-lg">
|
||||
<div class="text-3xl font-bold text-blue-400 mb-1">{{ result.totalFiles }}</div>
|
||||
<div class="text-sm text-gray-400 font-medium">Total Files</div>
|
||||
</div>
|
||||
<div class="text-center p-4 bg-zinc-700/30 rounded-lg">
|
||||
<div class="text-3xl font-bold text-green-400 mb-1">{{ result.successfullyImported }}</div>
|
||||
<div class="text-sm text-gray-400 font-medium">Successfully Imported</div>
|
||||
</div>
|
||||
<div class="text-center p-4 bg-zinc-700/30 rounded-lg">
|
||||
<div class="text-3xl font-bold text-red-400 mb-1">{{ result.failed }}</div>
|
||||
<div class="text-sm text-gray-400 font-medium">Failed</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="text-center pt-4 border-t border-zinc-600">
|
||||
<div class="text-sm text-gray-300 mb-1">Processed at</div>
|
||||
<div class="text-base text-white font-mono">{{ result.processedAt | date:'medium' }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="max-h-[35rem] overflow-y-scroll">
|
||||
<ul class="space-y-3 px-4">
|
||||
@for (r of result.results; track r) {
|
||||
<li
|
||||
class="flex items-start gap-3 p-3 rounded-xl border shadow-sm transition-colors"
|
||||
[ngClass]="{
|
||||
'bg-green-800/10 border-green-500/40 text-green-100': r.success,
|
||||
'bg-red-800/10 border-red-500/40 text-red-100': !r.success
|
||||
}"
|
||||
>
|
||||
<i
|
||||
class="pi text-xl mt-1"
|
||||
[ngClass]="{
|
||||
'pi-check-circle text-green-500': r.success,
|
||||
'pi-times-circle text-red-500': !r.success
|
||||
}"
|
||||
></i>
|
||||
|
||||
<div class="flex flex-col">
|
||||
<span class="font-medium text-sm text-white">
|
||||
{{ r.fileName }}
|
||||
</span>
|
||||
<span class="text-sm text-gray-400">{{ r.message }}</span>
|
||||
</div>
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
import {Component, OnDestroy} from '@angular/core';
|
||||
import {DatePipe, NgClass} from '@angular/common';
|
||||
import {BookdropFinalizeResult} from '../../service/bookdrop.service';
|
||||
import {DynamicDialogConfig, DynamicDialogRef} from "primeng/dynamicdialog";
|
||||
|
||||
@Component({
|
||||
selector: 'app-bookdrop-finalize-result-dialog-component',
|
||||
imports: [
|
||||
NgClass,
|
||||
DatePipe
|
||||
],
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -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,54 @@
|
||||
import {inject, Injectable, OnDestroy} from '@angular/core';
|
||||
import {BehaviorSubject, Subscription} from 'rxjs';
|
||||
import {map, filter, take} from 'rxjs/operators';
|
||||
import {BookdropFileApiService} from './bookdrop-file-api.service';
|
||||
import {AuthService} from '../../../shared/service/auth.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();
|
||||
|
||||
constructor() {
|
||||
this.authService.token$
|
||||
.pipe(filter(t => !!t), take(1))
|
||||
.subscribe(() => 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,79 @@
|
||||
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[];
|
||||
totalElements: number;
|
||||
totalPages: number;
|
||||
number: 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`, {});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user