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:
James Cox
2026-04-22 17:26:39 -04:00
committed by Zach Yale
parent c99aa87877
commit 874b013f75
1493 changed files with 3 additions and 3 deletions
@@ -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>
@@ -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;
}
@@ -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);
}
}