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:
+285
@@ -0,0 +1,285 @@
|
||||
<ng-container *transloco="let t; prefix: 'authorBrowser'">
|
||||
@if (loading()) {
|
||||
<div class="loading-state">
|
||||
<p-progressSpinner
|
||||
[style]="{'width': '60px', 'height': '60px'}"
|
||||
strokeWidth="3"
|
||||
fill="transparent"
|
||||
animationDuration="1.5s">
|
||||
</p-progressSpinner>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (!loading()) {
|
||||
<div class="browse-header">
|
||||
<h2 class="browse-title">{{ t('browseAllAuthors') }}</h2>
|
||||
|
||||
<div class="browse-controls">
|
||||
<div class="search-wrapper">
|
||||
<i class="pi pi-search search-icon"></i>
|
||||
<input
|
||||
pInputText
|
||||
type="text"
|
||||
[placeholder]="t('searchPlaceholder')"
|
||||
[ngModel]="searchTerm()"
|
||||
(ngModelChange)="onSearchChange($event)"
|
||||
class="search-input"/>
|
||||
</div>
|
||||
|
||||
<div class="filter-sort-wrapper">
|
||||
<p-select
|
||||
[options]="sortOptions"
|
||||
[ngModel]="sortBy()"
|
||||
(ngModelChange)="onSortChange($event)"
|
||||
optionLabel="label"
|
||||
optionValue="value"
|
||||
class="sort-dropdown">
|
||||
</p-select>
|
||||
|
||||
<button class="sort-direction-btn" (click)="toggleSortDirection()">
|
||||
<i class="pi" [class.pi-arrow-up]="sortDirection() === 'asc'" [class.pi-arrow-down]="sortDirection() === 'desc'"></i>
|
||||
</button>
|
||||
|
||||
<button class="filter-btn" (click)="filterPopover.toggle($event)">
|
||||
<i class="pi pi-filter"></i>
|
||||
@if (activeFilterCount() > 0) {
|
||||
<span class="filter-badge"></span>
|
||||
}
|
||||
</button>
|
||||
|
||||
@if (!isMobile) {
|
||||
<button class="display-settings-btn" (click)="displaySettingsPopover.toggle($event)">
|
||||
<i class="pi pi-sliders-h"></i>
|
||||
</button>
|
||||
<p-popover #displaySettingsPopover>
|
||||
<div class="display-settings-content">
|
||||
<label class="display-settings-label">{{ t('cardSize') }}</label>
|
||||
<p-slider
|
||||
[ngModel]="authorScaleService.scaleFactor()"
|
||||
(ngModelChange)="authorScaleService.setScale($event)"
|
||||
[min]="0.7"
|
||||
[max]="1.3"
|
||||
[step]="0.01"
|
||||
[style]="{ width: '100%' }">
|
||||
</p-slider>
|
||||
<div class="scale-value-display">
|
||||
{{ authorScaleService.scaleFactor().toFixed(2) }}x
|
||||
</div>
|
||||
</div>
|
||||
</p-popover>
|
||||
}
|
||||
|
||||
<p-popover #filterPopover>
|
||||
<div class="filter-popover-content">
|
||||
<div class="filter-group">
|
||||
<label class="filter-label">{{ t('filters.matchStatus') }}</label>
|
||||
<p-select
|
||||
[options]="[
|
||||
{label: t('filters.all'), value: 'all'},
|
||||
{label: t('filters.matched'), value: 'matched'},
|
||||
{label: t('filters.unmatched'), value: 'unmatched'}
|
||||
]"
|
||||
[ngModel]="filters().matchStatus"
|
||||
(ngModelChange)="onFilterChange('matchStatus', $event)"
|
||||
optionLabel="label"
|
||||
optionValue="value"
|
||||
class="filter-dropdown">
|
||||
</p-select>
|
||||
</div>
|
||||
|
||||
<div class="filter-group">
|
||||
<label class="filter-label">{{ t('filters.photoStatus') }}</label>
|
||||
<p-select
|
||||
[options]="[
|
||||
{label: t('filters.all'), value: 'all'},
|
||||
{label: t('filters.hasPhoto'), value: 'has-photo'},
|
||||
{label: t('filters.noPhoto'), value: 'no-photo'}
|
||||
]"
|
||||
[ngModel]="filters().photoStatus"
|
||||
(ngModelChange)="onFilterChange('photoStatus', $event)"
|
||||
optionLabel="label"
|
||||
optionValue="value"
|
||||
class="filter-dropdown">
|
||||
</p-select>
|
||||
</div>
|
||||
|
||||
<div class="filter-group">
|
||||
<label class="filter-label">{{ t('filters.readStatus') }}</label>
|
||||
<p-select
|
||||
[options]="[
|
||||
{label: t('filters.all'), value: 'all'},
|
||||
{label: t('filters.allRead'), value: 'all-read'},
|
||||
{label: t('filters.someRead'), value: 'some-read'},
|
||||
{label: t('filters.inProgress'), value: 'in-progress'},
|
||||
{label: t('filters.unread'), value: 'unread'}
|
||||
]"
|
||||
[ngModel]="filters().readStatus"
|
||||
(ngModelChange)="onFilterChange('readStatus', $event)"
|
||||
optionLabel="label"
|
||||
optionValue="value"
|
||||
class="filter-dropdown">
|
||||
</p-select>
|
||||
</div>
|
||||
|
||||
<div class="filter-group">
|
||||
<label class="filter-label">{{ t('filters.bookCount') }}</label>
|
||||
<p-select
|
||||
[options]="[
|
||||
{label: t('filters.all'), value: 'all'},
|
||||
{label: '0', value: '0'},
|
||||
{label: '1', value: '1'},
|
||||
{label: '2', value: '2'},
|
||||
{label: '3', value: '3'},
|
||||
{label: '4', value: '4'},
|
||||
{label: '5', value: '5'},
|
||||
{label: '6-10', value: '6-10'},
|
||||
{label: '11-20', value: '11-20'},
|
||||
{label: '21-35', value: '21-35'},
|
||||
{label: '36+', value: '36+'}
|
||||
]"
|
||||
[ngModel]="filters().bookCount"
|
||||
(ngModelChange)="onFilterChange('bookCount', $event)"
|
||||
optionLabel="label"
|
||||
optionValue="value"
|
||||
class="filter-dropdown">
|
||||
</p-select>
|
||||
</div>
|
||||
|
||||
<div class="filter-group">
|
||||
<label class="filter-label">{{ t('filters.library') }}</label>
|
||||
<p-select
|
||||
[options]="libraryOptions()"
|
||||
[ngModel]="filters().library"
|
||||
(ngModelChange)="onFilterChange('library', $event)"
|
||||
optionLabel="label"
|
||||
optionValue="value"
|
||||
class="filter-dropdown">
|
||||
</p-select>
|
||||
</div>
|
||||
|
||||
<div class="filter-group">
|
||||
<label class="filter-label">{{ t('filters.genre') }}</label>
|
||||
<p-select
|
||||
[options]="genreOptions()"
|
||||
[ngModel]="filters().genre"
|
||||
(ngModelChange)="onFilterChange('genre', $event)"
|
||||
optionLabel="label"
|
||||
optionValue="value"
|
||||
class="filter-dropdown">
|
||||
</p-select>
|
||||
</div>
|
||||
|
||||
@if (activeFilterCount() > 0) {
|
||||
<p-button
|
||||
[label]="t('filters.reset')"
|
||||
icon="pi pi-filter-slash"
|
||||
severity="secondary"
|
||||
[outlined]="true"
|
||||
size="small"
|
||||
(onClick)="resetFilters()"
|
||||
class="filter-reset-btn">
|
||||
</p-button>
|
||||
}
|
||||
</div>
|
||||
</p-popover>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (filteredAuthors(); as authorList) {
|
||||
@if (authorList.length === 0) {
|
||||
<div class="empty-state">
|
||||
<i class="pi pi-users empty-icon"></i>
|
||||
<p>{{ t('noAuthorsFound') }}</p>
|
||||
</div>
|
||||
} @else {
|
||||
<virtual-scroller
|
||||
#scroll
|
||||
[items]="authorList"
|
||||
class="virtual-scroller">
|
||||
<div class="author-grid"
|
||||
#container
|
||||
[ngStyle]="{'grid-template-columns': 'repeat(auto-fill, minmax(' + gridColumnMinWidth + ', 1fr))'}">
|
||||
@for (author of scroll.viewPortItems; track author.id; let i = $index) {
|
||||
<div class="virtual-scroller-item"
|
||||
[ngStyle]="{width: cardWidth + 'px', height: cardHeight + 'px'}"
|
||||
[style.--card-scale]="authorScaleService.scaleFactor()">
|
||||
<app-author-card
|
||||
[author]="author"
|
||||
[index]="authorList.indexOf(author)"
|
||||
[cacheBuster]="thumbnailCacheBusters.get(author.id) || 0"
|
||||
[canQuickMatch]="canEditMetadata"
|
||||
[canDelete]="canDeleteBook"
|
||||
[isCheckboxEnabled]="canEditMetadata || canDeleteBook"
|
||||
[isSelected]="isAuthorSelected(author.id)"
|
||||
(cardClick)="navigateToAuthor($event)"
|
||||
(viewAuthor)="navigateToAuthor($event)"
|
||||
(editAuthor)="navigateToAuthorEdit($event)"
|
||||
(deleteAuthor)="deleteAuthor($event)"
|
||||
(quickMatched)="onAuthorQuickMatched($event)"
|
||||
(checkboxClick)="onCheckboxClicked($event)">
|
||||
</app-author-card>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</virtual-scroller>
|
||||
}
|
||||
}
|
||||
|
||||
@if (currentUser(); as user) {
|
||||
<div class="author-browser-footer" [class.footer-hidden]="selectedCount() === 0">
|
||||
<div class="footer-content">
|
||||
<div class="selected-count-badge">
|
||||
<i class="pi pi-check-circle"></i>
|
||||
<span class="selected-count">{{ selectedCount() }}</span>
|
||||
<span class="selected-label">{{ t('footer.selected') }}</span>
|
||||
</div>
|
||||
@if (canEditMetadata || canDeleteBook) {
|
||||
<p-divider layout="vertical"></p-divider>
|
||||
<div class="action-buttons-group">
|
||||
@if (canEditMetadata) {
|
||||
<p-button
|
||||
icon="pi pi-bolt"
|
||||
outlined="true"
|
||||
severity="info"
|
||||
(onClick)="autoMatchSelected()"
|
||||
[pTooltip]="t('footer.autoMatch')"
|
||||
tooltipPosition="top">
|
||||
</p-button>
|
||||
}
|
||||
@if (canDeleteBook) {
|
||||
<p-button
|
||||
icon="pi pi-trash"
|
||||
outlined="true"
|
||||
severity="danger"
|
||||
(onClick)="deleteSelected()"
|
||||
[pTooltip]="t('footer.deleteSelected')"
|
||||
tooltipPosition="top">
|
||||
</p-button>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
<p-divider layout="vertical"></p-divider>
|
||||
<div class="action-buttons-group">
|
||||
<p-button
|
||||
outlined="true"
|
||||
icon="pi pi-check-square"
|
||||
severity="success"
|
||||
(click)="selectAllAuthors()"
|
||||
[pTooltip]="t('footer.selectAll')"
|
||||
tooltipPosition="top">
|
||||
</p-button>
|
||||
<p-button
|
||||
outlined="true"
|
||||
icon="pi pi-times"
|
||||
severity="warn"
|
||||
(click)="deselectAllAuthors()"
|
||||
[pTooltip]="t('footer.deselectAll')"
|
||||
tooltipPosition="top">
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
</ng-container>
|
||||
+305
@@ -0,0 +1,305 @@
|
||||
.loading-state {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: calc(100dvh - 6.7rem);
|
||||
}
|
||||
|
||||
.browse-header {
|
||||
padding: 0.75rem 1rem 0;
|
||||
}
|
||||
|
||||
.browse-title {
|
||||
font-size: 1.5rem;
|
||||
font-weight: 800;
|
||||
margin-bottom: 0.75rem;
|
||||
background: linear-gradient(135deg, #ffffff, #e2e8f0, #3b82f6);
|
||||
-webkit-background-clip: text;
|
||||
-webkit-text-fill-color: transparent;
|
||||
background-clip: text;
|
||||
letter-spacing: -0.02em;
|
||||
}
|
||||
|
||||
.browse-controls {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.75rem;
|
||||
margin-bottom: 0.5rem;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.search-wrapper {
|
||||
position: relative;
|
||||
flex: 1;
|
||||
min-width: 200px;
|
||||
max-width: 400px;
|
||||
|
||||
.search-icon {
|
||||
position: absolute;
|
||||
left: 12px;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
color: #94a3b8;
|
||||
font-size: 0.9rem;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.search-input {
|
||||
width: 100%;
|
||||
padding-left: 2.25rem;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
}
|
||||
|
||||
.filter-sort-wrapper {
|
||||
display: flex;
|
||||
gap: 0.75rem;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.sort-dropdown,
|
||||
.filter-dropdown {
|
||||
min-width: 160px;
|
||||
}
|
||||
|
||||
.display-settings-btn,
|
||||
.filter-btn,
|
||||
.sort-direction-btn {
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
border-radius: 8px;
|
||||
border: 1px solid color-mix(in srgb, var(--p-surface-500), transparent 50%);
|
||||
background: color-mix(in srgb, var(--p-surface-700), transparent 30%);
|
||||
color: #94a3b8;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
|
||||
&:hover {
|
||||
color: #e2e8f0;
|
||||
border-color: var(--p-primary-400);
|
||||
}
|
||||
}
|
||||
|
||||
.filter-badge {
|
||||
position: absolute;
|
||||
top: 4px;
|
||||
right: 4px;
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 50%;
|
||||
background: var(--p-primary-400);
|
||||
}
|
||||
|
||||
.display-settings-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
min-width: 180px;
|
||||
}
|
||||
|
||||
.display-settings-label {
|
||||
font-size: 0.85rem;
|
||||
font-weight: 600;
|
||||
color: #e2e8f0;
|
||||
}
|
||||
|
||||
.scale-value-display {
|
||||
text-align: center;
|
||||
font-size: 0.8rem;
|
||||
color: #94a3b8;
|
||||
}
|
||||
|
||||
.filter-popover-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
min-width: 220px;
|
||||
}
|
||||
|
||||
.filter-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.25rem;
|
||||
}
|
||||
|
||||
.filter-label {
|
||||
font-size: 0.8rem;
|
||||
font-weight: 600;
|
||||
color: #94a3b8;
|
||||
}
|
||||
|
||||
.filter-reset-btn {
|
||||
margin-top: 0.25rem;
|
||||
}
|
||||
|
||||
.virtual-scroller {
|
||||
width: 100%;
|
||||
height: calc(100dvh - 12.5rem);
|
||||
padding: 1rem;
|
||||
box-sizing: border-box;
|
||||
overflow-y: auto;
|
||||
|
||||
scrollbar-width: thin;
|
||||
scrollbar-color: var(--primary-color) rgba(20, 20, 30, 0.5);
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
width: 12px;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-track {
|
||||
background: rgba(20, 20, 30, 0.5);
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
height: calc(100dvh - 13rem);
|
||||
padding: 0.5rem;
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
width: 8px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.author-grid {
|
||||
display: grid;
|
||||
gap: 1.25rem;
|
||||
align-items: start;
|
||||
justify-items: center;
|
||||
width: 100%;
|
||||
padding-top: 1rem;
|
||||
padding-right: 1rem;
|
||||
padding-left: 1rem;
|
||||
}
|
||||
|
||||
.virtual-scroller-item {
|
||||
position: relative;
|
||||
overflow: visible;
|
||||
transition: width 0.2s ease, height 0.2s ease;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 4rem 2rem;
|
||||
text-align: center;
|
||||
|
||||
.empty-icon {
|
||||
font-size: 3rem;
|
||||
color: #64748b;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
p {
|
||||
color: #94a3b8;
|
||||
font-size: 1rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
|
||||
.author-browser-footer {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 1rem 0.5rem 0.5rem;
|
||||
z-index: 1;
|
||||
border-radius: 10px 10px 0 0;
|
||||
border: 1px solid rgba(255, 255, 255, 0.5);
|
||||
backdrop-filter: blur(10px);
|
||||
-webkit-backdrop-filter: blur(10px);
|
||||
background: rgba(0, 0, 0, 0.65);
|
||||
transition: transform 0.1s ease, opacity 0.1s ease;
|
||||
|
||||
&.footer-hidden {
|
||||
transform: translateX(-50%) translateY(100%);
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
> .footer-content {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
max-width: 100%;
|
||||
left: 0;
|
||||
right: 0;
|
||||
transform: none;
|
||||
|
||||
&.footer-hidden {
|
||||
transform: translateY(100%);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.footer-content {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 0 0.75rem;
|
||||
}
|
||||
|
||||
.selected-count-badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
padding: 0.5rem 1rem;
|
||||
font-size: 0.9rem;
|
||||
color: #e4e4e7;
|
||||
|
||||
i {
|
||||
font-size: 1rem;
|
||||
margin-right: 0.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
.selected-count {
|
||||
font-weight: 700;
|
||||
font-size: 1rem;
|
||||
color: var(--primary-color);
|
||||
}
|
||||
|
||||
.selected-label {
|
||||
margin-left: 0.25rem;
|
||||
}
|
||||
|
||||
.action-buttons-group {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
|
||||
@media (min-width: 768px) {
|
||||
gap: 1.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 767px) {
|
||||
.browse-header {
|
||||
padding: 0.5rem 0.5rem 0;
|
||||
}
|
||||
|
||||
.browse-controls {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.search-wrapper {
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.filter-sort-wrapper {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.sort-dropdown {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
}
|
||||
+582
@@ -0,0 +1,582 @@
|
||||
import {Component, computed, DestroyRef, effect, HostListener, inject, OnInit, signal, ViewChild} from '@angular/core';
|
||||
import {NgStyle} from '@angular/common';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
||||
import {filter} from 'rxjs/operators';
|
||||
import {ProgressSpinner} from 'primeng/progressspinner';
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
import {Select} from 'primeng/select';
|
||||
import {Slider} from 'primeng/slider';
|
||||
import {Popover} from 'primeng/popover';
|
||||
import {Button} from 'primeng/button';
|
||||
import {Divider} from 'primeng/divider';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
import {VirtualScrollerComponent, VirtualScrollerModule} from '@iharbeck/ngx-virtual-scroller';
|
||||
import {BookBrowserScrollService} from '../../../book/components/book-browser/book-browser-scroll.service';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {AuthorService} from '../../service/author.service';
|
||||
import {AuthorSummary, EnrichedAuthor, AuthorFilters, DEFAULT_AUTHOR_FILTERS} from '../../model/author.model';
|
||||
import {AuthorCardComponent} from '../author-card/author-card.component';
|
||||
import {AuthorScalePreferenceService} from '../../service/author-scale-preference.service';
|
||||
import {AuthorSelectionService, AuthorCheckboxClickEvent} from '../../service/author-selection.service';
|
||||
import {PageTitleService} from '../../../../shared/service/page-title.service';
|
||||
import {ActivatedRoute, NavigationStart, Router} from '@angular/router';
|
||||
import {UserService} from '../../../settings/user-management/user.service';
|
||||
import {BookService} from '../../../book/service/book.service';
|
||||
import {Book, ReadStatus} from '../../../book/model/book.model';
|
||||
|
||||
type SortDirection = 'asc' | 'desc';
|
||||
|
||||
interface SortOption {
|
||||
label: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
interface FilterOption {
|
||||
label: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
const DEFAULT_SORT_DIRECTIONS: Record<string, SortDirection> = {
|
||||
'name': 'asc',
|
||||
'book-count': 'desc',
|
||||
'matched': 'desc',
|
||||
'recently-added': 'desc',
|
||||
'recently-read': 'desc',
|
||||
'reading-progress': 'desc',
|
||||
'avg-rating': 'desc',
|
||||
'photo': 'desc',
|
||||
'series-count': 'desc'
|
||||
};
|
||||
|
||||
@Component({
|
||||
selector: 'app-author-browser',
|
||||
standalone: true,
|
||||
templateUrl: './author-browser.component.html',
|
||||
styleUrls: ['./author-browser.component.scss'],
|
||||
imports: [
|
||||
NgStyle,
|
||||
FormsModule,
|
||||
ProgressSpinner,
|
||||
InputText,
|
||||
Select,
|
||||
Slider,
|
||||
Popover,
|
||||
Button,
|
||||
Divider,
|
||||
Tooltip,
|
||||
TranslocoDirective,
|
||||
AuthorCardComponent,
|
||||
VirtualScrollerModule
|
||||
]
|
||||
})
|
||||
export class AuthorBrowserComponent implements OnInit {
|
||||
|
||||
private static readonly BASE_WIDTH = 165;
|
||||
private static readonly BASE_HEIGHT = 290;
|
||||
private static readonly MOBILE_BASE_WIDTH = 140;
|
||||
private static readonly MOBILE_BASE_HEIGHT = 250;
|
||||
|
||||
private authorService = inject(AuthorService);
|
||||
private bookService = inject(BookService);
|
||||
private messageService = inject(MessageService);
|
||||
private pageTitle = inject(PageTitleService);
|
||||
private scrollService = inject(BookBrowserScrollService);
|
||||
private t = inject(TranslocoService);
|
||||
private router = inject(Router);
|
||||
private activatedRoute = inject(ActivatedRoute);
|
||||
private destroyRef = inject(DestroyRef);
|
||||
protected userService = inject(UserService);
|
||||
protected authorScaleService = inject(AuthorScalePreferenceService);
|
||||
protected selectionService = inject(AuthorSelectionService);
|
||||
|
||||
@ViewChild('scroll')
|
||||
virtualScroller: VirtualScrollerComponent | undefined;
|
||||
|
||||
screenWidth = window.innerWidth;
|
||||
thumbnailCacheBusters = new Map<number, number>();
|
||||
private selectedAuthors = this.selectionService.selectedAuthors;
|
||||
private allAuthorsState = signal<AuthorSummary[] | null>(null);
|
||||
|
||||
loading = computed(() => this.allAuthorsState() === null || this.bookService.isBooksLoading());
|
||||
protected currentUser = this.userService.currentUser;
|
||||
selectedCount = computed(() => this.selectedAuthors().size);
|
||||
searchTerm = signal('');
|
||||
sortBy = signal('name');
|
||||
sortDirection = signal<SortDirection>('asc');
|
||||
filters = signal<AuthorFilters>({...DEFAULT_AUTHOR_FILTERS});
|
||||
private enrichedAuthors = computed(() => {
|
||||
const authors = this.allAuthorsState();
|
||||
if (!authors) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return this.enrichAuthors(authors, this.bookService.books());
|
||||
});
|
||||
libraryOptions = computed<FilterOption[]>(() => {
|
||||
const allLabel = this.t.translate('authorBrowser.filters.all');
|
||||
const librarySet = new Set<string>();
|
||||
|
||||
for (const author of this.enrichedAuthors()) {
|
||||
for (const library of author.libraryNames) {
|
||||
librarySet.add(library);
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
{label: allLabel, value: 'all'},
|
||||
...[...librarySet].sort().map(library => ({label: library, value: library}))
|
||||
];
|
||||
});
|
||||
genreOptions = computed<FilterOption[]>(() => {
|
||||
const allLabel = this.t.translate('authorBrowser.filters.all');
|
||||
const genreSet = new Set<string>();
|
||||
|
||||
for (const author of this.enrichedAuthors()) {
|
||||
for (const category of author.categories) {
|
||||
genreSet.add(category);
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
{label: allLabel, value: 'all'},
|
||||
...[...genreSet].sort().map(category => ({label: category, value: category}))
|
||||
];
|
||||
});
|
||||
activeFilterCount = computed(() => {
|
||||
const filters = this.filters();
|
||||
let count = 0;
|
||||
if (filters.matchStatus !== 'all') count++;
|
||||
if (filters.photoStatus !== 'all') count++;
|
||||
if (filters.readStatus !== 'all') count++;
|
||||
if (filters.bookCount !== 'all') count++;
|
||||
if (filters.library !== 'all') count++;
|
||||
if (filters.genre !== 'all') count++;
|
||||
return count;
|
||||
});
|
||||
filteredAuthors = computed<EnrichedAuthor[]>(() => {
|
||||
let result = this.enrichedAuthors();
|
||||
const search = this.searchTerm().trim().toLowerCase();
|
||||
|
||||
if (search) {
|
||||
result = result.filter(author => author.name.toLowerCase().includes(search));
|
||||
}
|
||||
|
||||
result = this.applyFilters(result, this.filters());
|
||||
return this.applySort(result, this.sortBy(), this.sortDirection());
|
||||
});
|
||||
private readonly syncAuthorsEffect = effect(() => {
|
||||
const authors = this.authorService.allAuthors();
|
||||
if (authors !== null) {
|
||||
this.allAuthorsState.set(authors);
|
||||
}
|
||||
});
|
||||
private readonly syncSelectionEffect = effect(() => {
|
||||
this.selectionService.setCurrentAuthors(this.filteredAuthors());
|
||||
});
|
||||
|
||||
@HostListener('window:resize')
|
||||
onResize(): void {
|
||||
this.screenWidth = window.innerWidth;
|
||||
}
|
||||
|
||||
get isMobile(): boolean {
|
||||
return this.screenWidth <= 767;
|
||||
}
|
||||
|
||||
get cardWidth(): number {
|
||||
const base = this.isMobile
|
||||
? AuthorBrowserComponent.MOBILE_BASE_WIDTH
|
||||
: AuthorBrowserComponent.BASE_WIDTH;
|
||||
return Math.round(base * this.authorScaleService.scaleFactor());
|
||||
}
|
||||
|
||||
get cardHeight(): number {
|
||||
const base = this.isMobile
|
||||
? AuthorBrowserComponent.MOBILE_BASE_HEIGHT
|
||||
: AuthorBrowserComponent.BASE_HEIGHT;
|
||||
return Math.round(base * this.authorScaleService.scaleFactor());
|
||||
}
|
||||
|
||||
get gridColumnMinWidth(): string {
|
||||
return `${this.cardWidth}px`;
|
||||
}
|
||||
|
||||
sortOptions: SortOption[] = [];
|
||||
|
||||
private readonly validSortValues = [
|
||||
'name', 'book-count', 'matched', 'recently-added', 'recently-read',
|
||||
'reading-progress', 'avg-rating', 'photo', 'series-count'
|
||||
];
|
||||
|
||||
ngOnInit(): void {
|
||||
this.pageTitle.setPageTitle(this.t.translate('authorBrowser.pageTitle'));
|
||||
|
||||
this.sortOptions = [
|
||||
{label: this.t.translate('authorBrowser.sort.name'), value: 'name'},
|
||||
{label: this.t.translate('authorBrowser.sort.bookCount'), value: 'book-count'},
|
||||
{label: this.t.translate('authorBrowser.sort.matched'), value: 'matched'},
|
||||
{label: this.t.translate('authorBrowser.sort.recentlyAdded'), value: 'recently-added'},
|
||||
{label: this.t.translate('authorBrowser.sort.recentlyRead'), value: 'recently-read'},
|
||||
{label: this.t.translate('authorBrowser.sort.readingProgress'), value: 'reading-progress'},
|
||||
{label: this.t.translate('authorBrowser.sort.avgRating'), value: 'avg-rating'},
|
||||
{label: this.t.translate('authorBrowser.sort.photo'), value: 'photo'},
|
||||
{label: this.t.translate('authorBrowser.sort.seriesCount'), value: 'series-count'}
|
||||
];
|
||||
|
||||
const sortParam = this.activatedRoute.snapshot.queryParamMap.get('sort');
|
||||
const dirParam = this.activatedRoute.snapshot.queryParamMap.get('dir') as SortDirection | null;
|
||||
if (sortParam && this.validSortValues.includes(sortParam)) {
|
||||
this.sortBy.set(sortParam);
|
||||
this.sortDirection.set(dirParam === 'asc' || dirParam === 'desc' ? dirParam : DEFAULT_SORT_DIRECTIONS[sortParam]);
|
||||
}
|
||||
|
||||
this.setupScrollPositionTracking();
|
||||
this.destroyRef.onDestroy(() => this.selectionService.deselectAll());
|
||||
}
|
||||
|
||||
onSearchChange(value: string): void {
|
||||
this.searchTerm.set(value);
|
||||
}
|
||||
|
||||
onSortChange(value: string): void {
|
||||
this.sortBy.set(value);
|
||||
const nextDirection = DEFAULT_SORT_DIRECTIONS[value] || 'asc';
|
||||
this.sortDirection.set(nextDirection);
|
||||
this.updateSortQueryParams(value, nextDirection);
|
||||
}
|
||||
|
||||
toggleSortDirection(): void {
|
||||
const next: SortDirection = this.sortDirection() === 'asc' ? 'desc' : 'asc';
|
||||
this.sortDirection.set(next);
|
||||
this.updateSortQueryParams(this.sortBy(), next);
|
||||
}
|
||||
|
||||
onFilterChange(key: keyof AuthorFilters, value: string): void {
|
||||
this.filters.update(current => ({...current, [key]: value}));
|
||||
}
|
||||
|
||||
resetFilters(): void {
|
||||
this.filters.set({...DEFAULT_AUTHOR_FILTERS});
|
||||
}
|
||||
|
||||
get canEditMetadata(): boolean {
|
||||
const user = this.userService.currentUser();
|
||||
return !!user?.permissions?.admin || !!user?.permissions?.canEditMetadata;
|
||||
}
|
||||
|
||||
get canDeleteBook(): boolean {
|
||||
const user = this.userService.currentUser();
|
||||
return !!user?.permissions?.admin || !!user?.permissions?.canDeleteBook;
|
||||
}
|
||||
|
||||
isAuthorSelected(authorId: number): boolean {
|
||||
return this.selectedAuthors().has(authorId);
|
||||
}
|
||||
|
||||
onCheckboxClicked(event: AuthorCheckboxClickEvent): void {
|
||||
this.selectionService.handleCheckboxClick(event);
|
||||
}
|
||||
|
||||
selectAllAuthors(): void {
|
||||
this.selectionService.selectAll();
|
||||
}
|
||||
|
||||
deselectAllAuthors(): void {
|
||||
this.selectionService.deselectAll();
|
||||
}
|
||||
|
||||
navigateToAuthor(author: AuthorSummary): void {
|
||||
this.router.navigate(['/author', author.id]);
|
||||
}
|
||||
|
||||
navigateToAuthorEdit(author: AuthorSummary): void {
|
||||
this.router.navigate(['/author', author.id], {queryParams: {tab: 'edit'}});
|
||||
}
|
||||
|
||||
deleteAuthor(author: AuthorSummary): void {
|
||||
this.authorService.deleteAuthors([author.id]).subscribe({
|
||||
next: () => {
|
||||
this.removeAuthorsFromList([author.id]);
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('authorBrowser.toast.deleteSuccessSummary'),
|
||||
detail: this.t.translate('authorBrowser.toast.deleteSuccessDetail')
|
||||
});
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('authorBrowser.toast.deleteFailedSummary'),
|
||||
detail: this.t.translate('authorBrowser.toast.deleteFailedDetail')
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onAuthorQuickMatched(updated: AuthorSummary): void {
|
||||
this.thumbnailCacheBusters.set(updated.id, Date.now());
|
||||
this.allAuthorsState.update(current =>
|
||||
(current ?? []).map(author => author.id === updated.id ? updated : author)
|
||||
);
|
||||
}
|
||||
|
||||
autoMatchSelected(): void {
|
||||
const ids = this.selectionService.getSelectedIds();
|
||||
this.selectionService.deselectAll();
|
||||
this.authorService.autoMatchAuthors(ids).subscribe({
|
||||
next: (matched) => {
|
||||
this.thumbnailCacheBusters.set(matched.id, Date.now());
|
||||
this.allAuthorsState.update(current => (current ?? []).map(author => author.id === matched.id
|
||||
? {...author, asin: matched.asin, hasPhoto: matched.hasPhoto}
|
||||
: author
|
||||
));
|
||||
},
|
||||
complete: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('authorBrowser.toast.autoMatchSuccessSummary'),
|
||||
detail: this.t.translate('authorBrowser.toast.autoMatchSuccessDetail')
|
||||
});
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('authorBrowser.toast.autoMatchFailedSummary'),
|
||||
detail: this.t.translate('authorBrowser.toast.autoMatchFailedDetail')
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
deleteSelected(): void {
|
||||
const ids = this.selectionService.getSelectedIds();
|
||||
this.authorService.deleteAuthors(ids).subscribe({
|
||||
next: () => {
|
||||
this.selectionService.deselectAll();
|
||||
this.removeAuthorsFromList(ids);
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('authorBrowser.toast.deleteSelectedSuccessSummary'),
|
||||
detail: this.t.translate('authorBrowser.toast.deleteSelectedSuccessDetail')
|
||||
});
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('authorBrowser.toast.deleteFailedSummary'),
|
||||
detail: this.t.translate('authorBrowser.toast.deleteFailedDetail')
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private updateSortQueryParams(sort: string, dir: SortDirection): void {
|
||||
this.router.navigate([], {
|
||||
queryParams: {sort, dir},
|
||||
queryParamsHandling: 'merge',
|
||||
replaceUrl: true
|
||||
});
|
||||
}
|
||||
|
||||
private enrichAuthors(authors: AuthorSummary[], books: Book[]): EnrichedAuthor[] {
|
||||
const booksByAuthor = new Map<string, Book[]>();
|
||||
for (const book of books) {
|
||||
if (book.metadata?.authors) {
|
||||
for (const authorName of book.metadata.authors) {
|
||||
const key = authorName.toLowerCase();
|
||||
let list = booksByAuthor.get(key);
|
||||
if (!list) {
|
||||
list = [];
|
||||
booksByAuthor.set(key, list);
|
||||
}
|
||||
list.push(book);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return authors.map(author => {
|
||||
const authorBooks = booksByAuthor.get(author.name.toLowerCase()) || [];
|
||||
|
||||
const libraryIds = new Set<number>();
|
||||
const libraryNameSet = new Set<string>();
|
||||
const categorySet = new Set<string>();
|
||||
const seriesSet = new Set<string>();
|
||||
let latestAddedOn: string | null = null;
|
||||
let lastReadTime: string | null = null;
|
||||
let readCount = 0;
|
||||
let inProgressCount = 0;
|
||||
let ratingSum = 0;
|
||||
let ratingCount = 0;
|
||||
|
||||
for (const book of authorBooks) {
|
||||
libraryIds.add(book.libraryId);
|
||||
if (book.libraryName) libraryNameSet.add(book.libraryName);
|
||||
|
||||
if (book.metadata?.categories) {
|
||||
for (const cat of book.metadata.categories) categorySet.add(cat);
|
||||
}
|
||||
if (book.metadata?.seriesName) {
|
||||
seriesSet.add(book.metadata.seriesName.toLowerCase());
|
||||
}
|
||||
if (book.addedOn && (!latestAddedOn || book.addedOn > latestAddedOn)) {
|
||||
latestAddedOn = book.addedOn;
|
||||
}
|
||||
if (book.lastReadTime && (!lastReadTime || book.lastReadTime > lastReadTime)) {
|
||||
lastReadTime = book.lastReadTime;
|
||||
}
|
||||
if (book.readStatus === ReadStatus.READ) readCount++;
|
||||
if (book.readStatus === ReadStatus.READING || book.readStatus === ReadStatus.RE_READING) inProgressCount++;
|
||||
if (book.personalRating != null) {
|
||||
ratingSum += book.personalRating;
|
||||
ratingCount++;
|
||||
}
|
||||
}
|
||||
|
||||
const totalBooks = authorBooks.length;
|
||||
let readStatus: EnrichedAuthor['readStatus'] = 'unread';
|
||||
if (totalBooks > 0) {
|
||||
if (readCount === totalBooks) {
|
||||
readStatus = 'all-read';
|
||||
} else if (inProgressCount > 0) {
|
||||
readStatus = 'in-progress';
|
||||
} else if (readCount > 0) {
|
||||
readStatus = 'some-read';
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
...author,
|
||||
libraryIds,
|
||||
libraryNames: [...libraryNameSet].sort(),
|
||||
categories: [...categorySet].sort(),
|
||||
readStatus,
|
||||
hasSeries: seriesSet.size > 0,
|
||||
seriesCount: seriesSet.size,
|
||||
latestAddedOn,
|
||||
lastReadTime,
|
||||
readingProgress: totalBooks > 0 ? Math.round((readCount / totalBooks) * 100) : 0,
|
||||
avgPersonalRating: ratingCount > 0 ? ratingSum / ratingCount : null
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
private applyFilters(authors: EnrichedAuthor[], filters: AuthorFilters): EnrichedAuthor[] {
|
||||
return authors.filter(a => {
|
||||
if (filters.matchStatus === 'matched' && !a.asin) return false;
|
||||
if (filters.matchStatus === 'unmatched' && a.asin) return false;
|
||||
|
||||
if (filters.photoStatus === 'has-photo' && !a.hasPhoto) return false;
|
||||
if (filters.photoStatus === 'no-photo' && a.hasPhoto) return false;
|
||||
|
||||
if (filters.readStatus !== 'all' && a.readStatus !== filters.readStatus) return false;
|
||||
|
||||
if (filters.bookCount !== 'all') {
|
||||
const c = a.bookCount;
|
||||
switch (filters.bookCount) {
|
||||
case '0': if (c !== 0) return false; break;
|
||||
case '1': if (c !== 1) return false; break;
|
||||
case '2': if (c !== 2) return false; break;
|
||||
case '3': if (c !== 3) return false; break;
|
||||
case '4': if (c !== 4) return false; break;
|
||||
case '5': if (c !== 5) return false; break;
|
||||
case '6-10': if (c < 6 || c > 10) return false; break;
|
||||
case '11-20': if (c < 11 || c > 20) return false; break;
|
||||
case '21-35': if (c < 21 || c > 35) return false; break;
|
||||
case '36+': if (c < 36) return false; break;
|
||||
}
|
||||
}
|
||||
|
||||
if (filters.library !== 'all' && !a.libraryNames.includes(filters.library)) return false;
|
||||
if (filters.genre !== 'all' && !a.categories.includes(filters.genre)) return false;
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
private getScrollPositionKey(): string {
|
||||
const path = this.activatedRoute.snapshot.routeConfig?.path ?? '';
|
||||
return this.scrollService.createKey(path, this.activatedRoute.snapshot.params);
|
||||
}
|
||||
|
||||
private setupScrollPositionTracking(): void {
|
||||
this.router.events.pipe(
|
||||
filter(event => event instanceof NavigationStart),
|
||||
takeUntilDestroyed(this.destroyRef)
|
||||
).subscribe(() => {
|
||||
this.dismissBodyMenus();
|
||||
this.saveScrollPosition();
|
||||
});
|
||||
}
|
||||
|
||||
private dismissBodyMenus(): void {
|
||||
document.querySelectorAll('.p-tieredmenu-overlay').forEach(el => el.remove());
|
||||
}
|
||||
|
||||
private saveScrollPosition(): void {
|
||||
if (this.virtualScroller?.viewPortInfo) {
|
||||
const key = this.getScrollPositionKey();
|
||||
const position = this.virtualScroller.viewPortInfo.scrollStartPosition ?? 0;
|
||||
this.scrollService.savePosition(key, position);
|
||||
}
|
||||
}
|
||||
|
||||
private removeAuthorsFromList(ids: number[]): void {
|
||||
const idSet = new Set(ids);
|
||||
this.allAuthorsState.update(current => (current ?? []).filter(author => !idSet.has(author.id)));
|
||||
}
|
||||
|
||||
private applySort(authors: EnrichedAuthor[], sortBy: string, direction: SortDirection): EnrichedAuthor[] {
|
||||
const sorted = [...authors];
|
||||
const dir = direction === 'asc' ? 1 : -1;
|
||||
|
||||
switch (sortBy) {
|
||||
case 'name':
|
||||
return sorted.sort((a, b) => dir * a.name.localeCompare(b.name));
|
||||
case 'book-count':
|
||||
return sorted.sort((a, b) => dir * (a.bookCount - b.bookCount));
|
||||
case 'matched':
|
||||
return sorted.sort((a, b) => {
|
||||
const aVal = a.asin ? 1 : 0;
|
||||
const bVal = b.asin ? 1 : 0;
|
||||
if (aVal !== bVal) return dir * (aVal - bVal);
|
||||
return a.name.localeCompare(b.name);
|
||||
});
|
||||
case 'recently-added':
|
||||
return sorted.sort((a, b) => {
|
||||
if (!a.latestAddedOn && !b.latestAddedOn) return a.name.localeCompare(b.name);
|
||||
if (!a.latestAddedOn) return 1;
|
||||
if (!b.latestAddedOn) return -1;
|
||||
return dir * a.latestAddedOn.localeCompare(b.latestAddedOn);
|
||||
});
|
||||
case 'recently-read':
|
||||
return sorted.sort((a, b) => {
|
||||
if (!a.lastReadTime && !b.lastReadTime) return a.name.localeCompare(b.name);
|
||||
if (!a.lastReadTime) return 1;
|
||||
if (!b.lastReadTime) return -1;
|
||||
return dir * a.lastReadTime.localeCompare(b.lastReadTime);
|
||||
});
|
||||
case 'reading-progress':
|
||||
return sorted.sort((a, b) => dir * (a.readingProgress - b.readingProgress));
|
||||
case 'avg-rating':
|
||||
return sorted.sort((a, b) => {
|
||||
if (a.avgPersonalRating == null && b.avgPersonalRating == null) return a.name.localeCompare(b.name);
|
||||
if (a.avgPersonalRating == null) return 1;
|
||||
if (b.avgPersonalRating == null) return -1;
|
||||
return dir * (a.avgPersonalRating - b.avgPersonalRating);
|
||||
});
|
||||
case 'photo':
|
||||
return sorted.sort((a, b) => {
|
||||
const aVal = a.hasPhoto ? 1 : 0;
|
||||
const bVal = b.hasPhoto ? 1 : 0;
|
||||
if (aVal !== bVal) return dir * (aVal - bVal);
|
||||
return a.name.localeCompare(b.name);
|
||||
});
|
||||
case 'series-count':
|
||||
return sorted.sort((a, b) => dir * (a.seriesCount - b.seriesCount));
|
||||
default:
|
||||
return sorted;
|
||||
}
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
<div class="author-card" [class.selected]="isSelected" (click)="onCardClick($event)">
|
||||
<div class="cover-container" [ngClass]="{'loaded': isImageLoaded}">
|
||||
@if (hasPhoto) {
|
||||
<img
|
||||
[src]="thumbnailUrl"
|
||||
class="author-photo"
|
||||
[class.loaded]="isImageLoaded"
|
||||
[alt]="author.name"
|
||||
loading="lazy"
|
||||
decoding="async"
|
||||
(load)="onImageLoad()"
|
||||
(error)="onPhotoError()"/>
|
||||
} @else {
|
||||
<div class="author-photo-placeholder">
|
||||
<i class="pi pi-user"></i>
|
||||
</div>
|
||||
}
|
||||
|
||||
<span class="book-count-badge">{{ author.bookCount }}</span>
|
||||
|
||||
@if (isCheckboxEnabled) {
|
||||
<p-checkbox
|
||||
[binary]="true"
|
||||
class="select-checkbox"
|
||||
(click)="captureMouseEvent($event)"
|
||||
[ngModel]="isSelected"
|
||||
(onChange)="toggleSelection($event)">
|
||||
</p-checkbox>
|
||||
}
|
||||
|
||||
<div class="card-overlay">
|
||||
@if (isMatched) {
|
||||
<i class="pi pi-check-circle matched-icon" [pTooltip]="'authorBrowser.card.matched' | transloco" tooltipPosition="top"></i>
|
||||
}
|
||||
<h4 class="author-name" [pTooltip]="author.name" tooltipPosition="bottom">{{ author.name }}</h4>
|
||||
<div class="menu-button-container">
|
||||
<p-tieredmenu #menu [model]="items" [popup]="true" appendTo="body" (onShow)="onMenuShow()" (onHide)="onMenuHide()"></p-tieredmenu>
|
||||
<p-button
|
||||
class="card-menu-btn"
|
||||
size="small"
|
||||
[text]="true"
|
||||
(click)="onMenuToggle($event, menu)"
|
||||
icon="pi pi-ellipsis-v">
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
+166
@@ -0,0 +1,166 @@
|
||||
.author-card {
|
||||
background-color: var(--card-background);
|
||||
border-radius: 8px;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
|
||||
transition: box-shadow 0.25s ease, transform 0.25s ease;
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
&.selected {
|
||||
border: 2px solid var(--primary-color);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes shimmer {
|
||||
0% {
|
||||
background-position: -200% 0;
|
||||
}
|
||||
100% {
|
||||
background-position: 200% 0;
|
||||
}
|
||||
}
|
||||
|
||||
.cover-container {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: var(--card-background);
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.cover-container:not(.loaded) {
|
||||
background: linear-gradient(
|
||||
90deg,
|
||||
var(--surface-ground) 25%,
|
||||
var(--surface-hover, rgba(255, 255, 255, 0.08)) 50%,
|
||||
var(--surface-ground) 75%
|
||||
);
|
||||
background-size: 200% 100%;
|
||||
animation: shimmer 1.5s ease-in-out infinite;
|
||||
}
|
||||
|
||||
.author-photo {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
border-radius: 8px;
|
||||
opacity: 0;
|
||||
transition: opacity 0.2s ease-in, transform 0.35s ease;
|
||||
}
|
||||
|
||||
.author-photo.loaded {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.author-card:hover .author-photo.loaded {
|
||||
transform: scale(1.04);
|
||||
}
|
||||
|
||||
.author-photo-placeholder {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
color: #64748b;
|
||||
background: color-mix(in srgb, var(--p-surface-800), transparent 20%);
|
||||
|
||||
i {
|
||||
font-size: 3rem;
|
||||
}
|
||||
}
|
||||
|
||||
.book-count-badge {
|
||||
position: absolute;
|
||||
top: 8px;
|
||||
left: 8px;
|
||||
font-size: 0.8rem;
|
||||
font-weight: 700;
|
||||
color: #fff;
|
||||
background: rgba(0, 0, 0, 0.6);
|
||||
padding: 3px 9px;
|
||||
border-radius: 10px;
|
||||
line-height: 1.3;
|
||||
z-index: 3;
|
||||
}
|
||||
|
||||
.card-overlay {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
padding: 8px 2px 4px 8px;
|
||||
background: linear-gradient(to top, rgba(0, 0, 0, 0.9) 0%, rgba(0, 0, 0, 0.5) 70%, transparent 100%);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
.matched-icon {
|
||||
color: #22c55e;
|
||||
font-size: 0.85rem;
|
||||
flex-shrink: 0;
|
||||
filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.5));
|
||||
}
|
||||
|
||||
.author-name {
|
||||
font-size: 0.8rem;
|
||||
font-weight: 600;
|
||||
color: #fff;
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
line-height: 1.3;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
|
||||
}
|
||||
|
||||
.menu-button-container {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
::ng-deep .card-menu-btn .p-button {
|
||||
padding: 0.15rem 0.25rem !important;
|
||||
color: #fff !important;
|
||||
|
||||
&:hover {
|
||||
background: rgba(255, 255, 255, 0.15) !important;
|
||||
}
|
||||
}
|
||||
|
||||
.select-checkbox {
|
||||
position: absolute;
|
||||
top: 8px;
|
||||
right: 8px;
|
||||
opacity: 0;
|
||||
visibility: hidden;
|
||||
transition: opacity 0.15s ease, visibility 0.15s ease;
|
||||
z-index: 3;
|
||||
|
||||
@media (max-width: 767px) {
|
||||
top: 4px;
|
||||
right: 4px;
|
||||
}
|
||||
}
|
||||
|
||||
.cover-container:hover .select-checkbox,
|
||||
.author-card.selected .select-checkbox {
|
||||
opacity: 1;
|
||||
visibility: visible;
|
||||
}
|
||||
+184
@@ -0,0 +1,184 @@
|
||||
import {ChangeDetectorRef, Component, EventEmitter, inject, Input, OnChanges, Output, SimpleChanges} from '@angular/core';
|
||||
import {NgClass} from '@angular/common';
|
||||
import {TranslocoPipe, TranslocoService} from '@jsverse/transloco';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {CheckboxChangeEvent, CheckboxModule} from 'primeng/checkbox';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {TieredMenu} from 'primeng/tieredmenu';
|
||||
import {Button} from 'primeng/button';
|
||||
import {MenuItem, MessageService} from 'primeng/api';
|
||||
import {AuthorSummary} from '../../model/author.model';
|
||||
import {AuthorService} from '../../service/author.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-author-card',
|
||||
standalone: true,
|
||||
templateUrl: './author-card.component.html',
|
||||
styleUrls: ['./author-card.component.scss'],
|
||||
imports: [NgClass, TranslocoPipe, Tooltip, CheckboxModule, FormsModule, TieredMenu, Button]
|
||||
})
|
||||
export class AuthorCardComponent implements OnChanges {
|
||||
|
||||
@Input({required: true}) author!: AuthorSummary;
|
||||
@Input() canQuickMatch = false;
|
||||
@Input() canDelete = false;
|
||||
@Input() isCheckboxEnabled = false;
|
||||
@Input() isSelected = false;
|
||||
@Output() cardClick = new EventEmitter<AuthorSummary>();
|
||||
@Output() quickMatched = new EventEmitter<AuthorSummary>();
|
||||
@Output() checkboxClick = new EventEmitter<{ index: number; author: AuthorSummary; selected: boolean; shiftKey: boolean }>();
|
||||
@Output() viewAuthor = new EventEmitter<AuthorSummary>();
|
||||
@Output() editAuthor = new EventEmitter<AuthorSummary>();
|
||||
@Output() deleteAuthor = new EventEmitter<AuthorSummary>();
|
||||
@Output() menuToggled = new EventEmitter<boolean>();
|
||||
@Input() index = 0;
|
||||
@Input() cacheBuster = 0;
|
||||
|
||||
private authorService = inject(AuthorService);
|
||||
private messageService = inject(MessageService);
|
||||
private t = inject(TranslocoService);
|
||||
private cdr = inject(ChangeDetectorRef);
|
||||
private lastShiftKey = false;
|
||||
|
||||
hasPhoto = false;
|
||||
isImageLoaded = false;
|
||||
quickMatching = false;
|
||||
|
||||
items: MenuItem[] = [];
|
||||
private menuInitialized = false;
|
||||
|
||||
ngOnChanges(changes: SimpleChanges): void {
|
||||
if (changes['author']) {
|
||||
const prev = changes['author'].previousValue as AuthorSummary | undefined;
|
||||
const curr = changes['author'].currentValue as AuthorSummary;
|
||||
if (!prev || prev.id !== curr.id || prev.hasPhoto !== curr.hasPhoto || prev.asin !== curr.asin) {
|
||||
this.hasPhoto = curr.hasPhoto;
|
||||
this.isImageLoaded = false;
|
||||
}
|
||||
}
|
||||
if (changes['cacheBuster'] && !changes['cacheBuster'].firstChange) {
|
||||
this.hasPhoto = true;
|
||||
this.isImageLoaded = false;
|
||||
}
|
||||
}
|
||||
|
||||
get thumbnailUrl(): string {
|
||||
return this.authorService.getAuthorThumbnailUrl(this.author.id, this.cacheBuster || undefined);
|
||||
}
|
||||
|
||||
get isMatched(): boolean {
|
||||
return !!this.author.asin;
|
||||
}
|
||||
|
||||
onCardClick(event: MouseEvent): void {
|
||||
const target = event.target as HTMLElement;
|
||||
if (target.closest('.menu-button-container')) {
|
||||
return;
|
||||
}
|
||||
if (event.ctrlKey || event.metaKey) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
this.toggleCardSelection(!this.isSelected);
|
||||
return;
|
||||
}
|
||||
event.stopPropagation();
|
||||
this.cardClick.emit(this.author);
|
||||
}
|
||||
|
||||
onImageLoad(): void {
|
||||
this.isImageLoaded = true;
|
||||
}
|
||||
|
||||
onPhotoError(): void {
|
||||
this.hasPhoto = false;
|
||||
}
|
||||
|
||||
captureMouseEvent(event: MouseEvent): void {
|
||||
event.stopPropagation();
|
||||
this.lastShiftKey = event.shiftKey;
|
||||
}
|
||||
|
||||
toggleSelection(event: CheckboxChangeEvent): void {
|
||||
this.checkboxClick.emit({index: this.index, author: this.author, selected: event.checked, shiftKey: this.lastShiftKey});
|
||||
}
|
||||
|
||||
toggleCardSelection(selected: boolean): void {
|
||||
this.checkboxClick.emit({index: this.index, author: this.author, selected, shiftKey: false});
|
||||
}
|
||||
|
||||
onMenuToggle(event: Event, menu: TieredMenu): void {
|
||||
if (!this.menuInitialized) {
|
||||
this.menuInitialized = true;
|
||||
this.initMenu();
|
||||
this.cdr.markForCheck();
|
||||
}
|
||||
menu.toggle(event);
|
||||
}
|
||||
|
||||
onMenuShow(): void {
|
||||
this.menuToggled.emit(true);
|
||||
}
|
||||
|
||||
onMenuHide(): void {
|
||||
this.menuToggled.emit(false);
|
||||
}
|
||||
|
||||
private initMenu(): void {
|
||||
this.items = [
|
||||
{
|
||||
label: this.t.translate('authorBrowser.card.menu.viewAuthor'),
|
||||
icon: 'pi pi-user',
|
||||
command: () => this.viewAuthor.emit(this.author)
|
||||
},
|
||||
...(this.canQuickMatch ? [
|
||||
{
|
||||
label: this.t.translate('authorBrowser.card.menu.editAuthor'),
|
||||
icon: 'pi pi-pencil',
|
||||
command: () => this.editAuthor.emit(this.author)
|
||||
},
|
||||
{
|
||||
label: this.t.translate('authorBrowser.card.menu.quickMatch'),
|
||||
icon: this.quickMatching ? 'pi pi-spin pi-spinner' : 'pi pi-bolt',
|
||||
disabled: this.quickMatching,
|
||||
command: () => this.onQuickMatch()
|
||||
}
|
||||
] : []),
|
||||
...(this.canDelete ? [
|
||||
{
|
||||
label: this.t.translate('authorBrowser.card.menu.deleteAuthor'),
|
||||
icon: 'pi pi-trash',
|
||||
command: () => this.deleteAuthor.emit(this.author)
|
||||
}
|
||||
] : [])
|
||||
];
|
||||
}
|
||||
|
||||
private onQuickMatch(): void {
|
||||
if (this.quickMatching) return;
|
||||
|
||||
this.quickMatching = true;
|
||||
this.authorService.quickMatchAuthor(this.author.id).subscribe({
|
||||
next: (updated) => {
|
||||
this.quickMatching = false;
|
||||
this.author = {...this.author, asin: updated.asin, hasPhoto: true};
|
||||
this.hasPhoto = true;
|
||||
this.isImageLoaded = false;
|
||||
this.menuInitialized = false;
|
||||
this.quickMatched.emit(this.author);
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('authorBrowser.toast.quickMatchSuccessSummary'),
|
||||
detail: this.t.translate('authorBrowser.toast.quickMatchSuccessDetail')
|
||||
});
|
||||
},
|
||||
error: () => {
|
||||
this.quickMatching = false;
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('authorBrowser.toast.quickMatchFailedSummary'),
|
||||
detail: this.t.translate('authorBrowser.toast.quickMatchFailedDetail')
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
+148
@@ -0,0 +1,148 @@
|
||||
<ng-container *transloco="let t; prefix: 'authorBrowser.detail'">
|
||||
@if (loading) {
|
||||
<div class="loading-state">
|
||||
<p-progressSpinner strokeWidth="4" fill="transparent" animationDuration=".8s">
|
||||
</p-progressSpinner>
|
||||
<p style="color: var(--primary-color);">{{ t('loading') }}</p>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (!loading && author(); as author) {
|
||||
<div class="author-wrapper">
|
||||
<p-tabs [value]="tab" lazy="true" scrollable>
|
||||
<p-tablist>
|
||||
<p-tab value="books">
|
||||
<i class="pi pi-user"></i>
|
||||
{{ t('booksTab') }}
|
||||
</p-tab>
|
||||
@if (canEditMetadata) {
|
||||
<p-tab value="edit">
|
||||
<i class="pi pi-pencil"></i>
|
||||
{{ t('editTab') }}
|
||||
</p-tab>
|
||||
<p-tab value="match">
|
||||
<i class="pi pi-search"></i>
|
||||
{{ t('matchTab') }}
|
||||
</p-tab>
|
||||
}
|
||||
</p-tablist>
|
||||
<p-tabpanels class="tabpanels-responsive">
|
||||
<p-tabpanel value="books">
|
||||
<div class="author-header">
|
||||
<div class="author-photo-section">
|
||||
@if (hasPhoto) {
|
||||
<img
|
||||
[src]="photoUrl"
|
||||
class="author-photo-large"
|
||||
[alt]="author.name"
|
||||
(error)="onPhotoError()"/>
|
||||
} @else {
|
||||
<div class="author-photo-placeholder-large">
|
||||
<i class="pi pi-user"></i>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
<div class="author-info">
|
||||
<div class="author-title-row">
|
||||
<h2 class="author-title">{{ author.name }}</h2>
|
||||
@if (author.asin) {
|
||||
<a [href]="'https://www.amazon.com/stores/author/' + author.asin + '/about'"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
class="asin-link">
|
||||
<p-tag [value]="'ASIN: ' + author.asin" severity="info"></p-tag>
|
||||
</a>
|
||||
<a [href]="'https://www.audible.com/author/' + author.asin"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
class="asin-link">
|
||||
<p-tag value="Audible" severity="warn"></p-tag>
|
||||
</a>
|
||||
}
|
||||
@if (canEditMetadata) {
|
||||
<p-button
|
||||
[icon]="quickMatching ? 'pi pi-spin pi-spinner' : 'pi pi-bolt'"
|
||||
[outlined]="true"
|
||||
severity="warn"
|
||||
size="small"
|
||||
[disabled]="quickMatching"
|
||||
(onClick)="quickMatch()"
|
||||
[pTooltip]="t('quickMatchTooltip')"
|
||||
tooltipPosition="top">
|
||||
</p-button>
|
||||
}
|
||||
</div>
|
||||
|
||||
@if (author.description) {
|
||||
<div class="description-box">
|
||||
<div #descriptionContent
|
||||
[ngClass]="{'line-clamp-5': !isExpanded, 'line-clamp-none': isExpanded}"
|
||||
class="description-container">
|
||||
<div class="readonly-editor">{{ author.description }}</div>
|
||||
</div>
|
||||
@if (isExpanded || isOverflowing) {
|
||||
<p-button
|
||||
[label]="isExpanded ? t('showLess') : t('showMore')"
|
||||
[icon]="isExpanded ? 'pi pi-chevron-up' : 'pi pi-chevron-down'"
|
||||
iconPos="right"
|
||||
size="small"
|
||||
text
|
||||
(click)="toggleExpand()">
|
||||
</p-button>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (authorBooks(); as books) {
|
||||
<div class="books-section">
|
||||
<h3 class="section-title">{{ t('booksBy', {name: author.name}) }} ({{ books.length }})</h3>
|
||||
@if (books.length === 0) {
|
||||
<div class="empty-books">
|
||||
<i class="pi pi-book"></i>
|
||||
<p>{{ t('noBooksFound') }}</p>
|
||||
</div>
|
||||
} @else {
|
||||
<virtual-scroller #scroll [items]="books" class="books-virtual-scroller">
|
||||
<div class="books-grid" #container
|
||||
[ngStyle]="{'grid-template-columns': 'repeat(auto-fill, minmax(' + gridColumnMinWidth + ', 1fr))'}">
|
||||
@for (book of scroll.viewPortItems; track book.id; let i = $index) {
|
||||
<div class="virtual-scroller-item"
|
||||
[ngStyle]="{width: currentCardSize.width + 'px', height: currentCardSize.height + 'px'}">
|
||||
<app-book-card
|
||||
[index]="books.indexOf(book)"
|
||||
[book]="book"
|
||||
[isSeriesCollapsed]="false"
|
||||
[overlayPreferenceService]="bookCardOverlayPreferenceService">
|
||||
</app-book-card>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</virtual-scroller>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</p-tabpanel>
|
||||
|
||||
@if (canEditMetadata) {
|
||||
<p-tabpanel value="edit">
|
||||
<app-author-editor
|
||||
[authorId]="author.id"
|
||||
[author]="author"
|
||||
(authorUpdated)="onAuthorUpdated($event)">
|
||||
</app-author-editor>
|
||||
</p-tabpanel>
|
||||
<p-tabpanel value="match">
|
||||
<app-author-match
|
||||
[authorId]="author.id"
|
||||
[authorName]="author.name"
|
||||
(authorMatched)="onAuthorUpdated($event)">
|
||||
</app-author-match>
|
||||
</p-tabpanel>
|
||||
}
|
||||
</p-tabpanels>
|
||||
</p-tabs>
|
||||
</div>
|
||||
}
|
||||
</ng-container>
|
||||
+211
@@ -0,0 +1,211 @@
|
||||
.tabpanels-responsive {
|
||||
height: calc(100dvh - 9.7rem);
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.tabpanels-responsive {
|
||||
height: calc(100dvh - 8.5rem);
|
||||
}
|
||||
}
|
||||
|
||||
.author-wrapper {
|
||||
position: relative;
|
||||
border-radius: 0.75rem;
|
||||
overflow: hidden;
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
}
|
||||
|
||||
.loading-state {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100%;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.author-header {
|
||||
display: flex;
|
||||
gap: 1.5rem;
|
||||
padding: 0.5rem;
|
||||
margin-bottom: 1.5rem;
|
||||
|
||||
@media (max-width: 767px) {
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
|
||||
.author-photo-section {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.author-photo-large {
|
||||
width: 180px;
|
||||
height: 220px;
|
||||
object-fit: cover;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
|
||||
|
||||
@media (max-width: 767px) {
|
||||
width: 140px;
|
||||
height: 175px;
|
||||
}
|
||||
}
|
||||
|
||||
.author-photo-placeholder-large {
|
||||
width: 180px;
|
||||
height: 220px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: 12px;
|
||||
background: color-mix(in srgb, var(--p-surface-800), transparent 20%);
|
||||
color: #64748b;
|
||||
|
||||
i {
|
||||
font-size: 4rem;
|
||||
}
|
||||
|
||||
@media (max-width: 767px) {
|
||||
width: 140px;
|
||||
height: 175px;
|
||||
}
|
||||
}
|
||||
|
||||
.author-info {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.author-title-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
flex-wrap: wrap;
|
||||
|
||||
@media (max-width: 767px) {
|
||||
justify-content: center;
|
||||
}
|
||||
}
|
||||
|
||||
.asin-link {
|
||||
text-decoration: none;
|
||||
cursor: pointer;
|
||||
transition: opacity 0.2s;
|
||||
|
||||
&:hover {
|
||||
opacity: 0.8;
|
||||
}
|
||||
}
|
||||
|
||||
.author-title {
|
||||
font-size: 1.5rem;
|
||||
font-weight: 800;
|
||||
line-height: 1.25;
|
||||
margin: 0;
|
||||
|
||||
@media (min-width: 768px) {
|
||||
font-size: 1.875rem;
|
||||
}
|
||||
}
|
||||
|
||||
.description-box {
|
||||
padding: 1rem 0.5rem 0.5rem;
|
||||
|
||||
@media (max-width: 767px) {
|
||||
text-align: left;
|
||||
}
|
||||
}
|
||||
|
||||
.description-container {
|
||||
transition: all 0.3s;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.line-clamp-5 {
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 5;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.line-clamp-none {
|
||||
-webkit-line-clamp: unset;
|
||||
}
|
||||
|
||||
.readonly-editor {
|
||||
font-size: 0.9rem;
|
||||
color: #d1d5db;
|
||||
line-height: 1.6;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
.books-section {
|
||||
padding: 0 0.5rem;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 1.1rem;
|
||||
font-weight: 700;
|
||||
margin-bottom: 1rem;
|
||||
color: #e2e8f0;
|
||||
}
|
||||
|
||||
.books-virtual-scroller {
|
||||
width: 100%;
|
||||
height: calc(100dvh - 22rem);
|
||||
box-sizing: border-box;
|
||||
overflow-y: auto;
|
||||
|
||||
scrollbar-width: thin;
|
||||
scrollbar-color: var(--primary-color) rgba(20, 20, 30, 0.5);
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
width: 12px;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-track {
|
||||
background: rgba(20, 20, 30, 0.5);
|
||||
border-radius: 10px;
|
||||
}
|
||||
}
|
||||
|
||||
.books-grid {
|
||||
display: grid;
|
||||
gap: 1.3rem;
|
||||
align-items: start;
|
||||
justify-items: center;
|
||||
width: 100%;
|
||||
padding: 0.5rem;
|
||||
}
|
||||
|
||||
.virtual-scroller-item {
|
||||
position: relative;
|
||||
overflow: visible;
|
||||
}
|
||||
|
||||
.empty-books {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
padding: 3rem;
|
||||
text-align: center;
|
||||
|
||||
i {
|
||||
font-size: 2.5rem;
|
||||
color: #64748b;
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
|
||||
p {
|
||||
color: #94a3b8;
|
||||
font-size: 1rem;
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
+173
@@ -0,0 +1,173 @@
|
||||
import {AfterViewChecked, Component, computed, ElementRef, inject, OnInit, signal, ViewChild} from '@angular/core';
|
||||
import {ActivatedRoute, Router} from '@angular/router';
|
||||
import {NgClass, NgStyle} from '@angular/common';
|
||||
import {Tab, TabList, TabPanel, TabPanels, Tabs} from 'primeng/tabs';
|
||||
import {ProgressSpinner} from 'primeng/progressspinner';
|
||||
import {Button} from 'primeng/button';
|
||||
import {Tag} from 'primeng/tag';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
import {VirtualScrollerModule} from '@iharbeck/ngx-virtual-scroller';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {AuthorService} from '../../service/author.service';
|
||||
import {AuthorDetails} from '../../model/author.model';
|
||||
import {BookService} from '../../../book/service/book.service';
|
||||
import {BookCardComponent} from '../../../book/components/book-browser/book-card/book-card.component';
|
||||
import {CoverScalePreferenceService} from '../../../book/components/book-browser/cover-scale-preference.service';
|
||||
import {BookCardOverlayPreferenceService} from '../../../book/components/book-browser/book-card-overlay-preference.service';
|
||||
import {UserService} from '../../../settings/user-management/user.service';
|
||||
import {AuthorMatchComponent} from '../author-match/author-match.component';
|
||||
import {AuthorEditorComponent} from '../author-editor/author-editor.component';
|
||||
import {PageTitleService} from '../../../../shared/service/page-title.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-author-detail',
|
||||
standalone: true,
|
||||
templateUrl: './author-detail.component.html',
|
||||
styleUrls: ['./author-detail.component.scss'],
|
||||
imports: [
|
||||
NgClass,
|
||||
NgStyle,
|
||||
Tabs,
|
||||
TabList,
|
||||
Tab,
|
||||
TabPanels,
|
||||
TabPanel,
|
||||
ProgressSpinner,
|
||||
Button,
|
||||
Tag,
|
||||
TranslocoDirective,
|
||||
Tooltip,
|
||||
VirtualScrollerModule,
|
||||
BookCardComponent,
|
||||
AuthorMatchComponent,
|
||||
AuthorEditorComponent
|
||||
]
|
||||
})
|
||||
export class AuthorDetailComponent implements OnInit, AfterViewChecked {
|
||||
|
||||
private route = inject(ActivatedRoute);
|
||||
private router = inject(Router);
|
||||
private authorService = inject(AuthorService);
|
||||
private bookService = inject(BookService);
|
||||
private messageService = inject(MessageService);
|
||||
protected coverScalePreferenceService = inject(CoverScalePreferenceService);
|
||||
protected bookCardOverlayPreferenceService = inject(BookCardOverlayPreferenceService);
|
||||
protected userService = inject(UserService);
|
||||
private pageTitle = inject(PageTitleService);
|
||||
private t = inject(TranslocoService);
|
||||
|
||||
@ViewChild('descriptionContent') descriptionContentRef?: ElementRef<HTMLElement>;
|
||||
|
||||
loading = true;
|
||||
tab = 'books';
|
||||
isExpanded = false;
|
||||
isOverflowing = false;
|
||||
hasPhoto = true;
|
||||
photoTimestamp = Date.now();
|
||||
quickMatching = false;
|
||||
private authorState = signal<AuthorDetails | null>(null);
|
||||
author = this.authorState.asReadonly();
|
||||
authorBooks = computed(() => {
|
||||
const authorName = this.author()?.name?.toLowerCase();
|
||||
if (!authorName) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return this.bookService.books().filter(book =>
|
||||
book.metadata?.authors?.some(author => author.toLowerCase() === authorName)
|
||||
);
|
||||
});
|
||||
|
||||
get currentCardSize() {
|
||||
return this.coverScalePreferenceService.currentCardSize();
|
||||
}
|
||||
|
||||
get gridColumnMinWidth(): string {
|
||||
return this.coverScalePreferenceService.gridColumnMinWidth();
|
||||
}
|
||||
|
||||
get photoUrl(): string {
|
||||
const author = this.author();
|
||||
if (!author) return '';
|
||||
return this.authorService.getAuthorPhotoUrl(author.id) + '&t=' + this.photoTimestamp;
|
||||
}
|
||||
|
||||
get canEditMetadata(): boolean {
|
||||
const user = this.userService.getCurrentUser();
|
||||
return !!user?.permissions?.admin || !!user?.permissions?.canEditMetadata;
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
const authorId = Number(this.route.snapshot.paramMap.get('authorId'));
|
||||
const tabParam = this.route.snapshot.queryParamMap.get('tab');
|
||||
if (tabParam) {
|
||||
this.tab = tabParam;
|
||||
}
|
||||
this.loadAuthor(authorId);
|
||||
}
|
||||
|
||||
ngAfterViewChecked(): void {
|
||||
if (!this.isExpanded && this.descriptionContentRef) {
|
||||
const el = this.descriptionContentRef.nativeElement;
|
||||
this.isOverflowing = el.scrollHeight > el.clientHeight;
|
||||
}
|
||||
}
|
||||
|
||||
toggleExpand(): void {
|
||||
this.isExpanded = !this.isExpanded;
|
||||
}
|
||||
|
||||
onPhotoError(): void {
|
||||
this.hasPhoto = false;
|
||||
}
|
||||
|
||||
onAuthorUpdated(updatedAuthor: AuthorDetails): void {
|
||||
this.authorState.set(updatedAuthor);
|
||||
this.hasPhoto = true;
|
||||
this.photoTimestamp = Date.now();
|
||||
this.authorService.patchAuthorInCache(updatedAuthor.id, {
|
||||
name: updatedAuthor.name,
|
||||
asin: updatedAuthor.asin,
|
||||
hasPhoto: true,
|
||||
});
|
||||
}
|
||||
|
||||
quickMatch(): void {
|
||||
const author = this.author();
|
||||
if (!author || this.quickMatching) return;
|
||||
this.quickMatching = true;
|
||||
this.authorService.quickMatchAuthor(author.id).subscribe({
|
||||
next: (matched) => {
|
||||
this.onAuthorUpdated(matched);
|
||||
this.quickMatching = false;
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('authorBrowser.toast.quickMatchSuccessSummary'),
|
||||
detail: this.t.translate('authorBrowser.toast.quickMatchSuccessDetail')
|
||||
});
|
||||
},
|
||||
error: () => {
|
||||
this.quickMatching = false;
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('authorBrowser.toast.quickMatchFailedSummary'),
|
||||
detail: this.t.translate('authorBrowser.toast.quickMatchFailedDetail')
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private loadAuthor(authorId: number): void {
|
||||
this.authorService.getAuthorDetails(authorId).subscribe({
|
||||
next: (author) => {
|
||||
this.authorState.set(author);
|
||||
this.loading = false;
|
||||
this.pageTitle.setPageTitle(author.name);
|
||||
},
|
||||
error: () => {
|
||||
this.loading = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
+134
@@ -0,0 +1,134 @@
|
||||
<ng-container *transloco="let t; prefix: 'authorBrowser.editor'">
|
||||
<div class="editor-container">
|
||||
<div class="cover-section">
|
||||
@if (hasPhoto) {
|
||||
<p-image
|
||||
[src]="photoUrl"
|
||||
alt="Author Photo"
|
||||
width="200"
|
||||
appendTo="body"
|
||||
[preview]="true"
|
||||
(onImageError)="onPhotoError()">
|
||||
</p-image>
|
||||
} @else {
|
||||
<div class="photo-placeholder">
|
||||
<i class="pi pi-user"></i>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (isUploading) {
|
||||
<p-progressSpinner class="upload-spinner" strokeWidth="4" fill="transparent" animationDuration=".8s"></p-progressSpinner>
|
||||
}
|
||||
|
||||
<div class="cover-actions">
|
||||
<p-fileupload
|
||||
[chooseStyleClass]="'p-button-sm p-button-outlined p-button-danger'"
|
||||
[pTooltip]="t('uploadPhotoTooltip')"
|
||||
tooltipPosition="top"
|
||||
[disabled]="form.get('photoLocked')?.value"
|
||||
name="file"
|
||||
[url]="uploadUrl"
|
||||
mode="basic"
|
||||
chooseIcon="pi pi-upload"
|
||||
accept="image/jpeg,image/png"
|
||||
maxFileSize="5000000"
|
||||
(onUpload)="onUpload()"
|
||||
(onError)="onUploadError()"
|
||||
[auto]="true"
|
||||
(onBeforeUpload)="onBeforeUpload()">
|
||||
</p-fileupload>
|
||||
|
||||
<p-button
|
||||
[pTooltip]="t('searchPhotoTooltip')"
|
||||
tooltipPosition="top"
|
||||
size="small"
|
||||
icon="pi pi-search"
|
||||
[outlined]="true"
|
||||
[disabled]="form.get('photoLocked')?.value"
|
||||
(onClick)="openPhotoSearch()"
|
||||
severity="info">
|
||||
</p-button>
|
||||
|
||||
@if (!form.get('photoLocked')?.value) {
|
||||
<p-button
|
||||
[pTooltip]="t('lockField')"
|
||||
tooltipPosition="top"
|
||||
size="small"
|
||||
icon="pi pi-lock-open"
|
||||
[outlined]="true"
|
||||
(onClick)="togglePhotoLock()"
|
||||
severity="success">
|
||||
</p-button>
|
||||
}
|
||||
@if (form.get('photoLocked')?.value) {
|
||||
<p-button
|
||||
[pTooltip]="t('unlockField')"
|
||||
tooltipPosition="top"
|
||||
size="small"
|
||||
icon="pi pi-lock"
|
||||
[outlined]="true"
|
||||
(onClick)="togglePhotoLock()"
|
||||
severity="warn">
|
||||
</p-button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<form class="fields-section" [formGroup]="form" (ngSubmit)="onSave()">
|
||||
<div class="field-group">
|
||||
<label for="authorName">{{ t('nameLabel') }}</label>
|
||||
<div class="field-with-lock">
|
||||
<input pInputText id="authorName" formControlName="name"/>
|
||||
@if (!form.get('nameLocked')?.value) {
|
||||
<p-button icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('name')" severity="success"></p-button>
|
||||
}
|
||||
@if (form.get('nameLocked')?.value) {
|
||||
<p-button icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('name')" severity="warn"></p-button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="field-group">
|
||||
<label for="authorAsin">{{ t('asinLabel') }}</label>
|
||||
<div class="field-with-lock">
|
||||
<input pInputText id="authorAsin" formControlName="asin"/>
|
||||
@if (!form.get('asinLocked')?.value) {
|
||||
<p-button icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('asin')" severity="success"></p-button>
|
||||
}
|
||||
@if (form.get('asinLocked')?.value) {
|
||||
<p-button icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('asin')" severity="warn"></p-button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="field-group description-group">
|
||||
<label for="authorDescription">{{ t('descriptionLabel') }}</label>
|
||||
<div class="field-with-lock description-with-lock">
|
||||
<textarea pTextarea id="authorDescription" formControlName="description"
|
||||
[rows]="8" [autoResize]="true"></textarea>
|
||||
@if (!form.get('descriptionLocked')?.value) {
|
||||
<p-button icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('description')" severity="success" size="small"></p-button>
|
||||
}
|
||||
@if (form.get('descriptionLocked')?.value) {
|
||||
<p-button icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('description')" severity="warn" size="small"></p-button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-footer">
|
||||
<p-divider></p-divider>
|
||||
<div class="footer-actions">
|
||||
<p-button [label]="t('unlockAllBtn')" icon="pi pi-lock-open" [outlined]="true" severity="success" (onClick)="unlockAll()"></p-button>
|
||||
<p-button [label]="t('lockAllBtn')" icon="pi pi-lock" [outlined]="true" severity="warn" (onClick)="lockAll()"></p-button>
|
||||
<p-divider layout="vertical"/>
|
||||
<p-button
|
||||
type="submit"
|
||||
[label]="isSaving ? t('saving') : t('saveBtn')"
|
||||
[icon]="isSaving ? 'pi pi-spin pi-spinner' : 'pi pi-check'"
|
||||
[disabled]="isSaving">
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</ng-container>
|
||||
+126
@@ -0,0 +1,126 @@
|
||||
:host {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex: 1;
|
||||
min-height: calc(100dvh - 11rem);
|
||||
}
|
||||
|
||||
.editor-container {
|
||||
padding: 1rem 0.5rem;
|
||||
display: flex;
|
||||
gap: 2rem;
|
||||
flex: 1;
|
||||
|
||||
@media (max-width: 767px) {
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
}
|
||||
|
||||
.cover-section {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
flex-shrink: 0;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.photo-placeholder {
|
||||
width: 200px;
|
||||
height: 280px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: 12px;
|
||||
background: color-mix(in srgb, var(--p-surface-800), transparent 20%);
|
||||
color: #64748b;
|
||||
|
||||
i {
|
||||
font-size: 4rem;
|
||||
}
|
||||
}
|
||||
|
||||
.upload-spinner {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
}
|
||||
|
||||
.cover-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
padding-top: 0.75rem;
|
||||
}
|
||||
|
||||
.fields-section {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.field-group {
|
||||
margin-bottom: 1.25rem;
|
||||
|
||||
label {
|
||||
display: block;
|
||||
font-size: 0.85rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-color-secondary);
|
||||
margin-bottom: 0.4rem;
|
||||
}
|
||||
}
|
||||
|
||||
.field-with-lock {
|
||||
display: flex;
|
||||
|
||||
input,
|
||||
textarea {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
::ng-deep .field-with-lock input {
|
||||
border-radius: 6px 0 0 6px;
|
||||
}
|
||||
|
||||
.field-with-lock textarea {
|
||||
border-radius: 6px 0 6px 6px;
|
||||
}
|
||||
|
||||
::ng-deep .field-with-lock button {
|
||||
border-color: var(--p-inputtext-border-color) !important;
|
||||
border-radius: 0 6px 6px 0 !important;
|
||||
border-left: 0px !important;
|
||||
}
|
||||
|
||||
.description-with-lock {
|
||||
display: flex;
|
||||
flex-grow: 1;
|
||||
width: 100%;
|
||||
|
||||
textarea {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.form-footer {
|
||||
margin-top: auto;
|
||||
}
|
||||
|
||||
.footer-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
justify-content: flex-end;
|
||||
padding: 0.5rem 0;
|
||||
|
||||
@media (max-width: 639px) {
|
||||
flex-wrap: wrap;
|
||||
justify-content: center;
|
||||
}
|
||||
}
|
||||
+220
@@ -0,0 +1,220 @@
|
||||
import {Component, EventEmitter, inject, Input, OnChanges, OnInit, Output, SimpleChanges} from '@angular/core';
|
||||
import {FormControl, FormGroup, ReactiveFormsModule} from '@angular/forms';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
import {Button} from 'primeng/button';
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
import {Textarea} from 'primeng/textarea';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {Image} from 'primeng/image';
|
||||
import {FileUpload} from 'primeng/fileupload';
|
||||
import {ProgressSpinner} from 'primeng/progressspinner';
|
||||
import {Divider} from 'primeng/divider';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {DialogService} from 'primeng/dynamicdialog';
|
||||
import {AuthorService} from '../../service/author.service';
|
||||
import {AuthorDetails} from '../../model/author.model';
|
||||
import {AuthorPhotoSearchComponent} from '../author-photo-search/author-photo-search.component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-author-editor',
|
||||
standalone: true,
|
||||
templateUrl: './author-editor.component.html',
|
||||
styleUrls: ['./author-editor.component.scss'],
|
||||
imports: [
|
||||
ReactiveFormsModule,
|
||||
TranslocoDirective,
|
||||
Button,
|
||||
InputText,
|
||||
Textarea,
|
||||
Tooltip,
|
||||
Image,
|
||||
FileUpload,
|
||||
ProgressSpinner,
|
||||
Divider
|
||||
],
|
||||
providers: [DialogService]
|
||||
})
|
||||
export class AuthorEditorComponent implements OnInit, OnChanges {
|
||||
|
||||
@Input({required: true}) authorId!: number;
|
||||
@Input({required: true}) author!: AuthorDetails;
|
||||
@Output() authorUpdated = new EventEmitter<AuthorDetails>();
|
||||
|
||||
private authorService = inject(AuthorService);
|
||||
private messageService = inject(MessageService);
|
||||
private dialogService = inject(DialogService);
|
||||
private t = inject(TranslocoService);
|
||||
|
||||
form!: FormGroup;
|
||||
isSaving = false;
|
||||
isUploading = false;
|
||||
hasPhoto = true;
|
||||
photoTimestamp = Date.now();
|
||||
|
||||
get photoUrl(): string {
|
||||
return this.authorService.getAuthorPhotoUrl(this.authorId) + '&t=' + this.photoTimestamp;
|
||||
}
|
||||
|
||||
get uploadUrl(): string {
|
||||
return this.authorService.getUploadAuthorPhotoUrl(this.authorId);
|
||||
}
|
||||
|
||||
ngOnChanges(changes: SimpleChanges): void {
|
||||
if (changes['author'] && !changes['author'].firstChange) {
|
||||
this.hasPhoto = true;
|
||||
this.photoTimestamp = Date.now();
|
||||
}
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.form = new FormGroup({
|
||||
name: new FormControl(this.author.name || ''),
|
||||
nameLocked: new FormControl(this.author.nameLocked || false),
|
||||
description: new FormControl(this.author.description || ''),
|
||||
descriptionLocked: new FormControl(this.author.descriptionLocked || false),
|
||||
asin: new FormControl(this.author.asin || ''),
|
||||
asinLocked: new FormControl(this.author.asinLocked || false),
|
||||
photoLocked: new FormControl(this.author.photoLocked || false)
|
||||
});
|
||||
|
||||
this.applyLockStates();
|
||||
}
|
||||
|
||||
toggleLock(field: string): void {
|
||||
const lockedControl = this.form.get(field + 'Locked');
|
||||
if (!lockedControl) return;
|
||||
const isLocked = !lockedControl.value;
|
||||
lockedControl.setValue(isLocked);
|
||||
|
||||
const fieldControl = this.form.get(field);
|
||||
if (fieldControl) {
|
||||
isLocked ? fieldControl.disable() : fieldControl.enable();
|
||||
}
|
||||
|
||||
this.saveMetadata();
|
||||
}
|
||||
|
||||
togglePhotoLock(): void {
|
||||
const lockedControl = this.form.get('photoLocked');
|
||||
if (!lockedControl) return;
|
||||
lockedControl.setValue(!lockedControl.value);
|
||||
this.saveMetadata();
|
||||
}
|
||||
|
||||
onSave(): void {
|
||||
this.saveMetadata();
|
||||
}
|
||||
|
||||
lockAll(): void {
|
||||
for (const field of ['name', 'description', 'asin']) {
|
||||
this.form.get(field + 'Locked')?.setValue(true);
|
||||
this.form.get(field)?.disable();
|
||||
}
|
||||
this.form.get('photoLocked')?.setValue(true);
|
||||
this.saveMetadata();
|
||||
}
|
||||
|
||||
unlockAll(): void {
|
||||
for (const field of ['name', 'description', 'asin']) {
|
||||
this.form.get(field + 'Locked')?.setValue(false);
|
||||
this.form.get(field)?.enable();
|
||||
}
|
||||
this.form.get('photoLocked')?.setValue(false);
|
||||
this.saveMetadata();
|
||||
}
|
||||
|
||||
openPhotoSearch(): void {
|
||||
const ref = this.dialogService.open(AuthorPhotoSearchComponent, {
|
||||
data: {authorId: this.authorId, authorName: this.author.name},
|
||||
header: this.t.translate('authorBrowser.editor.searchPhotoTitle'),
|
||||
width: '70vw',
|
||||
height: '80vh',
|
||||
modal: true,
|
||||
closable: true,
|
||||
dismissableMask: true,
|
||||
contentStyle: {'overflow': 'hidden', 'padding': '0', 'display': 'flex', 'flex-direction': 'column'}
|
||||
});
|
||||
ref?.onClose.subscribe((result: boolean) => {
|
||||
if (result) {
|
||||
this.photoTimestamp = Date.now();
|
||||
this.hasPhoto = true;
|
||||
this.authorUpdated.emit(this.author);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onPhotoError(): void {
|
||||
this.hasPhoto = false;
|
||||
}
|
||||
|
||||
onBeforeUpload(): void {
|
||||
this.isUploading = true;
|
||||
}
|
||||
|
||||
onUpload(): void {
|
||||
this.isUploading = false;
|
||||
this.photoTimestamp = Date.now();
|
||||
this.hasPhoto = true;
|
||||
this.authorUpdated.emit(this.author);
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('authorBrowser.editor.toast.photoUploadedSummary'),
|
||||
detail: this.t.translate('authorBrowser.editor.toast.photoUploadedDetail')
|
||||
});
|
||||
}
|
||||
|
||||
onUploadError(): void {
|
||||
this.isUploading = false;
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('authorBrowser.editor.toast.errorSummary'),
|
||||
detail: this.t.translate('authorBrowser.editor.toast.photoUploadErrorDetail')
|
||||
});
|
||||
}
|
||||
|
||||
private saveMetadata(): void {
|
||||
if (this.isSaving) return;
|
||||
this.isSaving = true;
|
||||
|
||||
const formValue = this.form.getRawValue();
|
||||
const request = {
|
||||
name: formValue.name?.trim() || undefined,
|
||||
description: formValue.description?.trim(),
|
||||
asin: formValue.asin?.trim(),
|
||||
nameLocked: formValue.nameLocked,
|
||||
descriptionLocked: formValue.descriptionLocked,
|
||||
asinLocked: formValue.asinLocked,
|
||||
photoLocked: formValue.photoLocked
|
||||
};
|
||||
|
||||
this.authorService.updateAuthor(this.authorId, request).subscribe({
|
||||
next: (updated) => {
|
||||
this.isSaving = false;
|
||||
this.authorUpdated.emit(updated);
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('authorBrowser.editor.toast.successSummary'),
|
||||
detail: this.t.translate('authorBrowser.editor.toast.successDetail')
|
||||
});
|
||||
},
|
||||
error: () => {
|
||||
this.isSaving = false;
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('authorBrowser.editor.toast.errorSummary'),
|
||||
detail: this.t.translate('authorBrowser.editor.toast.errorDetail')
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private applyLockStates(): void {
|
||||
for (const field of ['name', 'description', 'asin']) {
|
||||
const lockedControl = this.form.get(field + 'Locked');
|
||||
const fieldControl = this.form.get(field);
|
||||
if (lockedControl?.value && fieldControl) {
|
||||
fieldControl.disable();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+100
@@ -0,0 +1,100 @@
|
||||
<ng-container *transloco="let t; prefix: 'authorBrowser.match'">
|
||||
<div class="match-container">
|
||||
<div class="search-form">
|
||||
<div class="search-fields">
|
||||
<div class="field">
|
||||
<label>{{ t('authorNameLabel') }}</label>
|
||||
<input pInputText type="text" [(ngModel)]="searchQuery" [placeholder]="t('authorNamePlaceholder')" class="search-input"/>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>{{ t('asinLabel') }}</label>
|
||||
<input pInputText type="text" [(ngModel)]="asinQuery" [placeholder]="t('asinPlaceholder')" class="search-input"/>
|
||||
</div>
|
||||
<div class="field region-field">
|
||||
<label>{{ t('regionLabel') }}</label>
|
||||
<p-select
|
||||
[options]="regionOptions"
|
||||
[(ngModel)]="selectedRegion"
|
||||
optionLabel="label"
|
||||
optionValue="value"
|
||||
class="region-dropdown">
|
||||
</p-select>
|
||||
</div>
|
||||
<div class="field search-btn-field">
|
||||
<p-button
|
||||
[label]="t('searchBtn')"
|
||||
icon="pi pi-search"
|
||||
(onClick)="search()"
|
||||
[loading]="searching"
|
||||
[disabled]="!canSearch">
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (searching) {
|
||||
<div class="search-loading">
|
||||
<p-progressSpinner
|
||||
[style]="{'width': '40px', 'height': '40px'}"
|
||||
strokeWidth="3"
|
||||
fill="transparent"
|
||||
animationDuration="1.5s">
|
||||
</p-progressSpinner>
|
||||
<span>{{ t('searching') }}</span>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (!searching && hasSearched && results.length === 0) {
|
||||
<div class="empty-results">
|
||||
<i class="pi pi-info-circle"></i>
|
||||
<p>{{ t('noResults') }}</p>
|
||||
<p class="hint">{{ t('noResultsHint') }}</p>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (!searching && !hasSearched) {
|
||||
<div class="ready-state">
|
||||
<i class="pi pi-search"></i>
|
||||
<p>{{ t('readyToSearch') }}</p>
|
||||
<p class="hint">{{ t('readyToSearchHint') }}</p>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (!searching && results.length > 0) {
|
||||
<div class="results-header">
|
||||
<span>{{ t('resultsFound', {count: results.length}) }}</span>
|
||||
</div>
|
||||
<div class="results-list">
|
||||
@for (result of results; track result.asin) {
|
||||
<div class="result-card">
|
||||
<div class="result-image">
|
||||
@if (result.imageUrl) {
|
||||
<img [src]="result.imageUrl" [alt]="result.name" loading="lazy"/>
|
||||
} @else {
|
||||
<div class="result-placeholder">
|
||||
<i class="pi pi-user"></i>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
<div class="result-info">
|
||||
<h4 class="result-name">{{ result.name }}</h4>
|
||||
<span class="result-asin">ASIN: {{ result.asin }}</span>
|
||||
@if (result.description) {
|
||||
<p class="result-description">{{ result.description }}</p>
|
||||
}
|
||||
</div>
|
||||
<div class="result-action">
|
||||
<p-button
|
||||
[label]="t('matchBtn')"
|
||||
icon="pi pi-link"
|
||||
severity="success"
|
||||
[loading]="matching"
|
||||
(onClick)="matchAuthor(result)">
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</ng-container>
|
||||
+203
@@ -0,0 +1,203 @@
|
||||
.match-container {
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.search-form {
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.search-fields {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
align-items: flex-end;
|
||||
|
||||
.field {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.4rem;
|
||||
|
||||
label {
|
||||
font-size: 0.85rem;
|
||||
font-weight: 600;
|
||||
color: #94a3b8;
|
||||
}
|
||||
|
||||
&:first-child {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.search-input {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.region-field {
|
||||
min-width: 100px;
|
||||
}
|
||||
|
||||
.region-dropdown {
|
||||
min-width: 100px;
|
||||
}
|
||||
|
||||
.search-btn-field {
|
||||
padding-bottom: 1px;
|
||||
}
|
||||
}
|
||||
|
||||
.search-loading {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
padding: 3rem;
|
||||
color: #94a3b8;
|
||||
}
|
||||
|
||||
.empty-results,
|
||||
.ready-state {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
padding: 3rem;
|
||||
text-align: center;
|
||||
|
||||
i {
|
||||
font-size: 2.5rem;
|
||||
color: #64748b;
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
|
||||
p {
|
||||
color: #94a3b8;
|
||||
font-size: 1rem;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.hint {
|
||||
font-size: 0.85rem;
|
||||
color: #64748b;
|
||||
margin-top: 0.25rem;
|
||||
}
|
||||
}
|
||||
|
||||
.results-header {
|
||||
font-size: 0.9rem;
|
||||
color: #94a3b8;
|
||||
margin-bottom: 1rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.results-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.result-card {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
padding: 1rem;
|
||||
border-radius: 10px;
|
||||
border: 1px solid color-mix(in srgb, var(--p-surface-500), transparent 60%);
|
||||
background: color-mix(in srgb, var(--p-surface-900), transparent 30%);
|
||||
transition: border-color 0.2s ease;
|
||||
|
||||
&:hover {
|
||||
border-color: color-mix(in srgb, var(--p-primary-400), transparent 50%);
|
||||
}
|
||||
}
|
||||
|
||||
.result-image {
|
||||
flex-shrink: 0;
|
||||
width: 80px;
|
||||
height: 100px;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
background: color-mix(in srgb, var(--p-surface-800), transparent 20%);
|
||||
|
||||
img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
}
|
||||
|
||||
.result-placeholder {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
color: #64748b;
|
||||
|
||||
i {
|
||||
font-size: 2rem;
|
||||
}
|
||||
}
|
||||
|
||||
.result-info {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.25rem;
|
||||
}
|
||||
|
||||
.result-name {
|
||||
font-size: 1rem;
|
||||
font-weight: 700;
|
||||
color: #e2e8f0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.result-asin {
|
||||
font-size: 0.8rem;
|
||||
color: #64748b;
|
||||
font-family: monospace;
|
||||
}
|
||||
|
||||
.result-description {
|
||||
font-size: 0.85rem;
|
||||
color: #94a3b8;
|
||||
margin: 0.25rem 0 0;
|
||||
line-height: 1.4;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 3;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.result-action {
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
@media (max-width: 767px) {
|
||||
.search-fields {
|
||||
flex-direction: column;
|
||||
|
||||
.search-input {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.region-field,
|
||||
.region-dropdown {
|
||||
min-width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.result-card {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.result-image {
|
||||
width: 60px;
|
||||
height: 75px;
|
||||
}
|
||||
|
||||
.result-action {
|
||||
align-self: flex-end;
|
||||
}
|
||||
}
|
||||
+126
@@ -0,0 +1,126 @@
|
||||
import {Component, EventEmitter, inject, Input, OnInit, Output} from '@angular/core';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {Button} from 'primeng/button';
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
import {Select} from 'primeng/select';
|
||||
import {ProgressSpinner} from 'primeng/progressspinner';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {AuthorService} from '../../service/author.service';
|
||||
import {AuthorDetails, AuthorMatchRequest, AuthorSearchResult} from '../../model/author.model';
|
||||
|
||||
interface RegionOption {
|
||||
label: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-author-match',
|
||||
standalone: true,
|
||||
templateUrl: './author-match.component.html',
|
||||
styleUrls: ['./author-match.component.scss'],
|
||||
imports: [
|
||||
FormsModule,
|
||||
Button,
|
||||
InputText,
|
||||
Select,
|
||||
ProgressSpinner,
|
||||
TranslocoDirective
|
||||
]
|
||||
})
|
||||
export class AuthorMatchComponent implements OnInit {
|
||||
|
||||
@Input({required: true}) authorId!: number;
|
||||
@Input({required: true}) authorName!: string;
|
||||
@Output() authorMatched = new EventEmitter<AuthorDetails>();
|
||||
|
||||
private authorService = inject(AuthorService);
|
||||
private messageService = inject(MessageService);
|
||||
private t = inject(TranslocoService);
|
||||
|
||||
searchQuery = '';
|
||||
asinQuery = '';
|
||||
selectedRegion = 'us';
|
||||
searching = false;
|
||||
matching = false;
|
||||
results: AuthorSearchResult[] = [];
|
||||
hasSearched = false;
|
||||
|
||||
regionOptions: RegionOption[] = [
|
||||
{label: 'US', value: 'us'},
|
||||
{label: 'UK', value: 'uk'},
|
||||
{label: 'AU', value: 'au'},
|
||||
{label: 'CA', value: 'ca'},
|
||||
{label: 'IN', value: 'in'},
|
||||
{label: 'FR', value: 'fr'},
|
||||
{label: 'DE', value: 'de'},
|
||||
{label: 'IT', value: 'it'},
|
||||
{label: 'ES', value: 'es'},
|
||||
{label: 'JP', value: 'jp'}
|
||||
];
|
||||
|
||||
ngOnInit(): void {
|
||||
this.searchQuery = this.authorName;
|
||||
}
|
||||
|
||||
get canSearch(): boolean {
|
||||
return !!this.searchQuery.trim() || !!this.asinQuery.trim();
|
||||
}
|
||||
|
||||
search(): void {
|
||||
const asin = this.asinQuery.trim();
|
||||
const query = this.searchQuery.trim();
|
||||
if (!query && !asin) return;
|
||||
this.searching = true;
|
||||
this.results = [];
|
||||
this.hasSearched = true;
|
||||
|
||||
this.authorService.searchAuthorMetadata(this.authorId, query, this.selectedRegion, asin || undefined)
|
||||
.subscribe({
|
||||
next: (results) => {
|
||||
this.results = results;
|
||||
this.searching = false;
|
||||
},
|
||||
error: () => {
|
||||
this.searching = false;
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('authorBrowser.match.toast.searchFailedSummary'),
|
||||
detail: this.t.translate('authorBrowser.match.toast.searchFailedDetail'),
|
||||
life: 3000
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
matchAuthor(result: AuthorSearchResult): void {
|
||||
this.matching = true;
|
||||
const request: AuthorMatchRequest = {
|
||||
source: result.source,
|
||||
asin: result.asin,
|
||||
region: this.selectedRegion
|
||||
};
|
||||
|
||||
this.authorService.matchAuthor(this.authorId, request).subscribe({
|
||||
next: (updatedAuthor) => {
|
||||
this.matching = false;
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('authorBrowser.match.toast.matchSuccessSummary'),
|
||||
detail: this.t.translate('authorBrowser.match.toast.matchSuccessDetail'),
|
||||
life: 3000
|
||||
});
|
||||
this.authorMatched.emit(updatedAuthor);
|
||||
},
|
||||
error: () => {
|
||||
this.matching = false;
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('authorBrowser.match.toast.matchFailedSummary'),
|
||||
detail: this.t.translate('authorBrowser.match.toast.matchFailedDetail'),
|
||||
life: 3000
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
<ng-container *transloco="let t; prefix: 'authorBrowser.photoSearch'">
|
||||
<div class="photo-search-container">
|
||||
<div class="search-section">
|
||||
<form [formGroup]="searchForm" (ngSubmit)="onSearch()">
|
||||
<div class="form-row">
|
||||
<div class="form-field">
|
||||
<label for="photoQuery">
|
||||
<i class="pi pi-user"></i>
|
||||
{{ t('queryLabel') }}
|
||||
</label>
|
||||
<input
|
||||
pInputText
|
||||
id="photoQuery"
|
||||
formControlName="query"
|
||||
[placeholder]="t('queryPlaceholder')"/>
|
||||
</div>
|
||||
|
||||
<div class="form-actions">
|
||||
<p-button
|
||||
type="submit"
|
||||
[label]="t('searchBtn')"
|
||||
icon="pi pi-search"
|
||||
[loading]="searching"
|
||||
[disabled]="searchForm.invalid">
|
||||
</p-button>
|
||||
<p-button
|
||||
type="button"
|
||||
icon="pi pi-refresh"
|
||||
[text]="true"
|
||||
[rounded]="true"
|
||||
severity="secondary"
|
||||
(click)="onClear()"
|
||||
[pTooltip]="t('resetTooltip')"
|
||||
tooltipPosition="top">
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="results-section">
|
||||
@if (!hasSearched) {
|
||||
<div class="empty-state">
|
||||
<div class="empty-state-icon">
|
||||
<i class="pi pi-images"></i>
|
||||
</div>
|
||||
<h3>{{ t('readyTitle') }}</h3>
|
||||
<p>{{ t('readyHint') }}</p>
|
||||
</div>
|
||||
} @else if (searching) {
|
||||
<div class="loading-state">
|
||||
<p-progressSpinner strokeWidth="3" animationDuration="1s"></p-progressSpinner>
|
||||
<p>{{ t('searching') }}</p>
|
||||
</div>
|
||||
} @else if (photos.length === 0) {
|
||||
<div class="empty-state no-results">
|
||||
<div class="empty-state-icon warning">
|
||||
<i class="pi pi-search"></i>
|
||||
</div>
|
||||
<h3>{{ t('noResults') }}</h3>
|
||||
<p>{{ t('noResultsHint') }}</p>
|
||||
</div>
|
||||
} @else {
|
||||
<div class="results-header">
|
||||
<span class="results-count">
|
||||
<i class="pi pi-images"></i>
|
||||
{{ t('resultsFound', { count: photos.length }) }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="photos-grid">
|
||||
@for (photo of photos; track photo.url; let i = $index) {
|
||||
<div class="photo-card">
|
||||
<div class="photo-image-wrapper">
|
||||
<p-image
|
||||
[src]="photo.url"
|
||||
[alt]="t('photoAlt', { index: i + 1 })"
|
||||
appendTo="body"
|
||||
[preview]="true">
|
||||
</p-image>
|
||||
@if (photo.width && photo.height) {
|
||||
<div class="resolution-badge">
|
||||
{{ photo.width }} x {{ photo.height }}
|
||||
</div>
|
||||
}
|
||||
<div class="photo-overlay">
|
||||
<p-button
|
||||
(click)="selectAndUploadPhoto(photo)"
|
||||
[label]="t('selectBtn')"
|
||||
icon="pi pi-check"
|
||||
size="small">
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
+244
@@ -0,0 +1,244 @@
|
||||
:host {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.photo-search-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
padding: 0 1.5rem 1.5rem 1.5rem;
|
||||
}
|
||||
|
||||
.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;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
input {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.form-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
padding-bottom: 1px;
|
||||
}
|
||||
}
|
||||
|
||||
.results-section {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.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 {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.photos-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
|
||||
gap: 1.25rem;
|
||||
padding: 0.25rem;
|
||||
}
|
||||
|
||||
.photo-card {
|
||||
.photo-image-wrapper {
|
||||
position: relative;
|
||||
width: 150px;
|
||||
height: 200px;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
background: var(--surface-ground);
|
||||
border: 2px solid transparent;
|
||||
|
||||
&:hover {
|
||||
border-color: var(--primary-color);
|
||||
|
||||
.photo-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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.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;
|
||||
}
|
||||
|
||||
.photo-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;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.search-section .form-row {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
|
||||
.form-actions {
|
||||
flex-direction: row;
|
||||
justify-content: flex-end;
|
||||
margin-top: 0.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
.photos-grid {
|
||||
grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
|
||||
gap: 1rem;
|
||||
}
|
||||
}
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
import {Component, inject, OnInit} from '@angular/core';
|
||||
import {FormBuilder, FormGroup, ReactiveFormsModule, Validators} from '@angular/forms';
|
||||
import {Button} from 'primeng/button';
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
import {ProgressSpinner} from 'primeng/progressspinner';
|
||||
import {Image} from 'primeng/image';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {finalize} from 'rxjs/operators';
|
||||
import {AuthorService} from '../../service/author.service';
|
||||
import {AuthorPhotoResult} from '../../model/author.model';
|
||||
|
||||
@Component({
|
||||
selector: 'app-author-photo-search',
|
||||
templateUrl: './author-photo-search.component.html',
|
||||
styleUrls: ['./author-photo-search.component.scss'],
|
||||
imports: [
|
||||
ReactiveFormsModule,
|
||||
Button,
|
||||
InputText,
|
||||
ProgressSpinner,
|
||||
Image,
|
||||
Tooltip,
|
||||
TranslocoDirective
|
||||
]
|
||||
})
|
||||
export class AuthorPhotoSearchComponent implements OnInit {
|
||||
searchForm: FormGroup;
|
||||
photos: AuthorPhotoResult[] = [];
|
||||
searching = false;
|
||||
hasSearched = false;
|
||||
|
||||
private fb = inject(FormBuilder);
|
||||
private authorService = inject(AuthorService);
|
||||
private dynamicDialogConfig = inject(DynamicDialogConfig);
|
||||
protected dynamicDialogRef = inject(DynamicDialogRef);
|
||||
private messageService = inject(MessageService);
|
||||
private t = inject(TranslocoService);
|
||||
|
||||
private authorId!: number;
|
||||
|
||||
constructor() {
|
||||
this.searchForm = this.fb.group({
|
||||
query: ['', Validators.required]
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.authorId = this.dynamicDialogConfig.data.authorId;
|
||||
const authorName = this.dynamicDialogConfig.data.authorName;
|
||||
|
||||
if (authorName) {
|
||||
this.searchForm.patchValue({query: authorName});
|
||||
if (this.searchForm.valid) {
|
||||
this.onSearch();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onSearch(): void {
|
||||
if (!this.searchForm.valid) return;
|
||||
this.searching = true;
|
||||
|
||||
this.authorService.searchAuthorPhotos(this.authorId, this.searchForm.value.query)
|
||||
.pipe(finalize(() => this.searching = false))
|
||||
.subscribe({
|
||||
next: (photos) => {
|
||||
this.photos = photos.sort((a, b) => a.index - b.index);
|
||||
this.hasSearched = true;
|
||||
},
|
||||
error: () => {
|
||||
this.photos = [];
|
||||
this.hasSearched = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
selectAndUploadPhoto(photo: AuthorPhotoResult): void {
|
||||
this.authorService.uploadAuthorPhotoFromUrl(this.authorId, photo.url).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('authorBrowser.editor.toast.photoUploadedSummary'),
|
||||
detail: this.t.translate('authorBrowser.editor.toast.photoUploadedDetail')
|
||||
});
|
||||
this.dynamicDialogRef.close(true);
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('authorBrowser.editor.toast.errorSummary'),
|
||||
detail: this.t.translate('authorBrowser.editor.toast.photoUploadErrorDetail')
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onClear(): void {
|
||||
this.searchForm.reset();
|
||||
this.photos = [];
|
||||
this.hasSearched = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
export interface AuthorSummary {
|
||||
id: number;
|
||||
name: string;
|
||||
asin?: string;
|
||||
bookCount: number;
|
||||
hasPhoto: boolean;
|
||||
}
|
||||
|
||||
export interface EnrichedAuthor extends AuthorSummary {
|
||||
libraryIds: Set<number>;
|
||||
libraryNames: string[];
|
||||
categories: string[];
|
||||
readStatus: 'all-read' | 'some-read' | 'in-progress' | 'unread';
|
||||
hasSeries: boolean;
|
||||
seriesCount: number;
|
||||
latestAddedOn: string | null;
|
||||
lastReadTime: string | null;
|
||||
readingProgress: number;
|
||||
avgPersonalRating: number | null;
|
||||
}
|
||||
|
||||
export interface AuthorFilters {
|
||||
matchStatus: 'all' | 'matched' | 'unmatched';
|
||||
photoStatus: 'all' | 'has-photo' | 'no-photo';
|
||||
readStatus: 'all' | 'all-read' | 'some-read' | 'in-progress' | 'unread';
|
||||
bookCount: 'all' | '0' | '1' | '2' | '3' | '4' | '5' | '6-10' | '11-20' | '21-35' | '36+';
|
||||
library: string;
|
||||
genre: string;
|
||||
}
|
||||
|
||||
export const DEFAULT_AUTHOR_FILTERS: AuthorFilters = {
|
||||
matchStatus: 'all',
|
||||
photoStatus: 'all',
|
||||
readStatus: 'all',
|
||||
bookCount: 'all',
|
||||
library: 'all',
|
||||
genre: 'all'
|
||||
};
|
||||
|
||||
export interface AuthorDetails {
|
||||
id: number;
|
||||
name: string;
|
||||
description?: string;
|
||||
asin?: string;
|
||||
nameLocked: boolean;
|
||||
descriptionLocked: boolean;
|
||||
asinLocked: boolean;
|
||||
photoLocked: boolean;
|
||||
}
|
||||
|
||||
export interface AuthorSearchResult {
|
||||
source: string;
|
||||
asin: string;
|
||||
name: string;
|
||||
description?: string;
|
||||
imageUrl?: string;
|
||||
}
|
||||
|
||||
export interface AuthorMatchRequest {
|
||||
source: string;
|
||||
asin: string;
|
||||
region: string;
|
||||
}
|
||||
|
||||
export interface AuthorPhotoResult {
|
||||
url: string;
|
||||
width: number;
|
||||
height: number;
|
||||
index: number;
|
||||
}
|
||||
|
||||
export interface AuthorUpdateRequest {
|
||||
name?: string;
|
||||
description?: string;
|
||||
asin?: string;
|
||||
nameLocked?: boolean;
|
||||
descriptionLocked?: boolean;
|
||||
asinLocked?: boolean;
|
||||
photoLocked?: boolean;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import {QueryClient} from '@tanstack/angular-query-experimental';
|
||||
|
||||
import {AuthorSummary} from '../model/author.model';
|
||||
import {AUTHORS_QUERY_KEY} from './author-query-keys';
|
||||
|
||||
export function patchAuthorInCache(queryClient: QueryClient, authorId: number, fields: Partial<AuthorSummary>): void {
|
||||
queryClient.setQueryData<AuthorSummary[]>(AUTHORS_QUERY_KEY, current =>
|
||||
(current ?? []).map(author => author.id === authorId ? {...author, ...fields} : author)
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export const AUTHORS_QUERY_KEY = ['authors'] as const;
|
||||
@@ -0,0 +1,56 @@
|
||||
import {inject, Injectable, signal} from '@angular/core';
|
||||
import {LocalStorageService} from '../../../shared/service/local-storage.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class AuthorScalePreferenceService {
|
||||
|
||||
private readonly DEBOUNCE_MS = 1000;
|
||||
private readonly STORAGE_KEY = 'authorScalePreference';
|
||||
|
||||
private readonly localStorageService = inject(LocalStorageService);
|
||||
|
||||
private readonly _scaleFactor = signal(1.0);
|
||||
readonly scaleFactor = this._scaleFactor.asReadonly();
|
||||
|
||||
private saveTimeout: ReturnType<typeof setTimeout> | null = null;
|
||||
private lastPersistedScale = 1.0;
|
||||
|
||||
constructor() {
|
||||
const initialScale = this.loadScaleFromStorage();
|
||||
this._scaleFactor.set(initialScale);
|
||||
this.lastPersistedScale = initialScale;
|
||||
}
|
||||
|
||||
setScale(scale: number): void {
|
||||
this._scaleFactor.set(scale);
|
||||
if (scale === this.lastPersistedScale) {
|
||||
return;
|
||||
}
|
||||
this.scheduleSave(scale);
|
||||
}
|
||||
|
||||
private scheduleSave(scale: number): void {
|
||||
if (this.saveTimeout) {
|
||||
clearTimeout(this.saveTimeout);
|
||||
}
|
||||
|
||||
this.saveTimeout = setTimeout(() => {
|
||||
this.saveScalePreference(scale);
|
||||
}, this.DEBOUNCE_MS);
|
||||
}
|
||||
|
||||
private saveScalePreference(scale: number): void {
|
||||
this.localStorageService.set(this.STORAGE_KEY, scale);
|
||||
this.lastPersistedScale = scale;
|
||||
}
|
||||
|
||||
private loadScaleFromStorage(): number {
|
||||
const saved = this.localStorageService.get<number>(this.STORAGE_KEY);
|
||||
if (saved !== null && !isNaN(saved)) {
|
||||
return saved;
|
||||
}
|
||||
return 1.0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
import {computed, Injectable, signal} from '@angular/core';
|
||||
import {AuthorSummary} from '../model/author.model';
|
||||
|
||||
export interface AuthorCheckboxClickEvent {
|
||||
index: number;
|
||||
author: AuthorSummary;
|
||||
selected: boolean;
|
||||
shiftKey: boolean;
|
||||
}
|
||||
|
||||
@Injectable({providedIn: 'root'})
|
||||
export class AuthorSelectionService {
|
||||
private readonly _selectedAuthors = signal<Set<number>>(new Set());
|
||||
readonly selectedAuthors = this._selectedAuthors.asReadonly();
|
||||
readonly selectedCount = computed(() => this._selectedAuthors().size);
|
||||
|
||||
private currentAuthors: AuthorSummary[] = [];
|
||||
private lastSelectedIndex: number | null = null;
|
||||
|
||||
setCurrentAuthors(authors: AuthorSummary[]): void {
|
||||
this.currentAuthors = authors;
|
||||
}
|
||||
|
||||
handleCheckboxClick(event: AuthorCheckboxClickEvent): void {
|
||||
const {index, author, selected, shiftKey} = event;
|
||||
|
||||
if (!shiftKey || this.lastSelectedIndex === null) {
|
||||
if (selected) {
|
||||
this.select(author.id);
|
||||
} else {
|
||||
this.deselect(author.id);
|
||||
}
|
||||
this.lastSelectedIndex = index;
|
||||
} else {
|
||||
const start = Math.min(this.lastSelectedIndex, index);
|
||||
const end = Math.max(this.lastSelectedIndex, index);
|
||||
for (let i = start; i <= end; i++) {
|
||||
const a = this.currentAuthors[i];
|
||||
if (!a) continue;
|
||||
if (selected) {
|
||||
this.select(a.id);
|
||||
} else {
|
||||
this.deselect(a.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
selectAll(): void {
|
||||
this._selectedAuthors.update(current => {
|
||||
const next = new Set(current);
|
||||
for (const author of this.currentAuthors) {
|
||||
next.add(author.id);
|
||||
}
|
||||
return next;
|
||||
});
|
||||
}
|
||||
|
||||
deselectAll(): void {
|
||||
this._selectedAuthors.set(new Set());
|
||||
this.lastSelectedIndex = null;
|
||||
}
|
||||
|
||||
getSelectedIds(): number[] {
|
||||
return Array.from(this.selectedAuthors());
|
||||
}
|
||||
|
||||
private select(id: number): void {
|
||||
this._selectedAuthors.update(current => {
|
||||
const next = new Set(current);
|
||||
next.add(id);
|
||||
return next;
|
||||
});
|
||||
}
|
||||
|
||||
private deselect(id: number): void {
|
||||
this._selectedAuthors.update(current => {
|
||||
const next = new Set(current);
|
||||
next.delete(id);
|
||||
return next;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
import {computed, effect, inject, Injectable} from '@angular/core';
|
||||
import {HttpClient, HttpHeaders} from '@angular/common/http';
|
||||
import {lastValueFrom, Observable} from 'rxjs';
|
||||
import {map} from 'rxjs/operators';
|
||||
import {SseClient} from 'ngx-sse-client';
|
||||
import {API_CONFIG} from '../../../core/config/api-config';
|
||||
import {AuthorSummary, AuthorDetails, AuthorSearchResult, AuthorMatchRequest, AuthorUpdateRequest, AuthorPhotoResult} from '../model/author.model';
|
||||
import {AuthService} from '../../../shared/service/auth.service';
|
||||
import {injectQuery, queryOptions, QueryClient} from '@tanstack/angular-query-experimental';
|
||||
import {AUTHORS_QUERY_KEY} from './author-query-keys';
|
||||
import {patchAuthorInCache} from './author-query-cache';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class AuthorService {
|
||||
|
||||
private http = inject(HttpClient);
|
||||
private authService = inject(AuthService);
|
||||
private sseClient = inject(SseClient);
|
||||
private queryClient = inject(QueryClient);
|
||||
private readonly baseUrl = `${API_CONFIG.BASE_URL}/api/v1/authors`;
|
||||
private readonly mediaBaseUrl = `${API_CONFIG.BASE_URL}/api/v1/media`;
|
||||
private readonly token = this.authService.token;
|
||||
|
||||
private authorsQuery = injectQuery(() => ({
|
||||
...this.getAuthorsQueryOptions(),
|
||||
enabled: !!this.token(),
|
||||
}));
|
||||
|
||||
allAuthors = computed(() => this.authorsQuery.data() ?? null);
|
||||
isAuthorsLoading = computed(() => !!this.token() && this.authorsQuery.isPending());
|
||||
|
||||
constructor() {
|
||||
effect(() => {
|
||||
const token = this.token();
|
||||
if (token === null) {
|
||||
this.queryClient.removeQueries({queryKey: AUTHORS_QUERY_KEY});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private getAuthorsQueryOptions() {
|
||||
return queryOptions({
|
||||
queryKey: AUTHORS_QUERY_KEY,
|
||||
queryFn: () => lastValueFrom(this.http.get<AuthorSummary[]>(this.baseUrl))
|
||||
});
|
||||
}
|
||||
|
||||
invalidateAuthors(): void {
|
||||
void this.queryClient.invalidateQueries({queryKey: AUTHORS_QUERY_KEY, exact: true});
|
||||
}
|
||||
|
||||
patchAuthorInCache(authorId: number, fields: Partial<AuthorSummary>): void {
|
||||
patchAuthorInCache(this.queryClient, authorId, fields);
|
||||
}
|
||||
|
||||
getAuthorDetails(authorId: number): Observable<AuthorDetails> {
|
||||
return this.http.get<AuthorDetails>(`${this.baseUrl}/${authorId}`);
|
||||
}
|
||||
|
||||
getAuthorByName(name: string): Observable<AuthorDetails> {
|
||||
return this.http.get<AuthorDetails>(`${this.baseUrl}/by-name`, {params: {name}});
|
||||
}
|
||||
|
||||
searchAuthorMetadata(authorId: number, query: string, region: string, asin?: string): Observable<AuthorSearchResult[]> {
|
||||
const params: Record<string, string> = {region};
|
||||
if (asin) {
|
||||
params['asin'] = asin;
|
||||
} else {
|
||||
params['q'] = query;
|
||||
}
|
||||
return this.http.get<AuthorSearchResult[]>(`${this.baseUrl}/${authorId}/search-metadata`, {params});
|
||||
}
|
||||
|
||||
matchAuthor(authorId: number, request: AuthorMatchRequest): Observable<AuthorDetails> {
|
||||
return this.http.post<AuthorDetails>(`${this.baseUrl}/${authorId}/match`, request);
|
||||
}
|
||||
|
||||
quickMatchAuthor(authorId: number, region: string = 'us'): Observable<AuthorDetails> {
|
||||
return this.http.post<AuthorDetails>(`${this.baseUrl}/${authorId}/quick-match`, null, {
|
||||
params: {region}
|
||||
});
|
||||
}
|
||||
|
||||
autoMatchAuthors(authorIds: number[]): Observable<AuthorSummary> {
|
||||
const token = this.authService.getInternalAccessToken();
|
||||
const headers = new HttpHeaders()
|
||||
.set('Content-Type', 'application/json')
|
||||
.set('Authorization', `Bearer ${token}`);
|
||||
|
||||
return this.sseClient.stream(
|
||||
`${this.baseUrl}/auto-match`,
|
||||
{keepAlive: false, reconnectionDelay: 1000, responseType: 'event'},
|
||||
{headers, body: authorIds, withCredentials: true},
|
||||
'POST'
|
||||
).pipe(
|
||||
map(event => {
|
||||
if (event.type === 'error') {
|
||||
throw new Error((event as ErrorEvent).message);
|
||||
}
|
||||
return JSON.parse((event as MessageEvent).data) as AuthorSummary;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
updateAuthor(authorId: number, request: AuthorUpdateRequest): Observable<AuthorDetails> {
|
||||
return this.http.put<AuthorDetails>(`${this.baseUrl}/${authorId}`, request);
|
||||
}
|
||||
|
||||
unmatchAuthors(authorIds: number[]): Observable<void> {
|
||||
return this.http.post<void>(`${this.baseUrl}/unmatch`, authorIds);
|
||||
}
|
||||
|
||||
deleteAuthors(authorIds: number[]): Observable<void> {
|
||||
return this.http.delete<void>(this.baseUrl, {body: authorIds});
|
||||
}
|
||||
|
||||
searchAuthorPhotos(authorId: number, query: string): Observable<AuthorPhotoResult[]> {
|
||||
return this.http.get<AuthorPhotoResult[]>(`${this.baseUrl}/${authorId}/search-photos`, {
|
||||
params: {q: query}
|
||||
});
|
||||
}
|
||||
|
||||
uploadAuthorPhotoFromUrl(authorId: number, imageUrl: string): Observable<void> {
|
||||
return this.http.post<void>(`${this.baseUrl}/${authorId}/photo/url`, null, {
|
||||
params: {url: imageUrl}
|
||||
});
|
||||
}
|
||||
|
||||
getUploadAuthorPhotoUrl(authorId: number): string {
|
||||
return `${this.baseUrl}/${authorId}/photo/upload`;
|
||||
}
|
||||
|
||||
getAuthorPhotoUrl(authorId: number): string {
|
||||
const token = this.authService.getInternalAccessToken();
|
||||
let url = `${this.mediaBaseUrl}/author/${authorId}/photo`;
|
||||
if (token) {
|
||||
url += `?token=${token}`;
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
getAuthorThumbnailUrl(authorId: number, cacheBuster?: number): string {
|
||||
const token = this.authService.getInternalAccessToken();
|
||||
let url = `${this.mediaBaseUrl}/author/${authorId}/thumbnail`;
|
||||
if (token) {
|
||||
url += `?token=${token}`;
|
||||
}
|
||||
if (cacheBuster) {
|
||||
url += (token ? '&' : '?') + 't=' + cacheBuster;
|
||||
}
|
||||
return url;
|
||||
}
|
||||
}
|
||||
+258
@@ -0,0 +1,258 @@
|
||||
<ng-container *transloco="let t; prefix: 'book.addPhysicalBook'">
|
||||
<div class="add-physical-book">
|
||||
<div class="panel-header">
|
||||
<div class="header-icon-wrapper">
|
||||
<i class="pi pi-book header-icon"></i>
|
||||
</div>
|
||||
<div class="header-text">
|
||||
<h2 class="panel-title">{{ t('title') }}</h2>
|
||||
<p class="panel-description">{{ t('description') }}</p>
|
||||
</div>
|
||||
<p-button
|
||||
icon="pi pi-times"
|
||||
(click)="cancel()"
|
||||
severity="secondary"
|
||||
[text]="true"
|
||||
[rounded]="true"
|
||||
class="close-button"
|
||||
[pTooltip]="t('closeTooltip')"
|
||||
tooltipPosition="left"/>
|
||||
</div>
|
||||
|
||||
<div class="form-container">
|
||||
<div class="form-group highlight-group">
|
||||
<label for="library" class="form-label">
|
||||
<i class="pi pi-folder label-icon"></i>
|
||||
{{ t('libraryLabel') }}
|
||||
<span class="required-indicator">*</span>
|
||||
</label>
|
||||
<p-select
|
||||
id="library"
|
||||
[options]="libraries"
|
||||
[(ngModel)]="selectedLibraryId"
|
||||
optionLabel="name"
|
||||
optionValue="id"
|
||||
[placeholder]="t('libraryPlaceholder')"
|
||||
[style]="{'width': '100%'}"/>
|
||||
</div>
|
||||
|
||||
<div class="gradient-divider"></div>
|
||||
|
||||
<div class="top-section">
|
||||
@if (coverUrl) {
|
||||
<div class="cover-preview">
|
||||
<img [src]="coverUrl" alt="Book cover"/>
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="top-fields">
|
||||
<div class="form-row">
|
||||
<div class="form-group highlight-group flex-2">
|
||||
<label for="title" class="form-label">
|
||||
<i class="pi pi-tag label-icon"></i>
|
||||
{{ t('titleLabel') }}
|
||||
</label>
|
||||
<div class="input-wrapper">
|
||||
<input
|
||||
id="title"
|
||||
type="text"
|
||||
pInputText
|
||||
[(ngModel)]="title"
|
||||
class="input-full"
|
||||
[placeholder]="t('titlePlaceholder')"
|
||||
[class.filled]="title.trim()"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group highlight-group flex-1">
|
||||
<label for="isbn" class="form-label">
|
||||
<i class="pi pi-barcode label-icon"></i>
|
||||
{{ t('isbnLabel') }}
|
||||
</label>
|
||||
<div class="isbn-input-row">
|
||||
<input
|
||||
id="isbn"
|
||||
type="text"
|
||||
pInputText
|
||||
[(ngModel)]="isbn"
|
||||
class="input-full"
|
||||
[placeholder]="t('isbnPlaceholder')"/>
|
||||
<p-button
|
||||
icon="pi pi-search"
|
||||
[rounded]="true"
|
||||
[text]="true"
|
||||
severity="info"
|
||||
(onClick)="fetchMetadataByIsbn()"
|
||||
[disabled]="!isbn.trim() || isFetchingMetadata"
|
||||
[loading]="isFetchingMetadata"
|
||||
[pTooltip]="t('fetchMetadataTooltip')"
|
||||
tooltipPosition="top"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group highlight-group">
|
||||
<label for="authors" class="form-label">
|
||||
<i class="pi pi-user label-icon"></i>
|
||||
{{ t('authorsLabel') }}
|
||||
</label>
|
||||
<div class="autocomplete-wrapper">
|
||||
<p-autoComplete
|
||||
appendTo="body"
|
||||
[(ngModel)]="authors"
|
||||
[multiple]="true"
|
||||
[fluid]="true"
|
||||
[dropdown]="false"
|
||||
[suggestions]="filteredAuthors"
|
||||
[forceSelection]="false"
|
||||
[showClear]="false"
|
||||
[placeholder]="t('authorsPlaceholder')"
|
||||
(completeMethod)="filterAuthors($event)"
|
||||
(onKeyUp)="onAutoCompleteKeyUp('authors', $event)"
|
||||
(onSelect)="onAutoCompleteSelect('authors', $event)">
|
||||
</p-autoComplete>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="gradient-divider"></div>
|
||||
|
||||
<div class="form-group highlight-group">
|
||||
<label for="description" class="form-label">
|
||||
<i class="pi pi-align-left label-icon"></i>
|
||||
{{ t('descriptionLabel') }}
|
||||
</label>
|
||||
<textarea
|
||||
id="description"
|
||||
pTextarea
|
||||
[(ngModel)]="description"
|
||||
rows="3"
|
||||
[placeholder]="t('descriptionPlaceholder')"
|
||||
class="input-full"></textarea>
|
||||
</div>
|
||||
|
||||
<div class="gradient-divider"></div>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-group highlight-group flex-1">
|
||||
<label for="publisher" class="form-label">
|
||||
<i class="pi pi-building label-icon"></i>
|
||||
{{ t('publisherLabel') }}
|
||||
</label>
|
||||
<input
|
||||
id="publisher"
|
||||
type="text"
|
||||
pInputText
|
||||
[(ngModel)]="publisher"
|
||||
class="input-full"
|
||||
[placeholder]="t('publisherPlaceholder')"/>
|
||||
</div>
|
||||
|
||||
<div class="form-group highlight-group flex-1">
|
||||
<label for="publishedDate" class="form-label">
|
||||
<i class="pi pi-calendar label-icon"></i>
|
||||
{{ t('publishedDateLabel') }}
|
||||
</label>
|
||||
<input
|
||||
id="publishedDate"
|
||||
type="text"
|
||||
pInputText
|
||||
[(ngModel)]="publishedDate"
|
||||
class="input-full"
|
||||
[placeholder]="t('publishedDatePlaceholder')"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-group highlight-group flex-1">
|
||||
<label for="language" class="form-label">
|
||||
<i class="pi pi-globe label-icon"></i>
|
||||
{{ t('languageLabel') }}
|
||||
</label>
|
||||
<input
|
||||
id="language"
|
||||
type="text"
|
||||
pInputText
|
||||
[(ngModel)]="language"
|
||||
class="input-full"
|
||||
[placeholder]="t('languagePlaceholder')"/>
|
||||
</div>
|
||||
|
||||
<div class="form-group highlight-group flex-1">
|
||||
<label for="pageCount" class="form-label">
|
||||
<i class="pi pi-file label-icon"></i>
|
||||
{{ t('pageCountLabel') }}
|
||||
</label>
|
||||
<p-inputnumber
|
||||
id="pageCount"
|
||||
[(ngModel)]="pageCount"
|
||||
[useGrouping]="false"
|
||||
[placeholder]="t('pageCountPlaceholder')"
|
||||
class="input-full">
|
||||
</p-inputnumber>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="gradient-divider"></div>
|
||||
|
||||
<div class="form-group highlight-group">
|
||||
<label for="categories" class="form-label">
|
||||
<i class="pi pi-tags label-icon"></i>
|
||||
{{ t('categoriesLabel') }}
|
||||
</label>
|
||||
<div class="autocomplete-wrapper">
|
||||
<p-autoComplete
|
||||
appendTo="body"
|
||||
[(ngModel)]="categories"
|
||||
[multiple]="true"
|
||||
[fluid]="true"
|
||||
[dropdown]="false"
|
||||
[suggestions]="filteredCategories"
|
||||
[forceSelection]="false"
|
||||
[showClear]="true"
|
||||
[placeholder]="t('categoriesPlaceholder')"
|
||||
(completeMethod)="filterCategories($event)"
|
||||
(onKeyUp)="onAutoCompleteKeyUp('categories', $event)"
|
||||
(onSelect)="onAutoCompleteSelect('categories', $event)">
|
||||
</p-autoComplete>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="dialog-footer">
|
||||
<div class="validation-status">
|
||||
@if (!selectedLibraryId) {
|
||||
<div class="validation-message error">
|
||||
<i class="pi pi-exclamation-circle"></i>
|
||||
<span>{{ t('validationLibraryRequired') }}</span>
|
||||
</div>
|
||||
} @else if (!title.trim() && !isbn.trim()) {
|
||||
<div class="validation-message error">
|
||||
<i class="pi pi-exclamation-circle"></i>
|
||||
<span>{{ t('validationTitleOrIsbn') }}</span>
|
||||
</div>
|
||||
} @else {
|
||||
<div class="validation-message success">
|
||||
<i class="pi pi-check-circle"></i>
|
||||
<span>{{ t('validationReady') }}</span>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
<div class="footer-actions">
|
||||
<p-button
|
||||
[label]="t('cancelButton')"
|
||||
severity="secondary"
|
||||
[outlined]="true"
|
||||
(onClick)="cancel()"/>
|
||||
<p-button
|
||||
[label]="t('addButton')"
|
||||
icon="pi pi-plus"
|
||||
severity="success"
|
||||
(onClick)="createBook()"
|
||||
[disabled]="!canCreate() || isLoading"
|
||||
[loading]="isLoading"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
+202
@@ -0,0 +1,202 @@
|
||||
@use '../../../../shared/styles/panel-shared' as panel;
|
||||
|
||||
.add-physical-book {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-width: 700px;
|
||||
max-height: 90vh;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
min-width: auto;
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.panel-header {
|
||||
@include panel.panel-header;
|
||||
}
|
||||
|
||||
.form-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
padding: 1.25rem;
|
||||
background: var(--card-background);
|
||||
border: 1px solid var(--border-color);
|
||||
border-top: none;
|
||||
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
|
||||
overflow-y: auto;
|
||||
max-height: calc(90vh - 200px);
|
||||
|
||||
@media (max-width: 480px) {
|
||||
padding: 0.75rem;
|
||||
gap: 0.375rem;
|
||||
}
|
||||
}
|
||||
|
||||
.form-row {
|
||||
display: flex;
|
||||
gap: 0.75rem;
|
||||
|
||||
@media (max-width: 640px) {
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
.flex-1 {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.flex-2 {
|
||||
flex: 2;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.25rem;
|
||||
|
||||
&.highlight-group {
|
||||
padding: 0.5rem;
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
gap: 0.25rem;
|
||||
|
||||
&.highlight-group {
|
||||
padding: 0.375rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.form-label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.375rem;
|
||||
font-size: 0.9rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-color);
|
||||
|
||||
.label-icon {
|
||||
color: var(--primary-color);
|
||||
}
|
||||
|
||||
.required-indicator {
|
||||
color: var(--p-red-500);
|
||||
margin-left: 0.125rem;
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
}
|
||||
|
||||
.input-wrapper {
|
||||
position: relative;
|
||||
|
||||
.input-full {
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
}
|
||||
|
||||
.input-full {
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.isbn-input-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.25rem;
|
||||
|
||||
.input-full {
|
||||
flex: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.top-section {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
align-items: flex-start;
|
||||
|
||||
@media (max-width: 640px) {
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
}
|
||||
|
||||
.top-fields {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.cover-preview {
|
||||
flex-shrink: 0;
|
||||
padding: 0.5rem;
|
||||
|
||||
img {
|
||||
height: 180px;
|
||||
border-radius: 4px;
|
||||
border: 1px solid var(--border-color);
|
||||
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
|
||||
object-fit: contain;
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
img {
|
||||
height: 150px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.autocomplete-wrapper {
|
||||
width: 100%;
|
||||
|
||||
p-autocomplete {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.dialog-footer {
|
||||
@include panel.dialog-footer;
|
||||
border-top: none;
|
||||
}
|
||||
|
||||
.validation-message {
|
||||
@include panel.validation-message;
|
||||
}
|
||||
|
||||
::ng-deep {
|
||||
.p-inputnumber {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.p-inputnumber-input {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.p-autocomplete .p-chip .p-chip-label {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.p-autocomplete-input-chip {
|
||||
width: 2rem;
|
||||
}
|
||||
|
||||
.p-autocomplete-clearable ul {
|
||||
padding-inline-end: 2rem !important;
|
||||
}
|
||||
|
||||
.p-autocomplete-clearable .p-autocomplete-clear-icon {
|
||||
right: 0px;
|
||||
margin-top: -1rem;
|
||||
width: 2rem;
|
||||
height: 2rem;
|
||||
padding: 0.5rem;
|
||||
}
|
||||
}
|
||||
+179
@@ -0,0 +1,179 @@
|
||||
import {Component, computed, effect, inject} from '@angular/core';
|
||||
import {DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {Button} from 'primeng/button';
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {Select} from 'primeng/select';
|
||||
import {Textarea} from 'primeng/textarea';
|
||||
import {InputNumber} from 'primeng/inputnumber';
|
||||
import {AutoComplete, AutoCompleteCompleteEvent} from 'primeng/autocomplete';
|
||||
import {BookService} from '../../service/book.service';
|
||||
import {BookMetadataService} from '../../service/book-metadata.service';
|
||||
import {LibraryService} from '../../service/library.service';
|
||||
import {Library} from '../../model/library.model';
|
||||
import {CreatePhysicalBookRequest} from '../../model/book.model';
|
||||
import {TranslocoDirective} from '@jsverse/transloco';
|
||||
|
||||
@Component({
|
||||
selector: 'app-add-physical-book-dialog',
|
||||
standalone: true,
|
||||
templateUrl: './add-physical-book-dialog.component.html',
|
||||
imports: [
|
||||
FormsModule,
|
||||
Button,
|
||||
InputText,
|
||||
Tooltip,
|
||||
Select,
|
||||
Textarea,
|
||||
InputNumber,
|
||||
AutoComplete,
|
||||
TranslocoDirective
|
||||
],
|
||||
styleUrl: './add-physical-book-dialog.component.scss',
|
||||
})
|
||||
export class AddPhysicalBookDialogComponent {
|
||||
private dynamicDialogRef = inject(DynamicDialogRef);
|
||||
private dialogConfig = inject(DynamicDialogConfig);
|
||||
private bookService = inject(BookService);
|
||||
private bookMetadataService = inject(BookMetadataService);
|
||||
private libraryService = inject(LibraryService);
|
||||
|
||||
selectedLibraryId: number | null = null;
|
||||
title: string = '';
|
||||
isbn: string = '';
|
||||
authors: string[] = [];
|
||||
description: string = '';
|
||||
publisher: string = '';
|
||||
publishedDate: string = '';
|
||||
language: string = '';
|
||||
pageCount: number | null = null;
|
||||
categories: string[] = [];
|
||||
|
||||
private readonly metadata = computed(() => this.bookService.uniqueMetadata());
|
||||
get allAuthors(): string[] { return this.metadata().authors; }
|
||||
get allCategories(): string[] { return this.metadata().categories; }
|
||||
filteredAuthors: string[] = [];
|
||||
filteredCategories: string[] = [];
|
||||
|
||||
coverUrl: string | null = null;
|
||||
isLoading: boolean = false;
|
||||
isFetchingMetadata: boolean = false;
|
||||
private readonly initializeSelectedLibraryEffect = effect(() => {
|
||||
const libraries = this.libraries;
|
||||
if (libraries.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.dialogConfig.data?.libraryId) {
|
||||
this.selectedLibraryId = this.dialogConfig.data.libraryId;
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.selectedLibraryId == null && this.libraries[0].id !== undefined) {
|
||||
this.selectedLibraryId = this.libraries[0].id;
|
||||
}
|
||||
});
|
||||
|
||||
get libraries(): Library[] {
|
||||
return this.libraryService.libraries();
|
||||
}
|
||||
|
||||
filterAuthors(event: AutoCompleteCompleteEvent): void {
|
||||
const query = event.query.toLowerCase();
|
||||
this.filteredAuthors = this.allAuthors.filter((author) =>
|
||||
author.toLowerCase().includes(query)
|
||||
);
|
||||
}
|
||||
|
||||
filterCategories(event: AutoCompleteCompleteEvent): void {
|
||||
const query = event.query.toLowerCase();
|
||||
this.filteredCategories = this.allCategories.filter((category) =>
|
||||
category.toLowerCase().includes(query)
|
||||
);
|
||||
}
|
||||
|
||||
onAutoCompleteKeyUp(fieldName: 'authors' | 'categories', event: KeyboardEvent): void {
|
||||
if (event.key === 'Enter') {
|
||||
const input = event.target as HTMLInputElement;
|
||||
const value = input.value?.trim();
|
||||
if (value) {
|
||||
const values = this[fieldName];
|
||||
if (!values.includes(value)) {
|
||||
this[fieldName] = [...values, value];
|
||||
}
|
||||
input.value = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onAutoCompleteSelect(fieldName: 'authors' | 'categories', event: { value: string, originalEvent: Event }): void {
|
||||
const values = this[fieldName];
|
||||
if (!values.includes(event.value)) {
|
||||
this[fieldName] = [...values, event.value];
|
||||
}
|
||||
(event.originalEvent.target as HTMLInputElement).value = '';
|
||||
}
|
||||
|
||||
fetchMetadataByIsbn(): void {
|
||||
const isbnValue = this.isbn.trim();
|
||||
if (!isbnValue || this.isFetchingMetadata) return;
|
||||
|
||||
this.isFetchingMetadata = true;
|
||||
this.bookMetadataService.lookupByIsbn(isbnValue).subscribe({
|
||||
next: (metadata) => {
|
||||
if (metadata.title) this.title = metadata.title;
|
||||
if (metadata.authors?.length) this.authors = [...metadata.authors];
|
||||
if (metadata.description) this.description = metadata.description;
|
||||
if (metadata.publisher) this.publisher = metadata.publisher;
|
||||
if (metadata.publishedDate) this.publishedDate = metadata.publishedDate;
|
||||
if (metadata.language) this.language = metadata.language;
|
||||
if (metadata.pageCount) this.pageCount = metadata.pageCount;
|
||||
if (metadata.categories?.length) this.categories = [...metadata.categories];
|
||||
this.coverUrl = metadata.thumbnailUrl || null;
|
||||
this.isFetchingMetadata = false;
|
||||
},
|
||||
error: () => {
|
||||
this.isFetchingMetadata = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
cancel(): void {
|
||||
this.dynamicDialogRef.close();
|
||||
}
|
||||
|
||||
canCreate(): boolean {
|
||||
return !!this.selectedLibraryId && (!!this.title.trim() || !!this.isbn.trim());
|
||||
}
|
||||
|
||||
createBook(): void {
|
||||
if (!this.canCreate() || this.isLoading) return;
|
||||
|
||||
this.isLoading = true;
|
||||
|
||||
const request: CreatePhysicalBookRequest = {
|
||||
libraryId: this.selectedLibraryId!,
|
||||
title: this.title.trim() || undefined,
|
||||
isbn: this.isbn.trim() || undefined,
|
||||
authors: this.authors.length > 0 ? this.authors : undefined,
|
||||
description: this.description.trim() || undefined,
|
||||
publisher: this.publisher.trim() || undefined,
|
||||
publishedDate: this.publishedDate.trim() || undefined,
|
||||
language: this.language.trim() || undefined,
|
||||
pageCount: this.pageCount ?? undefined,
|
||||
categories: this.categories.length > 0 ? this.categories : undefined,
|
||||
thumbnailUrl: this.coverUrl || undefined
|
||||
};
|
||||
|
||||
this.bookService.createPhysicalBook(request).subscribe({
|
||||
next: (book) => {
|
||||
this.isLoading = false;
|
||||
this.dynamicDialogRef.close(book);
|
||||
},
|
||||
error: () => {
|
||||
this.isLoading = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
+141
@@ -0,0 +1,141 @@
|
||||
<ng-container *transloco="let t; prefix: 'book.fileUploader'">
|
||||
<div class="additional-file-uploader-container">
|
||||
<div class="panel-header">
|
||||
<div class="header-icon-wrapper">
|
||||
<i class="pi pi-file-plus header-icon"></i>
|
||||
</div>
|
||||
<div class="header-text">
|
||||
<h2 class="panel-title">{{ t('title') }}</h2>
|
||||
<p class="panel-description">{{ book.metadata?.title || t('unknownTitle') }}</p>
|
||||
</div>
|
||||
<p-button
|
||||
icon="pi pi-times"
|
||||
[rounded]="true"
|
||||
[text]="true"
|
||||
severity="secondary"
|
||||
(click)="closeDialog()"
|
||||
class="close-button">
|
||||
</p-button>
|
||||
</div>
|
||||
|
||||
<div class="dialog-content">
|
||||
<!-- File Type Selection -->
|
||||
<p-select
|
||||
[options]="fileTypeOptions"
|
||||
[(ngModel)]="fileType"
|
||||
(ngModelChange)="onFileTypeChange()"
|
||||
optionLabel="label"
|
||||
optionValue="value"
|
||||
[placeholder]="t('selectFileType')"
|
||||
class="full-width"
|
||||
[disabled]="isUploading"
|
||||
></p-select>
|
||||
|
||||
<!-- File Upload -->
|
||||
<p-fileupload class="file-upload" name="file"
|
||||
[customUpload]="true"
|
||||
[multiple]="false"
|
||||
[accept]="acceptedFormats"
|
||||
(onSelect)="onFilesSelect($event)"
|
||||
(uploadHandler)="uploadFiles($event)"
|
||||
[disabled]="isUploading">
|
||||
<ng-template #header let-files let-chooseCallback="chooseCallback" let-clearCallback="clearCallback" let-uploadCallback="uploadCallback">
|
||||
<div class="upload-header-actions">
|
||||
<div class="action-buttons">
|
||||
<p-button (onClick)="choose($event, chooseCallback)"
|
||||
icon="pi pi-images"
|
||||
[rounded]="true"
|
||||
[outlined]="true"
|
||||
[disabled]="isChooseDisabled()"/>
|
||||
<p-button (onClick)="uploadEvent(uploadCallback)"
|
||||
icon="pi pi-cloud-upload"
|
||||
[rounded]="true"
|
||||
[outlined]="true"
|
||||
severity="success"
|
||||
[disabled]="isUploadDisabled()"/>
|
||||
<p-button (onClick)="onClear(clearCallback)"
|
||||
icon="pi pi-times"
|
||||
[rounded]="true"
|
||||
[outlined]="true"
|
||||
severity="danger"
|
||||
[disabled]="!filesPresent() || isUploading"/>
|
||||
</div>
|
||||
</div>
|
||||
</ng-template>
|
||||
<ng-template #content let-files let-removeFileCallback="removeFileCallback">
|
||||
<div class="upload-content">
|
||||
@if (files?.length > 0) {
|
||||
<div>
|
||||
<div class="file-list-scroll">
|
||||
<div class="file-list">
|
||||
@for (uploadFile of this.files; track uploadFile; let i = $index) {
|
||||
<div class="file-row">
|
||||
<div class="file-info">
|
||||
<p-badge [value]="getFileStatusLabel(uploadFile)" [severity]="getBadgeSeverity(uploadFile.status)" class="file-badge"/>
|
||||
<span class="file-name">
|
||||
{{ uploadFile.file.name }}
|
||||
</span>
|
||||
<div class="file-size">{{ formatSize(uploadFile.file.size) }}</div>
|
||||
</div>
|
||||
@switch (uploadFile.status) {
|
||||
@case ('Pending') {
|
||||
<p-button
|
||||
icon="pi pi-times"
|
||||
(click)="onRemoveTemplatingFile($event, uploadFile.file, removeFileCallback, i)"
|
||||
severity="danger"
|
||||
[text]="true"/>
|
||||
}
|
||||
@case ('Uploading') {
|
||||
<i
|
||||
class="pi pi-spin pi-spinner status-icon"
|
||||
style="color: slateblue"
|
||||
[pTooltip]="t('statusUploading')"
|
||||
tooltipPosition="top">
|
||||
</i>
|
||||
}
|
||||
@case ('Uploaded') {
|
||||
<i
|
||||
class="pi pi-check status-icon"
|
||||
style="color: green"
|
||||
[pTooltip]="t('statusUploaded')"
|
||||
tooltipPosition="top">
|
||||
</i>
|
||||
}
|
||||
@case ('Failed') {
|
||||
<i
|
||||
class="pi pi-exclamation-triangle status-icon"
|
||||
style="color: darkred"
|
||||
[pTooltip]="uploadFile.errorMessage || t('statusUploadFailed')"
|
||||
tooltipPosition="top">
|
||||
</i>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</ng-template>
|
||||
<ng-template #file></ng-template>
|
||||
<ng-template #empty>
|
||||
<div class="empty-state">
|
||||
<i class="pi pi-cloud-upload empty-icon"></i>
|
||||
<p class="empty-text">{{ t('dragDropText') }}</p>
|
||||
<p class="empty-subtext">
|
||||
@if (fileType === AdditionalFileType.ALTERNATIVE_FORMAT) {
|
||||
<span [innerHTML]="t('supportedFormats')"></span>
|
||||
<br/>
|
||||
} @else {
|
||||
<span>{{ t('supplementaryAllFormats') }}</span>
|
||||
<br/>
|
||||
}
|
||||
{{ t('maxFileSize', { size: maxFileSizeDisplay }) }}
|
||||
</p>
|
||||
</div>
|
||||
</ng-template>
|
||||
</p-fileupload>
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
+140
@@ -0,0 +1,140 @@
|
||||
@use '../../../../shared/styles/panel-shared' as panel;
|
||||
|
||||
.additional-file-uploader-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.panel-header {
|
||||
@include panel.panel-header;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.dialog-content {
|
||||
flex: 1;
|
||||
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);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1.5rem;
|
||||
}
|
||||
|
||||
:host ::ng-deep {
|
||||
.p-fileupload-content p-progressbar {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.full-width {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.file-upload {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.upload-header-actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex: 1;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.action-buttons {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.upload-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2rem;
|
||||
padding: 0 1rem;
|
||||
}
|
||||
|
||||
.file-list-scroll {
|
||||
max-height: 24rem;
|
||||
max-width: 22rem;
|
||||
overflow-y: auto;
|
||||
padding-right: 0.5rem;
|
||||
|
||||
@media (min-width: 768px) {
|
||||
max-width: none;
|
||||
}
|
||||
}
|
||||
|
||||
.file-list {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.file-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.file-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
overflow: hidden;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.file-badge {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.file-name {
|
||||
font-weight: 600;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.file-size {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.status-icon {
|
||||
padding: 0.75rem;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-direction: column;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.empty-icon {
|
||||
border: 2px solid;
|
||||
border-radius: 9999px;
|
||||
padding: 2rem;
|
||||
font-size: 2.25rem;
|
||||
color: var(--p-text-muted-color);
|
||||
}
|
||||
|
||||
.empty-text {
|
||||
margin-top: 1.5rem;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.empty-subtext {
|
||||
margin-top: 0.5rem;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
+242
@@ -0,0 +1,242 @@
|
||||
import {ChangeDetectorRef, Component, effect, inject, OnDestroy, OnInit, ViewChild} from '@angular/core';
|
||||
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {Select} from 'primeng/select';
|
||||
import {Button} from 'primeng/button';
|
||||
import {FileSelectEvent, FileUpload, FileUploadHandlerEvent} from 'primeng/fileupload';
|
||||
import {Badge} from 'primeng/badge';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {Subject} from 'rxjs';
|
||||
import {BookFileService} from '../../service/book-file.service';
|
||||
import {AppSettingsService} from '../../../../shared/service/app-settings.service';
|
||||
import {AdditionalFileType, Book} from '../../model/book.model';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
interface FileTypeOption {
|
||||
label: string;
|
||||
value: AdditionalFileType;
|
||||
}
|
||||
|
||||
interface UploadingFile {
|
||||
file: File;
|
||||
status: 'Pending' | 'Uploading' | 'Uploaded' | 'Failed';
|
||||
errorMessage?: string;
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-additional-file-uploader',
|
||||
standalone: true,
|
||||
imports: [
|
||||
FormsModule,
|
||||
Select,
|
||||
Button,
|
||||
FileUpload,
|
||||
Badge,
|
||||
Tooltip,
|
||||
TranslocoDirective
|
||||
],
|
||||
templateUrl: './additional-file-uploader.component.html',
|
||||
styleUrls: ['./additional-file-uploader.component.scss']
|
||||
})
|
||||
export class AdditionalFileUploaderComponent implements OnInit, OnDestroy {
|
||||
private readonly t = inject(TranslocoService);
|
||||
|
||||
book!: Book;
|
||||
files: UploadingFile[] = [];
|
||||
fileType: AdditionalFileType = AdditionalFileType.ALTERNATIVE_FORMAT;
|
||||
isUploading = false;
|
||||
readonly AdditionalFileType = AdditionalFileType;
|
||||
private static readonly BOOK_FORMAT_ACCEPT = '.pdf,.epub,.cbz,.cbr,.cb7,.fb2,.mobi,.azw,.azw3,.m4b,.m4a,.mp3,.opus';
|
||||
maxFileSizeBytes?: number;
|
||||
maxFileSizeDisplay: string = '100 MB';
|
||||
|
||||
fileTypeOptions: FileTypeOption[] = [];
|
||||
|
||||
@ViewChild(FileUpload) private fileUpload!: FileUpload;
|
||||
private destroy$ = new Subject<void>();
|
||||
|
||||
constructor(
|
||||
private dialogRef: DynamicDialogRef,
|
||||
private config: DynamicDialogConfig,
|
||||
private bookFileService: BookFileService,
|
||||
private appSettingsService: AppSettingsService,
|
||||
private messageService: MessageService,
|
||||
private cdr: ChangeDetectorRef
|
||||
) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.book = this.config.data.book;
|
||||
this.fileTypeOptions = [
|
||||
{ label: this.t.translate('book.fileUploader.typeAlternativeFormat'), value: AdditionalFileType.ALTERNATIVE_FORMAT },
|
||||
{ label: this.t.translate('book.fileUploader.typeSupplementary'), value: AdditionalFileType.SUPPLEMENTARY }
|
||||
];
|
||||
const settings = this.appSettingsService.appSettings();
|
||||
if (settings) {
|
||||
const maxSizeMb = settings.maxFileUploadSizeInMb || 100;
|
||||
this.maxFileSizeBytes = maxSizeMb * 1024 * 1024;
|
||||
this.maxFileSizeDisplay = `${maxSizeMb} MB`;
|
||||
}
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
}
|
||||
|
||||
onFileTypeChange(): void {
|
||||
this.files = [];
|
||||
if (this.fileUpload) {
|
||||
this.fileUpload.clear();
|
||||
}
|
||||
}
|
||||
|
||||
get acceptedFormats(): string {
|
||||
return this.fileType === AdditionalFileType.ALTERNATIVE_FORMAT
|
||||
? AdditionalFileUploaderComponent.BOOK_FORMAT_ACCEPT
|
||||
: '';
|
||||
}
|
||||
|
||||
hasPendingFiles(): boolean {
|
||||
return this.files.some(f => f.status === 'Pending');
|
||||
}
|
||||
|
||||
filesPresent(): boolean {
|
||||
return this.files.length > 0;
|
||||
}
|
||||
|
||||
choose(_event: unknown, chooseCallback: () => void): void {
|
||||
chooseCallback();
|
||||
}
|
||||
|
||||
onClear(clearCallback: () => void): void {
|
||||
clearCallback();
|
||||
this.files = [];
|
||||
}
|
||||
|
||||
onFilesSelect(event: FileSelectEvent): void {
|
||||
const newFiles = event.currentFiles;
|
||||
// Only take the first file for single file upload
|
||||
if (newFiles.length > 0) {
|
||||
const file = newFiles[0];
|
||||
|
||||
if (this.maxFileSizeBytes && file.size > this.maxFileSizeBytes) {
|
||||
const maxSize = this.formatSize(this.maxFileSizeBytes);
|
||||
const errorMsg = this.t.translate('book.fileUploader.toast.fileTooLargeError', { maxSize });
|
||||
this.files = [{
|
||||
file,
|
||||
status: 'Failed',
|
||||
errorMessage: errorMsg
|
||||
}];
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('book.fileUploader.toast.fileTooLargeSummary'),
|
||||
detail: this.t.translate('book.fileUploader.toast.fileTooLargeDetail', { fileName: file.name, maxSize }),
|
||||
life: 5000
|
||||
});
|
||||
} else {
|
||||
this.files = [{
|
||||
file,
|
||||
status: 'Pending'
|
||||
}];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onRemoveTemplatingFile(_event: unknown, _file: File, removeFileCallback: (event: unknown, index: number) => void, index: number): void {
|
||||
removeFileCallback(_event, index);
|
||||
}
|
||||
|
||||
uploadEvent(uploadCallback: () => void): void {
|
||||
uploadCallback();
|
||||
}
|
||||
|
||||
uploadFiles(event: FileUploadHandlerEvent): void {
|
||||
const filesToUpload = this.files.filter(f => f.status === 'Pending');
|
||||
|
||||
if (filesToUpload.length === 0) return;
|
||||
|
||||
this.isUploading = true;
|
||||
let pending = filesToUpload.length;
|
||||
|
||||
for (const uploadFile of filesToUpload) {
|
||||
uploadFile.status = 'Uploading';
|
||||
|
||||
this.bookFileService.uploadAdditionalFile(
|
||||
this.book.id,
|
||||
uploadFile.file,
|
||||
this.fileType
|
||||
).subscribe({
|
||||
next: () => {
|
||||
uploadFile.status = 'Uploaded';
|
||||
if (--pending === 0) {
|
||||
this.isUploading = false;
|
||||
this.dialogRef.close({ success: true });
|
||||
}
|
||||
},
|
||||
error: (err) => {
|
||||
uploadFile.status = 'Failed';
|
||||
uploadFile.errorMessage = err?.error?.message || this.t.translate('book.fileUploader.toast.uploadFailedUnknown');
|
||||
console.error('Upload failed for', uploadFile.file.name, err);
|
||||
if (--pending === 0) {
|
||||
this.isUploading = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
isChooseDisabled(): boolean {
|
||||
return this.isUploading;
|
||||
}
|
||||
|
||||
isUploadDisabled(): boolean {
|
||||
return this.isChooseDisabled() || !this.filesPresent() || !this.hasPendingFiles();
|
||||
}
|
||||
|
||||
formatSize(bytes: number): string {
|
||||
const k = 1024;
|
||||
const dm = 2;
|
||||
if (bytes < k) return `${bytes} B`;
|
||||
if (bytes < k * k) return `${(bytes / k).toFixed(dm)} KB`;
|
||||
return `${(bytes / (k * k)).toFixed(dm)} MB`;
|
||||
}
|
||||
|
||||
getBadgeSeverity(status: UploadingFile['status']): 'info' | 'warn' | 'success' | 'danger' {
|
||||
switch (status) {
|
||||
case 'Pending':
|
||||
return 'warn';
|
||||
case 'Uploading':
|
||||
return 'info';
|
||||
case 'Uploaded':
|
||||
return 'success';
|
||||
case 'Failed':
|
||||
return 'danger';
|
||||
default:
|
||||
return 'info';
|
||||
}
|
||||
}
|
||||
|
||||
getFileStatusLabel(uploadFile: UploadingFile): string {
|
||||
if (uploadFile.status === 'Failed' && uploadFile.errorMessage?.includes('maximum size')) {
|
||||
return this.t.translate('book.fileUploader.statusTooLarge');
|
||||
}
|
||||
switch (uploadFile.status) {
|
||||
case 'Pending':
|
||||
return this.t.translate('book.fileUploader.statusReady');
|
||||
case 'Uploading':
|
||||
return this.t.translate('book.fileUploader.statusUploading');
|
||||
case 'Uploaded':
|
||||
return this.t.translate('book.fileUploader.statusUploaded');
|
||||
case 'Failed':
|
||||
return this.t.translate('book.fileUploader.statusFailed');
|
||||
default:
|
||||
return uploadFile.status;
|
||||
}
|
||||
}
|
||||
|
||||
closeDialog(): void {
|
||||
this.dialogRef.close();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
import {Injectable, inject} from '@angular/core';
|
||||
import {ParamMap} from '@angular/router';
|
||||
import {Library} from '../../model/library.model';
|
||||
import {Shelf} from '../../model/shelf.model';
|
||||
import {Book} from '../../model/book.model';
|
||||
import {LibraryService} from '../../service/library.service';
|
||||
import {ShelfService} from '../../service/shelf.service';
|
||||
import {MagicShelf, MagicShelfService} from '../../../magic-shelf/service/magic-shelf.service';
|
||||
import {BookRuleEvaluatorService} from '../../../magic-shelf/service/book-rule-evaluator.service';
|
||||
import {GroupRule} from '../../../magic-shelf/component/magic-shelf-component';
|
||||
import {EntityType} from './book-browser.component';
|
||||
|
||||
export interface EntityInfo {
|
||||
entityId: number;
|
||||
entityType: EntityType;
|
||||
}
|
||||
|
||||
@Injectable({providedIn: 'root'})
|
||||
export class BookBrowserEntityService {
|
||||
private libraryService = inject(LibraryService);
|
||||
private shelfService = inject(ShelfService);
|
||||
private magicShelfService = inject(MagicShelfService);
|
||||
private bookRuleEvaluatorService = inject(BookRuleEvaluatorService);
|
||||
|
||||
getEntityInfo(paramMap: ParamMap): EntityInfo {
|
||||
const libraryId = Number(paramMap.get('libraryId') || NaN);
|
||||
const shelfId = Number(paramMap.get('shelfId') || NaN);
|
||||
const magicShelfId = Number(paramMap.get('magicShelfId') || NaN);
|
||||
|
||||
if (!Number.isNaN(libraryId)) {
|
||||
return {entityId: libraryId, entityType: EntityType.LIBRARY};
|
||||
}
|
||||
|
||||
if (!Number.isNaN(shelfId)) {
|
||||
return {entityId: shelfId, entityType: EntityType.SHELF};
|
||||
}
|
||||
|
||||
if (!Number.isNaN(magicShelfId)) {
|
||||
return {entityId: magicShelfId, entityType: EntityType.MAGIC_SHELF};
|
||||
}
|
||||
|
||||
return {entityId: NaN, entityType: EntityType.ALL_BOOKS};
|
||||
}
|
||||
|
||||
getEntity(entityId: number, entityType: EntityType): Library | Shelf | MagicShelf | null {
|
||||
switch (entityType) {
|
||||
case EntityType.LIBRARY:
|
||||
return this.libraryService.libraries().find(lib => lib.id === entityId) ?? null;
|
||||
case EntityType.SHELF:
|
||||
return this.shelfService.shelves().find(shelf => shelf.id === entityId) ?? null;
|
||||
case EntityType.MAGIC_SHELF:
|
||||
return this.magicShelfService.findShelfById(entityId) ?? null;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
getBooksByEntity(books: Book[], entityId: number, entityType: EntityType): Book[] {
|
||||
switch (entityType) {
|
||||
case EntityType.LIBRARY:
|
||||
return books.filter(book => book.libraryId === entityId);
|
||||
case EntityType.SHELF:
|
||||
return books.filter(book => book.shelves?.some(shelf => shelf.id === entityId) ?? false);
|
||||
case EntityType.MAGIC_SHELF: {
|
||||
const magicShelf = this.getEntity(entityId, entityType);
|
||||
return this.isMagicShelf(magicShelf) ? this.filterByMagicShelf(books, magicShelf) : [];
|
||||
}
|
||||
case EntityType.UNSHELVED:
|
||||
return books.filter(book => !book.shelves || book.shelves.length === 0);
|
||||
case EntityType.ALL_BOOKS:
|
||||
default:
|
||||
return books;
|
||||
}
|
||||
}
|
||||
|
||||
isLibrary(entity: Library | Shelf | MagicShelf): entity is Library {
|
||||
return (entity as Library).paths !== undefined;
|
||||
}
|
||||
|
||||
isMagicShelf(entity: Library | Shelf | MagicShelf | null): entity is MagicShelf {
|
||||
return !!entity && 'filterJson' in entity;
|
||||
}
|
||||
|
||||
private filterByMagicShelf(books: Book[], magicShelf: MagicShelf): Book[] {
|
||||
if (!magicShelf.filterJson) {
|
||||
return [];
|
||||
}
|
||||
|
||||
try {
|
||||
const groupRule = JSON.parse(magicShelf.filterJson) as GroupRule;
|
||||
return books.filter(book => this.bookRuleEvaluatorService.evaluateGroup(book, groupRule, books));
|
||||
} catch {
|
||||
console.warn('Invalid filterJson for MagicShelf');
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
+306
@@ -0,0 +1,306 @@
|
||||
import {Injectable, inject} from '@angular/core';
|
||||
import {ActivatedRoute, ParamMap, Router} from '@angular/router';
|
||||
import {SortDirection, SortOption} from '../../model/sort.model';
|
||||
import {BookFilterMode, EntityViewPreference, EntityViewPreferences, SortCriterion} from '../../../settings/user-management/user.service';
|
||||
import {EntityType} from './book-browser.component';
|
||||
|
||||
export const QUERY_PARAMS = {
|
||||
VIEW: 'view',
|
||||
SORT: 'sort',
|
||||
DIRECTION: 'direction',
|
||||
FILTER: 'filter',
|
||||
FMODE: 'fmode',
|
||||
SIDEBAR: 'sidebar',
|
||||
FROM: 'from',
|
||||
} as const;
|
||||
|
||||
export const VIEW_MODES = {
|
||||
GRID: 'grid',
|
||||
TABLE: 'table',
|
||||
} as const;
|
||||
|
||||
export const SORT_DIRECTION = {
|
||||
ASCENDING: 'asc',
|
||||
DESCENDING: 'desc',
|
||||
} as const;
|
||||
|
||||
export interface BookBrowserQueryState {
|
||||
viewMode: 'grid' | 'table';
|
||||
sortField: string;
|
||||
sortDirection: SortDirection;
|
||||
filters: Record<string, string[]>;
|
||||
filterMode: BookFilterMode;
|
||||
}
|
||||
|
||||
export interface QueryParseResult {
|
||||
viewMode: string;
|
||||
sortOption: SortOption;
|
||||
sortCriteria: SortOption[];
|
||||
filters: Record<string, string[]>;
|
||||
filterMode: BookFilterMode;
|
||||
viewModeFromToggle: boolean;
|
||||
}
|
||||
|
||||
@Injectable({providedIn: 'root'})
|
||||
export class BookBrowserQueryParamsService {
|
||||
private router = inject(Router);
|
||||
private activatedRoute = inject(ActivatedRoute);
|
||||
|
||||
parseQueryParams(
|
||||
queryParamMap: ParamMap,
|
||||
userPrefs: EntityViewPreferences | undefined,
|
||||
entityType: EntityType | undefined,
|
||||
entityId: number | undefined,
|
||||
sortOptions: SortOption[],
|
||||
defaultFilterMode: BookFilterMode
|
||||
): QueryParseResult {
|
||||
const viewParam = queryParamMap.get(QUERY_PARAMS.VIEW);
|
||||
const sortParam = queryParamMap.get(QUERY_PARAMS.SORT);
|
||||
const directionParam = queryParamMap.get(QUERY_PARAMS.DIRECTION);
|
||||
const filterParams = queryParamMap.get(QUERY_PARAMS.FILTER);
|
||||
const filterModeParam = queryParamMap.get(QUERY_PARAMS.FMODE);
|
||||
const fromParam = queryParamMap.get(QUERY_PARAMS.FROM);
|
||||
|
||||
const filterMode = (filterModeParam || defaultFilterMode) as BookFilterMode;
|
||||
|
||||
// Parse filters
|
||||
const filters = this.deserializeFilters(filterParams);
|
||||
|
||||
// Determine effective preferences
|
||||
const globalPrefs = userPrefs?.global;
|
||||
const currentEntityTypeStr = entityType?.toString().toUpperCase().replaceAll(' ', '_');
|
||||
const override = userPrefs?.overrides?.find(o =>
|
||||
o.entityType?.toUpperCase() === currentEntityTypeStr &&
|
||||
o.entityId === entityId
|
||||
);
|
||||
|
||||
const effectivePrefs: EntityViewPreference = override?.preferences ?? globalPrefs ?? {
|
||||
sortKey: 'addedOn',
|
||||
sortDir: 'ASC',
|
||||
view: 'GRID',
|
||||
coverSize: 1.0,
|
||||
seriesCollapsed: false,
|
||||
overlayBookType: true
|
||||
};
|
||||
|
||||
// Parse sort criteria - supports both legacy and new multi-sort format
|
||||
let sortCriteria: SortOption[];
|
||||
|
||||
if (sortParam) {
|
||||
// Check if it's new multi-sort format (contains colons like "author:asc,title:desc")
|
||||
if (sortParam.includes(':')) {
|
||||
sortCriteria = this.deserializeSort(sortParam, sortOptions);
|
||||
} else {
|
||||
// Legacy format: separate sort and direction params
|
||||
const effectiveSortDir = directionParam
|
||||
? (directionParam.toLowerCase() === SORT_DIRECTION.DESCENDING ? SortDirection.DESCENDING : SortDirection.ASCENDING)
|
||||
: SortDirection.ASCENDING;
|
||||
const matchedSort = sortOptions.find(opt => opt.field === sortParam);
|
||||
sortCriteria = matchedSort ? [{
|
||||
label: matchedSort.label,
|
||||
field: matchedSort.field,
|
||||
direction: effectiveSortDir
|
||||
}] : [];
|
||||
}
|
||||
} else {
|
||||
// Use user preferences
|
||||
if (effectivePrefs.sortCriteria && effectivePrefs.sortCriteria.length > 0) {
|
||||
sortCriteria = effectivePrefs.sortCriteria.map((c: SortCriterion) => {
|
||||
const matchedSort = sortOptions.find(opt => opt.field === c.field);
|
||||
return {
|
||||
label: matchedSort?.label ?? c.field,
|
||||
field: c.field,
|
||||
direction: c.direction === 'DESC' ? SortDirection.DESCENDING : SortDirection.ASCENDING
|
||||
};
|
||||
});
|
||||
} else {
|
||||
// Fall back to legacy single sort preference
|
||||
const userSortKey = effectivePrefs.sortKey;
|
||||
const userSortDir = effectivePrefs.sortDir?.toUpperCase() === 'DESC'
|
||||
? SortDirection.DESCENDING
|
||||
: SortDirection.ASCENDING;
|
||||
const matchedSort = sortOptions.find(opt => opt.field === userSortKey);
|
||||
sortCriteria = matchedSort ? [{
|
||||
label: matchedSort.label,
|
||||
field: matchedSort.field,
|
||||
direction: userSortDir
|
||||
}] : [];
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure we have at least a default sort
|
||||
if (sortCriteria.length === 0) {
|
||||
sortCriteria = [{
|
||||
label: 'Added On',
|
||||
field: 'addedOn',
|
||||
direction: SortDirection.DESCENDING
|
||||
}];
|
||||
}
|
||||
|
||||
// For backward compatibility, expose the first sort as sortOption
|
||||
const sortOption = sortCriteria[0];
|
||||
|
||||
// Determine view mode
|
||||
const viewModeFromToggle = fromParam === 'toggle';
|
||||
const viewMode = viewModeFromToggle
|
||||
? (viewParam === VIEW_MODES.TABLE || viewParam === VIEW_MODES.GRID
|
||||
? viewParam
|
||||
: VIEW_MODES.GRID)
|
||||
: (effectivePrefs.view?.toLowerCase() ?? VIEW_MODES.GRID);
|
||||
|
||||
return {
|
||||
viewMode,
|
||||
sortOption,
|
||||
sortCriteria,
|
||||
filters,
|
||||
filterMode,
|
||||
viewModeFromToggle
|
||||
};
|
||||
}
|
||||
|
||||
updateViewMode(mode: 'grid' | 'table'): void {
|
||||
this.router.navigate([], {
|
||||
queryParams: {
|
||||
[QUERY_PARAMS.VIEW]: mode,
|
||||
[QUERY_PARAMS.FROM]: 'toggle'
|
||||
},
|
||||
queryParamsHandling: 'merge',
|
||||
replaceUrl: true
|
||||
});
|
||||
}
|
||||
|
||||
updateSort(sortOption: SortOption): void {
|
||||
this.updateMultiSort([sortOption]);
|
||||
}
|
||||
|
||||
updateMultiSort(sortCriteria: SortOption[]): void {
|
||||
const currentParams = this.activatedRoute.snapshot.queryParams;
|
||||
const newParams = {
|
||||
...currentParams,
|
||||
[QUERY_PARAMS.SORT]: this.serializeSort(sortCriteria),
|
||||
[QUERY_PARAMS.DIRECTION]: null // Remove legacy direction param
|
||||
};
|
||||
|
||||
this.router.navigate([], {
|
||||
queryParams: newParams,
|
||||
replaceUrl: true
|
||||
});
|
||||
}
|
||||
|
||||
serializeSort(criteria: SortOption[]): string {
|
||||
return criteria.map(c =>
|
||||
`${c.field}:${c.direction === SortDirection.ASCENDING ? 'asc' : 'desc'}`
|
||||
).join(',');
|
||||
}
|
||||
|
||||
deserializeSort(sortParam: string, sortOptions: SortOption[]): SortOption[] {
|
||||
const criteria: SortOption[] = [];
|
||||
|
||||
sortParam.split(',').forEach(part => {
|
||||
const [field, dir] = part.split(':');
|
||||
if (field) {
|
||||
const matchedSort = sortOptions.find(opt => opt.field === field);
|
||||
if (matchedSort) {
|
||||
criteria.push({
|
||||
label: matchedSort.label,
|
||||
field: matchedSort.field,
|
||||
direction: dir?.toLowerCase() === 'desc' ? SortDirection.DESCENDING : SortDirection.ASCENDING
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return criteria;
|
||||
}
|
||||
|
||||
updateFilters(filters: Record<string, string[]> | null): void {
|
||||
const queryParam = filters && Object.keys(filters).length > 0
|
||||
? this.serializeFilters(filters)
|
||||
: null;
|
||||
|
||||
if (queryParam !== this.activatedRoute.snapshot.queryParamMap.get(QUERY_PARAMS.FILTER)) {
|
||||
this.router.navigate([], {
|
||||
relativeTo: this.activatedRoute,
|
||||
queryParams: {[QUERY_PARAMS.FILTER]: queryParam},
|
||||
queryParamsHandling: 'merge',
|
||||
replaceUrl: false
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
updateFilterMode(mode: BookFilterMode, currentFilters: Record<string, string[]>): void {
|
||||
const params: Record<string, string | null> = {[QUERY_PARAMS.FMODE]: mode};
|
||||
|
||||
// Clear filters if switching from multiple selected to single mode
|
||||
if (mode === 'single') {
|
||||
const categories = Object.keys(currentFilters);
|
||||
if (categories.length > 1 || (categories.length === 1 && currentFilters[categories[0]].length > 1)) {
|
||||
params[QUERY_PARAMS.FILTER] = null;
|
||||
}
|
||||
}
|
||||
|
||||
this.router.navigate([], {
|
||||
relativeTo: this.activatedRoute,
|
||||
queryParams: params,
|
||||
queryParamsHandling: 'merge',
|
||||
replaceUrl: false
|
||||
});
|
||||
}
|
||||
|
||||
serializeFilters(filters: Record<string, string[]>): string {
|
||||
return Object.entries(filters)
|
||||
.map(([k, v]) => `${k}:${v.map(val => encodeURIComponent(val)).join('|')}`)
|
||||
.join(',');
|
||||
}
|
||||
|
||||
deserializeFilters(filterParam: string | null): Record<string, string[]> {
|
||||
const parsedFilters: Record<string, string[]> = {};
|
||||
|
||||
if (!filterParam) return parsedFilters;
|
||||
|
||||
filterParam.split(',').forEach(pair => {
|
||||
const [key, ...valueParts] = pair.split(':');
|
||||
const value = valueParts.join(':');
|
||||
if (key && value) {
|
||||
parsedFilters[key] = value.split('|').map(v => decodeURIComponent(v.trim())).filter(Boolean);
|
||||
}
|
||||
});
|
||||
|
||||
return parsedFilters;
|
||||
}
|
||||
|
||||
syncQueryParams(
|
||||
viewMode: string,
|
||||
filterMode: BookFilterMode,
|
||||
filters: Record<string, string[]>
|
||||
): void {
|
||||
const queryParams: Record<string, string | number | null | undefined> = {
|
||||
[QUERY_PARAMS.VIEW]: viewMode,
|
||||
[QUERY_PARAMS.FMODE]: filterMode,
|
||||
};
|
||||
|
||||
if (Object.keys(filters).length > 0) {
|
||||
queryParams[QUERY_PARAMS.FILTER] = this.serializeFilters(filters);
|
||||
}
|
||||
|
||||
const currentParams = this.activatedRoute.snapshot.queryParams;
|
||||
const changed = Object.keys(queryParams).some(k => (queryParams[k] ?? undefined) !== (currentParams[k] ?? undefined));
|
||||
|
||||
if (changed) {
|
||||
const mergedParams = {...currentParams, ...queryParams};
|
||||
this.router.navigate([], {
|
||||
queryParams: mergedParams,
|
||||
replaceUrl: true
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
shouldForceExpandSeries(queryParamMap: ParamMap): boolean {
|
||||
const filterParam = queryParamMap.get(QUERY_PARAMS.FILTER);
|
||||
return (
|
||||
!!filterParam &&
|
||||
typeof filterParam === 'string' &&
|
||||
filterParam.split(',').some(pair => pair.trim().startsWith('series:'))
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class BookBrowserScrollService {
|
||||
private scrollPositions = new Map<string, number>();
|
||||
|
||||
savePosition(key: string, position: number): void {
|
||||
this.scrollPositions.set(key, position);
|
||||
}
|
||||
|
||||
getPosition(key: string): number | undefined {
|
||||
return this.scrollPositions.get(key);
|
||||
}
|
||||
|
||||
clearPosition(key: string): void {
|
||||
this.scrollPositions.delete(key);
|
||||
}
|
||||
|
||||
createKey(path: string, params: Record<string, string>): string {
|
||||
const paramValues = Object.values(params).join('-');
|
||||
return paramValues ? `${path}:${paramValues}` : path;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,467 @@
|
||||
<ng-container *transloco="let t; prefix: 'book.browser'">
|
||||
<div class="book-browser-container">
|
||||
<div class="book-browser-main">
|
||||
|
||||
<div class="book-browser-header">
|
||||
<div class="entity-info-wrapper">
|
||||
@if (entityType(); as entityType) {
|
||||
<div class="entity-info">
|
||||
<p class="entity-title">
|
||||
@if (entityType === EntityType.ALL_BOOKS) {
|
||||
@if (currentFilterLabel && rawFilterParamFromUrl) {
|
||||
{{ currentFilterLabel }}
|
||||
} @else if (isFilterActive || hasSearchTerm) {
|
||||
{{ computedFilterLabel }}
|
||||
} @else {
|
||||
{{ t('labels.allBooks') }}
|
||||
}
|
||||
} @else if (entityType === EntityType.UNSHELVED) {
|
||||
{{ (isFilterActive || hasSearchTerm) ? t('labels.unshelvedBooksFiltered') : t('labels.unshelvedBooks') }}
|
||||
} @else {
|
||||
{{ entityType }}: {{ entity()?.name }}{{ (isFilterActive || hasSearchTerm) ? ' ' + t('labels.filteredSuffix') : '' }}
|
||||
}
|
||||
</p>
|
||||
@if (seriesCollapseFilter.seriesCollapsed() && books(); as books) {
|
||||
<p class="series-collapsed-info">
|
||||
{{ t('labels.seriesCollapsedInfo', { count: books.length, itemWord: books.length === 1 ? t('labels.item') : t('labels.items') }) }}
|
||||
</p>
|
||||
}
|
||||
</div>
|
||||
|
||||
@if (userService.currentUser(); as currentUser) {
|
||||
@if (entityType !== EntityType.ALL_BOOKS && entityType !== EntityType.UNSHELVED &&
|
||||
(currentUser.permissions.admin || currentUser.permissions.canManageLibrary)) {
|
||||
<div class="entity-menu-wrapper">
|
||||
<p-button
|
||||
icon="pi pi-ellipsis-v"
|
||||
[rounded]="true"
|
||||
[text]="true"
|
||||
severity="info"
|
||||
(click)="entitymenu.toggle($event)">
|
||||
</p-button>
|
||||
<p-menu #entitymenu [model]="entityOptions()" [popup]="true" appendTo="body"></p-menu>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
}
|
||||
</div>
|
||||
<div class="toolbar-actions">
|
||||
<div class="toolbar-icons">
|
||||
@if (isFilterActive) {
|
||||
<a class="topbar-items topbar-item" (click)="clearFilter()">
|
||||
<i
|
||||
class="pi pi-filter-slash filter-clear-icon"
|
||||
[pTooltip]="t('tooltip.clearFilters')"
|
||||
tooltipPosition="top">
|
||||
</i>
|
||||
</a>
|
||||
}
|
||||
|
||||
@if (currentViewMode === 'table') {
|
||||
<div>
|
||||
<a class="topbar-items topbar-item" (click)="columnPopover.toggle($event)">
|
||||
<i
|
||||
class="pi pi-eye"
|
||||
[pTooltip]="t('tooltip.visibleColumns')"
|
||||
tooltipPosition="top">
|
||||
</i>
|
||||
</a>
|
||||
<p-popover #columnPopover [dismissable]="true" appendTo="body">
|
||||
<div class="column-popover-content">
|
||||
<p-multiSelect
|
||||
optionLabel="header"
|
||||
[options]="columnPreferenceService.allColumns"
|
||||
[(ngModel)]="visibleColumns"
|
||||
(ngModelChange)="onVisibleColumnsChange($event)"
|
||||
display="chip"
|
||||
[placeholder]="t('placeholder.selectColumns')"
|
||||
[style]="{ width: '100%' }"
|
||||
[filter]="true"
|
||||
[showClear]="true"
|
||||
></p-multiSelect>
|
||||
</div>
|
||||
<div class="column-popover-footer">
|
||||
<p>{{ t('labels.setAsDefault') }}</p>
|
||||
<p-button
|
||||
[label]="t('labels.save')"
|
||||
outlined
|
||||
size="small"
|
||||
(click)="columnPreferenceService.saveVisibleColumns(visibleColumns)"></p-button>
|
||||
</div>
|
||||
</p-popover>
|
||||
</div>
|
||||
}
|
||||
<div>
|
||||
<a
|
||||
class="topbar-items topbar-item"
|
||||
(click)="seriesCollapseOverlay.toggle($event)"
|
||||
[pTooltip]="t('tooltip.displaySettings')"
|
||||
tooltipPosition="top">
|
||||
<i class="pi pi-cog"></i>
|
||||
</a>
|
||||
<p-popover #seriesCollapseOverlay [dismissable]="true" appendTo="body">
|
||||
<div class="display-settings-popover">
|
||||
<div class="display-settings-section">
|
||||
<div class="display-settings-checkbox-row">
|
||||
<p-checkbox
|
||||
inputId="collapse-series-checkbox"
|
||||
[binary]="true"
|
||||
[ngModel]="seriesCollapseFilter.seriesCollapsed()"
|
||||
(onChange)="onSeriesCollapseCheckboxChange($event.checked)">
|
||||
</p-checkbox>
|
||||
<label for="collapse-series-checkbox" class="display-settings-label">{{ t('labels.collapseSeries') }}</label>
|
||||
</div>
|
||||
</div>
|
||||
@if (isMobile) {
|
||||
<div class="display-settings-section">
|
||||
<label class="display-settings-label">{{ t('labels.gridColumns') }}</label>
|
||||
<div class="column-options">
|
||||
<button
|
||||
type="button"
|
||||
class="column-option-btn"
|
||||
[class.active]="mobileColumnCount === 2"
|
||||
(click)="setMobileColumns(2)">2</button>
|
||||
<button
|
||||
type="button"
|
||||
class="column-option-btn"
|
||||
[class.active]="mobileColumnCount === 3"
|
||||
(click)="setMobileColumns(3)">3</button>
|
||||
<button
|
||||
type="button"
|
||||
class="column-option-btn"
|
||||
[class.active]="mobileColumnCount === 4"
|
||||
(click)="setMobileColumns(4)">4</button>
|
||||
</div>
|
||||
</div>
|
||||
} @else {
|
||||
<div class="display-settings-section">
|
||||
<label class="display-settings-label">{{ t('labels.gridItemSize') }}</label>
|
||||
<p-slider
|
||||
[ngModel]="coverScalePreferenceService.scaleFactor()"
|
||||
(ngModelChange)="coverScalePreferenceService.setScale($event)"
|
||||
[min]="0.5"
|
||||
[max]="1.5"
|
||||
[step]="0.01"
|
||||
[style]="{ width: '100%' }">
|
||||
</p-slider>
|
||||
<div class="scale-value-display">
|
||||
{{ coverScalePreferenceService.scaleFactor().toFixed(2) }}x
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
<div class="display-settings-section">
|
||||
<div class="display-settings-checkbox-row">
|
||||
<p-checkbox
|
||||
inputId="show-book-type-pill-checkbox"
|
||||
[binary]="true"
|
||||
[ngModel]="bookCardOverlayPreferenceService.showBookTypePill()"
|
||||
(onChange)="bookCardOverlayPreferenceService.setShowBookTypePill($event.checked)">
|
||||
</p-checkbox>
|
||||
<label for="show-book-type-pill-checkbox" class="display-settings-label">{{ t('labels.bookTypeOverlay') }}</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</p-popover>
|
||||
</div>
|
||||
|
||||
<div class="sort-button-wrapper">
|
||||
<a class="topbar-items topbar-item" (click)="sortPopover.toggle($event)">
|
||||
<i
|
||||
class="pi pi-sort"
|
||||
[pTooltip]="t('tooltip.selectSorting')"
|
||||
tooltipPosition="top">
|
||||
</i>
|
||||
@if (sortCriteriaCount > 1) {
|
||||
<p-badge [value]="sortCriteriaCount.toString()" class="sort-badge"/>
|
||||
}
|
||||
</a>
|
||||
<p-popover #sortPopover [dismissable]="true" appendTo="body">
|
||||
<app-multi-sort-popover
|
||||
[sortCriteria]="this.bookSorter.selectedSortCriteria"
|
||||
[availableSortOptions]="visibleSortOptions"
|
||||
[showSaveButton]="canSaveSort"
|
||||
(criteriaChange)="onSortCriteriaChange($event)"
|
||||
(saveSortConfig)="onSaveSortConfig($event)">
|
||||
</app-multi-sort-popover>
|
||||
</p-popover>
|
||||
</div>
|
||||
|
||||
<a class="topbar-items topbar-item" (click)="toggleTableGrid()">
|
||||
<i
|
||||
[ngClass]="viewIcon"
|
||||
[pTooltip]="t('tooltip.toggleView')"
|
||||
tooltipPosition="top">
|
||||
</i>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<!-- MOBILE SEARCH (only visible below md) -->
|
||||
<div class="mobile-search-wrapper">
|
||||
<button
|
||||
type="button"
|
||||
class="topbar-items topbar-item"
|
||||
(click)="searchDropdown.toggle($event)"
|
||||
[pTooltip]="t('tooltip.search')"
|
||||
tooltipPosition="top"
|
||||
>
|
||||
<i class="pi pi-search"></i>
|
||||
</button>
|
||||
|
||||
<p-popover #searchDropdown [dismissable]="true" appendTo="body" [style]="{ width: '24rem' }">
|
||||
<div class="search-popover-content">
|
||||
<input
|
||||
type="text"
|
||||
pInputText
|
||||
[placeholder]="t('placeholder.search')"
|
||||
[(ngModel)]="bookTitle"
|
||||
(ngModelChange)="onSearchTermChange($event)"
|
||||
class="search-input-full"
|
||||
/>
|
||||
<p-button
|
||||
icon="pi pi-times"
|
||||
[text]="true"
|
||||
size="small"
|
||||
[rounded]="true"
|
||||
class="search-clear-btn"
|
||||
(click)="clearSearch(); searchDropdown.hide()"
|
||||
></p-button>
|
||||
</div>
|
||||
</p-popover>
|
||||
</div>
|
||||
|
||||
<div class="desktop-search-wrapper">
|
||||
<i class="pi pi-search search-icon"></i>
|
||||
<input
|
||||
type="text"
|
||||
pInputText
|
||||
[placeholder]="t('placeholder.search')"
|
||||
[(ngModel)]="bookTitle"
|
||||
(ngModelChange)="onSearchTermChange($event)"
|
||||
class="search-input"
|
||||
/>
|
||||
@if (bookTitle) {
|
||||
<p-button
|
||||
icon="pi pi-times"
|
||||
[text]="true"
|
||||
size="small"
|
||||
[rounded]="true"
|
||||
class="search-clear-btn"
|
||||
(click)="clearSearch()"
|
||||
></p-button>
|
||||
}
|
||||
</div>
|
||||
|
||||
<a class="topbar-items topbar-item" (click)="toggleSidebar()">
|
||||
<i
|
||||
[ngClass]="showFilter() ? 'pi pi-angle-double-right' : 'pi pi-angle-double-left'"
|
||||
[pTooltip]="t('tooltip.toggleSidebar')"
|
||||
tooltipPosition="top">
|
||||
</i>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (books(); as books) {
|
||||
<div>
|
||||
@if (isBooksLoading()) {
|
||||
<div>
|
||||
<p-progressSpinner></p-progressSpinner>
|
||||
</div>
|
||||
}
|
||||
<div class="book-state-wrapper">
|
||||
@if (booksError()) {
|
||||
<div class="no-books-container">
|
||||
<p class="no-books-text">
|
||||
{{ entityType() === EntityType.LIBRARY ? t('labels.failedLibrary') : t('labels.failedShelf') }}
|
||||
</p>
|
||||
</div>
|
||||
} @else if (!isBooksLoading() && books.length === 0) {
|
||||
<div class="no-books-container">
|
||||
<p class="no-books-text">
|
||||
{{ t('labels.noBooks') }}
|
||||
</p>
|
||||
</div>
|
||||
}
|
||||
@if (currentViewMode === 'table' && books.length > 0) {
|
||||
<app-book-table
|
||||
[books]="books"
|
||||
[preselectedBookIds]="selectedBooks()"
|
||||
(selectedBooksChange)="onSelectedBooksChange($event)"
|
||||
[sortOption]="this.bookSorter.selectedSort!"
|
||||
[visibleColumns]="visibleColumns"
|
||||
></app-book-table>
|
||||
}
|
||||
@if (currentViewMode === 'grid') {
|
||||
<virtual-scroller class="virtual-scroller" #scroll [items]="books">
|
||||
<div
|
||||
class="grid"
|
||||
#container
|
||||
[ngStyle]="{'grid-template-columns': 'repeat(auto-fill, minmax(' + gridColumnMinWidth + ', 1fr))'}">
|
||||
@for (book of scroll.viewPortItems; let i = $index; track book.id) {
|
||||
<div
|
||||
class="virtual-scroller-item"
|
||||
[ngStyle]="{width: currentCardSize.width + 'px', height: getCardHeight(book) + 'px'}">
|
||||
<app-book-card
|
||||
[index]="books.indexOf(book)"
|
||||
[book]="book"
|
||||
[isCheckboxEnabled]="true"
|
||||
[seriesViewEnabled]="seriesViewEnabled"
|
||||
[onBookSelect]="handleBookSelect.bind(this)"
|
||||
[isSeriesCollapsed]="seriesCollapseFilter.seriesCollapsed()"
|
||||
(checkboxClick)="onCheckboxClicked($event)"
|
||||
[isSelected]="selectedBooks().has(book.id)"
|
||||
[useSquareCovers]="isAudiobookOnlyLibrary"
|
||||
[overlayPreferenceService]="bookCardOverlayPreferenceService">
|
||||
</app-book-card>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</virtual-scroller>
|
||||
}
|
||||
@if (userService.currentUser(); as currentUser) {
|
||||
<div class="book-browser-footer" [class.footer-hidden]="selectedCount() === 0">
|
||||
<div class="footer-content">
|
||||
<div class="footer-left">
|
||||
<div class="selected-count-badge">
|
||||
<i class="pi pi-check-circle"></i>
|
||||
<span class="selected-count">{{ selectedCount() }}</span>
|
||||
<span class="selected-label">{{ t('labels.selected') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="footer-center">
|
||||
@if (entityType(); as entityType) {
|
||||
<div class="action-buttons-group">
|
||||
@if (hasMetadataMenuItems) {
|
||||
<p-tieredMenu #menu [model]="metadataMenuItems" [popup]="true" appendTo="body" styleClass="footer-menu"/>
|
||||
<p-button
|
||||
(click)="menu.toggle($event)"
|
||||
[pTooltip]="t('tooltip.metadataActions')"
|
||||
tooltipPosition="top"
|
||||
outlined="true"
|
||||
severity="info"
|
||||
icon="pi pi-database">
|
||||
</p-button>
|
||||
}
|
||||
<p-button
|
||||
icon="pi pi-bookmark-fill"
|
||||
outlined="true"
|
||||
severity="info"
|
||||
(onClick)="openShelfAssigner()"
|
||||
[pTooltip]="t('tooltip.assignToShelf')"
|
||||
tooltipPosition="top">
|
||||
</p-button>
|
||||
@if (entityType === EntityType.SHELF) {
|
||||
<p-button
|
||||
icon="pi pi-bookmark"
|
||||
outlined="true"
|
||||
severity="info"
|
||||
(click)="unshelfBooks()"
|
||||
[pTooltip]="t('tooltip.removeFromShelf')"
|
||||
tooltipPosition="top">
|
||||
</p-button>
|
||||
}
|
||||
@if (currentUser.permissions.canBulkLockUnlockMetadata) {
|
||||
<p-button
|
||||
outlined="true"
|
||||
icon="pi pi-lock"
|
||||
severity="info"
|
||||
(click)="lockUnlockMetadata()"
|
||||
[pTooltip]="t('tooltip.lockUnlockMetadata')"
|
||||
tooltipPosition="top">
|
||||
</p-button>
|
||||
}
|
||||
@if (currentUser.permissions.canMoveOrganizeFiles && appSettingsService.appSettings()?.diskType === 'LOCAL') {
|
||||
<p-button
|
||||
outlined="true"
|
||||
icon="pi pi-arrows-h"
|
||||
severity="info"
|
||||
(click)="moveFiles()"
|
||||
[pTooltip]="t('tooltip.organizeFiles')"
|
||||
tooltipPosition="top">
|
||||
</p-button>
|
||||
}
|
||||
@if (currentUser.permissions.canManageLibrary || currentUser.permissions.admin) {
|
||||
<p-button
|
||||
outlined="true"
|
||||
icon="pi pi-link"
|
||||
severity="info"
|
||||
(click)="attachFilesToBook()"
|
||||
[disabled]="!canAttachFiles()"
|
||||
[pTooltip]="t('tooltip.attachToBook')"
|
||||
tooltipPosition="top">
|
||||
</p-button>
|
||||
}
|
||||
@if (hasMoreActionsItems) {
|
||||
<div class="more-actions-wrapper">
|
||||
<p-button
|
||||
(click)="menu.toggle($event)"
|
||||
[pTooltip]="t('tooltip.moreActions')"
|
||||
tooltipPosition="top"
|
||||
outlined="true"
|
||||
severity="info"
|
||||
icon="pi pi-ellipsis-v">
|
||||
</p-button>
|
||||
<p-tieredMenu #menu [model]="moreActionsMenuItems" [popup]="true" appendTo="body" styleClass="footer-menu"/>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
<p-divider layout="vertical"></p-divider>
|
||||
<div class="action-buttons-group">
|
||||
<p-button
|
||||
outlined="true"
|
||||
icon="pi pi-check-square"
|
||||
severity="success"
|
||||
(click)="selectAllBooks()"
|
||||
[pTooltip]="t('tooltip.selectAll')"
|
||||
tooltipPosition="top">
|
||||
</p-button>
|
||||
<p-button
|
||||
outlined="true"
|
||||
icon="pi pi-times"
|
||||
severity="warn"
|
||||
(click)="deselectAllBooks()"
|
||||
[pTooltip]="t('tooltip.deselectAll')"
|
||||
tooltipPosition="top">
|
||||
</p-button>
|
||||
</div>
|
||||
@if (currentUser?.permissions?.admin || currentUser?.permissions?.canDeleteBook) {
|
||||
<p-divider layout="vertical"></p-divider>
|
||||
<p-button
|
||||
outlined="true"
|
||||
icon="pi pi-trash"
|
||||
severity="danger"
|
||||
(click)="confirmDeleteBooks()"
|
||||
[pTooltip]="t('tooltip.deleteSelected')"
|
||||
tooltipPosition="top">
|
||||
</p-button>
|
||||
}
|
||||
</div>
|
||||
<div class="footer-right"></div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@if (showFilter()) {
|
||||
<div
|
||||
class="mobile-filter-mask"
|
||||
(click)="toggleSidebar()">
|
||||
</div>
|
||||
<app-book-filter
|
||||
[showFilter]="showFilter()"
|
||||
class="filter-overlay-container"
|
||||
[ngClass]="{ 'active': showFilter() }"
|
||||
[entity]="entity()"
|
||||
[entityType]="entityType()"
|
||||
[resetFilter$]="resetFilterSubject"
|
||||
(filterSelected)="onFilterSelected($event)"
|
||||
(filterModeChanged)="onFilterModeChanged($event)">
|
||||
</app-book-filter>
|
||||
}
|
||||
|
||||
</div>
|
||||
</ng-container>
|
||||
@@ -0,0 +1,536 @@
|
||||
// Layout containers
|
||||
.book-browser-container {
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
}
|
||||
|
||||
.book-browser-main {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
// Header bar
|
||||
.book-browser-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
width: 100%;
|
||||
gap: 0.25rem;
|
||||
padding: 0.35rem 0.35rem;
|
||||
border-radius: 0.75rem 0.75rem 0 0;
|
||||
margin-bottom: 0.5rem;
|
||||
background-color: var(--card-background);
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
|
||||
@media (min-width: 768px) {
|
||||
gap: 1rem;
|
||||
padding: 0.5rem 1rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
// Entity info section
|
||||
.entity-info-wrapper {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
min-width: 0;
|
||||
flex-shrink: 1;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.entity-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.125rem;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
|
||||
@media (max-width: 767px) {
|
||||
gap: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.entity-title {
|
||||
font-size: 1.25rem;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
margin: 0;
|
||||
|
||||
@media (max-width: 767px) {
|
||||
font-size: 1rem;
|
||||
padding-left: 0.25rem;
|
||||
}
|
||||
}
|
||||
|
||||
.series-collapsed-info {
|
||||
font-size: 0.875rem;
|
||||
color: #6b7280;
|
||||
margin: 0;
|
||||
|
||||
@media (max-width: 767px) {
|
||||
display: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
height: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.entity-menu-wrapper {
|
||||
margin-left: 0.5rem;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
// Toolbar actions
|
||||
.toolbar-actions {
|
||||
display: flex;
|
||||
flex-wrap: nowrap;
|
||||
align-items: center;
|
||||
gap: 0.25rem;
|
||||
flex-shrink: 0;
|
||||
|
||||
@media (min-width: 768px) {
|
||||
gap: 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
.toolbar-icons {
|
||||
display: flex;
|
||||
flex-wrap: nowrap;
|
||||
align-items: center;
|
||||
gap: 0.25rem;
|
||||
|
||||
@media (min-width: 768px) {
|
||||
gap: 1.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
// Icon with orange color for filter
|
||||
.filter-clear-icon {
|
||||
color: orange;
|
||||
}
|
||||
|
||||
// Popover content containers
|
||||
.column-popover-content {
|
||||
width: 200px;
|
||||
}
|
||||
|
||||
.column-popover-footer {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
padding-top: 1rem;
|
||||
padding-left: 0.25rem;
|
||||
}
|
||||
|
||||
.display-settings-popover {
|
||||
width: 220px;
|
||||
padding: 0.5rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.display-settings-section {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.display-settings-checkbox-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.display-settings-label {
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.scale-value-display {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.column-options {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.column-option-btn {
|
||||
flex: 1;
|
||||
padding: 0.25rem 0.5rem;
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
border-radius: 6px;
|
||||
background-color: var(--card-background);
|
||||
color: var(--text-color);
|
||||
font-size: 1rem;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: all 0.15s ease;
|
||||
|
||||
&:hover {
|
||||
border-color: var(--primary-color);
|
||||
}
|
||||
|
||||
&.active {
|
||||
background-color: var(--primary-color);
|
||||
border-color: var(--primary-color);
|
||||
color: var(--primary-color-text);
|
||||
}
|
||||
}
|
||||
|
||||
// Sort button wrapper
|
||||
.sort-button-wrapper {
|
||||
position: relative;
|
||||
|
||||
.sort-badge {
|
||||
position: absolute;
|
||||
top: -6px;
|
||||
right: -6px;
|
||||
}
|
||||
}
|
||||
|
||||
// Sort menu item (kept for backward compat)
|
||||
.sort-menu-item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 0.5rem 1rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
// Search section
|
||||
.mobile-search-wrapper {
|
||||
position: relative;
|
||||
|
||||
@media (min-width: 768px) {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
.desktop-search-wrapper {
|
||||
display: none;
|
||||
position: relative;
|
||||
|
||||
@media (min-width: 768px) {
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
|
||||
.search-popover-content {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.search-input-full {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.search-clear-btn {
|
||||
position: absolute;
|
||||
right: 0.5rem;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
}
|
||||
|
||||
// Footer bar
|
||||
.book-browser-footer {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 10%;
|
||||
right: 10%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
overflow: hidden;
|
||||
padding: 1rem 0.5rem 0.5rem;
|
||||
z-index: 1;
|
||||
border-radius: 10px 10px 0 0;
|
||||
border: 1px solid rgba(255, 255, 255, 0.5);
|
||||
border-width: 1px 1px 0 1px;
|
||||
background-color: var(--card-background);
|
||||
transition: transform 0.15s ease-out, opacity 0.15s ease-out;
|
||||
transform: translateY(0);
|
||||
opacity: 1;
|
||||
|
||||
&.footer-hidden {
|
||||
transform: translateY(100%);
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
left: 0;
|
||||
right: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.footer-content {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
min-width: 0;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.footer-left {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding-left: 0.5rem;
|
||||
flex-shrink: 0;
|
||||
width: 120px;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
width: auto;
|
||||
}
|
||||
}
|
||||
|
||||
.footer-center {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
overflow-x: auto;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
scrollbar-width: none;
|
||||
mask-image: linear-gradient(to right, transparent 0, black 12px, black calc(100% - 32px), transparent 100%);
|
||||
-webkit-mask-image: linear-gradient(to right, transparent 0, black 12px, black calc(100% - 32px), transparent 100%);
|
||||
padding: 0 16px;
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
display: none;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
justify-content: flex-start;
|
||||
}
|
||||
}
|
||||
|
||||
.footer-right {
|
||||
flex-shrink: 0;
|
||||
width: 120px;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
.selected-count-badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
padding: 0.5rem 1rem;
|
||||
font-size: 0.9rem;
|
||||
color: #e4e4e7;
|
||||
|
||||
i {
|
||||
font-size: 1rem;
|
||||
margin-right: 0.5rem;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
padding: 0.4rem 0.8rem;
|
||||
font-size: 0.85rem;
|
||||
|
||||
i {
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.selected-count {
|
||||
font-weight: 700;
|
||||
font-size: 1rem;
|
||||
color: var(--primary-color);
|
||||
}
|
||||
|
||||
.selected-label {
|
||||
margin-left: 0.25rem;
|
||||
}
|
||||
|
||||
.action-buttons-group {
|
||||
display: flex;
|
||||
flex-shrink: 0;
|
||||
gap: 0.5rem;
|
||||
|
||||
@media (min-width: 768px) {
|
||||
gap: 1.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
.more-actions-wrapper {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
// Virtual scroller and grid
|
||||
.virtual-scroller {
|
||||
width: 100%;
|
||||
height: calc(100dvh - 10.9rem);
|
||||
padding: 1rem;
|
||||
box-sizing: border-box;
|
||||
overflow-y: auto;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
height: calc(100dvh - 9rem);
|
||||
}
|
||||
}
|
||||
|
||||
.grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(1px, 1fr));
|
||||
gap: 1.3rem;
|
||||
align-items: start;
|
||||
width: 100%;
|
||||
|
||||
// Mobile: fixed 2 or 3 columns based on phone width
|
||||
@media (max-width: 767px) {
|
||||
gap: 0.5rem;
|
||||
padding: 0 0.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
.virtual-scroller-item {
|
||||
position: relative;
|
||||
transition: width 0.2s ease, height 0.2s ease;
|
||||
}
|
||||
|
||||
// No books state
|
||||
.no-books-container {
|
||||
padding-top: 3rem;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.no-books-text {
|
||||
font-size: 1rem;
|
||||
font-weight: 500;
|
||||
color: var(--text-color);
|
||||
background: var(--card-background);
|
||||
padding: 0.75rem 1rem;
|
||||
border-radius: 0.5rem;
|
||||
}
|
||||
|
||||
// Topbar items (icon buttons)
|
||||
.topbar-item {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-shrink: 0;
|
||||
border: 1px solid var(--border-color);
|
||||
width: 2.5rem;
|
||||
height: 2.5rem;
|
||||
transition: outline-color 0.2s, border-color 0.2s;
|
||||
border-radius: 6px;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
outline-color: transparent;
|
||||
background-color: var(--card-background);
|
||||
cursor: pointer;
|
||||
|
||||
@media (max-width: 767px) {
|
||||
width: 2rem;
|
||||
height: 2rem;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
border-color: var(--primary-color);
|
||||
}
|
||||
|
||||
i, span {
|
||||
color: var(--primary-color);
|
||||
font-size: 1.25rem;
|
||||
font-weight: 100;
|
||||
|
||||
@media (max-width: 767px) {
|
||||
font-size: 1rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Search input styling
|
||||
.search-icon {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 10px;
|
||||
transform: translateY(-50%);
|
||||
color: var(--text-secondary-color);
|
||||
font-size: 1rem;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.search-input {
|
||||
min-width: 22rem;
|
||||
padding-left: 30px;
|
||||
height: 2.5rem;
|
||||
line-height: 2.5rem;
|
||||
font-size: 1rem;
|
||||
box-sizing: border-box;
|
||||
|
||||
@media (max-width: 767px) {
|
||||
min-width: 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Filter overlay (mobile sidebar)
|
||||
.mobile-filter-mask {
|
||||
@media (max-width: 991px) {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
z-index: 998;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: rgba(0, 0, 0, 0.4);
|
||||
}
|
||||
}
|
||||
|
||||
.filter-overlay-container {
|
||||
flex-shrink: 0;
|
||||
z-index: 50;
|
||||
|
||||
@media (max-width: 991px) {
|
||||
width: var(--sidebar-width, 225px);
|
||||
position: fixed;
|
||||
top: 3.85rem;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
height: calc(100% - 3.85rem);
|
||||
background-color: var(--card-background);
|
||||
box-shadow: -2px 0 10px rgba(0, 0, 0, 0.15);
|
||||
transform: translateX(100%);
|
||||
transition: transform 0.3s ease;
|
||||
z-index: 1001;
|
||||
|
||||
&.active {
|
||||
transform: translateX(0);
|
||||
margin-left: 0;
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 992px) {
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
flex-shrink: 0;
|
||||
|
||||
&:not(.active) {
|
||||
width: 0 !important;
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
margin-left: 0;
|
||||
}
|
||||
|
||||
&.active {
|
||||
width: var(--sidebar-width, 225px);
|
||||
opacity: 1;
|
||||
pointer-events: auto;
|
||||
margin-left: 1rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Book state container
|
||||
.book-state-wrapper {
|
||||
position: relative;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
+115
@@ -0,0 +1,115 @@
|
||||
import {effect, inject, Injectable, signal} from '@angular/core';
|
||||
import {UserService} from '../../../settings/user-management/user.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class BookCardOverlayPreferenceService {
|
||||
private static readonly PERSIST_DELAY_MS = 500;
|
||||
|
||||
private readonly userService = inject(UserService);
|
||||
|
||||
private readonly _showBookTypePill = signal(true);
|
||||
readonly showBookTypePill = this._showBookTypePill.asReadonly();
|
||||
|
||||
private currentContext: { type: 'LIBRARY' | 'SHELF' | 'MAGIC_SHELF', id: number } | null = null;
|
||||
private persistTimeout: ReturnType<typeof setTimeout> | null = null;
|
||||
|
||||
constructor() {
|
||||
effect(() => {
|
||||
const user = this.userService.currentUser();
|
||||
if (user) {
|
||||
this.loadPreferencesFromUser();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
setShowBookTypePill(show: boolean): void {
|
||||
this._showBookTypePill.set(show);
|
||||
this.schedulePersist(show);
|
||||
}
|
||||
|
||||
private loadPreferencesFromUser(): void {
|
||||
const user = this.userService.getCurrentUser();
|
||||
const prefs = user?.userSettings?.entityViewPreferences;
|
||||
|
||||
let show = true;
|
||||
if (prefs) {
|
||||
const globalAny = prefs.global as any;
|
||||
show = prefs.global?.overlayBookType ?? globalAny?.showBookTypePill ?? true;
|
||||
|
||||
if (this.currentContext) {
|
||||
const override = prefs.overrides?.find(o =>
|
||||
o.entityType === this.currentContext?.type && o.entityId === this.currentContext?.id
|
||||
);
|
||||
if (override) {
|
||||
const prefAny = override.preferences as any;
|
||||
if (override.preferences.overlayBookType !== undefined) {
|
||||
show = override.preferences.overlayBookType;
|
||||
} else if (prefAny?.showBookTypePill !== undefined) {
|
||||
show = prefAny.showBookTypePill;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this._showBookTypePill() !== show) {
|
||||
this._showBookTypePill.set(show);
|
||||
}
|
||||
}
|
||||
|
||||
private schedulePersist(show: boolean): void {
|
||||
if (this.persistTimeout) {
|
||||
clearTimeout(this.persistTimeout);
|
||||
}
|
||||
|
||||
this.persistTimeout = setTimeout(() => {
|
||||
this.persistPreference(show);
|
||||
}, BookCardOverlayPreferenceService.PERSIST_DELAY_MS);
|
||||
}
|
||||
|
||||
private persistPreference(show: boolean): void {
|
||||
const user = this.userService.getCurrentUser();
|
||||
if (!user) return;
|
||||
|
||||
const prefs = structuredClone(user.userSettings.entityViewPreferences ?? {
|
||||
global: {
|
||||
sortKey: 'addedOn',
|
||||
sortDir: 'DESC',
|
||||
view: 'GRID',
|
||||
coverSize: 1.0,
|
||||
seriesCollapsed: false,
|
||||
overlayBookType: true
|
||||
},
|
||||
overrides: []
|
||||
});
|
||||
|
||||
if (!prefs.overrides) {
|
||||
prefs.overrides = [];
|
||||
}
|
||||
|
||||
if (this.currentContext) {
|
||||
let override = prefs.overrides.find(o =>
|
||||
o.entityType === this.currentContext?.type && o.entityId === this.currentContext?.id
|
||||
);
|
||||
|
||||
if (!override) {
|
||||
override = {
|
||||
entityType: this.currentContext.type,
|
||||
entityId: this.currentContext.id,
|
||||
preferences: {
|
||||
...prefs.global,
|
||||
overlayBookType: show
|
||||
}
|
||||
};
|
||||
prefs.overrides.push(override);
|
||||
} else {
|
||||
override.preferences.overlayBookType = show;
|
||||
}
|
||||
} else {
|
||||
prefs.global.overlayBookType = show;
|
||||
}
|
||||
|
||||
this.userService.updateUserSetting(user.id, 'entityViewPreferences', prefs);
|
||||
}
|
||||
}
|
||||
+115
@@ -0,0 +1,115 @@
|
||||
<div class="book-card"
|
||||
[class.selected]="isSelected"
|
||||
(click)="onCardClick($event)">
|
||||
|
||||
<div class="cover-container" [ngClass]="{ 'center-info-btn': _isSeriesViewActive || !hasDigitalFile(), 'loaded': isImageLoaded, 'audiobook-cover': _isAudiobook, 'square-library-cover': useSquareCovers }">
|
||||
<img
|
||||
[src]="coverImageUrl"
|
||||
class="book-cover"
|
||||
[class.loaded]="isImageLoaded"
|
||||
[class.square-cover]="_isAudiobook || useSquareCovers"
|
||||
[alt]="('book.card.alt.cover' | transloco: { title: displayTitle })"
|
||||
loading="lazy"
|
||||
decoding="async"
|
||||
(load)="onImageLoad()"/>
|
||||
|
||||
<div class="top-left-overlay-stack">
|
||||
@if ((overlayPreferenceService?.showBookTypePill() ?? true) && getDisplayFormat(); as displayFormat) {
|
||||
<div class="book-type-pill-overlay" [ngClass]="'book-type-' + displayFormat.toLowerCase()">
|
||||
{{ displayFormat }}
|
||||
</div>
|
||||
}
|
||||
@if (!book.seriesCount && book.metadata?.seriesNumber != null) {
|
||||
<div class="series-number-overlay">
|
||||
#{{ book.metadata?.seriesNumber }}
|
||||
</div>
|
||||
}
|
||||
@if (book.seriesCount && book.seriesCount >= 1) {
|
||||
<div class="series-items-count-overlay">
|
||||
<i class="pi pi-book series-items-count-icon"></i>{{ book.seriesCount }}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@if (_isSeriesViewActive) {
|
||||
<p-button [rounded]="true" icon="pi pi-info" class="info-btn" (click)="openSeriesInfo()" [ariaLabel]="'book.card.alt.viewSeriesInfo' | transloco"></p-button>
|
||||
} @else {
|
||||
<p-button [rounded]="true" icon="pi pi-info" class="info-btn" (click)="openBookInfo(book)" [ariaLabel]="'book.card.alt.viewDetails' | transloco">
|
||||
</p-button>
|
||||
}
|
||||
|
||||
@if (!_isSeriesViewActive && hasDigitalFile()) {
|
||||
<a [routerLink]="urlHelper.getBookPrimaryReadingUrl(book)" (click)="readBook(book)"><p-button [rounded]="true" [icon]="readButtonIcon" class="read-btn" (click)="readBook(book)"
|
||||
[pTooltip]="_isContinueReading ? ('book.card.alt.continueReading' | transloco) : ''"
|
||||
tooltipPosition="bottom"
|
||||
[ariaLabel]="_isContinueReading ? ('book.card.alt.continueReading' | transloco) : (_isAudiobook ? ('book.card.alt.playAudiobook' | transloco) : ('book.card.alt.readBook' | transloco))"></p-button></a>
|
||||
}
|
||||
|
||||
@if (isCheckboxEnabled) {
|
||||
<p-checkbox
|
||||
[binary]="true"
|
||||
class="select-checkbox"
|
||||
(click)="captureMouseEvent($event)"
|
||||
[ngModel]="isSelected"
|
||||
(onChange)="toggleSelection($event)">
|
||||
</p-checkbox>
|
||||
}
|
||||
|
||||
@if (hasProgress) {
|
||||
<div class="cover-progress-bar-container" [pTooltip]="progressTooltip" tooltipPosition="top">
|
||||
@if (_progressPercentage !== null) {
|
||||
<p-progressBar
|
||||
[value]="_progressPercentage"
|
||||
[showValue]="false"
|
||||
class="cover-progress-bar"
|
||||
[ngClass]="{ 'progress-complete': _progressPercentage === 100, 'progress-incomplete': _progressPercentage < 100 }">
|
||||
</p-progressBar>
|
||||
}
|
||||
@if (_koProgressPercentage !== null) {
|
||||
<p-progressBar
|
||||
[value]="_koProgressPercentage"
|
||||
[showValue]="false"
|
||||
class="cover-progress-bar"
|
||||
[ngClass]="_koProgressPercentage === 100 ? 'progress-complete-ko' : 'progress-incomplete-ko'">
|
||||
</p-progressBar>
|
||||
}
|
||||
@if (_koboProgressPercentage !== null) {
|
||||
<p-progressBar
|
||||
[value]="_koboProgressPercentage"
|
||||
[showValue]="false"
|
||||
class="cover-progress-bar"
|
||||
[ngClass]="_koboProgressPercentage === 100 ? 'progress-complete-kobo' : 'progress-incomplete-kobo'">
|
||||
</p-progressBar>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@if (!bottomBarHidden) {
|
||||
<div class="book-title-container">
|
||||
<div class="read-status-indicator"
|
||||
[ngClass]="_readStatusClass"
|
||||
[pTooltip]="readStatusTooltip"
|
||||
tooltipPosition="bottom"
|
||||
(click)="toggleReadStatusMenu($event, readStatusMenu)"
|
||||
[attr.aria-label]="'book.card.alt.readStatusMenu' | transloco">
|
||||
<i [class]="_readStatusIcon" style="font-size: 0.9rem"></i>
|
||||
</div>
|
||||
<p-tieredmenu #readStatusMenu [model]="readStatusMenuItems" [popup]="true" appendTo="body"></p-tieredmenu>
|
||||
<h4 class="book-title"
|
||||
tooltipPosition="bottom"
|
||||
[pTooltip]="titleTooltip">
|
||||
{{ displayTitle }}
|
||||
</h4>
|
||||
<p-tieredmenu #menu [model]="items" [popup]="true" appendTo="body" (onShow)="onMenuShow()" (onHide)="onMenuHide()"></p-tieredmenu>
|
||||
<p-button
|
||||
class="custom-button-padding"
|
||||
size="small"
|
||||
[text]="true"
|
||||
(click)="onMenuToggle($event, menu)"
|
||||
icon="pi pi-ellipsis-v"
|
||||
[ariaLabel]="'book.card.alt.bookMenu' | transloco">
|
||||
</p-button>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
+464
@@ -0,0 +1,464 @@
|
||||
.book-card {
|
||||
background-color: var(--card-background);
|
||||
border-radius: 8px;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
|
||||
transition: box-shadow 0.25s ease, transform 0.25s ease;
|
||||
|
||||
&:hover {
|
||||
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
&.selected {
|
||||
border: 2px solid var(--primary-color);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes shimmer {
|
||||
0% {
|
||||
background-position: -200% 0;
|
||||
}
|
||||
100% {
|
||||
background-position: 200% 0;
|
||||
}
|
||||
}
|
||||
|
||||
.cover-container {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
aspect-ratio: 5/7;
|
||||
background-color: var(--card-background);
|
||||
border-radius: 8px 8px 0 0;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.cover-container:not(.loaded) {
|
||||
background: linear-gradient(
|
||||
90deg,
|
||||
var(--surface-ground) 25%,
|
||||
var(--surface-hover, rgba(255, 255, 255, 0.08)) 50%,
|
||||
var(--surface-ground) 75%
|
||||
);
|
||||
background-size: 200% 100%;
|
||||
animation: shimmer 1.5s ease-in-out infinite;
|
||||
}
|
||||
|
||||
.cover-container.audiobook-cover {
|
||||
aspect-ratio: 5/7;
|
||||
background-color: var(--surface-ground);
|
||||
}
|
||||
|
||||
.cover-container.square-library-cover {
|
||||
aspect-ratio: 1/1;
|
||||
background-color: var(--surface-ground);
|
||||
}
|
||||
|
||||
.book-cover {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border-radius: 8px 8px 0 0;
|
||||
opacity: 0;
|
||||
transition: opacity 0.2s ease-in, transform 0.35s ease;
|
||||
}
|
||||
|
||||
.book-cover.loaded {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.book-card:hover .book-cover.loaded {
|
||||
transform: scale(1.04);
|
||||
}
|
||||
|
||||
.book-cover.square-cover {
|
||||
object-fit: contain;
|
||||
}
|
||||
|
||||
.cover-container::after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: radial-gradient(circle, rgba(0, 0, 0, 0) 25%, rgba(0, 0, 0, 0.6) 100%);
|
||||
opacity: 0;
|
||||
transition: opacity 0.15s ease-in-out;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.cover-container:hover::after {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.book-title-container {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.book-title {
|
||||
flex-grow: 1;
|
||||
font-size: 0.9rem;
|
||||
color: var(--text-color);
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
text-align: center;
|
||||
margin: 0;
|
||||
padding-left: 0.5rem;
|
||||
|
||||
@media (max-width: 767px) {
|
||||
font-size: 0.75rem;
|
||||
padding-left: 0.25rem;
|
||||
}
|
||||
}
|
||||
|
||||
.info-btn,
|
||||
.read-btn {
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
opacity: 0;
|
||||
visibility: hidden;
|
||||
transition: opacity 0.15s ease, visibility 0.15s ease;
|
||||
z-index: 2;
|
||||
will-change: opacity, visibility;
|
||||
|
||||
::ng-deep .p-button {
|
||||
box-shadow:
|
||||
0 2px 8px rgba(0, 0, 0, 0.4),
|
||||
inset 0 1px 0 rgba(255, 255, 255, 0.15);
|
||||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||
transition: transform 0.15s ease, box-shadow 0.15s ease;
|
||||
|
||||
&:hover {
|
||||
transform: scale(1.08);
|
||||
box-shadow:
|
||||
0 4px 12px rgba(0, 0, 0, 0.5),
|
||||
inset 0 1px 0 rgba(255, 255, 255, 0.2);
|
||||
}
|
||||
|
||||
@media (max-width: 767px) {
|
||||
width: clamp(1.5rem, 8vw, 2.5rem);
|
||||
height: clamp(1.5rem, 8vw, 2.5rem);
|
||||
padding: 0;
|
||||
|
||||
.pi {
|
||||
font-size: clamp(0.65rem, 3.5vw, 1rem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.info-btn {
|
||||
top: 21%;
|
||||
}
|
||||
|
||||
.read-btn {
|
||||
bottom: 21%;
|
||||
}
|
||||
|
||||
.cover-container:hover .info-btn,
|
||||
.cover-container:hover .read-btn {
|
||||
opacity: 1;
|
||||
visibility: visible;
|
||||
}
|
||||
|
||||
.cover-container.center-info-btn .info-btn {
|
||||
top: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
}
|
||||
|
||||
.select-checkbox {
|
||||
position: absolute;
|
||||
top: 8px;
|
||||
right: 8px;
|
||||
opacity: 0;
|
||||
visibility: hidden;
|
||||
transition: opacity 0.15s ease, visibility 0.15s ease;
|
||||
z-index: 2;
|
||||
will-change: opacity, visibility;
|
||||
|
||||
@media (max-width: 767px) {
|
||||
top: 4px;
|
||||
right: 4px;
|
||||
}
|
||||
}
|
||||
|
||||
.select-checkbox .p-checkbox {
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
.cover-container:hover .select-checkbox,
|
||||
.book-card.selected .select-checkbox {
|
||||
opacity: 1;
|
||||
visibility: visible;
|
||||
}
|
||||
|
||||
.cover-progress-bar-container {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 7.5px;
|
||||
z-index: 2;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.cover-progress-bar {
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 2.5px;
|
||||
z-index: 1;
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.series-number-overlay {
|
||||
position: absolute;
|
||||
top: 8px;
|
||||
left: 8px;
|
||||
background-color: rgba(0, 0, 0, 0.7);
|
||||
color: white;
|
||||
font-size: 0.75rem;
|
||||
padding: 1px 3px;
|
||||
border-radius: 3px;
|
||||
z-index: 3;
|
||||
}
|
||||
|
||||
.series-items-count-overlay {
|
||||
position: absolute;
|
||||
background-color: var(--primary-color);
|
||||
color: var(--primary-text-color-dark);
|
||||
font-size: 0.7rem;
|
||||
padding: 0 5px;
|
||||
border-radius: 6px;
|
||||
z-index: 3;
|
||||
white-space: nowrap;
|
||||
user-select: none;
|
||||
font-weight: 700;
|
||||
text-align: center;
|
||||
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
|
||||
border: 1px solid rgba(255, 255, 255, 0.2);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
.series-items-count-icon {
|
||||
font-size: 0.6rem;
|
||||
margin-right: 2px;
|
||||
}
|
||||
|
||||
.book-type-pill-overlay {
|
||||
position: absolute;
|
||||
background: var(--primary-color, #6366f1);
|
||||
color: var(--primary-text-color-dark, #fff);
|
||||
font-size: 0.675rem;
|
||||
font-weight: 700;
|
||||
padding: 1px 6px;
|
||||
border-radius: 6px;
|
||||
z-index: 3;
|
||||
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
|
||||
letter-spacing: 0.03em;
|
||||
user-select: none;
|
||||
pointer-events: none;
|
||||
text-transform: uppercase;
|
||||
transition: background 0.2s;
|
||||
}
|
||||
|
||||
.top-left-overlay-stack {
|
||||
position: absolute;
|
||||
top: 7px;
|
||||
left: 7px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 4px;
|
||||
z-index: 4;
|
||||
|
||||
@media (max-width: 767px) {
|
||||
top: 4px;
|
||||
left: 4px;
|
||||
gap: 2px;
|
||||
}
|
||||
}
|
||||
|
||||
.book-type-pill-overlay,
|
||||
.series-number-overlay,
|
||||
.series-items-count-overlay {
|
||||
position: static;
|
||||
margin: 0;
|
||||
|
||||
@media (max-width: 767px) {
|
||||
font-size: 0.6rem;
|
||||
padding: 1px 4px;
|
||||
}
|
||||
}
|
||||
|
||||
.book-type-epub {
|
||||
background: var(--book-type-epub-color);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.book-type-pdf {
|
||||
background: var(--book-type-pdf-color);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.book-type-cbx {
|
||||
background: var(--book-type-cbx-color);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.book-type-mobi {
|
||||
background: var(--book-type-mobi-color);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.book-type-azw3 {
|
||||
background: var(--book-type-azw3-color);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.book-type-fb2 {
|
||||
background: var(--book-type-fb2-color);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.book-type-audiobook {
|
||||
background: var(--book-type-audiobook-color);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.book-type-m4b {
|
||||
background: var(--book-type-m4b-color);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.book-type-mp3 {
|
||||
background: var(--book-type-mp3-color);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.book-type-m4a {
|
||||
background: var(--book-type-m4a-color);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.book-type-opus {
|
||||
background: var(--book-type-opus-color);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.book-type-cbz {
|
||||
background: var(--book-type-cbz-color);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.book-type-cbr {
|
||||
background: var(--book-type-cbr-color);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.book-type-cb7 {
|
||||
background: var(--book-type-cb7-color);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.book-type-phy {
|
||||
background: var(--book-type-physical-color);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.read-status-indicator {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-weight: bold;
|
||||
margin-left: 0.5rem;
|
||||
cursor: pointer;
|
||||
border-radius: 4px;
|
||||
transition: opacity 0.15s ease;
|
||||
|
||||
&:hover {
|
||||
opacity: 0.7;
|
||||
}
|
||||
}
|
||||
|
||||
.status-read {
|
||||
color: #22c55e;
|
||||
}
|
||||
|
||||
.status-reading {
|
||||
color: #3b82f6;
|
||||
}
|
||||
|
||||
.status-re-reading {
|
||||
color: #06b6d4;
|
||||
}
|
||||
|
||||
.status-partially-read {
|
||||
color: #f59e0b;
|
||||
}
|
||||
|
||||
.status-paused {
|
||||
color: #eab308;
|
||||
}
|
||||
|
||||
.status-abandoned {
|
||||
color: #ef4444;
|
||||
}
|
||||
|
||||
.status-wont-read {
|
||||
color: #ec4899;
|
||||
}
|
||||
|
||||
.status-unset {
|
||||
color: var(--text-color-secondary);
|
||||
}
|
||||
|
||||
::ng-deep .progress-incomplete .p-progressbar-value {
|
||||
background-color: #3b82f6;
|
||||
}
|
||||
|
||||
::ng-deep .progress-complete .p-progressbar-value {
|
||||
background-color: #22c55e;
|
||||
}
|
||||
|
||||
::ng-deep .progress-incomplete-ko .p-progressbar-value {
|
||||
background-color: #fbbf24;
|
||||
}
|
||||
|
||||
::ng-deep .progress-complete-ko .p-progressbar-value {
|
||||
background-color: #8b5cf6;
|
||||
}
|
||||
|
||||
::ng-deep .progress-incomplete-kobo .p-progressbar-value {
|
||||
background-color: #bf0000;
|
||||
}
|
||||
|
||||
::ng-deep .progress-complete-kobo .p-progressbar-value {
|
||||
background-color: #f65c9c;
|
||||
}
|
||||
|
||||
::ng-deep .cover-progress-bar {
|
||||
--p-progressbar-border-radius: 0 !important;
|
||||
}
|
||||
|
||||
::ng-deep .custom-button-padding .p-button {
|
||||
padding-block: 0.25rem !important;
|
||||
}
|
||||
|
||||
::ng-deep .book-details-dialog .p-dialog-header {
|
||||
padding: 1rem 1.25rem !important;
|
||||
}
|
||||
+929
@@ -0,0 +1,929 @@
|
||||
import {ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, EventEmitter, inject, Input, OnChanges, OnInit, Output, SimpleChanges, ViewChild} from '@angular/core';
|
||||
import {TooltipModule} from "primeng/tooltip";
|
||||
import {AdditionalFile, Book, BookType, ReadStatus} from '../../../model/book.model';
|
||||
import {Button} from 'primeng/button';
|
||||
import {MenuModule} from 'primeng/menu';
|
||||
import {ConfirmationService, MenuItem, MessageService} from 'primeng/api';
|
||||
import {BookService} from '../../../service/book.service';
|
||||
import {BookFileService} from '../../../service/book-file.service';
|
||||
import {BookMetadataManageService} from '../../../service/book-metadata-manage.service';
|
||||
import {CheckboxChangeEvent, CheckboxModule} from 'primeng/checkbox';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {MetadataRefreshType} from '../../../../metadata/model/request/metadata-refresh-type.enum';
|
||||
import {UrlHelperService} from '../../../../../shared/service/url-helper.service';
|
||||
import {NgClass} from '@angular/common';
|
||||
import {User, UserService} from '../../../../settings/user-management/user.service';
|
||||
import {EmailService} from '../../../../settings/email-v2/email.service';
|
||||
import {TieredMenu} from 'primeng/tieredmenu';
|
||||
import {Router} from '@angular/router';
|
||||
import {RouterLink} from '@angular/router';
|
||||
import {ProgressBar} from 'primeng/progressbar';
|
||||
import {readStatusLabels} from '../book-filter/book-filter.config';
|
||||
import {ResetProgressTypes} from '../../../../../shared/constants/reset-progress-type';
|
||||
import {ReadStatusHelper} from '../../../helpers/read-status.helper';
|
||||
import {BookDialogHelperService} from '../book-dialog-helper.service';
|
||||
import {TaskHelperService} from '../../../../settings/task-management/task-helper.service';
|
||||
import {BookNavigationService} from '../../../service/book-navigation.service';
|
||||
import {BookCardOverlayPreferenceService} from '../book-card-overlay-preference.service';
|
||||
import {AppSettingsService} from '../../../../../shared/service/app-settings.service';
|
||||
import {TranslocoPipe, TranslocoService} from '@jsverse/transloco';
|
||||
import {QueryClient} from '@tanstack/angular-query-experimental';
|
||||
|
||||
@Component({
|
||||
selector: 'app-book-card',
|
||||
templateUrl: './book-card.component.html',
|
||||
styleUrls: ['./book-card.component.scss'],
|
||||
imports: [Button, MenuModule, CheckboxModule, FormsModule, NgClass, TieredMenu, ProgressBar, TooltipModule, RouterLink, TranslocoPipe],
|
||||
standalone: true,
|
||||
changeDetection: ChangeDetectionStrategy.OnPush
|
||||
})
|
||||
export class BookCardComponent implements OnInit, OnChanges {
|
||||
|
||||
@Output() checkboxClick = new EventEmitter<{ index: number; book: Book; selected: boolean; shiftKey: boolean }>();
|
||||
@Output() menuToggled = new EventEmitter<boolean>();
|
||||
|
||||
@Input() index!: number;
|
||||
@Input() book!: Book;
|
||||
@Input() isCheckboxEnabled: boolean = false;
|
||||
@Input() onBookSelect?: (book: Book, selected: boolean) => void;
|
||||
@Input() isSelected: boolean = false;
|
||||
@Input() bottomBarHidden: boolean = false;
|
||||
@Input() seriesViewEnabled: boolean = false;
|
||||
@Input() isSeriesCollapsed: boolean = false;
|
||||
@Input() overlayPreferenceService?: BookCardOverlayPreferenceService;
|
||||
@Input() forceEbookMode: boolean = false;
|
||||
@Input() useSquareCovers: boolean = false;
|
||||
|
||||
@ViewChild('checkboxElem') checkboxElem!: ElementRef<HTMLInputElement>;
|
||||
|
||||
items: MenuItem[] | undefined;
|
||||
readStatusMenuItems: MenuItem[] = [];
|
||||
isImageLoaded: boolean = false;
|
||||
isSubMenuLoading = false;
|
||||
private additionalFilesLoaded = false;
|
||||
|
||||
private bookService = inject(BookService);
|
||||
private bookFileService = inject(BookFileService);
|
||||
private bookMetadataManageService = inject(BookMetadataManageService);
|
||||
private taskHelperService = inject(TaskHelperService);
|
||||
private userService = inject(UserService);
|
||||
private emailService = inject(EmailService);
|
||||
private messageService = inject(MessageService);
|
||||
private router = inject(Router);
|
||||
protected urlHelper = inject(UrlHelperService);
|
||||
private confirmationService = inject(ConfirmationService);
|
||||
private bookDialogHelperService = inject(BookDialogHelperService);
|
||||
private bookNavigationService = inject(BookNavigationService);
|
||||
private cdr = inject(ChangeDetectorRef);
|
||||
private appSettingsService = inject(AppSettingsService);
|
||||
private readonly t = inject(TranslocoService);
|
||||
private queryClient = inject(QueryClient);
|
||||
|
||||
protected _progressPercentage: number | null = null;
|
||||
protected _koProgressPercentage: number | null = null;
|
||||
protected _koboProgressPercentage: number | null = null;
|
||||
protected _displayTitle: string | undefined = undefined;
|
||||
protected _isSeriesViewActive: boolean = false;
|
||||
protected _coverImageUrl: string = '';
|
||||
protected _readStatusIcon: string = '';
|
||||
protected _readStatusClass: string = '';
|
||||
protected _readStatusTooltip: string = '';
|
||||
protected _shouldShowStatusIcon: boolean = false;
|
||||
protected _seriesCountTooltip: string = '';
|
||||
protected _titleTooltip: string = '';
|
||||
protected _hasProgress: boolean = false;
|
||||
protected _isAudiobook: boolean = false;
|
||||
protected _progressTooltip: string = '';
|
||||
protected _isContinueReading: boolean = false;
|
||||
protected _readButtonIcon: string = 'pi pi-book';
|
||||
|
||||
private metadataCenterViewMode: 'route' | 'dialog' = 'route';
|
||||
protected readStatusHelper = inject(ReadStatusHelper);
|
||||
private user: User | null = null;
|
||||
private diskType: string = 'LOCAL';
|
||||
private menuInitialized = false;
|
||||
|
||||
ngOnInit(): void {
|
||||
this.computeAllMemoizedValues();
|
||||
const currentUser = this.userService.currentUser();
|
||||
if (currentUser) {
|
||||
this.user = currentUser;
|
||||
this.metadataCenterViewMode = currentUser.userSettings?.metadataCenterViewMode ?? 'route';
|
||||
}
|
||||
|
||||
const settings = this.appSettingsService.appSettings();
|
||||
if (settings) {
|
||||
this.diskType = settings.diskType ?? 'LOCAL';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ngOnChanges(changes: SimpleChanges): void {
|
||||
if (changes['book'] || changes['forceEbookMode'] || changes['useSquareCovers']) {
|
||||
this.computeAllMemoizedValues();
|
||||
if (changes['book'] && !changes['book'].firstChange && this.menuInitialized) {
|
||||
this.additionalFilesLoaded = false;
|
||||
this.initMenu();
|
||||
}
|
||||
}
|
||||
|
||||
if (changes['seriesViewEnabled'] || changes['isSeriesCollapsed']) {
|
||||
this._isSeriesViewActive = this.seriesViewEnabled && !!this.book.seriesCount && this.book.seriesCount >= 1;
|
||||
this._displayTitle = (this.isSeriesCollapsed && this.book.metadata?.seriesName) ? this.book.metadata?.seriesName : this.book.metadata?.title;
|
||||
this._titleTooltip = this.t.translate('book.card.alt.titleTooltip', { title: this._displayTitle });
|
||||
}
|
||||
}
|
||||
|
||||
private computeAllMemoizedValues(): void {
|
||||
this._progressPercentage = this.book.epubProgress?.percentage
|
||||
?? this.book.pdfProgress?.percentage
|
||||
?? this.book.cbxProgress?.percentage
|
||||
?? null;
|
||||
|
||||
this._koProgressPercentage = this.book.koreaderProgress?.percentage ?? null;
|
||||
this._koboProgressPercentage = this.book.koboProgress?.percentage ?? null;
|
||||
|
||||
this._hasProgress = this._progressPercentage !== null || this._koProgressPercentage !== null || this._koboProgressPercentage !== null;
|
||||
|
||||
this._isSeriesViewActive = this.seriesViewEnabled && !!this.book.seriesCount && this.book.seriesCount >= 1;
|
||||
this._displayTitle = (this.isSeriesCollapsed && this.book.metadata?.seriesName)
|
||||
? this.book.metadata?.seriesName
|
||||
: this.book.metadata?.title;
|
||||
this._isAudiobook = this.book.primaryFile?.bookType === 'AUDIOBOOK' && !this.forceEbookMode;
|
||||
this._coverImageUrl = this._isAudiobook
|
||||
? this.urlHelper.getAudiobookThumbnailUrl(this.book.id, this.book.metadata?.audiobookCoverUpdatedOn)
|
||||
: this.urlHelper.getThumbnailUrl(this.book.id, this.book.metadata?.coverUpdatedOn);
|
||||
|
||||
this._readStatusIcon = this.readStatusHelper.getReadStatusIcon(this.book.readStatus);
|
||||
this._readStatusClass = this.readStatusHelper.getReadStatusClass(this.book.readStatus);
|
||||
this._readStatusTooltip = this.readStatusHelper.getReadStatusTooltip(this.book.readStatus);
|
||||
this._shouldShowStatusIcon = this.readStatusHelper.shouldShowStatusIcon(this.book.readStatus);
|
||||
|
||||
this._seriesCountTooltip = this.t.translate('book.card.alt.seriesCollapsed', { count: this.book.seriesCount });
|
||||
this._titleTooltip = this.t.translate('book.card.alt.titleTooltip', { title: this._displayTitle });
|
||||
|
||||
const progressParts: string[] = [];
|
||||
if (this._progressPercentage !== null) {
|
||||
progressParts.push(`${this._progressPercentage}% (Grimmory)`);
|
||||
}
|
||||
if (this._koProgressPercentage !== null) {
|
||||
progressParts.push(`${this._koProgressPercentage}% (KOReader)`);
|
||||
}
|
||||
if (this._koboProgressPercentage !== null) {
|
||||
progressParts.push(`${this._koboProgressPercentage}% (Kobo)`);
|
||||
}
|
||||
this._progressTooltip = progressParts.join(' | ');
|
||||
|
||||
const maxProgress = Math.max(
|
||||
this._progressPercentage ?? 0,
|
||||
this._koProgressPercentage ?? 0,
|
||||
this._koboProgressPercentage ?? 0
|
||||
);
|
||||
this._isContinueReading = maxProgress > 0 && maxProgress < 100;
|
||||
|
||||
if (this._isAudiobook) {
|
||||
this._readButtonIcon = this._isContinueReading ? 'pi pi-forward' : 'pi pi-play';
|
||||
} else {
|
||||
this._readButtonIcon = this._isContinueReading ? 'pi pi-forward' : 'pi pi-book';
|
||||
}
|
||||
}
|
||||
|
||||
get hasProgress(): boolean {
|
||||
return this._hasProgress;
|
||||
}
|
||||
|
||||
get seriesCountTooltip(): string {
|
||||
return this._seriesCountTooltip;
|
||||
}
|
||||
|
||||
get titleTooltip(): string {
|
||||
return this._titleTooltip;
|
||||
}
|
||||
|
||||
get readStatusTooltip(): string {
|
||||
return this._readStatusTooltip;
|
||||
}
|
||||
|
||||
get progressTooltip(): string {
|
||||
return this._progressTooltip;
|
||||
}
|
||||
|
||||
get readButtonIcon(): string {
|
||||
return this._readButtonIcon;
|
||||
}
|
||||
|
||||
get displayTitle(): string | undefined {
|
||||
return this._displayTitle;
|
||||
}
|
||||
|
||||
get coverImageUrl(): string {
|
||||
return this._coverImageUrl;
|
||||
}
|
||||
|
||||
private buildReadStatusMenuItems(): void {
|
||||
this.readStatusMenuItems = Object.entries(readStatusLabels).map(([status, label]) => ({
|
||||
label,
|
||||
command: () => {
|
||||
this.bookService.updateBookReadStatus(this.book.id, status as ReadStatus).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('book.card.toast.readStatusUpdatedSummary'),
|
||||
detail: this.t.translate('book.card.toast.readStatusUpdatedDetail', {label}),
|
||||
life: 2000
|
||||
});
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('book.card.toast.readStatusFailedSummary'),
|
||||
detail: this.t.translate('book.card.toast.readStatusFailedDetail'),
|
||||
life: 3000
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
toggleReadStatusMenu(event: Event, menu: TieredMenu): void {
|
||||
event.stopPropagation();
|
||||
if (this.readStatusMenuItems.length === 0) {
|
||||
this.buildReadStatusMenuItems();
|
||||
}
|
||||
menu.toggle(event);
|
||||
}
|
||||
|
||||
onImageLoad(): void {
|
||||
this.isImageLoaded = true;
|
||||
this.cdr.markForCheck();
|
||||
}
|
||||
|
||||
readBook(book: Book): void {
|
||||
if (this.forceEbookMode && book.primaryFile?.bookType === 'AUDIOBOOK') {
|
||||
const ebookType = this.getEbookType(book);
|
||||
if (ebookType) {
|
||||
this.bookService.readBook(book.id, undefined, ebookType);
|
||||
return;
|
||||
}
|
||||
}
|
||||
this.bookService.readBook(book.id);
|
||||
}
|
||||
|
||||
private getEbookType(book: Book): BookType | undefined {
|
||||
if (book.epubProgress) return 'EPUB';
|
||||
if (book.pdfProgress) return 'PDF';
|
||||
if (book.cbxProgress) return 'CBX';
|
||||
const alternativeFormat = book.alternativeFormats?.find(f =>
|
||||
f.bookType && ['EPUB', 'PDF', 'CBX', 'FB2', 'MOBI', 'AZW3'].includes(f.bookType)
|
||||
);
|
||||
return alternativeFormat?.bookType;
|
||||
}
|
||||
|
||||
onMenuShow(): void {
|
||||
this.menuToggled.emit(true);
|
||||
}
|
||||
|
||||
onMenuHide(): void {
|
||||
this.menuToggled.emit(false);
|
||||
}
|
||||
|
||||
onMenuToggle(event: Event, menu: TieredMenu): void {
|
||||
if (!this.menuInitialized) {
|
||||
this.menuInitialized = true;
|
||||
this.initMenu();
|
||||
this.cdr.markForCheck();
|
||||
}
|
||||
|
||||
menu.toggle(event);
|
||||
|
||||
if (!this.additionalFilesLoaded && !this.isSubMenuLoading && this.needsAdditionalFilesData()) {
|
||||
this.isSubMenuLoading = true;
|
||||
this.cdr.markForCheck();
|
||||
const requestedBookId = this.book.id;
|
||||
void this.queryClient.fetchQuery(this.bookService.bookDetailQueryOptions(requestedBookId, true))
|
||||
.then((book) => {
|
||||
if (this.book.id !== requestedBookId) {
|
||||
return;
|
||||
}
|
||||
this.book = book;
|
||||
this.additionalFilesLoaded = true;
|
||||
this.isSubMenuLoading = false;
|
||||
this.initMenu();
|
||||
this.cdr.markForCheck();
|
||||
})
|
||||
.catch(() => {
|
||||
if (this.book.id !== requestedBookId) {
|
||||
return;
|
||||
}
|
||||
this.isSubMenuLoading = false;
|
||||
this.cdr.markForCheck();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private needsAdditionalFilesData(): boolean {
|
||||
if (this.additionalFilesLoaded) {
|
||||
return false;
|
||||
}
|
||||
const hasNoAlternativeFormats = !this.book.alternativeFormats || this.book.alternativeFormats.length === 0;
|
||||
const hasNoSupplementaryFiles = !this.book.supplementaryFiles || this.book.supplementaryFiles.length === 0;
|
||||
const canDownload = !!this.user?.permissions.canDownload;
|
||||
const canDeleteBook = !!this.user?.permissions.canDeleteBook;
|
||||
return (canDownload || canDeleteBook) && hasNoAlternativeFormats && hasNoSupplementaryFiles;
|
||||
}
|
||||
|
||||
private initMenu() {
|
||||
this.items = [
|
||||
{
|
||||
label: this.t.translate('book.card.menu.assignShelf'),
|
||||
icon: 'pi pi-folder',
|
||||
command: () => this.openShelfDialog()
|
||||
},
|
||||
{
|
||||
label: this.t.translate('book.card.menu.viewDetails'),
|
||||
icon: 'pi pi-info-circle',
|
||||
command: () => {
|
||||
setTimeout(() => {
|
||||
this.openBookInfo(this.book);
|
||||
}, 150);
|
||||
},
|
||||
},
|
||||
...this.getPermissionBasedMenuItems(),
|
||||
...this.moreMenuItems(),
|
||||
];
|
||||
}
|
||||
|
||||
private getPermissionBasedMenuItems(): MenuItem[] {
|
||||
const items: MenuItem[] = [];
|
||||
|
||||
if (this.user?.permissions.canDownload) {
|
||||
const hasAdditionalFiles = (this.book.alternativeFormats && this.book.alternativeFormats.length > 0) ||
|
||||
(this.book.supplementaryFiles && this.book.supplementaryFiles.length > 0);
|
||||
|
||||
if (hasAdditionalFiles) {
|
||||
const downloadItems = this.getDownloadMenuItems();
|
||||
items.push({
|
||||
label: this.t.translate('book.card.menu.download'),
|
||||
icon: 'pi pi-download',
|
||||
items: downloadItems
|
||||
});
|
||||
} else if (this.additionalFilesLoaded) {
|
||||
items.push({
|
||||
label: this.t.translate('book.card.menu.download'),
|
||||
icon: 'pi pi-download',
|
||||
command: () => {
|
||||
this.bookFileService.downloadFile(this.book);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
items.push({
|
||||
label: this.t.translate('book.card.menu.download'),
|
||||
icon: this.isSubMenuLoading ? 'pi pi-spin pi-spinner' : 'pi pi-download',
|
||||
items: [{label: this.t.translate('book.card.menu.loading'), disabled: true}]
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (this.user?.permissions.canDeleteBook) {
|
||||
const hasAdditionalFiles = (this.book.alternativeFormats && this.book.alternativeFormats.length > 0) ||
|
||||
(this.book.supplementaryFiles && this.book.supplementaryFiles.length > 0);
|
||||
|
||||
if (hasAdditionalFiles) {
|
||||
const deleteItems = this.getDeleteMenuItems();
|
||||
items.push({
|
||||
label: this.t.translate('book.card.menu.delete'),
|
||||
icon: 'pi pi-trash',
|
||||
items: deleteItems
|
||||
});
|
||||
} else if (this.additionalFilesLoaded) {
|
||||
items.push({
|
||||
label: this.t.translate('book.card.menu.delete'),
|
||||
icon: 'pi pi-trash',
|
||||
command: () => {
|
||||
this.confirmationService.confirm({
|
||||
message: this.t.translate('book.card.confirm.deleteBookMessage', {title: this.book.metadata?.title}),
|
||||
header: this.t.translate('book.card.confirm.deleteBookHeader'),
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
acceptIcon: 'pi pi-trash',
|
||||
rejectIcon: 'pi pi-times',
|
||||
acceptLabel: this.t.translate('common.delete'),
|
||||
rejectLabel: this.t.translate('common.cancel'),
|
||||
acceptButtonStyleClass: 'p-button-danger',
|
||||
rejectButtonStyleClass: 'p-button-outlined',
|
||||
accept: () => {
|
||||
this.bookService.deleteBooks(new Set([this.book.id])).subscribe();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
items.push({
|
||||
label: this.t.translate('book.card.menu.delete'),
|
||||
icon: this.isSubMenuLoading ? 'pi pi-spin pi-spinner' : 'pi pi-trash',
|
||||
items: [{label: this.t.translate('book.card.menu.loading'), disabled: true}]
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (this.user?.permissions.canEmailBook) {
|
||||
items.push(
|
||||
{
|
||||
label: this.t.translate('book.card.menu.emailBook'),
|
||||
icon: 'pi pi-envelope',
|
||||
items: [{
|
||||
label: this.t.translate('book.card.menu.quickSend'),
|
||||
icon: 'pi pi-envelope',
|
||||
command: () => {
|
||||
const doSend = () => {
|
||||
this.emailService.emailBookQuick(this.book.id).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'info',
|
||||
summary: this.t.translate('common.success'),
|
||||
detail: this.t.translate('book.card.toast.quickSendSuccessDetail'),
|
||||
});
|
||||
},
|
||||
error: (err) => {
|
||||
const errorMessage = err?.error?.message || this.t.translate('book.card.toast.quickSendErrorDetail');
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('common.error'),
|
||||
detail: errorMessage,
|
||||
});
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
if (this.book.primaryFile?.fileSizeKb && this.book.primaryFile.fileSizeKb > 25 * 1024) {
|
||||
this.confirmationService.confirm({
|
||||
message: this.t.translate('book.card.confirm.largeFileMessage'),
|
||||
header: this.t.translate('book.card.confirm.largeFileHeader'),
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
acceptLabel: this.t.translate('book.card.confirm.sendAnyway'),
|
||||
rejectLabel: this.t.translate('common.cancel'),
|
||||
acceptButtonProps: { severity: 'warn' },
|
||||
rejectButtonProps: { severity: 'secondary' },
|
||||
accept: doSend,
|
||||
});
|
||||
} else {
|
||||
doSend();
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
label: this.t.translate('book.card.menu.customSend'),
|
||||
icon: 'pi pi-envelope',
|
||||
command: () => {
|
||||
this.bookDialogHelperService.openCustomSendDialog(this.book);
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
if (this.user?.permissions.canEditMetadata) {
|
||||
items.push({
|
||||
label: this.t.translate('book.card.menu.metadata'),
|
||||
icon: 'pi pi-database',
|
||||
items: [
|
||||
{
|
||||
label: this.t.translate('book.card.menu.searchMetadata'),
|
||||
icon: 'pi pi-sparkles',
|
||||
command: () => {
|
||||
setTimeout(() => {
|
||||
this.router.navigate(['/book', this.book.id], {
|
||||
queryParams: {tab: 'match'}
|
||||
})
|
||||
}, 150);
|
||||
},
|
||||
},
|
||||
{
|
||||
label: this.t.translate('book.card.menu.autoFetch'),
|
||||
icon: 'pi pi-bolt',
|
||||
command: () => {
|
||||
this.taskHelperService.refreshMetadataTask({
|
||||
refreshType: MetadataRefreshType.BOOKS,
|
||||
bookIds: [this.book.id],
|
||||
}).subscribe();
|
||||
}
|
||||
},
|
||||
{
|
||||
label: this.t.translate('book.card.menu.customFetch'),
|
||||
icon: 'pi pi-sync',
|
||||
command: () => {
|
||||
this.bookDialogHelperService.openMetadataRefreshDialog(new Set([this.book!.id]))
|
||||
},
|
||||
},
|
||||
{
|
||||
label: this.t.translate('book.card.menu.regenerateCover'),
|
||||
icon: 'pi pi-image',
|
||||
command: () => {
|
||||
this.bookMetadataManageService.regenerateCover(this.book.id).subscribe({
|
||||
next: () => this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('common.success'),
|
||||
detail: this.t.translate('book.card.toast.coverRegenSuccessDetail')
|
||||
}),
|
||||
error: (err) => this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('common.error'),
|
||||
detail: err?.error?.message || this.t.translate('book.card.toast.coverRegenFailedDetail')
|
||||
})
|
||||
});
|
||||
}
|
||||
},
|
||||
{
|
||||
label: this.t.translate('book.card.menu.generateCustomCover'),
|
||||
icon: 'pi pi-palette',
|
||||
command: () => {
|
||||
this.bookMetadataManageService.generateCustomCover(this.book.id).subscribe({
|
||||
next: () => this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('common.success'),
|
||||
detail: this.t.translate('book.card.toast.customCoverSuccessDetail')
|
||||
}),
|
||||
error: (err) => this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('common.error'),
|
||||
detail: err?.error?.message || this.t.translate('book.card.toast.customCoverFailedDetail')
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
private moreMenuItems(): MenuItem[] {
|
||||
const items: MenuItem[] = [];
|
||||
const moreActions: MenuItem[] = [];
|
||||
|
||||
if (this.user?.permissions.canMoveOrganizeFiles && this.diskType === 'LOCAL') {
|
||||
moreActions.push({
|
||||
label: this.t.translate('book.card.menu.organizeFile'),
|
||||
icon: 'pi pi-arrows-h',
|
||||
command: () => {
|
||||
this.bookDialogHelperService.openFileMoverDialog(new Set([this.book.id]));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
moreActions.push(
|
||||
{
|
||||
label: this.t.translate('book.card.menu.readStatus'),
|
||||
icon: 'pi pi-book',
|
||||
items: Object.entries(readStatusLabels).map(([status, label]) => ({
|
||||
label,
|
||||
command: () => {
|
||||
this.bookService.updateBookReadStatus(this.book.id, status as ReadStatus).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('book.card.toast.readStatusUpdatedSummary'),
|
||||
detail: this.t.translate('book.card.toast.readStatusUpdatedDetail', {label}),
|
||||
life: 2000
|
||||
});
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('book.card.toast.readStatusFailedSummary'),
|
||||
detail: this.t.translate('book.card.toast.readStatusFailedDetail'),
|
||||
life: 3000
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}))
|
||||
},
|
||||
{
|
||||
label: this.t.translate('book.card.menu.resetGrimmoryProgress'),
|
||||
icon: 'pi pi-undo',
|
||||
command: () => {
|
||||
this.bookService.resetProgress(this.book.id, ResetProgressTypes.GRIMMORY).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('book.card.toast.progressResetSummary'),
|
||||
detail: this.t.translate('book.card.toast.progressResetGrimmoryDetail'),
|
||||
life: 1500
|
||||
});
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('book.card.toast.progressResetFailedSummary'),
|
||||
detail: this.t.translate('book.card.toast.progressResetGrimmoryFailedDetail'),
|
||||
life: 1500
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
},
|
||||
{
|
||||
label: this.t.translate('book.card.menu.resetKOReaderProgress'),
|
||||
icon: 'pi pi-undo',
|
||||
command: () => {
|
||||
this.bookService.resetProgress(this.book.id, ResetProgressTypes.KOREADER).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('book.card.toast.progressResetSummary'),
|
||||
detail: this.t.translate('book.card.toast.progressResetKOReaderDetail'),
|
||||
life: 1500
|
||||
});
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('book.card.toast.progressResetFailedSummary'),
|
||||
detail: this.t.translate('book.card.toast.progressResetKOReaderFailedDetail'),
|
||||
life: 1500
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
items.push({
|
||||
label: this.t.translate('book.card.menu.moreActions'),
|
||||
icon: 'pi pi-ellipsis-h',
|
||||
items: moreActions
|
||||
});
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
private openShelfDialog(): void {
|
||||
this.bookDialogHelperService.openShelfAssignerDialog(this.book, null);
|
||||
}
|
||||
|
||||
openSeriesInfo(): void {
|
||||
const seriesName = this.book?.metadata?.seriesName;
|
||||
if (this.isSeriesCollapsed && seriesName) {
|
||||
const encodedSeriesName = encodeURIComponent(seriesName);
|
||||
this.router.navigate(['/series', encodedSeriesName]);
|
||||
} else {
|
||||
this.openBookInfo(this.book);
|
||||
}
|
||||
}
|
||||
|
||||
openBookInfo(book: Book): void {
|
||||
const allBookIds = this.bookNavigationService.availableBookIds();
|
||||
if (allBookIds.length > 0) {
|
||||
this.bookNavigationService.setNavigationContext(allBookIds, book.id);
|
||||
}
|
||||
|
||||
if (this.metadataCenterViewMode === 'route') {
|
||||
this.router.navigate(['/book', book.id], {
|
||||
queryParams: {tab: 'view'}
|
||||
});
|
||||
} else {
|
||||
this.bookDialogHelperService.openBookDetailsDialog(book.id);
|
||||
}
|
||||
}
|
||||
|
||||
private getDownloadMenuItems(): MenuItem[] {
|
||||
const items: MenuItem[] = [];
|
||||
|
||||
items.push({
|
||||
label: `${this.book.fileName || 'Book File'}`,
|
||||
icon: 'pi pi-file',
|
||||
command: () => {
|
||||
this.bookFileService.downloadFile(this.book);
|
||||
}
|
||||
});
|
||||
|
||||
if (this.hasAdditionalFiles()) {
|
||||
items.push({separator: true});
|
||||
}
|
||||
|
||||
if (this.book.alternativeFormats && this.book.alternativeFormats.length > 0) {
|
||||
this.book.alternativeFormats.forEach(format => {
|
||||
const extension = this.getFileExtension(format.filePath);
|
||||
items.push({
|
||||
label: `${format.fileName} (${this.getFileSizeInMB(format)})`,
|
||||
icon: this.getFileIcon(extension),
|
||||
command: () => this.downloadAdditionalFile(this.book, format.id)
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (this.book.alternativeFormats && this.book.alternativeFormats.length > 0 &&
|
||||
this.book.supplementaryFiles && this.book.supplementaryFiles.length > 0) {
|
||||
items.push({separator: true});
|
||||
}
|
||||
|
||||
if (this.book.supplementaryFiles && this.book.supplementaryFiles.length > 0) {
|
||||
this.book.supplementaryFiles.forEach(file => {
|
||||
const extension = this.getFileExtension(file.filePath);
|
||||
items.push({
|
||||
label: `${file.fileName} (${this.getFileSizeInMB(file)})`,
|
||||
icon: this.getFileIcon(extension),
|
||||
command: () => this.downloadAdditionalFile(this.book, file.id)
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
private getDeleteMenuItems(): MenuItem[] {
|
||||
const items: MenuItem[] = [];
|
||||
|
||||
items.push({
|
||||
label: this.t.translate('book.card.menu.book'),
|
||||
icon: 'pi pi-book',
|
||||
command: () => {
|
||||
this.confirmationService.confirm({
|
||||
message: this.t.translate('book.card.confirm.deleteBookMessage', {title: this.book.metadata?.title}),
|
||||
header: this.t.translate('book.card.confirm.deleteBookHeader'),
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
acceptIcon: 'pi pi-trash',
|
||||
rejectIcon: 'pi pi-times',
|
||||
acceptLabel: this.t.translate('common.delete'),
|
||||
rejectLabel: this.t.translate('common.cancel'),
|
||||
acceptButtonStyleClass: 'p-button-danger',
|
||||
rejectButtonStyleClass: 'p-button-outlined',
|
||||
accept: () => {
|
||||
this.bookService.deleteBooks(new Set([this.book.id])).subscribe();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
if (this.hasAdditionalFiles()) {
|
||||
items.push({separator: true});
|
||||
}
|
||||
|
||||
if (this.book.alternativeFormats && this.book.alternativeFormats.length > 0) {
|
||||
this.book.alternativeFormats.forEach(format => {
|
||||
const extension = this.getFileExtension(format.filePath);
|
||||
items.push({
|
||||
label: `${format.fileName} (${this.getFileSizeInMB(format)})`,
|
||||
icon: this.getFileIcon(extension),
|
||||
command: () => this.deleteAdditionalFile(this.book.id, format.id, format.fileName || 'file')
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (this.book.alternativeFormats && this.book.alternativeFormats.length > 0 &&
|
||||
this.book.supplementaryFiles && this.book.supplementaryFiles.length > 0) {
|
||||
items.push({separator: true});
|
||||
}
|
||||
|
||||
if (this.book.supplementaryFiles && this.book.supplementaryFiles.length > 0) {
|
||||
this.book.supplementaryFiles.forEach(file => {
|
||||
const extension = this.getFileExtension(file.filePath);
|
||||
items.push({
|
||||
label: `${file.fileName} (${this.getFileSizeInMB(file)})`,
|
||||
icon: this.getFileIcon(extension),
|
||||
command: () => this.deleteAdditionalFile(this.book.id, file.id, file.fileName || 'file')
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
private hasAdditionalFiles(): boolean {
|
||||
return !!(this.book.alternativeFormats && this.book.alternativeFormats.length > 0) ||
|
||||
!!(this.book.supplementaryFiles && this.book.supplementaryFiles.length > 0);
|
||||
}
|
||||
|
||||
private downloadAdditionalFile(book: Book, fileId: number): void {
|
||||
this.bookFileService.downloadAdditionalFile(book, fileId);
|
||||
}
|
||||
|
||||
private deleteAdditionalFile(bookId: number, fileId: number, fileName: string): void {
|
||||
this.confirmationService.confirm({
|
||||
message: this.t.translate('book.card.confirm.deleteFileMessage', {fileName}),
|
||||
header: this.t.translate('book.card.confirm.deleteFileHeader'),
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
acceptIcon: 'pi pi-trash',
|
||||
rejectIcon: 'pi pi-times',
|
||||
acceptButtonStyleClass: 'p-button-danger',
|
||||
accept: () => {
|
||||
this.bookFileService.deleteAdditionalFile(bookId, fileId).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('common.success'),
|
||||
detail: this.t.translate('book.card.toast.deleteFileSuccessDetail', {fileName})
|
||||
});
|
||||
},
|
||||
error: (error) => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('common.error'),
|
||||
detail: this.t.translate('book.card.toast.deleteFileErrorDetail', {error: error.message || 'Unknown error'})
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getFileExtension(filePath?: string): string | null {
|
||||
if (!filePath) return null;
|
||||
const parts = filePath.split('.');
|
||||
if (parts.length < 2) return null;
|
||||
return parts.pop()?.toUpperCase() || null;
|
||||
}
|
||||
|
||||
getDisplayFormat(): string | null {
|
||||
if (!this.book?.primaryFile) {
|
||||
return 'PHY';
|
||||
}
|
||||
if (this.forceEbookMode && this.book.primaryFile?.bookType === 'AUDIOBOOK') {
|
||||
const ebookType = this.getEbookType(this.book);
|
||||
if (ebookType) {
|
||||
return ebookType;
|
||||
}
|
||||
}
|
||||
const ext = this.book?.primaryFile?.extension;
|
||||
if (ext) {
|
||||
return ext.toUpperCase();
|
||||
}
|
||||
return this.getFileExtension(this.book?.primaryFile?.filePath);
|
||||
}
|
||||
|
||||
hasDigitalFile(): boolean {
|
||||
return !!this.book?.primaryFile;
|
||||
}
|
||||
|
||||
private getFileIcon(fileType: string | null): string {
|
||||
if (!fileType) return 'pi pi-file';
|
||||
switch (fileType.toLowerCase()) {
|
||||
case 'pdf':
|
||||
return 'pi pi-file-pdf';
|
||||
case 'epub':
|
||||
case 'mobi':
|
||||
case 'azw3':
|
||||
case 'fb2':
|
||||
return 'pi pi-book';
|
||||
case 'cbz':
|
||||
case 'cbr':
|
||||
case 'cbx':
|
||||
return 'pi pi-image';
|
||||
case 'audiobook':
|
||||
case 'm4b':
|
||||
case 'm4a':
|
||||
case 'mp3':
|
||||
case 'opus':
|
||||
return 'pi pi-headphones';
|
||||
default:
|
||||
return 'pi pi-file';
|
||||
}
|
||||
}
|
||||
|
||||
private getFileSizeInMB(fileInfo: AdditionalFile): string {
|
||||
const sizeKb = fileInfo?.fileSizeKb;
|
||||
return sizeKb != null ? `${(sizeKb / 1024).toFixed(2)} MB` : '-';
|
||||
}
|
||||
|
||||
private lastMouseEvent: MouseEvent | null = null;
|
||||
|
||||
captureMouseEvent(event: MouseEvent): void {
|
||||
this.lastMouseEvent = event;
|
||||
}
|
||||
|
||||
onCardClick(event: MouseEvent): void {
|
||||
if (!event.ctrlKey) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.toggleCardSelection(!this.isSelected)
|
||||
}
|
||||
|
||||
toggleCardSelection(selected: boolean): void {
|
||||
if (!this.isCheckboxEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.isSelected = selected;
|
||||
const shiftKey = this.lastMouseEvent?.shiftKey ?? false;
|
||||
|
||||
this.checkboxClick.emit({
|
||||
index: this.index,
|
||||
book: this.book,
|
||||
selected: selected,
|
||||
shiftKey: shiftKey,
|
||||
});
|
||||
|
||||
if (this.onBookSelect) {
|
||||
this.onBookSelect(this.book, selected);
|
||||
}
|
||||
|
||||
this.lastMouseEvent = null;
|
||||
}
|
||||
|
||||
toggleSelection(event: CheckboxChangeEvent): void {
|
||||
this.toggleCardSelection(event.checked);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,199 @@
|
||||
import {inject, Injectable} from '@angular/core';
|
||||
import {DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {DialogLauncherService, DialogSize, DialogStyle} from '../../../../shared/services/dialog-launcher.service';
|
||||
import {ShelfAssignerComponent} from '../shelf-assigner/shelf-assigner.component';
|
||||
import {LockUnlockMetadataDialogComponent} from './lock-unlock-metadata-dialog/lock-unlock-metadata-dialog.component';
|
||||
import {MetadataRefreshType} from '../../../metadata/model/request/metadata-refresh-type.enum';
|
||||
import {BulkMetadataUpdateComponent} from '../../../metadata/component/bulk-metadata-update/bulk-metadata-update-component';
|
||||
import {MultiBookMetadataEditorComponent} from '../../../metadata/component/multi-book-metadata-editor/multi-book-metadata-editor-component';
|
||||
import {MultiBookMetadataFetchComponent} from '../../../metadata/component/multi-book-metadata-fetch/multi-book-metadata-fetch-component';
|
||||
import {FileMoverComponent} from '../../../../shared/components/file-mover/file-mover-component';
|
||||
import {ShelfCreatorComponent} from '../shelf-creator/shelf-creator.component';
|
||||
import {BookSenderComponent} from '../book-sender/book-sender.component';
|
||||
import {MetadataFetchOptionsComponent} from '../../../metadata/component/metadata-options-dialog/metadata-fetch-options/metadata-fetch-options.component';
|
||||
import {BookMetadataCenterComponent} from '../../../metadata/component/book-metadata-center/book-metadata-center.component';
|
||||
import {CoverSearchComponent} from '../../../metadata/component/cover-search/cover-search.component';
|
||||
import {Book} from '../../model/book.model';
|
||||
import {AdditionalFileUploaderComponent} from '../additional-file-uploader/additional-file-uploader.component';
|
||||
import {BookFileAttacherComponent} from '../book-file-attacher/book-file-attacher.component';
|
||||
import {AddPhysicalBookDialogComponent} from '../add-physical-book-dialog/add-physical-book-dialog.component';
|
||||
import {BulkIsbnImportDialogComponent} from '../bulk-isbn-import-dialog/bulk-isbn-import-dialog.component';
|
||||
import {DuplicateMergerComponent} from '../duplicate-merger/duplicate-merger.component';
|
||||
|
||||
@Injectable({providedIn: 'root'})
|
||||
export class BookDialogHelperService {
|
||||
|
||||
private dialogLauncherService = inject(DialogLauncherService);
|
||||
|
||||
private openDialog(component: unknown, options: {}): DynamicDialogRef | null {
|
||||
return this.dialogLauncherService.openDialog(component, options);
|
||||
}
|
||||
|
||||
openBookDetailsDialog(bookId: number): DynamicDialogRef | null {
|
||||
return this.openDialog(BookMetadataCenterComponent, {
|
||||
showHeader: false,
|
||||
styleClass: `book-details-dialog ${DialogSize.FULL} ${DialogStyle.MINIMAL}`,
|
||||
data: {
|
||||
bookId: bookId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
openShelfAssignerDialog(book: Book | null, bookIds: Set<number> | null): DynamicDialogRef | null {
|
||||
const data: any = {};
|
||||
if (book !== null) {
|
||||
data.isMultiBooks = false;
|
||||
data.book = book;
|
||||
} else if (bookIds !== null) {
|
||||
data.isMultiBooks = true;
|
||||
data.bookIds = bookIds;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return this.openDialog(ShelfAssignerComponent, {
|
||||
showHeader: false,
|
||||
data: data,
|
||||
styleClass: `${DialogSize.SM} ${DialogStyle.MINIMAL}`,
|
||||
});
|
||||
}
|
||||
|
||||
openShelfCreatorDialog(): DynamicDialogRef {
|
||||
return this.openDialog(ShelfCreatorComponent, {
|
||||
showHeader: false,
|
||||
styleClass: `${DialogSize.MD} ${DialogStyle.MINIMAL}`,
|
||||
})!;
|
||||
}
|
||||
|
||||
openLockUnlockMetadataDialog(bookIds: Set<number>): DynamicDialogRef | null {
|
||||
return this.openDialog(LockUnlockMetadataDialogComponent, {
|
||||
showHeader: false,
|
||||
styleClass: `${DialogSize.LG} ${DialogStyle.MINIMAL}`,
|
||||
data: {
|
||||
bookIds: Array.from(bookIds),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
openMetadataRefreshDialog(bookIds: Set<number>): DynamicDialogRef | null {
|
||||
return this.openDialog(MultiBookMetadataFetchComponent, {
|
||||
showHeader: false,
|
||||
styleClass: `${DialogSize.FULL} ${DialogStyle.MINIMAL}`,
|
||||
data: {
|
||||
bookIds: Array.from(bookIds),
|
||||
metadataRefreshType: MetadataRefreshType.BOOKS,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
openBulkMetadataEditDialog(bookIds: Set<number>): DynamicDialogRef | null {
|
||||
return this.openDialog(BulkMetadataUpdateComponent, {
|
||||
showHeader: false,
|
||||
styleClass: `${DialogSize.XL} ${DialogStyle.MINIMAL}`,
|
||||
data: {
|
||||
bookIds: Array.from(bookIds),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
openMultibookMetadataEditorDialog(bookIds: Set<number>): DynamicDialogRef | null {
|
||||
return this.openDialog(MultiBookMetadataEditorComponent, {
|
||||
showHeader: false,
|
||||
styleClass: `${DialogSize.FULL} ${DialogStyle.MINIMAL}`,
|
||||
data: {
|
||||
bookIds: Array.from(bookIds),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
openFileMoverDialog(bookIds: Set<number>): DynamicDialogRef | null {
|
||||
return this.openDialog(FileMoverComponent, {
|
||||
showHeader: false,
|
||||
styleClass: `${DialogSize.FULL} ${DialogStyle.MINIMAL}`,
|
||||
maximizable: true,
|
||||
data: {
|
||||
bookIds: Array.from(bookIds),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
openCustomSendDialog(book: Book): DynamicDialogRef | null {
|
||||
return this.openDialog(BookSenderComponent, {
|
||||
showHeader: false,
|
||||
styleClass: `${DialogSize.SM} ${DialogStyle.MINIMAL}`,
|
||||
data: {
|
||||
book: book,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
openCoverSearchDialog(bookId: number, coverType?: 'ebook' | 'audiobook'): DynamicDialogRef | null {
|
||||
return this.openDialog(CoverSearchComponent, {
|
||||
showHeader: false,
|
||||
styleClass: `${DialogSize.FULL} ${DialogStyle.MINIMAL}`,
|
||||
data: {
|
||||
bookId: bookId,
|
||||
coverType: coverType,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
openAdditionalFileUploaderDialog(book: Book): DynamicDialogRef | null {
|
||||
return this.openDialog(AdditionalFileUploaderComponent, {
|
||||
showHeader: false,
|
||||
styleClass: `${DialogSize.MD} ${DialogStyle.MINIMAL}`,
|
||||
data: {
|
||||
book: book,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
openBookFileAttacherDialog(sourceBook: Book): DynamicDialogRef | null {
|
||||
return this.openDialog(BookFileAttacherComponent, {
|
||||
showHeader: false,
|
||||
styleClass: `${DialogSize.MD} ${DialogStyle.MINIMAL}`,
|
||||
data: {
|
||||
sourceBook: sourceBook,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
openBulkBookFileAttacherDialog(sourceBooks: Book[]): DynamicDialogRef | null {
|
||||
return this.openDialog(BookFileAttacherComponent, {
|
||||
showHeader: false,
|
||||
styleClass: `${DialogSize.MD} ${DialogStyle.MINIMAL}`,
|
||||
data: {
|
||||
sourceBooks: sourceBooks,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
openDuplicateMergerDialog(libraryId: number): DynamicDialogRef | null {
|
||||
return this.openDialog(DuplicateMergerComponent, {
|
||||
showHeader: false,
|
||||
styleClass: `${DialogSize.XL} ${DialogStyle.MINIMAL}`,
|
||||
data: {
|
||||
libraryId: libraryId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
openAddPhysicalBookDialog(libraryId?: number): DynamicDialogRef | null {
|
||||
return this.openDialog(AddPhysicalBookDialogComponent, {
|
||||
showHeader: false,
|
||||
styleClass: `${DialogSize.LG} ${DialogStyle.MINIMAL}`,
|
||||
data: {
|
||||
libraryId: libraryId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
openBulkIsbnImportDialog(libraryId?: number): DynamicDialogRef | null {
|
||||
return this.openDialog(BulkIsbnImportDialogComponent, {
|
||||
showHeader: false,
|
||||
styleClass: `${DialogSize.LG} ${DialogStyle.MINIMAL}`,
|
||||
data: {
|
||||
libraryId: libraryId,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
import {inject, Injectable} from '@angular/core';
|
||||
import {ParamMap} from '@angular/router';
|
||||
import {Book} from '../../model/book.model';
|
||||
import {SortOption} from '../../model/sort.model';
|
||||
import {SortService} from '../../service/sort.service';
|
||||
import {filterBooksBySearchTerm} from './filters/HeaderFilter';
|
||||
import {filterBooksByFilters} from './filters/sidebar-filter';
|
||||
import {SeriesCollapseFilter} from './filters/SeriesCollapseFilter';
|
||||
import {QUERY_PARAMS} from './book-browser-query-params.service';
|
||||
import {BookFilterMode} from '../../../settings/user-management/user.service';
|
||||
|
||||
@Injectable({providedIn: 'root'})
|
||||
export class BookFilterOrchestrationService {
|
||||
private sortService = inject(SortService);
|
||||
|
||||
applyFilters(
|
||||
books: Book[],
|
||||
searchTerm: string,
|
||||
activeFilters: Record<string, unknown[]> | null,
|
||||
filterMode: BookFilterMode,
|
||||
seriesCollapseFilter: SeriesCollapseFilter,
|
||||
isSeriesCollapsed: boolean,
|
||||
forceExpandSeries: boolean,
|
||||
sortCriteria: SortOption[]
|
||||
): Book[] {
|
||||
const searchedBooks = filterBooksBySearchTerm(books, searchTerm);
|
||||
const filteredBooks = filterBooksByFilters(searchedBooks, activeFilters, filterMode);
|
||||
const collapsedBooks = seriesCollapseFilter.collapseBooks(filteredBooks, forceExpandSeries, isSeriesCollapsed);
|
||||
return this.sortService.applyMultiSort(collapsedBooks, sortCriteria);
|
||||
}
|
||||
|
||||
shouldForceExpandSeries(queryParamMap: ParamMap): boolean {
|
||||
const filterParam = queryParamMap.get(QUERY_PARAMS.FILTER);
|
||||
return !!filterParam && filterParam.split(',').some(pair => pair.trim().startsWith('series:'));
|
||||
}
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
<ng-container *transloco="let t; prefix: 'book.filter'">
|
||||
<div class="book-filter-container">
|
||||
|
||||
<div class="filter-header">
|
||||
<span class="filter-title">{{ t('title') }}</span>
|
||||
<p-selectButton
|
||||
[options]="filterModeOptions"
|
||||
[(ngModel)]="selectedFilterMode"
|
||||
optionLabel="label"
|
||||
optionValue="value"
|
||||
class="filter-mode-select"
|
||||
allowEmpty="false"
|
||||
></p-selectButton>
|
||||
</div>
|
||||
|
||||
<div class="filter-content">
|
||||
<p-accordion [value]="expandedPanels" [multiple]="true" (valueChange)="onExpandedPanelsChange($event)">
|
||||
@for (filterType of visibleFilterTypes; track trackByFilterType(i, filterType); let i = $index) {
|
||||
@if (filterSignals[filterType](); as filters) {
|
||||
@if (filters.length > 0) {
|
||||
<p-accordion-panel [value]="i">
|
||||
<p-accordion-header>
|
||||
<span class="filter-type-label">
|
||||
<span class="filter-label-text">
|
||||
{{ getFilterLabel(filterType) }}
|
||||
</span>
|
||||
@if (activeFilters[filterType]?.length) {
|
||||
<span class="active-filter-count">
|
||||
({{ activeFilters[filterType].length }})
|
||||
</span>
|
||||
}
|
||||
</span>
|
||||
</p-accordion-header>
|
||||
|
||||
<p-accordion-content>
|
||||
@if (expandedPanels.includes(i)) {
|
||||
<cdk-virtual-scroll-viewport
|
||||
[itemSize]="28"
|
||||
[style.height.px]="getVirtualScrollHeight(filters.length)"
|
||||
class="filter-list">
|
||||
<div
|
||||
*cdkVirtualFor="let filter of filters; trackBy: trackByFilter"
|
||||
class="filter-row"
|
||||
[ngClass]="{
|
||||
'active': activeFilters[filterType]?.includes(getFilterValueId(filter)),
|
||||
'active-not': activeFilters[filterType]?.includes(getFilterValueId(filter)) && selectedFilterMode === 'not'
|
||||
}"
|
||||
(click)="handleFilterClick(filterType, getFilterValueId(filter))">
|
||||
<span class="filter-value-text">{{ getFilterValueDisplay(filter) }}</span>
|
||||
<p-badge class="filter-value-badge" [value]="filter.bookCount"></p-badge>
|
||||
</div>
|
||||
</cdk-virtual-scroll-viewport>
|
||||
@if (truncatedFilters[filterType]) {
|
||||
<div class="truncation-notice">
|
||||
{{ t('showingFirst100') }}
|
||||
</div>
|
||||
}
|
||||
}
|
||||
</p-accordion-content>
|
||||
</p-accordion-panel>
|
||||
}
|
||||
}
|
||||
}
|
||||
</p-accordion>
|
||||
|
||||
<div class="footer-notice">
|
||||
{{ t('footerNote') }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
Executable
+129
@@ -0,0 +1,129 @@
|
||||
:host ::ng-deep p-accordion-header {
|
||||
--p-accordion-header-padding: 0.6rem 1rem;
|
||||
}
|
||||
|
||||
:host ::ng-deep .p-togglebutton {
|
||||
--p-togglebutton-content-padding: 0.25rem 0.35rem;
|
||||
}
|
||||
|
||||
:host ::ng-deep .cdk-virtual-scroll-orientation-vertical .cdk-virtual-scroll-content-wrapper {
|
||||
width: calc(var(--sidebar-width, 225px) - 35px) !important;
|
||||
min-width: unset;
|
||||
}
|
||||
|
||||
.book-filter-container {
|
||||
height: calc(100dvh - 6.1rem);
|
||||
border-radius: 0.75rem;
|
||||
overflow: hidden;
|
||||
background: var(--card-background);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
}
|
||||
|
||||
.filter-header {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 1rem;
|
||||
border-bottom: 1px solid var(--p-content-border-color);
|
||||
}
|
||||
|
||||
.filter-title {
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.filter-mode-select {
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
|
||||
:host ::ng-deep .filter-mode-select .p-togglebutton-label {
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
|
||||
.filter-content {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding-bottom: 1rem;
|
||||
overscroll-behavior: contain;
|
||||
}
|
||||
|
||||
.filter-type-label {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.25rem;
|
||||
max-width: 100%;
|
||||
overflow: hidden;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.filter-label-text {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
flex-shrink: 1;
|
||||
max-width: 175px;
|
||||
}
|
||||
|
||||
.active-filter-count {
|
||||
font-size: 0.875rem;
|
||||
color: var(--primary-color);
|
||||
flex-shrink: 0;
|
||||
white-space: nowrap;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.filter-list {
|
||||
padding-right: 0.25rem;
|
||||
}
|
||||
|
||||
.filter-row {
|
||||
cursor: pointer;
|
||||
transition: colors 200ms ease-in-out;
|
||||
height: 26px;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 0.5rem;
|
||||
max-width: 97%;
|
||||
|
||||
&.active {
|
||||
color: var(--primary-color);
|
||||
}
|
||||
|
||||
&.active-not {
|
||||
color: var(--p-red-400);
|
||||
text-decoration: line-through;
|
||||
}
|
||||
}
|
||||
|
||||
.filter-value-text {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.filter-value-badge {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.truncation-notice {
|
||||
font-size: 0.75rem;
|
||||
color: #6b7280;
|
||||
text-align: center;
|
||||
padding-top: 0.5rem;
|
||||
border-top: 1px solid #e5e7eb;
|
||||
}
|
||||
|
||||
.footer-notice {
|
||||
font-size: 0.75rem;
|
||||
color: #6b7280;
|
||||
text-align: center;
|
||||
padding-top: 1rem;
|
||||
padding-left: 1rem;
|
||||
padding-right: 1rem;
|
||||
margin-top: 0.5rem;
|
||||
}
|
||||
+236
@@ -0,0 +1,236 @@
|
||||
import {ChangeDetectionStrategy, Component, effect, EventEmitter, inject, Input, OnDestroy, OnInit, Output, Signal, signal} from '@angular/core';
|
||||
import {Subject, takeUntil} from 'rxjs';
|
||||
import {Library} from '../../../model/library.model';
|
||||
import {Shelf} from '../../../model/shelf.model';
|
||||
import {EntityType} from '../book-browser.component';
|
||||
import {Accordion, AccordionContent, AccordionHeader, AccordionPanel} from 'primeng/accordion';
|
||||
import {CdkFixedSizeVirtualScroll, CdkVirtualForOf, CdkVirtualScrollViewport} from '@angular/cdk/scrolling';
|
||||
import {NgClass} from '@angular/common';
|
||||
import {Badge} from 'primeng/badge';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {SelectButton} from 'primeng/selectbutton';
|
||||
import {BookFilterMode, DEFAULT_VISIBLE_FILTERS, UserService, VisibleFilterType} from '../../../../settings/user-management/user.service';
|
||||
import {MagicShelf} from '../../../../magic-shelf/service/magic-shelf.service';
|
||||
import {Filter, FILTER_LABEL_KEYS, FilterType} from './book-filter.config';
|
||||
import {BookFilterService} from './book-filter.service';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
interface FilterModeOption {
|
||||
label: string;
|
||||
value: BookFilterMode;
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-book-filter',
|
||||
templateUrl: './book-filter.component.html',
|
||||
styleUrls: ['./book-filter.component.scss'],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
standalone: true,
|
||||
imports: [
|
||||
Accordion, AccordionPanel, AccordionHeader, AccordionContent,
|
||||
CdkVirtualScrollViewport, CdkFixedSizeVirtualScroll, CdkVirtualForOf,
|
||||
NgClass, Badge, FormsModule, SelectButton,
|
||||
TranslocoDirective
|
||||
]
|
||||
})
|
||||
export class BookFilterComponent implements OnInit, OnDestroy {
|
||||
@Input() set entity(value: Library | Shelf | MagicShelf | null | undefined) {
|
||||
this.entitySignal.set(value ?? null);
|
||||
}
|
||||
@Input() set entityType(value: EntityType | undefined) {
|
||||
this.entityTypeSignal.set(value ?? EntityType.ALL_BOOKS);
|
||||
}
|
||||
@Input() resetFilter$!: Subject<void>;
|
||||
@Input() showFilter = false;
|
||||
|
||||
@Output() filterSelected = new EventEmitter<Record<string, unknown> | null>();
|
||||
@Output() filterModeChanged = new EventEmitter<BookFilterMode>();
|
||||
|
||||
private readonly filterService = inject(BookFilterService);
|
||||
private readonly userService = inject(UserService);
|
||||
private readonly t = inject(TranslocoService);
|
||||
private readonly destroy$ = new Subject<void>();
|
||||
|
||||
private readonly entitySignal = signal<Library | Shelf | MagicShelf | null>(null);
|
||||
private readonly entityTypeSignal = signal<EntityType>(EntityType.ALL_BOOKS);
|
||||
private readonly activeFiltersSignal = signal<Record<string, unknown[]> | null>(null);
|
||||
private readonly filterModeSignal = signal<BookFilterMode>('and');
|
||||
|
||||
activeFilters: Record<string, unknown[]> = {};
|
||||
filterSignals: Record<FilterType, Signal<Filter[]>> = this.filterService.createFilterSignals(
|
||||
this.entitySignal,
|
||||
this.entityTypeSignal,
|
||||
this.activeFiltersSignal,
|
||||
this.filterModeSignal
|
||||
);
|
||||
filterTypes: FilterType[] = Object.keys(this.filterSignals) as FilterType[];
|
||||
visibleFilterTypes: FilterType[] = [];
|
||||
expandedPanels: number[] = [0];
|
||||
truncatedFilters: Record<string, boolean> = {};
|
||||
|
||||
private _selectedFilterMode: BookFilterMode = 'and';
|
||||
private _visibleFilters: VisibleFilterType[] = [...DEFAULT_VISIBLE_FILTERS];
|
||||
|
||||
readonly filterLabelKeys = FILTER_LABEL_KEYS;
|
||||
|
||||
getFilterLabel(type: FilterType): string {
|
||||
const key = this.filterLabelKeys[type];
|
||||
return key ? this.t.translate(key) : type;
|
||||
}
|
||||
readonly filterModeOptions: FilterModeOption[] = [
|
||||
{label: 'AND', value: 'and'},
|
||||
{label: 'OR', value: 'or'},
|
||||
{label: 'NOT', value: 'not'},
|
||||
{label: '1', value: 'single'}
|
||||
];
|
||||
|
||||
get selectedFilterMode(): BookFilterMode {
|
||||
return this._selectedFilterMode;
|
||||
}
|
||||
|
||||
set selectedFilterMode(mode: BookFilterMode) {
|
||||
if (mode === this._selectedFilterMode) return;
|
||||
this._selectedFilterMode = mode;
|
||||
this.filterModeSignal.set(mode);
|
||||
this.filterModeChanged.emit(mode);
|
||||
this.emitFilters();
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.updateVisibleFilterTypes();
|
||||
this.updateExpandedPanels();
|
||||
this.subscribeToUserSettings();
|
||||
this.subscribeToReset();
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
}
|
||||
|
||||
handleFilterClick(filterType: string, value: unknown): void {
|
||||
if (this._selectedFilterMode === 'single') {
|
||||
this.handleSingleMode(filterType, value);
|
||||
} else {
|
||||
this.handleMultiMode(filterType, value);
|
||||
}
|
||||
this.emitFilters();
|
||||
}
|
||||
|
||||
setFilters(filters: Record<string, unknown>): void {
|
||||
this.activeFilters = {};
|
||||
for (const [key, value] of Object.entries(filters)) {
|
||||
const values = Array.isArray(value) ? value : [value];
|
||||
this.activeFilters[key] = values.map(v => this.filterService.processFilterValue(key, v));
|
||||
}
|
||||
this.emitFilters();
|
||||
}
|
||||
|
||||
clearActiveFilter(): void {
|
||||
this.activeFilters = {};
|
||||
this.expandedPanels = [0];
|
||||
this.activeFiltersSignal.set(null);
|
||||
this.filterSelected.emit(null);
|
||||
}
|
||||
|
||||
onExpandedPanelsChange(value: string | number | string[] | number[] | null | undefined): void {
|
||||
if (Array.isArray(value)) {
|
||||
this.expandedPanels = value.map(Number);
|
||||
}
|
||||
}
|
||||
|
||||
onFiltersChanged(): void {
|
||||
this.updateExpandedPanels();
|
||||
}
|
||||
|
||||
getVirtualScrollHeight = (itemCount: number): number => Math.min(itemCount * 28, 440);
|
||||
|
||||
trackByFilterType = (_: number, type: FilterType): string => type;
|
||||
|
||||
trackByFilter = (_: number, f: Filter): unknown => this.getFilterValueId(f);
|
||||
|
||||
getFilterValueId(f: Filter): unknown {
|
||||
const value = f.value;
|
||||
return typeof value === 'object' && value !== null && 'id' in value
|
||||
? value.id
|
||||
: f.value;
|
||||
}
|
||||
|
||||
getFilterValueDisplay(f: Filter): string {
|
||||
const value = f.value;
|
||||
if (typeof value === 'object' && value !== null && 'name' in value) {
|
||||
return String(value.name ?? '');
|
||||
}
|
||||
return String(value ?? '');
|
||||
}
|
||||
|
||||
private subscribeToUserSettings(): void {
|
||||
effect(() => {
|
||||
const user = this.userService.currentUser();
|
||||
if (!user) return;
|
||||
this._visibleFilters = user.userSettings.visibleFilters ?? [...DEFAULT_VISIBLE_FILTERS];
|
||||
this.updateVisibleFilterTypes();
|
||||
});
|
||||
}
|
||||
|
||||
private updateVisibleFilterTypes(): void {
|
||||
this.visibleFilterTypes = this._visibleFilters.filter(
|
||||
vf => this.filterTypes.includes(vf as FilterType)
|
||||
) as FilterType[];
|
||||
}
|
||||
|
||||
private subscribeToReset(): void {
|
||||
this.resetFilter$?.pipe(takeUntil(this.destroy$)).subscribe(() => this.clearActiveFilter());
|
||||
}
|
||||
|
||||
private handleSingleMode(filterType: string, value: unknown): void {
|
||||
const id = this.extractId(value);
|
||||
const current = this.activeFilters[filterType];
|
||||
const isSame = current?.length === 1 && this.valuesMatch(current[0], id);
|
||||
|
||||
this.activeFilters = isSame ? {} : {[filterType]: [id]};
|
||||
}
|
||||
|
||||
private handleMultiMode(filterType: string, value: unknown): void {
|
||||
const id = this.extractId(value);
|
||||
|
||||
if (!this.activeFilters[filterType]) {
|
||||
this.activeFilters[filterType] = [];
|
||||
}
|
||||
|
||||
const arr = this.activeFilters[filterType];
|
||||
const index = arr.findIndex(v => this.valuesMatch(v, id));
|
||||
|
||||
if (index > -1) {
|
||||
arr.splice(index, 1);
|
||||
if (arr.length === 0) delete this.activeFilters[filterType];
|
||||
} else {
|
||||
arr.push(id);
|
||||
}
|
||||
}
|
||||
|
||||
private extractId(value: unknown): unknown {
|
||||
return typeof value === 'object' && value !== null && 'id' in value
|
||||
? (value as { id: unknown }).id
|
||||
: value;
|
||||
}
|
||||
|
||||
private valuesMatch(a: unknown, b: unknown): boolean {
|
||||
return a === b || String(a) === String(b);
|
||||
}
|
||||
|
||||
private emitFilters(): void {
|
||||
const hasFilters = Object.keys(this.activeFilters).length > 0;
|
||||
const filtersToEmit = hasFilters ? {...this.activeFilters} : null;
|
||||
this.activeFiltersSignal.set(filtersToEmit);
|
||||
this.filterSelected.emit(filtersToEmit);
|
||||
}
|
||||
|
||||
private updateExpandedPanels(): void {
|
||||
const panels = new Set(this.expandedPanels);
|
||||
this.visibleFilterTypes.forEach((type, i) => {
|
||||
if (this.activeFilters[type]?.length) panels.add(i);
|
||||
});
|
||||
this.expandedPanels = panels.size > 0 ? [...panels] : [0];
|
||||
}
|
||||
}
|
||||
+365
@@ -0,0 +1,365 @@
|
||||
import {Book, ReadStatus} from '../../../model/book.model';
|
||||
|
||||
// ============================================================================
|
||||
// TYPES
|
||||
// ============================================================================
|
||||
|
||||
export interface FilterValue {
|
||||
id?: string | number;
|
||||
name?: string;
|
||||
sortIndex?: number;
|
||||
}
|
||||
|
||||
export interface Filter<T extends FilterValue = FilterValue> {
|
||||
value: T;
|
||||
bookCount: number;
|
||||
}
|
||||
|
||||
export type FilterType =
|
||||
| 'author' | 'category' | 'series' | 'bookType' | 'readStatus'
|
||||
| 'personalRating' | 'publisher' | 'matchScore' | 'library' | 'shelf'
|
||||
| 'shelfStatus' | 'tag' | 'publishedDate' | 'fileSize' | 'amazonRating'
|
||||
| 'goodreadsRating' | 'hardcoverRating' | 'language' | 'pageCount' | 'mood'
|
||||
| 'ageRating' | 'contentRating'
|
||||
| 'narrator'
|
||||
| 'comicCharacter' | 'comicTeam' | 'comicLocation' | 'comicCreator';
|
||||
|
||||
export type SortMode = 'count' | 'sortIndex';
|
||||
|
||||
export interface RangeConfig {
|
||||
id: number;
|
||||
label: string;
|
||||
min: number;
|
||||
max: number;
|
||||
sortIndex: number;
|
||||
}
|
||||
|
||||
export interface FilterConfig {
|
||||
label: string;
|
||||
extractor: (book: Book) => FilterValue[];
|
||||
sortMode: SortMode;
|
||||
isNumericId?: boolean;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// CONSTANTS
|
||||
// ============================================================================
|
||||
|
||||
export const READ_STATUS_LABELS: Readonly<Record<ReadStatus, string>> = {
|
||||
[ReadStatus.UNREAD]: 'Unread',
|
||||
[ReadStatus.READING]: 'Reading',
|
||||
[ReadStatus.RE_READING]: 'Re-reading',
|
||||
[ReadStatus.PARTIALLY_READ]: 'Partially Read',
|
||||
[ReadStatus.PAUSED]: 'Paused',
|
||||
[ReadStatus.READ]: 'Read',
|
||||
[ReadStatus.WONT_READ]: 'Won\'t Read',
|
||||
[ReadStatus.ABANDONED]: 'Abandoned',
|
||||
[ReadStatus.UNSET]: 'Unset'
|
||||
};
|
||||
|
||||
export const RATING_RANGES_5: readonly RangeConfig[] = [
|
||||
{id: 0, label: '0 to 1', min: 0, max: 1, sortIndex: 0},
|
||||
{id: 1, label: '1 to 2', min: 1, max: 2, sortIndex: 1},
|
||||
{id: 2, label: '2 to 3', min: 2, max: 3, sortIndex: 2},
|
||||
{id: 3, label: '3 to 4', min: 3, max: 4, sortIndex: 3},
|
||||
{id: 4, label: '4 to 4.5', min: 4, max: 4.5, sortIndex: 4},
|
||||
{id: 5, label: '4.5+', min: 4.5, max: Infinity, sortIndex: 5}
|
||||
];
|
||||
|
||||
export const RATING_OPTIONS_10: readonly RangeConfig[] = Array.from({length: 10}, (_, i) => ({
|
||||
id: i + 1,
|
||||
label: `${i + 1}`,
|
||||
min: i + 1,
|
||||
max: i + 2,
|
||||
sortIndex: i
|
||||
}));
|
||||
|
||||
export const FILE_SIZE_RANGES: readonly RangeConfig[] = [
|
||||
{id: 0, label: '< 1 MB', min: 0, max: 1024, sortIndex: 0},
|
||||
{id: 1, label: '1–10 MB', min: 1024, max: 10240, sortIndex: 1},
|
||||
{id: 2, label: '10–50 MB', min: 10240, max: 51200, sortIndex: 2},
|
||||
{id: 3, label: '50–100 MB', min: 51200, max: 102400, sortIndex: 3},
|
||||
{id: 4, label: '250–500 MB', min: 256000, max: 512000, sortIndex: 4},
|
||||
{id: 5, label: '0.5–1 GB', min: 512000, max: 1048576, sortIndex: 5},
|
||||
{id: 6, label: '1–2 GB', min: 1048576, max: 2097152, sortIndex: 6},
|
||||
{id: 7, label: '5+ GB', min: 5242880, max: Infinity, sortIndex: 7}
|
||||
];
|
||||
|
||||
export const PAGE_COUNT_RANGES: readonly RangeConfig[] = [
|
||||
{id: 0, label: '< 50 pages', min: 0, max: 50, sortIndex: 0},
|
||||
{id: 1, label: '50–100 pages', min: 50, max: 100, sortIndex: 1},
|
||||
{id: 2, label: '100–200 pages', min: 100, max: 200, sortIndex: 2},
|
||||
{id: 3, label: '200–400 pages', min: 200, max: 400, sortIndex: 3},
|
||||
{id: 4, label: '400–600 pages', min: 400, max: 600, sortIndex: 4},
|
||||
{id: 5, label: '600–1000 pages', min: 600, max: 1000, sortIndex: 5},
|
||||
{id: 6, label: '1000+ pages', min: 1000, max: Infinity, sortIndex: 6}
|
||||
];
|
||||
|
||||
export const MATCH_SCORE_RANGES: readonly RangeConfig[] = [
|
||||
{id: 0, min: 0.95, max: 1.01, label: 'Outstanding (95–100%)', sortIndex: 0},
|
||||
{id: 1, min: 0.90, max: 0.95, label: 'Excellent (90–94%)', sortIndex: 1},
|
||||
{id: 2, min: 0.80, max: 0.90, label: 'Great (80–89%)', sortIndex: 2},
|
||||
{id: 3, min: 0.70, max: 0.80, label: 'Good (70–79%)', sortIndex: 3},
|
||||
{id: 4, min: 0.50, max: 0.70, label: 'Fair (50–69%)', sortIndex: 4},
|
||||
{id: 5, min: 0.30, max: 0.50, label: 'Weak (30–49%)', sortIndex: 5},
|
||||
{id: 6, min: 0.00, max: 0.30, label: 'Poor (0–29%)', sortIndex: 6}
|
||||
];
|
||||
|
||||
export const AGE_RATING_OPTIONS: readonly RangeConfig[] = [
|
||||
{id: 0, min: 0, max: 1, label: 'All Ages', sortIndex: 0},
|
||||
{id: 6, min: 6, max: 7, label: '6+', sortIndex: 1},
|
||||
{id: 10, min: 10, max: 11, label: '10+', sortIndex: 2},
|
||||
{id: 13, min: 13, max: 14, label: '13+', sortIndex: 3},
|
||||
{id: 16, min: 16, max: 17, label: '16+', sortIndex: 4},
|
||||
{id: 18, min: 18, max: 19, label: '18+', sortIndex: 5},
|
||||
{id: 21, min: 21, max: 22, label: '21+', sortIndex: 6}
|
||||
];
|
||||
|
||||
export const CONTENT_RATING_LABELS: Readonly<Record<string, string>> = {
|
||||
'EVERYONE': 'Everyone',
|
||||
'TEEN': 'Teen',
|
||||
'MATURE': 'Mature',
|
||||
'ADULT': 'Adult',
|
||||
'EXPLICIT': 'Explicit'
|
||||
};
|
||||
|
||||
export const readStatusLabels = READ_STATUS_LABELS;
|
||||
export const ratingRanges = RATING_RANGES_5;
|
||||
export const ratingOptions10 = RATING_OPTIONS_10;
|
||||
export const fileSizeRanges = FILE_SIZE_RANGES;
|
||||
export const pageCountRanges = PAGE_COUNT_RANGES;
|
||||
export const matchScoreRanges = MATCH_SCORE_RANGES;
|
||||
|
||||
export const NUMERIC_ID_FILTER_TYPES = new Set<FilterType>([
|
||||
'personalRating', 'matchScore', 'fileSize', 'amazonRating',
|
||||
'goodreadsRating', 'hardcoverRating', 'pageCount', 'library', 'shelf',
|
||||
'ageRating'
|
||||
]);
|
||||
|
||||
export const FILTER_LABELS: Readonly<Record<FilterType, string>> = {
|
||||
author: 'Author',
|
||||
category: 'Genre',
|
||||
series: 'Series',
|
||||
bookType: 'File Format',
|
||||
readStatus: 'Read Status',
|
||||
personalRating: 'Personal Rating',
|
||||
publisher: 'Publisher',
|
||||
matchScore: 'Metadata Match Score',
|
||||
library: 'Library',
|
||||
shelf: 'Shelf',
|
||||
shelfStatus: 'Shelf Status',
|
||||
tag: 'Tag',
|
||||
publishedDate: 'Published Year',
|
||||
fileSize: 'File Size',
|
||||
amazonRating: 'Amazon Rating',
|
||||
goodreadsRating: 'Goodreads Rating',
|
||||
hardcoverRating: 'Hardcover Rating',
|
||||
language: 'Language',
|
||||
pageCount: 'Page Count',
|
||||
mood: 'Mood',
|
||||
ageRating: 'Age Rating',
|
||||
contentRating: 'Content Rating',
|
||||
narrator: 'Narrator',
|
||||
comicCharacter: 'Comic Character',
|
||||
comicTeam: 'Comic Team',
|
||||
comicLocation: 'Comic Location',
|
||||
comicCreator: 'Comic Creator'
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// FILTER EXTRACTORS
|
||||
// ============================================================================
|
||||
|
||||
const findInRange = (value: number | null | undefined, ranges: readonly RangeConfig[]): FilterValue[] => {
|
||||
if (value == null) return [];
|
||||
const match = ranges.find(r => value >= r.min && value < r.max);
|
||||
return match ? [{id: match.id, name: match.label, sortIndex: match.sortIndex}] : [];
|
||||
};
|
||||
|
||||
const findExactRating10 = (rating: number | undefined): FilterValue[] => {
|
||||
if (!rating || rating < 1 || rating > 10) return [];
|
||||
const match = RATING_OPTIONS_10.find(r => r.id === rating);
|
||||
return match ? [{id: match.id, name: match.label, sortIndex: match.sortIndex}] : [];
|
||||
};
|
||||
|
||||
const normalizeMatchScore = (score: number | null | undefined): number | null => {
|
||||
if (score == null) return null;
|
||||
return score > 1 ? score / 100 : score;
|
||||
};
|
||||
|
||||
const extractStringsAsFilters = (values: string[] | undefined): FilterValue[] =>
|
||||
values?.map(name => ({id: name, name})) ?? [];
|
||||
|
||||
const extractSingleString = (value: string | undefined | null): FilterValue[] =>
|
||||
value ? [{id: value, name: value}] : [];
|
||||
|
||||
const findExactAgeRating = (ageRating: number | null | undefined): FilterValue[] => {
|
||||
if (ageRating == null) return [];
|
||||
const match = AGE_RATING_OPTIONS.find(r => r.id === ageRating);
|
||||
return match ? [{id: match.id, name: match.label, sortIndex: match.sortIndex}] : [];
|
||||
};
|
||||
|
||||
export const FILTER_EXTRACTORS: Readonly<Record<Exclude<FilterType, 'library'>, (book: Book) => FilterValue[]>> = {
|
||||
author: (book) => extractStringsAsFilters(book.metadata?.authors),
|
||||
category: (book) => extractStringsAsFilters(book.metadata?.categories),
|
||||
series: (book) => extractSingleString(book.metadata?.seriesName?.trim()),
|
||||
bookType: (book) => book.isPhysical ? [{id: 'PHYSICAL', name: 'PHYSICAL'}] : extractSingleString(book.primaryFile?.bookType),
|
||||
readStatus: (book) => {
|
||||
const status = book.readStatus ?? ReadStatus.UNSET;
|
||||
const validStatus = status in READ_STATUS_LABELS ? status : ReadStatus.UNSET;
|
||||
return [{id: validStatus, name: READ_STATUS_LABELS[validStatus]}];
|
||||
},
|
||||
personalRating: (book) => findExactRating10(book.personalRating ?? undefined),
|
||||
publisher: (book) => extractSingleString(book.metadata?.publisher),
|
||||
matchScore: (book) => findInRange(normalizeMatchScore(book.metadataMatchScore), MATCH_SCORE_RANGES),
|
||||
shelf: (book) => book.shelves?.map(s => ({id: s.id, name: s.name})) ?? [],
|
||||
shelfStatus: (book) => {
|
||||
const isShelved = (book.shelves?.length ?? 0) > 0;
|
||||
return [{id: isShelved ? 'shelved' : 'unshelved', name: isShelved ? 'Shelved' : 'Unshelved'}];
|
||||
},
|
||||
tag: (book) => extractStringsAsFilters(book.metadata?.tags),
|
||||
publishedDate: (book) => {
|
||||
const date = book.metadata?.publishedDate;
|
||||
if (!date) return [];
|
||||
const year = new Date(date).getFullYear().toString();
|
||||
return [{id: year, name: year}];
|
||||
},
|
||||
fileSize: (book) => findInRange(book.fileSizeKb, FILE_SIZE_RANGES),
|
||||
amazonRating: (book) => findInRange(book.metadata?.amazonRating, RATING_RANGES_5),
|
||||
goodreadsRating: (book) => findInRange(book.metadata?.goodreadsRating, RATING_RANGES_5),
|
||||
hardcoverRating: (book) => findInRange(book.metadata?.hardcoverRating, RATING_RANGES_5),
|
||||
language: (book) => extractSingleString(book.metadata?.language),
|
||||
pageCount: (book) => findInRange(book.metadata?.pageCount, PAGE_COUNT_RANGES),
|
||||
mood: (book) => extractStringsAsFilters(book.metadata?.moods),
|
||||
ageRating: (book) => findExactAgeRating(book.metadata?.ageRating),
|
||||
contentRating: (book) => {
|
||||
const rating = book.metadata?.contentRating;
|
||||
if (!rating) return [];
|
||||
const label = CONTENT_RATING_LABELS[rating] ?? rating;
|
||||
return [{id: rating, name: label}];
|
||||
},
|
||||
narrator: (book) => extractSingleString(book.metadata?.narrator),
|
||||
comicCharacter: (book) => extractStringsAsFilters(book.metadata?.comicMetadata?.characters),
|
||||
comicTeam: (book) => extractStringsAsFilters(book.metadata?.comicMetadata?.teams),
|
||||
comicLocation: (book) => extractStringsAsFilters(book.metadata?.comicMetadata?.locations),
|
||||
comicCreator: (book) => {
|
||||
const comic = book.metadata?.comicMetadata;
|
||||
if (!comic) return [];
|
||||
const creators: FilterValue[] = [];
|
||||
const roleLabels: Record<string, string> = {
|
||||
penciller: 'Penciller', inker: 'Inker', colorist: 'Colorist',
|
||||
letterer: 'Letterer', coverArtist: 'Cover Artist', editor: 'Editor'
|
||||
};
|
||||
const roles: [string[] | undefined, string][] = [
|
||||
[comic.pencillers, 'penciller'],
|
||||
[comic.inkers, 'inker'],
|
||||
[comic.colorists, 'colorist'],
|
||||
[comic.letterers, 'letterer'],
|
||||
[comic.coverArtists, 'coverArtist'],
|
||||
[comic.editors, 'editor']
|
||||
];
|
||||
for (const [names, role] of roles) {
|
||||
if (names) {
|
||||
for (const name of names) {
|
||||
creators.push({id: `${name}:${role}`, name: `${name} (${roleLabels[role]})`});
|
||||
}
|
||||
}
|
||||
}
|
||||
return creators;
|
||||
}
|
||||
};
|
||||
|
||||
// Translation key for each FilterType — used by UI components to translate filter labels
|
||||
export const FILTER_LABEL_KEYS: Readonly<Record<FilterType, string>> = {
|
||||
author: 'book.filter.labels.author',
|
||||
category: 'book.filter.labels.category',
|
||||
series: 'book.filter.labels.series',
|
||||
bookType: 'book.filter.labels.bookType',
|
||||
readStatus: 'book.filter.labels.readStatus',
|
||||
personalRating: 'book.filter.labels.personalRating',
|
||||
publisher: 'book.filter.labels.publisher',
|
||||
matchScore: 'book.filter.labels.matchScore',
|
||||
library: 'book.filter.labels.library',
|
||||
shelf: 'book.filter.labels.shelf',
|
||||
shelfStatus: 'book.filter.labels.shelfStatus',
|
||||
tag: 'book.filter.labels.tag',
|
||||
publishedDate: 'book.filter.labels.publishedDate',
|
||||
fileSize: 'book.filter.labels.fileSize',
|
||||
amazonRating: 'book.filter.labels.amazonRating',
|
||||
goodreadsRating: 'book.filter.labels.goodreadsRating',
|
||||
hardcoverRating: 'book.filter.labels.hardcoverRating',
|
||||
language: 'book.filter.labels.language',
|
||||
pageCount: 'book.filter.labels.pageCount',
|
||||
mood: 'book.filter.labels.mood',
|
||||
ageRating: 'book.filter.labels.ageRating',
|
||||
contentRating: 'book.filter.labels.contentRating',
|
||||
narrator: 'book.filter.labels.narrator',
|
||||
comicCharacter: 'book.filter.labels.comicCharacter',
|
||||
comicTeam: 'book.filter.labels.comicTeam',
|
||||
comicLocation: 'book.filter.labels.comicLocation',
|
||||
comicCreator: 'book.filter.labels.comicCreator'
|
||||
};
|
||||
|
||||
export const READ_STATUS_LABEL_KEYS: Readonly<Record<ReadStatus, string>> = {
|
||||
[ReadStatus.UNREAD]: 'book.filter.readStatus.unread',
|
||||
[ReadStatus.READING]: 'book.filter.readStatus.reading',
|
||||
[ReadStatus.RE_READING]: 'book.filter.readStatus.reReading',
|
||||
[ReadStatus.PARTIALLY_READ]: 'book.filter.readStatus.partiallyRead',
|
||||
[ReadStatus.PAUSED]: 'book.filter.readStatus.paused',
|
||||
[ReadStatus.READ]: 'book.filter.readStatus.read',
|
||||
[ReadStatus.WONT_READ]: 'book.filter.readStatus.wontRead',
|
||||
[ReadStatus.ABANDONED]: 'book.filter.readStatus.abandoned',
|
||||
[ReadStatus.UNSET]: 'book.filter.readStatus.unset'
|
||||
};
|
||||
|
||||
export const CONTENT_RATING_LABEL_KEYS: Readonly<Record<string, string>> = {
|
||||
'EVERYONE': 'book.filter.contentRating.everyone',
|
||||
'TEEN': 'book.filter.contentRating.teen',
|
||||
'MATURE': 'book.filter.contentRating.mature',
|
||||
'ADULT': 'book.filter.contentRating.adult',
|
||||
'EXPLICIT': 'book.filter.contentRating.explicit'
|
||||
};
|
||||
|
||||
export const SHELF_STATUS_LABEL_KEYS: Readonly<Record<string, string>> = {
|
||||
'shelved': 'book.filter.shelfStatus.shelved',
|
||||
'unshelved': 'book.filter.shelfStatus.unshelved'
|
||||
};
|
||||
|
||||
|
||||
export const COMIC_ROLE_LABEL_KEYS: Readonly<Record<string, string>> = {
|
||||
penciller: 'book.filter.comicRoles.penciller',
|
||||
inker: 'book.filter.comicRoles.inker',
|
||||
colorist: 'book.filter.comicRoles.colorist',
|
||||
letterer: 'book.filter.comicRoles.letterer',
|
||||
coverArtist: 'book.filter.comicRoles.coverArtist',
|
||||
editor: 'book.filter.comicRoles.editor'
|
||||
};
|
||||
|
||||
export const FILTER_CONFIGS: Readonly<Record<Exclude<FilterType, 'library'>, Omit<FilterConfig, 'extractor'>>> = {
|
||||
author: {label: 'Author', sortMode: 'count'},
|
||||
category: {label: 'Genre', sortMode: 'count'},
|
||||
series: {label: 'Series', sortMode: 'count'},
|
||||
bookType: {label: 'Book Type', sortMode: 'count'},
|
||||
readStatus: {label: 'Read Status', sortMode: 'count'},
|
||||
personalRating: {label: 'Personal Rating', sortMode: 'sortIndex', isNumericId: true},
|
||||
publisher: {label: 'Publisher', sortMode: 'count'},
|
||||
matchScore: {label: 'Metadata Match Score', sortMode: 'sortIndex', isNumericId: true},
|
||||
shelf: {label: 'Shelf', sortMode: 'count', isNumericId: true},
|
||||
shelfStatus: {label: 'Shelf Status', sortMode: 'count'},
|
||||
tag: {label: 'Tag', sortMode: 'count'},
|
||||
publishedDate: {label: 'Published Year', sortMode: 'count'},
|
||||
fileSize: {label: 'File Size', sortMode: 'sortIndex', isNumericId: true},
|
||||
amazonRating: {label: 'Amazon Rating', sortMode: 'sortIndex', isNumericId: true},
|
||||
goodreadsRating: {label: 'Goodreads Rating', sortMode: 'sortIndex', isNumericId: true},
|
||||
hardcoverRating: {label: 'Hardcover Rating', sortMode: 'sortIndex', isNumericId: true},
|
||||
language: {label: 'Language', sortMode: 'count'},
|
||||
pageCount: {label: 'Page Count', sortMode: 'sortIndex', isNumericId: true},
|
||||
mood: {label: 'Mood', sortMode: 'count'},
|
||||
ageRating: {label: 'Age Rating', sortMode: 'sortIndex', isNumericId: true},
|
||||
contentRating: {label: 'Content Rating', sortMode: 'count'},
|
||||
narrator: {label: 'Narrator', sortMode: 'count'},
|
||||
comicCharacter: {label: 'Comic Character', sortMode: 'count'},
|
||||
comicTeam: {label: 'Comic Team', sortMode: 'count'},
|
||||
comicLocation: {label: 'Comic Location', sortMode: 'count'},
|
||||
comicCreator: {label: 'Comic Creator', sortMode: 'count'}
|
||||
};
|
||||
+168
@@ -0,0 +1,168 @@
|
||||
import {computed, inject, Injectable, Signal} from '@angular/core';
|
||||
import {Book} from '../../../model/book.model';
|
||||
import {Library} from '../../../model/library.model';
|
||||
import {Shelf} from '../../../model/shelf.model';
|
||||
import {MagicShelf} from '../../../../magic-shelf/service/magic-shelf.service';
|
||||
import {BookService} from '../../../service/book.service';
|
||||
import {LibraryService} from '../../../service/library.service';
|
||||
import {BookRuleEvaluatorService} from '../../../../magic-shelf/service/book-rule-evaluator.service';
|
||||
import {GroupRule} from '../../../../magic-shelf/component/magic-shelf-component';
|
||||
import {EntityType} from '../book-browser.component';
|
||||
import {Filter, FILTER_CONFIGS, FILTER_EXTRACTORS, FilterType, FilterValue, NUMERIC_ID_FILTER_TYPES, SortMode} from './book-filter.config';
|
||||
import {filterBooksByFilters} from '../filters/sidebar-filter';
|
||||
import {BookFilterMode} from '../../../../settings/user-management/user.service';
|
||||
|
||||
const MAX_FILTER_ITEMS = 100;
|
||||
|
||||
@Injectable({providedIn: 'root'})
|
||||
export class BookFilterService {
|
||||
private readonly bookService = inject(BookService);
|
||||
private readonly libraryService = inject(LibraryService);
|
||||
private readonly bookRuleEvaluatorService = inject(BookRuleEvaluatorService);
|
||||
|
||||
createFilterSignals(
|
||||
entity: Signal<Library | Shelf | MagicShelf | null>,
|
||||
entityType: Signal<EntityType>,
|
||||
activeFilters: Signal<Record<string, unknown[]> | null>,
|
||||
filterMode: Signal<BookFilterMode>
|
||||
): Record<FilterType, Signal<Filter[]>> {
|
||||
const filteredBooks = computed(() =>
|
||||
this.filterBooksByEntity(this.bookService.books(), entity(), entityType())
|
||||
);
|
||||
|
||||
const signals = {} as Record<FilterType, Signal<Filter[]>>;
|
||||
|
||||
for (const [type, config] of Object.entries(FILTER_CONFIGS)) {
|
||||
const filterType = type as Exclude<FilterType, 'library'>;
|
||||
signals[filterType] = computed(() => {
|
||||
const books = filterBooksByFilters(filteredBooks(), activeFilters(), filterMode(), filterType);
|
||||
return this.buildAndSortFilters(books, FILTER_EXTRACTORS[filterType], config.sortMode);
|
||||
});
|
||||
}
|
||||
|
||||
signals.library = computed(() => {
|
||||
const books = filterBooksByFilters(filteredBooks(), activeFilters(), filterMode(), 'library');
|
||||
const libraries = this.libraryService.libraries();
|
||||
|
||||
const libraryMap = new Map(
|
||||
libraries
|
||||
.filter(lib => lib.id !== undefined)
|
||||
.map(lib => [lib.id!, lib.name])
|
||||
);
|
||||
|
||||
const filterMap = new Map<number, Filter>();
|
||||
|
||||
for (const book of books) {
|
||||
if (book.libraryId == null) continue;
|
||||
|
||||
if (!filterMap.has(book.libraryId)) {
|
||||
filterMap.set(book.libraryId, {
|
||||
value: {
|
||||
id: book.libraryId,
|
||||
name: libraryMap.get(book.libraryId) || `Library ${book.libraryId}`
|
||||
},
|
||||
bookCount: 0
|
||||
});
|
||||
}
|
||||
filterMap.get(book.libraryId)!.bookCount++;
|
||||
}
|
||||
|
||||
return this.sortFiltersByCount(Array.from(filterMap.values()));
|
||||
});
|
||||
|
||||
return signals;
|
||||
}
|
||||
|
||||
filterBooksByEntity(
|
||||
books: Book[],
|
||||
entity: Library | Shelf | MagicShelf | null,
|
||||
entityType: EntityType
|
||||
): Book[] {
|
||||
if (!entity) return books;
|
||||
|
||||
switch (entityType) {
|
||||
case EntityType.LIBRARY:
|
||||
return books.filter(book => book.libraryId === (entity as Library).id);
|
||||
|
||||
case EntityType.SHELF: {
|
||||
const shelfId = (entity as Shelf).id;
|
||||
return books.filter(book => book.shelves?.some(s => s.id === shelfId));
|
||||
}
|
||||
|
||||
case EntityType.MAGIC_SHELF:
|
||||
return this.filterByMagicShelf(books, entity as MagicShelf);
|
||||
|
||||
default:
|
||||
return books;
|
||||
}
|
||||
}
|
||||
|
||||
processFilterValue(key: string, value: unknown): unknown {
|
||||
if (NUMERIC_ID_FILTER_TYPES.has(key as FilterType) && typeof value === 'string') {
|
||||
return Number(value);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
isNumericFilter(filterType: string): boolean {
|
||||
return NUMERIC_ID_FILTER_TYPES.has(filterType as FilterType);
|
||||
}
|
||||
|
||||
private buildAndSortFilters(
|
||||
books: Book[],
|
||||
extractor: (book: Book) => FilterValue[],
|
||||
sortMode: SortMode
|
||||
): Filter[] {
|
||||
const filterMap = new Map<unknown, Filter>();
|
||||
|
||||
for (const book of books) {
|
||||
for (const item of extractor(book)) {
|
||||
const id = item.id;
|
||||
if (!filterMap.has(id)) {
|
||||
filterMap.set(id, {value: item, bookCount: 0});
|
||||
}
|
||||
filterMap.get(id)!.bookCount++;
|
||||
}
|
||||
}
|
||||
|
||||
const filters = Array.from(filterMap.values());
|
||||
const sorted = sortMode === 'sortIndex'
|
||||
? this.sortFiltersBySortIndex(filters)
|
||||
: this.sortFiltersByCount(filters);
|
||||
|
||||
return sorted.slice(0, MAX_FILTER_ITEMS);
|
||||
}
|
||||
|
||||
private sortFiltersByCount(filters: Filter[]): Filter[] {
|
||||
return filters.sort((a, b) => {
|
||||
if (b.bookCount !== a.bookCount) return b.bookCount - a.bookCount;
|
||||
return this.compareNames(a, b);
|
||||
});
|
||||
}
|
||||
|
||||
private sortFiltersBySortIndex(filters: Filter[]): Filter[] {
|
||||
return filters.sort((a, b) => {
|
||||
const aIndex = (a.value as { sortIndex?: number }).sortIndex ?? 999;
|
||||
const bIndex = (b.value as { sortIndex?: number }).sortIndex ?? 999;
|
||||
if (aIndex !== bIndex) return aIndex - bIndex;
|
||||
return this.compareNames(a, b);
|
||||
});
|
||||
}
|
||||
|
||||
private compareNames(a: Filter, b: Filter): number {
|
||||
const aName = String((a.value as { name?: string }).name ?? '');
|
||||
const bName = String((b.value as { name?: string }).name ?? '');
|
||||
return aName.localeCompare(bName);
|
||||
}
|
||||
|
||||
private filterByMagicShelf(books: Book[], magicShelf: MagicShelf): Book[] {
|
||||
if (!magicShelf.filterJson) return [];
|
||||
try {
|
||||
const groupRule = JSON.parse(magicShelf.filterJson) as GroupRule;
|
||||
return books.filter(book => this.bookRuleEvaluatorService.evaluateGroup(book, groupRule, books));
|
||||
} catch {
|
||||
console.warn('Invalid filterJson for MagicShelf');
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
import {computed, Injectable, signal} from '@angular/core';
|
||||
import {Book} from '../../model/book.model';
|
||||
|
||||
export interface CheckboxClickEvent {
|
||||
index: number;
|
||||
book: Book;
|
||||
selected: boolean;
|
||||
shiftKey: boolean;
|
||||
}
|
||||
|
||||
@Injectable({providedIn: 'root'})
|
||||
export class BookSelectionService {
|
||||
private readonly _selectedBooks = signal<Set<number>>(new Set());
|
||||
readonly selectedBooks = this._selectedBooks.asReadonly();
|
||||
readonly selectedCount = computed(() => this._selectedBooks().size);
|
||||
|
||||
private currentBooks: Book[] = [];
|
||||
private lastSelectedIndex: number | null = null;
|
||||
|
||||
setCurrentBooks(books: Book[]): void {
|
||||
this.currentBooks = books;
|
||||
}
|
||||
|
||||
selectBook(book: Book): void {
|
||||
this._selectedBooks.update(current => {
|
||||
const next = new Set(current);
|
||||
if (book.seriesBooks) {
|
||||
book.seriesBooks.forEach(seriesBook => next.add(seriesBook.id));
|
||||
} else {
|
||||
next.add(book.id);
|
||||
}
|
||||
return next;
|
||||
});
|
||||
}
|
||||
|
||||
deselectBook(book: Book): void {
|
||||
this._selectedBooks.update(current => {
|
||||
const next = new Set(current);
|
||||
if (book.seriesBooks) {
|
||||
book.seriesBooks.forEach(seriesBook => next.delete(seriesBook.id));
|
||||
} else {
|
||||
next.delete(book.id);
|
||||
}
|
||||
return next;
|
||||
});
|
||||
}
|
||||
|
||||
handleCheckboxClick(event: CheckboxClickEvent): void {
|
||||
const {index, book, selected, shiftKey} = event;
|
||||
|
||||
if (!shiftKey || this.lastSelectedIndex === null) {
|
||||
this.handleBookSelection(book, selected);
|
||||
this.lastSelectedIndex = index;
|
||||
} else {
|
||||
const start = Math.min(this.lastSelectedIndex, index);
|
||||
const end = Math.max(this.lastSelectedIndex, index);
|
||||
const isUnselectingRange = !selected;
|
||||
|
||||
for (let i = start; i <= end; i++) {
|
||||
const rangeBook = this.currentBooks[i];
|
||||
if (!rangeBook) continue;
|
||||
this.handleBookSelection(rangeBook, !isUnselectingRange);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
handleBookSelection(book: Book, selected: boolean): void {
|
||||
if (selected) {
|
||||
this.selectBook(book);
|
||||
} else {
|
||||
this.deselectBook(book);
|
||||
}
|
||||
}
|
||||
|
||||
selectAll(): void {
|
||||
if (!this.currentBooks || this.currentBooks.length === 0) return;
|
||||
|
||||
this._selectedBooks.update(current => {
|
||||
const next = new Set(current);
|
||||
for (const book of this.currentBooks) {
|
||||
next.add(book.id);
|
||||
}
|
||||
return next;
|
||||
});
|
||||
}
|
||||
|
||||
deselectAll(): void {
|
||||
this._selectedBooks.set(new Set());
|
||||
this.lastSelectedIndex = null;
|
||||
}
|
||||
|
||||
setSelectedBooks(bookIds: Set<number>): void {
|
||||
this._selectedBooks.set(new Set(bookIds));
|
||||
}
|
||||
}
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
<ng-container *transloco="let t; prefix: 'book.table'">
|
||||
<p-table
|
||||
[value]="books"
|
||||
[columns]="visibleColumns"
|
||||
[dataKey]="'id'"
|
||||
[resizableColumns]="true"
|
||||
[reorderableColumns]="true"
|
||||
columnResizeMode="expand"
|
||||
[rowTrackBy]="trackByBookId"
|
||||
[metaKeySelection]="true"
|
||||
showGridlines
|
||||
stripedRows
|
||||
[scrollable]="true"
|
||||
[scrollHeight]="scrollHeight"
|
||||
[virtualScroll]="true"
|
||||
[virtualScrollItemSize]="46"
|
||||
[(selection)]="selectedBooks"
|
||||
(onHeaderCheckboxToggle)="onHeaderCheckboxToggle($event)"
|
||||
(onRowSelect)="onRowSelect($event)"
|
||||
(onRowUnselect)="onRowUnselect($event)"
|
||||
>
|
||||
<ng-template pTemplate="header">
|
||||
<tr>
|
||||
<th>
|
||||
<p-tableHeaderCheckbox/>
|
||||
</th>
|
||||
<th></th>
|
||||
<th class="cover-header-cell"></th>
|
||||
@for (col of visibleColumns; track col.field) {
|
||||
<th pResizableColumn>{{ col.header }}</th>
|
||||
}
|
||||
</tr>
|
||||
</ng-template>
|
||||
|
||||
<ng-template pTemplate="body" let-book>
|
||||
@if (book.metadata; as metadata) {
|
||||
<tr style="height:46px">
|
||||
<td>
|
||||
<p-tableCheckbox [value]="book"/>
|
||||
</td>
|
||||
<td class="cell-center">
|
||||
<p-button
|
||||
[icon]="isMetadataFullyLocked(metadata) ? 'pi pi-lock' : 'pi pi-lock-open'"
|
||||
[severity]="isMetadataFullyLocked(metadata) ? 'danger' : 'success'"
|
||||
[text]="true"
|
||||
[title]="isMetadataFullyLocked(metadata) ? t('locked') : t('unlocked')"
|
||||
size="small"
|
||||
[style]="{ width: '1.5rem', height: '1.5rem', padding: '0', fontSize: '0.75rem' }"
|
||||
(click)="toggleMetadataLock(metadata)">
|
||||
</p-button>
|
||||
</td>
|
||||
<td>
|
||||
<a [routerLink]="urlHelper.getBookUrl(book)">
|
||||
<img
|
||||
[attr.src]="urlHelper.getThumbnailUrl(metadata.bookId, metadata.coverUpdatedOn)"
|
||||
[alt]="t('bookCoverAlt')"
|
||||
class="cover-thumbnail"
|
||||
tooltipPosition="left"
|
||||
[pTooltip]="tooltipContent"
|
||||
tooltipStyleClass="cover-tooltip"
|
||||
/>
|
||||
</a>
|
||||
<ng-template #tooltipContent>
|
||||
<div class="tooltip-cover-container">
|
||||
<img
|
||||
[attr.src]="urlHelper.getThumbnailUrl(metadata.bookId, metadata.coverUpdatedOn)"
|
||||
[alt]="t('bookCoverAlt')"
|
||||
class="tooltip-cover-image"
|
||||
/>
|
||||
<em class="tooltip-cover-title">{{ metadata.title }}</em>
|
||||
</div>
|
||||
</ng-template>
|
||||
</td>
|
||||
|
||||
@for (col of visibleColumns; track col.field) {
|
||||
@if (col.field === 'readStatus') {
|
||||
<td class="cell-status">
|
||||
@if (shouldShowStatusIcon(book.readStatus)) {
|
||||
<div class="read-status-indicator"
|
||||
[ngClass]="getReadStatusClass(book.readStatus)"
|
||||
[pTooltip]="t('statusPrefix') + getReadStatusTooltip(book.readStatus)"
|
||||
tooltipPosition="top">
|
||||
<i [class]="getReadStatusIcon(book.readStatus)"></i>
|
||||
</div>
|
||||
}
|
||||
</td>
|
||||
} @else if (col.field === 'amazonRating' || col.field === 'goodreadsRating' || col.field === 'hardcoverRating' || col.field == 'ranobedbRating') {
|
||||
<td class="cell-rating">
|
||||
<span class="rating-wrapper">
|
||||
<p-rating
|
||||
[(ngModel)]="metadata[col.field]"
|
||||
readonly
|
||||
stars="5"
|
||||
[style.--p-rating-icon-active-color]="getStarColor(metadata[col.field])"
|
||||
></p-rating>
|
||||
@if (metadata[col.field] != null) {
|
||||
<span>({{ metadata[col.field]?.toFixed(1) }})</span>
|
||||
}
|
||||
</span>
|
||||
</td>
|
||||
} @else {
|
||||
<td
|
||||
[title]="getCellValue(metadata, book, col.field)"
|
||||
class="cell-text">
|
||||
@if(['title', 'authors', 'publisher', 'seriesName', 'categories', 'language'].includes(col.field)) {
|
||||
@for (item of getCellClickableValue(metadata, book, col.field); track $index; let isLast = $last) {
|
||||
<a [routerLink]="item.url" class="cell-link">
|
||||
{{ item.anchor }}</a>@if (!isLast) {<span>, </span>}
|
||||
}
|
||||
} @else {
|
||||
{{ getCellValue(metadata, book, col.field) }}
|
||||
}
|
||||
</td>
|
||||
}
|
||||
}
|
||||
</tr>
|
||||
}
|
||||
</ng-template>
|
||||
</p-table>
|
||||
</ng-container>
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
.read-status-indicator {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 0.875rem;
|
||||
font-weight: bold;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.status-read {
|
||||
color: #22c55e;
|
||||
}
|
||||
|
||||
.status-reading {
|
||||
color: #3b82f6;
|
||||
}
|
||||
|
||||
.status-re-reading {
|
||||
color: #06b6d4;
|
||||
}
|
||||
|
||||
.status-partially-read {
|
||||
color: #f59e0b;
|
||||
}
|
||||
|
||||
.status-paused {
|
||||
color: #eab308;
|
||||
}
|
||||
|
||||
.status-abandoned {
|
||||
color: #ef4444;
|
||||
}
|
||||
|
||||
.status-wont-read {
|
||||
color: #ec4899;
|
||||
}
|
||||
|
||||
.cover-header-cell {
|
||||
max-width: 3.5rem;
|
||||
min-width: 3.5rem;
|
||||
}
|
||||
|
||||
.cell-center {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.cover-thumbnail {
|
||||
width: 1.75rem;
|
||||
height: 1.75rem;
|
||||
}
|
||||
|
||||
.tooltip-cover-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.tooltip-cover-image {
|
||||
width: 40rem;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.tooltip-cover-title {
|
||||
font-size: 0.875rem;
|
||||
text-wrap: balance;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.cell-status {
|
||||
text-align: center;
|
||||
min-width: 4rem;
|
||||
max-width: 4rem;
|
||||
}
|
||||
|
||||
.cell-rating {
|
||||
min-width: 10rem;
|
||||
max-width: 10rem;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.rating-wrapper {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.25rem;
|
||||
}
|
||||
|
||||
.cell-text {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
text-align: right;
|
||||
min-width: 6rem;
|
||||
max-width: 12rem;
|
||||
}
|
||||
|
||||
.cell-link {
|
||||
&:hover {
|
||||
text-decoration: underline;
|
||||
color: #60a5fa;
|
||||
}
|
||||
}
|
||||
|
||||
::ng-deep .cover-tooltip > .p-tooltip-text {
|
||||
padding: 0.25rem;
|
||||
}
|
||||
+348
@@ -0,0 +1,348 @@
|
||||
import {Component, EventEmitter, inject, Input, OnChanges, OnDestroy, OnInit, Output} from '@angular/core';
|
||||
import {TableModule} from 'primeng/table';
|
||||
import {DatePipe, NgClass} from '@angular/common';
|
||||
import {Rating} from 'primeng/rating';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {TooltipModule} from "primeng/tooltip";
|
||||
import {Book, BookMetadata, ReadStatus} from '../../../model/book.model';
|
||||
import {SortOption} from '../../../model/sort.model';
|
||||
import {UrlHelperService} from '../../../../../shared/service/url-helper.service';
|
||||
import {Button} from 'primeng/button';
|
||||
import {BookService} from '../../../service/book.service';
|
||||
import {BookMetadataManageService} from '../../../service/book-metadata-manage.service';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {RouterLink} from '@angular/router';
|
||||
import {Subject} from 'rxjs';
|
||||
import {UserService} from '../../../../settings/user-management/user.service';
|
||||
import {ReadStatusHelper} from '../../../helpers/read-status.helper';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
@Component({
|
||||
selector: 'app-book-table',
|
||||
standalone: true,
|
||||
templateUrl: './book-table.component.html',
|
||||
imports: [
|
||||
TableModule,
|
||||
Rating,
|
||||
FormsModule,
|
||||
Button,
|
||||
TooltipModule,
|
||||
NgClass,
|
||||
RouterLink,
|
||||
TranslocoDirective
|
||||
],
|
||||
styleUrls: ['./book-table.component.scss'],
|
||||
providers: [DatePipe]
|
||||
})
|
||||
export class BookTableComponent implements OnInit, OnDestroy, OnChanges {
|
||||
selectedBooks: Book[] = [];
|
||||
selectedBookIds = new Set<number>();
|
||||
|
||||
@Output() selectedBooksChange = new EventEmitter<Set<number>>();
|
||||
@Input() books: Book[] = [];
|
||||
@Input() sortOption: SortOption | null = null;
|
||||
@Input() visibleColumns: { field: string; header: string }[] = [];
|
||||
@Input() preselectedBookIds = new Set<number>();
|
||||
|
||||
protected urlHelper = inject(UrlHelperService);
|
||||
private bookService = inject(BookService);
|
||||
private bookMetadataManageService = inject(BookMetadataManageService);
|
||||
private messageService = inject(MessageService);
|
||||
private userService = inject(UserService);
|
||||
private datePipe = inject(DatePipe);
|
||||
private readStatusHelper = inject(ReadStatusHelper);
|
||||
private readonly t = inject(TranslocoService);
|
||||
|
||||
private metadataCenterViewMode: 'route' | 'dialog' = 'route';
|
||||
private destroy$ = new Subject<void>();
|
||||
|
||||
readonly allColumns: { field: string; header: string }[] = [
|
||||
{field: 'readStatus', header: this.t.translate('book.columnPref.columns.readStatus')},
|
||||
{field: 'title', header: this.t.translate('book.columnPref.columns.title')},
|
||||
{field: 'authors', header: this.t.translate('book.columnPref.columns.authors')},
|
||||
{field: 'publisher', header: this.t.translate('book.columnPref.columns.publisher')},
|
||||
{field: 'seriesName', header: this.t.translate('book.columnPref.columns.seriesName')},
|
||||
{field: 'seriesNumber', header: this.t.translate('book.columnPref.columns.seriesNumber')},
|
||||
{field: 'categories', header: this.t.translate('book.columnPref.columns.categories')},
|
||||
{field: 'publishedDate', header: this.t.translate('book.columnPref.columns.publishedDate')},
|
||||
{field: 'lastReadTime', header: this.t.translate('book.columnPref.columns.lastReadTime')},
|
||||
{field: 'addedOn', header: this.t.translate('book.columnPref.columns.addedOn')},
|
||||
{field: 'fileName', header: this.t.translate('book.columnPref.columns.fileName')},
|
||||
{field: 'fileSizeKb', header: this.t.translate('book.columnPref.columns.fileSizeKb')},
|
||||
{field: 'language', header: this.t.translate('book.columnPref.columns.language')},
|
||||
{field: 'isbn', header: this.t.translate('book.columnPref.columns.isbn')},
|
||||
{field: 'pageCount', header: this.t.translate('book.columnPref.columns.pageCount')},
|
||||
{field: 'amazonRating', header: this.t.translate('book.columnPref.columns.amazonRating')},
|
||||
{field: 'amazonReviewCount', header: this.t.translate('book.columnPref.columns.amazonReviewCount')},
|
||||
{field: 'goodreadsRating', header: this.t.translate('book.columnPref.columns.goodreadsRating')},
|
||||
{field: 'goodreadsReviewCount', header: this.t.translate('book.columnPref.columns.goodreadsReviewCount')},
|
||||
{field: 'hardcoverRating', header: this.t.translate('book.columnPref.columns.hardcoverRating')},
|
||||
{field: 'hardcoverReviewCount', header: this.t.translate('book.columnPref.columns.hardcoverReviewCount')},
|
||||
{field: 'ranobedbRating', header: this.t.translate('book.columnPref.columns.ranobedbRating')},
|
||||
];
|
||||
|
||||
scrollHeight = 'calc(100dvh - 160px)';
|
||||
|
||||
ngOnInit(): void {
|
||||
const user = this.userService.currentUser();
|
||||
if (user) {
|
||||
this.metadataCenterViewMode = user.userSettings.metadataCenterViewMode ?? 'route';
|
||||
}
|
||||
|
||||
this.selectedBookIds = this.preselectedBookIds;
|
||||
this.selectedBooks = this.bookService.getBooksByIds([...this.selectedBookIds]);
|
||||
this.setScrollHeight();
|
||||
window.addEventListener('resize', this.setScrollHeight.bind(this));
|
||||
}
|
||||
|
||||
setScrollHeight() {
|
||||
const isMobile = window.innerWidth <= 768;
|
||||
this.scrollHeight = isMobile
|
||||
? 'calc(100dvh - 125px)'
|
||||
: 'calc(100dvh - 150px)';
|
||||
}
|
||||
|
||||
ngOnChanges() {
|
||||
const wrapperElements: HTMLCollection = document.getElementsByClassName('p-virtualscroller');
|
||||
Array.prototype.forEach.call(wrapperElements, function (wrapperElement) {
|
||||
wrapperElement.style["height"] = 'calc(100dvh - 160px)';
|
||||
});
|
||||
}
|
||||
|
||||
selectAllBooks(): void {
|
||||
this.selectedBookIds = new Set(this.books.map(book => book.id));
|
||||
this.selectedBooks = [...this.books];
|
||||
this.selectedBooksChange.emit(this.selectedBookIds);
|
||||
}
|
||||
|
||||
clearSelectedBooks(): void {
|
||||
this.selectedBookIds.clear();
|
||||
this.selectedBooks = [];
|
||||
this.selectedBooksChange.emit(this.selectedBookIds);
|
||||
}
|
||||
|
||||
onRowSelect(event: { data?: Book | Book[] }): void {
|
||||
if (event.data && !Array.isArray(event.data)) {
|
||||
this.selectedBookIds.add(event.data.id);
|
||||
this.selectedBooksChange.emit(this.selectedBookIds);
|
||||
}
|
||||
}
|
||||
|
||||
onRowUnselect(event: { data?: Book | Book[] }): void {
|
||||
if (event.data && !Array.isArray(event.data)) {
|
||||
this.selectedBookIds.delete(event.data.id);
|
||||
this.selectedBooksChange.emit(this.selectedBookIds);
|
||||
}
|
||||
}
|
||||
|
||||
onHeaderCheckboxToggle(event: { checked: boolean }): void {
|
||||
if (event.checked) {
|
||||
this.selectedBooks = [...this.books];
|
||||
this.selectedBookIds = new Set(this.books.map(book => book.id));
|
||||
} else {
|
||||
this.clearSelectedBooks();
|
||||
}
|
||||
this.selectedBooksChange.emit(this.selectedBookIds);
|
||||
}
|
||||
|
||||
getStarColor(rating: number): string {
|
||||
if (rating >= 4.5) {
|
||||
return 'rgb(34, 197, 94)';
|
||||
} else if (rating >= 4) {
|
||||
return 'rgb(52, 211, 153)';
|
||||
} else if (rating >= 3.5) {
|
||||
return 'rgb(234, 179, 8)';
|
||||
} else if (rating >= 2.5) {
|
||||
return 'rgb(249, 115, 22)';
|
||||
} else {
|
||||
return 'rgb(239, 68, 68)';
|
||||
}
|
||||
}
|
||||
|
||||
getAuthorNames(authors: string[]): string {
|
||||
return authors?.join(', ') || '';
|
||||
}
|
||||
|
||||
getGenres(genres: string[]) {
|
||||
return genres?.join(', ') || '';
|
||||
}
|
||||
|
||||
trackByBookId(index: number, book: Book): number {
|
||||
return book.id;
|
||||
}
|
||||
|
||||
isMetadataFullyLocked(metadata: BookMetadata): boolean {
|
||||
const lockedKeys = Object.keys(metadata).filter(key => key.endsWith('Locked'));
|
||||
if (lockedKeys.length === 0) return false;
|
||||
return lockedKeys.every(key => metadata[key] === true);
|
||||
}
|
||||
|
||||
formatFileSize(kb?: number): string {
|
||||
if (kb == null || isNaN(kb)) return '-';
|
||||
const mb = kb / 1024;
|
||||
return mb >= 1 ? `${mb.toFixed(1)} MB` : `${mb.toFixed(2)} MB`;
|
||||
}
|
||||
|
||||
getReadStatusIcon(readStatus: ReadStatus | undefined): string {
|
||||
return this.readStatusHelper.getReadStatusIcon(readStatus);
|
||||
}
|
||||
|
||||
getReadStatusClass(readStatus: ReadStatus | undefined): string {
|
||||
return this.readStatusHelper.getReadStatusClass(readStatus);
|
||||
}
|
||||
|
||||
getReadStatusTooltip(readStatus: ReadStatus | undefined): string {
|
||||
return this.readStatusHelper.getReadStatusTooltip(readStatus);
|
||||
}
|
||||
|
||||
shouldShowStatusIcon(readStatus: ReadStatus | undefined): boolean {
|
||||
return this.readStatusHelper.shouldShowStatusIcon(readStatus);
|
||||
}
|
||||
|
||||
getCellClickableValue(metadata: BookMetadata, book: Book, field: string) {
|
||||
const filterKeys: Record<string, string> = {
|
||||
'authors': 'author',
|
||||
'publisher': 'publisher',
|
||||
'categories': 'category',
|
||||
'language': 'language',
|
||||
'title': 'title',
|
||||
'isbn': 'isbn'
|
||||
} as const;
|
||||
|
||||
let data: string[] = [metadata[field] as string];
|
||||
|
||||
switch (field) {
|
||||
case 'title':
|
||||
return [
|
||||
{
|
||||
url: this.urlHelper.getBookUrl(book),
|
||||
anchor: metadata.title ?? book.fileName
|
||||
}
|
||||
];
|
||||
|
||||
case 'categories':
|
||||
data = metadata.categories ?? [];
|
||||
break;
|
||||
|
||||
case 'authors':
|
||||
data = metadata.authors ?? [];
|
||||
break;
|
||||
|
||||
case 'seriesName':
|
||||
return [
|
||||
{
|
||||
url: this.urlHelper.filterBooksBy('series', metadata.seriesName ?? ''),
|
||||
anchor: metadata.seriesName
|
||||
}
|
||||
]
|
||||
case 'isbn':
|
||||
return [
|
||||
{
|
||||
url: '',
|
||||
anchor: this.getCellValue(metadata, book, 'isbn')
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
return data.map(item => {
|
||||
return {
|
||||
url: this.urlHelper.filterBooksBy(filterKeys[field] ?? field, item),
|
||||
anchor: item
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getCellValue(metadata: BookMetadata, book: Book, field: string): string | number {
|
||||
switch (field) {
|
||||
case 'readStatus':
|
||||
return this.readStatusHelper.getReadStatusTooltip(book?.readStatus);
|
||||
|
||||
case 'title':
|
||||
return metadata.title ?? '';
|
||||
|
||||
case 'authors':
|
||||
return this.getAuthorNames(metadata.authors!);
|
||||
|
||||
case 'publisher':
|
||||
return metadata.publisher ?? '';
|
||||
|
||||
case 'seriesName':
|
||||
return metadata.seriesName ?? '';
|
||||
|
||||
case 'seriesNumber':
|
||||
return metadata.seriesNumber ?? '';
|
||||
|
||||
case 'categories':
|
||||
return this.getGenres(metadata.categories!);
|
||||
|
||||
case 'publishedDate':
|
||||
return metadata.publishedDate ? this.datePipe.transform(metadata.publishedDate, 'dd-MMM-yyyy') ?? '' : '';
|
||||
|
||||
case 'lastReadTime':
|
||||
return book.lastReadTime ? this.datePipe.transform(book.lastReadTime, 'dd-MMM-yyyy') ?? '' : '';
|
||||
|
||||
case 'addedOn':
|
||||
return book.addedOn ? this.datePipe.transform(book.addedOn, 'dd-MMM-yyyy') ?? '' : '';
|
||||
|
||||
case 'fileName':
|
||||
return book.primaryFile?.fileName ?? '';
|
||||
|
||||
case 'fileSizeKb':
|
||||
return this.formatFileSize(book.fileSizeKb);
|
||||
|
||||
case 'language':
|
||||
return metadata.language ?? '';
|
||||
|
||||
case 'pageCount':
|
||||
return metadata.pageCount ?? '';
|
||||
|
||||
case 'amazonRating':
|
||||
case 'goodreadsRating':
|
||||
case 'hardcoverRating':
|
||||
case 'ranobedbRating': {
|
||||
const rating = metadata[field];
|
||||
return typeof rating === 'number' ? rating.toFixed(1) : '';
|
||||
}
|
||||
|
||||
case 'amazonReviewCount':
|
||||
case 'goodreadsReviewCount':
|
||||
case 'hardcoverReviewCount':
|
||||
return metadata[field] ?? '';
|
||||
|
||||
case 'isbn':
|
||||
return metadata.isbn13 || metadata.isbn10 || '';
|
||||
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
toggleMetadataLock(metadata: BookMetadata): void {
|
||||
const lockKeys = Object.keys(metadata).filter(key => key.endsWith('Locked'));
|
||||
const allLocked = lockKeys.every(key => metadata[key] === true);
|
||||
const lockAction = allLocked ? 'UNLOCK' : 'LOCK';
|
||||
|
||||
this.bookMetadataManageService.toggleAllLock(new Set([metadata.bookId]), lockAction).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: lockAction === 'LOCK' ? this.t.translate('book.table.toast.metadataLockedSummary') : this.t.translate('book.table.toast.metadataUnlockedSummary'),
|
||||
detail: lockAction === 'LOCK' ? this.t.translate('book.table.toast.metadataLockedDetail') : this.t.translate('book.table.toast.metadataUnlockedDetail'),
|
||||
});
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: lockAction === 'LOCK' ? this.t.translate('book.table.toast.lockFailedSummary') : this.t.translate('book.table.toast.unlockFailedSummary'),
|
||||
detail: lockAction === 'LOCK' ? this.t.translate('book.table.toast.lockFailedDetail') : this.t.translate('book.table.toast.unlockFailedDetail'),
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
window.removeEventListener('resize', this.setScrollHeight.bind(this));
|
||||
}
|
||||
}
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
import {computed, inject, Injectable, signal} from '@angular/core';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {TranslocoService} from '@jsverse/transloco';
|
||||
import {LocalStorageService} from '../../../../shared/service/local-storage.service';
|
||||
import {Book} from '../../model/book.model';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class CoverScalePreferenceService {
|
||||
|
||||
private readonly BASE_WIDTH = 135;
|
||||
private readonly BASE_HEIGHT = 220;
|
||||
private readonly TITLE_BAR_HEIGHT = 31;
|
||||
private readonly DEBOUNCE_MS = 1000;
|
||||
private readonly STORAGE_KEY = 'coverScalePreference';
|
||||
|
||||
private readonly messageService = inject(MessageService);
|
||||
private readonly t = inject(TranslocoService);
|
||||
private readonly localStorageService = inject(LocalStorageService);
|
||||
|
||||
private readonly _scaleFactor = signal(1.0);
|
||||
readonly scaleFactor = this._scaleFactor.asReadonly();
|
||||
|
||||
readonly currentCardSize = computed(() => ({
|
||||
width: Math.round(this.BASE_WIDTH * this.scaleFactor()),
|
||||
height: Math.round(this.BASE_HEIGHT * this.scaleFactor()),
|
||||
}));
|
||||
readonly gridColumnMinWidth = computed(() => `${this.currentCardSize().width}px`);
|
||||
|
||||
private saveTimeout: ReturnType<typeof setTimeout> | null = null;
|
||||
private lastPersistedScale = 1.0;
|
||||
|
||||
constructor() {
|
||||
const initialScale = this.loadScaleFromStorage();
|
||||
this._scaleFactor.set(initialScale);
|
||||
this.lastPersistedScale = initialScale;
|
||||
}
|
||||
|
||||
setScale(scale: number): void {
|
||||
this._scaleFactor.set(scale);
|
||||
if (scale === this.lastPersistedScale) {
|
||||
return;
|
||||
}
|
||||
this.scheduleSave(scale);
|
||||
}
|
||||
|
||||
getCardHeight(_book: Book): number {
|
||||
// Use uniform height for all book types to ensure smooth virtual scrolling.
|
||||
// Mixed heights cause choppy/jumpy scrolling because the virtual scroller
|
||||
// cannot accurately estimate positions when item heights vary.
|
||||
return this.currentCardSize().height;
|
||||
}
|
||||
|
||||
private scheduleSave(scale: number): void {
|
||||
if (this.saveTimeout) {
|
||||
clearTimeout(this.saveTimeout);
|
||||
}
|
||||
|
||||
this.saveTimeout = setTimeout(() => {
|
||||
this.saveScalePreference(scale);
|
||||
}, this.DEBOUNCE_MS);
|
||||
}
|
||||
|
||||
private saveScalePreference(scale: number): void {
|
||||
try {
|
||||
this.localStorageService.set(this.STORAGE_KEY, scale);
|
||||
this.lastPersistedScale = scale;
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('book.coverPref.toast.savedSummary'),
|
||||
detail: this.t.translate('book.coverPref.toast.savedDetail', {scale: scale.toFixed(2)}),
|
||||
life: 1500
|
||||
});
|
||||
} catch (e) {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('book.coverPref.toast.saveFailedSummary'),
|
||||
detail: this.t.translate('book.coverPref.toast.saveFailedDetail'),
|
||||
life: 3000
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private loadScaleFromStorage(): number {
|
||||
const saved = this.localStorageService.get<number>(this.STORAGE_KEY);
|
||||
if (saved !== null && !isNaN(saved)) {
|
||||
return saved;
|
||||
}
|
||||
return 1.0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
import {fileSizeRanges, matchScoreRanges, pageCountRanges, ratingOptions10, ratingRanges} from './book-filter/book-filter.config';
|
||||
|
||||
export class FilterLabelHelper {
|
||||
private static readonly FILTER_TYPE_MAP: Record<string, string> = {
|
||||
author: 'Author',
|
||||
category: 'Genre',
|
||||
series: 'Series',
|
||||
publisher: 'Publisher',
|
||||
readStatus: 'Read Status',
|
||||
personalRating: 'Personal Rating',
|
||||
publishedDate: 'Year Published',
|
||||
matchScore: 'Metadata Match Score',
|
||||
language: 'Language',
|
||||
bookType: 'Book Type',
|
||||
shelfStatus: 'Shelf Status',
|
||||
fileSize: 'File Size',
|
||||
pageCount: 'Page Count',
|
||||
amazonRating: 'Amazon Rating',
|
||||
goodreadsRating: 'Goodreads Rating',
|
||||
hardcoverRating: 'Hardcover Rating',
|
||||
ranobedbRating: 'Ranobedb Rating',
|
||||
mood: 'Mood',
|
||||
tag: 'Tag',
|
||||
};
|
||||
|
||||
static getFilterTypeName(filterType: string): string {
|
||||
return this.FILTER_TYPE_MAP[filterType] || this.capitalize(filterType);
|
||||
}
|
||||
|
||||
static getFilterDisplayValue(filterType: string, value: string | number): string {
|
||||
const numericValue = typeof value === 'string' ? Number(value) : value;
|
||||
|
||||
switch (filterType.toLowerCase()) {
|
||||
case 'filesize': {
|
||||
const fileSizeRange = fileSizeRanges.find(r => r.id === numericValue);
|
||||
if (fileSizeRange) return fileSizeRange.label;
|
||||
return String(value);
|
||||
}
|
||||
|
||||
case 'pagecount': {
|
||||
const pageCountRange = pageCountRanges.find(r => r.id === numericValue);
|
||||
if (pageCountRange) return pageCountRange.label;
|
||||
return String(value);
|
||||
}
|
||||
|
||||
case 'matchscore': {
|
||||
const matchScoreRange = matchScoreRanges.find(r => r.id === numericValue);
|
||||
if (matchScoreRange) return matchScoreRange.label;
|
||||
return String(value);
|
||||
}
|
||||
|
||||
case 'personalrating': {
|
||||
const personalRating = ratingOptions10.find(r => r.id === numericValue);
|
||||
if (personalRating) return personalRating.label;
|
||||
return String(value);
|
||||
}
|
||||
|
||||
case 'amazonrating':
|
||||
case 'goodreadsrating':
|
||||
case 'hardcoverrating': {
|
||||
const ratingRange = ratingRanges.find(r => r.id === numericValue);
|
||||
if (ratingRange) return ratingRange.label;
|
||||
return String(value);
|
||||
}
|
||||
|
||||
default:
|
||||
return String(value);
|
||||
}
|
||||
}
|
||||
|
||||
private static capitalize(str: string): string {
|
||||
return str.charAt(0).toUpperCase() + str.slice(1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import {Book} from '../../../model/book.model';
|
||||
|
||||
export function normalizeSearchTerm(str: string): string {
|
||||
if (!str) return '';
|
||||
// Normalize Unicode combining characters (e.g., é -> e)
|
||||
let s = str.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
|
||||
s = s.replace(/ø/gi, 'o')
|
||||
.replace(/ł/gi, 'l')
|
||||
.replace(/æ/gi, 'ae')
|
||||
.replace(/œ/gi, 'oe')
|
||||
.replace(/ß/g, 'ss');
|
||||
s = s.replace(/[!@$%^&*_=|~`<>?/";']/g, '');
|
||||
s = s.replace(/\s+/g, ' ').trim();
|
||||
return s.toLowerCase();
|
||||
}
|
||||
|
||||
export function filterBooksBySearchTerm(books: Book[], term: string): Book[] {
|
||||
const normalizedTerm = normalizeSearchTerm(term || '').trim();
|
||||
if (normalizedTerm.length < 2) {
|
||||
return books;
|
||||
}
|
||||
|
||||
return books.filter(book => {
|
||||
const title = book.metadata?.title || '';
|
||||
const series = book.metadata?.seriesName || '';
|
||||
const authors = book.metadata?.authors || [];
|
||||
const categories = book.metadata?.categories || [];
|
||||
const isbn = book.metadata?.isbn10 || '';
|
||||
const isbn13 = book.metadata?.isbn13 || '';
|
||||
const fileName = book.primaryFile?.fileName || '';
|
||||
|
||||
const matchesTitle = normalizeSearchTerm(title).includes(normalizedTerm);
|
||||
const matchesSeries = normalizeSearchTerm(series).includes(normalizedTerm);
|
||||
const matchesAuthor = authors.some(author => normalizeSearchTerm(author).includes(normalizedTerm));
|
||||
const matchesCategory = categories.some(category => normalizeSearchTerm(category).includes(normalizedTerm));
|
||||
const matchesIsbn = normalizeSearchTerm(isbn).includes(normalizedTerm) || normalizeSearchTerm(isbn13).includes(normalizedTerm);
|
||||
const matchesFileName = normalizeSearchTerm(fileName).includes(normalizedTerm);
|
||||
|
||||
return matchesTitle || matchesSeries || matchesAuthor || matchesCategory || matchesIsbn || matchesFileName;
|
||||
});
|
||||
}
|
||||
|
||||
+169
@@ -0,0 +1,169 @@
|
||||
import {effect, inject, Injectable, signal} from '@angular/core';
|
||||
import {Book} from '../../../model/book.model';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {UserService} from '../../../../settings/user-management/user.service';
|
||||
|
||||
@Injectable({providedIn: 'root'})
|
||||
export class SeriesCollapseFilter {
|
||||
private static readonly PERSIST_DELAY_MS = 500;
|
||||
|
||||
private readonly userService = inject(UserService);
|
||||
private readonly messageService = inject(MessageService);
|
||||
|
||||
private readonly _seriesCollapsed = signal(false);
|
||||
readonly seriesCollapsed = this._seriesCollapsed.asReadonly();
|
||||
private currentContext: { type: 'LIBRARY' | 'SHELF' | 'MAGIC_SHELF', id: number } | null = null;
|
||||
private persistTimeout: ReturnType<typeof setTimeout> | null = null;
|
||||
|
||||
constructor() {
|
||||
effect(() => {
|
||||
const user = this.userService.currentUser();
|
||||
if (user) {
|
||||
this.applyPreference();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
setContext(type: 'LIBRARY' | 'SHELF' | 'MAGIC_SHELF' | null, id: number | null): void {
|
||||
if (type && id) {
|
||||
this.currentContext = {type, id};
|
||||
} else {
|
||||
this.currentContext = null;
|
||||
}
|
||||
this.applyPreference();
|
||||
}
|
||||
|
||||
setCollapsed(value: boolean): void {
|
||||
this._seriesCollapsed.set(value);
|
||||
this.schedulePersist(value);
|
||||
}
|
||||
|
||||
private applyPreference(): void {
|
||||
const user = this.userService.getCurrentUser();
|
||||
const prefs = user?.userSettings?.entityViewPreferences;
|
||||
|
||||
let collapsed = false;
|
||||
|
||||
if (prefs) {
|
||||
// Backward compatibility: check for old 'seriesCollapse' field
|
||||
const legacyGlobalSeriesCollapse = (prefs.global as { seriesCollapse?: boolean }).seriesCollapse;
|
||||
collapsed = prefs.global?.seriesCollapsed ?? legacyGlobalSeriesCollapse ?? false;
|
||||
|
||||
if (this.currentContext) {
|
||||
const override = prefs.overrides?.find(o =>
|
||||
o.entityType === this.currentContext?.type && o.entityId === this.currentContext?.id
|
||||
);
|
||||
if (override) {
|
||||
const legacyOverrideSeriesCollapse = (override.preferences as { seriesCollapse?: boolean }).seriesCollapse;
|
||||
if (override.preferences.seriesCollapsed !== undefined) {
|
||||
collapsed = override.preferences.seriesCollapsed;
|
||||
} else if (legacyOverrideSeriesCollapse !== undefined) {
|
||||
collapsed = legacyOverrideSeriesCollapse;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this._seriesCollapsed() !== collapsed) {
|
||||
this._seriesCollapsed.set(collapsed);
|
||||
}
|
||||
}
|
||||
|
||||
collapseBooks(books: Book[], forceExpandSeries?: boolean, isSeriesCollapsed: boolean = this.seriesCollapsed()): Book[] {
|
||||
const shouldCollapse = forceExpandSeries ? false : isSeriesCollapsed;
|
||||
if (!shouldCollapse || books.length === 0) return books;
|
||||
|
||||
const sourceBooks = [...books];
|
||||
const seriesMap = new Map<string, Book[]>();
|
||||
const collapsedBooks: Book[] = [];
|
||||
|
||||
for (const book of sourceBooks) {
|
||||
const seriesName = book.metadata?.seriesName?.trim();
|
||||
if (seriesName) {
|
||||
if (!seriesMap.has(seriesName)) {
|
||||
seriesMap.set(seriesName, []);
|
||||
}
|
||||
seriesMap.get(seriesName)!.push(book);
|
||||
} else {
|
||||
collapsedBooks.push(book);
|
||||
}
|
||||
}
|
||||
|
||||
for (const group of seriesMap.values()) {
|
||||
const sortedGroup = group.slice().sort((a, b) => {
|
||||
const aNum = a.metadata?.seriesNumber ?? Number.MAX_VALUE;
|
||||
const bNum = b.metadata?.seriesNumber ?? Number.MAX_VALUE;
|
||||
return aNum - bNum;
|
||||
});
|
||||
const firstBook = sortedGroup[0];
|
||||
collapsedBooks.push({
|
||||
...firstBook,
|
||||
seriesBooks: group,
|
||||
seriesCount: group.length
|
||||
});
|
||||
}
|
||||
|
||||
return collapsedBooks;
|
||||
}
|
||||
|
||||
private schedulePersist(isCollapsed: boolean): void {
|
||||
if (this.persistTimeout) {
|
||||
clearTimeout(this.persistTimeout);
|
||||
}
|
||||
|
||||
this.persistTimeout = setTimeout(() => {
|
||||
this.persistCollapsePreference(isCollapsed);
|
||||
}, SeriesCollapseFilter.PERSIST_DELAY_MS);
|
||||
}
|
||||
|
||||
private persistCollapsePreference(isCollapsed: boolean): void {
|
||||
const user = this.userService.getCurrentUser();
|
||||
if (!user) return;
|
||||
|
||||
const prefs = structuredClone(user.userSettings.entityViewPreferences ?? {
|
||||
global: {
|
||||
sortKey: 'addedOn',
|
||||
sortDir: 'DESC',
|
||||
view: 'GRID',
|
||||
coverSize: 1.0,
|
||||
seriesCollapsed: false
|
||||
},
|
||||
overrides: []
|
||||
});
|
||||
|
||||
if (!prefs.overrides) {
|
||||
prefs.overrides = [];
|
||||
}
|
||||
|
||||
if (this.currentContext) {
|
||||
let override = prefs.overrides.find(o =>
|
||||
o.entityType === this.currentContext?.type && o.entityId === this.currentContext?.id
|
||||
);
|
||||
|
||||
if (!override) {
|
||||
override = {
|
||||
entityType: this.currentContext.type,
|
||||
entityId: this.currentContext.id,
|
||||
preferences: {
|
||||
...prefs.global,
|
||||
seriesCollapsed: isCollapsed
|
||||
}
|
||||
};
|
||||
prefs.overrides.push(override);
|
||||
} else {
|
||||
override.preferences.seriesCollapsed = isCollapsed;
|
||||
}
|
||||
} else {
|
||||
prefs.global.seriesCollapsed = isCollapsed;
|
||||
}
|
||||
|
||||
this.userService.updateUserSetting(user.id, 'entityViewPreferences', prefs);
|
||||
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Preference Saved',
|
||||
detail: `Series collapse set to ${isCollapsed ? 'enabled' : 'disabled'}${this.currentContext ? ' for this view' : ' globally'}.`,
|
||||
life: 1500
|
||||
});
|
||||
}
|
||||
}
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
import {inject, Injectable, signal} from '@angular/core';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {TranslocoService} from '@jsverse/transloco';
|
||||
import {LocalStorageService} from '../../../../../shared/service/local-storage.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class SidebarFilterTogglePrefService {
|
||||
|
||||
private readonly STORAGE_KEY = 'showSidebarFilter';
|
||||
private readonly messageService = inject(MessageService);
|
||||
private readonly t = inject(TranslocoService);
|
||||
private readonly localStorageService = inject(LocalStorageService);
|
||||
|
||||
private readonly _showFilter = signal(true);
|
||||
readonly showFilter = this._showFilter.asReadonly();
|
||||
|
||||
constructor() {
|
||||
const isNarrow = window.innerWidth <= 768;
|
||||
this._showFilter.set(!isNarrow);
|
||||
this.loadFromStorage();
|
||||
}
|
||||
|
||||
toggle(): void {
|
||||
this.setShowFilter(!this.showFilter());
|
||||
}
|
||||
|
||||
setShowFilter(value: boolean): void {
|
||||
if (this._showFilter() !== value) {
|
||||
this._showFilter.set(value);
|
||||
this.savePreference(value);
|
||||
}
|
||||
}
|
||||
|
||||
private savePreference(value: boolean): void {
|
||||
try {
|
||||
this.localStorageService.set(this.STORAGE_KEY, value);
|
||||
} catch (e) {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('book.filterPref.toast.saveFailedSummary'),
|
||||
detail: this.t.translate('book.filterPref.toast.saveFailedDetail'),
|
||||
life: 3000
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private loadFromStorage(): void {
|
||||
const isNarrow = window.innerWidth <= 768;
|
||||
if (isNarrow) {
|
||||
this._showFilter.set(false);
|
||||
} else {
|
||||
const saved = this.localStorageService.get<boolean>(this.STORAGE_KEY);
|
||||
this._showFilter.set(saved !== null ? saved : true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,194 @@
|
||||
import {fileSizeRanges, matchScoreRanges, pageCountRanges, ratingRanges} from '../book-filter/book-filter.config';
|
||||
import {Book, ReadStatus} from '../../../model/book.model';
|
||||
import {BookFilterMode} from '../../../../settings/user-management/user.service';
|
||||
|
||||
export function isRatingInRange(rating: number | undefined | null, rangeId: string | number): boolean {
|
||||
if (rating == null) return false;
|
||||
const numericId = typeof rangeId === 'string' ? Number(rangeId) : rangeId;
|
||||
const range = ratingRanges.find(r => r.id === numericId);
|
||||
if (!range) return false;
|
||||
return rating >= range.min && rating < range.max;
|
||||
}
|
||||
|
||||
export function isRatingInRange10(rating: number | undefined | null, rangeId: string | number): boolean {
|
||||
if (rating == null) return false;
|
||||
const numericId = typeof rangeId === 'string' ? Number(rangeId) : rangeId;
|
||||
return Math.round(rating) === numericId;
|
||||
}
|
||||
|
||||
export function isFileSizeInRange(fileSizeKb: number | undefined, rangeId: string | number): boolean {
|
||||
if (fileSizeKb == null) return false;
|
||||
const numericId = typeof rangeId === 'string' ? Number(rangeId) : rangeId;
|
||||
const range = fileSizeRanges.find(r => r.id === numericId);
|
||||
if (!range) return false;
|
||||
return fileSizeKb >= range.min && fileSizeKb < range.max;
|
||||
}
|
||||
|
||||
export function isPageCountInRange(pageCount: number | undefined, rangeId: string | number): boolean {
|
||||
if (pageCount == null) return false;
|
||||
const numericId = typeof rangeId === 'string' ? Number(rangeId) : rangeId;
|
||||
const range = pageCountRanges.find(r => r.id === numericId);
|
||||
if (!range) return false;
|
||||
return pageCount >= range.min && pageCount < range.max;
|
||||
}
|
||||
|
||||
export function isMatchScoreInRange(score: number | undefined | null, rangeId: string | number): boolean {
|
||||
if (score == null) return false;
|
||||
const normalizedScore = score > 1 ? score / 100 : score;
|
||||
const numericId = typeof rangeId === 'string' ? Number(rangeId) : rangeId;
|
||||
const range = matchScoreRanges.find(r => r.id === numericId);
|
||||
if (!range) return false;
|
||||
return normalizedScore >= range.min && normalizedScore < range.max;
|
||||
}
|
||||
|
||||
export function doesBookMatchReadStatus(book: Book, selected: unknown[]): boolean {
|
||||
const status = book.readStatus ?? ReadStatus.UNSET;
|
||||
return selected.includes(status);
|
||||
}
|
||||
|
||||
export function doesBookMatchFilter(
|
||||
book: Book,
|
||||
filterType: string,
|
||||
filterValues: unknown[],
|
||||
mode: BookFilterMode
|
||||
): boolean {
|
||||
if (!Array.isArray(filterValues) || filterValues.length === 0) {
|
||||
return mode === 'or';
|
||||
}
|
||||
|
||||
const effectiveMode = mode === 'not' ? 'or' : mode;
|
||||
|
||||
switch (filterType) {
|
||||
case 'author':
|
||||
return effectiveMode === 'or'
|
||||
? filterValues.some(val => book.metadata?.authors?.includes(val as string))
|
||||
: filterValues.every(val => book.metadata?.authors?.includes(val as string));
|
||||
case 'category':
|
||||
return effectiveMode === 'or'
|
||||
? filterValues.some(val => book.metadata?.categories?.includes(val as string))
|
||||
: filterValues.every(val => book.metadata?.categories?.includes(val as string));
|
||||
case 'series':
|
||||
return effectiveMode === 'or'
|
||||
? filterValues.some(val => book.metadata?.seriesName?.trim() === val)
|
||||
: filterValues.every(val => book.metadata?.seriesName?.trim() === val);
|
||||
case 'bookType':
|
||||
return book.isPhysical ? filterValues.includes('PHYSICAL') : filterValues.includes(book.primaryFile?.bookType);
|
||||
case 'readStatus':
|
||||
return doesBookMatchReadStatus(book, filterValues);
|
||||
case 'personalRating':
|
||||
return filterValues.some(range => isRatingInRange10(book.personalRating, range as string | number));
|
||||
case 'publisher':
|
||||
return effectiveMode === 'or'
|
||||
? filterValues.some(val => book.metadata?.publisher === val)
|
||||
: filterValues.every(val => book.metadata?.publisher === val);
|
||||
case 'matchScore':
|
||||
return filterValues.some(range => isMatchScoreInRange(book.metadataMatchScore, range as string | number));
|
||||
case 'library':
|
||||
return effectiveMode === 'or'
|
||||
? filterValues.some(val => val == book.libraryId)
|
||||
: filterValues.every(val => val == book.libraryId);
|
||||
case 'shelf':
|
||||
return effectiveMode === 'or'
|
||||
? filterValues.some(val => book.shelves?.some(s => s.id == val))
|
||||
: filterValues.every(val => book.shelves?.some(s => s.id == val));
|
||||
case 'shelfStatus': {
|
||||
const shelved = book.shelves && book.shelves.length > 0 ? 'shelved' : 'unshelved';
|
||||
return filterValues.includes(shelved);
|
||||
}
|
||||
case 'tag':
|
||||
return effectiveMode === 'or'
|
||||
? filterValues.some(val => book.metadata?.tags?.includes(val as string))
|
||||
: filterValues.every(val => book.metadata?.tags?.includes(val as string));
|
||||
case 'publishedDate': {
|
||||
const bookYear = book.metadata?.publishedDate
|
||||
? new Date(book.metadata.publishedDate).getFullYear()
|
||||
: null;
|
||||
return bookYear ? filterValues.some(val => val == bookYear || val == bookYear.toString()) : false;
|
||||
}
|
||||
case 'fileSize':
|
||||
return filterValues.some(range => isFileSizeInRange(book.fileSizeKb, range as string | number));
|
||||
case 'amazonRating':
|
||||
return filterValues.some(range => isRatingInRange(book.metadata?.amazonRating, range as string | number));
|
||||
case 'goodreadsRating':
|
||||
return filterValues.some(range => isRatingInRange(book.metadata?.goodreadsRating, range as string | number));
|
||||
case 'hardcoverRating':
|
||||
return filterValues.some(range => isRatingInRange(book.metadata?.hardcoverRating, range as string | number));
|
||||
case 'language':
|
||||
return filterValues.includes(book.metadata?.language);
|
||||
case 'pageCount':
|
||||
return filterValues.some(range => isPageCountInRange(book.metadata?.pageCount ?? undefined, range as string | number));
|
||||
case 'mood':
|
||||
return effectiveMode === 'or'
|
||||
? filterValues.some(val => book.metadata?.moods?.includes(val as string))
|
||||
: filterValues.every(val => book.metadata?.moods?.includes(val as string));
|
||||
case 'ageRating':
|
||||
return filterValues.some(val => {
|
||||
const numVal = typeof val === 'string' ? Number(val) : val;
|
||||
return book.metadata?.ageRating === numVal;
|
||||
});
|
||||
case 'contentRating':
|
||||
return filterValues.includes(book.metadata?.contentRating);
|
||||
case 'narrator':
|
||||
return filterValues.includes(book.metadata?.narrator);
|
||||
case 'comicCharacter':
|
||||
return effectiveMode === 'or'
|
||||
? filterValues.some(val => book.metadata?.comicMetadata?.characters?.includes(val as string))
|
||||
: filterValues.every(val => book.metadata?.comicMetadata?.characters?.includes(val as string));
|
||||
case 'comicTeam':
|
||||
return effectiveMode === 'or'
|
||||
? filterValues.some(val => book.metadata?.comicMetadata?.teams?.includes(val as string))
|
||||
: filterValues.every(val => book.metadata?.comicMetadata?.teams?.includes(val as string));
|
||||
case 'comicLocation':
|
||||
return effectiveMode === 'or'
|
||||
? filterValues.some(val => book.metadata?.comicMetadata?.locations?.includes(val as string))
|
||||
: filterValues.every(val => book.metadata?.comicMetadata?.locations?.includes(val as string));
|
||||
case 'comicCreator': {
|
||||
const comic = book.metadata?.comicMetadata;
|
||||
if (!comic) return false;
|
||||
const allCreators: string[] = [];
|
||||
const roles: [string[] | undefined, string][] = [
|
||||
[comic.pencillers, 'penciller'],
|
||||
[comic.inkers, 'inker'],
|
||||
[comic.colorists, 'colorist'],
|
||||
[comic.letterers, 'letterer'],
|
||||
[comic.coverArtists, 'coverArtist'],
|
||||
[comic.editors, 'editor']
|
||||
];
|
||||
for (const [names, role] of roles) {
|
||||
if (names) {
|
||||
for (const name of names) {
|
||||
allCreators.push(`${name}:${role}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
return effectiveMode === 'or'
|
||||
? filterValues.some(val => allCreators.includes(val as string))
|
||||
: filterValues.every(val => allCreators.includes(val as string));
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export function filterBooksByFilters(
|
||||
books: Book[],
|
||||
activeFilters: Record<string, unknown[]> | null,
|
||||
mode: BookFilterMode,
|
||||
excludeFilterType?: string
|
||||
): Book[] {
|
||||
if (!activeFilters) return books;
|
||||
|
||||
const filterEntries = Object.entries(activeFilters)
|
||||
.filter(([type]) => type !== excludeFilterType);
|
||||
|
||||
if (filterEntries.length === 0) return books;
|
||||
|
||||
return books.filter(book => {
|
||||
const matches = filterEntries.map(([filterType, filterValues]) =>
|
||||
doesBookMatchFilter(book, filterType, filterValues, mode)
|
||||
);
|
||||
if (mode === 'not') return matches.every(m => !m);
|
||||
return mode === 'or' ? matches.some(m => m) : matches.every(m => m);
|
||||
});
|
||||
}
|
||||
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
<ng-container *transloco="let t; prefix: 'book.lockUnlockDialog'">
|
||||
<div class="lock-unlock-container">
|
||||
<div class="panel-header">
|
||||
<div class="header-icon-wrapper">
|
||||
<i class="pi pi-lock header-icon"></i>
|
||||
</div>
|
||||
<div class="header-text">
|
||||
<h2 class="panel-title">{{ t('title') }}</h2>
|
||||
<p class="panel-description">{{ t('selectedCount', { count: bookIds.size }) }}</p>
|
||||
</div>
|
||||
<p-button
|
||||
icon="pi pi-times"
|
||||
[rounded]="true"
|
||||
[text]="true"
|
||||
severity="secondary"
|
||||
(click)="dialogRef.close()"
|
||||
class="close-button">
|
||||
</p-button>
|
||||
</div>
|
||||
|
||||
<div class="dialog-content">
|
||||
<div class="fields-grid">
|
||||
@for (field of lockableFields; track field) {
|
||||
<div class="field-row">
|
||||
<label class="field-label">{{ fieldLabels[field] || field }}</label>
|
||||
<p-button
|
||||
[outlined]="true"
|
||||
[label]="getLockLabel(field)"
|
||||
[icon]="getLockIcon(field)"
|
||||
[severity]="fieldLocks[field] === true ? 'danger' : fieldLocks[field] === false ? 'success' : 'secondary'"
|
||||
(click)="cycleLockState(field)"
|
||||
></p-button>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="dialog-footer">
|
||||
<div class="footer-actions">
|
||||
<p-button icon="pi pi-refresh" [label]="t('reset')" outlined="true" severity="warn" (onClick)="resetFieldLocks()"></p-button>
|
||||
</div>
|
||||
<div class="footer-actions">
|
||||
<p-button icon="pi pi-lock" [label]="t('lockAll')" outlined="true" severity="danger" (onClick)="toggleLockAll('LOCK')"></p-button>
|
||||
<p-button icon="pi pi-lock-open" [label]="t('unlockAll')" outlined="true" severity="success" (onClick)="toggleLockAll('UNLOCK')"></p-button>
|
||||
<p-divider layout="vertical"></p-divider>
|
||||
<p-button [label]="isSaving ? t('saving') : t('save')" [outlined]="true" icon="pi pi-check" severity="info" (onClick)="applyFieldLocks()" [disabled]="bookIds.size === 0 || isSaving"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
@use '../../../../../shared/styles/panel-shared' as panel;
|
||||
|
||||
.lock-unlock-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.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-bottom: none;
|
||||
}
|
||||
|
||||
.dialog-footer {
|
||||
@include panel.dialog-footer;
|
||||
}
|
||||
|
||||
.footer-actions {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.fields-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(1, minmax(0, 1fr));
|
||||
column-gap: 6rem;
|
||||
row-gap: 1rem;
|
||||
|
||||
@media (min-width: 576px) {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
}
|
||||
}
|
||||
|
||||
.field-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.field-label {
|
||||
text-transform: capitalize;
|
||||
}
|
||||
+155
@@ -0,0 +1,155 @@
|
||||
import {Component, inject, OnInit} from '@angular/core';
|
||||
import {Button} from 'primeng/button';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
|
||||
import {DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {BookMetadataManageService} from '../../../service/book-metadata-manage.service';
|
||||
import {Divider} from 'primeng/divider';
|
||||
import {LoadingService} from '../../../../../core/services/loading.service';
|
||||
import {finalize} from 'rxjs';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
@Component({
|
||||
selector: 'app-lock-unlock-metadata-dialog',
|
||||
standalone: true,
|
||||
imports: [
|
||||
Button,
|
||||
FormsModule,
|
||||
Divider,
|
||||
TranslocoDirective
|
||||
],
|
||||
templateUrl: './lock-unlock-metadata-dialog.component.html',
|
||||
styleUrl: './lock-unlock-metadata-dialog.component.scss'
|
||||
})
|
||||
export class LockUnlockMetadataDialogComponent implements OnInit {
|
||||
private bookMetadataManageService = inject(BookMetadataManageService);
|
||||
private dynamicDialogConfig = inject(DynamicDialogConfig);
|
||||
dialogRef = inject(DynamicDialogRef);
|
||||
private messageService = inject(MessageService);
|
||||
private loadingService = inject(LoadingService);
|
||||
private readonly t = inject(TranslocoService);
|
||||
fieldLocks: Record<string, boolean | undefined> = {};
|
||||
|
||||
bookIds: Set<number> = this.dynamicDialogConfig.data.bookIds;
|
||||
|
||||
lockableFields: string[] = [
|
||||
'titleLocked', 'subtitleLocked', 'publisherLocked', 'publishedDateLocked', 'descriptionLocked',
|
||||
'isbn13Locked', 'isbn10Locked', 'asinLocked', 'pageCountLocked', 'thumbnailLocked', 'languageLocked', 'coverLocked',
|
||||
'seriesNameLocked', 'seriesNumberLocked', 'seriesTotalLocked', 'authorsLocked', 'categoriesLocked', 'moodsLocked', 'tagsLocked',
|
||||
'amazonRatingLocked', 'amazonReviewCountLocked', 'goodreadsRatingLocked', 'goodreadsReviewCountLocked',
|
||||
'hardcoverRatingLocked', 'hardcoverReviewCountLocked', 'goodreadsIdLocked', 'hardcoverIdLocked', 'hardcoverBookIdLocked', 'googleIdLocked', 'comicvineIdLocked',
|
||||
'ranobedbIdLocked', 'ranobedbRatingLocked'
|
||||
];
|
||||
|
||||
fieldLabels: Record<string, string> = {
|
||||
titleLocked: 'Title',
|
||||
subtitleLocked: 'Subtitle',
|
||||
publisherLocked: 'Publisher',
|
||||
publishedDateLocked: 'Date',
|
||||
descriptionLocked: 'Description',
|
||||
isbn13Locked: 'ISBN-13',
|
||||
isbn10Locked: 'ISBN-10',
|
||||
asinLocked: 'ASIN',
|
||||
pageCountLocked: 'Page Count',
|
||||
thumbnailLocked: 'Thumbnail',
|
||||
languageLocked: 'Language',
|
||||
coverLocked: 'Cover',
|
||||
seriesNameLocked: 'Series',
|
||||
seriesNumberLocked: 'Series #',
|
||||
seriesTotalLocked: 'Series Total #',
|
||||
authorsLocked: 'Authors',
|
||||
categoriesLocked: 'Genres',
|
||||
moodsLocked: 'Moods',
|
||||
tagsLocked: 'Tags',
|
||||
amazonRatingLocked: 'Amazon ★',
|
||||
amazonReviewCountLocked: 'Amazon Reviews',
|
||||
goodreadsRatingLocked: 'Goodreads ★',
|
||||
goodreadsReviewCountLocked: 'Goodreads Reviews',
|
||||
hardcoverRatingLocked: 'Hardcover ★',
|
||||
hardcoverReviewCountLocked: 'Hardcover Reviews',
|
||||
goodreadsIdLocked: 'Goodreads ID',
|
||||
hardcoverIdLocked: 'Hardcover ID',
|
||||
hardcoverBookIdLocked: 'Hardcover Book ID',
|
||||
googleIdLocked: 'Google ID',
|
||||
comicvineIdLocked: 'Comicvine ID',
|
||||
ranobedbIdLocked: 'Ranobedb ID',
|
||||
ranobedbRatingLocked: 'Ranobedb ★',
|
||||
};
|
||||
|
||||
isSaving = false;
|
||||
|
||||
ngOnInit(): void {
|
||||
this.lockableFields.forEach(field => this.fieldLocks[field] = undefined);
|
||||
}
|
||||
|
||||
toggleLockAll(action: 'LOCK' | 'UNLOCK'): void {
|
||||
const lockState = action === 'LOCK' ? true : false;
|
||||
this.lockableFields.forEach(field => {
|
||||
this.fieldLocks[field] = lockState;
|
||||
});
|
||||
}
|
||||
|
||||
getLockLabel(field: string): string {
|
||||
const state = this.fieldLocks[field];
|
||||
if (state === undefined) return this.t.translate('book.lockUnlockDialog.unselected');
|
||||
return state ? this.t.translate('book.lockUnlockDialog.locked') : this.t.translate('book.lockUnlockDialog.unlocked');
|
||||
}
|
||||
|
||||
getLockIcon(field: string): string {
|
||||
const state = this.fieldLocks[field];
|
||||
return state === undefined ? '' : state ? 'pi pi-lock' : 'pi pi-lock-open';
|
||||
}
|
||||
|
||||
resetFieldLocks(): void {
|
||||
this.lockableFields.forEach(field => {
|
||||
this.fieldLocks[field] = undefined;
|
||||
});
|
||||
}
|
||||
|
||||
cycleLockState(field: string): void {
|
||||
const current = this.fieldLocks[field];
|
||||
if (current === undefined) {
|
||||
this.fieldLocks[field] = true;
|
||||
} else if (current) {
|
||||
this.fieldLocks[field] = false;
|
||||
} else {
|
||||
this.fieldLocks[field] = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
applyFieldLocks(): void {
|
||||
const fieldActions: Record<string, 'LOCK' | 'UNLOCK'> = {};
|
||||
for (const [field, locked] of Object.entries(this.fieldLocks)) {
|
||||
if (locked !== undefined) {
|
||||
fieldActions[field] = locked ? 'LOCK' : 'UNLOCK';
|
||||
}
|
||||
}
|
||||
|
||||
this.isSaving = true;
|
||||
const loader = this.loadingService.show(this.t.translate('book.lockUnlockDialog.toast.updatingFieldLocks'));
|
||||
|
||||
this.bookMetadataManageService.toggleFieldLocks(this.bookIds, fieldActions)
|
||||
.pipe(finalize(() => {
|
||||
this.isSaving = false;
|
||||
this.loadingService.hide(loader);
|
||||
}))
|
||||
.subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('book.lockUnlockDialog.toast.updatedSummary'),
|
||||
detail: this.t.translate('book.lockUnlockDialog.toast.updatedDetail')
|
||||
});
|
||||
this.dialogRef.close('fields-updated');
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('book.lockUnlockDialog.toast.failedSummary'),
|
||||
detail: this.t.translate('book.lockUnlockDialog.toast.failedDetail')
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
import {SortDirection, SortOption} from '../../../model/sort.model';
|
||||
import {CdkDragDrop, moveItemInArray} from '@angular/cdk/drag-drop';
|
||||
import {TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
export const SORT_OPTION_LABEL_KEYS: Readonly<Record<string, string>> = {
|
||||
title: 'book.sorting.options.title',
|
||||
fileName: 'book.sorting.options.fileName',
|
||||
filePath: 'book.sorting.options.filePath',
|
||||
author: 'book.sorting.options.author',
|
||||
authorSurnameVorname: 'book.sorting.options.authorSurnameVorname',
|
||||
seriesName: 'book.sorting.options.seriesName',
|
||||
seriesNumber: 'book.sorting.options.seriesNumber',
|
||||
lastReadTime: 'book.sorting.options.lastReadTime',
|
||||
personalRating: 'book.sorting.options.personalRating',
|
||||
addedOn: 'book.sorting.options.addedOn',
|
||||
fileSizeKb: 'book.sorting.options.fileSizeKb',
|
||||
locked: 'book.sorting.options.locked',
|
||||
publisher: 'book.sorting.options.publisher',
|
||||
publishedDate: 'book.sorting.options.publishedDate',
|
||||
readStatus: 'book.sorting.options.readStatus',
|
||||
dateFinished: 'book.sorting.options.dateFinished',
|
||||
readingProgress: 'book.sorting.options.readingProgress',
|
||||
bookType: 'book.sorting.options.bookType',
|
||||
amazonRating: 'book.sorting.options.amazonRating',
|
||||
amazonReviewCount: 'book.sorting.options.amazonReviewCount',
|
||||
goodreadsRating: 'book.sorting.options.goodreadsRating',
|
||||
goodreadsReviewCount: 'book.sorting.options.goodreadsReviewCount',
|
||||
hardcoverRating: 'book.sorting.options.hardcoverRating',
|
||||
hardcoverReviewCount: 'book.sorting.options.hardcoverReviewCount',
|
||||
ranobedbRating: 'book.sorting.options.ranobedbRating',
|
||||
narrator: 'book.sorting.options.narrator',
|
||||
pageCount: 'book.sorting.options.pageCount',
|
||||
random: 'book.sorting.options.random'
|
||||
};
|
||||
|
||||
const SORT_FIELDS: { field: string; defaultLabel: string }[] = [
|
||||
{field: 'title', defaultLabel: 'Title'},
|
||||
{field: 'fileName', defaultLabel: 'File Name'},
|
||||
{field: 'filePath', defaultLabel: 'File Path'},
|
||||
{field: 'author', defaultLabel: 'Author'},
|
||||
{field: 'authorSurnameVorname', defaultLabel: 'Author (Surname)'},
|
||||
{field: 'seriesName', defaultLabel: 'Series Name'},
|
||||
{field: 'seriesNumber', defaultLabel: 'Series Number'},
|
||||
{field: 'lastReadTime', defaultLabel: 'Last Read'},
|
||||
{field: 'personalRating', defaultLabel: 'Personal Rating'},
|
||||
{field: 'addedOn', defaultLabel: 'Added On'},
|
||||
{field: 'fileSizeKb', defaultLabel: 'File Size'},
|
||||
{field: 'locked', defaultLabel: 'Locked'},
|
||||
{field: 'publisher', defaultLabel: 'Publisher'},
|
||||
{field: 'publishedDate', defaultLabel: 'Published Date'},
|
||||
{field: 'readStatus', defaultLabel: 'Read Status'},
|
||||
{field: 'dateFinished', defaultLabel: 'Date Finished'},
|
||||
{field: 'readingProgress', defaultLabel: 'Reading Progress'},
|
||||
{field: 'bookType', defaultLabel: 'Book Type'},
|
||||
{field: 'amazonRating', defaultLabel: 'Amazon Rating'},
|
||||
{field: 'amazonReviewCount', defaultLabel: 'Amazon #'},
|
||||
{field: 'goodreadsRating', defaultLabel: 'Goodreads Rating'},
|
||||
{field: 'goodreadsReviewCount', defaultLabel: 'Goodreads #'},
|
||||
{field: 'hardcoverRating', defaultLabel: 'Hardcover Rating'},
|
||||
{field: 'hardcoverReviewCount', defaultLabel: 'Hardcover #'},
|
||||
{field: 'ranobedbRating', defaultLabel: 'Ranobedb Rating'},
|
||||
{field: 'narrator', defaultLabel: 'Narrator'},
|
||||
{field: 'pageCount', defaultLabel: 'Pages'},
|
||||
{field: 'random', defaultLabel: 'Random'},
|
||||
];
|
||||
|
||||
export class BookSorter {
|
||||
selectedSortCriteria: SortOption[] = [];
|
||||
|
||||
sortOptions: SortOption[];
|
||||
|
||||
constructor(private onSortChange: (criteria: SortOption[]) => void, translocoService?: TranslocoService) {
|
||||
this.sortOptions = SORT_FIELDS.map(({field, defaultLabel}) => {
|
||||
const key = SORT_OPTION_LABEL_KEYS[field];
|
||||
const label = key && translocoService ? translocoService.translate(key) : defaultLabel;
|
||||
return {label, field, direction: SortDirection.ASCENDING};
|
||||
});
|
||||
}
|
||||
|
||||
// For backward compatibility - get first sort option
|
||||
get selectedSort(): SortOption | undefined {
|
||||
return this.selectedSortCriteria[0];
|
||||
}
|
||||
|
||||
// For backward compatibility - set from single sort option
|
||||
set selectedSort(sort: SortOption | undefined) {
|
||||
if (sort) {
|
||||
this.selectedSortCriteria = [sort];
|
||||
} else {
|
||||
this.selectedSortCriteria = [];
|
||||
}
|
||||
}
|
||||
|
||||
setSortCriteria(criteria: SortOption[]): void {
|
||||
this.selectedSortCriteria = [...criteria];
|
||||
this.updateSortOptions();
|
||||
}
|
||||
|
||||
// Quick sort by field - toggles direction if already selected as primary sort
|
||||
sortBooks(field: string): void {
|
||||
const existingSort = this.sortOptions.find(opt => opt.field === field);
|
||||
if (!existingSort) return;
|
||||
|
||||
// If this field is the first (primary) sort, toggle its direction
|
||||
if (this.selectedSortCriteria.length > 0 && this.selectedSortCriteria[0].field === field) {
|
||||
this.selectedSortCriteria[0] = {
|
||||
...this.selectedSortCriteria[0],
|
||||
direction: this.selectedSortCriteria[0].direction === SortDirection.ASCENDING
|
||||
? SortDirection.DESCENDING
|
||||
: SortDirection.ASCENDING
|
||||
};
|
||||
} else {
|
||||
// Set as the only sort criterion (single click behavior)
|
||||
this.selectedSortCriteria = [{
|
||||
label: existingSort.label,
|
||||
field: existingSort.field,
|
||||
direction: SortDirection.ASCENDING
|
||||
}];
|
||||
}
|
||||
|
||||
this.updateSortOptions();
|
||||
this.onSortChange(this.selectedSortCriteria);
|
||||
}
|
||||
|
||||
addSortCriterion(field: string): void {
|
||||
// Don't add if already exists
|
||||
if (this.selectedSortCriteria.some(c => c.field === field)) return;
|
||||
|
||||
const option = this.sortOptions.find(opt => opt.field === field);
|
||||
if (!option) return;
|
||||
|
||||
this.selectedSortCriteria.push({
|
||||
label: option.label,
|
||||
field: option.field,
|
||||
direction: SortDirection.ASCENDING
|
||||
});
|
||||
|
||||
this.updateSortOptions();
|
||||
this.onSortChange(this.selectedSortCriteria);
|
||||
}
|
||||
|
||||
removeSortCriterion(index: number): void {
|
||||
if (index < 0 || index >= this.selectedSortCriteria.length) return;
|
||||
|
||||
this.selectedSortCriteria.splice(index, 1);
|
||||
this.updateSortOptions();
|
||||
this.onSortChange(this.selectedSortCriteria);
|
||||
}
|
||||
|
||||
toggleCriterionDirection(index: number): void {
|
||||
if (index < 0 || index >= this.selectedSortCriteria.length) return;
|
||||
|
||||
const criterion = this.selectedSortCriteria[index];
|
||||
this.selectedSortCriteria[index] = {
|
||||
...criterion,
|
||||
direction: criterion.direction === SortDirection.ASCENDING
|
||||
? SortDirection.DESCENDING
|
||||
: SortDirection.ASCENDING
|
||||
};
|
||||
|
||||
this.updateSortOptions();
|
||||
this.onSortChange(this.selectedSortCriteria);
|
||||
}
|
||||
|
||||
reorderCriteria(event: CdkDragDrop<SortOption[]>): void {
|
||||
moveItemInArray(this.selectedSortCriteria, event.previousIndex, event.currentIndex);
|
||||
this.updateSortOptions();
|
||||
this.onSortChange(this.selectedSortCriteria);
|
||||
}
|
||||
|
||||
getAvailableSortOptions(): SortOption[] {
|
||||
const usedFields = new Set(this.selectedSortCriteria.map(c => c.field));
|
||||
return this.sortOptions.filter(opt => !usedFields.has(opt.field));
|
||||
}
|
||||
|
||||
updateSortOptions(): void {
|
||||
const primaryField = this.selectedSortCriteria[0]?.field;
|
||||
const primaryDirection = this.selectedSortCriteria[0]?.direction;
|
||||
|
||||
const directionIcon = primaryDirection === SortDirection.ASCENDING ? 'pi pi-arrow-up' : 'pi pi-arrow-down';
|
||||
|
||||
this.sortOptions = this.sortOptions.map((option) => ({
|
||||
...option,
|
||||
icon: option.field === primaryField ? directionIcon : '',
|
||||
}));
|
||||
}
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
<ng-container *transloco="let t; prefix: 'book.sorting'">
|
||||
<div class="multi-sort-container">
|
||||
<div class="multi-sort-header">
|
||||
<span class="header-title">{{ t('sortOrder') }}</span>
|
||||
</div>
|
||||
|
||||
<div
|
||||
class="sort-criteria-list"
|
||||
cdkDropList
|
||||
[cdkDropListData]="sortCriteria"
|
||||
(cdkDropListDropped)="onDrop($event)">
|
||||
@for (criterion of sortCriteria; track criterion.field; let i = $index) {
|
||||
<div class="sort-criterion" cdkDrag>
|
||||
<div class="criterion-drag-handle" cdkDragHandle>
|
||||
<i class="pi pi-bars"></i>
|
||||
</div>
|
||||
<span class="criterion-rank">{{ i + 1 }}.</span>
|
||||
<span class="criterion-label">{{ criterion.label }}</span>
|
||||
<div class="criterion-actions">
|
||||
<button
|
||||
type="button"
|
||||
class="direction-btn"
|
||||
(click)="onToggleDirection(i)"
|
||||
[pTooltip]="getDirectionTooltip(criterion.direction)"
|
||||
tooltipPosition="top">
|
||||
<i [class]="getDirectionIcon(criterion.direction)"></i>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="remove-btn"
|
||||
(click)="onRemove(i)"
|
||||
[pTooltip]="t('removeTooltip')"
|
||||
tooltipPosition="top"
|
||||
[disabled]="sortCriteria.length === 1">
|
||||
<i class="pi pi-times"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@if (unusedOptions.length > 0) {
|
||||
<div class="add-sort-section">
|
||||
<p-select
|
||||
[options]="unusedOptions"
|
||||
[(ngModel)]="selectedField"
|
||||
optionLabel="label"
|
||||
optionValue="field"
|
||||
[placeholder]="t('addSortFieldPlaceholder')"
|
||||
[style]="{ width: '100%' }"
|
||||
size="small"
|
||||
appendTo="body"
|
||||
(onChange)="onAddField()">
|
||||
</p-select>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (showSaveButton) {
|
||||
<div class="save-sort-section">
|
||||
<p-button
|
||||
icon="pi pi-save"
|
||||
[label]="t('saveAsDefault')"
|
||||
size="small"
|
||||
[outlined]="true"
|
||||
[style]="{ width: '100%' }"
|
||||
(onClick)="onSave()">
|
||||
</p-button>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</ng-container>
|
||||
+150
@@ -0,0 +1,150 @@
|
||||
.multi-sort-container {
|
||||
width: 280px;
|
||||
padding: 0.5rem;
|
||||
}
|
||||
|
||||
.multi-sort-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding-bottom: 0.75rem;
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
|
||||
.header-title {
|
||||
font-weight: 600;
|
||||
font-size: 0.9rem;
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
.sort-criteria-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
min-height: 40px;
|
||||
}
|
||||
|
||||
.sort-criterion {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
padding: 0.5rem;
|
||||
background-color: var(--overlay-background);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 6px;
|
||||
cursor: move;
|
||||
transition: background-color 0.15s ease, box-shadow 0.15s ease;
|
||||
|
||||
&:hover {
|
||||
background-color: var(--ground-background);
|
||||
}
|
||||
}
|
||||
|
||||
.cdk-drag-preview {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
padding: 0.5rem;
|
||||
background-color: var(--card-background);
|
||||
border: 1px solid var(--primary-color);
|
||||
border-radius: 6px;
|
||||
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.25);
|
||||
}
|
||||
|
||||
.cdk-drag-placeholder {
|
||||
opacity: 0.3;
|
||||
}
|
||||
|
||||
.cdk-drag-animating {
|
||||
transition: transform 250ms cubic-bezier(0, 0, 0.2, 1);
|
||||
}
|
||||
|
||||
.sort-criteria-list.cdk-drop-list-dragging .sort-criterion:not(.cdk-drag-placeholder) {
|
||||
transition: transform 250ms cubic-bezier(0, 0, 0.2, 1);
|
||||
}
|
||||
|
||||
.criterion-drag-handle {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: var(--text-secondary-color);
|
||||
cursor: grab;
|
||||
|
||||
&:active {
|
||||
cursor: grabbing;
|
||||
}
|
||||
|
||||
i {
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
}
|
||||
|
||||
.criterion-rank {
|
||||
font-weight: 600;
|
||||
color: var(--primary-color);
|
||||
min-width: 1.25rem;
|
||||
}
|
||||
|
||||
.criterion-label {
|
||||
flex: 1;
|
||||
font-size: 0.875rem;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
.criterion-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.25rem;
|
||||
}
|
||||
|
||||
.direction-btn,
|
||||
.remove-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 1.75rem;
|
||||
height: 1.75rem;
|
||||
padding: 0;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
background-color: transparent;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.15s ease;
|
||||
|
||||
i {
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
|
||||
&:hover:not(:disabled) {
|
||||
background-color: var(--ground-background);
|
||||
}
|
||||
|
||||
&:disabled {
|
||||
opacity: 0.4;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
}
|
||||
|
||||
.direction-btn {
|
||||
color: var(--primary-color);
|
||||
}
|
||||
|
||||
.remove-btn {
|
||||
color: var(--p-red-500);
|
||||
}
|
||||
|
||||
.add-sort-section {
|
||||
margin-top: 0.75rem;
|
||||
padding-top: 0.75rem;
|
||||
border-top: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
.save-sort-section {
|
||||
margin-top: 0.75rem;
|
||||
padding-top: 0.75rem;
|
||||
border-top: 1px solid var(--border-color);
|
||||
}
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
import {ChangeDetectionStrategy, Component, EventEmitter, inject, Input, Output} from '@angular/core';
|
||||
import {SortDirection, SortOption} from '../../../../model/sort.model';
|
||||
import {CdkDrag, CdkDragDrop, CdkDragHandle, CdkDropList, moveItemInArray} from '@angular/cdk/drag-drop';
|
||||
import {Select} from 'primeng/select';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {Button} from 'primeng/button';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
@Component({
|
||||
selector: 'app-multi-sort-popover',
|
||||
standalone: true,
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
imports: [
|
||||
CdkDropList,
|
||||
CdkDrag,
|
||||
CdkDragHandle,
|
||||
Select,
|
||||
FormsModule,
|
||||
Tooltip,
|
||||
Button,
|
||||
TranslocoDirective
|
||||
],
|
||||
templateUrl: './multi-sort-popover.component.html',
|
||||
styleUrl: './multi-sort-popover.component.scss'
|
||||
})
|
||||
export class MultiSortPopoverComponent {
|
||||
private readonly t = inject(TranslocoService);
|
||||
@Input() sortCriteria: SortOption[] = [];
|
||||
@Input() availableSortOptions: SortOption[] = [];
|
||||
@Input() showSaveButton = false;
|
||||
|
||||
@Output() criteriaChange = new EventEmitter<SortOption[]>();
|
||||
@Output() saveSortConfig = new EventEmitter<SortOption[]>();
|
||||
|
||||
selectedField: string | null = null;
|
||||
|
||||
get unusedOptions(): SortOption[] {
|
||||
const usedFields = new Set(this.sortCriteria.map(c => c.field));
|
||||
return this.availableSortOptions.filter(opt => !usedFields.has(opt.field));
|
||||
}
|
||||
|
||||
onDrop(event: CdkDragDrop<SortOption[]>): void {
|
||||
const criteria = [...this.sortCriteria];
|
||||
moveItemInArray(criteria, event.previousIndex, event.currentIndex);
|
||||
this.sortCriteria = criteria;
|
||||
this.criteriaChange.emit(this.sortCriteria);
|
||||
}
|
||||
|
||||
onToggleDirection(index: number): void {
|
||||
this.sortCriteria = this.sortCriteria.map((c, i) =>
|
||||
i === index
|
||||
? {...c, direction: c.direction === SortDirection.ASCENDING ? SortDirection.DESCENDING : SortDirection.ASCENDING}
|
||||
: c
|
||||
);
|
||||
this.criteriaChange.emit(this.sortCriteria);
|
||||
}
|
||||
|
||||
onRemove(index: number): void {
|
||||
this.sortCriteria = this.sortCriteria.filter((_, i) => i !== index);
|
||||
this.criteriaChange.emit(this.sortCriteria);
|
||||
}
|
||||
|
||||
onAddField(): void {
|
||||
if (!this.selectedField) return;
|
||||
const option = this.availableSortOptions.find(o => o.field === this.selectedField);
|
||||
if (!option) return;
|
||||
this.sortCriteria = [...this.sortCriteria, {
|
||||
label: option.label,
|
||||
field: option.field,
|
||||
direction: SortDirection.ASCENDING
|
||||
}];
|
||||
this.selectedField = null;
|
||||
this.criteriaChange.emit(this.sortCriteria);
|
||||
}
|
||||
|
||||
onSave(): void {
|
||||
this.saveSortConfig.emit(this.sortCriteria);
|
||||
}
|
||||
|
||||
getDirectionIcon(direction: SortDirection): string {
|
||||
return direction === SortDirection.ASCENDING ? 'pi pi-arrow-up' : 'pi pi-arrow-down';
|
||||
}
|
||||
|
||||
getDirectionTooltip(direction: SortDirection): string {
|
||||
return direction === SortDirection.ASCENDING
|
||||
? this.t.translate('book.sorting.ascendingTooltip')
|
||||
: this.t.translate('book.sorting.descendingTooltip');
|
||||
}
|
||||
|
||||
protected readonly SortDirection = SortDirection;
|
||||
}
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
import {inject, Injectable, signal} from '@angular/core';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {TranslocoService} from '@jsverse/transloco';
|
||||
import {TableColumnPreference, UserService} from '../../../settings/user-management/user.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class TableColumnPreferenceService {
|
||||
private readonly userService = inject(UserService);
|
||||
private readonly messageService = inject(MessageService);
|
||||
private readonly t = inject(TranslocoService);
|
||||
|
||||
private readonly _preferences = signal<TableColumnPreference[]>([]);
|
||||
readonly preferences = this._preferences.asReadonly();
|
||||
|
||||
private readonly allAvailableFields = [
|
||||
'readStatus', 'title', 'authors', 'publisher', 'seriesName', 'seriesNumber',
|
||||
'categories', 'publishedDate', 'lastReadTime', 'addedOn', 'fileName', 'fileSizeKb',
|
||||
'language', 'isbn', 'pageCount', 'amazonRating', 'amazonReviewCount',
|
||||
'goodreadsRating', 'goodreadsReviewCount', 'hardcoverRating', 'hardcoverReviewCount',
|
||||
'ranobedbRating',
|
||||
];
|
||||
|
||||
private readonly fallbackPreferences: TableColumnPreference[] = this.allAvailableFields.map((field, index) => ({
|
||||
field,
|
||||
visible: true,
|
||||
order: index
|
||||
}));
|
||||
|
||||
initPreferences(savedPrefs: TableColumnPreference[] | undefined): void {
|
||||
const effectivePrefs = savedPrefs?.length ? savedPrefs : this.fallbackPreferences;
|
||||
this._preferences.set(this.mergeWithAllColumns(effectivePrefs));
|
||||
}
|
||||
|
||||
get allColumns(): { field: string; header: string }[] {
|
||||
return this.allAvailableFields.map(field => ({
|
||||
field,
|
||||
header: this.t.translate(`book.columnPref.columns.${field}`)
|
||||
}));
|
||||
}
|
||||
|
||||
get visibleColumns(): { field: string; header: string }[] {
|
||||
return this.preferences()
|
||||
.filter(pref => pref.visible)
|
||||
.sort((a, b) => a.order - b.order)
|
||||
.map(pref => ({
|
||||
field: pref.field,
|
||||
header: this.t.translate(`book.columnPref.columns.${pref.field}`)
|
||||
}));
|
||||
}
|
||||
|
||||
saveVisibleColumns(selectedColumns: { field: string }[]): void {
|
||||
const selectedFieldSet = new Set(selectedColumns.map(c => c.field));
|
||||
|
||||
const updatedPreferences: TableColumnPreference[] = this.allAvailableFields.map((field, index) => {
|
||||
const selectionIndex = selectedColumns.findIndex(c => c.field === field);
|
||||
return {
|
||||
field,
|
||||
visible: selectedFieldSet.has(field),
|
||||
order: selectionIndex >= 0 ? selectionIndex : index
|
||||
};
|
||||
});
|
||||
|
||||
this._preferences.set(updatedPreferences);
|
||||
|
||||
const currentUser = this.userService.getCurrentUser();
|
||||
if (!currentUser) return;
|
||||
|
||||
this.userService.updateUserSetting(currentUser.id, 'tableColumnPreference', updatedPreferences);
|
||||
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('book.columnPref.toast.savedSummary'),
|
||||
detail: this.t.translate('book.columnPref.toast.savedDetail'),
|
||||
life: 1500
|
||||
});
|
||||
}
|
||||
|
||||
private mergeWithAllColumns(savedPrefs: TableColumnPreference[]): TableColumnPreference[] {
|
||||
const savedPrefMap = new Map(savedPrefs.map(p => [p.field, p]));
|
||||
|
||||
return this.allAvailableFields.map((field, index) => {
|
||||
const saved = savedPrefMap.get(field);
|
||||
return {
|
||||
field,
|
||||
visible: saved?.visible ?? true,
|
||||
order: saved?.order ?? index
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
<div class="book-cover-wrapper" [class.audiobook-only]="isAudiobookOnly()" (mouseenter)="isHovered = true" (mouseleave)="isHovered = false">
|
||||
<img
|
||||
[src]="getThumbnailUrl()"
|
||||
class="book-cover"
|
||||
alt="Cover of {{ book.metadata?.title }}"
|
||||
loading="lazy"/>
|
||||
|
||||
@if (showSeriesNumber && !book.seriesCount && book.metadata?.seriesNumber != null) {
|
||||
<div class="series-number-overlay">
|
||||
#{{ book.metadata?.seriesNumber }}
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (!this.isActive) {
|
||||
<p-button
|
||||
icon="pi pi-info"
|
||||
class="info-btn"
|
||||
[rounded]="true"
|
||||
[pTooltip]="book.metadata?.title"
|
||||
tooltipPosition="top"
|
||||
[ngClass]="{ 'visible': isHovered }"
|
||||
(onClick)="openBookInfo(book)">
|
||||
</p-button>
|
||||
}
|
||||
</div>
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
.book-cover-wrapper {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
width: 100%;
|
||||
height: auto;
|
||||
|
||||
.book-cover {
|
||||
width: 100%;
|
||||
display: block;
|
||||
border-radius: 0.5rem;
|
||||
}
|
||||
|
||||
&.audiobook-only {
|
||||
.book-cover {
|
||||
aspect-ratio: 1 / 1;
|
||||
object-fit: cover;
|
||||
}
|
||||
}
|
||||
|
||||
.info-btn {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
transition: opacity 0.2s ease-in-out;
|
||||
z-index: 2;
|
||||
|
||||
&.visible {
|
||||
opacity: 1;
|
||||
pointer-events: auto;
|
||||
}
|
||||
}
|
||||
|
||||
.series-number-overlay {
|
||||
position: absolute;
|
||||
top: 4px;
|
||||
left: 4px;
|
||||
background-color: rgba(0, 0, 0, 0.7);
|
||||
color: white;
|
||||
font-size: 0.75rem;
|
||||
padding: 1px 3px;
|
||||
border-radius: 3px;
|
||||
z-index: 3;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
import {ChangeDetectionStrategy, Component, computed, inject, Input} from '@angular/core';
|
||||
import {Book} from '../../model/book.model';
|
||||
import {UrlHelperService} from '../../../../shared/service/url-helper.service';
|
||||
import {Button} from 'primeng/button';
|
||||
import {UserService} from '../../../settings/user-management/user.service';
|
||||
import {Router} from '@angular/router';
|
||||
import {NgClass} from '@angular/common';
|
||||
import {BookMetadataHostService} from '../../../../shared/service/book-metadata-host.service';
|
||||
import {TooltipModule} from 'primeng/tooltip';
|
||||
|
||||
@Component({
|
||||
selector: 'app-book-card-lite-component',
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
imports: [
|
||||
Button,
|
||||
NgClass,
|
||||
TooltipModule
|
||||
],
|
||||
templateUrl: './book-card-lite-component.html',
|
||||
styleUrl: './book-card-lite-component.scss'
|
||||
})
|
||||
export class BookCardLiteComponent {
|
||||
@Input() book!: Book;
|
||||
@Input() isActive: boolean = false;
|
||||
@Input() showSeriesNumber: boolean = false;
|
||||
|
||||
private router = inject(Router);
|
||||
protected urlHelper = inject(UrlHelperService);
|
||||
private userService = inject(UserService);
|
||||
private bookMetadataHostService = inject(BookMetadataHostService);
|
||||
|
||||
private metadataCenterViewMode = computed(() =>
|
||||
this.userService.currentUser()?.userSettings.metadataCenterViewMode ?? 'route'
|
||||
);
|
||||
isHovered: boolean = false;
|
||||
|
||||
isAudiobookOnly(): boolean {
|
||||
const primaryIsAudiobook = this.book.primaryFile?.bookType === 'AUDIOBOOK';
|
||||
const hasEbookAlternative = this.book.alternativeFormats?.some(f => f.bookType !== 'AUDIOBOOK') ?? false;
|
||||
return primaryIsAudiobook && !hasEbookAlternative;
|
||||
}
|
||||
|
||||
getThumbnailUrl(): string {
|
||||
if (this.isAudiobookOnly()) {
|
||||
return this.urlHelper.getAudiobookThumbnailUrl(this.book.id, this.book.metadata?.audiobookCoverUpdatedOn);
|
||||
}
|
||||
return this.urlHelper.getThumbnailUrl(this.book.id, this.book.metadata?.coverUpdatedOn);
|
||||
}
|
||||
|
||||
openBookInfo(book: Book): void {
|
||||
if (this.metadataCenterViewMode() === 'route') {
|
||||
this.router.navigate(['/book', book.id], {
|
||||
queryParams: {tab: 'view'}
|
||||
});
|
||||
} else {
|
||||
this.bookMetadataHostService.requestBookSwitch(book.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
+118
@@ -0,0 +1,118 @@
|
||||
<ng-container *transloco="let t; prefix: 'book.fileAttacher'">
|
||||
<div class="book-file-attacher-container">
|
||||
<div class="panel-header">
|
||||
<div class="header-icon-wrapper">
|
||||
<i class="pi pi-link header-icon"></i>
|
||||
</div>
|
||||
<div class="header-text">
|
||||
<h2 class="panel-title">{{ isBulkMode ? t('titleBulk') : t('title') }}</h2>
|
||||
<p class="panel-description">{{ isBulkMode ? t('descriptionBulk') : t('description') }}</p>
|
||||
</div>
|
||||
<p-button
|
||||
icon="pi pi-times"
|
||||
[rounded]="true"
|
||||
[text]="true"
|
||||
severity="secondary"
|
||||
(click)="closeDialog()"
|
||||
class="close-button">
|
||||
</p-button>
|
||||
</div>
|
||||
|
||||
<div class="dialog-content">
|
||||
<!-- Source Book(s) Info -->
|
||||
<div class="source-info">
|
||||
<h3 class="section-title">{{ isBulkMode ? t('sourceBooksLabel', { count: sourceBooks.length }) : t('sourceBookLabel', { count: sourceBooks.length }) }}</h3>
|
||||
<div class="source-books-list">
|
||||
@for (book of sourceBooks; track book.id) {
|
||||
<div class="book-info-card">
|
||||
<div class="book-title">{{ book.metadata?.title || t('unknownTitle') }}</div>
|
||||
@if (book.metadata?.authors?.length) {
|
||||
<div class="book-authors">{{ book.metadata?.authors?.join(', ') }}</div>
|
||||
}
|
||||
<div class="file-info">
|
||||
<i class="pi pi-file"></i>
|
||||
<span>{{ getSourceFileInfo(book) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Target Book Selection -->
|
||||
<div class="target-selection">
|
||||
<h3 class="section-title">{{ t('selectTargetBook') }}</h3>
|
||||
<p-autocomplete
|
||||
[(ngModel)]="targetBook"
|
||||
[suggestions]="filteredBooks"
|
||||
(completeMethod)="filterBooks($event)"
|
||||
(onSelect)="onBookSelect($event)"
|
||||
(onClear)="onBookClear()"
|
||||
optionLabel="metadata.title"
|
||||
[dropdown]="true"
|
||||
[showClear]="true"
|
||||
[placeholder]="t('searchPlaceholder')"
|
||||
fluid
|
||||
[disabled]="isAttaching">
|
||||
<ng-template let-book pTemplate="item">
|
||||
<div class="book-suggestion">
|
||||
<div class="suggestion-title">{{ book.metadata?.title || t('unknownTitle') }}</div>
|
||||
@if (book.metadata?.authors?.length) {
|
||||
<div class="suggestion-authors">{{ book.metadata.authors.join(', ') }}</div>
|
||||
}
|
||||
@if (book.primaryFile) {
|
||||
<div class="suggestion-format">{{ book.primaryFile.extension?.toUpperCase() || book.primaryFile.bookType }}</div>
|
||||
}
|
||||
</div>
|
||||
</ng-template>
|
||||
<ng-template let-book pTemplate="selectedItem">
|
||||
<span>{{ getBookDisplayName(book) }}</span>
|
||||
</ng-template>
|
||||
</p-autocomplete>
|
||||
</div>
|
||||
|
||||
<!-- Options -->
|
||||
<div class="delete-option">
|
||||
<p-checkbox
|
||||
[(ngModel)]="moveFiles"
|
||||
[binary]="true"
|
||||
inputId="moveFiles"
|
||||
[disabled]="isAttaching">
|
||||
</p-checkbox>
|
||||
<label for="moveFiles" class="delete-label">
|
||||
{{ t('moveFilesLabel') }}
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<!-- Warning Message -->
|
||||
<div class="warning-message">
|
||||
<i class="pi pi-info-circle"></i>
|
||||
<div class="warning-text">
|
||||
@if (moveFiles) {
|
||||
<p>{{ isBulkMode ? t('warningMoveBulk') : t('warningMove') }}</p>
|
||||
} @else {
|
||||
<p>{{ isBulkMode ? t('warningNoMoveBulk') : t('warningNoMove') }}</p>
|
||||
}
|
||||
<p>{{ isBulkMode ? t('warningDeleteBulk') : t('warningDelete') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Action Buttons -->
|
||||
<div class="action-buttons">
|
||||
<p-button
|
||||
[label]="'common.cancel' | transloco"
|
||||
[outlined]="true"
|
||||
severity="secondary"
|
||||
(click)="closeDialog()"
|
||||
[disabled]="isAttaching">
|
||||
</p-button>
|
||||
<p-button
|
||||
[label]="isBulkMode ? t('attachFilesBulk') : t('attachFile')"
|
||||
icon="pi pi-link"
|
||||
(click)="attach()"
|
||||
[disabled]="!canAttach()"
|
||||
[loading]="isAttaching">
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
+180
@@ -0,0 +1,180 @@
|
||||
@use '../../../../shared/styles/panel-shared' as panel;
|
||||
|
||||
.book-file-attacher-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.panel-header {
|
||||
@include panel.panel-header;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.dialog-content {
|
||||
flex: 1;
|
||||
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);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1.5rem;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 0.875rem;
|
||||
font-weight: 600;
|
||||
color: var(--p-text-muted-color);
|
||||
margin-bottom: 0.75rem;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
}
|
||||
|
||||
.source-info {
|
||||
.source-books-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
max-height: 200px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.book-info-card {
|
||||
background: var(--p-surface-100);
|
||||
border-radius: 8px;
|
||||
padding: 0.75rem 1rem;
|
||||
border: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
.book-title {
|
||||
font-weight: 600;
|
||||
font-size: 0.9375rem;
|
||||
margin-bottom: 0.125rem;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.book-authors {
|
||||
color: var(--p-text-muted-color);
|
||||
font-size: 0.875rem;
|
||||
margin-bottom: 0.375rem;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.file-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
color: var(--p-primary-color);
|
||||
font-size: 0.875rem;
|
||||
font-weight: 500;
|
||||
|
||||
i {
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
span {
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.target-selection {
|
||||
:host ::ng-deep {
|
||||
.full-width {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.book-suggestion {
|
||||
padding: 0.25rem 0;
|
||||
|
||||
.suggestion-title {
|
||||
font-weight: 500;
|
||||
margin-bottom: 0.125rem;
|
||||
}
|
||||
|
||||
.suggestion-authors {
|
||||
font-size: 0.875rem;
|
||||
color: var(--p-text-muted-color);
|
||||
}
|
||||
|
||||
.suggestion-format {
|
||||
font-size: 0.75rem;
|
||||
color: var(--p-primary-color);
|
||||
font-weight: 600;
|
||||
margin-top: 0.25rem;
|
||||
}
|
||||
}
|
||||
|
||||
.delete-option {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
|
||||
.delete-label {
|
||||
font-size: 0.9375rem;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
}
|
||||
}
|
||||
|
||||
.warning-message {
|
||||
display: flex;
|
||||
gap: 0.75rem;
|
||||
padding: 1rem;
|
||||
background: var(--p-yellow-50);
|
||||
border: 1px solid var(--p-yellow-200);
|
||||
border-radius: 8px;
|
||||
color: var(--p-yellow-800);
|
||||
|
||||
i {
|
||||
flex-shrink: 0;
|
||||
font-size: 1.25rem;
|
||||
margin-top: 0.125rem;
|
||||
}
|
||||
|
||||
.warning-text {
|
||||
font-size: 0.875rem;
|
||||
line-height: 1.5;
|
||||
|
||||
p {
|
||||
margin: 0;
|
||||
|
||||
&:not(:last-child) {
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
:host-context(.p-dark) {
|
||||
.warning-message {
|
||||
background: rgba(234, 179, 8, 0.1);
|
||||
border-color: rgba(234, 179, 8, 0.3);
|
||||
color: var(--p-yellow-400);
|
||||
}
|
||||
|
||||
.source-info .book-info-card {
|
||||
background: var(--p-surface-800);
|
||||
}
|
||||
}
|
||||
|
||||
.action-buttons {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 0.75rem;
|
||||
margin-top: auto;
|
||||
padding-top: 0.5rem;
|
||||
}
|
||||
+160
@@ -0,0 +1,160 @@
|
||||
import { Component, computed, inject, OnInit, OnDestroy, Signal, signal } from '@angular/core';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { DynamicDialogRef, DynamicDialogConfig } from 'primeng/dynamicdialog';
|
||||
import { AutoComplete, AutoCompleteSelectEvent } from 'primeng/autocomplete';
|
||||
import { Button } from 'primeng/button';
|
||||
import { Checkbox } from 'primeng/checkbox';
|
||||
import { Subject, takeUntil } from 'rxjs';
|
||||
import { BookService } from '../../service/book.service';
|
||||
import { BookFileService } from '../../service/book-file.service';
|
||||
import { Book } from '../../model/book.model';
|
||||
import {MessageService, PrimeTemplate} from 'primeng/api';
|
||||
import { TranslocoDirective, TranslocoPipe, TranslocoService } from '@jsverse/transloco';
|
||||
import { AppSettingsService } from '../../../../shared/service/app-settings.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-book-file-attacher',
|
||||
standalone: true,
|
||||
imports: [
|
||||
FormsModule,
|
||||
AutoComplete,
|
||||
Button,
|
||||
Checkbox,
|
||||
TranslocoDirective,
|
||||
TranslocoPipe,
|
||||
PrimeTemplate,
|
||||
],
|
||||
templateUrl: './book-file-attacher.component.html',
|
||||
styleUrls: ['./book-file-attacher.component.scss']
|
||||
})
|
||||
export class BookFileAttacherComponent implements OnInit, OnDestroy {
|
||||
sourceBooks: Book[] = [];
|
||||
targetBook: Book | null = null;
|
||||
moveFiles = false;
|
||||
isAttaching = false;
|
||||
searchQuery = '';
|
||||
filteredBooks: Book[] = [];
|
||||
|
||||
private destroy$ = new Subject<void>();
|
||||
private allBooks: Signal<Book[]> = signal([]);
|
||||
|
||||
private readonly t = inject(TranslocoService);
|
||||
private readonly appSettingsService = inject(AppSettingsService);
|
||||
|
||||
constructor(
|
||||
private dialogRef: DynamicDialogRef,
|
||||
private config: DynamicDialogConfig,
|
||||
private bookService: BookService,
|
||||
private bookFileService: BookFileService,
|
||||
private messageService: MessageService
|
||||
) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
// Support both single book and multiple books
|
||||
if (this.config.data.sourceBook) {
|
||||
this.sourceBooks = [this.config.data.sourceBook];
|
||||
} else if (this.config.data.sourceBooks) {
|
||||
this.sourceBooks = this.config.data.sourceBooks;
|
||||
}
|
||||
|
||||
if (this.sourceBooks.length === 0) {
|
||||
this.closeDialog();
|
||||
return;
|
||||
}
|
||||
|
||||
const settings = this.appSettingsService.appSettings();
|
||||
if (settings) {
|
||||
this.moveFiles = settings.metadataPersistenceSettings?.moveFilesToLibraryPattern ?? false;
|
||||
}
|
||||
|
||||
// Get the library ID from first source book (all should be same library)
|
||||
const libraryId = this.sourceBooks[0].libraryId;
|
||||
const sourceBookIds = new Set(this.sourceBooks.map(b => b.id));
|
||||
|
||||
this.allBooks = computed(() =>
|
||||
this.bookService.books().filter(book =>
|
||||
book.libraryId === libraryId && !sourceBookIds.has(book.id)
|
||||
)
|
||||
);
|
||||
|
||||
this.filteredBooks = this.allBooks().slice(0, 20);
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
}
|
||||
|
||||
get isBulkMode(): boolean {
|
||||
return this.sourceBooks.length > 1;
|
||||
}
|
||||
|
||||
filterBooks(event: { query: string }): void {
|
||||
const query = event.query.toLowerCase().trim();
|
||||
const books = this.allBooks();
|
||||
if (!query) {
|
||||
this.filteredBooks = books.slice(0, 20);
|
||||
return;
|
||||
}
|
||||
|
||||
this.filteredBooks = books
|
||||
.filter(book => {
|
||||
const title = book.metadata?.title?.toLowerCase() || '';
|
||||
const authors = book.metadata?.authors?.join(' ').toLowerCase() || '';
|
||||
return title.includes(query) || authors.includes(query);
|
||||
})
|
||||
.slice(0, 20);
|
||||
}
|
||||
|
||||
onBookSelect(event: AutoCompleteSelectEvent): void {
|
||||
this.targetBook = event.value as Book;
|
||||
}
|
||||
|
||||
onBookClear(): void {
|
||||
this.targetBook = null;
|
||||
}
|
||||
|
||||
getBookDisplayName(book: Book): string {
|
||||
const title = book.metadata?.title || `Book #${book.id}`;
|
||||
const authors = book.metadata?.authors?.join(', ');
|
||||
return authors ? `${title} - ${authors}` : title;
|
||||
}
|
||||
|
||||
getSourceFileInfo(book: Book): string {
|
||||
const file = book.primaryFile;
|
||||
if (!file) return this.t.translate('book.fileAttacher.unknownFile');
|
||||
const format = file.extension?.toUpperCase() || file.bookType || this.t.translate('book.fileAttacher.unknownFormat');
|
||||
return `${format} - ${file.fileName || this.t.translate('book.fileAttacher.unknownFilename')}`;
|
||||
}
|
||||
|
||||
canAttach(): boolean {
|
||||
return !!this.targetBook && !this.isAttaching;
|
||||
}
|
||||
|
||||
attach(): void {
|
||||
if (!this.targetBook) return;
|
||||
|
||||
this.isAttaching = true;
|
||||
|
||||
const sourceBookIds = this.sourceBooks.map(b => b.id);
|
||||
|
||||
this.bookFileService.attachBookFiles(
|
||||
this.targetBook.id,
|
||||
sourceBookIds,
|
||||
this.moveFiles
|
||||
).pipe(
|
||||
takeUntil(this.destroy$)
|
||||
).subscribe({
|
||||
next: () => {
|
||||
this.dialogRef.close({ success: true });
|
||||
},
|
||||
error: () => {
|
||||
this.isAttaching = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
closeDialog(): void {
|
||||
this.dialogRef.close();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,206 @@
|
||||
<div class="book-notes-container">
|
||||
<div class="notes-content">
|
||||
@if (loading) {
|
||||
<div class="loading-state">
|
||||
<p-progressSpinner/>
|
||||
<span class="loading-text">Loading notes...</span>
|
||||
</div>
|
||||
} @else if (notes.length === 0) {
|
||||
<div class="empty-state">
|
||||
<div class="empty-state-icon">
|
||||
<p-button
|
||||
outlined
|
||||
rounded
|
||||
icon="pi pi-plus"
|
||||
severity="primary"
|
||||
(click)="openCreateDialog()"
|
||||
pTooltip="Add New Note"
|
||||
tooltipPosition="top"
|
||||
class="action-btn floating-btn">
|
||||
</p-button>
|
||||
</div>
|
||||
<p class="empty-state-title">No notes yet for this book</p>
|
||||
<p class="empty-state-subtitle">
|
||||
Click "Add Note" to create your first note and start capturing your thoughts
|
||||
</p>
|
||||
<div class="empty-state-decoration"></div>
|
||||
</div>
|
||||
} @else {
|
||||
<div class="notes-scroll-container">
|
||||
<div class="notes-horizontal-list">
|
||||
@for (note of notes; track note.id + '-' + note.createdAt + '-' + $index) {
|
||||
<div class="note-card">
|
||||
<div class="note-header">
|
||||
<div class="note-header-inner">
|
||||
<div class="note-title-group">
|
||||
<h4 class="note-title">{{ note.title }}</h4>
|
||||
<div class="note-meta">
|
||||
<i class="pi pi-clock note-meta-icon"></i>
|
||||
<span class="note-meta-text">
|
||||
@if (note.createdAt !== note.updatedAt) {
|
||||
Updated {{ formatDate(note.updatedAt) }}
|
||||
} @else {
|
||||
Created {{ formatDate(note.createdAt) }}
|
||||
}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="note-actions">
|
||||
<p-button
|
||||
icon="pi pi-pencil"
|
||||
size="small"
|
||||
severity="secondary"
|
||||
text
|
||||
(onClick)="openEditDialog(note)"
|
||||
pTooltip="Edit note"
|
||||
tooltipPosition="top"
|
||||
class="action-btn-hover">
|
||||
</p-button>
|
||||
<p-button
|
||||
icon="pi pi-trash"
|
||||
size="small"
|
||||
severity="danger"
|
||||
text
|
||||
(onClick)="deleteNote(note)"
|
||||
pTooltip="Delete note"
|
||||
tooltipPosition="top"
|
||||
class="action-btn-hover">
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="note-content-area">
|
||||
<div class="note-body">{{ note.content }}</div>
|
||||
<div class="note-fade-overlay"></div>
|
||||
</div>
|
||||
<div class="note-bottom-glow"></div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@if (notes.length > 0) {
|
||||
<div class="action-bar">
|
||||
<p-button
|
||||
outlined
|
||||
icon="pi pi-plus"
|
||||
severity="success"
|
||||
(click)="openCreateDialog()"
|
||||
pTooltip="Add New Note"
|
||||
tooltipPosition="left">
|
||||
</p-button>
|
||||
</div>
|
||||
}
|
||||
|
||||
<p-dialog
|
||||
header="Add New Note"
|
||||
[(visible)]="showCreateDialog"
|
||||
[modal]="true"
|
||||
[style]="{width: '500px'}"
|
||||
[closable]="true"
|
||||
[dismissableMask]="true">
|
||||
|
||||
<div class="dialog-form">
|
||||
<div class="field">
|
||||
<label for="create-title" class="field-label">Title</label>
|
||||
<input
|
||||
id="create-title"
|
||||
pInputText
|
||||
[(ngModel)]="newNote.title"
|
||||
placeholder="Enter note title"
|
||||
class="field-input"
|
||||
maxlength="255"/>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label for="create-content" class="field-label">Content</label>
|
||||
<textarea
|
||||
id="create-content"
|
||||
pTextarea
|
||||
[(ngModel)]="newNote.content"
|
||||
placeholder="Enter your note content..."
|
||||
[rows]="8"
|
||||
class="field-input"
|
||||
[autoResize]="true">
|
||||
</textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ng-template #footer>
|
||||
<div class="dialog-actions">
|
||||
<p-button
|
||||
label="Cancel"
|
||||
severity="secondary"
|
||||
outlined
|
||||
(onClick)="cancelCreate()">
|
||||
</p-button>
|
||||
<p-button
|
||||
outlined
|
||||
severity="success"
|
||||
label="Save Note"
|
||||
icon="pi pi-save"
|
||||
(onClick)="createNote()">
|
||||
</p-button>
|
||||
</div>
|
||||
</ng-template>
|
||||
</p-dialog>
|
||||
|
||||
<p-dialog
|
||||
header="Edit Note"
|
||||
[(visible)]="showEditDialog"
|
||||
[modal]="true"
|
||||
[style]="{width: '500px'}"
|
||||
[closable]="true"
|
||||
[dismissableMask]="true">
|
||||
|
||||
<div class="dialog-form">
|
||||
<div class="field">
|
||||
<label for="edit-title" class="field-label">Title</label>
|
||||
<input
|
||||
id="edit-title"
|
||||
pInputText
|
||||
[(ngModel)]="editNote.title"
|
||||
placeholder="Enter note title"
|
||||
class="field-input"
|
||||
maxlength="255"/>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label for="edit-content" class="field-label">Content</label>
|
||||
<textarea
|
||||
id="edit-content"
|
||||
pTextarea
|
||||
[(ngModel)]="editNote.content"
|
||||
placeholder="Enter your note content..."
|
||||
[rows]="8"
|
||||
class="field-input"
|
||||
[autoResize]="true">
|
||||
</textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ng-template #footer>
|
||||
<div class="dialog-actions">
|
||||
<p-button
|
||||
label="Cancel"
|
||||
severity="secondary"
|
||||
outlined
|
||||
(onClick)="cancelEdit()">
|
||||
</p-button>
|
||||
<p-button
|
||||
outlined
|
||||
severity="success"
|
||||
label="Update Note"
|
||||
icon="pi pi-save"
|
||||
(onClick)="updateNote()">
|
||||
</p-button>
|
||||
</div>
|
||||
</ng-template>
|
||||
</p-dialog>
|
||||
|
||||
<p-confirmDialog key="deleteNote"></p-confirmDialog>
|
||||
</div>
|
||||
@@ -0,0 +1,320 @@
|
||||
.book-notes-container {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
position: relative;
|
||||
display: flex;
|
||||
min-height: 250px;
|
||||
|
||||
.notes-content {
|
||||
flex: 1;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.action-bar {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
right: 0;
|
||||
transform: translateY(-50%);
|
||||
z-index: 1000;
|
||||
}
|
||||
}
|
||||
|
||||
.loading-state {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 2rem;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.loading-text {
|
||||
color: #9ca3af;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
position: relative;
|
||||
padding: 3rem !important;
|
||||
text-align: center;
|
||||
color: #9ca3af;
|
||||
|
||||
.empty-state-title {
|
||||
font-size: 1.25rem;
|
||||
font-weight: 600;
|
||||
margin-top: 1rem;
|
||||
margin-bottom: 0.5rem;
|
||||
color: #e5e7eb;
|
||||
}
|
||||
|
||||
.empty-state-subtitle {
|
||||
max-width: 400px;
|
||||
margin: 0.5rem auto 0;
|
||||
line-height: 1.6;
|
||||
font-size: 0.875rem;
|
||||
color: #9ca3af;
|
||||
}
|
||||
|
||||
.empty-state-decoration {
|
||||
position: absolute;
|
||||
top: 20%;
|
||||
right: 15%;
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
border-radius: 50%;
|
||||
filter: blur(40px);
|
||||
animation: float 4s ease-in-out infinite;
|
||||
}
|
||||
}
|
||||
|
||||
.notes-scroll-container {
|
||||
overflow-x: auto;
|
||||
overflow-y: hidden;
|
||||
height: 100%;
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
height: 10px;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-track {
|
||||
background: rgba(30, 30, 30, 0.5);
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
scrollbar-width: thin;
|
||||
}
|
||||
|
||||
.notes-horizontal-list {
|
||||
display: flex;
|
||||
gap: 1.5rem;
|
||||
padding: 0.5rem;
|
||||
}
|
||||
|
||||
.note-card {
|
||||
width: 500px;
|
||||
height: 240px;
|
||||
flex-shrink: 0;
|
||||
padding: 0;
|
||||
border-radius: 16px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
|
||||
@media (max-width: 768px) {
|
||||
width: 340px;
|
||||
height: 220px;
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
width: 290px;
|
||||
height: 200px;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
transform: translateY(-2px);
|
||||
border-color: color-mix(in srgb, var(--primary-color), transparent 50%);
|
||||
|
||||
.note-bottom-glow {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.action-btn-hover {
|
||||
opacity: 1;
|
||||
transform: scale(1);
|
||||
}
|
||||
}
|
||||
|
||||
.note-header {
|
||||
flex-shrink: 0;
|
||||
background: linear-gradient(135deg, rgba(40, 40, 40, 0.8), rgba(30, 30, 30, 0.8));
|
||||
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
|
||||
position: relative;
|
||||
|
||||
.note-header-inner {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: flex-start;
|
||||
padding: 0.75rem;
|
||||
}
|
||||
|
||||
.note-title-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.25rem;
|
||||
}
|
||||
|
||||
.note-title {
|
||||
max-width: 350px;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
background: linear-gradient(135deg, #f8fafc, #e2e8f0);
|
||||
-webkit-background-clip: text;
|
||||
-webkit-text-fill-color: transparent;
|
||||
background-clip: text;
|
||||
font-weight: 500;
|
||||
font-size: 1.125rem;
|
||||
margin: 0;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
max-width: 200px;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
max-width: 180px;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
}
|
||||
|
||||
.note-meta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
opacity: 0.8;
|
||||
|
||||
i {
|
||||
color: #3b82f6;
|
||||
}
|
||||
}
|
||||
|
||||
.note-meta-icon {
|
||||
font-size: 0.75rem;
|
||||
margin-right: 0.25rem;
|
||||
}
|
||||
|
||||
.note-meta-text {
|
||||
font-size: 0.875rem;
|
||||
color: #9ca3af;
|
||||
}
|
||||
|
||||
.note-actions {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
flex-shrink: 0;
|
||||
|
||||
.action-btn-hover {
|
||||
opacity: 0.7;
|
||||
transition: all 0.3s ease;
|
||||
transform: scale(0.9);
|
||||
|
||||
::ng-deep .p-button {
|
||||
border-radius: 8px;
|
||||
|
||||
&:hover {
|
||||
transform: scale(1.1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.note-content-area {
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
position: relative;
|
||||
padding: 1rem;
|
||||
|
||||
.note-fade-overlay {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 30px;
|
||||
background: linear-gradient(transparent, rgba(20, 20, 20, 0.9));
|
||||
pointer-events: none;
|
||||
}
|
||||
}
|
||||
|
||||
.note-bottom-glow {
|
||||
position: absolute;
|
||||
bottom: -5px;
|
||||
left: 20%;
|
||||
right: 20%;
|
||||
height: 10px;
|
||||
background: linear-gradient(
|
||||
90deg,
|
||||
transparent,
|
||||
color-mix(in srgb, var(--primary-color), transparent 60%),
|
||||
transparent
|
||||
);
|
||||
border-radius: 50%;
|
||||
opacity: 0;
|
||||
transition: opacity 0.3s ease;
|
||||
filter: blur(5px);
|
||||
}
|
||||
}
|
||||
|
||||
.note-body {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
max-height: 180px;
|
||||
overflow-y: auto;
|
||||
word-wrap: break-word;
|
||||
white-space: pre-wrap;
|
||||
padding-right: 8px;
|
||||
box-sizing: border-box;
|
||||
line-height: 1.6;
|
||||
color: #e2e8f0;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
max-height: 140px;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
max-height: 120px;
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
width: 6px;
|
||||
}
|
||||
}
|
||||
|
||||
.dialog-form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.field-label {
|
||||
display: block;
|
||||
font-size: 0.875rem;
|
||||
font-weight: 500;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.field-input {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.dialog-actions {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
@keyframes float {
|
||||
0%, 100% {
|
||||
transform: translateY(0px);
|
||||
}
|
||||
50% {
|
||||
transform: translateY(-10px);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes pulse {
|
||||
0%, 100% {
|
||||
transform: scale(1);
|
||||
opacity: 1;
|
||||
}
|
||||
50% {
|
||||
transform: scale(1.05);
|
||||
opacity: 0.8;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,255 @@
|
||||
import {Component, DestroyRef, inject, Input, OnChanges, OnInit, SimpleChanges} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
||||
import {Button} from 'primeng/button';
|
||||
import {Dialog} from 'primeng/dialog';
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
import {Textarea} from 'primeng/textarea';
|
||||
import {ConfirmDialog} from 'primeng/confirmdialog';
|
||||
import {ProgressSpinner} from 'primeng/progressspinner';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {ConfirmationService, MessageService} from 'primeng/api';
|
||||
import {TranslocoService} from '@jsverse/transloco';
|
||||
import {BookNote, BookNoteService, CreateBookNoteRequest} from '../../../../shared/service/book-note.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-book-notes-component',
|
||||
standalone: true,
|
||||
imports: [
|
||||
CommonModule,
|
||||
FormsModule,
|
||||
Button,
|
||||
Dialog,
|
||||
InputText,
|
||||
Textarea,
|
||||
ConfirmDialog,
|
||||
ProgressSpinner,
|
||||
Tooltip
|
||||
],
|
||||
templateUrl: './book-notes-component.html',
|
||||
styleUrl: './book-notes-component.scss'
|
||||
})
|
||||
export class BookNotesComponent implements OnInit, OnChanges {
|
||||
@Input() bookId!: number;
|
||||
|
||||
private bookNoteService = inject(BookNoteService);
|
||||
private confirmationService = inject(ConfirmationService);
|
||||
private messageService = inject(MessageService);
|
||||
private destroyRef = inject(DestroyRef);
|
||||
private readonly t = inject(TranslocoService);
|
||||
|
||||
notes: BookNote[] = [];
|
||||
loading = false;
|
||||
showCreateDialog = false;
|
||||
showEditDialog = false;
|
||||
selectedNote: BookNote | null = null;
|
||||
|
||||
newNote: CreateBookNoteRequest = {
|
||||
bookId: 0,
|
||||
title: '',
|
||||
content: ''
|
||||
};
|
||||
|
||||
editNote: CreateBookNoteRequest = {
|
||||
bookId: 0,
|
||||
title: '',
|
||||
content: ''
|
||||
};
|
||||
|
||||
ngOnInit(): void {
|
||||
if (this.bookId) {
|
||||
this.loadNotes();
|
||||
}
|
||||
}
|
||||
|
||||
ngOnChanges(changes: SimpleChanges): void {
|
||||
if (changes['bookId'] && changes['bookId'].currentValue) {
|
||||
this.loadNotes();
|
||||
}
|
||||
}
|
||||
|
||||
loadNotes(): void {
|
||||
if (!this.bookId) return;
|
||||
|
||||
this.loading = true;
|
||||
this.bookNoteService.getNotesForBook(this.bookId)
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe({
|
||||
next: (notes) => {
|
||||
this.notes = notes.sort((a, b) =>
|
||||
new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime()
|
||||
);
|
||||
this.loading = false;
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Failed to load notes:', error);
|
||||
this.loading = false;
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('common.error'),
|
||||
detail: this.t.translate('book.notes.toast.loadFailedDetail')
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
openCreateDialog(): void {
|
||||
this.newNote = {
|
||||
bookId: this.bookId,
|
||||
title: '',
|
||||
content: ''
|
||||
};
|
||||
this.showCreateDialog = true;
|
||||
}
|
||||
|
||||
openEditDialog(note: BookNote): void {
|
||||
this.selectedNote = note;
|
||||
this.editNote = {
|
||||
id: note.id,
|
||||
bookId: note.bookId,
|
||||
title: note.title,
|
||||
content: note.content
|
||||
};
|
||||
this.showEditDialog = true;
|
||||
}
|
||||
|
||||
createNote(): void {
|
||||
if (!this.newNote.title.trim() || !this.newNote.content.trim()) {
|
||||
this.messageService.add({
|
||||
severity: 'warn',
|
||||
summary: this.t.translate('book.notes.toast.validationSummary'),
|
||||
detail: this.t.translate('book.notes.toast.validationDetail')
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
this.bookNoteService.createOrUpdateNote(this.newNote)
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe({
|
||||
next: (note) => {
|
||||
this.notes.unshift(note);
|
||||
this.showCreateDialog = false;
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('common.success'),
|
||||
detail: this.t.translate('book.notes.toast.createSuccessDetail')
|
||||
});
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Failed to create note:', error);
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('common.error'),
|
||||
detail: this.t.translate('book.notes.toast.createFailedDetail')
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
updateNote(): void {
|
||||
if (!this.editNote.title?.trim() || !this.editNote.content?.trim()) {
|
||||
this.messageService.add({
|
||||
severity: 'warn',
|
||||
summary: this.t.translate('book.notes.toast.validationSummary'),
|
||||
detail: this.t.translate('book.notes.toast.validationDetail')
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
this.bookNoteService.createOrUpdateNote(this.editNote)
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe({
|
||||
next: (updatedNote) => {
|
||||
const index = this.notes.findIndex(n => n.id === this.selectedNote?.id);
|
||||
if (index !== -1) {
|
||||
this.notes[index] = updatedNote;
|
||||
this.notes.sort((a, b) =>
|
||||
new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime()
|
||||
);
|
||||
}
|
||||
this.showEditDialog = false;
|
||||
this.selectedNote = null;
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('common.success'),
|
||||
detail: this.t.translate('book.notes.toast.updateSuccessDetail')
|
||||
});
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Failed to update note:', error);
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('common.error'),
|
||||
detail: this.t.translate('book.notes.toast.updateFailedDetail')
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
deleteNote(note: BookNote): void {
|
||||
this.confirmationService.confirm({
|
||||
key: 'deleteNote',
|
||||
message: this.t.translate('book.notes.confirm.deleteMessage', {title: note.title}),
|
||||
header: this.t.translate('book.notes.confirm.deleteHeader'),
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
acceptIcon: 'pi pi-trash',
|
||||
rejectIcon: 'pi pi-times',
|
||||
acceptButtonStyleClass: 'p-button-danger, p-button-outlined p-button-danger',
|
||||
rejectButtonStyleClass: 'p-button-danger, p-button-outlined p-button-info',
|
||||
accept: () => {
|
||||
this.performDelete(note.id);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private performDelete(noteId: number): void {
|
||||
this.bookNoteService.deleteNote(noteId).subscribe({
|
||||
next: () => {
|
||||
this.notes = this.notes.filter(n => n.id !== noteId);
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('common.success'),
|
||||
detail: this.t.translate('book.notes.toast.deleteSuccessDetail')
|
||||
});
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Failed to delete note:', error);
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('common.error'),
|
||||
detail: this.t.translate('book.notes.toast.deleteFailedDetail')
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
cancelCreate(): void {
|
||||
this.showCreateDialog = false;
|
||||
this.newNote = {
|
||||
bookId: this.bookId,
|
||||
title: '',
|
||||
content: ''
|
||||
};
|
||||
}
|
||||
|
||||
cancelEdit(): void {
|
||||
this.showEditDialog = false;
|
||||
this.selectedNote = null;
|
||||
this.editNote = {
|
||||
bookId: this.bookId,
|
||||
title: '',
|
||||
content: ''
|
||||
};
|
||||
}
|
||||
|
||||
formatDate(dateString: string): string {
|
||||
return new Date(dateString).toLocaleDateString('en-US', {
|
||||
year: 'numeric',
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit'
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import {inject, Injectable} from '@angular/core';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {Observable} from 'rxjs';
|
||||
import {API_CONFIG} from '../../../../core/config/api-config';
|
||||
|
||||
export interface BookReview {
|
||||
id?: number;
|
||||
metadataProvider?: string;
|
||||
reviewerName?: string;
|
||||
title?: string;
|
||||
rating?: number;
|
||||
date?: string;
|
||||
body?: string;
|
||||
country?: string;
|
||||
spoiler?: boolean;
|
||||
followersCount?: number;
|
||||
textReviewsCount?: number;
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class BookReviewService {
|
||||
|
||||
private readonly url = `${API_CONFIG.BASE_URL}/api/v1/reviews`;
|
||||
private http = inject(HttpClient);
|
||||
|
||||
getByBookId(bookId: number): Observable<BookReview[]> {
|
||||
return this.http.get<BookReview[]>(`${this.url}/book/${bookId}`);
|
||||
}
|
||||
|
||||
refreshReviews(bookId: number): Observable<BookReview[]> {
|
||||
return this.http.post<BookReview[]>(`${this.url}/book/${bookId}/refresh`, {});
|
||||
}
|
||||
|
||||
delete(reviewId: number): Observable<void> {
|
||||
return this.http.delete<void>(`${this.url}/${reviewId}`);
|
||||
}
|
||||
|
||||
deleteAllByBookId(bookId: number): Observable<void> {
|
||||
return this.http.delete<void>(`${this.url}/book/${bookId}`);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,217 @@
|
||||
<ng-container *transloco="let t; prefix: 'book.reviews'">
|
||||
<div class="book-reviews-container">
|
||||
<div class="reviews-content">
|
||||
@if (loading) {
|
||||
<div class="loading-state">
|
||||
<p-progressSpinner/>
|
||||
<span class="loading-text">{{ t('labels.loadingReviews') }}</span>
|
||||
</div>
|
||||
} @else if (reviews?.length === 0) {
|
||||
<div class="empty-state">
|
||||
<div class="empty-state-icon">
|
||||
@if (hasPermission && !reviewsLocked && reviewDownloadEnabled) {
|
||||
<p-button
|
||||
outlined
|
||||
rounded
|
||||
icon="pi pi-download"
|
||||
severity="primary"
|
||||
(click)="fetchNewReviews()"
|
||||
[pTooltip]="t('tooltip.fetchReviews')"
|
||||
tooltipPosition="top"
|
||||
class="action-btn floating-btn">
|
||||
</p-button>
|
||||
}
|
||||
</div>
|
||||
<p class="empty-state-title">{{ t('empty.noReviews') }}</p>
|
||||
@if (!reviewDownloadEnabled) {
|
||||
<p class="empty-state-subtitle empty-state-subtitle--warning">
|
||||
{{ t('empty.downloadsDisabled') }}
|
||||
</p>
|
||||
} @else if (hasPermission && !reviewsLocked) {
|
||||
<p class="empty-state-subtitle">
|
||||
{{ t('empty.fetchPrompt') }}
|
||||
</p>
|
||||
}
|
||||
<div class="empty-state-decoration"></div>
|
||||
</div>
|
||||
} @else {
|
||||
<div class="reviews-scroll-container">
|
||||
<div class="reviews-horizontal-list">
|
||||
@for (review of reviews; track review.id || $index) {
|
||||
<div [class]="'review-card' + (!review.title ? ' no-title' : '') + (review.spoiler && !isSpoilerRevealed(review.id!) ? ' has-spoiler' : '')">
|
||||
@if (review.spoiler && !isSpoilerRevealed(review.id!)) {
|
||||
<p-button
|
||||
[label]="t('labels.showSpoiler')"
|
||||
icon="pi pi-eye"
|
||||
severity="warn"
|
||||
size="small"
|
||||
class="spoiler-overlay-button"
|
||||
(onClick)="revealSpoiler(review.id!)"/>
|
||||
}
|
||||
|
||||
<div class="review-header">
|
||||
<div class="review-header-inner">
|
||||
<div class="reviewer-info-group">
|
||||
<div class="reviewer-name-row">
|
||||
<span class="reviewer-name">{{ review.reviewerName || t('labels.anonymous') }}</span>
|
||||
@if (review.metadataProvider) {
|
||||
<p-tag
|
||||
[rounded]="true"
|
||||
[value]="review.metadataProvider"
|
||||
[severity]="getProviderSeverity(review.metadataProvider)"/>
|
||||
}
|
||||
@if (review.country) {
|
||||
<p-tag [rounded]="true" [value]="review.country" severity="info"/>
|
||||
}
|
||||
@if (review.spoiler) {
|
||||
<p-tag [rounded]="true" [value]="t('labels.spoiler')" severity="warn" icon="pi pi-exclamation-triangle"/>
|
||||
}
|
||||
</div>
|
||||
<div class="review-meta">
|
||||
<i class="pi pi-clock review-meta-icon"></i>
|
||||
@if (review.date) {
|
||||
<span class="review-meta-text">{{ formatDate(review.date) }}</span>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="review-actions">
|
||||
@if (review.rating) {
|
||||
<div class="rating-wrapper">
|
||||
<p-rating
|
||||
[ngModel]="review.rating"
|
||||
[readonly]="true"
|
||||
[stars]="5"/>
|
||||
<span class="rating-text">{{ review.rating }}/5</span>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (hasPermission) {
|
||||
@if (reviewsLocked) {
|
||||
<div class="lock-icon-container">
|
||||
<i class="pi pi-lock lock-icon"
|
||||
[pTooltip]="t('tooltip.reviewsLocked')"
|
||||
tooltipPosition="top"></i>
|
||||
</div>
|
||||
} @else {
|
||||
<p-button
|
||||
icon="pi pi-trash"
|
||||
size="small"
|
||||
severity="danger"
|
||||
text
|
||||
(onClick)="deleteReview(review)"
|
||||
[pTooltip]="t('tooltip.deleteReview')"
|
||||
tooltipPosition="top"
|
||||
class="action-btn-hover"/>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (review.title && (!review.spoiler || isSpoilerRevealed(review.id!))) {
|
||||
<div class="review-title-section">
|
||||
<h4 class="review-title"
|
||||
[pTooltip]="review.title"
|
||||
tooltipPosition="top">{{ review.title }}
|
||||
</h4>
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="review-content-area">
|
||||
@if (review.spoiler && !isSpoilerRevealed(review.id!)) {
|
||||
<div class="spoiler-blur-content">
|
||||
@if (review.title) {
|
||||
<h4 class="review-title review-title--blurred">{{ review.title }}</h4>
|
||||
}
|
||||
@if (review.body) {
|
||||
<div class="review-body review-body--blurred">{{ review.body }}</div>
|
||||
} @else {
|
||||
<div class="review-empty-text review-empty-text--blurred">{{ t('empty.noContent') }}</div>
|
||||
}
|
||||
</div>
|
||||
} @else {
|
||||
@if (review.body) {
|
||||
<div class="review-body">{{ review.body }}</div>
|
||||
} @else {
|
||||
<div class="review-empty-text">{{ t('empty.noContent') }}</div>
|
||||
}
|
||||
}
|
||||
<div class="review-fade-overlay"></div>
|
||||
</div>
|
||||
<div class="review-bottom-glow"></div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="action-bar">
|
||||
<div class="action-buttons">
|
||||
|
||||
@if (hasPermission) {
|
||||
<p-button
|
||||
outlined
|
||||
[icon]="reviewsLocked ? 'pi pi-lock' : 'pi pi-lock-open'"
|
||||
size="small"
|
||||
[severity]="reviewsLocked ? 'danger' : 'success'"
|
||||
[disabled]="!reviewDownloadEnabled || loading"
|
||||
(click)="toggleReviewsLock()"
|
||||
[pTooltip]="loading ? t('tooltip.pleaseWait') : (!reviewDownloadEnabled ? t('tooltip.enableDownloads') : (reviewsLocked ? t('tooltip.unlockReviews') : t('tooltip.lockReviews')))"
|
||||
tooltipPosition="left"
|
||||
class="action-btn"/>
|
||||
|
||||
<p-button
|
||||
outlined
|
||||
icon="pi pi-refresh"
|
||||
size="small"
|
||||
severity="primary"
|
||||
[loading]="loading"
|
||||
[disabled]="reviewsLocked || !reviewDownloadEnabled || loading"
|
||||
(click)="fetchNewReviews()"
|
||||
[pTooltip]="loading ? t('tooltip.pleaseWait') : (!reviewDownloadEnabled ? t('tooltip.enableDownloads') : (reviewsLocked ? t('tooltip.reviewsLocked') : t('tooltip.fetchNewReviews')))"
|
||||
tooltipPosition="left"
|
||||
class="action-btn"/>
|
||||
}
|
||||
|
||||
@if (hasPermission && reviews && reviews.length > 0) {
|
||||
<p-button
|
||||
outlined
|
||||
icon="pi pi-trash"
|
||||
size="small"
|
||||
severity="danger"
|
||||
[disabled]="reviewsLocked || loading"
|
||||
(click)="deleteAllReviews()"
|
||||
[pTooltip]="loading ? t('tooltip.pleaseWait') : (reviewsLocked ? t('tooltip.reviewsLocked') : t('tooltip.deleteAllReviews'))"
|
||||
tooltipPosition="left"
|
||||
class="action-btn"/>
|
||||
}
|
||||
|
||||
@if (reviews && reviews.length > 0) {
|
||||
<p-button
|
||||
outlined
|
||||
[icon]="allSpoilersRevealed ? 'pi pi-eye-slash' : 'pi pi-eye'"
|
||||
size="small"
|
||||
[severity]="allSpoilersRevealed ? 'warn' : 'info'"
|
||||
[disabled]="loading"
|
||||
(click)="toggleSpoilerVisibility()"
|
||||
[pTooltip]="loading ? t('tooltip.pleaseWait') : (allSpoilersRevealed ? t('tooltip.hideAllSpoilers') : t('tooltip.revealAllSpoilers'))"
|
||||
tooltipPosition="left"
|
||||
class="action-btn"/>
|
||||
|
||||
<p-button
|
||||
outlined
|
||||
icon="pi pi-sort-amount-down"
|
||||
size="small"
|
||||
severity="contrast"
|
||||
[disabled]="loading"
|
||||
(click)="toggleSortOrder()"
|
||||
[pTooltip]="loading ? t('tooltip.pleaseWait') : (sortAscending ? t('tooltip.sortNewest') : t('tooltip.sortOldest'))"
|
||||
tooltipPosition="left"
|
||||
class="action-btn"/>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
@@ -0,0 +1,402 @@
|
||||
.book-reviews-container {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
position: relative;
|
||||
display: flex;
|
||||
min-height: 250px;
|
||||
|
||||
.reviews-content {
|
||||
flex: 1;
|
||||
padding-right: 60px;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.action-bar {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
right: 0;
|
||||
transform: translateY(-50%);
|
||||
width: 50px;
|
||||
z-index: 1000;
|
||||
pointer-events: none;
|
||||
|
||||
.action-buttons {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
padding: 16px 8px;
|
||||
background: rgba(0, 0, 0, 0.1);
|
||||
border-radius: 8px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.2);
|
||||
backdrop-filter: blur(8px);
|
||||
pointer-events: auto;
|
||||
position: relative;
|
||||
top: -50%;
|
||||
|
||||
.action-btn {
|
||||
width: 34px;
|
||||
height: 34px;
|
||||
|
||||
::ng-deep {
|
||||
.p-button {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
padding: 0;
|
||||
|
||||
.p-button-icon {
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.loading-state {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 2rem;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.loading-text {
|
||||
color: #9ca3af;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
position: relative;
|
||||
padding: 3rem !important;
|
||||
text-align: center;
|
||||
color: #9ca3af;
|
||||
|
||||
.empty-state-title {
|
||||
font-size: 1.25rem;
|
||||
font-weight: 600;
|
||||
margin-top: 1rem;
|
||||
margin-bottom: 0.5rem;
|
||||
color: #e5e7eb;
|
||||
}
|
||||
|
||||
.empty-state-subtitle {
|
||||
max-width: 400px;
|
||||
margin: 0.5rem auto 0;
|
||||
line-height: 1.6;
|
||||
font-size: 0.875rem;
|
||||
color: #9ca3af;
|
||||
|
||||
&--warning {
|
||||
color: #fbbf24;
|
||||
}
|
||||
}
|
||||
|
||||
.empty-state-decoration {
|
||||
position: absolute;
|
||||
top: 20%;
|
||||
right: 15%;
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
border-radius: 50%;
|
||||
filter: blur(40px);
|
||||
animation: float 4s ease-in-out infinite;
|
||||
}
|
||||
}
|
||||
|
||||
.reviews-scroll-container {
|
||||
overflow-x: auto;
|
||||
overflow-y: hidden;
|
||||
padding-bottom: 8px;
|
||||
height: 100%;
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
height: 8px;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-track {
|
||||
background: var(--surface-ground);
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-thumb {
|
||||
background: var(--surface-border);
|
||||
border-radius: 4px;
|
||||
|
||||
&:hover {
|
||||
background: var(--primary-color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.reviews-horizontal-list {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
padding: 0.5rem;
|
||||
}
|
||||
|
||||
.review-card {
|
||||
width: 500px;
|
||||
height: 250px;
|
||||
flex-shrink: 0;
|
||||
padding: 0;
|
||||
border-radius: 16px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
|
||||
@media (max-width: 768px) {
|
||||
width: 340px;
|
||||
height: 220px;
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
width: 290px;
|
||||
height: 200px;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
transform: translateY(-2px);
|
||||
border-color: color-mix(in srgb, var(--primary-color), transparent 50%);
|
||||
|
||||
.action-btn-hover {
|
||||
opacity: 1;
|
||||
transform: scale(1);
|
||||
}
|
||||
}
|
||||
|
||||
&.no-title {
|
||||
.review-content-area {
|
||||
height: calc(100% - 80px);
|
||||
}
|
||||
}
|
||||
|
||||
&.has-spoiler {
|
||||
.review-content-area {
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
&::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0, 0, 0, 0.3);
|
||||
z-index: 50;
|
||||
pointer-events: none;
|
||||
}
|
||||
}
|
||||
|
||||
.review-header {
|
||||
flex-shrink: 0;
|
||||
background: linear-gradient(135deg, rgba(40, 40, 40, 0.8), rgba(30, 30, 30, 0.8));
|
||||
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
|
||||
position: relative;
|
||||
|
||||
.review-header-inner {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: flex-start;
|
||||
padding: 0.75rem;
|
||||
}
|
||||
|
||||
.reviewer-info-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.25rem;
|
||||
}
|
||||
|
||||
.reviewer-name-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.reviewer-name {
|
||||
max-width: 120px;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
background: linear-gradient(135deg, #f8fafc, #e2e8f0);
|
||||
-webkit-background-clip: text;
|
||||
-webkit-text-fill-color: transparent;
|
||||
background-clip: text;
|
||||
font-weight: 500;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.review-meta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
opacity: 0.8;
|
||||
|
||||
i {
|
||||
color: #3b82f6;
|
||||
}
|
||||
}
|
||||
|
||||
.review-meta-icon {
|
||||
font-size: 0.75rem;
|
||||
margin-right: 0.25rem;
|
||||
}
|
||||
|
||||
.review-meta-text {
|
||||
font-size: 0.875rem;
|
||||
color: #9ca3af;
|
||||
}
|
||||
|
||||
.review-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.rating-wrapper {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.25rem;
|
||||
}
|
||||
|
||||
.rating-text {
|
||||
font-size: 0.875rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.lock-icon-container {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 2rem;
|
||||
height: 2rem;
|
||||
}
|
||||
|
||||
.lock-icon {
|
||||
color: #f59e0b;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.action-btn-hover {
|
||||
opacity: 0.7;
|
||||
transition: all 0.3s ease;
|
||||
transform: scale(0.9);
|
||||
|
||||
::ng-deep .p-button {
|
||||
border-radius: 8px;
|
||||
|
||||
&:hover {
|
||||
transform: scale(1.1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.review-title-section {
|
||||
flex-shrink: 0;
|
||||
border-bottom: 1px solid var(--surface-border);
|
||||
padding: 8px 16px 4px 16px;
|
||||
}
|
||||
|
||||
.review-content-area {
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
position: relative;
|
||||
padding: 8px 16px 16px 16px;
|
||||
|
||||
.review-fade-overlay {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 30px;
|
||||
background: linear-gradient(transparent, rgba(20, 20, 20, 0.9));
|
||||
pointer-events: none;
|
||||
}
|
||||
}
|
||||
|
||||
.spoiler-overlay-button {
|
||||
position: absolute;
|
||||
top: 62%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
z-index: 100;
|
||||
pointer-events: auto;
|
||||
}
|
||||
}
|
||||
|
||||
.review-title {
|
||||
max-width: 450px;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
cursor: help;
|
||||
font-weight: 500;
|
||||
font-size: 1.25rem;
|
||||
color: #e5e7eb;
|
||||
line-height: 1.25;
|
||||
margin: 0;
|
||||
|
||||
&--blurred {
|
||||
filter: blur(4px);
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
.review-body {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
max-height: 210px;
|
||||
overflow-y: auto;
|
||||
word-wrap: break-word;
|
||||
white-space: pre-wrap;
|
||||
box-sizing: border-box;
|
||||
color: #d4d4d8;
|
||||
|
||||
&--blurred {
|
||||
filter: blur(4px);
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
width: 4px;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-track {
|
||||
background: var(--surface-ground);
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-thumb {
|
||||
background: var(--surface-border);
|
||||
border-radius: 2px;
|
||||
|
||||
&:hover {
|
||||
background: var(--primary-color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.review-empty-text {
|
||||
color: #a1a1aa;
|
||||
font-style: italic;
|
||||
font-size: 0.875rem;
|
||||
|
||||
&--blurred {
|
||||
filter: blur(4px);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes float {
|
||||
0%, 100% {
|
||||
transform: translateY(0px);
|
||||
}
|
||||
50% {
|
||||
transform: translateY(-10px);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,330 @@
|
||||
import {Component, DestroyRef, effect, inject, Input, OnChanges, OnInit, signal, SimpleChanges} from '@angular/core';
|
||||
|
||||
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
||||
import {BookReview, BookReviewService} from './book-review-service';
|
||||
import {ProgressSpinner} from 'primeng/progressspinner';
|
||||
import {Rating} from 'primeng/rating';
|
||||
import {Tag} from 'primeng/tag';
|
||||
import {Button} from 'primeng/button';
|
||||
import {ConfirmationService, MessageService} from 'primeng/api';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
import {UserService} from '../../../settings/user-management/user.service';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {BookService} from '../../service/book.service';
|
||||
import {BookMetadataManageService} from '../../service/book-metadata-manage.service';
|
||||
import {AppSettingsService} from '../../../../shared/service/app-settings.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-book-reviews',
|
||||
standalone: true,
|
||||
imports: [ProgressSpinner, Rating, Tag, Button, FormsModule, Tooltip, TranslocoDirective],
|
||||
templateUrl: './book-reviews.component.html',
|
||||
styleUrl: './book-reviews.component.scss'
|
||||
})
|
||||
export class BookReviewsComponent implements OnInit, OnChanges {
|
||||
@Input() bookId!: number;
|
||||
@Input() reviews: BookReview[] | undefined = [];
|
||||
@Input() active: boolean = false;
|
||||
|
||||
private reviewService = inject(BookReviewService);
|
||||
private bookService = inject(BookService);
|
||||
private bookMetadataManageService = inject(BookMetadataManageService);
|
||||
private confirmationService = inject(ConfirmationService);
|
||||
private messageService = inject(MessageService);
|
||||
private userService = inject(UserService);
|
||||
private appSettingsService = inject(AppSettingsService);
|
||||
private destroyRef = inject(DestroyRef);
|
||||
private readonly t = inject(TranslocoService);
|
||||
private bookIdState = signal<number | null>(null);
|
||||
|
||||
loading = false;
|
||||
hasPermission = false;
|
||||
revealedSpoilers = new Set<number>();
|
||||
sortAscending = false;
|
||||
reviewsLocked = false;
|
||||
allSpoilersRevealed = false;
|
||||
reviewDownloadEnabled = true;
|
||||
|
||||
constructor() {
|
||||
effect(() => {
|
||||
const bookId = this.bookIdState();
|
||||
if (!bookId) {
|
||||
this.reviewsLocked = false;
|
||||
return;
|
||||
}
|
||||
|
||||
const book = this.bookService.findBookById(bookId);
|
||||
this.reviewsLocked = book?.metadata?.reviewsLocked ?? false;
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.checkUserPermissions();
|
||||
this.subscribeToAppSettings();
|
||||
}
|
||||
|
||||
ngOnChanges(changes: SimpleChanges): void {
|
||||
if (changes['bookId'] && changes['bookId'].currentValue) {
|
||||
this.bookIdState.set(changes['bookId'].currentValue);
|
||||
this.loadReviews();
|
||||
}
|
||||
}
|
||||
|
||||
private loadReviews(): void {
|
||||
if (this.loading || !this.bookId) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.loading = true;
|
||||
this.reviewService.getByBookId(this.bookId)
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe({
|
||||
next: (reviews) => {
|
||||
this.reviews = this.sortReviewsByDate(reviews || []);
|
||||
this.loading = false;
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Failed to load reviews for bookId', this.bookId, ':', error);
|
||||
this.reviews = [];
|
||||
this.loading = false;
|
||||
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('book.reviews.toast.loadFailedSummary'),
|
||||
detail: this.t.translate('book.reviews.toast.loadFailedDetail'),
|
||||
life: 3000
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fetchNewReviews(): void {
|
||||
if (!this.bookId || this.loading || this.reviewsLocked) return;
|
||||
|
||||
this.loading = true;
|
||||
this.revealedSpoilers.clear();
|
||||
|
||||
this.reviewService.refreshReviews(this.bookId)
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe({
|
||||
next: (reviews) => {
|
||||
this.reviews = this.sortReviewsByDate(reviews || []);
|
||||
this.loading = false;
|
||||
this.updateSpoilerState();
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('book.reviews.toast.reviewsUpdatedSummary'),
|
||||
detail: this.t.translate('book.reviews.toast.reviewsUpdatedDetail'),
|
||||
life: 3000
|
||||
});
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Failed to fetch new reviews:', error);
|
||||
this.loading = false;
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('book.reviews.toast.fetchFailedSummary'),
|
||||
detail: this.t.translate('book.reviews.toast.fetchFailedDetail'),
|
||||
life: 3000
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
deleteAllReviews(): void {
|
||||
if (!this.reviews || this.reviews.length === 0 || this.reviewsLocked) return;
|
||||
|
||||
this.confirmationService.confirm({
|
||||
message: this.t.translate('book.reviews.confirm.deleteAllMessage', {count: this.reviews.length}),
|
||||
header: this.t.translate('book.reviews.confirm.deleteAllHeader'),
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
acceptIcon: 'pi pi-trash',
|
||||
rejectIcon: 'pi pi-times',
|
||||
acceptButtonStyleClass: 'p-button-danger',
|
||||
accept: () => {
|
||||
if (!this.bookId) return;
|
||||
|
||||
this.reviewService.deleteAllByBookId(this.bookId).subscribe({
|
||||
next: () => {
|
||||
this.reviews = [];
|
||||
this.revealedSpoilers.clear();
|
||||
this.allSpoilersRevealed = false;
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('book.reviews.toast.allDeletedSummary'),
|
||||
detail: this.t.translate('book.reviews.toast.allDeletedDetail'),
|
||||
life: 3000
|
||||
});
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Failed to delete all reviews:', error);
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('book.reviews.toast.deleteAllFailedSummary'),
|
||||
detail: this.t.translate('book.reviews.toast.deleteAllFailedDetail'),
|
||||
life: 3000
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
toggleSpoilerVisibility(): void {
|
||||
if (this.allSpoilersRevealed) {
|
||||
this.hideAllSpoilers();
|
||||
} else {
|
||||
this.revealAllSpoilers();
|
||||
}
|
||||
}
|
||||
|
||||
hideAllSpoilers(): void {
|
||||
this.revealedSpoilers.clear();
|
||||
this.allSpoilersRevealed = false;
|
||||
}
|
||||
|
||||
revealAllSpoilers(): void {
|
||||
if (this.reviews) {
|
||||
this.reviews.forEach(review => {
|
||||
if (review.spoiler && review.id) {
|
||||
this.revealedSpoilers.add(review.id);
|
||||
}
|
||||
});
|
||||
this.allSpoilersRevealed = true;
|
||||
}
|
||||
}
|
||||
|
||||
toggleReviewsLock(): void {
|
||||
if (!this.bookId) return;
|
||||
|
||||
const newLockState = !this.reviewsLocked;
|
||||
const fieldActions: Record<string, 'LOCK' | 'UNLOCK'> = {
|
||||
'reviewsLocked': newLockState ? 'LOCK' : 'UNLOCK'
|
||||
};
|
||||
|
||||
this.bookMetadataManageService.toggleFieldLocks([this.bookId], fieldActions)
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'info',
|
||||
summary: this.t.translate(newLockState ? 'book.reviews.toast.lockedSummary' : 'book.reviews.toast.unlockedSummary'),
|
||||
detail: this.t.translate(newLockState ? 'book.reviews.toast.lockedDetail' : 'book.reviews.toast.unlockedDetail'),
|
||||
life: 3000
|
||||
});
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Failed to toggle lock status:', error);
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('book.reviews.toast.lockFailedSummary'),
|
||||
detail: this.t.translate('book.reviews.toast.lockFailedDetail'),
|
||||
life: 3000
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
toggleSortOrder(): void {
|
||||
this.sortAscending = !this.sortAscending;
|
||||
if (this.reviews) {
|
||||
this.reviews = this.sortReviewsByDate([...this.reviews]);
|
||||
}
|
||||
}
|
||||
|
||||
private sortReviewsByDate(reviews: BookReview[]): BookReview[] {
|
||||
return reviews.sort((a, b) => {
|
||||
if (!a.date && !b.date) return 0;
|
||||
if (!a.date) return this.sortAscending ? -1 : 1;
|
||||
if (!b.date) return this.sortAscending ? 1 : -1;
|
||||
|
||||
const dateA = new Date(a.date).getTime();
|
||||
const dateB = new Date(b.date).getTime();
|
||||
|
||||
return this.sortAscending ? dateA - dateB : dateB - dateA;
|
||||
});
|
||||
}
|
||||
|
||||
private checkUserPermissions(): void {
|
||||
const user = this.userService.currentUser();
|
||||
this.hasPermission = user?.permissions?.admin ||
|
||||
user?.permissions?.canEditMetadata || false;
|
||||
}
|
||||
|
||||
deleteReview(review: BookReview): void {
|
||||
if (!review.id || this.reviewsLocked) return;
|
||||
|
||||
this.confirmationService.confirm({
|
||||
message: this.t.translate('book.reviews.confirm.deleteMessage', {reviewer: review.reviewerName || 'Anonymous'}),
|
||||
header: this.t.translate('book.reviews.confirm.deleteHeader'),
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
acceptIcon: 'pi pi-trash',
|
||||
rejectIcon: 'pi pi-times',
|
||||
acceptButtonStyleClass: 'p-button-danger',
|
||||
accept: () => {
|
||||
this.reviewService.delete(review.id!).subscribe({
|
||||
next: () => {
|
||||
this.reviews = this.reviews?.filter(r => r.id !== review.id);
|
||||
this.updateSpoilerState();
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('book.reviews.toast.deleteSuccessSummary'),
|
||||
detail: this.t.translate('book.reviews.toast.deleteSuccessDetail'),
|
||||
life: 2000
|
||||
});
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Failed to delete review:', error);
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('book.reviews.toast.deleteFailedSummary'),
|
||||
detail: this.t.translate('book.reviews.toast.deleteFailedDetail'),
|
||||
life: 3000
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
revealSpoiler(reviewId: number): void {
|
||||
if (reviewId) {
|
||||
this.revealedSpoilers.add(reviewId);
|
||||
this.updateSpoilerState();
|
||||
}
|
||||
}
|
||||
|
||||
private updateSpoilerState(): void {
|
||||
const spoilerReviews = this.reviews?.filter(r => r.spoiler) || [];
|
||||
const revealedSpoilerReviews = spoilerReviews.filter(r => r.id && this.revealedSpoilers.has(r.id));
|
||||
this.allSpoilersRevealed = spoilerReviews.length > 0 && spoilerReviews.length === revealedSpoilerReviews.length;
|
||||
}
|
||||
|
||||
formatDate(dateString: string): string {
|
||||
const date = new Date(dateString);
|
||||
return date.toLocaleDateString('en-US', {
|
||||
year: 'numeric',
|
||||
month: 'long',
|
||||
day: 'numeric'
|
||||
});
|
||||
}
|
||||
|
||||
isSpoilerRevealed(reviewId: number): boolean {
|
||||
return this.revealedSpoilers.has(reviewId);
|
||||
}
|
||||
|
||||
private subscribeToAppSettings(): void {
|
||||
const settings = this.appSettingsService.appSettings();
|
||||
this.reviewDownloadEnabled = settings?.metadataPublicReviewsSettings?.downloadEnabled ?? true;
|
||||
}
|
||||
|
||||
getProviderSeverity(provider: string): 'success' | 'warn' {
|
||||
switch (provider?.toLowerCase()) {
|
||||
case 'amazon':
|
||||
return 'warn';
|
||||
default:
|
||||
return 'success';
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<ng-container *transloco="let t; prefix: 'book.searcher'">
|
||||
<div class="book-searcher-container">
|
||||
<p-iconfield class="search-iconfield" [class.focused]="isSearchFocused" [class.has-results]="isDropdownOpen">
|
||||
<p-inputicon class="pi pi-search"/>
|
||||
<input
|
||||
type="text"
|
||||
pInputText
|
||||
[(ngModel)]="searchQuery"
|
||||
(input)="onSearchInputChange()"
|
||||
(focus)="isSearchFocused = true"
|
||||
(keydown)="onKeydown($event)"
|
||||
[placeholder]="t('placeholder')"
|
||||
class="search-input"
|
||||
/>
|
||||
@if (searchQuery) {
|
||||
<p-button
|
||||
icon="pi pi-times"
|
||||
(click)="clearSearch()"
|
||||
[text]="true"
|
||||
[rounded]="true"
|
||||
class="clear-search-btn"
|
||||
[attr.aria-label]="t('clearSearch')">
|
||||
</p-button>
|
||||
}
|
||||
</p-iconfield>
|
||||
|
||||
@if (books.length > 0 || searchQuery) {
|
||||
<div
|
||||
class="search-dropdown layout-menu"
|
||||
[class.show]="isDropdownOpen"
|
||||
>
|
||||
@if (isLoading) {
|
||||
@for (i of [1,2,3]; track i) {
|
||||
<div class="search-skeleton-item">
|
||||
<p-skeleton width="50px" height="67px" borderRadius="4px"/>
|
||||
<div class="search-skeleton-details">
|
||||
<p-skeleton width="80%" height="1rem"/>
|
||||
<p-skeleton width="60%" height="0.8rem"/>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
} @else if (books.length > 0) {
|
||||
@for (book of books; track book; let idx = $index) {
|
||||
<div class="search-dropdown-item" [class.active]="activeIndex === idx" (click)="onBookClick(book)">
|
||||
<div class="search-item-content">
|
||||
<img
|
||||
[attr.src]="urlHelper.getThumbnailUrl(book.id, book.metadata?.coverUpdatedOn)"
|
||||
[alt]="t('bookCoverAlt')"
|
||||
class="search-book-cover"
|
||||
/>
|
||||
<div class="search-book-details">
|
||||
<div class="search-book-title-container">
|
||||
<p class="search-book-name">
|
||||
{{ book.metadata?.title | slice: 0:70 }}
|
||||
</p>
|
||||
</div>
|
||||
<div class="search-book-meta-line">
|
||||
@if (book.metadata?.authors?.length ?? 0 > 0) {
|
||||
<p class="search-book-authors">{{ t('byPrefix') }} {{ getAuthorNames(book.metadata?.authors) }}</p>
|
||||
}
|
||||
@if (getPublishedYear(book.metadata?.publishedDate)) {
|
||||
<span class="metadata-badge year-badge">{{ getPublishedYear(book.metadata?.publishedDate) }}</span>
|
||||
}
|
||||
</div>
|
||||
@if (getSeriesInfo(book.metadata?.seriesName, book.metadata?.seriesNumber)) {
|
||||
<div class="search-book-series metadata-badge series-badge">
|
||||
<i class="pi pi-book"></i>
|
||||
<span>{{ getSeriesInfo(book.metadata?.seriesName, book.metadata?.seriesNumber) }}</span>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
} @else {
|
||||
<div class="search-dropdown-item no-results">
|
||||
<span>{{ t('noResults') }}</span>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</ng-container>
|
||||
@@ -0,0 +1,261 @@
|
||||
.book-searcher-container {
|
||||
margin-left: 0.5rem;
|
||||
position: relative;
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
|
||||
@media (min-width: 768px) {
|
||||
margin-left: 1.25rem;
|
||||
max-width: 315px;
|
||||
transition: max-width 0.3s ease;
|
||||
}
|
||||
|
||||
&:has(.search-iconfield.focused),
|
||||
&:has(.search-iconfield.has-results) {
|
||||
@media (min-width: 768px) {
|
||||
max-width: 100%;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.search-iconfield {
|
||||
width: 100%;
|
||||
|
||||
@media (min-width: 640px) {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
}
|
||||
|
||||
.search-input {
|
||||
width: 100%;
|
||||
padding-right: 2.5rem;
|
||||
height: 2.5rem;
|
||||
line-height: 2.5rem;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.clear-search-btn {
|
||||
position: absolute;
|
||||
right: 0.5rem;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
display: none;
|
||||
|
||||
@media (min-width: 640px) {
|
||||
display: inline-flex;
|
||||
}
|
||||
}
|
||||
|
||||
.search-dropdown {
|
||||
position: absolute;
|
||||
top: calc(100% + 0.5rem);
|
||||
left: 0;
|
||||
width: 100%;
|
||||
max-width: 600px;
|
||||
background-color: var(--card-background);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1),
|
||||
0 2px 4px -1px rgba(0, 0, 0, 0.06),
|
||||
0 10px 15px -3px rgba(0, 0, 0, 0.1);
|
||||
z-index: 1000;
|
||||
max-height: min(70vh, calc(100dvh - 4rem));
|
||||
overflow-y: auto;
|
||||
opacity: 0;
|
||||
height: 0;
|
||||
transform: translateY(-10px);
|
||||
transition: opacity 0.2s ease, transform 0.2s ease, height 0.2s ease;
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
width: 8px;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-track {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-thumb {
|
||||
background: var(--border-color);
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-thumb:hover {
|
||||
background: var(--text-secondary-color);
|
||||
}
|
||||
}
|
||||
|
||||
.search-dropdown.show {
|
||||
opacity: 1;
|
||||
height: auto;
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
.search-dropdown-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.2s ease;
|
||||
border-bottom: 1px solid color-mix(in srgb, var(--border-color) 50%, transparent);
|
||||
|
||||
&:first-child {
|
||||
border-radius: 8px 8px 0 0;
|
||||
}
|
||||
|
||||
&:last-child {
|
||||
border-radius: 0 0 8px 8px;
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
&:hover,
|
||||
&.active {
|
||||
background-color: var(--surface-hover);
|
||||
}
|
||||
|
||||
&.no-results {
|
||||
padding: 2rem 1rem;
|
||||
text-align: center;
|
||||
color: var(--text-secondary-color);
|
||||
font-style: italic;
|
||||
}
|
||||
}
|
||||
|
||||
.search-item-content {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: flex-start;
|
||||
gap: 1rem;
|
||||
width: 100%;
|
||||
padding: 0.75rem 1rem;
|
||||
}
|
||||
|
||||
.search-book-cover {
|
||||
width: 50px;
|
||||
height: 67px;
|
||||
min-width: 50px;
|
||||
object-fit: cover;
|
||||
border-radius: 4px;
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||
background-color: var(--surface-ground);
|
||||
aspect-ratio: 2/3;
|
||||
}
|
||||
|
||||
.search-book-details {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.25rem;
|
||||
}
|
||||
|
||||
.search-book-title-container {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.search-book-name {
|
||||
font-weight: 600;
|
||||
font-size: 0.95rem;
|
||||
line-height: 1.4;
|
||||
color: var(--text-color);
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
word-break: break-word;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.search-book-meta-line {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.search-book-authors {
|
||||
font-size: 0.9rem;
|
||||
font-style: italic;
|
||||
color: var(--text-secondary-color);
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
margin: 0;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.search-book-year {
|
||||
font-size: 0.8rem;
|
||||
color: var(--text-secondary-color);
|
||||
background-color: var(--surface-ground);
|
||||
padding: 0.125rem 0.5rem;
|
||||
border-radius: 4px;
|
||||
white-space: nowrap;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.search-book-series {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.375rem;
|
||||
font-size: 0.8rem;
|
||||
color: var(--primary-color);
|
||||
padding: 0.075rem 0.125rem;
|
||||
border-radius: 4px;
|
||||
width: fit-content;
|
||||
|
||||
i {
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
|
||||
span {
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
|
||||
.search-book-metadata {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.5rem;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.metadata-badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.25rem;
|
||||
font-size: 0.8rem;
|
||||
padding: 0.1rem 0.25rem;
|
||||
border-radius: 4px;
|
||||
background-color: var(--surface-hover);
|
||||
color: var(--text-secondary-color);
|
||||
white-space: nowrap;
|
||||
|
||||
i {
|
||||
font-size: 0.7rem;
|
||||
}
|
||||
|
||||
&.series-badge {
|
||||
background-color: color-mix(in srgb, var(--p-primary-color) 10%, transparent);
|
||||
color: var(--p-primary-color);
|
||||
}
|
||||
}
|
||||
|
||||
.search-skeleton-item {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
gap: 1rem;
|
||||
padding: 0.75rem 1rem;
|
||||
}
|
||||
|
||||
.search-skeleton-details {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
flex: 1;
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
import {Component, ElementRef, HostListener, computed, inject, signal} from '@angular/core';
|
||||
import {toObservable, toSignal} from '@angular/core/rxjs-interop';
|
||||
import {debounceTime, distinctUntilChanged} from 'rxjs/operators';
|
||||
import {Book} from '../../model/book.model';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {InputTextModule} from 'primeng/inputtext';
|
||||
import {BookService} from '../../service/book.service';
|
||||
import {Button} from 'primeng/button';
|
||||
import {SlicePipe} from '@angular/common';
|
||||
import {Skeleton} from 'primeng/skeleton';
|
||||
import {UrlHelperService} from '../../../../shared/service/url-helper.service';
|
||||
import {Router} from '@angular/router';
|
||||
import {IconField} from 'primeng/iconfield';
|
||||
import {InputIcon} from 'primeng/inputicon';
|
||||
import {filterBooksBySearchTerm} from '../book-browser/filters/HeaderFilter';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
@Component({
|
||||
selector: 'app-book-searcher',
|
||||
templateUrl: './book-searcher.component.html',
|
||||
imports: [
|
||||
FormsModule,
|
||||
InputTextModule,
|
||||
Button,
|
||||
SlicePipe,
|
||||
Skeleton,
|
||||
IconField,
|
||||
InputIcon,
|
||||
TranslocoDirective,
|
||||
],
|
||||
styleUrls: ['./book-searcher.component.scss'],
|
||||
standalone: true
|
||||
})
|
||||
export class BookSearcherComponent {
|
||||
searchQuery = '';
|
||||
activeIndex = -1;
|
||||
isSearchFocused = false;
|
||||
|
||||
private readonly searchTerm = signal('');
|
||||
private readonly debouncedSearchTerm = toSignal(
|
||||
toObservable(this.searchTerm).pipe(
|
||||
debounceTime(200),
|
||||
distinctUntilChanged()
|
||||
),
|
||||
{initialValue: ''}
|
||||
);
|
||||
private readonly filteredBooks = computed(() => {
|
||||
const term = this.debouncedSearchTerm().trim();
|
||||
if (term.length < 2) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return filterBooksBySearchTerm(this.bookService.books(), term).slice(0, 50);
|
||||
});
|
||||
|
||||
private bookService = inject(BookService);
|
||||
private router = inject(Router);
|
||||
protected urlHelper = inject(UrlHelperService);
|
||||
private readonly t = inject(TranslocoService);
|
||||
private elRef = inject(ElementRef);
|
||||
|
||||
get books(): Book[] {
|
||||
return this.filteredBooks();
|
||||
}
|
||||
|
||||
get isLoading(): boolean {
|
||||
const rawTerm = this.searchTerm().trim();
|
||||
return rawTerm.length >= 2 && rawTerm !== this.debouncedSearchTerm().trim();
|
||||
}
|
||||
|
||||
getAuthorNames(authors: string[] | undefined): string {
|
||||
return authors?.join(', ') || this.t.translate('book.searcher.unknownAuthor');
|
||||
}
|
||||
|
||||
getPublishedYear(publishedDate: string | undefined): string | null {
|
||||
if (!publishedDate) return null;
|
||||
const year = publishedDate.split('-')[0];
|
||||
return year && year.length === 4 ? year : null;
|
||||
}
|
||||
|
||||
getSeriesInfo(seriesName: string | undefined, seriesNumber: number | null | undefined): string | null {
|
||||
if (!seriesName) return null;
|
||||
if (seriesNumber) {
|
||||
return `${seriesName} #${seriesNumber}`;
|
||||
}
|
||||
return seriesName;
|
||||
}
|
||||
|
||||
onSearchInputChange(): void {
|
||||
this.searchTerm.set(this.searchQuery.trim());
|
||||
this.activeIndex = -1;
|
||||
}
|
||||
|
||||
onBookClick(book: Book): void {
|
||||
this.clearSearch();
|
||||
this.router.navigate(['/book', book.id], {
|
||||
queryParams: {tab: 'view'}
|
||||
});
|
||||
}
|
||||
|
||||
clearSearch(): void {
|
||||
this.searchQuery = '';
|
||||
this.searchTerm.set('');
|
||||
this.activeIndex = -1;
|
||||
}
|
||||
|
||||
get isDropdownOpen(): boolean {
|
||||
return this.books.length > 0 || this.isLoading;
|
||||
}
|
||||
|
||||
@HostListener('document:click', ['$event'])
|
||||
onDocumentClick(event: Event): void {
|
||||
if (!this.elRef.nativeElement.contains(event.target)) {
|
||||
this.clearSearch();
|
||||
this.isSearchFocused = false;
|
||||
}
|
||||
}
|
||||
|
||||
onKeydown(event: KeyboardEvent): void {
|
||||
if (!this.isDropdownOpen) return;
|
||||
|
||||
switch (event.key) {
|
||||
case 'ArrowDown':
|
||||
this.activeIndex = Math.min(this.activeIndex + 1, this.books.length - 1);
|
||||
event.preventDefault();
|
||||
break;
|
||||
case 'ArrowUp':
|
||||
this.activeIndex = Math.max(this.activeIndex - 1, 0);
|
||||
event.preventDefault();
|
||||
break;
|
||||
case 'Enter':
|
||||
if (this.activeIndex >= 0 && this.activeIndex < this.books.length) {
|
||||
this.onBookClick(this.books[this.activeIndex]);
|
||||
}
|
||||
break;
|
||||
case 'Escape':
|
||||
this.clearSearch();
|
||||
(event.target as HTMLElement).blur();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
<ng-container *transloco="let t; prefix: 'book.sender'">
|
||||
<div class="book-sender-container">
|
||||
<div class="panel-header">
|
||||
<div class="header-icon-wrapper">
|
||||
<i class="pi pi-envelope header-icon"></i>
|
||||
</div>
|
||||
<div class="header-text">
|
||||
<h2 class="panel-title">{{ t('title') }}</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">
|
||||
<div class="form-fields">
|
||||
<div class="form-field">
|
||||
<label class="field-label">{{ t('emailProvider') }}</label>
|
||||
<p-select
|
||||
[options]="emailProviders"
|
||||
optionLabel="label"
|
||||
[placeholder]="t('selectProvider')"
|
||||
[(ngModel)]="selectedProvider"
|
||||
appendTo="body"
|
||||
class="full-width">
|
||||
</p-select>
|
||||
</div>
|
||||
|
||||
<div class="form-field">
|
||||
<label class="field-label">{{ t('recipient') }}</label>
|
||||
<p-select
|
||||
[options]="emailRecipients"
|
||||
optionLabel="label"
|
||||
[placeholder]="t('selectRecipient')"
|
||||
[(ngModel)]="selectedRecipient"
|
||||
[disabled]="!selectedProvider"
|
||||
appendTo="body"
|
||||
class="full-width">
|
||||
</p-select>
|
||||
</div>
|
||||
|
||||
@if (emailableFiles.length > 0) {
|
||||
<div class="form-field">
|
||||
<label class="field-label">{{ t('fileFormat') }}</label>
|
||||
<div class="format-options">
|
||||
@for (file of emailableFiles; track file.id) {
|
||||
<div class="format-option" [class.selected]="selectedFileId === file.id">
|
||||
<p-radioButton name="fileFormat" [value]="file.id" [(ngModel)]="selectedFileId"/>
|
||||
<div class="format-info">
|
||||
<span class="format-type">{{ file.bookType || t('unknownFormat') }}</span>
|
||||
@if (file.isPrimary) { <span class="primary-badge">{{ t('primaryBadge') }}</span> }
|
||||
<span class="file-size">{{ formatFileSize(file.fileSizeKb) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (showLargeFileWarning) {
|
||||
<div class="warning-banner">
|
||||
<i class="pi pi-exclamation-triangle"></i>
|
||||
<span>{{ t('largeFileWarning') }}</span>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="dialog-footer">
|
||||
<p-button
|
||||
icon="pi pi-envelope"
|
||||
[label]="t('sendBook')"
|
||||
[disabled]="!selectedProvider || !selectedRecipient"
|
||||
(onClick)="sendBook()">
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
@@ -0,0 +1,124 @@
|
||||
@use '../../../../shared/styles/panel-shared' as panel;
|
||||
|
||||
.book-sender-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.panel-header {
|
||||
@include panel.panel-header;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.dialog-content {
|
||||
flex: 1;
|
||||
padding: 1.5rem;
|
||||
background: var(--card-background);
|
||||
border: 1px solid var(--border-color);
|
||||
border-top: none;
|
||||
border-bottom: none;
|
||||
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
|
||||
.dialog-footer {
|
||||
@include panel.dialog-footer;
|
||||
}
|
||||
|
||||
.form-fields {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1.5rem;
|
||||
}
|
||||
|
||||
.form-field {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.field-label {
|
||||
font-size: 0.875rem;
|
||||
font-weight: 500;
|
||||
color: #d1d5db;
|
||||
}
|
||||
|
||||
:host ::ng-deep .full-width {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.format-options {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.format-option {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
padding: 0.75rem;
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
transition: all 0.15s ease;
|
||||
|
||||
&:hover {
|
||||
background: rgba(255, 255, 255, 0.03);
|
||||
border-color: var(--p-primary-400);
|
||||
}
|
||||
|
||||
&.selected {
|
||||
background: rgba(var(--p-primary-500-rgb), 0.1);
|
||||
border-color: var(--p-primary-500);
|
||||
}
|
||||
}
|
||||
|
||||
.format-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.format-type {
|
||||
font-weight: 500;
|
||||
color: #e5e7eb;
|
||||
}
|
||||
|
||||
.primary-badge {
|
||||
font-size: 0.7rem;
|
||||
font-weight: 600;
|
||||
padding: 0.125rem 0.375rem;
|
||||
background: var(--p-primary-500);
|
||||
color: white;
|
||||
border-radius: 4px;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.file-size {
|
||||
margin-left: auto;
|
||||
font-size: 0.8rem;
|
||||
color: #9ca3af;
|
||||
}
|
||||
|
||||
.warning-banner {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 0.75rem;
|
||||
padding: 0.75rem 1rem;
|
||||
background: rgba(234, 179, 8, 0.1);
|
||||
border: 1px solid rgba(234, 179, 8, 0.3);
|
||||
border-radius: 6px;
|
||||
color: #fbbf24;
|
||||
|
||||
i {
|
||||
font-size: 1rem;
|
||||
margin-top: 0.125rem;
|
||||
}
|
||||
|
||||
span {
|
||||
font-size: 0.85rem;
|
||||
line-height: 1.4;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
import {Component, inject, OnInit} from '@angular/core';
|
||||
import {Button} from 'primeng/button';
|
||||
import {Select} from 'primeng/select';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {EmailProvider} from '../../../settings/email-v2/email-provider.model';
|
||||
import {EmailRecipient} from '../../../settings/email-v2/email-recipient.model';
|
||||
import {EmailService} from '../../../settings/email-v2/email.service';
|
||||
import {DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {EmailV2ProviderService} from '../../../settings/email-v2/email-v2-provider/email-v2-provider.service';
|
||||
import {EmailV2RecipientService} from '../../../settings/email-v2/email-v2-recipient/email-v2-recipient.service';
|
||||
import {Book, BookFile} from '../../model/book.model';
|
||||
import {RadioButton} from 'primeng/radiobutton';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
interface EmailableFile {
|
||||
id: number;
|
||||
bookType?: string;
|
||||
fileSizeKb?: number;
|
||||
isPrimary: boolean;
|
||||
}
|
||||
|
||||
const LARGE_FILE_THRESHOLD_KB = 25 * 1024; // 25MB
|
||||
|
||||
@Component({
|
||||
selector: 'app-book-sender',
|
||||
imports: [
|
||||
Button,
|
||||
Select,
|
||||
FormsModule,
|
||||
RadioButton,
|
||||
TranslocoDirective,
|
||||
],
|
||||
templateUrl: './book-sender.component.html',
|
||||
styleUrls: ['./book-sender.component.scss']
|
||||
})
|
||||
export class BookSenderComponent implements OnInit {
|
||||
|
||||
private emailProviderService = inject(EmailV2ProviderService);
|
||||
private emailRecipientService = inject(EmailV2RecipientService);
|
||||
private emailService = inject(EmailService);
|
||||
private messageService = inject(MessageService);
|
||||
private readonly t = inject(TranslocoService);
|
||||
dynamicDialogRef = inject(DynamicDialogRef);
|
||||
private dynamicDialogConfig = inject(DynamicDialogConfig);
|
||||
|
||||
book: Book = this.dynamicDialogConfig.data.book;
|
||||
|
||||
emailProviders: { label: string, value: EmailProvider }[] = [];
|
||||
emailRecipients: { label: string, value: EmailRecipient }[] = [];
|
||||
selectedProvider?: { label: string; value: EmailProvider };
|
||||
selectedRecipient?: { label: string; value: EmailRecipient };
|
||||
|
||||
emailableFiles: EmailableFile[] = [];
|
||||
selectedFileId?: number;
|
||||
|
||||
ngOnInit(): void {
|
||||
this.buildEmailableFiles();
|
||||
|
||||
this.emailProviderService.getEmailProviders().subscribe({
|
||||
next: (emailProviders: EmailProvider[]) => {
|
||||
this.emailProviders = emailProviders.map(provider => ({
|
||||
label: `${provider.name} | ${provider.fromAddress || provider.host}`,
|
||||
value: provider
|
||||
}));
|
||||
}
|
||||
});
|
||||
|
||||
this.emailRecipientService.getRecipients().subscribe({
|
||||
next: (emailRecipients: EmailRecipient[]) => {
|
||||
this.emailRecipients = emailRecipients.map(recipient => ({
|
||||
label: `${recipient.name} | ${recipient.email}`,
|
||||
value: recipient
|
||||
}));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private buildEmailableFiles(): void {
|
||||
this.emailableFiles = [];
|
||||
|
||||
// Add primary file
|
||||
if (this.book.primaryFile) {
|
||||
this.emailableFiles.push({
|
||||
id: this.book.primaryFile.id,
|
||||
bookType: this.book.primaryFile.bookType,
|
||||
fileSizeKb: this.book.primaryFile.fileSizeKb,
|
||||
isPrimary: true
|
||||
});
|
||||
this.selectedFileId = this.book.primaryFile.id;
|
||||
}
|
||||
|
||||
// Add alternative formats (only book formats, not supplementary files)
|
||||
if (this.book.alternativeFormats) {
|
||||
for (const format of this.book.alternativeFormats) {
|
||||
this.emailableFiles.push({
|
||||
id: format.id,
|
||||
bookType: format.bookType,
|
||||
fileSizeKb: format.fileSizeKb,
|
||||
isPrimary: false
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
get showLargeFileWarning(): boolean {
|
||||
if (!this.selectedFileId) return false;
|
||||
const selectedFile = this.emailableFiles.find(f => f.id === this.selectedFileId);
|
||||
return !!selectedFile?.fileSizeKb && selectedFile.fileSizeKb > LARGE_FILE_THRESHOLD_KB;
|
||||
}
|
||||
|
||||
formatFileSize(fileSizeKb?: number): string {
|
||||
if (fileSizeKb == null) return '-';
|
||||
|
||||
const units = ['KB', 'MB', 'GB', 'TB'];
|
||||
let size = fileSizeKb;
|
||||
let unitIndex = 0;
|
||||
|
||||
while (size >= 1024 && unitIndex < units.length - 1) {
|
||||
size /= 1024;
|
||||
unitIndex++;
|
||||
}
|
||||
|
||||
const decimals = size >= 100 ? 0 : size >= 10 ? 1 : 2;
|
||||
return `${size.toFixed(decimals)} ${units[unitIndex]}`;
|
||||
}
|
||||
|
||||
sendBook() {
|
||||
if (this.selectedProvider && this.selectedRecipient && this.book?.id) {
|
||||
const bookId = this.book.id;
|
||||
const recipientId = this.selectedRecipient.value.id;
|
||||
const providerId = this.selectedProvider.value.id;
|
||||
|
||||
const emailRequest: { bookId: number, providerId: number, recipientId: number, bookFileId?: number } = {
|
||||
bookId,
|
||||
providerId,
|
||||
recipientId: recipientId,
|
||||
};
|
||||
|
||||
// Include bookFileId if a specific file is selected and it's not the primary
|
||||
if (this.selectedFileId) {
|
||||
emailRequest.bookFileId = this.selectedFileId;
|
||||
}
|
||||
|
||||
this.emailService.emailBook(emailRequest).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('book.sender.toast.emailScheduledSummary'),
|
||||
detail: this.t.translate('book.sender.toast.emailScheduledDetail')
|
||||
});
|
||||
this.dynamicDialogRef.close(true);
|
||||
},
|
||||
error: (error) => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('book.sender.toast.sendingFailedSummary'),
|
||||
detail: this.t.translate('book.sender.toast.sendingFailedDetail')
|
||||
});
|
||||
console.error('Error sending book:', error);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (!this.selectedProvider) {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('book.sender.toast.providerMissingSummary'),
|
||||
detail: this.t.translate('book.sender.toast.providerMissingDetail')
|
||||
});
|
||||
}
|
||||
if (!this.selectedRecipient) {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('book.sender.toast.recipientMissingSummary'),
|
||||
detail: this.t.translate('book.sender.toast.recipientMissingDetail')
|
||||
});
|
||||
}
|
||||
if (!this.book?.id) {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('book.sender.toast.bookNotSelectedSummary'),
|
||||
detail: this.t.translate('book.sender.toast.bookNotSelectedDetail')
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+346
@@ -0,0 +1,346 @@
|
||||
<ng-container *transloco="let t; prefix: 'book.bulkIsbnImport'">
|
||||
<div class="bulk-isbn-import">
|
||||
<div class="panel-header">
|
||||
<div class="header-icon-wrapper">
|
||||
<i class="pi pi-barcode header-icon"></i>
|
||||
</div>
|
||||
<div class="header-text">
|
||||
<h2 class="panel-title">{{ t('title') }}</h2>
|
||||
<p class="panel-description">{{ t('description') }}</p>
|
||||
</div>
|
||||
<p-button
|
||||
icon="pi pi-times"
|
||||
(click)="close()"
|
||||
severity="secondary"
|
||||
[text]="true"
|
||||
[rounded]="true"
|
||||
class="close-button"
|
||||
[pTooltip]="t('closeTooltip')"
|
||||
tooltipPosition="left"/>
|
||||
</div>
|
||||
|
||||
<!-- Phase 1: Upload & Parse -->
|
||||
@if (phase === 'upload') {
|
||||
<div class="form-container">
|
||||
<div class="form-group highlight-group">
|
||||
<label for="library" class="form-label">
|
||||
<i class="pi pi-folder label-icon"></i>
|
||||
{{ t('libraryLabel') }}
|
||||
<span class="required-indicator">*</span>
|
||||
</label>
|
||||
<p-select
|
||||
id="library"
|
||||
[options]="libraries"
|
||||
[(ngModel)]="selectedLibraryId"
|
||||
optionLabel="name"
|
||||
optionValue="id"
|
||||
[placeholder]="t('libraryPlaceholder')"
|
||||
[style]="{'width': '100%'}"/>
|
||||
</div>
|
||||
|
||||
<div class="gradient-divider"></div>
|
||||
|
||||
@if (entries.length === 0 && skipped.length === 0 && duplicatesRemoved === 0) {
|
||||
<p-tabs value="file">
|
||||
<p-tablist>
|
||||
<p-tab value="file">{{ t('tabFile') }}</p-tab>
|
||||
<p-tab value="paste">{{ t('tabPaste') }}</p-tab>
|
||||
</p-tablist>
|
||||
<p-tabpanels>
|
||||
<p-tabpanel value="file">
|
||||
<div class="upload-section">
|
||||
<p-fileupload
|
||||
mode="basic"
|
||||
[auto]="true"
|
||||
[customUpload]="true"
|
||||
accept=".txt,.csv,.tsv"
|
||||
[maxFileSize]="1048576"
|
||||
(onSelect)="onFileSelect($event)"
|
||||
[chooseLabel]="t('chooseFile')"
|
||||
chooseIcon="pi pi-upload"/>
|
||||
<p class="upload-hint">{{ t('fileFormatsHint') }}</p>
|
||||
</div>
|
||||
</p-tabpanel>
|
||||
<p-tabpanel value="paste">
|
||||
<div class="paste-section">
|
||||
<textarea
|
||||
pTextarea
|
||||
[(ngModel)]="pasteText"
|
||||
rows="6"
|
||||
[placeholder]="t('pastePlaceholder')"
|
||||
class="input-full"></textarea>
|
||||
<p-button
|
||||
[label]="t('parseButton')"
|
||||
icon="pi pi-check"
|
||||
severity="info"
|
||||
[outlined]="true"
|
||||
(onClick)="parsePastedText()"
|
||||
[disabled]="!pasteText.trim()"/>
|
||||
</div>
|
||||
</p-tabpanel>
|
||||
</p-tabpanels>
|
||||
</p-tabs>
|
||||
|
||||
@if (parseError === 'fileTooLarge') {
|
||||
<div class="parse-error">
|
||||
<i class="pi pi-exclamation-triangle"></i>
|
||||
{{ t('errorFileTooLarge') }}
|
||||
</div>
|
||||
}
|
||||
@if (parseError === 'empty') {
|
||||
<div class="parse-error">
|
||||
<i class="pi pi-exclamation-triangle"></i>
|
||||
{{ t('errorNoIsbns') }}
|
||||
</div>
|
||||
}
|
||||
} @else {
|
||||
<div class="parse-results">
|
||||
<div class="parse-summary">
|
||||
<div class="summary-stat success">
|
||||
<i class="pi pi-check-circle"></i>
|
||||
{{ t('validCount', { count: entries.length }) }}
|
||||
</div>
|
||||
@if (skipped.length > 0) {
|
||||
<div class="summary-stat warn" (click)="showSkipped = !showSkipped">
|
||||
<i class="pi pi-exclamation-triangle"></i>
|
||||
{{ t('skippedCount', { count: skipped.length }) }}
|
||||
<i class="pi" [class.pi-chevron-down]="!showSkipped" [class.pi-chevron-up]="showSkipped"></i>
|
||||
</div>
|
||||
}
|
||||
@if (duplicatesRemoved > 0) {
|
||||
<div class="summary-stat info">
|
||||
<i class="pi pi-copy"></i>
|
||||
{{ t('duplicatesRemoved', { count: duplicatesRemoved }) }}
|
||||
</div>
|
||||
}
|
||||
@if (parseError === 'tooMany') {
|
||||
<div class="summary-stat warn">
|
||||
<i class="pi pi-exclamation-triangle"></i>
|
||||
{{ t('errorTooMany', { max: maxIsbnCount }) }}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@if (showSkipped && skipped.length > 0) {
|
||||
<div class="skipped-list">
|
||||
@for (item of skipped; track item.value) {
|
||||
<div class="skipped-item">
|
||||
<code>{{ item.value }}</code>
|
||||
<span class="skipped-reason">{{ t('reason.' + item.reason) }}</span>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="isbn-preview">
|
||||
<div class="preview-header">
|
||||
<span class="preview-label">{{ t('previewLabel') }}</span>
|
||||
<p-button
|
||||
[label]="t('clearButton')"
|
||||
icon="pi pi-times"
|
||||
severity="secondary"
|
||||
[text]="true"
|
||||
size="small"
|
||||
(onClick)="clearParsed()"/>
|
||||
</div>
|
||||
<div class="preview-list">
|
||||
@for (entry of entries; track entry.isbn; let i = $index) {
|
||||
<div class="preview-item">
|
||||
<span class="preview-index">{{ i + 1 }}.</span>
|
||||
<code class="preview-isbn">{{ entry.isbn }}</code>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="dialog-footer">
|
||||
<div class="validation-status">
|
||||
@if (!selectedLibraryId) {
|
||||
<div class="validation-message error">
|
||||
<i class="pi pi-exclamation-circle"></i>
|
||||
<span>{{ t('validationLibraryRequired') }}</span>
|
||||
</div>
|
||||
} @else if (entries.length === 0) {
|
||||
<div class="validation-message error">
|
||||
<i class="pi pi-exclamation-circle"></i>
|
||||
<span>{{ t('validationNoIsbns') }}</span>
|
||||
</div>
|
||||
} @else {
|
||||
<div class="validation-message success">
|
||||
<i class="pi pi-check-circle"></i>
|
||||
<span>{{ t('validationReady', { count: entries.length }) }}</span>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
<div class="footer-actions">
|
||||
<p-button
|
||||
[label]="t('cancelButton')"
|
||||
severity="secondary"
|
||||
[outlined]="true"
|
||||
(onClick)="close()"/>
|
||||
<p-button
|
||||
[label]="t('startImportButton')"
|
||||
icon="pi pi-play"
|
||||
severity="success"
|
||||
(onClick)="startImport()"
|
||||
[disabled]="!canStartImport()"/>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
<!-- Phase 2: Processing -->
|
||||
@if (phase === 'processing') {
|
||||
<div class="form-container processing-container">
|
||||
<div class="progress-section">
|
||||
<div class="progress-header">
|
||||
<span class="progress-label">{{ t('processingLabel', { current: processedCount, total: entries.length }) }}</span>
|
||||
<span class="progress-percent">{{ progressPercent }}%</span>
|
||||
</div>
|
||||
<p-progressbar [value]="progressPercent" [showValue]="false"/>
|
||||
<div class="progress-stats">
|
||||
<span class="stat-created"><i class="pi pi-check-circle"></i> {{ createdCount }}</span>
|
||||
<span class="stat-no-metadata"><i class="pi pi-exclamation-triangle"></i> {{ noMetadataCount }}</span>
|
||||
<span class="stat-failed"><i class="pi pi-times-circle"></i> {{ failedCount }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="isbn-progress-list">
|
||||
@for (entry of entries; track entry.isbn) {
|
||||
<div class="progress-item" [class]="'status-' + entry.status">
|
||||
<div class="progress-item-icon">
|
||||
@switch (entry.status) {
|
||||
@case ('pending') { <i class="pi pi-clock"></i> }
|
||||
@case ('looking-up') { <i class="pi pi-spin pi-spinner"></i> }
|
||||
@case ('created') { <i class="pi pi-check-circle"></i> }
|
||||
@case ('created-no-metadata') { <i class="pi pi-exclamation-triangle"></i> }
|
||||
@case ('failed') { <i class="pi pi-times-circle"></i> }
|
||||
}
|
||||
</div>
|
||||
<code class="progress-item-isbn">{{ entry.isbn }}</code>
|
||||
<span class="progress-item-detail">
|
||||
@if (entry.status === 'created' && entry.title) {
|
||||
{{ entry.title }}
|
||||
} @else if (entry.status === 'created-no-metadata') {
|
||||
{{ t('createdNoMetadata') }}
|
||||
} @else if (entry.status === 'failed') {
|
||||
{{ entry.error || t('unknownError') }}
|
||||
} @else if (entry.status === 'looking-up') {
|
||||
{{ t('lookingUp') }}
|
||||
}
|
||||
</span>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="dialog-footer">
|
||||
<div class="validation-status">
|
||||
<div class="validation-message info">
|
||||
<i class="pi pi-info-circle"></i>
|
||||
<span>{{ t('processingHint') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="footer-actions">
|
||||
<p-button
|
||||
[label]="t('cancelImportButton')"
|
||||
icon="pi pi-stop"
|
||||
severity="danger"
|
||||
[outlined]="true"
|
||||
(onClick)="cancelImport()"/>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
<!-- Phase 3: Summary -->
|
||||
@if (phase === 'summary') {
|
||||
<div class="form-container">
|
||||
<div class="summary-header-bar">
|
||||
<span class="summary-title">{{ t('summaryTitle') }}</span>
|
||||
@if (selectedLibraryName) {
|
||||
<span class="summary-library">
|
||||
<i class="pi pi-folder"></i>
|
||||
{{ selectedLibraryName }}
|
||||
</span>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="summary-results">
|
||||
<div class="summary-card success">
|
||||
<i class="pi pi-check-circle"></i>
|
||||
<div class="summary-card-content">
|
||||
<span class="summary-card-count">{{ createdCount }}</span>
|
||||
<span class="summary-card-label">{{ t('summaryCreated') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
@if (noMetadataCount > 0) {
|
||||
<div class="summary-card warn">
|
||||
<i class="pi pi-exclamation-triangle"></i>
|
||||
<div class="summary-card-content">
|
||||
<span class="summary-card-count">{{ noMetadataCount }}</span>
|
||||
<span class="summary-card-label">{{ t('summaryNoMetadata') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
@if (failedCount > 0) {
|
||||
<div class="summary-card error">
|
||||
<i class="pi pi-times-circle"></i>
|
||||
<div class="summary-card-content">
|
||||
<span class="summary-card-count">{{ failedCount }}</span>
|
||||
<span class="summary-card-label">{{ t('summaryFailed') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
@if (cancelled) {
|
||||
<div class="summary-card info">
|
||||
<i class="pi pi-info-circle"></i>
|
||||
<div class="summary-card-content">
|
||||
<span class="summary-card-count">{{ entries.length - processedCount }}</span>
|
||||
<span class="summary-card-label">{{ t('summaryCancelled') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="summary-detail-list">
|
||||
@for (entry of entries; track entry.isbn) {
|
||||
@if (entry.status !== 'pending') {
|
||||
<div class="summary-detail-item" [class]="'status-' + entry.status">
|
||||
<div class="summary-detail-icon">
|
||||
@switch (entry.status) {
|
||||
@case ('created') { <i class="pi pi-check-circle"></i> }
|
||||
@case ('created-no-metadata') { <i class="pi pi-exclamation-triangle"></i> }
|
||||
@case ('failed') { <i class="pi pi-times-circle"></i> }
|
||||
}
|
||||
</div>
|
||||
<code class="summary-detail-isbn">{{ entry.isbn }}</code>
|
||||
<span class="summary-detail-info">
|
||||
@if (entry.status === 'created' && entry.title) {
|
||||
{{ entry.title }}
|
||||
} @else if (entry.status === 'created-no-metadata') {
|
||||
{{ t('createdNoMetadata') }}
|
||||
} @else if (entry.status === 'failed') {
|
||||
{{ entry.error || t('unknownError') }}
|
||||
}
|
||||
</span>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="dialog-footer">
|
||||
<div class="validation-status"></div>
|
||||
<div class="footer-actions">
|
||||
<p-button
|
||||
[label]="t('doneButton')"
|
||||
icon="pi pi-check"
|
||||
severity="success"
|
||||
(onClick)="close()"/>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</ng-container>
|
||||
+514
@@ -0,0 +1,514 @@
|
||||
@use '../../../../shared/styles/panel-shared' as panel;
|
||||
|
||||
.bulk-isbn-import {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-width: 600px;
|
||||
max-height: 90vh;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
min-width: auto;
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.panel-header {
|
||||
@include panel.panel-header;
|
||||
}
|
||||
|
||||
.form-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
padding: 1.25rem;
|
||||
background: var(--card-background);
|
||||
border: 1px solid var(--border-color);
|
||||
border-top: none;
|
||||
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
|
||||
overflow-y: auto;
|
||||
max-height: calc(90vh - 200px);
|
||||
|
||||
@media (max-width: 480px) {
|
||||
padding: 0.75rem;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
.form-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.25rem;
|
||||
|
||||
&.highlight-group {
|
||||
padding: 0.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
.form-label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.375rem;
|
||||
font-size: 0.9rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-color);
|
||||
|
||||
.label-icon {
|
||||
color: var(--primary-color);
|
||||
}
|
||||
|
||||
.required-indicator {
|
||||
color: var(--p-red-500);
|
||||
margin-left: 0.125rem;
|
||||
}
|
||||
}
|
||||
|
||||
.input-full {
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.gradient-divider {
|
||||
height: 1px;
|
||||
background: linear-gradient(to right, transparent, var(--border-color), transparent);
|
||||
margin: 0.25rem 0;
|
||||
}
|
||||
|
||||
// Upload section
|
||||
.upload-section {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
padding: 1.5rem;
|
||||
|
||||
.upload-hint {
|
||||
font-size: 0.8rem;
|
||||
color: var(--text-secondary-color);
|
||||
margin: 0;
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
|
||||
.paste-section {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
padding: 0.75rem 0;
|
||||
|
||||
p-button {
|
||||
align-self: flex-end;
|
||||
}
|
||||
}
|
||||
|
||||
.parse-error {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
padding: 0.75rem 1rem;
|
||||
background: rgba(239, 68, 68, 0.1);
|
||||
border: 1px solid rgba(239, 68, 68, 0.3);
|
||||
border-radius: 6px;
|
||||
color: var(--p-red-500);
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
// Parse results
|
||||
.parse-results {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.parse-summary {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.summary-stat {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.375rem;
|
||||
padding: 0.375rem 0.75rem;
|
||||
border-radius: 6px;
|
||||
font-size: 0.85rem;
|
||||
font-weight: 500;
|
||||
|
||||
&.success {
|
||||
background: rgba(34, 197, 94, 0.1);
|
||||
color: var(--p-green-500);
|
||||
border: 1px solid rgba(34, 197, 94, 0.3);
|
||||
}
|
||||
|
||||
&.warn {
|
||||
background: rgba(234, 179, 8, 0.1);
|
||||
color: var(--p-yellow-500);
|
||||
border: 1px solid rgba(234, 179, 8, 0.3);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
&.info {
|
||||
background: rgba(59, 130, 246, 0.1);
|
||||
color: var(--p-blue-500);
|
||||
border: 1px solid rgba(59, 130, 246, 0.3);
|
||||
}
|
||||
}
|
||||
|
||||
.skipped-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.25rem;
|
||||
padding: 0.5rem;
|
||||
background: rgba(234, 179, 8, 0.05);
|
||||
border: 1px solid rgba(234, 179, 8, 0.2);
|
||||
border-radius: 6px;
|
||||
max-height: 150px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.skipped-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
font-size: 0.8rem;
|
||||
|
||||
code {
|
||||
color: var(--text-color);
|
||||
background: var(--ground-background);
|
||||
padding: 0.125rem 0.375rem;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.skipped-reason {
|
||||
color: var(--text-secondary-color);
|
||||
font-style: italic;
|
||||
}
|
||||
}
|
||||
|
||||
.isbn-preview {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.preview-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
|
||||
.preview-label {
|
||||
font-size: 0.875rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-color);
|
||||
}
|
||||
}
|
||||
|
||||
.preview-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.25rem;
|
||||
max-height: 200px;
|
||||
overflow-y: auto;
|
||||
padding: 0.5rem;
|
||||
background: var(--ground-background);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.preview-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
padding: 0.25rem 0.375rem;
|
||||
font-size: 0.85rem;
|
||||
|
||||
.preview-index {
|
||||
color: var(--text-secondary-color);
|
||||
min-width: 2rem;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.preview-isbn {
|
||||
color: var(--text-color);
|
||||
}
|
||||
}
|
||||
|
||||
// Processing phase
|
||||
.processing-container {
|
||||
max-height: calc(90vh - 180px);
|
||||
}
|
||||
|
||||
.progress-section {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
padding: 0.5rem 0;
|
||||
}
|
||||
|
||||
.progress-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
|
||||
.progress-label {
|
||||
font-size: 0.9rem;
|
||||
font-weight: 500;
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
.progress-percent {
|
||||
font-size: 0.9rem;
|
||||
font-weight: 600;
|
||||
color: var(--primary-color);
|
||||
}
|
||||
}
|
||||
|
||||
.progress-stats {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
font-size: 0.85rem;
|
||||
|
||||
.stat-created {
|
||||
color: var(--p-green-500);
|
||||
}
|
||||
|
||||
.stat-no-metadata {
|
||||
color: var(--p-yellow-500);
|
||||
}
|
||||
|
||||
.stat-failed {
|
||||
color: var(--p-red-500);
|
||||
}
|
||||
|
||||
i {
|
||||
margin-right: 0.25rem;
|
||||
}
|
||||
}
|
||||
|
||||
.isbn-progress-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.25rem;
|
||||
}
|
||||
|
||||
.progress-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
padding: 0.375rem 0.5rem;
|
||||
border-radius: 4px;
|
||||
font-size: 0.85rem;
|
||||
transition: background-color 0.2s;
|
||||
|
||||
&.status-pending {
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
&.status-looking-up {
|
||||
background: rgba(59, 130, 246, 0.05);
|
||||
}
|
||||
|
||||
&.status-created {
|
||||
background: rgba(34, 197, 94, 0.05);
|
||||
}
|
||||
|
||||
&.status-created-no-metadata {
|
||||
background: rgba(234, 179, 8, 0.05);
|
||||
}
|
||||
|
||||
&.status-failed {
|
||||
background: rgba(239, 68, 68, 0.05);
|
||||
}
|
||||
}
|
||||
|
||||
.progress-item-icon {
|
||||
width: 1.25rem;
|
||||
text-align: center;
|
||||
flex-shrink: 0;
|
||||
|
||||
.status-pending & { color: var(--text-secondary-color); }
|
||||
.status-looking-up & { color: var(--p-blue-500); }
|
||||
.status-created & { color: var(--p-green-500); }
|
||||
.status-created-no-metadata & { color: var(--p-yellow-500); }
|
||||
.status-failed & { color: var(--p-red-500); }
|
||||
}
|
||||
|
||||
.progress-item-isbn {
|
||||
min-width: 8rem;
|
||||
flex-shrink: 0;
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
.progress-item-detail {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
color: var(--text-secondary-color);
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
|
||||
// Summary phase
|
||||
.summary-header-bar {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 0.25rem 0;
|
||||
|
||||
.summary-title {
|
||||
font-size: 1rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
.summary-library {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.375rem;
|
||||
font-size: 0.85rem;
|
||||
color: var(--text-secondary-color);
|
||||
|
||||
i {
|
||||
color: var(--primary-color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.summary-results {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.75rem;
|
||||
padding: 0.25rem 0;
|
||||
}
|
||||
|
||||
.summary-card {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
padding: 0.75rem 1rem;
|
||||
border-radius: 8px;
|
||||
flex: 1;
|
||||
min-width: 120px;
|
||||
|
||||
> i {
|
||||
font-size: 1.25rem;
|
||||
}
|
||||
|
||||
&.success {
|
||||
background: rgba(34, 197, 94, 0.1);
|
||||
border: 1px solid rgba(34, 197, 94, 0.3);
|
||||
> i { color: var(--p-green-500); }
|
||||
}
|
||||
|
||||
&.warn {
|
||||
background: rgba(234, 179, 8, 0.1);
|
||||
border: 1px solid rgba(234, 179, 8, 0.3);
|
||||
> i { color: var(--p-yellow-500); }
|
||||
}
|
||||
|
||||
&.error {
|
||||
background: rgba(239, 68, 68, 0.1);
|
||||
border: 1px solid rgba(239, 68, 68, 0.3);
|
||||
> i { color: var(--p-red-500); }
|
||||
}
|
||||
|
||||
&.info {
|
||||
background: rgba(59, 130, 246, 0.1);
|
||||
border: 1px solid rgba(59, 130, 246, 0.3);
|
||||
> i { color: var(--p-blue-500); }
|
||||
}
|
||||
}
|
||||
|
||||
.summary-card-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
.summary-card-count {
|
||||
font-size: 1.25rem;
|
||||
font-weight: 700;
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
.summary-card-label {
|
||||
font-size: 0.75rem;
|
||||
color: var(--text-secondary-color);
|
||||
}
|
||||
}
|
||||
|
||||
.summary-detail-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.125rem;
|
||||
margin-top: 0.25rem;
|
||||
}
|
||||
|
||||
.summary-detail-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
padding: 0.375rem 0.5rem;
|
||||
border-radius: 4px;
|
||||
font-size: 0.85rem;
|
||||
|
||||
&.status-created {
|
||||
background: rgba(34, 197, 94, 0.04);
|
||||
}
|
||||
|
||||
&.status-created-no-metadata {
|
||||
background: rgba(234, 179, 8, 0.04);
|
||||
}
|
||||
|
||||
&.status-failed {
|
||||
background: rgba(239, 68, 68, 0.04);
|
||||
}
|
||||
}
|
||||
|
||||
.summary-detail-icon {
|
||||
width: 1.25rem;
|
||||
text-align: center;
|
||||
flex-shrink: 0;
|
||||
|
||||
.status-created & { color: var(--p-green-500); }
|
||||
.status-created-no-metadata & { color: var(--p-yellow-500); }
|
||||
.status-failed & { color: var(--p-red-500); }
|
||||
}
|
||||
|
||||
.summary-detail-isbn {
|
||||
min-width: 8rem;
|
||||
flex-shrink: 0;
|
||||
color: var(--text-color);
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
|
||||
.summary-detail-info {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
font-size: 0.8rem;
|
||||
|
||||
.status-created & { color: var(--text-color); }
|
||||
.status-created-no-metadata & { color: var(--p-yellow-500); font-style: italic; }
|
||||
.status-failed & { color: var(--p-red-500); font-style: italic; }
|
||||
}
|
||||
|
||||
.validation-message {
|
||||
@include panel.validation-message;
|
||||
|
||||
&.info {
|
||||
background: rgba(59, 130, 246, 0.1);
|
||||
color: var(--p-blue-500);
|
||||
border: 1px solid rgba(59, 130, 246, 0.3);
|
||||
|
||||
i {
|
||||
color: var(--p-blue-500);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.dialog-footer {
|
||||
@include panel.dialog-footer;
|
||||
border-top: none;
|
||||
}
|
||||
+369
@@ -0,0 +1,369 @@
|
||||
import {Component, effect, inject} from '@angular/core';
|
||||
import {DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {Button} from 'primeng/button';
|
||||
import {Select} from 'primeng/select';
|
||||
import {Textarea} from 'primeng/textarea';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {ProgressBar} from 'primeng/progressbar';
|
||||
import {FileUpload, FileSelectEvent} from 'primeng/fileupload';
|
||||
import {BookService} from '../../service/book.service';
|
||||
import {BookMetadataService} from '../../service/book-metadata.service';
|
||||
import {LibraryService} from '../../service/library.service';
|
||||
import {Library} from '../../model/library.model';
|
||||
import {BookMetadata, CreatePhysicalBookRequest} from '../../model/book.model';
|
||||
import {TranslocoDirective} from '@jsverse/transloco';
|
||||
import {Tabs, TabList, Tab, TabPanels, TabPanel} from 'primeng/tabs';
|
||||
|
||||
const MAX_ISBN_COUNT = 500;
|
||||
const MAX_FILE_SIZE_BYTES = 1_048_576; // 1 MB
|
||||
const DELAY_BETWEEN_REQUESTS_MS = 300;
|
||||
const RETRY_DELAY_MS = 2000;
|
||||
|
||||
export type IsbnEntryStatus = 'pending' | 'looking-up' | 'created' | 'created-no-metadata' | 'failed';
|
||||
|
||||
export interface IsbnEntry {
|
||||
isbn: string;
|
||||
status: IsbnEntryStatus;
|
||||
title?: string;
|
||||
error?: string;
|
||||
}
|
||||
|
||||
export interface SkippedEntry {
|
||||
value: string;
|
||||
reason: string;
|
||||
}
|
||||
|
||||
type ImportPhase = 'upload' | 'processing' | 'summary';
|
||||
|
||||
@Component({
|
||||
selector: 'app-bulk-isbn-import-dialog',
|
||||
standalone: true,
|
||||
templateUrl: './bulk-isbn-import-dialog.component.html',
|
||||
imports: [
|
||||
FormsModule,
|
||||
Button,
|
||||
Select,
|
||||
Textarea,
|
||||
Tooltip,
|
||||
ProgressBar,
|
||||
FileUpload,
|
||||
TranslocoDirective,
|
||||
Tabs,
|
||||
TabList,
|
||||
Tab,
|
||||
TabPanels,
|
||||
TabPanel,
|
||||
],
|
||||
styleUrl: './bulk-isbn-import-dialog.component.scss',
|
||||
})
|
||||
export class BulkIsbnImportDialogComponent {
|
||||
private dynamicDialogRef = inject(DynamicDialogRef);
|
||||
private dialogConfig = inject(DynamicDialogConfig);
|
||||
private bookService = inject(BookService);
|
||||
private bookMetadataService = inject(BookMetadataService);
|
||||
private libraryService = inject(LibraryService);
|
||||
|
||||
selectedLibraryId: number | null = null;
|
||||
|
||||
phase: ImportPhase = 'upload';
|
||||
pasteText = '';
|
||||
entries: IsbnEntry[] = [];
|
||||
skipped: SkippedEntry[] = [];
|
||||
duplicatesRemoved = 0;
|
||||
showSkipped = false;
|
||||
|
||||
processedCount = 0;
|
||||
createdCount = 0;
|
||||
noMetadataCount = 0;
|
||||
failedCount = 0;
|
||||
cancelled = false;
|
||||
|
||||
parseError = '';
|
||||
readonly maxIsbnCount = MAX_ISBN_COUNT;
|
||||
private readonly initializeSelectedLibraryEffect = effect(() => {
|
||||
const libraries = this.libraries;
|
||||
if (libraries.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.dialogConfig.data?.libraryId) {
|
||||
this.selectedLibraryId = this.dialogConfig.data.libraryId;
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.selectedLibraryId == null && libraries[0].id !== undefined) {
|
||||
this.selectedLibraryId = libraries[0].id;
|
||||
}
|
||||
});
|
||||
|
||||
get libraries(): Library[] {
|
||||
return this.libraryService.libraries();
|
||||
}
|
||||
|
||||
onFileSelect(event: FileSelectEvent): void {
|
||||
const file = event.files?.[0];
|
||||
if (!file) return;
|
||||
|
||||
if (file.size > MAX_FILE_SIZE_BYTES) {
|
||||
this.parseError = 'fileTooLarge';
|
||||
return;
|
||||
}
|
||||
|
||||
const reader = new FileReader();
|
||||
reader.onload = () => {
|
||||
const content = reader.result as string;
|
||||
this.parseContent(content, file.name);
|
||||
};
|
||||
reader.readAsText(file, 'UTF-8');
|
||||
}
|
||||
|
||||
parsePastedText(): void {
|
||||
if (!this.pasteText.trim()) return;
|
||||
this.parseContent(this.pasteText, 'paste');
|
||||
}
|
||||
|
||||
clearParsed(): void {
|
||||
this.entries = [];
|
||||
this.skipped = [];
|
||||
this.duplicatesRemoved = 0;
|
||||
this.parseError = '';
|
||||
this.pasteText = '';
|
||||
}
|
||||
|
||||
canStartImport(): boolean {
|
||||
return this.phase === 'upload' && this.entries.length > 0 && !!this.selectedLibraryId;
|
||||
}
|
||||
|
||||
async startImport(): Promise<void> {
|
||||
if (!this.canStartImport()) return;
|
||||
|
||||
this.phase = 'processing';
|
||||
this.processedCount = 0;
|
||||
this.createdCount = 0;
|
||||
this.noMetadataCount = 0;
|
||||
this.failedCount = 0;
|
||||
this.cancelled = false;
|
||||
|
||||
for (const entry of this.entries) {
|
||||
if (this.cancelled) break;
|
||||
|
||||
entry.status = 'looking-up';
|
||||
|
||||
try {
|
||||
const metadata = await this.lookupIsbn(entry.isbn);
|
||||
if (this.cancelled) break;
|
||||
|
||||
const request: CreatePhysicalBookRequest = {
|
||||
libraryId: this.selectedLibraryId!,
|
||||
isbn: entry.isbn,
|
||||
title: metadata?.title || undefined,
|
||||
authors: metadata?.authors?.length ? [...metadata.authors] : undefined,
|
||||
description: metadata?.description || undefined,
|
||||
publisher: metadata?.publisher || undefined,
|
||||
publishedDate: metadata?.publishedDate || undefined,
|
||||
language: metadata?.language || undefined,
|
||||
pageCount: metadata?.pageCount ?? undefined,
|
||||
categories: metadata?.categories?.length ? [...metadata.categories] : undefined,
|
||||
thumbnailUrl: metadata?.thumbnailUrl || undefined,
|
||||
};
|
||||
|
||||
await this.createBook(request);
|
||||
|
||||
if (metadata?.title) {
|
||||
entry.status = 'created';
|
||||
entry.title = metadata.title;
|
||||
this.createdCount++;
|
||||
} else {
|
||||
entry.status = 'created-no-metadata';
|
||||
this.noMetadataCount++;
|
||||
}
|
||||
} catch (err: unknown) {
|
||||
entry.status = 'failed';
|
||||
entry.error = err instanceof Error ? err.message : 'Unknown error';
|
||||
this.failedCount++;
|
||||
}
|
||||
|
||||
this.processedCount++;
|
||||
|
||||
if (!this.cancelled && entry !== this.entries[this.entries.length - 1]) {
|
||||
await this.delay(DELAY_BETWEEN_REQUESTS_MS);
|
||||
}
|
||||
}
|
||||
|
||||
this.phase = 'summary';
|
||||
}
|
||||
|
||||
cancelImport(): void {
|
||||
this.cancelled = true;
|
||||
}
|
||||
|
||||
close(): void {
|
||||
this.dynamicDialogRef.close();
|
||||
}
|
||||
|
||||
get progressPercent(): number {
|
||||
return this.entries.length > 0 ? Math.round((this.processedCount / this.entries.length) * 100) : 0;
|
||||
}
|
||||
|
||||
get selectedLibraryName(): string {
|
||||
return this.libraries.find(l => l.id === this.selectedLibraryId)?.name ?? '';
|
||||
}
|
||||
|
||||
private parseContent(content: string, source: string): void {
|
||||
this.parseError = '';
|
||||
this.skipped = [];
|
||||
this.duplicatesRemoved = 0;
|
||||
|
||||
// Strip BOM
|
||||
const cleaned = content.replace(/^\uFEFF/, '');
|
||||
const lines = cleaned.split(/\r?\n|\r/);
|
||||
|
||||
let isbns: string[];
|
||||
const extension = source.split('.').pop()?.toLowerCase();
|
||||
|
||||
if (extension === 'csv' || extension === 'tsv') {
|
||||
isbns = this.parseCsvLines(lines, extension === 'tsv' ? '\t' : undefined);
|
||||
} else if (source === 'paste') {
|
||||
// Pasted text: split by newlines, commas, semicolons, or spaces
|
||||
const tokens = cleaned.split(/[\n\r,;\s]+/);
|
||||
isbns = tokens.map(t => t.trim()).filter(t => t.length > 0);
|
||||
} else {
|
||||
// Plain text: one per line
|
||||
isbns = lines.map(l => l.trim()).filter(l => l.length > 0 && !l.startsWith('#'));
|
||||
}
|
||||
|
||||
const existingIsbns = this.getExistingIsbnsForLibrary();
|
||||
const validEntries: IsbnEntry[] = [];
|
||||
const seen = new Set<string>();
|
||||
|
||||
for (const raw of isbns) {
|
||||
const normalized = this.normalizeIsbn(raw);
|
||||
|
||||
if (!this.isValidIsbn(normalized)) {
|
||||
this.skipped.push({value: raw, reason: 'invalid'});
|
||||
continue;
|
||||
}
|
||||
|
||||
if (seen.has(normalized)) {
|
||||
this.duplicatesRemoved++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (existingIsbns.has(normalized)) {
|
||||
this.skipped.push({value: normalized, reason: 'alreadyExists'});
|
||||
continue;
|
||||
}
|
||||
|
||||
seen.add(normalized);
|
||||
validEntries.push({isbn: normalized, status: 'pending'});
|
||||
}
|
||||
|
||||
if (validEntries.length > MAX_ISBN_COUNT) {
|
||||
this.parseError = 'tooMany';
|
||||
this.entries = validEntries.slice(0, MAX_ISBN_COUNT);
|
||||
} else {
|
||||
this.entries = validEntries;
|
||||
}
|
||||
|
||||
if (this.entries.length === 0 && this.skipped.length === 0) {
|
||||
this.parseError = 'empty';
|
||||
}
|
||||
}
|
||||
|
||||
private parseCsvLines(lines: string[], delimiter?: string): string[] {
|
||||
if (lines.length === 0) return [];
|
||||
|
||||
// Auto-detect delimiter if not provided
|
||||
if (!delimiter) {
|
||||
const firstLine = lines[0];
|
||||
if (firstLine.includes('\t')) delimiter = '\t';
|
||||
else if (firstLine.includes(';')) delimiter = ';';
|
||||
else delimiter = ',';
|
||||
}
|
||||
|
||||
const headerFields = lines[0].split(delimiter).map(f => f.trim().replace(/^["']|["']$/g, '').toLowerCase());
|
||||
let isbnColIndex = headerFields.findIndex(h => h === 'isbn' || h === 'isbn13' || h === 'isbn10');
|
||||
|
||||
let startLine: number;
|
||||
if (isbnColIndex >= 0) {
|
||||
startLine = 1; // skip header
|
||||
} else {
|
||||
isbnColIndex = 0; // assume first column
|
||||
startLine = 0;
|
||||
}
|
||||
|
||||
const result: string[] = [];
|
||||
for (let i = startLine; i < lines.length; i++) {
|
||||
const line = lines[i].trim();
|
||||
if (!line) continue;
|
||||
|
||||
const fields = line.split(delimiter);
|
||||
if (fields.length > isbnColIndex) {
|
||||
const value = fields[isbnColIndex].trim().replace(/^["']|["']$/g, '');
|
||||
if (value) result.push(value);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private getExistingIsbnsForLibrary(): Set<string> {
|
||||
const isbns = new Set<string>();
|
||||
if (!this.selectedLibraryId) return isbns;
|
||||
|
||||
const books = this.bookService.books();
|
||||
for (const book of books) {
|
||||
if (book.libraryId !== this.selectedLibraryId) continue;
|
||||
const isbn13 = book.metadata?.isbn13;
|
||||
const isbn10 = book.metadata?.isbn10;
|
||||
if (isbn13) isbns.add(isbn13.toUpperCase());
|
||||
if (isbn10) isbns.add(isbn10.toUpperCase());
|
||||
}
|
||||
return isbns;
|
||||
}
|
||||
|
||||
private normalizeIsbn(raw: string): string {
|
||||
// Strip hyphens, spaces, surrounding whitespace; preserve trailing X
|
||||
return raw.trim().replace(/[-\s]/g, '').toUpperCase();
|
||||
}
|
||||
|
||||
private isValidIsbn(isbn: string): boolean {
|
||||
if (/^\d{10}$/.test(isbn) || /^\d{9}X$/.test(isbn)) return true;
|
||||
if (/^\d{13}$/.test(isbn) && (isbn.startsWith('978') || isbn.startsWith('979'))) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private lookupIsbn(isbn: string): Promise<BookMetadata | null> {
|
||||
return new Promise((resolve) => {
|
||||
this.bookMetadataService.lookupByIsbn(isbn).subscribe({
|
||||
next: metadata => resolve(metadata),
|
||||
error: err => {
|
||||
// Retry once on potential rate limiting
|
||||
if (err?.status === 429) {
|
||||
setTimeout(() => {
|
||||
this.bookMetadataService.lookupByIsbn(isbn).subscribe({
|
||||
next: metadata => resolve(metadata),
|
||||
error: () => resolve(null), // Still create with ISBN only
|
||||
});
|
||||
}, RETRY_DELAY_MS);
|
||||
} else {
|
||||
resolve(null); // No metadata found, still create with ISBN
|
||||
}
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private createBook(request: CreatePhysicalBookRequest): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.bookService.createPhysicalBook(request).subscribe({
|
||||
next: () => resolve(),
|
||||
error: err => reject(err),
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private delay(ms: number): Promise<void> {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
}
|
||||
+248
@@ -0,0 +1,248 @@
|
||||
<ng-container *transloco="let t; prefix: 'book.duplicateMerger'">
|
||||
<div class="duplicate-merger-container">
|
||||
<div class="panel-header">
|
||||
<div class="header-icon-wrapper">
|
||||
<i class="pi pi-copy header-icon"></i>
|
||||
</div>
|
||||
<div class="header-text">
|
||||
<h2 class="panel-title">{{ t('title') }}</h2>
|
||||
<p class="panel-description">{{ t('description') }}</p>
|
||||
</div>
|
||||
<p-button
|
||||
icon="pi pi-times"
|
||||
[rounded]="true"
|
||||
[text]="true"
|
||||
severity="secondary"
|
||||
(click)="closeDialog()"
|
||||
class="close-button">
|
||||
</p-button>
|
||||
</div>
|
||||
|
||||
<div class="dialog-content">
|
||||
<!-- Preset Mode Selector -->
|
||||
<div class="preset-section">
|
||||
<p-selectButton
|
||||
[options]="presetOptions"
|
||||
[(ngModel)]="presetMode"
|
||||
(onChange)="onPresetChange()"
|
||||
optionLabel="label"
|
||||
optionValue="value"
|
||||
[disabled]="isScanning || isMerging">
|
||||
</p-selectButton>
|
||||
</div>
|
||||
|
||||
<!-- Advanced Toggles -->
|
||||
<div class="advanced-section">
|
||||
<button class="advanced-toggle" (click)="showAdvanced = !showAdvanced">
|
||||
<i class="pi" [class.pi-chevron-right]="!showAdvanced" [class.pi-chevron-down]="showAdvanced"></i>
|
||||
{{ t('advanced') }}
|
||||
</button>
|
||||
|
||||
@if (showAdvanced) {
|
||||
<div class="signal-checkboxes">
|
||||
<div class="signal-checkbox">
|
||||
<p-checkbox [(ngModel)]="matchByIsbn" [binary]="true" inputId="isbn" (onChange)="onSignalToggle()" [disabled]="isScanning || isMerging"></p-checkbox>
|
||||
<label for="isbn">{{ t('signalIsbn') }}</label>
|
||||
</div>
|
||||
<div class="signal-checkbox">
|
||||
<p-checkbox [(ngModel)]="matchByExternalId" [binary]="true" inputId="externalId" (onChange)="onSignalToggle()" [disabled]="isScanning || isMerging"></p-checkbox>
|
||||
<label for="externalId">{{ t('signalExternalId') }}</label>
|
||||
</div>
|
||||
<div class="signal-checkbox">
|
||||
<p-checkbox [(ngModel)]="matchByTitleAuthor" [binary]="true" inputId="titleAuthor" (onChange)="onSignalToggle()" [disabled]="isScanning || isMerging"></p-checkbox>
|
||||
<label for="titleAuthor">{{ t('signalTitleAuthor') }}</label>
|
||||
</div>
|
||||
<div class="signal-checkbox">
|
||||
<p-checkbox [(ngModel)]="matchByDirectory" [binary]="true" inputId="directory" (onChange)="onSignalToggle()" [disabled]="isScanning || isMerging"></p-checkbox>
|
||||
<label for="directory">{{ t('signalDirectory') }}</label>
|
||||
</div>
|
||||
<div class="signal-checkbox">
|
||||
<p-checkbox [(ngModel)]="matchByFilename" [binary]="true" inputId="filename" (onChange)="onSignalToggle()" [disabled]="isScanning || isMerging"></p-checkbox>
|
||||
<label for="filename">{{ t('signalFilename') }}</label>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<!-- Action Bar -->
|
||||
<div class="action-bar">
|
||||
<div class="action-bar-left">
|
||||
<p-button
|
||||
[label]="t('scan')"
|
||||
icon="pi pi-search"
|
||||
(click)="scan()"
|
||||
[disabled]="!canScan"
|
||||
[loading]="isScanning">
|
||||
</p-button>
|
||||
</div>
|
||||
<div class="action-bar-right">
|
||||
<div class="delete-option">
|
||||
<p-checkbox
|
||||
[(ngModel)]="moveFiles"
|
||||
[binary]="true"
|
||||
inputId="moveFiles"
|
||||
[disabled]="isMerging">
|
||||
</p-checkbox>
|
||||
<label for="moveFiles">{{ 'book.fileAttacher.moveFilesLabel' | transloco }}</label>
|
||||
</div>
|
||||
@if (activeGroups.length > 0) {
|
||||
<p-button
|
||||
[label]="t('mergeAll', { count: activeGroups.length })"
|
||||
icon="pi pi-check-circle"
|
||||
severity="success"
|
||||
(click)="mergeAll()"
|
||||
[disabled]="isMerging"
|
||||
[loading]="isMerging">
|
||||
</p-button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Merge Progress -->
|
||||
@if (isMerging) {
|
||||
<p-progressBar [value]="mergeTotal > 0 ? (mergeProgress / mergeTotal) * 100 : 0" [showValue]="false"></p-progressBar>
|
||||
}
|
||||
|
||||
<!-- Help Text -->
|
||||
@if (hasScanned && activeGroups.length > 0) {
|
||||
<div class="help-text">
|
||||
<i class="pi pi-info-circle"></i>
|
||||
<span>{{ t('helpText') }}</span>
|
||||
</div>
|
||||
}
|
||||
|
||||
<!-- Results Area -->
|
||||
<div class="results-area">
|
||||
@if (isScanning) {
|
||||
<div class="empty-state">
|
||||
<i class="pi pi-spin pi-spinner"></i>
|
||||
<p>{{ t('scanning') }}</p>
|
||||
</div>
|
||||
} @else if (!hasScanned) {
|
||||
<div class="empty-state">
|
||||
<i class="pi pi-search"></i>
|
||||
<p>{{ t('scanPrompt') }}</p>
|
||||
</div>
|
||||
} @else if (activeGroups.length === 0 && groups.length === 0) {
|
||||
<div class="empty-state">
|
||||
<i class="pi pi-check-circle"></i>
|
||||
<p>{{ t('noDuplicates') }}</p>
|
||||
</div>
|
||||
} @else if (activeGroups.length === 0 && groups.length > 0) {
|
||||
<div class="empty-state">
|
||||
<i class="pi pi-check-circle"></i>
|
||||
<p>{{ t('allMerged') }}</p>
|
||||
</div>
|
||||
} @else {
|
||||
<div class="groups-list">
|
||||
@for (group of pagedGroups; track group.suggestedTargetBookId) {
|
||||
<div class="duplicate-group">
|
||||
<div class="group-header">
|
||||
<span class="group-label">{{ t('groupLabel', { index: pageFirst + $index + 1 }) }}</span>
|
||||
<p-tag [value]="getMatchReasonLabel(group.matchReason)" [severity]="getMatchReasonSeverity(group.matchReason)"></p-tag>
|
||||
@if (hasSameFormatConflict(group)) {
|
||||
<p-tag [value]="t('sameFormatWarning')" severity="warn" icon="pi pi-exclamation-triangle"></p-tag>
|
||||
}
|
||||
<div class="group-actions">
|
||||
<p-button
|
||||
[label]="t('merge')"
|
||||
icon="pi pi-check"
|
||||
size="small"
|
||||
severity="success"
|
||||
(click)="mergeGroup(group)"
|
||||
[disabled]="isMerging">
|
||||
</p-button>
|
||||
@if (getDeleteSelectedCount(group) > 0) {
|
||||
<p-button
|
||||
[label]="t('deleteSelected', { count: getDeleteSelectedCount(group) })"
|
||||
icon="pi pi-trash"
|
||||
size="small"
|
||||
severity="danger"
|
||||
[outlined]="true"
|
||||
(click)="deleteGroup(group)"
|
||||
[disabled]="isMerging">
|
||||
</p-button>
|
||||
}
|
||||
<p-button
|
||||
[label]="t('dismiss')"
|
||||
icon="pi pi-times"
|
||||
size="small"
|
||||
severity="secondary"
|
||||
[outlined]="true"
|
||||
(click)="dismissGroup(group)"
|
||||
[disabled]="isMerging">
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="group-books">
|
||||
@for (book of group.books; track book.id) {
|
||||
<div class="book-row" [class.selected-target]="book.id === group.selectedTargetBookId" [class.marked-for-deletion]="group.selectedForDeletion.has(book.id)">
|
||||
@if (book.id !== group.selectedTargetBookId) {
|
||||
<p-checkbox
|
||||
[binary]="true"
|
||||
[ngModel]="group.selectedForDeletion.has(book.id)"
|
||||
(onChange)="toggleDeleteSelection(group, book.id)"
|
||||
[disabled]="isMerging"
|
||||
class="delete-checkbox">
|
||||
</p-checkbox>
|
||||
}
|
||||
<img class="book-cover"
|
||||
[src]="urlHelper.getThumbnailUrl(book.id, book.metadata?.coverUpdatedOn)"
|
||||
[alt]="book.metadata?.title || ''"
|
||||
loading="lazy"/>
|
||||
<div class="book-info">
|
||||
<div class="book-title">{{ book.metadata?.title || ('book.fileAttacher.unknownTitle' | transloco) }}</div>
|
||||
@if (book.metadata?.authors?.length) {
|
||||
<div class="book-authors">{{ book.metadata?.authors?.join(', ') }}</div>
|
||||
}
|
||||
<div class="book-formats">
|
||||
@for (format of getBookFormats(book); track format) {
|
||||
<span class="format-badge">{{ format }}</span>
|
||||
}
|
||||
@if (getFileCount(book) > 1) {
|
||||
<span class="file-count">{{ t('fileCount', { count: getFileCount(book) }) }}</span>
|
||||
}
|
||||
@if (book.primaryFile?.fileSizeKb) {
|
||||
<span class="file-detail">{{ formatFileSize(book.primaryFile?.fileSizeKb) }}</span>
|
||||
}
|
||||
</div>
|
||||
@if (book.primaryFile?.fileName) {
|
||||
<div class="book-file-path" [title]="getBookFilePath(book)">
|
||||
<i class="pi pi-file"></i>
|
||||
{{ getBookFilePath(book) }}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
<div class="book-select">
|
||||
<p-radioButton
|
||||
[name]="'target-' + group.suggestedTargetBookId"
|
||||
[value]="book.id"
|
||||
[(ngModel)]="group.selectedTargetBookId"
|
||||
(onClick)="onTargetChange(group)"
|
||||
[disabled]="isMerging">
|
||||
</p-radioButton>
|
||||
@if (book.id === group.selectedTargetBookId) {
|
||||
<span class="target-label">{{ t('target') }}</span>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@if (activeGroups.length > pageSize) {
|
||||
<p-paginator
|
||||
[rows]="pageSize"
|
||||
[totalRecords]="activeGroups.length"
|
||||
[first]="pageFirst"
|
||||
(onPageChange)="onPageChange($event)"
|
||||
[rowsPerPageOptions]="[10, 20, 50]">
|
||||
</p-paginator>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
+338
@@ -0,0 +1,338 @@
|
||||
@use '../../../../shared/styles/panel-shared' as panel;
|
||||
|
||||
.duplicate-merger-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.panel-header {
|
||||
@include panel.panel-header;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.dialog-content {
|
||||
flex: 1;
|
||||
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);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.preset-section {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.advanced-section {
|
||||
.advanced-toggle {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
background: none;
|
||||
border: none;
|
||||
color: var(--p-text-muted-color);
|
||||
font-size: 0.875rem;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
padding: 0.25rem 0;
|
||||
|
||||
&:hover {
|
||||
color: var(--p-text-color);
|
||||
}
|
||||
|
||||
i {
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
}
|
||||
|
||||
.signal-checkboxes {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.75rem 1.5rem;
|
||||
padding: 0.75rem 0 0 0;
|
||||
}
|
||||
|
||||
.signal-checkbox {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
|
||||
label {
|
||||
font-size: 0.875rem;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.action-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 1rem;
|
||||
padding: 0.75rem 0;
|
||||
border-top: 1px solid var(--border-color);
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
|
||||
.action-bar-left {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.action-bar-right {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.delete-option {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
|
||||
label {
|
||||
font-size: 0.875rem;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.results-area {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 3rem 1rem;
|
||||
color: var(--p-text-muted-color);
|
||||
gap: 0.75rem;
|
||||
|
||||
i {
|
||||
font-size: 2.5rem;
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 0;
|
||||
font-size: 0.9375rem;
|
||||
}
|
||||
}
|
||||
|
||||
.groups-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.duplicate-group {
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
|
||||
.group-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
padding: 0.5rem 0.75rem;
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
|
||||
.group-label {
|
||||
font-weight: 600;
|
||||
font-size: 0.8125rem;
|
||||
color: var(--p-text-muted-color);
|
||||
}
|
||||
|
||||
.group-actions {
|
||||
margin-left: auto;
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
.group-books {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
|
||||
.book-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
padding: 0.625rem 0.75rem;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.1s;
|
||||
|
||||
&:not(:last-child) {
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
&:hover {
|
||||
background: var(--p-content-hover-background);
|
||||
}
|
||||
|
||||
&.selected-target {
|
||||
background: var(--p-highlight-background);
|
||||
}
|
||||
|
||||
&.marked-for-deletion {
|
||||
background: color-mix(in srgb, var(--p-red-500) 8%, transparent);
|
||||
}
|
||||
|
||||
.delete-checkbox {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.book-cover {
|
||||
width: 36px;
|
||||
height: 52px;
|
||||
flex-shrink: 0;
|
||||
border-radius: 3px;
|
||||
object-fit: cover;
|
||||
background: var(--p-surface-200);
|
||||
}
|
||||
|
||||
.book-info {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.0625rem;
|
||||
|
||||
.book-title {
|
||||
font-weight: 600;
|
||||
font-size: 0.875rem;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.book-authors {
|
||||
font-size: 0.8125rem;
|
||||
color: var(--p-text-muted-color);
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.book-formats {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.25rem;
|
||||
margin-top: 0.125rem;
|
||||
|
||||
.format-badge {
|
||||
display: inline-block;
|
||||
font-size: 0.625rem;
|
||||
font-weight: 700;
|
||||
padding: 0.0625rem 0.3125rem;
|
||||
border-radius: 3px;
|
||||
background: var(--p-primary-100);
|
||||
color: var(--p-primary-700);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.02em;
|
||||
}
|
||||
|
||||
.file-count {
|
||||
font-size: 0.75rem;
|
||||
color: var(--p-text-muted-color);
|
||||
}
|
||||
|
||||
.file-detail {
|
||||
font-size: 0.75rem;
|
||||
color: var(--p-text-muted-color);
|
||||
}
|
||||
}
|
||||
|
||||
.book-file-path {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.25rem;
|
||||
font-size: 0.75rem;
|
||||
color: var(--p-text-muted-color);
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
margin-top: 0.125rem;
|
||||
|
||||
i {
|
||||
font-size: 0.6875rem;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.book-select {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.375rem;
|
||||
flex-shrink: 0;
|
||||
|
||||
.target-label {
|
||||
font-size: 0.6875rem;
|
||||
color: var(--p-primary-color);
|
||||
text-transform: uppercase;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.03em;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.help-text {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 0.5rem;
|
||||
padding: 0.625rem 0.75rem;
|
||||
font-size: 0.8125rem;
|
||||
color: var(--p-text-muted-color);
|
||||
background: var(--p-content-hover-background);
|
||||
border-radius: 6px;
|
||||
line-height: 1.4;
|
||||
|
||||
i {
|
||||
flex-shrink: 0;
|
||||
margin-top: 0.125rem;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
}
|
||||
|
||||
:host-context(.p-dark) {
|
||||
.book-row .book-cover {
|
||||
background: var(--p-surface-700);
|
||||
}
|
||||
|
||||
.book-row .book-formats .format-badge {
|
||||
background: rgba(var(--p-primary-500-rgb, 99, 102, 241), 0.15);
|
||||
color: var(--p-primary-400);
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.action-bar {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
|
||||
.action-bar-right {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
}
|
||||
|
||||
.duplicate-group .group-header {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
}
|
||||
+394
@@ -0,0 +1,394 @@
|
||||
import {Component, inject, OnDestroy, OnInit} from '@angular/core';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {Button} from 'primeng/button';
|
||||
import {Checkbox} from 'primeng/checkbox';
|
||||
import {RadioButton} from 'primeng/radiobutton';
|
||||
import {SelectButton} from 'primeng/selectbutton';
|
||||
import {ProgressBar} from 'primeng/progressbar';
|
||||
import {Tag} from 'primeng/tag';
|
||||
import {Paginator} from 'primeng/paginator';
|
||||
import {Subject, takeUntil} from 'rxjs';
|
||||
import {BookFileService} from '../../service/book-file.service';
|
||||
import {BookService} from '../../service/book.service';
|
||||
import {Book, DuplicateDetectionRequest, DuplicateGroup} from '../../model/book.model';
|
||||
import {ConfirmationService, MessageService} from 'primeng/api';
|
||||
import {TranslocoDirective, TranslocoPipe, TranslocoService} from '@jsverse/transloco';
|
||||
import {UrlHelperService} from '../../../../shared/service/url-helper.service';
|
||||
import {AppSettingsService} from '../../../../shared/service/app-settings.service';
|
||||
|
||||
type PresetMode = 'strict' | 'balanced' | 'aggressive' | 'custom';
|
||||
|
||||
interface DisplayGroup extends DuplicateGroup {
|
||||
selectedTargetBookId: number;
|
||||
dismissed: boolean;
|
||||
selectedForDeletion: Set<number>;
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-duplicate-merger',
|
||||
standalone: true,
|
||||
imports: [
|
||||
FormsModule,
|
||||
Button,
|
||||
Checkbox,
|
||||
RadioButton,
|
||||
SelectButton,
|
||||
ProgressBar,
|
||||
Tag,
|
||||
Paginator,
|
||||
TranslocoDirective,
|
||||
TranslocoPipe,
|
||||
],
|
||||
templateUrl: './duplicate-merger.component.html',
|
||||
styleUrls: ['./duplicate-merger.component.scss']
|
||||
})
|
||||
export class DuplicateMergerComponent implements OnInit, OnDestroy {
|
||||
libraryId!: number;
|
||||
presetMode: PresetMode = 'balanced';
|
||||
showAdvanced = false;
|
||||
|
||||
matchByIsbn = true;
|
||||
matchByExternalId = true;
|
||||
matchByTitleAuthor = true;
|
||||
matchByDirectory = false;
|
||||
matchByFilename = false;
|
||||
|
||||
isScanning = false;
|
||||
isMerging = false;
|
||||
hasScanned = false;
|
||||
moveFiles = false;
|
||||
mergeProgress = 0;
|
||||
mergeTotal = 0;
|
||||
|
||||
groups: DisplayGroup[] = [];
|
||||
presetOptions: { label: string; value: PresetMode }[] = [];
|
||||
|
||||
pageFirst = 0;
|
||||
pageSize = 20;
|
||||
|
||||
private destroy$ = new Subject<void>();
|
||||
private readonly bookFileService = inject(BookFileService);
|
||||
private readonly bookService = inject(BookService);
|
||||
private readonly messageService = inject(MessageService);
|
||||
private readonly confirmationService = inject(ConfirmationService);
|
||||
private readonly dialogRef = inject(DynamicDialogRef);
|
||||
private readonly config = inject(DynamicDialogConfig);
|
||||
private readonly t = inject(TranslocoService);
|
||||
readonly urlHelper = inject(UrlHelperService);
|
||||
private readonly appSettingsService = inject(AppSettingsService);
|
||||
|
||||
ngOnInit(): void {
|
||||
this.libraryId = this.config.data.libraryId;
|
||||
|
||||
const settings = this.appSettingsService.appSettings();
|
||||
if (settings) {
|
||||
this.moveFiles = settings.metadataPersistenceSettings?.moveFilesToLibraryPattern ?? false;
|
||||
}
|
||||
|
||||
this.presetOptions = [
|
||||
{label: this.t.translate('book.duplicateMerger.presetStrict'), value: 'strict'},
|
||||
{label: this.t.translate('book.duplicateMerger.presetBalanced'), value: 'balanced'},
|
||||
{label: this.t.translate('book.duplicateMerger.presetAggressive'), value: 'aggressive'},
|
||||
{label: this.t.translate('book.duplicateMerger.presetCustom'), value: 'custom'},
|
||||
];
|
||||
this.applyPreset('balanced');
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
}
|
||||
|
||||
onPresetChange(): void {
|
||||
if (this.presetMode !== 'custom') {
|
||||
this.applyPreset(this.presetMode);
|
||||
}
|
||||
}
|
||||
|
||||
onSignalToggle(): void {
|
||||
this.presetMode = 'custom';
|
||||
}
|
||||
|
||||
applyPreset(mode: PresetMode): void {
|
||||
switch (mode) {
|
||||
case 'strict':
|
||||
this.matchByIsbn = true;
|
||||
this.matchByExternalId = true;
|
||||
this.matchByTitleAuthor = false;
|
||||
this.matchByDirectory = false;
|
||||
this.matchByFilename = false;
|
||||
break;
|
||||
case 'balanced':
|
||||
this.matchByIsbn = true;
|
||||
this.matchByExternalId = true;
|
||||
this.matchByTitleAuthor = true;
|
||||
this.matchByDirectory = false;
|
||||
this.matchByFilename = false;
|
||||
break;
|
||||
case 'aggressive':
|
||||
this.matchByIsbn = true;
|
||||
this.matchByExternalId = true;
|
||||
this.matchByTitleAuthor = true;
|
||||
this.matchByDirectory = true;
|
||||
this.matchByFilename = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
scan(): void {
|
||||
this.isScanning = true;
|
||||
this.hasScanned = false;
|
||||
this.groups = [];
|
||||
this.pageFirst = 0;
|
||||
|
||||
const request: DuplicateDetectionRequest = {
|
||||
libraryId: this.libraryId,
|
||||
matchByIsbn: this.matchByIsbn,
|
||||
matchByExternalId: this.matchByExternalId,
|
||||
matchByTitleAuthor: this.matchByTitleAuthor,
|
||||
matchByDirectory: this.matchByDirectory,
|
||||
matchByFilename: this.matchByFilename,
|
||||
};
|
||||
|
||||
this.bookFileService.findDuplicates(request).pipe(
|
||||
takeUntil(this.destroy$)
|
||||
).subscribe({
|
||||
next: (groups) => {
|
||||
this.groups = groups.map(g => ({
|
||||
...g,
|
||||
selectedTargetBookId: g.suggestedTargetBookId,
|
||||
dismissed: false,
|
||||
selectedForDeletion: new Set<number>(),
|
||||
}));
|
||||
this.isScanning = false;
|
||||
this.hasScanned = true;
|
||||
},
|
||||
error: (err) => {
|
||||
this.isScanning = false;
|
||||
this.hasScanned = true;
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('book.duplicateMerger.toast.scanFailedSummary'),
|
||||
detail: err?.error?.message || this.t.translate('book.duplicateMerger.toast.scanFailedDetail'),
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get activeGroups(): DisplayGroup[] {
|
||||
return this.groups.filter(g => !g.dismissed);
|
||||
}
|
||||
|
||||
get pagedGroups(): DisplayGroup[] {
|
||||
return this.activeGroups.slice(this.pageFirst, this.pageFirst + this.pageSize);
|
||||
}
|
||||
|
||||
get canScan(): boolean {
|
||||
return !this.isScanning && !this.isMerging &&
|
||||
(this.matchByIsbn || this.matchByExternalId || this.matchByTitleAuthor ||
|
||||
this.matchByDirectory || this.matchByFilename);
|
||||
}
|
||||
|
||||
onPageChange(event: any): void {
|
||||
this.pageFirst = event.first;
|
||||
this.pageSize = event.rows;
|
||||
}
|
||||
|
||||
getBookFormats(book: Book): string[] {
|
||||
const formats: string[] = [];
|
||||
if (book.primaryFile?.bookType) {
|
||||
formats.push(book.primaryFile.bookType);
|
||||
}
|
||||
if (book.alternativeFormats) {
|
||||
for (const alt of book.alternativeFormats) {
|
||||
if (alt.bookType) {
|
||||
formats.push(alt.bookType);
|
||||
}
|
||||
}
|
||||
}
|
||||
return formats;
|
||||
}
|
||||
|
||||
getFileCount(book: Book): number {
|
||||
let count = book.primaryFile ? 1 : 0;
|
||||
count += book.alternativeFormats?.length ?? 0;
|
||||
return count;
|
||||
}
|
||||
|
||||
getMatchReasonLabel(reason: string): string {
|
||||
return this.t.translate(`book.duplicateMerger.reason.${reason}`);
|
||||
}
|
||||
|
||||
hasSameFormatConflict(group: DisplayGroup): boolean {
|
||||
const formats = new Set<string>();
|
||||
for (const book of group.books) {
|
||||
if (book.primaryFile?.bookType) {
|
||||
if (formats.has(book.primaryFile.bookType)) return true;
|
||||
formats.add(book.primaryFile.bookType);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
getBookFilePath(book: Book): string {
|
||||
const subPath = book.primaryFile?.fileSubPath;
|
||||
const fileName = book.primaryFile?.fileName || '';
|
||||
if (subPath) return `${subPath}/${fileName}`;
|
||||
return fileName;
|
||||
}
|
||||
|
||||
formatFileSize(sizeKb?: number): string {
|
||||
if (!sizeKb) return '';
|
||||
if (sizeKb < 1024) return `${sizeKb} KB`;
|
||||
const sizeMb = sizeKb / 1024;
|
||||
if (sizeMb < 1024) return `${sizeMb.toFixed(1)} MB`;
|
||||
return `${(sizeMb / 1024).toFixed(2)} GB`;
|
||||
}
|
||||
|
||||
getMatchReasonSeverity(reason: string): "success" | "info" | "warn" | "danger" | "secondary" | "contrast" {
|
||||
switch (reason) {
|
||||
case 'ISBN':
|
||||
case 'EXTERNAL_ID':
|
||||
return 'success';
|
||||
case 'TITLE_AUTHOR':
|
||||
return 'info';
|
||||
case 'DIRECTORY':
|
||||
return 'warn';
|
||||
case 'FILENAME':
|
||||
return 'secondary';
|
||||
default:
|
||||
return 'info';
|
||||
}
|
||||
}
|
||||
|
||||
onTargetChange(group: DisplayGroup): void {
|
||||
group.selectedForDeletion.delete(group.selectedTargetBookId);
|
||||
}
|
||||
|
||||
toggleDeleteSelection(group: DisplayGroup, bookId: number): void {
|
||||
if (group.selectedForDeletion.has(bookId)) {
|
||||
group.selectedForDeletion.delete(bookId);
|
||||
} else {
|
||||
group.selectedForDeletion.add(bookId);
|
||||
}
|
||||
}
|
||||
|
||||
getDeleteSelectedCount(group: DisplayGroup): number {
|
||||
return group.selectedForDeletion.size;
|
||||
}
|
||||
|
||||
dismissGroup(group: DisplayGroup): void {
|
||||
group.dismissed = true;
|
||||
if (this.pagedGroups.length === 0 && this.pageFirst > 0) {
|
||||
this.pageFirst = Math.max(0, this.pageFirst - this.pageSize);
|
||||
}
|
||||
}
|
||||
|
||||
async mergeGroup(group: DisplayGroup): Promise<void> {
|
||||
const targetId = group.selectedTargetBookId;
|
||||
const sourceIds = group.books
|
||||
.filter(b => b.id !== targetId)
|
||||
.map(b => b.id);
|
||||
|
||||
if (sourceIds.length === 0) return;
|
||||
|
||||
group.dismissed = true;
|
||||
try {
|
||||
await this.bookFileService.attachBookFiles(targetId, sourceIds, this.moveFiles)
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
.toPromise();
|
||||
} catch {
|
||||
group.dismissed = false;
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('book.duplicateMerger.toast.mergeFailedSummary'),
|
||||
detail: this.t.translate('book.duplicateMerger.toast.mergeFailedDetail'),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async mergeAll(): Promise<void> {
|
||||
const toMerge = this.activeGroups;
|
||||
if (toMerge.length === 0) return;
|
||||
|
||||
this.isMerging = true;
|
||||
this.mergeTotal = toMerge.length;
|
||||
this.mergeProgress = 0;
|
||||
|
||||
let successCount = 0;
|
||||
let failCount = 0;
|
||||
|
||||
for (const group of toMerge) {
|
||||
const targetId = group.selectedTargetBookId;
|
||||
const sourceIds = group.books
|
||||
.filter(b => b.id !== targetId)
|
||||
.map(b => b.id);
|
||||
|
||||
if (sourceIds.length === 0) {
|
||||
group.dismissed = true;
|
||||
this.mergeProgress++;
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
await this.bookFileService.attachBookFiles(targetId, sourceIds, this.moveFiles)
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
.toPromise();
|
||||
group.dismissed = true;
|
||||
successCount++;
|
||||
} catch {
|
||||
failCount++;
|
||||
}
|
||||
this.mergeProgress++;
|
||||
}
|
||||
|
||||
this.isMerging = false;
|
||||
|
||||
if (successCount > 0) {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('book.duplicateMerger.toast.mergeSuccessSummary'),
|
||||
detail: this.t.translate('book.duplicateMerger.toast.mergeSuccessDetail', {count: successCount}),
|
||||
});
|
||||
}
|
||||
if (failCount > 0) {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('book.duplicateMerger.toast.mergeFailedSummary'),
|
||||
detail: this.t.translate('book.duplicateMerger.toast.mergePartialDetail', {success: successCount, failed: failCount}),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
deleteGroup(group: DisplayGroup): void {
|
||||
const idsToDelete = Array.from(group.selectedForDeletion);
|
||||
if (idsToDelete.length === 0) return;
|
||||
|
||||
this.confirmationService.confirm({
|
||||
message: this.t.translate('book.duplicateMerger.confirm.deleteMessage', {count: idsToDelete.length}),
|
||||
header: this.t.translate('book.duplicateMerger.confirm.deleteHeader'),
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
acceptLabel: this.t.translate('common.yes'),
|
||||
rejectLabel: this.t.translate('common.no'),
|
||||
acceptButtonProps: {severity: 'danger'},
|
||||
accept: () => {
|
||||
this.bookService.deleteBooks(new Set(idsToDelete)).pipe(
|
||||
takeUntil(this.destroy$)
|
||||
).subscribe({
|
||||
next: () => {
|
||||
group.books = group.books.filter(b => !group.selectedForDeletion.has(b.id));
|
||||
group.selectedForDeletion.clear();
|
||||
if (group.books.length <= 1) {
|
||||
group.dismissed = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
closeDialog(): void {
|
||||
this.dialogRef.close();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,471 @@
|
||||
<ng-container *transloco="let t; prefix: 'book.seriesPage'">
|
||||
@if (isBooksLoading()) {
|
||||
<div class="loading-state">
|
||||
<p-progressSpinner strokeWidth="4" fill="transparent" animationDuration=".8s">
|
||||
</p-progressSpinner>
|
||||
<p style="color: var(--primary-color);">
|
||||
{{ t('loadingSeriesDetails') }}
|
||||
</p>
|
||||
</div>
|
||||
} @else {
|
||||
@let books = filteredBooks();
|
||||
<div class="series-wrapper">
|
||||
<p-tabs [value]="tab" lazy="true" scrollable>
|
||||
<p-tablist>
|
||||
<p-tab value="view">
|
||||
<i [class]="'pi pi-crown'"></i>
|
||||
{{ t('seriesDetailsTab') }}
|
||||
</p-tab>
|
||||
<p-tab value="list">
|
||||
<i [class]="'pi pi-list'"></i>
|
||||
{{ t('bookListTab') }}
|
||||
</p-tab>
|
||||
</p-tablist>
|
||||
<p-tabpanels class="tabpanels-responsive">
|
||||
<p-tabpanel value="view">
|
||||
|
||||
@if (books[0]; as firstBook) {
|
||||
<div class="series-main">
|
||||
<div class="series-details">
|
||||
|
||||
<!-- HERO: Cover + Identity info -->
|
||||
<div class="series-hero">
|
||||
@if (coverBook(); as coverBook) {
|
||||
<div class="hero-cover-section">
|
||||
<img
|
||||
[src]="getBookThumbnailUrl(coverBook)"
|
||||
class="hero-cover-img"
|
||||
[alt]="coverBook.metadata?.title || ''"
|
||||
loading="lazy"
|
||||
decoding="async"/>
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="hero-info">
|
||||
<h2 class="series-title">{{ seriesTitle() }}</h2>
|
||||
|
||||
@if (allAuthors(); as authors) {
|
||||
<p class="series-authors">
|
||||
@for (author of authors; track $index; let isLast = $last) {
|
||||
<a class="author-link" (click)="goToAuthorBooks(author)">{{ author }}</a>
|
||||
@if (!isLast) {<span>, </span>}
|
||||
}
|
||||
</p>
|
||||
}
|
||||
|
||||
@if (allCategories(); as categories) {
|
||||
@if (categories.length) {
|
||||
<div class="categories-scroll">
|
||||
<div class="categories-list">
|
||||
@for (category of categories; track category) {
|
||||
<a (click)="goToCategory(category)" class="category-link">
|
||||
<app-tag color="red" size="xs">{{ category }}</app-tag>
|
||||
</a>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
<div class="metadata-cards">
|
||||
@if (allPublishers(); as publishers) {
|
||||
@if (publishers.length) {
|
||||
<span class="meta-card meta-card--publisher" (click)="goToPublisher(publishers[0])">
|
||||
<i class="pi pi-building"></i>
|
||||
@for (pub of publishers; track pub; let isLast = $last) {
|
||||
{{ pub }}{{ isLast ? '' : ', ' }}
|
||||
}
|
||||
</span>
|
||||
}
|
||||
}
|
||||
<span class="meta-card meta-card--books">
|
||||
<i class="pi pi-book"></i>
|
||||
{{ books.length }} {{ books.length === 1 ? t('book') : t('books') }}
|
||||
</span>
|
||||
@if (yearsRange(); as years) {
|
||||
<span class="meta-card meta-card--years">
|
||||
<i class="pi pi-calendar"></i>
|
||||
{{ years }}
|
||||
</span>
|
||||
}
|
||||
@if (seriesStats(); as stats) {
|
||||
@if (stats.totalPages > 0) {
|
||||
<span class="meta-card meta-card--pages">
|
||||
<i class="pi pi-file"></i>
|
||||
{{ stats.totalPages | number }} {{ t('stats.totalPages') }}
|
||||
</span>
|
||||
}
|
||||
@if (stats.formatCounts.size > 0) {
|
||||
<span class="meta-card meta-card--format">
|
||||
<i class="pi pi-tag"></i>
|
||||
@for (entry of stats.formatCounts | keyvalue; track entry.key) {
|
||||
{{ entry.key }}{{ $last ? '' : ', ' }}
|
||||
}
|
||||
</span>
|
||||
}
|
||||
@if (stats.totalAudioDurationSeconds > 0) {
|
||||
<span class="meta-card meta-card--audio">
|
||||
<i class="pi pi-headphones"></i>
|
||||
{{ formatDuration(stats.totalAudioDurationSeconds) }}
|
||||
</span>
|
||||
}
|
||||
}
|
||||
@if (allLanguages(); as languages) {
|
||||
@if (languages.length) {
|
||||
<span class="meta-card meta-card--language">
|
||||
<i class="pi pi-globe"></i>
|
||||
{{ languages.join(', ') }}
|
||||
</span>
|
||||
}
|
||||
}
|
||||
@if (seriesCompletion(); as completion) {
|
||||
<span class="meta-card meta-card--owned">
|
||||
<i class="pi pi-check-circle"></i>
|
||||
{{ completion.owned }}/{{ completion.total }} {{ t('stats.owned') }}
|
||||
</span>
|
||||
}
|
||||
</div>
|
||||
|
||||
<!-- Ratings -->
|
||||
@if (seriesStats(); as stats) {
|
||||
@if (stats.avgPersonalRating != null || stats.avgGoodreads != null || stats.avgAmazon != null || stats.avgHardcover != null) {
|
||||
<div class="ratings-row">
|
||||
@if (stats.avgPersonalRating != null) {
|
||||
<div class="rating-chip">
|
||||
<i class="pi pi-star-fill rating-icon personal"></i>
|
||||
<span class="rating-value">{{ stats.avgPersonalRating | number:'1.1-1' }}/10</span>
|
||||
<span class="rating-label">{{ t('stats.avgPersonalRating') }}</span>
|
||||
</div>
|
||||
}
|
||||
@if (stats.avgGoodreads != null) {
|
||||
<div class="rating-chip">
|
||||
<i class="pi pi-star-fill rating-icon goodreads"></i>
|
||||
<span class="rating-value">{{ getRatingPercent(stats.avgGoodreads) }}%</span>
|
||||
<span class="rating-label">{{ t('stats.avgGoodreads') }}</span>
|
||||
</div>
|
||||
}
|
||||
@if (stats.avgAmazon != null) {
|
||||
<div class="rating-chip">
|
||||
<i class="pi pi-star-fill rating-icon amazon"></i>
|
||||
<span class="rating-value">{{ getRatingPercent(stats.avgAmazon) }}%</span>
|
||||
<span class="rating-label">{{ t('stats.avgAmazon') }}</span>
|
||||
</div>
|
||||
}
|
||||
@if (stats.avgHardcover != null) {
|
||||
<div class="rating-chip">
|
||||
<i class="pi pi-star-fill rating-icon hardcover"></i>
|
||||
<span class="rating-value">{{ getRatingPercent(stats.avgHardcover) }}%</span>
|
||||
<span class="rating-label">{{ t('stats.avgHardcover') }}</span>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
<!-- Next Up + Progress (pushed to bottom, aligned with cover) -->
|
||||
<div class="hero-status">
|
||||
@if (nextUp(); as nextUp) {
|
||||
<div class="next-up-card" (click)="readBook(nextUp.book.id)">
|
||||
<img [src]="nextUp.thumbnailUrl"
|
||||
[alt]="nextUp.book.metadata?.title || ''"
|
||||
class="next-up-thumb"
|
||||
loading="lazy"/>
|
||||
<div class="next-up-info">
|
||||
<span class="next-up-label">
|
||||
<i class="pi pi-bookmark-fill"></i>
|
||||
{{ nextUp.isReading ? t('continueReading') : t('nextUp') }}
|
||||
</span>
|
||||
<span class="next-up-title">{{ nextUp.book.metadata?.title || '' }}</span>
|
||||
@if (nextUp.isReading && nextUp.progressPercent != null) {
|
||||
<div class="next-up-progress-row">
|
||||
<p-progressBar
|
||||
[value]="nextUp.progressPercent"
|
||||
[showValue]="false"
|
||||
class="next-up-progress">
|
||||
</p-progressBar>
|
||||
<span class="next-up-percent">{{ nextUp.progressPercent }}%</span>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (readStatusBreakdown(); as segments) {
|
||||
@if (segments.length) {
|
||||
<div class="read-progress-card">
|
||||
<div class="read-progress-section">
|
||||
<div class="read-progress-bar">
|
||||
@for (seg of segments; track seg.status) {
|
||||
<div class="read-progress-segment"
|
||||
[ngStyle]="{'width': seg.percent + '%', 'background-color': getStatusColor(seg.status)}"
|
||||
[pTooltip]="getStatusLabel(seg.status) + ': ' + seg.count">
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
<div class="read-progress-legend">
|
||||
@for (seg of segments; track seg.status) {
|
||||
<span class="legend-item"
|
||||
[ngStyle]="{'border-color': getStatusColor(seg.status)}">
|
||||
<span class="legend-dot"
|
||||
[ngStyle]="{'background-color': getStatusColor(seg.status)}"></span>
|
||||
{{ getStatusLabel(seg.status) }} ({{ seg.count }})
|
||||
</span>
|
||||
}
|
||||
@let readProg = seriesReadProgress();
|
||||
@if (readProg) {
|
||||
<span class="read-percent-label">
|
||||
{{ t('readPercent', { progress: readProg }) }}
|
||||
</span>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="description-section">
|
||||
<div class="description-header">
|
||||
<i class="pi pi-align-left"></i>
|
||||
<span>{{ t('synopsis') }}</span>
|
||||
</div>
|
||||
<div class="description-body">
|
||||
<div #descriptionContent [ngClass]="{ 'line-clamp-7': !isExpanded }"
|
||||
class="description-content">
|
||||
<div class="description-html"
|
||||
[innerHTML]="firstDescription() || t('noDescription')"></div>
|
||||
</div>
|
||||
@if (isExpanded || isOverflowing) {
|
||||
<button class="expand-toggle" (click)="toggleExpand()">
|
||||
{{ isExpanded ? t('showLess') : t('showMore') }}
|
||||
<i class="pi" [ngClass]="isExpanded ? 'pi-chevron-up' : 'pi-chevron-down'"></i>
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h3 class="section-title">
|
||||
<i class="pi pi-objects-column"></i>
|
||||
{{ t('booksInSeries') }}
|
||||
</h3>
|
||||
<div class="series-items-grid" #Container
|
||||
[ngStyle]="{'grid-template-columns': 'repeat(auto-fill, minmax(' + gridColumnMinWidth + ', 1fr))'}">
|
||||
@for (book of books; track book; let i = $index) {
|
||||
<div class="grid-item"
|
||||
[ngStyle]="{width: currentCardSize.width + 'px', height: currentCardSize.height + 'px'}">
|
||||
<app-book-card
|
||||
[index]="i"
|
||||
[book]="book"
|
||||
[isCheckboxEnabled]="true"
|
||||
[isSelected]="selectedBooks.has(book.id)"
|
||||
(checkboxClick)="onCheckboxClicked($event)"
|
||||
[onBookSelect]="handleBookSelect.bind(this)"
|
||||
[isSeriesCollapsed]="false"
|
||||
[overlayPreferenceService]="bookCardOverlayPreferenceService">
|
||||
</app-book-card>
|
||||
</div>
|
||||
}
|
||||
@if (books.length === 0) {
|
||||
<div class="empty-state">{{ t('noBooksFound') }}</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
}
|
||||
|
||||
</p-tabpanel>
|
||||
|
||||
<!-- BOOK LIST TAB -->
|
||||
<p-tabpanel value="list">
|
||||
<div class="book-list-container">
|
||||
@for (book of books; track book.id; let i = $index) {
|
||||
<div class="book-list-card">
|
||||
<div class="list-number-col">
|
||||
<span class="list-series-number">
|
||||
{{ book.metadata?.seriesNumber != null ? '#' + book.metadata?.seriesNumber : '-' }}
|
||||
</span>
|
||||
</div>
|
||||
<img [src]="getBookThumbnailUrl(book)"
|
||||
[alt]="book.metadata?.title || ''"
|
||||
class="list-thumb"
|
||||
loading="lazy"/>
|
||||
<div class="list-book-info">
|
||||
<span class="list-book-title">{{ book.metadata?.title || '' }}</span>
|
||||
<div class="list-book-meta">
|
||||
@if (book.metadata?.authors?.length) {
|
||||
<span class="list-book-authors">{{ book.metadata!.authors!.join(', ') }}</span>
|
||||
}
|
||||
@if (book.metadata?.publishedDate; as date) {
|
||||
<span class="list-meta-dot">·</span>
|
||||
<span class="list-book-year">{{ date }}</span>
|
||||
}
|
||||
@if (book.metadata?.pageCount; as pages) {
|
||||
<span class="list-meta-dot">·</span>
|
||||
<span class="list-book-pages">{{ pages }} {{ t('listPages') }}</span>
|
||||
}
|
||||
</div>
|
||||
@if (getBookProgress(book); as progress) {
|
||||
<div class="list-progress-row">
|
||||
<div class="list-progress-bar">
|
||||
<div class="list-progress-fill" [ngStyle]="{'width': progress + '%'}"></div>
|
||||
</div>
|
||||
<span class="list-progress-text">{{ progress }}%</span>
|
||||
</div>
|
||||
}
|
||||
@if (book.personalRating) {
|
||||
<div class="list-rating-row">
|
||||
@for (star of [1,2,3,4,5]; track star) {
|
||||
<i class="pi list-star"
|
||||
[ngClass]="book.personalRating! >= star * 2 ? 'pi-star-fill' : (book.personalRating! >= star * 2 - 1 ? 'pi-star-half-fill' : 'pi-star')">
|
||||
</i>
|
||||
}
|
||||
<span class="list-rating-value">{{ book.personalRating }}/10</span>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
<div class="list-right-col">
|
||||
<div class="list-badges">
|
||||
<span class="list-status-badge"
|
||||
[ngStyle]="{'background-color': getStatusColor(book.readStatus)}">
|
||||
{{ getStatusLabel(book.readStatus) }}
|
||||
</span>
|
||||
@if (book.primaryFile?.bookType; as bookType) {
|
||||
<span class="list-format-badge"
|
||||
[style.background-color]="'color-mix(in srgb, var(--book-type-' + bookType.toLowerCase() + '-color) 20%, transparent)'"
|
||||
[style.border-color]="'var(--book-type-' + bookType.toLowerCase() + '-color)'"
|
||||
[style.color]="'var(--book-type-' + bookType.toLowerCase() + '-color)'">
|
||||
{{ bookType }}
|
||||
</span>
|
||||
}
|
||||
</div>
|
||||
<div class="list-actions">
|
||||
<button class="list-action-btn btn-read" (click)="readBook(book.id); $event.stopPropagation()"
|
||||
[pTooltip]="t('readButton')" tooltipPosition="top">
|
||||
<i class="pi pi-book"></i>
|
||||
</button>
|
||||
<button class="list-action-btn btn-details" (click)="viewBookDetails(book.id); $event.stopPropagation()"
|
||||
[pTooltip]="t('viewDetails')" tooltipPosition="top">
|
||||
<i class="pi pi-info-circle"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
@if (books.length === 0) {
|
||||
<div class="empty-state">{{ t('noBooksFound') }}</div>
|
||||
}
|
||||
</div>
|
||||
</p-tabpanel>
|
||||
|
||||
</p-tabpanels>
|
||||
</p-tabs>
|
||||
@if (selectedBooks.size > 0) {
|
||||
@if (currentUser(); as user) {
|
||||
<div class="book-browser-footer" [@slideInOut]>
|
||||
<div class="footer-content">
|
||||
<div class="footer-left">
|
||||
<div class="selected-count-badge">
|
||||
<i class="pi pi-check-circle badge-icon"></i>
|
||||
<span class="badge-count" style="color: var(--primary-color)">{{ selectedBooks.size }}</span>
|
||||
<span class="badge-label">{{ t('selected') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="footer-center">
|
||||
<div class="footer-action-group">
|
||||
@if (hasMetadataMenuItems) {
|
||||
<p-tieredMenu #menu [model]="metadataMenuItems" [popup]="true" appendTo="body"/>
|
||||
<p-button
|
||||
(click)="menu.toggle($event)"
|
||||
[pTooltip]="t('tooltip.metadataActions')"
|
||||
tooltipPosition="top"
|
||||
outlined="true"
|
||||
severity="info"
|
||||
icon="pi pi-database">
|
||||
</p-button>
|
||||
}
|
||||
<p-button
|
||||
icon="pi pi-bookmark-fill"
|
||||
outlined="true"
|
||||
severity="info"
|
||||
(onClick)="openShelfAssigner()"
|
||||
[pTooltip]="t('tooltip.assignToShelf')"
|
||||
tooltipPosition="top">
|
||||
</p-button>
|
||||
@if (user.permissions.canBulkLockUnlockMetadata) {
|
||||
<p-button
|
||||
outlined="true"
|
||||
icon="pi pi-lock"
|
||||
severity="info"
|
||||
(click)="lockUnlockMetadata()"
|
||||
[pTooltip]="t('tooltip.lockUnlockMetadata')"
|
||||
tooltipPosition="top">
|
||||
</p-button>
|
||||
}
|
||||
@if (user.permissions.canMoveOrganizeFiles && appSettings()?.diskType === 'LOCAL') {
|
||||
<p-button
|
||||
outlined="true"
|
||||
icon="pi pi-arrows-h"
|
||||
severity="info"
|
||||
(click)="moveFiles()"
|
||||
[pTooltip]="t('tooltip.organizeFiles')"
|
||||
tooltipPosition="top">
|
||||
</p-button>
|
||||
}
|
||||
@if (hasMoreActionsItems) {
|
||||
<div class="more-actions-wrapper">
|
||||
<p-button
|
||||
(click)="menu.toggle($event)"
|
||||
[pTooltip]="t('tooltip.moreActions')"
|
||||
tooltipPosition="top"
|
||||
outlined="true"
|
||||
severity="info"
|
||||
icon="pi pi-ellipsis-v">
|
||||
</p-button>
|
||||
<p-tieredMenu #menu [model]="moreActionsMenuItems" [popup]="true" appendTo="body"/>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
<p-divider layout="vertical"></p-divider>
|
||||
<div class="footer-action-group">
|
||||
<p-button
|
||||
outlined="true"
|
||||
icon="pi pi-check-square"
|
||||
severity="success"
|
||||
(click)="selectAllBooks()"
|
||||
[pTooltip]="t('tooltip.selectAll')"
|
||||
tooltipPosition="top">
|
||||
</p-button>
|
||||
<p-button
|
||||
outlined="true"
|
||||
icon="pi pi-times"
|
||||
severity="warn"
|
||||
(click)="deselectAllBooks()"
|
||||
[pTooltip]="t('tooltip.deselectAll')"
|
||||
tooltipPosition="top">
|
||||
</p-button>
|
||||
</div>
|
||||
@if (user.permissions.admin || user.permissions.canDeleteBook) {
|
||||
<p-divider layout="vertical"></p-divider>
|
||||
<p-button
|
||||
outlined="true"
|
||||
icon="pi pi-trash"
|
||||
severity="danger"
|
||||
(click)="confirmDeleteBooks()"
|
||||
[pTooltip]="t('tooltip.deleteSelected')"
|
||||
tooltipPosition="top">
|
||||
</p-button>
|
||||
}
|
||||
</div>
|
||||
<div class="footer-right"></div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</ng-container>
|
||||
@@ -0,0 +1,906 @@
|
||||
.tabpanels-responsive {
|
||||
height: calc(100dvh - 9.7rem);
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.tabpanels-responsive {
|
||||
height: calc(100dvh - 8.5rem);
|
||||
}
|
||||
}
|
||||
|
||||
.series-wrapper {
|
||||
position: relative;
|
||||
border-radius: 0.75rem;
|
||||
overflow: hidden;
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
}
|
||||
|
||||
.series-main {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex-grow: 1;
|
||||
}
|
||||
|
||||
.series-details {
|
||||
> * + * {
|
||||
margin-top: 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
// ── Hero ──
|
||||
|
||||
.series-hero {
|
||||
display: flex;
|
||||
gap: 1.5rem;
|
||||
padding: 0.5rem;
|
||||
align-items: stretch;
|
||||
|
||||
@media (max-width: 767px) {
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
|
||||
.hero-cover-section {
|
||||
flex-shrink: 0;
|
||||
|
||||
@media (max-width: 767px) {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
}
|
||||
|
||||
.hero-cover-img {
|
||||
width: 240px;
|
||||
height: 360px;
|
||||
object-fit: cover;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
|
||||
|
||||
@media (max-width: 767px) {
|
||||
width: 180px;
|
||||
height: 270px;
|
||||
}
|
||||
}
|
||||
|
||||
.hero-info {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.series-title {
|
||||
font-size: 1.5rem;
|
||||
font-weight: 800;
|
||||
line-height: 1.25;
|
||||
margin: 0;
|
||||
|
||||
@media (min-width: 768px) {
|
||||
font-size: 1.875rem;
|
||||
}
|
||||
}
|
||||
|
||||
.series-authors {
|
||||
font-size: 1rem;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.author-link {
|
||||
cursor: pointer;
|
||||
color: var(--primary-text-color);
|
||||
|
||||
&:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
}
|
||||
|
||||
// ── Metadata cards ──
|
||||
|
||||
.metadata-cards {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.4rem;
|
||||
margin-top: 0.5rem;
|
||||
|
||||
@media (max-width: 767px) {
|
||||
justify-content: center;
|
||||
}
|
||||
}
|
||||
|
||||
.meta-card {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.35rem;
|
||||
padding: 0.35rem 0.7rem;
|
||||
border-radius: 0.4rem;
|
||||
font-size: 0.85rem;
|
||||
font-weight: 600;
|
||||
border: 1px solid;
|
||||
white-space: nowrap;
|
||||
|
||||
i {
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
}
|
||||
|
||||
.meta-card--publisher {
|
||||
background: color-mix(in srgb, #3b82f6, transparent 85%);
|
||||
border-color: color-mix(in srgb, #3b82f6, transparent 60%);
|
||||
color: #93c5fd;
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
background: color-mix(in srgb, #3b82f6, transparent 75%);
|
||||
}
|
||||
|
||||
i { color: #60a5fa; }
|
||||
}
|
||||
|
||||
.meta-card--books {
|
||||
background: color-mix(in srgb, #8b5cf6, transparent 85%);
|
||||
border-color: color-mix(in srgb, #8b5cf6, transparent 60%);
|
||||
color: #c4b5fd;
|
||||
|
||||
i { color: #a78bfa; }
|
||||
}
|
||||
|
||||
.meta-card--years {
|
||||
background: color-mix(in srgb, #f59e0b, transparent 85%);
|
||||
border-color: color-mix(in srgb, #f59e0b, transparent 60%);
|
||||
color: #fcd34d;
|
||||
|
||||
i { color: #fbbf24; }
|
||||
}
|
||||
|
||||
.meta-card--pages {
|
||||
background: color-mix(in srgb, #10b981, transparent 85%);
|
||||
border-color: color-mix(in srgb, #10b981, transparent 60%);
|
||||
color: #6ee7b7;
|
||||
|
||||
i { color: #34d399; }
|
||||
}
|
||||
|
||||
.meta-card--format {
|
||||
background: color-mix(in srgb, #f43f5e, transparent 85%);
|
||||
border-color: color-mix(in srgb, #f43f5e, transparent 60%);
|
||||
color: #fda4af;
|
||||
|
||||
i { color: #fb7185; }
|
||||
}
|
||||
|
||||
.meta-card--audio {
|
||||
background: color-mix(in srgb, #06b6d4, transparent 85%);
|
||||
border-color: color-mix(in srgb, #06b6d4, transparent 60%);
|
||||
color: #67e8f9;
|
||||
|
||||
i { color: #22d3ee; }
|
||||
}
|
||||
|
||||
.meta-card--language {
|
||||
background: color-mix(in srgb, #ec4899, transparent 85%);
|
||||
border-color: color-mix(in srgb, #ec4899, transparent 60%);
|
||||
color: #f9a8d4;
|
||||
|
||||
i { color: #f472b6; }
|
||||
}
|
||||
|
||||
.meta-card--owned {
|
||||
background: color-mix(in srgb, #14b8a6, transparent 85%);
|
||||
border-color: color-mix(in srgb, #14b8a6, transparent 60%);
|
||||
color: #5eead4;
|
||||
|
||||
i { color: #2dd4bf; }
|
||||
}
|
||||
|
||||
.publisher-link {
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
// ── Ratings ──
|
||||
|
||||
.ratings-row {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.4rem;
|
||||
|
||||
@media (max-width: 767px) {
|
||||
justify-content: center;
|
||||
}
|
||||
}
|
||||
|
||||
.rating-chip {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.3rem;
|
||||
padding: 0.25rem 0.6rem;
|
||||
border-radius: 0.375rem;
|
||||
background: color-mix(in srgb, var(--p-surface-700), transparent 50%);
|
||||
border: 1px solid var(--border-color);
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
|
||||
.rating-icon {
|
||||
font-size: 0.75rem;
|
||||
|
||||
&.personal { color: #facc15; }
|
||||
&.goodreads { color: #8b5cf6; }
|
||||
&.amazon { color: #f97316; }
|
||||
&.hardcover { color: #06b6d4; }
|
||||
}
|
||||
|
||||
.rating-value {
|
||||
font-weight: 700;
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
.rating-label {
|
||||
color: var(--text-secondary-color);
|
||||
font-size: 0.7rem;
|
||||
}
|
||||
|
||||
// ── Categories ──
|
||||
|
||||
.categories-scroll {
|
||||
overflow-x: auto;
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.categories-list {
|
||||
display: flex;
|
||||
gap: 0.4rem;
|
||||
width: max-content;
|
||||
|
||||
@media (max-width: 767px) {
|
||||
margin: 0 auto;
|
||||
}
|
||||
}
|
||||
|
||||
.category-link {
|
||||
flex-shrink: 0;
|
||||
text-decoration: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
// ── Description (matches metadata-viewer) ──
|
||||
|
||||
.description-section {
|
||||
background: var(--card-background);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 0.75rem;
|
||||
overflow: hidden;
|
||||
margin: 0 0.5rem;
|
||||
transition: box-shadow 0.3s ease;
|
||||
|
||||
&:hover {
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
}
|
||||
|
||||
.description-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
padding: 0.625rem 0.875rem;
|
||||
background: var(--surface-ground);
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
border-radius: 0.75rem 0.75rem 0 0;
|
||||
font-weight: 600;
|
||||
font-size: 0.875rem;
|
||||
color: var(--text-color);
|
||||
|
||||
i {
|
||||
font-size: 0.95rem;
|
||||
color: var(--primary-color);
|
||||
}
|
||||
}
|
||||
|
||||
.description-body {
|
||||
padding: 0.875rem;
|
||||
}
|
||||
|
||||
.description-content {
|
||||
overflow: hidden;
|
||||
transition: max-height 0.3s ease-in-out;
|
||||
}
|
||||
|
||||
.description-content.line-clamp-7 {
|
||||
max-height: 37px;
|
||||
}
|
||||
|
||||
.description-content:not(.line-clamp-7) {
|
||||
max-height: none;
|
||||
}
|
||||
|
||||
.description-html {
|
||||
color: var(--text-color-secondary);
|
||||
line-height: 1.6;
|
||||
font-size: 0.9375rem;
|
||||
word-wrap: break-word;
|
||||
overflow-wrap: break-word;
|
||||
}
|
||||
|
||||
.expand-toggle {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.375rem;
|
||||
margin-top: 0.5rem;
|
||||
padding: 0.25rem 0.5rem;
|
||||
background: transparent;
|
||||
border: none;
|
||||
border-radius: 0.25rem;
|
||||
color: var(--primary-color);
|
||||
font-size: 0.8rem;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
transition: background 0.2s ease, color 0.2s ease;
|
||||
|
||||
&:hover {
|
||||
background: var(--surface-hover);
|
||||
color: var(--primary-hover-color);
|
||||
}
|
||||
|
||||
i {
|
||||
font-size: 0.7rem;
|
||||
}
|
||||
}
|
||||
|
||||
// ── Hero status (next up + progress, aligned to cover bottom) ──
|
||||
|
||||
.hero-status {
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
gap: 0.75rem;
|
||||
width: 100%;
|
||||
margin-top: auto;
|
||||
|
||||
@media (max-width: 767px) {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
margin-top: 0;
|
||||
}
|
||||
}
|
||||
|
||||
// ── Reading progress ──
|
||||
|
||||
.read-progress-card {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 0.75rem 1rem;
|
||||
border-radius: 0.5rem;
|
||||
background: color-mix(in srgb, var(--p-surface-700), transparent 50%);
|
||||
border: 1px solid var(--border-color);
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
|
||||
@media (min-width: 768px) {
|
||||
min-width: 16rem;
|
||||
max-width: 22rem;
|
||||
}
|
||||
}
|
||||
|
||||
.read-progress-section {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.read-progress-bar {
|
||||
display: flex;
|
||||
height: 0.625rem;
|
||||
border-radius: 0.375rem;
|
||||
overflow: hidden;
|
||||
background: color-mix(in srgb, var(--p-surface-600), transparent 50%);
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
.read-progress-segment {
|
||||
height: 100%;
|
||||
min-width: 4px;
|
||||
border-radius: 0.375rem;
|
||||
}
|
||||
|
||||
.read-progress-legend {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.4rem;
|
||||
margin-top: 0.5rem;
|
||||
font-size: 0.75rem;
|
||||
color: var(--text-color-secondary);
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.legend-item {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.25rem;
|
||||
padding: 0.1rem 0.4rem 0.1rem 0.3rem;
|
||||
border-radius: 9999px;
|
||||
border: 1px solid;
|
||||
font-size: 0.7rem;
|
||||
background: color-mix(in srgb, var(--p-surface-700), transparent 60%);
|
||||
}
|
||||
|
||||
.legend-dot {
|
||||
display: inline-block;
|
||||
width: 0.4rem;
|
||||
height: 0.4rem;
|
||||
border-radius: 50%;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.read-percent-label {
|
||||
margin-left: auto;
|
||||
font-weight: 600;
|
||||
font-size: 0.75rem;
|
||||
color: var(--text-secondary-color);
|
||||
}
|
||||
|
||||
// ── Next Up card ──
|
||||
|
||||
.next-up-card {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
padding: 0.6rem 0.85rem;
|
||||
border-radius: 0.5rem;
|
||||
background: color-mix(in srgb, var(--p-surface-700), transparent 50%);
|
||||
border: 1px solid var(--border-color);
|
||||
cursor: pointer;
|
||||
transition: background 0.15s ease, border-color 0.15s ease;
|
||||
flex-shrink: 0;
|
||||
|
||||
&:hover {
|
||||
background: color-mix(in srgb, var(--p-surface-700), transparent 30%);
|
||||
border-color: var(--primary-text-color);
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
min-width: 16rem;
|
||||
max-width: 22rem;
|
||||
}
|
||||
}
|
||||
|
||||
.next-up-thumb {
|
||||
width: 2.75rem;
|
||||
height: 4rem;
|
||||
object-fit: cover;
|
||||
border-radius: 0.25rem;
|
||||
flex-shrink: 0;
|
||||
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
|
||||
}
|
||||
|
||||
.next-up-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.2rem;
|
||||
min-width: 0;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.next-up-label {
|
||||
font-size: 0.65rem;
|
||||
font-weight: 700;
|
||||
color: var(--text-secondary-color);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.04em;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.25rem;
|
||||
|
||||
i {
|
||||
font-size: 0.6rem;
|
||||
color: var(--primary-text-color);
|
||||
}
|
||||
}
|
||||
|
||||
.next-up-title {
|
||||
font-weight: 600;
|
||||
font-size: 0.85rem;
|
||||
color: var(--text-color);
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.next-up-progress-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.4rem;
|
||||
margin-top: 0.15rem;
|
||||
}
|
||||
|
||||
.next-up-progress {
|
||||
flex: 1;
|
||||
height: 0.25rem;
|
||||
}
|
||||
|
||||
.next-up-percent {
|
||||
font-size: 0.7rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-secondary-color);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
// ── Section title ──
|
||||
|
||||
.section-title {
|
||||
font-size: 1.1rem;
|
||||
font-weight: 700;
|
||||
color: var(--text-color-secondary);
|
||||
margin: 0.75rem 0 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
padding: 0.75rem 0.5rem 0;
|
||||
border-top: 1px solid var(--border-color);
|
||||
|
||||
i {
|
||||
font-size: 1rem;
|
||||
color: var(--text-secondary-color);
|
||||
}
|
||||
}
|
||||
|
||||
// ── Book grid ──
|
||||
|
||||
.series-items-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(1px, 1fr));
|
||||
gap: 1rem;
|
||||
align-items: start;
|
||||
width: 100%;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
// ── Book list tab ──
|
||||
|
||||
.book-list-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
padding: 0.5rem;
|
||||
}
|
||||
|
||||
.book-list-card {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.85rem;
|
||||
padding: 0.65rem 0.85rem;
|
||||
cursor: pointer;
|
||||
border-radius: 0.5rem;
|
||||
background: color-mix(in srgb, var(--p-surface-700), transparent 65%);
|
||||
border: 1px solid color-mix(in srgb, var(--border-color), transparent 60%);
|
||||
transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
|
||||
|
||||
&:hover {
|
||||
background: color-mix(in srgb, var(--p-surface-700), transparent 40%);
|
||||
border-color: var(--border-color);
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
gap: 0.5rem;
|
||||
padding: 0.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
.list-number-col {
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 2rem;
|
||||
height: 2rem;
|
||||
border-radius: 0.375rem;
|
||||
background: color-mix(in srgb, var(--primary-color), transparent 85%);
|
||||
}
|
||||
|
||||
.list-series-number {
|
||||
font-weight: 700;
|
||||
font-size: 0.8rem;
|
||||
color: var(--primary-color);
|
||||
}
|
||||
|
||||
.list-thumb {
|
||||
width: 2.75rem;
|
||||
height: 4rem;
|
||||
object-fit: cover;
|
||||
border-radius: 0.375rem;
|
||||
flex-shrink: 0;
|
||||
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
.list-book-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.2rem;
|
||||
min-width: 0;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.list-book-title {
|
||||
font-weight: 600;
|
||||
font-size: 0.95rem;
|
||||
color: var(--text-color);
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.list-book-meta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.35rem;
|
||||
font-size: 0.85rem;
|
||||
color: var(--text-color-secondary);
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.list-meta-dot {
|
||||
color: var(--text-color-secondary);
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
.list-book-authors {
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
max-width: 16rem;
|
||||
}
|
||||
|
||||
.list-book-year,
|
||||
.list-book-pages {
|
||||
white-space: nowrap;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.list-right-col {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.list-badges {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.4rem;
|
||||
}
|
||||
|
||||
.list-status-badge {
|
||||
display: inline-block;
|
||||
padding: 0.25rem 0.6rem;
|
||||
border-radius: 9999px;
|
||||
font-size: 0.7rem;
|
||||
font-weight: 700;
|
||||
color: white;
|
||||
white-space: nowrap;
|
||||
letter-spacing: 0.02em;
|
||||
}
|
||||
|
||||
.list-format-badge {
|
||||
display: inline-block;
|
||||
padding: 0.2rem 0.5rem;
|
||||
border-radius: 0.25rem;
|
||||
font-size: 0.7rem;
|
||||
font-weight: 700;
|
||||
border: 1px solid;
|
||||
white-space: nowrap;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.03em;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
// ── List: progress bar ──
|
||||
|
||||
.list-progress-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.4rem;
|
||||
margin-top: 0.15rem;
|
||||
}
|
||||
|
||||
.list-progress-bar {
|
||||
width: 5rem;
|
||||
height: 0.25rem;
|
||||
border-radius: 0.25rem;
|
||||
background: color-mix(in srgb, var(--p-surface-600), transparent 50%);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.list-progress-fill {
|
||||
height: 100%;
|
||||
border-radius: 0.25rem;
|
||||
background: var(--primary-color);
|
||||
transition: width 0.3s ease;
|
||||
}
|
||||
|
||||
.list-progress-text {
|
||||
font-size: 0.65rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-color-secondary);
|
||||
}
|
||||
|
||||
// ── List: rating stars ──
|
||||
|
||||
.list-rating-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.1rem;
|
||||
margin-top: 0.1rem;
|
||||
}
|
||||
|
||||
.list-star {
|
||||
font-size: 0.65rem;
|
||||
color: #facc15;
|
||||
}
|
||||
|
||||
.list-rating-value {
|
||||
font-size: 0.65rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-color-secondary);
|
||||
margin-left: 0.25rem;
|
||||
}
|
||||
|
||||
// ── List: action buttons ──
|
||||
|
||||
.list-actions {
|
||||
display: flex;
|
||||
gap: 0.35rem;
|
||||
}
|
||||
|
||||
.list-action-btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 2.1rem;
|
||||
height: 2.1rem;
|
||||
border-radius: 0.4rem;
|
||||
border: 1px solid;
|
||||
cursor: pointer;
|
||||
transition: all 0.15s ease;
|
||||
|
||||
i {
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
|
||||
&.btn-read {
|
||||
background: color-mix(in srgb, #10b981, transparent 85%);
|
||||
border-color: color-mix(in srgb, #10b981, transparent 55%);
|
||||
color: #6ee7b7;
|
||||
|
||||
&:hover {
|
||||
background: color-mix(in srgb, #10b981, transparent 65%);
|
||||
}
|
||||
}
|
||||
|
||||
&.btn-details {
|
||||
background: color-mix(in srgb, #3b82f6, transparent 85%);
|
||||
border-color: color-mix(in srgb, #3b82f6, transparent 55%);
|
||||
color: #93c5fd;
|
||||
|
||||
&:hover {
|
||||
background: color-mix(in srgb, #3b82f6, transparent 65%);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
text-align: center;
|
||||
padding: 2rem;
|
||||
color: var(--text-secondary-color);
|
||||
}
|
||||
|
||||
// ── Loading ──
|
||||
|
||||
.loading-state {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100%;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
// ── Footer ──
|
||||
|
||||
.book-browser-footer {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 10%;
|
||||
right: 10%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 1rem 0.5rem 0.5rem;
|
||||
z-index: 100;
|
||||
border-radius: 10px 10px 0 0;
|
||||
border: 1px solid rgba(255, 255, 255, 0.5);
|
||||
border-width: 1px 1px 0px 1px;
|
||||
background-color: var(--card-background);
|
||||
|
||||
> .footer-content {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
left: 0;
|
||||
right: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.footer-content {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.footer-left {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding-left: 0.5rem;
|
||||
width: 25%;
|
||||
}
|
||||
|
||||
.footer-center {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
width: 50%;
|
||||
}
|
||||
|
||||
.footer-right {
|
||||
width: 25%;
|
||||
}
|
||||
|
||||
.footer-action-group {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
|
||||
@media (min-width: 768px) {
|
||||
gap: 1.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
.more-actions-wrapper {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.selected-count-badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
padding: 0.5rem 1rem;
|
||||
font-size: 0.9rem;
|
||||
color: var(--text-color);
|
||||
|
||||
i {
|
||||
font-size: 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
.badge-icon {
|
||||
margin-right: 0.5rem;
|
||||
}
|
||||
|
||||
.badge-count {
|
||||
font-weight: 700;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.badge-label {
|
||||
margin-left: 0.25rem;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.selected-count-badge {
|
||||
padding: 0.4rem 0.8rem;
|
||||
font-size: 0.85rem;
|
||||
|
||||
i {
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,750 @@
|
||||
import {FormsModule} from "@angular/forms";
|
||||
import {Button} from "primeng/button";
|
||||
import {ActivatedRoute, Router} from "@angular/router";
|
||||
import {toSignal} from '@angular/core/rxjs-interop';
|
||||
import {DecimalPipe, KeyValuePipe, NgClass, NgStyle} from "@angular/common";
|
||||
import {finalize, map} from "rxjs/operators";
|
||||
import {Book, BookType, computeSeriesReadStatus, ReadStatus} from "../../model/book.model";
|
||||
import {BookService} from "../../service/book.service";
|
||||
import {BookMetadataManageService} from "../../service/book-metadata-manage.service";
|
||||
import {BookCardComponent} from "../book-browser/book-card/book-card.component";
|
||||
import {CoverScalePreferenceService} from "../book-browser/cover-scale-preference.service";
|
||||
import {Tab, TabList, TabPanel, TabPanels, Tabs} from "primeng/tabs";
|
||||
import {VirtualScrollerModule} from "@iharbeck/ngx-virtual-scroller";
|
||||
import {ProgressSpinner} from "primeng/progressspinner";
|
||||
import {ProgressBar} from "primeng/progressbar";
|
||||
import {DynamicDialogRef} from "primeng/dynamicdialog";
|
||||
import {ConfirmationService, MenuItem, MessageService} from "primeng/api";
|
||||
import {UserService} from "../../../settings/user-management/user.service";
|
||||
import {BookMenuService} from "../../service/book-menu.service";
|
||||
import {LoadingService} from "../../../../core/services/loading.service";
|
||||
import {BookDialogHelperService} from "../book-browser/book-dialog-helper.service";
|
||||
import {TaskHelperService} from "../../../settings/task-management/task-helper.service";
|
||||
import {MetadataRefreshType} from "../../../metadata/model/request/metadata-refresh-type.enum";
|
||||
import {TieredMenu} from "primeng/tieredmenu";
|
||||
import {AppSettingsService} from "../../../../shared/service/app-settings.service";
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
import {Tooltip} from "primeng/tooltip";
|
||||
import {Divider} from "primeng/divider";
|
||||
import {TagComponent} from "../../../../shared/components/tag/tag.component";
|
||||
import {animate, style, transition, trigger} from "@angular/animations";
|
||||
import {AfterViewChecked, Component, computed, effect, ElementRef, inject, ViewChild} from '@angular/core';
|
||||
import {BookCardOverlayPreferenceService} from '../book-browser/book-card-overlay-preference.service';
|
||||
import {UrlHelperService} from '../../../../shared/service/url-helper.service';
|
||||
import {injectQuery} from '@tanstack/angular-query-experimental';
|
||||
|
||||
interface ReadStatusSegment {
|
||||
status: ReadStatus;
|
||||
count: number;
|
||||
percent: number;
|
||||
}
|
||||
|
||||
interface SeriesCompletion {
|
||||
owned: number;
|
||||
total: number;
|
||||
percent: number;
|
||||
missingNumbers: number[];
|
||||
}
|
||||
|
||||
interface NextUpBook {
|
||||
book: Book;
|
||||
thumbnailUrl: string;
|
||||
isReading: boolean;
|
||||
progressPercent: number | null;
|
||||
}
|
||||
|
||||
interface SeriesStats {
|
||||
totalPages: number;
|
||||
avgPersonalRating: number | null;
|
||||
avgGoodreads: number | null;
|
||||
avgAmazon: number | null;
|
||||
avgHardcover: number | null;
|
||||
formatCounts: Map<BookType, number>;
|
||||
totalAudioDurationSeconds: number;
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: "app-series-page",
|
||||
standalone: true,
|
||||
templateUrl: "./series-page.component.html",
|
||||
styleUrls: ["./series-page.component.scss"],
|
||||
imports: [
|
||||
DecimalPipe,
|
||||
KeyValuePipe,
|
||||
Button,
|
||||
FormsModule,
|
||||
NgStyle,
|
||||
NgClass,
|
||||
BookCardComponent,
|
||||
ProgressSpinner,
|
||||
ProgressBar,
|
||||
Tabs,
|
||||
TabList,
|
||||
Tab,
|
||||
TabPanels,
|
||||
TabPanel,
|
||||
VirtualScrollerModule,
|
||||
TieredMenu,
|
||||
Tooltip,
|
||||
Divider,
|
||||
TranslocoDirective,
|
||||
TagComponent
|
||||
],
|
||||
animations: [
|
||||
trigger('slideInOut', [
|
||||
transition(':enter', [
|
||||
style({transform: 'translateY(100%)'}),
|
||||
animate('0.1s ease-in', style({transform: 'translateY(0)'}))
|
||||
]),
|
||||
transition(':leave', [
|
||||
style({transform: 'translateY(0)'}),
|
||||
animate('0.1s ease-out', style({transform: 'translateY(100%)'}))
|
||||
])
|
||||
])
|
||||
]
|
||||
})
|
||||
export class SeriesPageComponent implements AfterViewChecked {
|
||||
|
||||
private route = inject(ActivatedRoute);
|
||||
private bookService = inject(BookService);
|
||||
private bookMetadataManageService = inject(BookMetadataManageService);
|
||||
protected coverScalePreferenceService = inject(CoverScalePreferenceService);
|
||||
private metadataCenterViewMode: "route" | "dialog" = "route";
|
||||
private dialogRef?: DynamicDialogRef | null;
|
||||
private router = inject(Router);
|
||||
protected userService = inject(UserService);
|
||||
private bookMenuService = inject(BookMenuService);
|
||||
protected confirmationService = inject(ConfirmationService);
|
||||
private loadingService = inject(LoadingService);
|
||||
private dialogHelperService = inject(BookDialogHelperService);
|
||||
protected taskHelperService = inject(TaskHelperService);
|
||||
private messageService = inject(MessageService);
|
||||
protected bookCardOverlayPreferenceService = inject(BookCardOverlayPreferenceService);
|
||||
protected appSettingsService = inject(AppSettingsService);
|
||||
private readonly t = inject(TranslocoService);
|
||||
protected urlHelper = inject(UrlHelperService);
|
||||
|
||||
@ViewChild('descriptionContent') descriptionContentRef?: ElementRef<HTMLElement>;
|
||||
tab: string = "view";
|
||||
isExpanded = false;
|
||||
isOverflowing = false;
|
||||
protected appSettings = this.appSettingsService.appSettings;
|
||||
protected currentUser = this.userService.currentUser;
|
||||
protected isBooksLoading = this.bookService.isBooksLoading;
|
||||
|
||||
// Selection state
|
||||
selectedBooks = new Set<number>();
|
||||
lastSelectedIndex: number | null = null;
|
||||
|
||||
// Menu items
|
||||
protected metadataMenuItems: MenuItem[] | undefined;
|
||||
protected moreActionsMenuItems: MenuItem[] | undefined;
|
||||
|
||||
private seriesParam = toSignal(this.route.paramMap.pipe(
|
||||
map((params) => params.get("seriesName") || ""),
|
||||
map((name) => decodeURIComponent(name))
|
||||
), {initialValue: ""});
|
||||
|
||||
filteredBooks = computed(() => {
|
||||
const seriesName = this.seriesParam().trim().toLowerCase();
|
||||
const inSeries = this.bookService.books().filter(
|
||||
(book) => book.metadata?.seriesName?.trim().toLowerCase() === seriesName
|
||||
);
|
||||
|
||||
return [...inSeries].sort((a, b) => {
|
||||
const aNum = a.metadata?.seriesNumber ?? Number.MAX_SAFE_INTEGER;
|
||||
const bNum = b.metadata?.seriesNumber ?? Number.MAX_SAFE_INTEGER;
|
||||
return aNum - bNum;
|
||||
});
|
||||
});
|
||||
|
||||
coverBook = computed(() => this.filteredBooks()[0] ?? null);
|
||||
private firstBookId = computed(() => this.coverBook()?.id ?? null);
|
||||
private firstBookDetailQuery = injectQuery(() => ({
|
||||
...this.bookService.bookDetailQueryOptions(this.firstBookId() ?? -1, true),
|
||||
enabled: this.firstBookId() != null,
|
||||
}));
|
||||
|
||||
seriesTitle = computed(() => this.filteredBooks()[0]?.metadata?.seriesName || this.seriesParam());
|
||||
|
||||
yearsRange = computed(() => {
|
||||
const years = this.filteredBooks()
|
||||
.map((book) => book.metadata?.publishedDate)
|
||||
.filter((date): date is string => !!date)
|
||||
.map((date) => {
|
||||
const match = date.match(/\d{4}/);
|
||||
return match ? parseInt(match[0], 10) : null;
|
||||
})
|
||||
.filter((year): year is number => year !== null);
|
||||
|
||||
if (years.length === 0) return null;
|
||||
const min = Math.min(...years);
|
||||
const max = Math.max(...years);
|
||||
return min === max ? String(min) : `${min}-${max}`;
|
||||
});
|
||||
|
||||
firstBookWithDesc = computed(() => this.firstBookDetailQuery.data() ?? null);
|
||||
firstDescription = computed(() => this.firstBookWithDesc()?.metadata?.description || "");
|
||||
|
||||
seriesReadStatus = computed(() => computeSeriesReadStatus(this.filteredBooks()));
|
||||
|
||||
seriesReadProgress = computed(() => {
|
||||
const books = this.filteredBooks();
|
||||
const readCount = books.filter((book) => book.readStatus === ReadStatus.READ).length;
|
||||
return `${readCount}/${books.length}`;
|
||||
});
|
||||
|
||||
allAuthors = computed(() => {
|
||||
const authors = new Set<string>();
|
||||
for (const book of this.filteredBooks()) {
|
||||
book.metadata?.authors?.forEach((author) => authors.add(author));
|
||||
}
|
||||
return Array.from(authors);
|
||||
});
|
||||
|
||||
allCategories = computed(() => {
|
||||
const categories = new Set<string>();
|
||||
for (const book of this.filteredBooks()) {
|
||||
book.metadata?.categories?.forEach((category) => categories.add(category));
|
||||
}
|
||||
return Array.from(categories);
|
||||
});
|
||||
|
||||
allPublishers = computed(() => {
|
||||
const publishers = new Set<string>();
|
||||
for (const book of this.filteredBooks()) {
|
||||
if (book.metadata?.publisher) {
|
||||
publishers.add(book.metadata.publisher);
|
||||
}
|
||||
}
|
||||
return Array.from(publishers);
|
||||
});
|
||||
|
||||
allLanguages = computed(() => {
|
||||
const languages = new Set<string>();
|
||||
for (const book of this.filteredBooks()) {
|
||||
if (book.metadata?.language) {
|
||||
languages.add(book.metadata.language);
|
||||
}
|
||||
}
|
||||
return Array.from(languages);
|
||||
});
|
||||
|
||||
seriesCompletion = computed<SeriesCompletion | null>(() => {
|
||||
const totals = this.filteredBooks()
|
||||
.map((book) => book.metadata?.seriesTotal)
|
||||
.filter((total): total is number => total != null && total > 0);
|
||||
if (totals.length === 0) return null;
|
||||
|
||||
const seriesTotal = Math.max(...totals);
|
||||
const ownedNumbers = new Set(
|
||||
this.filteredBooks()
|
||||
.map((book) => book.metadata?.seriesNumber)
|
||||
.filter((number): number is number => number != null)
|
||||
);
|
||||
|
||||
const missingNumbers: number[] = [];
|
||||
for (let i = 1; i <= seriesTotal; i++) {
|
||||
if (!ownedNumbers.has(i)) missingNumbers.push(i);
|
||||
}
|
||||
|
||||
const owned = ownedNumbers.size;
|
||||
return {
|
||||
owned,
|
||||
total: seriesTotal,
|
||||
percent: seriesTotal > 0 ? Math.round((owned / seriesTotal) * 100) : 0,
|
||||
missingNumbers
|
||||
};
|
||||
});
|
||||
|
||||
readStatusBreakdown = computed(() => {
|
||||
const books = this.filteredBooks();
|
||||
if (books.length === 0) return [];
|
||||
|
||||
const counts = new Map<ReadStatus, number>();
|
||||
for (const book of books) {
|
||||
const status = (book.readStatus as ReadStatus) ?? ReadStatus.UNREAD;
|
||||
counts.set(status, (counts.get(status) || 0) + 1);
|
||||
}
|
||||
|
||||
const total = books.length;
|
||||
const segments: ReadStatusSegment[] = [];
|
||||
for (const [status, count] of counts) {
|
||||
segments.push({status, count, percent: (count / total) * 100});
|
||||
}
|
||||
return segments;
|
||||
});
|
||||
|
||||
nextUp = computed<NextUpBook | null>(() => {
|
||||
const books = this.filteredBooks();
|
||||
const reading = books.find(book =>
|
||||
book.readStatus === ReadStatus.READING ||
|
||||
book.readStatus === ReadStatus.RE_READING ||
|
||||
book.readStatus === ReadStatus.PAUSED
|
||||
);
|
||||
const target = reading || books.find(book => book.readStatus === ReadStatus.UNREAD || !book.readStatus);
|
||||
if (!target) return null;
|
||||
|
||||
const isAudiobook = target.primaryFile?.bookType === 'AUDIOBOOK';
|
||||
const thumbnailUrl = isAudiobook
|
||||
? this.urlHelper.getAudiobookThumbnailUrl(target.id, target.metadata?.audiobookCoverUpdatedOn)
|
||||
: this.urlHelper.getThumbnailUrl(target.id, target.metadata?.coverUpdatedOn);
|
||||
|
||||
const isReading = target.readStatus === ReadStatus.READING ||
|
||||
target.readStatus === ReadStatus.RE_READING ||
|
||||
target.readStatus === ReadStatus.PAUSED;
|
||||
|
||||
let progressPercent: number | null = null;
|
||||
if (isReading) {
|
||||
progressPercent = target.epubProgress?.percentage
|
||||
?? target.pdfProgress?.percentage
|
||||
?? target.cbxProgress?.percentage
|
||||
?? target.audiobookProgress?.percentage
|
||||
?? target.koreaderProgress?.percentage
|
||||
?? target.koboProgress?.percentage
|
||||
?? null;
|
||||
if (progressPercent != null) {
|
||||
progressPercent = Math.round(progressPercent);
|
||||
}
|
||||
}
|
||||
|
||||
return {book: target, thumbnailUrl, isReading, progressPercent};
|
||||
});
|
||||
|
||||
seriesStats = computed<SeriesStats>(() => {
|
||||
let totalPages = 0;
|
||||
const personalRatings: number[] = [];
|
||||
const goodreadsRatings: number[] = [];
|
||||
const amazonRatings: number[] = [];
|
||||
const hardcoverRatings: number[] = [];
|
||||
const formatCounts = new Map<BookType, number>();
|
||||
let totalAudioDurationSeconds = 0;
|
||||
|
||||
for (const book of this.filteredBooks()) {
|
||||
if (book.metadata?.pageCount) totalPages += book.metadata.pageCount;
|
||||
if (book.personalRating != null) personalRatings.push(book.personalRating);
|
||||
if (book.metadata?.goodreadsRating != null) goodreadsRatings.push(book.metadata.goodreadsRating);
|
||||
if (book.metadata?.amazonRating != null) amazonRatings.push(book.metadata.amazonRating);
|
||||
if (book.metadata?.hardcoverRating != null) hardcoverRatings.push(book.metadata.hardcoverRating);
|
||||
|
||||
const bookType = book.primaryFile?.bookType;
|
||||
if (bookType) {
|
||||
formatCounts.set(bookType, (formatCounts.get(bookType) || 0) + 1);
|
||||
}
|
||||
|
||||
if (book.metadata?.audiobookMetadata?.durationSeconds) {
|
||||
totalAudioDurationSeconds += book.metadata.audiobookMetadata.durationSeconds;
|
||||
}
|
||||
}
|
||||
|
||||
const avg = (ratings: number[]) => ratings.length > 0
|
||||
? ratings.reduce((total, rating) => total + rating, 0) / ratings.length
|
||||
: null;
|
||||
|
||||
return {
|
||||
totalPages,
|
||||
avgPersonalRating: avg(personalRatings),
|
||||
avgGoodreads: avg(goodreadsRatings),
|
||||
avgAmazon: avg(amazonRatings),
|
||||
avgHardcover: avg(hardcoverRatings),
|
||||
formatCounts,
|
||||
totalAudioDurationSeconds
|
||||
};
|
||||
});
|
||||
|
||||
constructor() {
|
||||
effect(() => {
|
||||
const user = this.currentUser();
|
||||
if (!user) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.metadataMenuItems = this.bookMenuService.getMetadataMenuItems(
|
||||
() => this.autoFetchMetadata(),
|
||||
() => this.fetchMetadata(),
|
||||
() => this.bulkEditMetadata(),
|
||||
() => this.multiBookEditMetadata(),
|
||||
() => this.regenerateCoversForSelected(),
|
||||
() => this.generateCustomCoversForSelected(),
|
||||
user
|
||||
);
|
||||
this.moreActionsMenuItems = this.bookMenuService.getMoreActionsMenu(this.selectedBooks, this.currentUser());
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
get currentCardSize() {
|
||||
return this.coverScalePreferenceService.currentCardSize();
|
||||
}
|
||||
|
||||
get gridColumnMinWidth(): string {
|
||||
return this.coverScalePreferenceService.gridColumnMinWidth();
|
||||
}
|
||||
|
||||
goToAuthorBooks(author: string): void {
|
||||
this.handleMetadataClick("author", author);
|
||||
}
|
||||
|
||||
goToCategory(category: string): void {
|
||||
this.handleMetadataClick("category", category);
|
||||
}
|
||||
|
||||
goToPublisher(publisher: string): void {
|
||||
this.handleMetadataClick("publisher", publisher);
|
||||
}
|
||||
|
||||
private navigateToFilteredBooks(
|
||||
filterKey: string,
|
||||
filterValue: string
|
||||
): void {
|
||||
this.router.navigate(["/all-books"], {
|
||||
queryParams: {
|
||||
view: "grid",
|
||||
sort: "title",
|
||||
direction: "asc",
|
||||
sidebar: true,
|
||||
filter: `${filterKey}:${encodeURIComponent(filterValue)}`,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
private handleMetadataClick(filterKey: string, filterValue: string): void {
|
||||
if (this.metadataCenterViewMode === "dialog") {
|
||||
this.dialogRef?.close();
|
||||
setTimeout(
|
||||
() => this.navigateToFilteredBooks(filterKey, filterValue),
|
||||
200
|
||||
);
|
||||
} else {
|
||||
this.navigateToFilteredBooks(filterKey, filterValue);
|
||||
}
|
||||
}
|
||||
|
||||
ngAfterViewChecked(): void {
|
||||
if (!this.isExpanded && this.descriptionContentRef) {
|
||||
const el = this.descriptionContentRef.nativeElement;
|
||||
this.isOverflowing = el.scrollHeight > el.clientHeight;
|
||||
}
|
||||
}
|
||||
|
||||
toggleExpand(): void {
|
||||
this.isExpanded = !this.isExpanded;
|
||||
}
|
||||
|
||||
getStatusLabel(value: string | ReadStatus | null | undefined): string {
|
||||
const v = (value ?? '').toString().toUpperCase();
|
||||
switch (v) {
|
||||
case ReadStatus.UNREAD:
|
||||
return this.t.translate('book.seriesPage.status.unread');
|
||||
case ReadStatus.READING:
|
||||
return this.t.translate('book.seriesPage.status.reading');
|
||||
case ReadStatus.RE_READING:
|
||||
return this.t.translate('book.seriesPage.status.reReading');
|
||||
case ReadStatus.READ:
|
||||
return this.t.translate('book.seriesPage.status.read');
|
||||
case ReadStatus.PARTIALLY_READ:
|
||||
return this.t.translate('book.seriesPage.status.partiallyRead');
|
||||
case ReadStatus.PAUSED:
|
||||
return this.t.translate('book.seriesPage.status.paused');
|
||||
case ReadStatus.ABANDONED:
|
||||
return this.t.translate('book.seriesPage.status.abandoned');
|
||||
case ReadStatus.WONT_READ:
|
||||
return this.t.translate('book.seriesPage.status.wontRead');
|
||||
default:
|
||||
return this.t.translate('book.seriesPage.status.unset');
|
||||
}
|
||||
}
|
||||
|
||||
getStatusColor(status: string | ReadStatus | null | undefined): string {
|
||||
const normalized = (status ?? '').toString().toUpperCase();
|
||||
switch (normalized) {
|
||||
case "UNREAD":
|
||||
return "#6b7280";
|
||||
case "READING":
|
||||
return "#2563eb";
|
||||
case "READ":
|
||||
return "#16a34a";
|
||||
case "PARTIALLY_READ":
|
||||
return "#ca8a04";
|
||||
case "PAUSED":
|
||||
return "#475569";
|
||||
case "RE-READING":
|
||||
case "RE_READING":
|
||||
return "#9333ea";
|
||||
case "ABANDONED":
|
||||
return "#dc2626";
|
||||
case "WONT_READ":
|
||||
return "#be185d";
|
||||
default:
|
||||
return "#4b5563";
|
||||
}
|
||||
}
|
||||
|
||||
getBookThumbnailUrl(book: Book): string {
|
||||
const isAudiobook = book.primaryFile?.bookType === 'AUDIOBOOK';
|
||||
return isAudiobook
|
||||
? this.urlHelper.getAudiobookThumbnailUrl(book.id, book.metadata?.audiobookCoverUpdatedOn)
|
||||
: this.urlHelper.getThumbnailUrl(book.id, book.metadata?.coverUpdatedOn);
|
||||
}
|
||||
|
||||
readBook(bookId: number): void {
|
||||
this.bookService.readBook(bookId);
|
||||
}
|
||||
|
||||
viewBookDetails(bookId: number): void {
|
||||
this.router.navigate(['/book', bookId], {
|
||||
queryParams: {tab: 'view'}
|
||||
});
|
||||
}
|
||||
|
||||
getBookProgress(book: Book): number | null {
|
||||
const progress = book.epubProgress?.percentage
|
||||
?? book.pdfProgress?.percentage
|
||||
?? book.cbxProgress?.percentage
|
||||
?? book.audiobookProgress?.percentage
|
||||
?? book.koreaderProgress?.percentage
|
||||
?? book.koboProgress?.percentage;
|
||||
if (progress == null || progress <= 0) return null;
|
||||
const pct = progress > 1 ? progress : Math.round(progress * 100);
|
||||
return Math.min(Math.round(pct), 100);
|
||||
}
|
||||
|
||||
formatDuration(totalSeconds: number): string {
|
||||
if (!totalSeconds || !isFinite(totalSeconds)) return '0:00';
|
||||
const h = Math.floor(totalSeconds / 3600);
|
||||
const m = Math.floor((totalSeconds % 3600) / 60);
|
||||
if (h > 0) {
|
||||
return `${h}h ${m}m`;
|
||||
}
|
||||
return `${m}m`;
|
||||
}
|
||||
|
||||
getRatingPercent(rating: number | null | undefined): number {
|
||||
if (rating == null) return 0;
|
||||
return Math.round((rating / 5) * 100);
|
||||
}
|
||||
|
||||
handleBookSelection(book: Book, selected: boolean) {
|
||||
if (selected) {
|
||||
if (book.seriesBooks) {
|
||||
this.selectedBooks = new Set([...this.selectedBooks, ...book.seriesBooks.map(book => book.id)]);
|
||||
} else {
|
||||
this.selectedBooks.add(book.id);
|
||||
}
|
||||
} else {
|
||||
if (book.seriesBooks) {
|
||||
book.seriesBooks.forEach(book => {
|
||||
this.selectedBooks.delete(book.id);
|
||||
});
|
||||
} else {
|
||||
this.selectedBooks.delete(book.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onCheckboxClicked(event: { index: number; book: Book; selected: boolean; shiftKey: boolean }) {
|
||||
const {index, book, selected, shiftKey} = event;
|
||||
if (!shiftKey || this.lastSelectedIndex === null) {
|
||||
this.handleBookSelection(book, selected);
|
||||
this.lastSelectedIndex = index;
|
||||
} else {
|
||||
const start = Math.min(this.lastSelectedIndex, index);
|
||||
const end = Math.max(this.lastSelectedIndex, index);
|
||||
const isUnselectingRange = !selected;
|
||||
const books = this.filteredBooks();
|
||||
for (let i = start; i <= end; i++) {
|
||||
const book = books[i];
|
||||
if (!book) continue;
|
||||
this.handleBookSelection(book, !isUnselectingRange);
|
||||
}
|
||||
}
|
||||
this.moreActionsMenuItems = this.bookMenuService.getMoreActionsMenu(this.selectedBooks, this.user());
|
||||
}
|
||||
|
||||
handleBookSelect(book: Book, selected: boolean): void {
|
||||
this.handleBookSelection(book, selected);
|
||||
this.moreActionsMenuItems = this.bookMenuService.getMoreActionsMenu(this.selectedBooks, this.user());
|
||||
}
|
||||
|
||||
selectAllBooks(): void {
|
||||
for (const book of this.filteredBooks()) {
|
||||
this.selectedBooks.add(book.id);
|
||||
}
|
||||
this.moreActionsMenuItems = this.bookMenuService.getMoreActionsMenu(this.selectedBooks, this.user());
|
||||
}
|
||||
|
||||
deselectAllBooks(): void {
|
||||
this.selectedBooks.clear();
|
||||
this.moreActionsMenuItems = this.bookMenuService.getMoreActionsMenu(this.selectedBooks, this.user());
|
||||
}
|
||||
|
||||
confirmDeleteBooks(): void {
|
||||
this.confirmationService.confirm({
|
||||
message: this.t.translate('book.browser.confirm.deleteMessage', {count: this.selectedBooks.size}),
|
||||
header: this.t.translate('book.browser.confirm.deleteHeader'),
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
acceptIcon: 'pi pi-trash',
|
||||
rejectIcon: 'pi pi-times',
|
||||
acceptLabel: this.t.translate('common.delete'),
|
||||
rejectLabel: this.t.translate('common.cancel'),
|
||||
acceptButtonStyleClass: 'p-button-danger',
|
||||
rejectButtonStyleClass: 'p-button-outlined',
|
||||
accept: () => {
|
||||
const count = this.selectedBooks.size;
|
||||
const loader = this.loadingService.show(this.t.translate('book.browser.loading.deleting', {count}));
|
||||
|
||||
this.bookService.deleteBooks(this.selectedBooks)
|
||||
.pipe(finalize(() => this.loadingService.hide(loader)))
|
||||
.subscribe(() => {
|
||||
this.selectedBooks.clear();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
openShelfAssigner(): void {
|
||||
this.dialogRef = this.dialogHelperService.openShelfAssignerDialog(null, this.selectedBooks);
|
||||
if (this.dialogRef) {
|
||||
this.dialogRef.onClose.subscribe(result => {
|
||||
if (result.assigned) {
|
||||
this.selectedBooks.clear();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
lockUnlockMetadata(): void {
|
||||
this.dialogRef = this.dialogHelperService.openLockUnlockMetadataDialog(this.selectedBooks);
|
||||
if (this.dialogRef) {
|
||||
this.dialogRef.onClose.subscribe(() => {
|
||||
this.deselectAllBooks();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
autoFetchMetadata(): void {
|
||||
if (!this.selectedBooks || this.selectedBooks.size === 0) return;
|
||||
this.taskHelperService.refreshMetadataTask({
|
||||
refreshType: MetadataRefreshType.BOOKS,
|
||||
bookIds: Array.from(this.selectedBooks),
|
||||
}).subscribe();
|
||||
}
|
||||
|
||||
fetchMetadata(): void {
|
||||
this.dialogHelperService.openMetadataRefreshDialog(this.selectedBooks);
|
||||
}
|
||||
|
||||
bulkEditMetadata(): void {
|
||||
this.dialogRef = this.dialogHelperService.openBulkMetadataEditDialog(this.selectedBooks);
|
||||
if (this.dialogRef) {
|
||||
this.dialogRef.onClose.subscribe(() => {
|
||||
this.deselectAllBooks();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
multiBookEditMetadata(): void {
|
||||
this.dialogRef = this.dialogHelperService.openMultibookMetadataEditorDialog(this.selectedBooks);
|
||||
if (this.dialogRef) {
|
||||
this.dialogRef.onClose.subscribe(() => {
|
||||
this.deselectAllBooks();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
regenerateCoversForSelected(): void {
|
||||
if (!this.selectedBooks || this.selectedBooks.size === 0) return;
|
||||
const count = this.selectedBooks.size;
|
||||
this.confirmationService.confirm({
|
||||
message: this.t.translate('book.browser.confirm.regenCoverMessage', {count}),
|
||||
header: this.t.translate('book.browser.confirm.regenCoverHeader'),
|
||||
icon: 'pi pi-image',
|
||||
acceptLabel: this.t.translate('common.yes'),
|
||||
rejectLabel: this.t.translate('common.no'),
|
||||
acceptButtonProps: {
|
||||
label: this.t.translate('common.yes'),
|
||||
severity: 'success'
|
||||
},
|
||||
rejectButtonProps: {
|
||||
label: this.t.translate('common.no'),
|
||||
severity: 'secondary'
|
||||
},
|
||||
accept: () => {
|
||||
this.bookMetadataManageService.regenerateCoversForBooks(Array.from(this.selectedBooks)).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('book.browser.toast.regenCoverStartedSummary'),
|
||||
detail: this.t.translate('book.browser.toast.regenCoverStartedDetail', {count}),
|
||||
life: 3000
|
||||
});
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('book.browser.toast.failedSummary'),
|
||||
detail: this.t.translate('book.browser.toast.regenCoverFailedDetail'),
|
||||
life: 3000
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
generateCustomCoversForSelected(): void {
|
||||
if (!this.selectedBooks || this.selectedBooks.size === 0) return;
|
||||
const count = this.selectedBooks.size;
|
||||
this.confirmationService.confirm({
|
||||
message: this.t.translate('book.browser.confirm.customCoverMessage', {count}),
|
||||
header: this.t.translate('book.browser.confirm.customCoverHeader'),
|
||||
icon: 'pi pi-palette',
|
||||
acceptLabel: this.t.translate('common.yes'),
|
||||
rejectLabel: this.t.translate('common.no'),
|
||||
acceptButtonProps: {
|
||||
label: this.t.translate('common.yes'),
|
||||
severity: 'success'
|
||||
},
|
||||
rejectButtonProps: {
|
||||
label: this.t.translate('common.no'),
|
||||
severity: 'secondary'
|
||||
},
|
||||
accept: () => {
|
||||
this.bookMetadataManageService.generateCustomCoversForBooks(Array.from(this.selectedBooks)).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('book.browser.toast.customCoverStartedSummary'),
|
||||
detail: this.t.translate('book.browser.toast.customCoverStartedDetail', {count}),
|
||||
life: 3000
|
||||
});
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('book.browser.toast.failedSummary'),
|
||||
detail: this.t.translate('book.browser.toast.customCoverFailedDetail'),
|
||||
life: 3000
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
moveFiles() {
|
||||
this.dialogHelperService.openFileMoverDialog(this.selectedBooks);
|
||||
}
|
||||
|
||||
user() {
|
||||
return this.currentUser();
|
||||
}
|
||||
|
||||
get hasMetadataMenuItems(): boolean {
|
||||
return (this.metadataMenuItems?.length ?? 0) > 0;
|
||||
}
|
||||
|
||||
get hasMoreActionsItems(): boolean {
|
||||
return (this.moreActionsMenuItems?.length ?? 0) > 0;
|
||||
}
|
||||
}
|
||||
+118
@@ -0,0 +1,118 @@
|
||||
<ng-container *transloco="let t; prefix: 'book.shelfAssigner'">
|
||||
<div class="shelf-assigner">
|
||||
<div class="panel-header">
|
||||
<div class="header-icon-wrapper">
|
||||
<i class="pi pi-bookmark header-icon"></i>
|
||||
</div>
|
||||
<div class="header-text">
|
||||
<h2 class="panel-title">{{ t('title') }}</h2>
|
||||
<p class="panel-description">
|
||||
@if (isMultiBooks) {
|
||||
{{ t('descriptionMulti', { count: bookIds.size }) }}
|
||||
} @else {
|
||||
{{ t('descriptionSingle', { title: book.metadata?.title }) }}
|
||||
}
|
||||
</p>
|
||||
</div>
|
||||
<p-button
|
||||
icon="pi pi-times"
|
||||
[text]="true"
|
||||
[rounded]="true"
|
||||
severity="secondary"
|
||||
(onClick)="closeDialog()"
|
||||
class="close-button">
|
||||
</p-button>
|
||||
</div>
|
||||
|
||||
<div class="shelves-container">
|
||||
@if (shelves(); as shelves) {
|
||||
@if (shelves.length > 0) {
|
||||
<div class="shelves-list">
|
||||
<div class="list-header">
|
||||
<span class="shelf-count">
|
||||
<i class="pi pi-bookmark"></i>
|
||||
{{ t('shelvesAvailable', { count: shelves.length }) }}
|
||||
</span>
|
||||
<p-iconfield class="shelf-search">
|
||||
<p-inputicon class="pi pi-search"/>
|
||||
<input
|
||||
type="text"
|
||||
pInputText
|
||||
[(ngModel)]="searchQuery"
|
||||
[placeholder]="t('searchPlaceholder')"
|
||||
/>
|
||||
@if (searchQuery) {
|
||||
<button type="button" class="clear-icon" (click)="searchQuery = ''">
|
||||
<i class="pi pi-times"></i>
|
||||
</button>
|
||||
}
|
||||
</p-iconfield>
|
||||
</div>
|
||||
|
||||
<div class="shelves-grid">
|
||||
@for (shelf of filterShelves(shelves); track shelf.id) {
|
||||
<div class="shelf-item" [class.selected]="isShelfSelected(shelf)">
|
||||
<div class="shelf-checkbox">
|
||||
<p-checkbox
|
||||
[inputId]="'shelf-' + shelf.id"
|
||||
name="shelves"
|
||||
[value]="shelf"
|
||||
[(ngModel)]="selectedShelves"
|
||||
/>
|
||||
</div>
|
||||
<label [for]="'shelf-' + shelf.id" class="shelf-label">
|
||||
@if (shelf.icon) {
|
||||
<div class="shelf-icon-wrapper">
|
||||
<app-icon-display
|
||||
[icon]="getShelfIcon(shelf)"
|
||||
size="20px"
|
||||
iconClass="shelf-icon"
|
||||
/>
|
||||
</div>
|
||||
} @else {
|
||||
<div class="shelf-icon-wrapper-empty">
|
||||
</div>
|
||||
}
|
||||
<span class="shelf-name">{{ shelf.name }}</span>
|
||||
</label>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
} @else {
|
||||
<div class="empty-state">
|
||||
<div class="empty-icon-wrapper">
|
||||
<i class="pi pi-bookmark empty-icon"></i>
|
||||
</div>
|
||||
<h3 class="empty-title">{{ t('emptyTitle') }}</h3>
|
||||
<p class="empty-description" [innerHTML]="t('emptyDescription')"></p>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="dialog-footer">
|
||||
<p-button
|
||||
[label]="t('createShelf')"
|
||||
icon="pi pi-plus"
|
||||
[outlined]="true"
|
||||
severity="info"
|
||||
(onClick)="createShelfDialog()"
|
||||
/>
|
||||
<div class="footer-actions">
|
||||
<p-button
|
||||
[label]="t('cancelButton')"
|
||||
severity="secondary"
|
||||
[outlined]="true"
|
||||
(onClick)="closeDialog()"
|
||||
/>
|
||||
<p-button
|
||||
[label]="t('saveChanges')"
|
||||
icon="pi pi-check"
|
||||
severity="success"
|
||||
(onClick)="updateBooksShelves()"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
+311
@@ -0,0 +1,311 @@
|
||||
@use '../../../../shared/styles/panel-shared' as panel;
|
||||
|
||||
.shelf-assigner {
|
||||
width: 550px;
|
||||
max-width: 550px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
@media (max-width: 640px) {
|
||||
width: 100%;
|
||||
max-width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.panel-header {
|
||||
@include panel.panel-header;
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.shelves-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
padding: 1rem 2rem;
|
||||
background: var(--card-background);
|
||||
border: 1px solid var(--border-color);
|
||||
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
|
||||
min-height: 350px;
|
||||
max-height: 450px;
|
||||
overflow: hidden;
|
||||
|
||||
@media (max-width: 480px) {
|
||||
padding: 1rem;
|
||||
min-height: 300px;
|
||||
max-height: 400px;
|
||||
}
|
||||
}
|
||||
|
||||
.shelves-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.list-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 0.625rem 0.875rem;
|
||||
background: var(--overlay-background);
|
||||
border-radius: 6px;
|
||||
gap: 0.5rem;
|
||||
|
||||
.shelf-count {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.375rem;
|
||||
font-size: 0.9rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-color);
|
||||
white-space: nowrap;
|
||||
|
||||
i {
|
||||
color: var(--primary-color);
|
||||
}
|
||||
}
|
||||
|
||||
.shelf-search {
|
||||
flex: 1;
|
||||
max-width: 200px;
|
||||
position: relative;
|
||||
|
||||
input {
|
||||
width: 100%;
|
||||
font-size: 0.85rem;
|
||||
padding: 0.375rem 2rem 0.375rem 2rem;
|
||||
}
|
||||
|
||||
.clear-icon {
|
||||
position: absolute;
|
||||
right: 0.5rem;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
cursor: pointer;
|
||||
color: var(--text-secondary-color);
|
||||
font-size: 0.75rem;
|
||||
z-index: 1;
|
||||
|
||||
&:hover {
|
||||
color: var(--text-color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
padding: 0.5rem 0.625rem;
|
||||
flex-wrap: wrap;
|
||||
|
||||
.shelf-count {
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
|
||||
.shelf-search {
|
||||
max-width: 100%;
|
||||
order: 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.shelves-grid {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
overflow-y: auto;
|
||||
flex: 1;
|
||||
padding-right: 0.25rem;
|
||||
min-height: 0;
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
width: 6px;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-track {
|
||||
background: var(--overlay-background);
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-thumb {
|
||||
background: var(--border-color);
|
||||
border-radius: 3px;
|
||||
transition: background 0.2s ease;
|
||||
|
||||
&:hover {
|
||||
background: var(--primary-color);
|
||||
}
|
||||
}
|
||||
|
||||
scrollbar-width: thin;
|
||||
scrollbar-color: var(--border-color) var(--overlay-background);
|
||||
}
|
||||
|
||||
.shelf-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
padding: 0.5rem 1rem;
|
||||
background: var(--ground-background);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 8px;
|
||||
transition: all 0.3s ease;
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
border-color: var(--primary-color);
|
||||
transform: translateX(3px);
|
||||
box-shadow: 0 3px 8px rgba(0, 0, 0, 0.1);
|
||||
|
||||
.shelf-icon {
|
||||
color: var(--primary-color);
|
||||
transform: scale(1.08);
|
||||
}
|
||||
}
|
||||
|
||||
&.selected {
|
||||
border-color: var(--primary-color);
|
||||
|
||||
.shelf-icon-wrapper {
|
||||
background: var(--primary-color);
|
||||
|
||||
.shelf-icon {
|
||||
color: var(--primary-contrast-color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.shelf-checkbox {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.shelf-label {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
cursor: pointer;
|
||||
min-width: 0;
|
||||
|
||||
.shelf-icon-wrapper, .shelf-icon-wrapper-empty {
|
||||
width: 34px;
|
||||
height: 34px;
|
||||
}
|
||||
|
||||
.shelf-icon-wrapper {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: var(--overlay-background);
|
||||
border-radius: 8px;
|
||||
flex-shrink: 0;
|
||||
|
||||
.shelf-icon {
|
||||
font-size: 1.125rem;
|
||||
color: var(--text-secondary-color);
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
}
|
||||
|
||||
.shelf-name {
|
||||
font-size: 0.9375rem;
|
||||
color: var(--text-color);
|
||||
font-weight: 500;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
padding: 0.625rem;
|
||||
gap: 0.5rem;
|
||||
|
||||
.shelf-label {
|
||||
gap: 0.5rem;
|
||||
|
||||
.shelf-icon-wrapper, .shelf-icon-wrapper-empty {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
|
||||
.shelf-icon {
|
||||
font-size: 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
.shelf-name {
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
text-align: center;
|
||||
padding: 2rem 1rem;
|
||||
flex: 1;
|
||||
|
||||
.empty-icon-wrapper {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 80px;
|
||||
height: 80px;
|
||||
background: var(--overlay-background);
|
||||
border-radius: 50%;
|
||||
margin-bottom: 1rem;
|
||||
|
||||
.empty-icon {
|
||||
font-size: 2.5rem;
|
||||
color: var(--text-secondary-color);
|
||||
opacity: 0.5;
|
||||
}
|
||||
}
|
||||
|
||||
.empty-title {
|
||||
margin: 0 0 0.5rem 0;
|
||||
font-size: 1.125rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
.empty-description {
|
||||
margin: 0;
|
||||
font-size: 0.875rem;
|
||||
color: var(--text-secondary-color);
|
||||
max-width: 350px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
padding: 1.5rem 0.75rem;
|
||||
|
||||
.empty-icon-wrapper {
|
||||
width: 60px;
|
||||
height: 60px;
|
||||
|
||||
.empty-icon {
|
||||
font-size: 2rem;
|
||||
}
|
||||
}
|
||||
|
||||
.empty-title {
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.empty-description {
|
||||
font-size: 0.8rem;
|
||||
max-width: 100%;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.dialog-footer {
|
||||
@include panel.dialog-footer;
|
||||
border-top: none;
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
import {Component, computed, effect, inject} from '@angular/core';
|
||||
import {DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {Book} from '../../model/book.model';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {ShelfService} from '../../service/shelf.service';
|
||||
import {finalize} from 'rxjs';
|
||||
import {BookService} from '../../service/book.service';
|
||||
import {Shelf} from '../../model/shelf.model';
|
||||
import {Button} from 'primeng/button';
|
||||
import {Checkbox} from 'primeng/checkbox';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {BookDialogHelperService} from '../book-browser/book-dialog-helper.service';
|
||||
import {LoadingService} from '../../../../core/services/loading.service';
|
||||
import {UserService} from '../../../settings/user-management/user.service';
|
||||
import {IconDisplayComponent} from '../../../../shared/components/icon-display/icon-display.component';
|
||||
import {IconSelection} from '../../../../shared/service/icon-picker.service';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
import {IconField} from 'primeng/iconfield';
|
||||
import {InputIcon} from 'primeng/inputicon';
|
||||
|
||||
@Component({
|
||||
selector: 'app-shelf-assigner',
|
||||
standalone: true,
|
||||
templateUrl: './shelf-assigner.component.html',
|
||||
styleUrl: './shelf-assigner.component.scss',
|
||||
imports: [
|
||||
Button,
|
||||
Checkbox,
|
||||
FormsModule,
|
||||
IconDisplayComponent,
|
||||
TranslocoDirective,
|
||||
InputText,
|
||||
IconField,
|
||||
InputIcon
|
||||
]
|
||||
})
|
||||
export class ShelfAssignerComponent {
|
||||
|
||||
private shelfService = inject(ShelfService);
|
||||
private dynamicDialogConfig = inject(DynamicDialogConfig);
|
||||
private dynamicDialogRef = inject(DynamicDialogRef);
|
||||
private messageService = inject(MessageService);
|
||||
private bookService = inject(BookService);
|
||||
private bookDialogHelper = inject(BookDialogHelperService);
|
||||
private loadingService = inject(LoadingService);
|
||||
private userService = inject(UserService);
|
||||
private readonly t = inject(TranslocoService);
|
||||
|
||||
searchQuery = '';
|
||||
private currentUser = this.userService.currentUser;
|
||||
|
||||
book: Book = this.dynamicDialogConfig.data.book;
|
||||
selectedShelves: Shelf[] = [];
|
||||
bookIds: Set<number> = this.dynamicDialogConfig.data.bookIds;
|
||||
isMultiBooks: boolean = this.dynamicDialogConfig.data.isMultiBooks;
|
||||
private readonly shelfSortField = computed<'name' | 'id'>(() => {
|
||||
const sorting = this.currentUser()?.userSettings.sidebarShelfSorting;
|
||||
return sorting ? this.validateSortField(sorting.field) : 'name';
|
||||
});
|
||||
private readonly shelfSortOrder = computed<'asc' | 'desc'>(() => {
|
||||
const sorting = this.currentUser()?.userSettings.sidebarShelfSorting;
|
||||
return sorting ? this.validateSortOrder(sorting.order) : 'asc';
|
||||
});
|
||||
readonly shelves = computed(() => {
|
||||
const user = this.currentUser();
|
||||
const filteredShelves = this.shelfService.shelves().filter(shelf => shelf.userId === user?.id);
|
||||
return this.sortShelves(filteredShelves);
|
||||
});
|
||||
private hasInitializedSelectedShelves = false;
|
||||
private readonly initializeSelectedShelvesEffect = effect(() => {
|
||||
if (this.isMultiBooks || this.hasInitializedSelectedShelves || !this.book.shelves?.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
const selectedShelves = this.shelves().filter(shelf =>
|
||||
this.book.shelves?.some(bookShelf => bookShelf.id === shelf.id)
|
||||
);
|
||||
|
||||
if (selectedShelves.length > 0 || this.shelfService.shelves().length > 0) {
|
||||
this.selectedShelves = selectedShelves;
|
||||
this.hasInitializedSelectedShelves = true;
|
||||
}
|
||||
});
|
||||
|
||||
updateBooksShelves(): void {
|
||||
const idsToAssign = new Set<number | undefined>(this.selectedShelves.map(shelf => shelf.id));
|
||||
const idsToUnassign: Set<number> = this.isMultiBooks ? new Set() : this.getIdsToUnAssign(this.book, idsToAssign);
|
||||
const bookIds = this.isMultiBooks ? this.bookIds : new Set([this.book.id]);
|
||||
this.updateBookShelves(bookIds, idsToAssign, idsToUnassign);
|
||||
}
|
||||
|
||||
private updateBookShelves(bookIds: Set<number>, idsToAssign: Set<number | undefined>, idsToUnassign: Set<number>): void {
|
||||
const loader = this.loadingService.show(this.t.translate('book.shelfAssigner.loading.updatingShelves', { count: bookIds.size }));
|
||||
|
||||
this.bookService.updateBookShelves(bookIds, idsToAssign, idsToUnassign)
|
||||
.pipe(finalize(() => this.loadingService.hide(loader)))
|
||||
.subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({severity: 'info', summary: this.t.translate('common.success'), detail: this.t.translate('book.shelfAssigner.toast.updateSuccessDetail')});
|
||||
this.dynamicDialogRef.close({assigned: true});
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({severity: 'error', summary: this.t.translate('common.error'), detail: this.t.translate('book.shelfAssigner.toast.updateFailedDetail')});
|
||||
this.dynamicDialogRef.close({assigned: false});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private getIdsToUnAssign(book: Book, idsToAssign: Set<number | undefined>): Set<number> {
|
||||
const idsToUnassign = new Set<number>();
|
||||
book.shelves?.forEach(shelf => {
|
||||
if (!idsToAssign.has(shelf.id)) {
|
||||
idsToUnassign.add(shelf.id!);
|
||||
}
|
||||
});
|
||||
return idsToUnassign;
|
||||
}
|
||||
|
||||
createShelfDialog(): void {
|
||||
this.bookDialogHelper.openShelfCreatorDialog();
|
||||
}
|
||||
|
||||
closeDialog(): void {
|
||||
this.dynamicDialogRef.close({assigned: false});
|
||||
}
|
||||
|
||||
isShelfSelected(shelf: Shelf): boolean {
|
||||
return this.selectedShelves.some(s => s.id === shelf.id);
|
||||
}
|
||||
|
||||
getShelfIcon(shelf: Shelf): IconSelection {
|
||||
if (shelf.iconType === 'CUSTOM_SVG') {
|
||||
return {type: 'CUSTOM_SVG', value: shelf.icon ?? ""};
|
||||
} else {
|
||||
return {type: 'PRIME_NG', value: `pi pi-${shelf.icon}`};
|
||||
}
|
||||
}
|
||||
|
||||
filterShelves(shelves: Shelf[]): Shelf[] {
|
||||
if (!this.searchQuery.trim()) {
|
||||
return shelves;
|
||||
}
|
||||
const query = this.searchQuery.trim().toLowerCase();
|
||||
return shelves.filter(s => s.name.toLowerCase().includes(query));
|
||||
}
|
||||
|
||||
private sortShelves(shelves: Shelf[]): Shelf[] {
|
||||
const sortField = this.shelfSortField();
|
||||
const sortOrder = this.shelfSortOrder();
|
||||
return [...shelves].sort((a, b) => {
|
||||
const aVal = (a as unknown as Record<string, unknown>)[sortField] ?? '';
|
||||
const bVal = (b as unknown as Record<string, unknown>)[sortField] ?? '';
|
||||
let comparison = 0;
|
||||
if (typeof aVal === 'string' && typeof bVal === 'string') {
|
||||
comparison = aVal.localeCompare(bVal);
|
||||
} else if (typeof aVal === 'number' && typeof bVal === 'number') {
|
||||
comparison = aVal - bVal;
|
||||
}
|
||||
return sortOrder === 'asc' ? comparison : -comparison;
|
||||
});
|
||||
}
|
||||
|
||||
private validateSortField(field: string): 'name' | 'id' {
|
||||
return field === 'id' ? 'id' : 'name';
|
||||
}
|
||||
|
||||
private validateSortOrder(order: string): 'asc' | 'desc' {
|
||||
return order === 'desc' ? 'desc' : 'asc';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
<ng-container *transloco="let t; prefix: 'book.shelfCreator'">
|
||||
<div class="shelf-creator">
|
||||
<div class="panel-header">
|
||||
<div class="header-icon-wrapper">
|
||||
<i class="pi pi-bookmark header-icon"></i>
|
||||
</div>
|
||||
<div class="header-text">
|
||||
<h2 class="panel-title">{{ t('title') }}</h2>
|
||||
<p class="panel-description">{{ t('description') }}</p>
|
||||
</div>
|
||||
<p-button
|
||||
icon="pi pi-times"
|
||||
(click)="cancel()"
|
||||
severity="secondary"
|
||||
[text]="true"
|
||||
[rounded]="true"
|
||||
class="close-button"
|
||||
[pTooltip]="t('closeTooltip')"
|
||||
tooltipPosition="left"/>
|
||||
</div>
|
||||
|
||||
<div class="form-container">
|
||||
<div class="form-group highlight-group">
|
||||
<label for="shelfName" class="form-label">
|
||||
<i class="pi pi-tag label-icon"></i>
|
||||
{{ t('shelfNameLabel') }}
|
||||
<span class="required-indicator">*</span>
|
||||
</label>
|
||||
<div class="input-wrapper">
|
||||
<input
|
||||
id="shelfName"
|
||||
type="text"
|
||||
pInputText
|
||||
[(ngModel)]="shelfName"
|
||||
class="input-full"
|
||||
[placeholder]="t('shelfNamePlaceholder')"
|
||||
[class.filled]="shelfName.trim()"
|
||||
|
||||
/>
|
||||
@if (shelfName.trim()) {
|
||||
<i class="pi pi-check-circle input-icon success"></i>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="gradient-divider"></div>
|
||||
|
||||
<div class="form-group highlight-group">
|
||||
<label class="form-label">
|
||||
<i class="pi pi-palette label-icon"></i>
|
||||
{{ t('shelfIconLabel') }}
|
||||
</label>
|
||||
@if (!selectedIcon) {
|
||||
<button class="icon-select-btn" (click)="openIconPicker()" type="button">
|
||||
<i class="pi pi-plus"></i>
|
||||
<div class="btn-content">
|
||||
<span class="btn-title">{{ t('chooseIcon') }}</span>
|
||||
<span class="btn-subtitle">{{ t('chooseIconSubtitle') }}</span>
|
||||
</div>
|
||||
</button>
|
||||
} @else {
|
||||
<div class="selected-icon-display">
|
||||
<div class="icon-preview">
|
||||
<app-icon-display
|
||||
[icon]="selectedIcon"
|
||||
size="24px"
|
||||
/>
|
||||
</div>
|
||||
<div class="icon-info">
|
||||
<span class="icon-label">{{ t('selectedIcon') }}</span>
|
||||
<span class="icon-name">
|
||||
@if (selectedIcon.type === 'PRIME_NG') {
|
||||
{{ selectedIcon.value }}
|
||||
} @else {
|
||||
{{ selectedIcon.value }}
|
||||
}
|
||||
</span>
|
||||
</div>
|
||||
<p-button
|
||||
icon="pi pi-times"
|
||||
severity="danger"
|
||||
[outlined]="true"
|
||||
[rounded]="true"
|
||||
size="small"
|
||||
(onClick)="clearSelectedIcon()"
|
||||
[pTooltip]="t('removeIconTooltip')"
|
||||
tooltipPosition="left"
|
||||
/>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@if (isAdmin) {
|
||||
<div class="gradient-divider"></div>
|
||||
|
||||
<div class="form-group highlight-group">
|
||||
<label class="form-label">
|
||||
<i class="pi pi-globe label-icon"></i>
|
||||
{{ t('visibilityLabel') }}
|
||||
</label>
|
||||
<div class="input-wrapper" style="display: flex; align-items: center; gap: 0.5rem;">
|
||||
<p-checkbox [(ngModel)]="isPublic" [binary]="true" inputId="publicShelf"></p-checkbox>
|
||||
<label for="publicShelf" style="cursor: pointer">{{ t('makePublicLabel') }}</label>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="dialog-footer">
|
||||
<div class="validation-status">
|
||||
@if (!shelfName.trim()) {
|
||||
<div class="validation-message error">
|
||||
<i class="pi pi-exclamation-circle"></i>
|
||||
<span>{{ t('validationRequired') }}</span>
|
||||
</div>
|
||||
} @else {
|
||||
<div class="validation-message success">
|
||||
<i class="pi pi-check-circle"></i>
|
||||
<span>{{ t('validationReady') }}</span>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
<div class="footer-actions">
|
||||
<p-button
|
||||
[label]="t('cancelButton')"
|
||||
severity="secondary"
|
||||
[outlined]="true"
|
||||
(onClick)="cancel()"
|
||||
/>
|
||||
<p-button
|
||||
[label]="t('createButton')"
|
||||
icon="pi pi-plus"
|
||||
severity="success"
|
||||
(onClick)="createShelf()"
|
||||
[disabled]="!shelfName.trim()"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
@@ -0,0 +1,244 @@
|
||||
@use '../../../../shared/styles/panel-shared' as panel;
|
||||
|
||||
.shelf-creator {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-width: 600px;
|
||||
|
||||
@media (max-width: 640px) {
|
||||
min-width: auto;
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.panel-header {
|
||||
@include panel.panel-header;
|
||||
}
|
||||
|
||||
.form-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1.5rem;
|
||||
padding: 1.5rem;
|
||||
background: var(--card-background);
|
||||
border: 1px solid var(--border-color);
|
||||
border-top: none;
|
||||
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
|
||||
|
||||
@media (max-width: 480px) {
|
||||
padding: 1rem;
|
||||
gap: 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
.form-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
|
||||
&.highlight-group {
|
||||
padding: 0.875rem;
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
gap: 0.375rem;
|
||||
|
||||
&.highlight-group {
|
||||
padding: 0.625rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.form-label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.375rem;
|
||||
font-size: 0.95rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-color);
|
||||
|
||||
.label-icon {
|
||||
color: var(--primary-color);
|
||||
}
|
||||
|
||||
.required-indicator {
|
||||
color: var(--p-red-500);
|
||||
margin-left: 0.125rem;
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
}
|
||||
|
||||
.input-wrapper {
|
||||
position: relative;
|
||||
|
||||
.input-full {
|
||||
width: 100%;
|
||||
padding-right: 2.5rem;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.input-icon {
|
||||
position: absolute;
|
||||
right: 0.75rem;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
font-size: 1rem;
|
||||
pointer-events: none;
|
||||
|
||||
&.success {
|
||||
color: var(--p-green-500);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.icon-select-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 0.75rem;
|
||||
width: 100%;
|
||||
padding: 1rem;
|
||||
background: var(--ground-background);
|
||||
border: 1px dashed var(--border-color);
|
||||
border-radius: 8px;
|
||||
color: var(--text-color);
|
||||
font-size: 0.875rem;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
|
||||
&:hover {
|
||||
background: var(--overlay-background);
|
||||
border-color: var(--primary-color);
|
||||
color: var(--primary-color);
|
||||
transform: translateY(-1px);
|
||||
box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
|
||||
i {
|
||||
font-size: 1.25rem;
|
||||
}
|
||||
|
||||
.btn-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 0.125rem;
|
||||
|
||||
.btn-title {
|
||||
font-size: 0.9375rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.btn-subtitle {
|
||||
font-size: 0.8rem;
|
||||
opacity: 0.85;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
padding: 0.75rem;
|
||||
gap: 0.5rem;
|
||||
|
||||
i {
|
||||
font-size: 1.125rem;
|
||||
}
|
||||
|
||||
.btn-content {
|
||||
.btn-title {
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.btn-subtitle {
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.selected-icon-display {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
padding: 0.875rem;
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 8px;
|
||||
background: var(--ground-background);
|
||||
|
||||
.icon-preview {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 42px;
|
||||
height: 42px;
|
||||
background: var(--primary-color);
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 3px 8px rgba(0, 0, 0, 0.2);
|
||||
|
||||
app-icon-display {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: var(--primary-contrast-color);
|
||||
|
||||
::ng-deep i {
|
||||
color: var(--primary-contrast-color);
|
||||
}
|
||||
|
||||
::ng-deep img {
|
||||
filter: brightness(0) invert(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.icon-info {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.125rem;
|
||||
|
||||
.icon-label {
|
||||
font-size: 0.8rem;
|
||||
color: var(--text-secondary-color);
|
||||
}
|
||||
|
||||
.icon-name {
|
||||
font-size: 0.875rem;
|
||||
font-weight: 500;
|
||||
color: var(--text-color);
|
||||
font-family: monospace;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
padding: 0.625rem;
|
||||
gap: 0.5rem;
|
||||
|
||||
.icon-preview {
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
}
|
||||
|
||||
.icon-info {
|
||||
.icon-label {
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
|
||||
.icon-name {
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.dialog-footer {
|
||||
@include panel.dialog-footer;
|
||||
border-top: none;
|
||||
}
|
||||
|
||||
.validation-message {
|
||||
@include panel.validation-message;
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
import {Component, inject} from '@angular/core';
|
||||
import {DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {ShelfService} from '../../service/shelf.service';
|
||||
import {IconPickerService, IconSelection} from '../../../../shared/service/icon-picker.service';
|
||||
import {Shelf} from '../../model/shelf.model';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {Button} from 'primeng/button';
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {IconDisplayComponent} from '../../../../shared/components/icon-display/icon-display.component';
|
||||
import {UserService} from '../../../settings/user-management/user.service';
|
||||
import {CheckboxModule} from 'primeng/checkbox';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
@Component({
|
||||
selector: 'app-shelf-creator',
|
||||
standalone: true,
|
||||
templateUrl: './shelf-creator.component.html',
|
||||
imports: [
|
||||
FormsModule,
|
||||
Button,
|
||||
InputText,
|
||||
Tooltip,
|
||||
IconDisplayComponent,
|
||||
CheckboxModule,
|
||||
TranslocoDirective
|
||||
],
|
||||
styleUrl: './shelf-creator.component.scss',
|
||||
})
|
||||
export class ShelfCreatorComponent {
|
||||
private shelfService = inject(ShelfService);
|
||||
private dynamicDialogRef = inject(DynamicDialogRef);
|
||||
private messageService = inject(MessageService);
|
||||
private iconPickerService = inject(IconPickerService);
|
||||
private userService = inject(UserService);
|
||||
private readonly t = inject(TranslocoService);
|
||||
|
||||
shelfName: string = '';
|
||||
selectedIcon: IconSelection | null = null;
|
||||
isPublic: boolean = false;
|
||||
isAdmin: boolean = this.userService.getCurrentUser()?.permissions.admin ?? false;
|
||||
|
||||
openIconPicker(): void {
|
||||
this.iconPickerService.open().subscribe(icon => {
|
||||
if (icon) {
|
||||
this.selectedIcon = icon;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
clearSelectedIcon(): void {
|
||||
this.selectedIcon = null;
|
||||
}
|
||||
|
||||
cancel(): void {
|
||||
this.dynamicDialogRef.close();
|
||||
}
|
||||
|
||||
createShelf(): void {
|
||||
const iconValue = this.selectedIcon?.value ?? null;
|
||||
const iconType = this.selectedIcon?.type ?? null;
|
||||
|
||||
const newShelf: Partial<Shelf> = {
|
||||
name: this.shelfName,
|
||||
icon: iconValue,
|
||||
iconType: iconType,
|
||||
publicShelf: this.isPublic
|
||||
};
|
||||
|
||||
this.shelfService.createShelf(newShelf as Shelf).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({severity: 'info', summary: this.t.translate('common.success'), detail: this.t.translate('book.shelfCreator.toast.createSuccessDetail', { name: this.shelfName })});
|
||||
this.dynamicDialogRef.close(true);
|
||||
},
|
||||
error: (e) => {
|
||||
this.messageService.add({severity: 'error', summary: this.t.translate('common.error'), detail: this.t.translate('book.shelfCreator.toast.createFailedDetail')});
|
||||
console.error('Error creating shelf:', e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
<ng-container *transloco="let t; prefix: 'book.shelfEditDialog'">
|
||||
<div class="shelf-form">
|
||||
<div class="panel-header">
|
||||
<div class="header-icon-wrapper">
|
||||
<i class="pi pi-pencil header-icon"></i>
|
||||
</div>
|
||||
<div class="header-text">
|
||||
<h2 class="panel-title">{{ t('title') }}</h2>
|
||||
<p class="panel-description">
|
||||
{{ t('description') }}
|
||||
</p>
|
||||
</div>
|
||||
<p-button
|
||||
icon="pi pi-times"
|
||||
[text]="true"
|
||||
[rounded]="true"
|
||||
severity="secondary"
|
||||
(onClick)="closeDialog()"
|
||||
class="close-button">
|
||||
</p-button>
|
||||
</div>
|
||||
|
||||
<div class="shelf-container">
|
||||
<div class="shelf-fields">
|
||||
<div class="shelf-row">
|
||||
<label class="label">{{ t('shelfNameLabel') }}</label>
|
||||
<input type="text" pInputText [(ngModel)]="shelfName" [placeholder]="t('shelfNamePlaceholder')" class="input"/>
|
||||
</div>
|
||||
|
||||
<div class="shelf-row">
|
||||
<label class="label">{{ t('shelfIconLabel') }}</label>
|
||||
<div class="icon-section">
|
||||
@if (!selectedIcon) {
|
||||
<p-button [label]="t('selectIcon')" icon="pi pi-search" [outlined]="true" severity="info" (onClick)="openIconPicker()"></p-button>
|
||||
}
|
||||
|
||||
@if (selectedIcon) {
|
||||
<div class="icon-container">
|
||||
<div class="icon-wrapper">
|
||||
<app-icon-display
|
||||
[icon]="selectedIcon"
|
||||
size="24px"
|
||||
iconClass="icon"
|
||||
/>
|
||||
</div>
|
||||
<p-button icon="pi pi-times" (onClick)="clearSelectedIcon()" [rounded]="true" [text]="true" severity="danger"></p-button>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (isAdmin) {
|
||||
<div class="shelf-row">
|
||||
<label class="label">{{ t('visibilityLabel') }}</label>
|
||||
<div class="visibility-section" style="display: flex; align-items: center; gap: 0.5rem;">
|
||||
<p-checkbox [(ngModel)]="isPublic" [binary]="true" inputId="publicShelf"></p-checkbox>
|
||||
<label for="publicShelf" style="cursor: pointer; user-select: none;">{{ t('publicShelfLabel') }}</label>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="dialog-footer">
|
||||
<div></div>
|
||||
<div class="footer-actions">
|
||||
<p-button
|
||||
[label]="t('cancelButton')"
|
||||
severity="secondary"
|
||||
[outlined]="true"
|
||||
(onClick)="closeDialog()"
|
||||
/>
|
||||
<p-button
|
||||
[label]="t('saveChanges')"
|
||||
icon="pi pi-check"
|
||||
severity="success"
|
||||
(onClick)="save()"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user