diff --git a/booklore-ui/src/app/app.routes.ts b/booklore-ui/src/app/app.routes.ts index 714a68229..732e73ccf 100644 --- a/booklore-ui/src/app/app.routes.ts +++ b/booklore-ui/src/app/app.routes.ts @@ -17,6 +17,7 @@ import {OidcCallbackComponent} from './core/security/oidc-callback/oidc-callback import {CbxReaderComponent} from './book/components/cbx-reader/cbx-reader.component'; import {BookdropFileReviewComponent} from './bookdrop/bookdrop-file-review-component/bookdrop-file-review.component'; import {MainDashboardComponent} from './dashboard/components/main-dashboard/main-dashboard.component'; +import {SeriesPageComponent} from './book/components/series-page/series-page.component'; import {StatsComponent} from './stats-component/stats-component'; export const routes: Routes = [ @@ -42,6 +43,7 @@ export const routes: Routes = [ {path: 'library/:libraryId/books', component: BookBrowserComponent, canActivate: [AuthGuard]}, {path: 'shelf/:shelfId/books', component: BookBrowserComponent, canActivate: [AuthGuard]}, {path: 'unshelved-books', component: BookBrowserComponent, canActivate: [AuthGuard]}, + {path: 'series/:seriesName', component: SeriesPageComponent, canActivate: [AuthGuard]}, { path: 'magic-shelf/:magicShelfId/books', component: BookBrowserComponent, canActivate: [AuthGuard] }, {path: 'book/:bookId', component: BookMetadataCenterComponent, canActivate: [AuthGuard]}, {path: 'bookdrop', component: BookdropFileReviewComponent, canActivate: [AuthGuard]}, diff --git a/booklore-ui/src/app/book/components/book-browser/book-browser.component.html b/booklore-ui/src/app/book/components/book-browser/book-browser.component.html index 782d24f78..c02649b23 100644 --- a/booklore-ui/src/app/book/components/book-browser/book-browser.component.html +++ b/booklore-ui/src/app/book/components/book-browser/book-browser.component.html @@ -277,15 +277,16 @@
- - + +
} diff --git a/booklore-ui/src/app/book/components/book-browser/book-card/book-card.component.html b/booklore-ui/src/app/book/components/book-browser/book-card/book-card.component.html index 3ad19c575..ef652da5c 100644 --- a/booklore-ui/src/app/book/components/book-browser/book-card/book-card.component.html +++ b/booklore-ui/src/app/book/components/book-browser/book-card/book-card.component.html @@ -14,24 +14,28 @@ [src]="urlHelper.getThumbnailUrl(book.id, book.metadata?.coverUpdatedOn)" class="book-cover" [class.loaded]="isImageLoaded" - alt="Cover of {{ book.metadata?.title }}" + alt="Cover of {{ displayTitle }}" loading="lazy" (load)="onImageLoad()"/> - @if (book.metadata?.seriesNumber != null) { + @if (!book.seriesCount && book.metadata?.seriesNumber != null) {
#{{ book.metadata?.seriesNumber }}
} - @if (book.seriesCount != null && book.seriesCount! > 1) { -
+ @if (book.seriesCount && book.seriesCount! >= 1) { +
{{ book.seriesCount }}
} - + @if (book.seriesCount && book.seriesCount! >= 1) { + + } @else { + + } @@ -70,8 +74,8 @@

- {{ book.metadata?.title }} + [pTooltip]="displayTitle"> + {{ displayTitle }}

- - + @if (!this.isActive) { + + + }
diff --git a/booklore-ui/src/app/book/components/book-card-lite/book-card-lite-component.ts b/booklore-ui/src/app/book/components/book-card-lite/book-card-lite-component.ts index c0041670a..8bf6e9da8 100644 --- a/booklore-ui/src/app/book/components/book-card-lite/book-card-lite-component.ts +++ b/booklore-ui/src/app/book/components/book-card-lite/book-card-lite-component.ts @@ -22,6 +22,7 @@ import {TooltipModule} from 'primeng/tooltip'; }) export class BookCardLiteComponent implements OnInit, OnDestroy { @Input() book!: Book; + @Input() isActive: boolean = false; private router = inject(Router); protected urlHelper = inject(UrlHelperService); diff --git a/booklore-ui/src/app/book/components/series-page/series-page.component.html b/booklore-ui/src/app/book/components/series-page/series-page.component.html new file mode 100644 index 000000000..85902e5cc --- /dev/null +++ b/booklore-ui/src/app/book/components/series-page/series-page.component.html @@ -0,0 +1,123 @@ +@if (filteredBooks$ | async; as books) { +
+ + + + + Series Details + + + + + + @if (books[0]; as firstBook) { +
+
+ + +
+ +
+
+

+ {{ seriesTitle$ | async }} +

+
+ +

+ @for (author of firstBook.metadata?.authors; track $index; let isLast = $last) { + + {{ author }} + + @if (!isLast) { + , + } + } +

+ +
+ + @if (firstBook.metadata?.categories?.length) { +
+
+ @for (category of firstBook.metadata?.categories; track category) { + + + + } +
+
+ } +
+
+

+ Publisher: + @if (firstBook.metadata?.publisher; as publisher) { + + {{publisher}} + + } @else { + - + } +

+

Years: {{ (yearsRange$ | async) || '-' }}

+

Number of books: {{ books.length || 0}}

+

Language: {{ firstBook.metadata?.language || "-"}}

+

Read Status: + @let s = seriesReadStatus$ | async; + + {{ getStatusLabel(s) }} + +

+
+
+ + +
+
+
+
+ @let desc = firstDescription$ | async; + @if ((desc?.length ?? 0) > 500) { + + + } +
+ +
+
+ + +
+
No books found for this series.
+
+ +
+ +
+
+ } + +
+
+
+
+ +} @else { +
+ + +

+ Loading series details... +

+
+} \ No newline at end of file diff --git a/booklore-ui/src/app/book/components/series-page/series-page.component.html.backup b/booklore-ui/src/app/book/components/series-page/series-page.component.html.backup new file mode 100644 index 000000000..a95b06536 --- /dev/null +++ b/booklore-ui/src/app/book/components/series-page/series-page.component.html.backup @@ -0,0 +1,147 @@ +@if (filteredBooks$ | async; as books) { +
+ + + + + Series Details + + + + + + + +
+
+ + +
+ + +
+
+

+ {{ seriesTitle$ | async }} +

+
+ +

+ @for (author of books[0]?.metadata?.authors; track $index; let isLast = $last) { + + + {{ author }} + + @if (!isLast) { + , + } + } +

+ +
+ + + @if (books[0]?.metadata?.categories?.length) { +
+
+ @for (category of books[0].metadata!.categories; track category) { + + + + } +
+
+ } + + +
+
+

Number of books: {{ books.length || 0}}

+

Publisher: {{ books[0]?.metadata?.publisher || "-"}}

+

Year: {{ books[0]?.metadata?.publishedDate || "-"}}

+

Language: {{ books[0]?.metadata?.language || "-"}}

+
+
+ + + +
+
+
+ +
+
+ +
+ + + + + + +
+
+ + +
+
No books found for this series.
+
+ +
+ +
+
+ + + +
+
+
+
+} @else { +
+ + +

+ Loading series details... +

+
+} \ No newline at end of file diff --git a/booklore-ui/src/app/book/components/series-page/series-page.component.scss b/booklore-ui/src/app/book/components/series-page/series-page.component.scss new file mode 100644 index 000000000..0552f4ba6 --- /dev/null +++ b/booklore-ui/src/app/book/components/series-page/series-page.component.scss @@ -0,0 +1,18 @@ +.tabpanels-responsive { + height: calc(100dvh - 9.7rem); +} + +@media (max-width: 768px) { + .tabpanels-responsive { + height: calc(100dvh - 8.5rem); + } +} + +.grid { + display: grid; + grid-template-columns: repeat(auto-fit, minmax(1px, 1fr)); + gap: 1.3rem; + align-items: start; + width: 100%; +} + diff --git a/booklore-ui/src/app/book/components/series-page/series-page.component.ts b/booklore-ui/src/app/book/components/series-page/series-page.component.ts new file mode 100644 index 000000000..dbca831d4 --- /dev/null +++ b/booklore-ui/src/app/book/components/series-page/series-page.component.ts @@ -0,0 +1,226 @@ +import { Component, inject, ViewChild } from "@angular/core"; +import { FormsModule } from "@angular/forms"; +import { Button } from "primeng/button"; +import { ActivatedRoute } from "@angular/router"; +import { AsyncPipe, NgClass, NgFor, NgIf, NgStyle } from "@angular/common"; +import { map, filter, switchMap } from "rxjs/operators"; +import { Observable, combineLatest } from "rxjs"; +import { Book, ReadStatus } from "../../model/book.model"; +import { BookService } from "../../service/book.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 { Tag } from "primeng/tag"; +import { VirtualScrollerModule } from "@iharbeck/ngx-virtual-scroller"; +import { ProgressSpinner } from "primeng/progressspinner"; +import { DialogService, DynamicDialogRef } from "primeng/dynamicdialog"; +import { Router } from "@angular/router"; + +@Component({ + selector: "app-series-page", + standalone: true, + templateUrl: "./series-page.component.html", + styleUrls: ["./series-page.component.scss"], + imports: [ + AsyncPipe, + Button, + FormsModule, + NgIf, + NgFor, + NgStyle, + NgClass, + BookCardComponent, + ProgressSpinner, + Tabs, + TabList, + Tab, + TabPanels, + TabPanel, + Tag, + + VirtualScrollerModule, + ], +}) +export class SeriesPageComponent { + + private route = inject(ActivatedRoute); + private bookService = inject(BookService); + protected coverScalePreferenceService = inject(CoverScalePreferenceService); + private metadataCenterViewMode: "route" | "dialog" = "route"; + private dialogRef?: DynamicDialogRef; + private router = inject(Router); + + tab: string = "view"; + isExpanded = false; + + + seriesParam$: Observable = this.route.paramMap.pipe( + map((params) => params.get("seriesName") || ""), + map((name) => decodeURIComponent(name)) + ); + + booksInSeries$: Observable = this.bookService.bookState$.pipe( + filter((state) => state.loaded && !!state.books), + map((state) => state.books || []) + ); + + filteredBooks$: Observable = combineLatest([ + this.seriesParam$.pipe(map((n) => n.trim().toLowerCase())), + this.booksInSeries$, + ]).pipe( + map(([seriesName, books]) => { + const inSeries = books.filter( + (b) => b.metadata?.seriesName?.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; + }); + }) + ); + + seriesTitle$: Observable = combineLatest([ + this.seriesParam$, + this.filteredBooks$, + ]).pipe(map(([param, books]) => books[0]?.metadata?.seriesName || param)); + + yearsRange$: Observable = this.filteredBooks$.pipe( + map((books) => { + const years = books + .map((b) => b.metadata?.publishedDate) + .filter((d): d is string => !!d) + .map((d) => { + const match = d.match(/\d{4}/); + return match ? parseInt(match[0], 10) : null; + }) + .filter((y): y is number => y !== 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$: Observable = this.filteredBooks$.pipe( + map((books) => books[0]), + filter((b): b is Book => !!b), + switchMap((b) => this.bookService.getBookByIdFromAPI(b.id, true)) + ); + + firstDescription$: Observable = this.firstBookWithDesc$.pipe( + map((b) => b.metadata?.description || "") + ); + + seriesReadStatus$: Observable = this.filteredBooks$.pipe( + map((books) => { + if (!books || books.length === 0) return ReadStatus.UNREAD; + const statuses = books.map((b) => (b.readStatus as ReadStatus) ?? ReadStatus.UNREAD); + + const hasWontRead = statuses.includes(ReadStatus.WONT_READ); + if (hasWontRead) return ReadStatus.WONT_READ; + + const hasAbandoned = statuses.includes(ReadStatus.ABANDONED); + if (hasAbandoned) return ReadStatus.ABANDONED; + + const allRead = statuses.every((s) => s === ReadStatus.READ); + if (allRead) return ReadStatus.READ; + + const someRead = statuses.some((s) => s === ReadStatus.READ); + if (someRead) return ReadStatus.PARTIALLY_READ; + + const allUnread = statuses.every((s) => s === ReadStatus.UNREAD); + if (allUnread) return ReadStatus.UNREAD; + + return ReadStatus.PARTIALLY_READ; + }) + ); + + 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}:${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); + } + } + + toggleExpand(): void { + this.isExpanded = !this.isExpanded; + } + + getStatusLabel(value: string | ReadStatus | null | undefined): string { + const v = (value ?? '').toString().toUpperCase(); + switch (v) { + case ReadStatus.UNREAD: + return 'UNREAD'; + case ReadStatus.READ: + return 'READ'; + case ReadStatus.PARTIALLY_READ: + return 'PARTIALLY READ'; + case ReadStatus.ABANDONED: + return 'ABANDONED'; + case ReadStatus.WONT_READ: + return "WON'T READ"; + default: + return 'UNSET'; + } + } + + getStatusSeverityClass(status: string): string { + const normalized = status?.toUpperCase(); + switch (normalized) { + case "UNREAD": + return "bg-gray-500"; + case "READ": + return "bg-green-600"; + case "PARTIALLY_READ": + return "bg-yellow-600"; + case "ABANDONED": + return "bg-red-600"; + case "WONT_READ": + return "bg-pink-700"; + default: + return "bg-gray-600"; + } + } +} diff --git a/booklore-ui/src/app/book/service/book.service.ts b/booklore-ui/src/app/book/service/book.service.ts index 0230872f5..22f755ca4 100644 --- a/booklore-ui/src/app/book/service/book.service.ts +++ b/booklore-ui/src/app/book/service/book.service.ts @@ -578,10 +578,7 @@ export class BookService { } const seriesName = currentBook.metadata.seriesName.toLowerCase(); - return allBooks.filter(b => - b.id !== bookId && - b.metadata?.seriesName?.toLowerCase() === seriesName - ); + return allBooks.filter(b => b.metadata?.seriesName?.toLowerCase() === seriesName); }) ); } diff --git a/booklore-ui/src/app/metadata/book-metadata-center-component/metadata-viewer/metadata-viewer.component.html b/booklore-ui/src/app/metadata/book-metadata-center-component/metadata-viewer/metadata-viewer.component.html index ad9c6ca62..18ff79053 100644 --- a/booklore-ui/src/app/metadata/book-metadata-center-component/metadata-viewer/metadata-viewer.component.html +++ b/booklore-ui/src/app/metadata/book-metadata-center-component/metadata-viewer/metadata-viewer.component.html @@ -527,9 +527,9 @@ [infiniteScrollDistance]="2" [infiniteScrollThrottle]="50" [horizontal]="true"> - @for (book of bookInSeries; track book.id) { + @for (bookInSeriesItem of bookInSeries; track bookInSeriesItem) {
- +
} @@ -548,7 +548,7 @@ [horizontal]="true"> @for (book of recommendedBooks; track book.book.id) {
- +
} diff --git a/booklore-ui/src/app/metadata/book-metadata-center-component/metadata-viewer/metadata-viewer.component.ts b/booklore-ui/src/app/metadata/book-metadata-center-component/metadata-viewer/metadata-viewer.component.ts index 5c6062fc2..90401dab9 100644 --- a/booklore-ui/src/app/metadata/book-metadata-center-component/metadata-viewer/metadata-viewer.component.ts +++ b/booklore-ui/src/app/metadata/book-metadata-center-component/metadata-viewer/metadata-viewer.component.ts @@ -543,7 +543,7 @@ export class MetadataViewerComponent implements OnInit, OnChanges { } goToSeries(seriesName: string): void { - this.handleMetadataClick('series', seriesName); + this.router.navigate(['/series', seriesName]); } goToPublisher(publisher: string): void {