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:
+152
@@ -0,0 +1,152 @@
|
||||
<ng-container *transloco="let t; prefix: 'metadata.coverSearch'">
|
||||
<div class="cover-search-container">
|
||||
<div class="panel-header">
|
||||
<div class="header-icon-wrapper">
|
||||
<i class="pi {{ coverType === 'audiobook' ? 'pi-headphones' : 'pi-image' }} header-icon"></i>
|
||||
</div>
|
||||
<div class="header-text">
|
||||
<h2 class="panel-title">{{ coverType === 'audiobook' ? t('searchAudiobookCover') : t('searchEbookCover') }}</h2>
|
||||
<p class="panel-description">{{ t('description') }}</p>
|
||||
</div>
|
||||
<p-button
|
||||
icon="pi pi-times"
|
||||
[rounded]="true"
|
||||
[text]="true"
|
||||
severity="secondary"
|
||||
(click)="dynamicDialogRef.close()"
|
||||
class="close-button">
|
||||
</p-button>
|
||||
</div>
|
||||
|
||||
<div class="dialog-content">
|
||||
<!-- Search Form -->
|
||||
<div class="search-section">
|
||||
<form [formGroup]="searchForm" (ngSubmit)="onSearch()">
|
||||
<div class="form-row">
|
||||
<div class="form-field title-field">
|
||||
<label for="title">
|
||||
<i class="pi pi-book"></i>
|
||||
{{ t('titleLabel') }}
|
||||
<span class="required">*</span>
|
||||
</label>
|
||||
<input
|
||||
pInputText
|
||||
id="title"
|
||||
formControlName="title"
|
||||
[placeholder]="t('titlePlaceholder')"
|
||||
/>
|
||||
@if (searchForm.get('title')?.invalid && searchForm.get('title')?.touched) {
|
||||
<small class="error-message">
|
||||
<i class="pi pi-exclamation-circle"></i>
|
||||
{{ t('titleRequired') }}
|
||||
</small>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="form-field author-field">
|
||||
<label for="author">
|
||||
<i class="pi pi-user"></i>
|
||||
{{ t('authorLabel') }}
|
||||
</label>
|
||||
<input
|
||||
pInputText
|
||||
id="author"
|
||||
formControlName="author"
|
||||
[placeholder]="t('authorPlaceholder')"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="form-actions">
|
||||
<p-button
|
||||
type="submit"
|
||||
[label]="t('searchBtn')"
|
||||
icon="pi pi-search"
|
||||
[loading]="loading"
|
||||
[disabled]="searchForm.invalid">
|
||||
</p-button>
|
||||
<p-button
|
||||
type="button"
|
||||
icon="pi pi-refresh"
|
||||
[text]="true"
|
||||
[rounded]="true"
|
||||
severity="secondary"
|
||||
(click)="onClear()"
|
||||
[pTooltip]="t('resetSearchTooltip')"
|
||||
tooltipPosition="top">
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- Results Area -->
|
||||
<div class="results-section">
|
||||
@if (!hasSearched) {
|
||||
<!-- Initial State -->
|
||||
<div class="empty-state">
|
||||
<div class="empty-state-icon">
|
||||
<i class="pi pi-images"></i>
|
||||
</div>
|
||||
<h3>{{ t('searchForCovers') }}</h3>
|
||||
<p>{{ t('searchForCoversDescription') }}</p>
|
||||
</div>
|
||||
} @else if (loading) {
|
||||
<!-- Loading State -->
|
||||
<div class="loading-state">
|
||||
<p-progressSpinner strokeWidth="3" animationDuration="1s"></p-progressSpinner>
|
||||
<p>{{ t('searchingForCovers') }}</p>
|
||||
</div>
|
||||
} @else if (coverImages.length === 0) {
|
||||
<!-- No Results State -->
|
||||
<div class="empty-state no-results">
|
||||
<div class="empty-state-icon warning">
|
||||
<i class="pi pi-search"></i>
|
||||
</div>
|
||||
<h3>{{ t('noCoversFound') }}</h3>
|
||||
<p>{{ t('noCoversFoundDescription') }}</p>
|
||||
</div>
|
||||
} @else {
|
||||
<!-- Results Grid -->
|
||||
<div class="results-header">
|
||||
<span class="results-count">
|
||||
<i class="pi pi-images"></i>
|
||||
{{ coverImages.length === 1 ? t('coversFoundSingular', { count: coverImages.length }) : t('coversFoundPlural', { count: coverImages.length }) }}
|
||||
</span>
|
||||
<span class="results-hint">
|
||||
<i class="pi pi-info-circle"></i>
|
||||
{{ t('resultsHint') }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="covers-grid">
|
||||
@for (cover of coverImages; track cover.url; let i = $index) {
|
||||
<div class="cover-card">
|
||||
<div class="cover-image-wrapper">
|
||||
<p-image
|
||||
[src]="cover.url"
|
||||
[alt]="t('bookCoverAlt', { index: i + 1 })"
|
||||
appendTo="body"
|
||||
[preview]="true">
|
||||
</p-image>
|
||||
@if (cover.width && cover.height) {
|
||||
<div class="resolution-badge">
|
||||
{{ cover.width }} x {{ cover.height }}
|
||||
</div>
|
||||
}
|
||||
<div class="cover-overlay">
|
||||
<p-button
|
||||
(click)="selectAndSave(cover)"
|
||||
[label]="t('selectCover')"
|
||||
icon="pi pi-check"
|
||||
size="small">
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
+330
@@ -0,0 +1,330 @@
|
||||
@use '../../../../shared/styles/panel-shared' as panel;
|
||||
|
||||
:host {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.cover-search-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
|
||||
.panel-header {
|
||||
@include panel.panel-header;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.dialog-content {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow-y: auto;
|
||||
min-height: 0;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
// Search Section
|
||||
.search-section {
|
||||
flex-shrink: 0;
|
||||
background: var(--surface-ground);
|
||||
border: 1px solid var(--surface-border);
|
||||
border-radius: 12px;
|
||||
padding: 1.25rem 1.5rem;
|
||||
margin-bottom: 1.5rem;
|
||||
|
||||
.form-row {
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.form-field {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
|
||||
&.title-field {
|
||||
flex: 1.2;
|
||||
}
|
||||
|
||||
&.author-field {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
font-size: 0.875rem;
|
||||
font-weight: 500;
|
||||
color: var(--text-color-secondary);
|
||||
|
||||
i {
|
||||
font-size: 0.875rem;
|
||||
color: var(--primary-color);
|
||||
}
|
||||
|
||||
.required {
|
||||
color: var(--red-400);
|
||||
}
|
||||
}
|
||||
|
||||
input {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.error-message {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.35rem;
|
||||
color: var(--red-400);
|
||||
font-size: 0.8rem;
|
||||
|
||||
i {
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.form-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
padding-bottom: 1px;
|
||||
}
|
||||
}
|
||||
|
||||
// Results Section
|
||||
.results-section {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
// Empty & Loading States
|
||||
.empty-state,
|
||||
.loading-state {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 3rem;
|
||||
text-align: center;
|
||||
background: var(--surface-ground);
|
||||
border: 1px dashed var(--surface-border);
|
||||
border-radius: 12px;
|
||||
|
||||
h3 {
|
||||
margin: 0 0 0.5rem;
|
||||
font-size: 1.125rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 0;
|
||||
font-size: 0.9rem;
|
||||
color: var(--text-color-secondary);
|
||||
max-width: 300px;
|
||||
}
|
||||
}
|
||||
|
||||
.empty-state-icon {
|
||||
width: 80px;
|
||||
height: 80px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: linear-gradient(135deg, var(--primary-100), var(--primary-50));
|
||||
border-radius: 50%;
|
||||
margin-bottom: 1.5rem;
|
||||
|
||||
i {
|
||||
font-size: 2rem;
|
||||
color: var(--primary-color);
|
||||
}
|
||||
|
||||
&.warning {
|
||||
background: linear-gradient(135deg, var(--yellow-100), var(--yellow-50));
|
||||
|
||||
i {
|
||||
color: var(--yellow-600);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.loading-state {
|
||||
p {
|
||||
margin-top: 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
// Results Header
|
||||
.results-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.75rem;
|
||||
margin-bottom: 1rem;
|
||||
padding-bottom: 0.75rem;
|
||||
border-bottom: 1px solid var(--surface-border);
|
||||
|
||||
.results-count {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
font-size: 0.95rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-color);
|
||||
|
||||
i {
|
||||
color: var(--primary-color);
|
||||
}
|
||||
}
|
||||
|
||||
.results-hint {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.4rem;
|
||||
font-size: 0.8rem;
|
||||
color: var(--text-color-secondary);
|
||||
|
||||
i {
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Covers Grid
|
||||
.covers-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
|
||||
gap: 1.25rem;
|
||||
padding: 0.25rem;
|
||||
}
|
||||
|
||||
.cover-card {
|
||||
.cover-image-wrapper {
|
||||
position: relative;
|
||||
width: 150px;
|
||||
height: 220px;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
background: var(--surface-ground);
|
||||
border: 2px solid transparent;
|
||||
|
||||
&:hover {
|
||||
border-color: var(--primary-color);
|
||||
|
||||
.cover-overlay {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
::ng-deep {
|
||||
.p-image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.p-image-preview {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
cursor: pointer;
|
||||
|
||||
img {
|
||||
max-width: 100%;
|
||||
max-height: 100%;
|
||||
object-fit: contain;
|
||||
}
|
||||
}
|
||||
|
||||
.p-image-preview-mask {
|
||||
background: rgba(0, 0, 0, 0.6);
|
||||
}
|
||||
|
||||
.p-image-preview-indicator {
|
||||
border-radius: 4px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.resolution-badge {
|
||||
position: absolute;
|
||||
top: 6px;
|
||||
right: 6px;
|
||||
background: rgba(0, 0, 0, 0.8);
|
||||
color: white;
|
||||
padding: 3px 6px;
|
||||
border-radius: 4px;
|
||||
font-size: 0.7rem;
|
||||
font-weight: 600;
|
||||
z-index: 2;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.cover-overlay {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 0.5rem;
|
||||
background: linear-gradient(to top, rgba(0, 0, 0, 0.8), transparent);
|
||||
opacity: 0;
|
||||
z-index: 3;
|
||||
}
|
||||
}
|
||||
|
||||
// Responsive
|
||||
@media (max-width: 768px) {
|
||||
.search-section .form-row {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
|
||||
.form-field {
|
||||
&.title-field,
|
||||
&.author-field {
|
||||
flex: none;
|
||||
}
|
||||
}
|
||||
|
||||
.form-actions {
|
||||
flex-direction: row;
|
||||
justify-content: flex-end;
|
||||
margin-top: 0.5rem;
|
||||
|
||||
::ng-deep .p-button:not(.p-button-icon-only) {
|
||||
flex: 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.results-header {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.covers-grid {
|
||||
grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
|
||||
gap: 1rem;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
import {Component, inject, Input, OnInit} from '@angular/core';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {FormBuilder, FormGroup, FormsModule, ReactiveFormsModule, Validators} from '@angular/forms';
|
||||
import {BookCoverService, CoverFetchRequest, CoverImage} from '../../../../shared/services/book-cover.service';
|
||||
import {finalize} from 'rxjs/operators';
|
||||
import {Button} from 'primeng/button';
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
import {ProgressSpinner} from 'primeng/progressspinner';
|
||||
import {DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {BookService} from '../../../book/service/book.service';
|
||||
import {BookMetadataManageService} from '../../../book/service/book-metadata-manage.service';
|
||||
import {Image} from 'primeng/image';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
@Component({
|
||||
selector: 'app-cover-search',
|
||||
templateUrl: './cover-search.component.html',
|
||||
imports: [
|
||||
Button,
|
||||
ReactiveFormsModule,
|
||||
FormsModule,
|
||||
InputText,
|
||||
ProgressSpinner,
|
||||
Image,
|
||||
Tooltip,
|
||||
TranslocoDirective
|
||||
],
|
||||
styleUrls: ['./cover-search.component.scss']
|
||||
})
|
||||
export class CoverSearchComponent implements OnInit {
|
||||
@Input() bookId!: number;
|
||||
searchForm: FormGroup;
|
||||
coverImages: CoverImage[] = [];
|
||||
loading = false;
|
||||
hasSearched = false;
|
||||
coverType: 'ebook' | 'audiobook' = 'ebook';
|
||||
|
||||
private fb = inject(FormBuilder);
|
||||
private bookCoverService = inject(BookCoverService);
|
||||
private dynamicDialogConfig = inject(DynamicDialogConfig);
|
||||
protected dynamicDialogRef = inject(DynamicDialogRef);
|
||||
protected bookService = inject(BookService);
|
||||
private bookMetadataManageService = inject(BookMetadataManageService);
|
||||
private messageService = inject(MessageService);
|
||||
private readonly t = inject(TranslocoService);
|
||||
|
||||
constructor() {
|
||||
this.searchForm = this.fb.group({
|
||||
title: ['', Validators.required],
|
||||
author: ['']
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.bookId = this.dynamicDialogConfig.data.bookId;
|
||||
const book = this.bookService.findBookById(this.bookId);
|
||||
|
||||
// Use explicitly provided coverType, or auto-detect based on primary file
|
||||
if (this.dynamicDialogConfig.data.coverType) {
|
||||
this.coverType = this.dynamicDialogConfig.data.coverType;
|
||||
} else if (book?.primaryFile?.bookType === 'AUDIOBOOK') {
|
||||
this.coverType = 'audiobook';
|
||||
} else {
|
||||
this.coverType = 'ebook';
|
||||
}
|
||||
|
||||
if (book) {
|
||||
this.searchForm.patchValue({
|
||||
title: book.metadata?.title || '',
|
||||
author: book.metadata?.authors && book.metadata?.authors.length > 0 ? book.metadata?.authors[0] : ''
|
||||
});
|
||||
|
||||
if (this.searchForm.valid) {
|
||||
this.onSearch();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onSearch() {
|
||||
if (this.searchForm.valid) {
|
||||
this.loading = true;
|
||||
const request: CoverFetchRequest = {
|
||||
title: this.searchForm.value.title,
|
||||
author: this.searchForm.value.author,
|
||||
coverType: this.coverType
|
||||
};
|
||||
|
||||
this.bookCoverService.fetchBookCovers(request)
|
||||
.pipe(finalize(() => this.loading = false))
|
||||
.subscribe({
|
||||
next: (images) => {
|
||||
this.coverImages = images.sort((a, b) => a.index - b.index);
|
||||
this.hasSearched = true;
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Error fetching covers:', error);
|
||||
this.coverImages = [];
|
||||
this.hasSearched = true;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
console.log('Form invalid', {
|
||||
formErrors: this.searchForm.errors,
|
||||
titleErrors: this.searchForm.get('title')?.errors
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
selectAndSave(image: CoverImage) {
|
||||
const uploadObservable = this.coverType === 'audiobook'
|
||||
? this.bookMetadataManageService.uploadAudiobookCoverFromUrl(this.bookId, image.url)
|
||||
: this.bookMetadataManageService.uploadCoverFromUrl(this.bookId, image.url);
|
||||
|
||||
uploadObservable.subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('metadata.coverSearch.toast.coverUpdatedSummary'),
|
||||
detail: this.coverType === 'audiobook'
|
||||
? this.t.translate('metadata.coverSearch.toast.audiobookCoverUpdatedDetail')
|
||||
: this.t.translate('metadata.coverSearch.toast.ebookCoverUpdatedDetail')
|
||||
});
|
||||
this.dynamicDialogRef.close(true);
|
||||
},
|
||||
error: err => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('metadata.coverSearch.toast.coverUpdateFailedSummary'),
|
||||
detail: err?.message || this.t.translate('metadata.coverSearch.toast.coverUpdateFailedDetail')
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onClear() {
|
||||
this.searchForm.reset();
|
||||
this.coverImages = [];
|
||||
this.hasSearched = false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user