Add configurability to dashboard scrollers with support for magic shelves (#1453)

This commit is contained in:
Aditya Chandel
2025-10-26 11:51:06 -06:00
committed by GitHub
parent 4251fe42c3
commit 11e59f7588
19 changed files with 842 additions and 77 deletions
@@ -62,10 +62,8 @@ public class BookLoreUserTransformer {
case SIDEBAR_LIBRARY_SORTING -> userSettings.setSidebarLibrarySorting(objectMapper.readValue(value, SidebarSortOption.class));
case SIDEBAR_SHELF_SORTING -> userSettings.setSidebarShelfSorting(objectMapper.readValue(value, SidebarSortOption.class));
case ENTITY_VIEW_PREFERENCES -> userSettings.setEntityViewPreferences(objectMapper.readValue(value, BookLoreUser.UserSettings.EntityViewPreferences.class));
case TABLE_COLUMN_PREFERENCE -> userSettings.setTableColumnPreference(
objectMapper.readValue(value, new TypeReference<>() {
})
);
case TABLE_COLUMN_PREFERENCE -> userSettings.setTableColumnPreference(objectMapper.readValue(value, new TypeReference<>() {}));
case DASHBOARD_CONFIG -> userSettings.setDashboardConfig(objectMapper.readValue(value, BookLoreUser.UserSettings.DashboardConfig.class));
}
} else {
switch (settingKey) {
@@ -52,6 +52,7 @@ public class BookLoreUser {
public String filterSortingMode;
public String metadataCenterViewMode;
public boolean koReaderEnabled;
public DashboardConfig dashboardConfig;
@Data
@Builder
@@ -162,5 +163,29 @@ public class BookLoreUser {
Global, Individual
}
}
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public static class DashboardConfig {
private List<ScrollerConfig> scrollers;
}
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public static class ScrollerConfig {
private String id;
private String type;
private String title;
private boolean enabled;
private int order;
private int maxItems;
private Long magicShelfId;
private String sortField;
private String sortDirection;
}
}
}
@@ -13,6 +13,7 @@ public enum UserSettingKey {
SIDEBAR_SHELF_SORTING("sidebarShelfSorting", true),
ENTITY_VIEW_PREFERENCES("entityViewPreferences", true),
TABLE_COLUMN_PREFERENCE("tableColumnPreference", true),
DASHBOARD_CONFIG("dashboardConfig", true),
FILTER_SORTING_MODE("filterSortingMode", false),
METADATA_CENTER_VIEW_MODE("metadataCenterViewMode", false);
@@ -24,6 +24,7 @@ export class SortService {
publisher: (book) => book.metadata?.publisher || null,
pageCount: (book) => book.metadata?.pageCount || null,
rating: (book) => book.metadata?.rating || null,
personalRating: (book) => book.metadata?.personalRating || null,
reviewCount: (book) => book.metadata?.reviewCount || null,
amazonRating: (book) => book.metadata?.amazonRating || null,
amazonReviewCount: (book) => book.metadata?.amazonReviewCount || null,
@@ -1,14 +1,17 @@
<div class="dashboard-scroller-container">
<h2 class="dashboard-scroller-title">{{ title }}</h2>
<h2 class="dashboard-scroller-title">
{{ title }}
@if (isMagicShelf) {
<i class="pi pi-sparkles magic-shelf-icon"></i>
}
</h2>
@if (!books || books.length === 0) {
<div class="dashboard-scroller-no-books">
<div class="empty-state-icon">
<i class="pi pi-book"></i>
</div>
<p>
{{ bookListType === 'lastRead' ? "You haven't read any books yet! Start your reading journey." : "No books have been added to BookLore yet! Add your first book to get started." }}
</p>
<p>No books found for this scroller.</p>
</div>
}
@@ -19,7 +22,7 @@
[infiniteScrollThrottle]="50"
#scrollContainer
[horizontal]="true">
@for (book of books; track book) {
@for (book of books; track book.id) {
<div class="dashboard-scroller-card">
<app-book-card [book]="book" [isCheckboxEnabled]="false"></app-book-card>
</div>
@@ -146,6 +146,15 @@
}
}
.magic-shelf-icon {
margin-left: 0.5rem;
color: var(--primary-color) !important;
background: none !important;
-webkit-background-clip: unset !important;
-webkit-text-fill-color: var(--primary-color) !important;
background-clip: unset !important;
}
@media (max-width: 767px) {
.dashboard-scroller-card {
@@ -1,9 +1,10 @@
import {Component, ElementRef, Input, OnChanges, OnInit, ViewChild} from '@angular/core';
import {Component, ElementRef, Input, ViewChild} from '@angular/core';
import {BookCardComponent} from '../../../book/components/book-browser/book-card/book-card.component';
import {InfiniteScrollDirective} from 'ngx-infinite-scroll';
import {ProgressSpinnerModule} from 'primeng/progressspinner';
import {Book} from '../../../book/model/book.model';
import {ScrollerType} from '../../models/dashboard-config.model';
@Component({
selector: 'app-dashboard-scroller',
@@ -18,9 +19,10 @@ import {Book} from '../../../book/model/book.model';
})
export class DashboardScrollerComponent {
@Input() bookListType: 'lastRead' | null = null;
@Input() title: string = 'Last Read Books';
@Input() bookListType: ScrollerType | null = null;
@Input() title!: string;
@Input() books!: Book[] | null;
@Input() isMagicShelf: boolean = false;
@ViewChild('scrollContainer') scrollContainer!: ElementRef;
}
@@ -0,0 +1,141 @@
<div class="dashboard-settings">
<div class="settings-info">
<h3 class="settings-info-title">
<i class="pi pi-info-circle"></i>
Dashboard Configuration
</h3>
<p class="settings-info-text">
Customize your dashboard by adding up to 5 scrollers. Each scroller can display different book collections.
Choose from Continue Reading, Recently Added, Random Discovery, or create custom views using Magic Shelves.
Enable/disable, reorder, and configure the number of items shown in each scroller.
</p>
</div>
<div class="add-scroller-wrapper">
<p-button
label="Add Scroller"
icon="pi pi-plus"
size="small"
(click)="addScroller()"
[disabled]="config.scrollers.length >= 5">
</p-button>
</div>
@for (scroller of config.scrollers; track scroller.id; let i = $index) {
<div class="scroller-item">
<div class="scroller-content">
<div class="scroller-controls-left">
<p-checkbox [(ngModel)]="scroller.enabled" [binary]="true"></p-checkbox>
</div>
<div class="scroller-fields">
<div class="scroller-field">
<label>Type</label>
<p-select
fluid
[options]="availableScrollerTypes"
[(ngModel)]="scroller.type"
(onChange)="onScrollerTypeChange(scroller)"
placeholder="Select type"
appendTo="body">
</p-select>
</div>
<div class="scroller-field" [style.visibility]="scroller.type === 'magicShelf' ? 'visible' : 'hidden'">
<label>Magic Shelf</label>
<p-select
fluid
[options]="magicShelves$ | async"
[(ngModel)]="scroller.magicShelfId"
placeholder="Select magic shelf"
appendTo="body">
</p-select>
</div>
<div class="scroller-field" [style.visibility]="scroller.type === 'magicShelf' ? 'visible' : 'hidden'">
<label>Sort Field</label>
<p-select
fluid
[options]="sortFieldOptions"
[(ngModel)]="scroller.sortField"
placeholder="Select field"
appendTo="body">
</p-select>
</div>
<div class="scroller-field" [style.visibility]="scroller.type === 'magicShelf' ? 'visible' : 'hidden'">
<label>Direction</label>
<p-select
fluid
[options]="sortDirectionOptions"
[(ngModel)]="scroller.sortDirection"
placeholder="Select direction"
appendTo="body">
</p-select>
</div>
<div class="scroller-field">
<label>Max Items</label>
<p-inputNumber
fluid
[(ngModel)]="scroller.maxItems"
[min]="MIN_ITEMS"
[max]="MAX_ITEMS"
[showButtons]="true">
</p-inputNumber>
</div>
</div>
<div class="scroller-controls-right">
<p-button
icon="pi pi-arrow-up"
outlined
rounded
severity="info"
size="small"
[disabled]="i === 0"
(click)="moveUp(i)">
</p-button>
<p-button
icon="pi pi-arrow-down"
outlined
rounded
severity="info"
size="small"
[disabled]="i === config.scrollers.length - 1"
(click)="moveDown(i)">
</p-button>
<p-button
icon="pi pi-trash"
outlined
rounded
size="small"
severity="danger"
(click)="removeScroller(i)"
[disabled]="config.scrollers.length === 1">
</p-button>
</div>
</div>
</div>
}
<div class="footer-actions">
<p-button
label="Reset to Default"
severity="warn"
text
(click)="resetToDefault()">
</p-button>
<p-button
label="Cancel"
outlined
severity="secondary"
(click)="cancel()">
</p-button>
<p-button
label="Save"
severity="success"
(click)="save()">
</p-button>
</div>
</div>
@@ -0,0 +1,166 @@
.dashboard-settings {
width: 1000px;
max-width: 1200px;
min-height: 300px;
padding: 2rem 1rem 0 1rem;
margin: 0 auto;
@media (max-width: 768px) {
width: 100%;
max-width: 100%;
padding: 3rem 1rem 0 1rem;
box-sizing: border-box;
}
}
.scroller-item {
border: var(--card-border);
transition: all 0.2s;
border-color: var(--p-content-border-color);
background: var(--p-content-background);
padding: 1rem;
margin-bottom: 0.75rem;
border-radius: 0.375rem;
@media (max-width: 768px) {
padding: 0.75rem !important;
}
}
.scroller-content {
display: flex;
align-items: flex-end;
gap: 0.75rem;
@media (max-width: 768px) {
flex-direction: column;
align-items: stretch;
gap: 1rem;
}
}
.scroller-controls-left {
display: flex;
align-items: center;
padding-bottom: 0.65rem;
@media (max-width: 768px) {
padding-bottom: 0;
align-self: flex-start;
}
}
.scroller-controls-right {
display: flex;
gap: 0.5rem;
padding-bottom: 0.25rem;
@media (max-width: 768px) {
padding-bottom: 0;
align-self: flex-end;
}
}
.scroller-header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 1rem;
margin-bottom: 1rem;
padding-bottom: 1rem;
border-bottom: 1px solid var(--p-content-border-color);
@media (max-width: 768px) {
flex-direction: column;
align-items: flex-start;
gap: 0.75rem;
}
}
.scroller-fields {
display: grid;
grid-template-columns: minmax(120px, 1fr) minmax(150px, 1.5fr) minmax(120px, 1fr) minmax(100px, 1fr) 90px;
gap: 0.75rem;
flex: 1;
@media (max-width: 768px) {
grid-template-columns: 1fr;
gap: 0.75rem;
}
@media (max-width: 640px) {
gap: 0.5rem;
}
}
.scroller-field {
label {
display: block;
margin-bottom: 0.5rem;
}
}
label {
color: var(--text-color-secondary);
font-size: 0.875rem;
font-weight: 500;
}
.footer-actions {
display: flex;
justify-content: flex-end;
gap: 0.75rem;
margin-top: 2rem;
padding-top: 1.5rem;
border-top: 1px solid var(--p-content-border-color);
@media (max-width: 768px) {
flex-wrap: wrap;
justify-content: stretch;
::ng-deep button {
flex: 1;
}
}
}
.settings-info {
border: 1px solid var(--p-primary-300);
margin-bottom: 2rem;
padding: 0.75rem;
border-radius: 0.375rem;
@media (max-width: 768px) {
padding: 0.75rem !important;
}
}
.settings-info-title {
color: var(--p-primary-600);
font-size: 1.125rem;
font-weight: 600;
margin-bottom: 0.5rem;
i {
margin-right: 0.25rem;
}
@media (max-width: 768px) {
font-size: 1rem;
}
}
.settings-info-text {
margin: 0;
line-height: 1.5;
font-size: 0.875rem;
color: var(--text-color-secondary);
@media (max-width: 768px) {
font-size: 0.813rem;
}
}
.add-scroller-wrapper {
margin-bottom: 1rem;
}
@@ -0,0 +1,179 @@
import {Component, inject, OnInit} from '@angular/core';
import {CommonModule} from '@angular/common';
import {FormsModule} from '@angular/forms';
import {DynamicDialogRef} from 'primeng/dynamicdialog';
import {ButtonModule} from 'primeng/button';
import {CheckboxModule} from 'primeng/checkbox';
import {InputTextModule} from 'primeng/inputtext';
import {SelectModule} from 'primeng/select';
import {InputNumberModule} from 'primeng/inputnumber';
import {DashboardConfig, ScrollerConfig, ScrollerType} from '../../models/dashboard-config.model';
import {DashboardConfigService} from '../../services/dashboard-config.service';
import {MagicShelfService} from '../../../magic-shelf/service/magic-shelf.service';
import {map} from 'rxjs/operators';
export const MAX_SCROLLERS = 5;
export const DEFAULT_MAX_ITEMS = 20;
export const MIN_ITEMS = 10;
export const MAX_ITEMS = 20;
@Component({
selector: 'app-dashboard-settings',
standalone: true,
imports: [
CommonModule,
FormsModule,
ButtonModule,
CheckboxModule,
InputTextModule,
SelectModule,
InputNumberModule
],
templateUrl: './dashboard-settings.component.html',
styleUrls: ['./dashboard-settings.component.scss']
})
export class DashboardSettingsComponent implements OnInit {
private configService = inject(DashboardConfigService);
private dialogRef = inject(DynamicDialogRef);
private magicShelfService = inject(MagicShelfService);
config!: DashboardConfig;
availableScrollerTypes = [
{label: 'Continue Reading', value: ScrollerType.LAST_READ},
{label: 'Recently Added', value: ScrollerType.LATEST_ADDED},
{label: 'Discover Something New', value: ScrollerType.RANDOM},
{label: 'Magic Shelf', value: ScrollerType.MAGIC_SHELF}
];
magicShelves$ = this.magicShelfService.shelvesState$.pipe(
map(state => (state.shelves || []).map(shelf => ({
label: shelf.name,
value: shelf.id!
})))
);
sortFieldOptions = [
{label: 'Title', value: 'title'},
{label: 'Title + Series', value: 'titleSeries'},
{label: 'Date Added', value: 'addedOn'},
{label: 'Author', value: 'author'},
{label: 'Personal Rating', value: 'personalRating'},
{label: 'Publisher', value: 'publisher'},
{label: 'Published Date', value: 'publishedDate'},
{label: 'Last Read', value: 'lastReadTime'},
{label: 'Pages', value: 'pageCount'}
];
sortDirectionOptions = [
{label: 'Ascending', value: 'asc'},
{label: 'Descending', value: 'desc'}
];
private magicShelvesMap = new Map<number, string>();
readonly MIN_ITEMS = MIN_ITEMS;
readonly MAX_ITEMS = MAX_ITEMS;
ngOnInit(): void {
this.configService.config$.subscribe(config => {
this.config = JSON.parse(JSON.stringify(config));
});
this.magicShelfService.shelvesState$.subscribe(state => {
this.magicShelvesMap.clear();
(state.shelves || []).forEach(shelf => {
if (shelf.id) {
this.magicShelvesMap.set(shelf.id, shelf.name);
}
});
});
}
getScrollerTitle(scroller: ScrollerConfig): string {
if (scroller.type === ScrollerType.MAGIC_SHELF && scroller.magicShelfId) {
return this.magicShelvesMap.get(scroller.magicShelfId) || 'Magic Shelf';
}
switch (scroller.type) {
case ScrollerType.LAST_READ:
return 'Continue Reading';
case ScrollerType.LATEST_ADDED:
return 'Recently Added';
case ScrollerType.RANDOM:
return 'Discover Something New';
default:
return 'Scroller';
}
}
addScroller(): void {
if (this.config.scrollers.length >= MAX_SCROLLERS) {
return;
}
const newId = (Math.max(...this.config.scrollers.map((s: ScrollerConfig) => parseInt(s.id)), 0) + 1).toString();
this.config.scrollers.push({
id: newId,
type: ScrollerType.LATEST_ADDED,
title: '',
enabled: true,
order: this.config.scrollers.length + 1,
maxItems: DEFAULT_MAX_ITEMS
});
}
removeScroller(index: number): void {
if (this.config.scrollers.length <= 1) {
return;
}
this.config.scrollers.splice(index, 1);
this.updateOrder();
}
onScrollerTypeChange(scroller: ScrollerConfig): void {
if (scroller.type === ScrollerType.MAGIC_SHELF) {
scroller.magicShelfId = undefined;
} else {
delete scroller.magicShelfId;
}
}
moveUp(index: number): void {
if (index > 0) {
[this.config.scrollers[index], this.config.scrollers[index - 1]] =
[this.config.scrollers[index - 1], this.config.scrollers[index]];
this.updateOrder();
}
}
moveDown(index: number): void {
if (index < this.config.scrollers.length - 1) {
[this.config.scrollers[index], this.config.scrollers[index + 1]] =
[this.config.scrollers[index + 1], this.config.scrollers[index]];
this.updateOrder();
}
}
private updateOrder(): void {
this.config.scrollers.forEach((scroller, index) => {
scroller.order = index + 1;
});
}
save(): void {
this.config.scrollers.forEach(scroller => {
scroller.title = this.getScrollerTitle(scroller);
});
this.configService.saveConfig(this.config);
this.dialogRef.close();
}
cancel(): void {
this.dialogRef.close();
}
resetToDefault(): void {
this.configService.resetToDefault();
this.dialogRef.close();
}
}
@@ -38,21 +38,28 @@
}
</div>
} @else {
<app-dashboard-scroller
[books]="lastReadBooks$ | async"
[bookListType]="'lastRead'"
[title]="'Continue Reading'">
</app-dashboard-scroller>
<div class="dashboard-settings-button">
<p-button
icon="pi pi-cog"
[pTooltip]="'Customize Dashboard'"
tooltipPosition="left"
styleClass="p-button-rounded p-button-text"
(click)="openDashboardSettings()">
</p-button>
</div>
<app-dashboard-scroller
[books]="latestAddedBooks$ | async"
[title]="'Recently Added'">
</app-dashboard-scroller>
<app-dashboard-scroller
[books]="randomBooks$ | async"
[title]="'Discover Something New'">
</app-dashboard-scroller>
@if (dashboardConfig$ | async; as config) {
@for (scroller of config.scrollers; track scroller.id) {
@if (scroller.enabled) {
<app-dashboard-scroller
[bookListType]="scroller.type"
[title]="scroller.title"
[isMagicShelf]="scroller.type === ScrollerType.MAGIC_SHELF"
[books]="getBooksForScroller(scroller) | async">
</app-dashboard-scroller>
}
}
}
}
</div>
</div>
@@ -79,3 +79,35 @@
::ng-deep .p-dialog-mask {
backdrop-filter: blur(3px);
}
.dashboard-settings-button {
position: fixed;
top: 6rem;
right: 2rem;
z-index: 100;
::ng-deep .p-button {
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
backdrop-filter: blur(10px);
background: rgba(var(--p-surface-900-rgb), 0.8);
border: 1px solid var(--p-content-border-color);
&:hover {
background: rgba(var(--p-surface-800-rgb), 0.9);
transform: scale(1.05);
transition: all 0.2s ease;
}
}
}
@media (max-width: 768px) {
.dashboard-settings-button {
top: 5rem;
right: 1rem;
::ng-deep .p-button {
width: 2.5rem;
height: 2.5rem;
}
}
}
@@ -1,9 +1,8 @@
import {Component, inject, OnInit} from '@angular/core';
import {LibraryCreatorComponent} from '../../../library-creator/library-creator.component';
import {DialogService, DynamicDialogRef} from 'primeng/dynamicdialog';
import {DynamicDialogRef} from 'primeng/dynamicdialog';
import {LibraryService} from '../../../book/service/library.service';
import {Observable} from 'rxjs';
import {map} from 'rxjs/operators';
import {map, shareReplay, switchMap} from 'rxjs/operators';
import {Button} from 'primeng/button';
import {AsyncPipe} from '@angular/common';
import {DashboardScrollerComponent} from '../dashboard-scroller/dashboard-scroller.component';
@@ -12,6 +11,18 @@ import {BookState} from '../../../book/model/state/book-state.model';
import {Book, ReadStatus} from '../../../book/model/book.model';
import {UserService} from '../../../settings/user-management/user.service';
import {ProgressSpinner} from 'primeng/progressspinner';
import {TooltipModule} from 'primeng/tooltip';
import {DashboardConfigService} from '../../services/dashboard-config.service';
import {ScrollerConfig, ScrollerType} from '../../models/dashboard-config.model';
import {DashboardSettingsComponent} from '../dashboard-settings/dashboard-settings.component';
import {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 {DialogLauncherService} from '../../../../shared/services/dialog-launcher.service';
import {SortService} from '../../../book/service/sort.service';
import {SortDirection, SortOption} from '../../../book/model/sort.model';
const DEFAULT_MAX_ITEMS = 20;
@Component({
selector: 'app-main-dashboard',
@@ -21,70 +32,171 @@ import {ProgressSpinner} from 'primeng/progressspinner';
Button,
DashboardScrollerComponent,
AsyncPipe,
ProgressSpinner
ProgressSpinner,
TooltipModule
],
providers: [DialogService],
standalone: true
})
export class MainDashboardComponent implements OnInit {
ref: DynamicDialogRef | undefined | null;
private bookService = inject(BookService);
private dialogService = inject(DialogService);
private dialogLauncher = inject(DialogLauncherService);
protected userService = inject(UserService);
private dashboardConfigService = inject(DashboardConfigService);
private magicShelfService = inject(MagicShelfService);
private ruleEvaluatorService = inject(BookRuleEvaluatorService);
private sortService = inject(SortService);
bookState$ = this.bookService.bookState$;
dashboardConfig$ = this.dashboardConfigService.config$;
lastReadBooks$: Observable<Book[]> | undefined;
latestAddedBooks$: Observable<Book[]> | undefined;
randomBooks$: Observable<Book[]> | undefined;
private scrollerBooksCache = new Map<string, Observable<Book[]>>();
isLibrariesEmpty$: Observable<boolean> = inject(LibraryService).libraryState$.pipe(
map(state => !state.libraries || state.libraries.length === 0)
);
ScrollerType = ScrollerType;
ngOnInit(): void {
this.dashboardConfig$.subscribe(() => {
this.scrollerBooksCache.clear();
});
}
this.lastReadBooks$ = this.bookService.bookState$.pipe(
map((state: BookState) => (
(state.books || []).filter(book => book.lastReadTime && (book.readStatus === ReadStatus.READING || book.readStatus === ReadStatus.RE_READING || book.readStatus === ReadStatus.PAUSED))
.sort((a, b) => {
const aTime = new Date(a.lastReadTime!).getTime();
const bTime = new Date(b.lastReadTime!).getTime();
return bTime - aTime;
})
.slice(0, 25)
))
);
private getLastReadBooks(maxItems: number, sortBy?: string): Observable<Book[]> {
return this.bookService.bookState$.pipe(
map((state: BookState) => {
let books = (state.books || []).filter(book =>
book.lastReadTime &&
(book.readStatus === ReadStatus.READING ||
book.readStatus === ReadStatus.RE_READING ||
book.readStatus === ReadStatus.PAUSED)
);
this.latestAddedBooks$ = this.bookService.bookState$.pipe(
map((state: BookState) => (
(state.books || [])
.filter(book => book.addedOn)
.sort((a, b) => {
const aTime = new Date(a.addedOn!).getTime();
const bTime = new Date(b.addedOn!).getTime();
return bTime - aTime;
})
.slice(0, 25)
))
);
books = books.sort((a, b) => {
const aTime = new Date(a.lastReadTime!).getTime();
const bTime = new Date(b.lastReadTime!).getTime();
return bTime - aTime;
});
this.randomBooks$ = this.bookService.bookState$.pipe(
map((state: BookState) => this.getRandomBooks(state.books || [], 15))
return books.slice(0, maxItems);
})
);
}
private getRandomBooks(books: Book[], count: number): Book[] {
const shuffled = books.sort(() => 0.5 - Math.random());
return shuffled.slice(0, count);
private getLatestAddedBooks(maxItems: number, sortBy?: string): Observable<Book[]> {
return this.bookService.bookState$.pipe(
map((state: BookState) => {
let books = (state.books || []).filter(book => book.addedOn);
books = books.sort((a, b) => {
const aTime = new Date(a.addedOn!).getTime();
const bTime = new Date(b.addedOn!).getTime();
return bTime - aTime;
});
return books.slice(0, maxItems);
})
);
}
private getRandomBooks(maxItems: number, sortBy?: string): Observable<Book[]> {
return this.bookService.bookState$.pipe(
map((state: BookState) => {
return this.shuffleBooks(state.books || [], maxItems);
})
);
}
private getMagicShelfBooks(shelfId: number, maxItems?: number, sortBy?: string): Observable<Book[]> {
return this.magicShelfService.getShelf(shelfId).pipe(
switchMap((shelf) => {
if (!shelf) return this.bookService.bookState$.pipe(map(() => []));
let group: GroupRule;
try {
group = JSON.parse(shelf.filterJson);
} catch (e) {
console.error('Invalid filter JSON', e);
return this.bookService.bookState$.pipe(map(() => []));
}
return this.bookService.bookState$.pipe(
map((state: BookState) => {
let filteredBooks = (state.books || []).filter((book) =>
this.ruleEvaluatorService.evaluateGroup(book, group)
);
return maxItems ? filteredBooks.slice(0, maxItems) : filteredBooks;
})
);
})
);
}
getBooksForScroller(config: ScrollerConfig): Observable<Book[]> {
if (!this.scrollerBooksCache.has(config.id)) {
let books$: Observable<Book[]>;
switch (config.type) {
case ScrollerType.LAST_READ:
books$ = this.getLastReadBooks(config.maxItems || DEFAULT_MAX_ITEMS);
break;
case ScrollerType.LATEST_ADDED:
books$ = this.getLatestAddedBooks(config.maxItems || DEFAULT_MAX_ITEMS);
break;
case ScrollerType.RANDOM:
books$ = this.getRandomBooks(config.maxItems || DEFAULT_MAX_ITEMS);
break;
case ScrollerType.MAGIC_SHELF:
books$ = this.getMagicShelfBooks(config.magicShelfId!, config.maxItems).pipe(
map(books => {
if (config.sortField && config.sortDirection) {
const sortOption = this.createSortOption(config.sortField, config.sortDirection);
return this.sortService.applySort(books, sortOption);
}
return books;
})
);
break;
default:
books$ = this.bookService.bookState$.pipe(map(() => []));
}
this.scrollerBooksCache.set(config.id, books$.pipe(shareReplay(1)));
}
return this.scrollerBooksCache.get(config.id)!;
}
private createSortOption(field: string, direction: string): SortOption {
return {
field: field,
direction: direction === 'asc' ? SortDirection.ASCENDING : SortDirection.DESCENDING,
label: ''
};
}
private shuffleBooks(books: Book[], maxItems: number): Book[] {
const shuffled = [...books];
for (let i = shuffled.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
}
return shuffled.slice(0, maxItems);
}
openDashboardSettings(): void {
this.ref = this.dialogLauncher.open({
component: DashboardSettingsComponent,
header: 'Configure Dashboard',
showHeader: false
});
}
createNewLibrary() {
this.ref = this.dialogService.open(LibraryCreatorComponent, {
header: 'Create New Library',
modal: true,
closable: true
});
this.dialogLauncher.openLibraryCreatorDialog();
}
}
@@ -0,0 +1,32 @@
import {DEFAULT_MAX_ITEMS} from '../components/dashboard-settings/dashboard-settings.component';
export enum ScrollerType {
LAST_READ = 'lastRead',
LATEST_ADDED = 'latestAdded',
RANDOM = 'random',
MAGIC_SHELF = 'magicShelf'
}
export interface ScrollerConfig {
id: string;
type: ScrollerType;
title: string;
enabled: boolean;
order: number;
maxItems: number;
magicShelfId?: number;
sortField?: string;
sortDirection?: string;
}
export interface DashboardConfig {
scrollers: ScrollerConfig[];
}
export const DEFAULT_DASHBOARD_CONFIG: DashboardConfig = {
scrollers: [
{id: '1', type: ScrollerType.LAST_READ, title: 'Continue Reading', enabled: true, order: 1, maxItems: DEFAULT_MAX_ITEMS},
{id: '2', type: ScrollerType.LATEST_ADDED, title: 'Recently Added', enabled: true, order: 2, maxItems: DEFAULT_MAX_ITEMS},
{id: '3', type: ScrollerType.RANDOM, title: 'Discover Something New', enabled: true, order: 3, maxItems: DEFAULT_MAX_ITEMS}
]
};
@@ -0,0 +1,41 @@
import {Injectable} from '@angular/core';
import {BehaviorSubject, Observable} from 'rxjs';
import {DashboardConfig, DEFAULT_DASHBOARD_CONFIG} from '../models/dashboard-config.model';
import {UserService} from '../../settings/user-management/user.service';
import {filter, take} from 'rxjs/operators';
@Injectable({
providedIn: 'root'
})
export class DashboardConfigService {
private configSubject = new BehaviorSubject<DashboardConfig>(DEFAULT_DASHBOARD_CONFIG);
public config$: Observable<DashboardConfig> = this.configSubject.asObservable();
constructor(private userService: UserService) {
this.userService.userState$
.pipe(
filter(userState => !!userState?.user && userState.loaded),
take(1)
)
.subscribe(userState => {
const dashboardConfig = userState.user?.userSettings?.dashboardConfig as DashboardConfig;
if (dashboardConfig) {
this.configSubject.next(dashboardConfig);
}
});
}
saveConfig(config: DashboardConfig): void {
this.configSubject.next(config);
const user = this.userService.getCurrentUser();
if (user) {
this.userService.updateUserSetting(user.id, 'dashboardConfig', config);
}
}
resetToDefault(): void {
this.saveConfig(DEFAULT_DASHBOARD_CONFIG);
}
}
@@ -93,7 +93,7 @@
<p-multiSelect [options]="libraryOptions" formControlName="value" display="chip" class="w-full" appendTo="body" placeholder="Select Libraries"></p-multiSelect>
} @else {
<div class="w-full">
<p-autoComplete [formControl]="ruleCtrl.get('value')" [multiple]="true" [typeahead]="false" [dropdown]="false" [forceSelection]="false" class="w-full" placeholder="Enter values (press Enter or comma)" (onBlur)="onAutoCompleteBlur(ruleCtrl.get('value'), $event)"></p-autoComplete>
<p-autoComplete [formControl]="ruleCtrl.get('value')" [multiple]="true" [typeahead]="false" [dropdown]="false" [forceSelection]="false" class="w-full" placeholder="Enter values (press Enter)" (onBlur)="onAutoCompleteBlur(ruleCtrl.get('value'), $event)"></p-autoComplete>
</div>
}
} @else if (ruleCtrl.get('field')?.value === 'readStatus') {
@@ -90,21 +90,37 @@ export class BookRuleEvaluatorService {
return value !== ruleVal;
case 'contains':
if (Array.isArray(value)) {
if (typeof ruleVal !== 'string') return false;
return value.some(v => String(v).includes(ruleVal));
}
if (typeof value !== 'string') return false;
if (typeof ruleVal !== 'string') return false;
return value.includes(ruleVal);
case 'does_not_contain':
if (Array.isArray(value)) {
if (typeof ruleVal !== 'string') return true;
return value.every(v => !String(v).includes(ruleVal));
}
if (typeof value !== 'string') return true;
if (typeof ruleVal !== 'string') return true;
return !value.includes(ruleVal);
case 'starts_with':
if (Array.isArray(value)) {
if (typeof ruleVal !== 'string') return false;
return value.some(v => String(v).startsWith(ruleVal));
}
if (typeof value !== 'string') return false;
if (typeof ruleVal !== 'string') return false;
return value.startsWith(ruleVal);
case 'ends_with':
if (Array.isArray(value)) {
if (typeof ruleVal !== 'string') return false;
return value.some(v => String(v).endsWith(ruleVal));
}
if (typeof value !== 'string') return false;
if (typeof ruleVal !== 'string') return false;
return value.endsWith(ruleVal);
@@ -5,6 +5,7 @@ import {API_CONFIG} from '../../../core/config/api-config';
import {Library} from '../../book/model/library.model';
import {catchError, distinctUntilChanged, finalize, shareReplay, tap} from 'rxjs/operators';
import {AuthService} from '../../../shared/service/auth.service';
import {DashboardConfig} from '../../dashboard/models/dashboard-config.model';
export interface EntityViewPreferences {
global: EntityViewPreference;
@@ -130,6 +131,7 @@ export interface UserSettings {
metadataCenterViewMode: 'route' | 'dialog';
entityViewPreferences: EntityViewPreferences;
tableColumnPreference?: TableColumnPreference[];
dashboardConfig?: DashboardConfig;
koReaderEnabled: boolean;
}
@@ -218,17 +220,17 @@ export class UserService {
private fetchMyself(): Observable<User> {
return this.http.get<User>(`${this.userUrl}/me`).pipe(
tap(user => this.userStateSubject.next({ user, loaded: true, error: null })),
tap(user => this.userStateSubject.next({user, loaded: true, error: null})),
catchError(err => {
const curr = this.userStateSubject.value;
this.userStateSubject.next({ user: curr.user, loaded: true, error: err.message });
this.userStateSubject.next({user: curr.user, loaded: true, error: err.message});
throw err;
})
);
}
public setInitialUser(user: User): void {
this.userStateSubject.next({ user, loaded: true, error: null });
this.userStateSubject.next({user, loaded: true, error: null});
}
getCurrentUser(): User | null {
@@ -13,16 +13,14 @@ export class DialogLauncherService {
dialogService = inject(DialogService);
open(options: { component: any; header: string; top?: string; width?: string }): DynamicDialogRef | null {
open(options: { component: any; header: string; top?: string; width?: string; showHeader?: boolean }): DynamicDialogRef | null {
const isMobile = window.innerWidth <= 768;
const {component, header, top, width} = options;
const {component, header, top, width, showHeader = true} = options;
return this.dialogService.open(component, {
header,
showHeader,
modal: true,
closable: true,
contentStyle: {
overflowY: 'hidden',
},
style: {
position: 'absolute',
...(top ? {top} : {}),