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:
+49
@@ -0,0 +1,49 @@
|
||||
<ng-container *transloco="let t; prefix: 'dashboard.scroller'">
|
||||
<div class="dashboard-scroller-container">
|
||||
<h2 class="dashboard-scroller-title">
|
||||
{{ title | transloco }}
|
||||
@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>{{ t('noBooksFound') }}</p>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (books) {
|
||||
<div class="dashboard-scroller-infinite"
|
||||
infiniteScroll
|
||||
[infiniteScrollDistance]="2"
|
||||
[infiniteScrollThrottle]="50"
|
||||
#scrollContainer
|
||||
[horizontal]="true">
|
||||
@for (book of books; track book.id) {
|
||||
<div class="dashboard-scroller-card" [ngClass]="{'menu-open': openMenuBookId === book.id, 'square-card': useSquareCovers}">
|
||||
<app-book-card
|
||||
[book]="book"
|
||||
[isCheckboxEnabled]="false"
|
||||
[forceEbookMode]="forceEbookMode"
|
||||
(menuToggled)="handleMenuToggle(book.id, $event)"
|
||||
[overlayPreferenceService]="bookCardOverlayPreferenceService"
|
||||
></app-book-card>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (books === null) {
|
||||
<div class="dashboard-scroller-error">
|
||||
<div class="error-icon">
|
||||
<i class="pi pi-exclamation-triangle"></i>
|
||||
</div>
|
||||
<p>{{ t('loadError') }}</p>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</ng-container>
|
||||
+218
@@ -0,0 +1,218 @@
|
||||
.dashboard-scroller-container {
|
||||
border-radius: 20px;
|
||||
padding: 1rem 2rem 0rem 2rem;
|
||||
margin-bottom: 2rem;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
backdrop-filter: blur(20px);
|
||||
border: color-mix(in srgb, var(--p-surface-500), transparent 50%) 1px solid;
|
||||
}
|
||||
|
||||
.dashboard-scroller-title {
|
||||
text-align: left;
|
||||
font-size: 1.5rem;
|
||||
font-weight: 800;
|
||||
margin-bottom: 1rem;
|
||||
padding: 0;
|
||||
background: linear-gradient(135deg, #ffffff, #e2e8f0, #3b82f6);
|
||||
-webkit-background-clip: text;
|
||||
-webkit-text-fill-color: transparent;
|
||||
background-clip: text;
|
||||
position: relative;
|
||||
z-index: 2;
|
||||
letter-spacing: -0.02em;
|
||||
|
||||
&::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
bottom: -6px;
|
||||
left: 0;
|
||||
width: 80px;
|
||||
height: 4px;
|
||||
background: linear-gradient(90deg, var(--primary-color), var(--primary-color));
|
||||
border-radius: 2px;
|
||||
}
|
||||
}
|
||||
|
||||
.dashboard-scroller-no-books {
|
||||
padding: 3rem 2rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
position: relative;
|
||||
z-index: 2;
|
||||
|
||||
.empty-state-icon {
|
||||
width: 25px;
|
||||
height: 25px;
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-bottom: 2rem;
|
||||
position: relative;
|
||||
|
||||
i {
|
||||
font-size: 2rem;
|
||||
color: white;
|
||||
filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
|
||||
}
|
||||
}
|
||||
|
||||
p {
|
||||
color: #e2e8f0;
|
||||
font-size: 1rem;
|
||||
font-weight: 500;
|
||||
max-width: 400px;
|
||||
line-height: 1.7;
|
||||
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
}
|
||||
|
||||
.dashboard-scroller-infinite {
|
||||
display: flex;
|
||||
overflow-x: auto;
|
||||
overflow-y: hidden;
|
||||
scroll-snap-type: x mandatory;
|
||||
padding: 1rem 0.5rem 1rem 0.5rem;
|
||||
gap: 2rem;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
position: relative;
|
||||
z-index: 2;
|
||||
|
||||
scrollbar-color: var(--primary-color) rgba(20, 20, 30, 0.5);
|
||||
}
|
||||
|
||||
.dashboard-scroller-card {
|
||||
height: 200px;
|
||||
width: 116px;
|
||||
flex-basis: 124px;
|
||||
flex-shrink: 0;
|
||||
flex-grow: 0;
|
||||
scroll-snap-align: start;
|
||||
transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
position: relative;
|
||||
|
||||
&.square-card {
|
||||
width: 160px;
|
||||
height: auto;
|
||||
flex-basis: 160px;
|
||||
|
||||
::ng-deep .cover-container.audiobook-cover {
|
||||
aspect-ratio: 1/1 !important;
|
||||
flex: none;
|
||||
}
|
||||
}
|
||||
|
||||
&:hover, &.menu-open {
|
||||
transform: translateY(-4px) scale(1.04);
|
||||
filter: drop-shadow(0 25px 50px rgba(0, 0, 0, 0.4));
|
||||
|
||||
&::after {
|
||||
opacity: 1;
|
||||
transform: scale(1.2);
|
||||
}
|
||||
|
||||
&::before {
|
||||
opacity: 0.8;
|
||||
}
|
||||
}
|
||||
|
||||
&::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
inset: -2px;
|
||||
background: linear-gradient(
|
||||
135deg,
|
||||
color-mix(in srgb, var(--p-primary-400), transparent 70%),
|
||||
color-mix(in srgb, var(--p-primary-800), transparent 70%)
|
||||
);
|
||||
border-radius: 12px;
|
||||
z-index: -1;
|
||||
opacity: 0;
|
||||
transition: opacity 0.4s ease;
|
||||
filter: blur(8px);
|
||||
}
|
||||
|
||||
&::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
bottom: -8px;
|
||||
left: 10%;
|
||||
right: 10%;
|
||||
height: 5px;
|
||||
background: linear-gradient(
|
||||
90deg,
|
||||
transparent,
|
||||
var(--p-primary-500),
|
||||
transparent
|
||||
);
|
||||
border-radius: 50%;
|
||||
opacity: 0;
|
||||
transition: all 0.4s ease;
|
||||
filter: blur(6px);
|
||||
}
|
||||
|
||||
// Audiobook covers should fill the container height
|
||||
::ng-deep {
|
||||
app-book-card {
|
||||
display: block;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.book-card {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.cover-container.audiobook-cover {
|
||||
aspect-ratio: unset;
|
||||
flex: 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.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 {
|
||||
height: 184px;
|
||||
width: 108px;
|
||||
flex-basis: 108px;
|
||||
|
||||
&.square-card {
|
||||
width: 150px;
|
||||
height: auto;
|
||||
flex-basis: 150px;
|
||||
}
|
||||
}
|
||||
|
||||
.dashboard-scroller-no-books {
|
||||
padding: 4rem 1rem;
|
||||
|
||||
.empty-state-icon {
|
||||
width: 80px;
|
||||
height: 80px;
|
||||
|
||||
i {
|
||||
font-size: 2rem;
|
||||
}
|
||||
}
|
||||
|
||||
p {
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
import {ChangeDetectionStrategy, Component, ElementRef, Input, ViewChild, inject} from '@angular/core';
|
||||
import {BookCardComponent} from '../../../book/components/book-browser/book-card/book-card.component';
|
||||
import {InfiniteScrollDirective} from 'ngx-infinite-scroll';
|
||||
import {NgClass} from '@angular/common';
|
||||
|
||||
import {ProgressSpinnerModule} from 'primeng/progressspinner';
|
||||
import {Book} from '../../../book/model/book.model';
|
||||
import {ScrollerType} from '../../models/dashboard-config.model';
|
||||
import { BookCardOverlayPreferenceService } from '../../../book/components/book-browser/book-card-overlay-preference.service';
|
||||
import {TranslocoDirective, TranslocoPipe} from '@jsverse/transloco';
|
||||
|
||||
@Component({
|
||||
selector: 'app-dashboard-scroller',
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
templateUrl: './dashboard-scroller.component.html',
|
||||
styleUrls: ['./dashboard-scroller.component.scss'],
|
||||
imports: [
|
||||
InfiniteScrollDirective,
|
||||
BookCardComponent,
|
||||
ProgressSpinnerModule,
|
||||
NgClass,
|
||||
TranslocoDirective,
|
||||
TranslocoPipe
|
||||
],
|
||||
standalone: true
|
||||
})
|
||||
export class DashboardScrollerComponent {
|
||||
|
||||
@Input() bookListType: ScrollerType | null = null;
|
||||
@Input() title!: string;
|
||||
@Input() books!: Book[] | null;
|
||||
@Input() isMagicShelf: boolean = false;
|
||||
@Input() useSquareCovers: boolean = false;
|
||||
|
||||
@ViewChild('scrollContainer') scrollContainer!: ElementRef;
|
||||
openMenuBookId: number | null = null;
|
||||
|
||||
public bookCardOverlayPreferenceService = inject(BookCardOverlayPreferenceService);
|
||||
|
||||
get forceEbookMode(): boolean {
|
||||
return this.bookListType === ScrollerType.LAST_READ;
|
||||
}
|
||||
|
||||
handleMenuToggle(bookId: number, isOpen: boolean) {
|
||||
this.openMenuBookId = isOpen ? bookId : null;
|
||||
}
|
||||
}
|
||||
+161
@@ -0,0 +1,161 @@
|
||||
<ng-container *transloco="let t; prefix: 'dashboard.settings'">
|
||||
<div class="dashboard-settings">
|
||||
<div class="panel-header">
|
||||
<div class="header-icon-wrapper">
|
||||
<i class="pi pi-sliders-h 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)="cancel()"
|
||||
class="close-button"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="scrollers-container">
|
||||
@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" [class.expanded]="scroller.type !== 'magicShelf'">
|
||||
<label [for]="'dashboard-scroller-type-' + scroller.id">{{ t('type') }}</label>
|
||||
<p-select
|
||||
fluid
|
||||
[inputId]="'dashboard-scroller-type-' + scroller.id"
|
||||
[options]="availableScrollerTypes"
|
||||
[(ngModel)]="scroller.type"
|
||||
(onChange)="onScrollerTypeChange(scroller)"
|
||||
[placeholder]="t('selectType')"
|
||||
appendTo="body">
|
||||
</p-select>
|
||||
</div>
|
||||
|
||||
@if (scroller.type === 'magicShelf') {
|
||||
<div class="scroller-field">
|
||||
<label [for]="'dashboard-scroller-magic-shelf-' + scroller.id">{{ t('magicShelf') }}</label>
|
||||
<p-select
|
||||
fluid
|
||||
[inputId]="'dashboard-scroller-magic-shelf-' + scroller.id"
|
||||
[options]="magicShelves()"
|
||||
[(ngModel)]="scroller.magicShelfId"
|
||||
[placeholder]="t('selectMagicShelf')"
|
||||
appendTo="body">
|
||||
</p-select>
|
||||
</div>
|
||||
|
||||
<div class="scroller-field">
|
||||
<label [for]="'dashboard-scroller-sort-field-' + scroller.id">{{ t('sortField') }}</label>
|
||||
<p-select
|
||||
fluid
|
||||
[inputId]="'dashboard-scroller-sort-field-' + scroller.id"
|
||||
[options]="sortFieldOptions"
|
||||
[(ngModel)]="scroller.sortField"
|
||||
[placeholder]="t('selectField')"
|
||||
appendTo="body">
|
||||
</p-select>
|
||||
</div>
|
||||
|
||||
<div class="scroller-field">
|
||||
<label [for]="'dashboard-scroller-sort-direction-' + scroller.id">{{ t('direction') }}</label>
|
||||
<p-select
|
||||
fluid
|
||||
[inputId]="'dashboard-scroller-sort-direction-' + scroller.id"
|
||||
[options]="sortDirectionOptions"
|
||||
[(ngModel)]="scroller.sortDirection"
|
||||
[placeholder]="t('selectDirection')"
|
||||
appendTo="body">
|
||||
</p-select>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="scroller-field max-items-field">
|
||||
<label [for]="'dashboard-scroller-max-items-' + scroller.id">{{ t('maxItems') }}</label>
|
||||
<p-inputNumber
|
||||
fluid
|
||||
[inputId]="'dashboard-scroller-max-items-' + scroller.id"
|
||||
[(ngModel)]="scroller.maxItems"
|
||||
[min]="MIN_ITEMS"
|
||||
[max]="MAX_ITEMS"
|
||||
[showButtons]="true">
|
||||
</p-inputNumber>
|
||||
</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>
|
||||
|
||||
<div class="dialog-footer">
|
||||
<div class="footer-left">
|
||||
<p-button
|
||||
[label]="t('addScroller')"
|
||||
icon="pi pi-plus"
|
||||
severity="primary"
|
||||
(click)="addScroller()"
|
||||
[disabled]="config.scrollers.length >= 5">
|
||||
</p-button>
|
||||
<p-button
|
||||
[label]="t('resetToDefault')"
|
||||
icon="pi pi-refresh"
|
||||
severity="secondary"
|
||||
text
|
||||
(click)="resetToDefault()">
|
||||
</p-button>
|
||||
</div>
|
||||
<div class="footer-actions">
|
||||
<p-button
|
||||
[label]="'common.cancel' | transloco"
|
||||
[outlined]="true"
|
||||
severity="secondary"
|
||||
(click)="cancel()">
|
||||
</p-button>
|
||||
<p-button
|
||||
[label]="'common.save' | transloco"
|
||||
icon="pi pi-check"
|
||||
severity="success"
|
||||
(click)="save()">
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
+225
@@ -0,0 +1,225 @@
|
||||
@use '../../../../shared/styles/panel-shared' as panel;
|
||||
|
||||
.dashboard-settings {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
@media (max-width: 640px) {
|
||||
width: 100%;
|
||||
max-width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.panel-header {
|
||||
@include panel.panel-header;
|
||||
}
|
||||
|
||||
.settings-controls {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
padding: 1rem 2rem;
|
||||
background: var(--card-background);
|
||||
border: 1px solid var(--border-color);
|
||||
border-top: none;
|
||||
|
||||
.settings-info {
|
||||
.info-content {
|
||||
display: flex;
|
||||
gap: 0.75rem;
|
||||
padding: 0.75rem;
|
||||
background: var(--overlay-background);
|
||||
border-radius: 6px;
|
||||
border: 1px solid var(--p-primary-300);
|
||||
|
||||
.info-icon {
|
||||
color: var(--primary-color);
|
||||
font-size: 1.125rem;
|
||||
flex-shrink: 0;
|
||||
margin-top: 0.125rem;
|
||||
}
|
||||
|
||||
.info-text {
|
||||
flex: 1;
|
||||
|
||||
p {
|
||||
margin: 0;
|
||||
line-height: 1.5;
|
||||
font-size: 0.875rem;
|
||||
color: var(--text-color-secondary);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
padding: 1rem;
|
||||
gap: 0.5rem;
|
||||
|
||||
.settings-info {
|
||||
.info-content {
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.scrollers-container {
|
||||
padding: 1.5rem 2rem;
|
||||
background: var(--card-background);
|
||||
border: 1px solid var(--border-color);
|
||||
border-top: none;
|
||||
min-height: 200px;
|
||||
max-height: 450px;
|
||||
overflow-y: auto;
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
width: 6px;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-track {
|
||||
background: var(--overlay-background);
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-thumb {
|
||||
background: var(--border-color);
|
||||
border-radius: 3px;
|
||||
|
||||
&:hover {
|
||||
background: var(--primary-color);
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
padding: 1rem;
|
||||
max-height: 400px;
|
||||
}
|
||||
}
|
||||
|
||||
.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-fields {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
|
||||
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;
|
||||
}
|
||||
|
||||
&.expanded {
|
||||
flex: 1;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
flex: unset;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.max-items-field {
|
||||
max-width: 9rem;
|
||||
flex-shrink: 0;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
max-width: none;
|
||||
}
|
||||
}
|
||||
|
||||
label {
|
||||
color: var(--text-color-secondary);
|
||||
font-size: 0.875rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.dialog-footer {
|
||||
@include panel.dialog-footer;
|
||||
border-top: none;
|
||||
|
||||
.footer-left {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.footer-left {
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
|
||||
::ng-deep .p-button {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.footer-actions {
|
||||
::ng-deep .p-button {
|
||||
flex: 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.add-scroller-wrapper {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
+206
@@ -0,0 +1,206 @@
|
||||
import {Component, computed, effect, inject} from '@angular/core';
|
||||
import {toSignal} from '@angular/core/rxjs-interop';
|
||||
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 {TranslocoDirective, TranslocoPipe, TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
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,
|
||||
TranslocoDirective,
|
||||
TranslocoPipe
|
||||
],
|
||||
templateUrl: './dashboard-settings.component.html',
|
||||
styleUrls: ['./dashboard-settings.component.scss']
|
||||
})
|
||||
export class DashboardSettingsComponent {
|
||||
private configService = inject(DashboardConfigService);
|
||||
private dialogRef = inject(DynamicDialogRef);
|
||||
private magicShelfService = inject(MagicShelfService);
|
||||
private translocoService = inject(TranslocoService);
|
||||
private readonly activeLanguage = toSignal(this.translocoService.langChanges$, {
|
||||
initialValue: this.translocoService.getActiveLang()
|
||||
});
|
||||
|
||||
config: DashboardConfig = structuredClone(this.configService.config());
|
||||
|
||||
availableScrollerTypes: {label: string; value: ScrollerType}[] = [];
|
||||
sortFieldOptions: {label: string; value: string}[] = [];
|
||||
sortDirectionOptions: {label: string; value: string}[] = [];
|
||||
|
||||
magicShelves = computed(() =>
|
||||
this.magicShelfService.shelves().map(shelf => ({
|
||||
label: shelf.name,
|
||||
value: shelf.id!
|
||||
}))
|
||||
);
|
||||
private magicShelvesMap = computed(() => {
|
||||
const shelfMap = new Map<number, string>();
|
||||
this.magicShelfService.shelves().forEach(shelf => {
|
||||
if (shelf.id) {
|
||||
shelfMap.set(shelf.id, shelf.name);
|
||||
}
|
||||
});
|
||||
return shelfMap;
|
||||
});
|
||||
|
||||
readonly MIN_ITEMS = MIN_ITEMS;
|
||||
readonly MAX_ITEMS = MAX_ITEMS;
|
||||
|
||||
private readonly syncTranslatedOptionsEffect = effect(() => {
|
||||
this.activeLanguage();
|
||||
this.buildTranslatedOptions();
|
||||
});
|
||||
|
||||
private readonly syncConfigEffect = effect(() => {
|
||||
this.config = structuredClone(this.configService.config());
|
||||
});
|
||||
|
||||
private buildTranslatedOptions(): void {
|
||||
const t = (key: string) => this.translocoService.translate(`dashboard.settings.${key}`);
|
||||
|
||||
this.availableScrollerTypes = [
|
||||
{label: t('scrollerTypes.lastRead'), value: ScrollerType.LAST_READ},
|
||||
{label: t('scrollerTypes.lastListened'), value: ScrollerType.LAST_LISTENED},
|
||||
{label: t('scrollerTypes.latestAdded'), value: ScrollerType.LATEST_ADDED},
|
||||
{label: t('scrollerTypes.random'), value: ScrollerType.RANDOM},
|
||||
{label: t('scrollerTypes.magicShelf'), value: ScrollerType.MAGIC_SHELF}
|
||||
];
|
||||
|
||||
this.sortFieldOptions = [
|
||||
{label: t('sortFields.title'), value: 'title'},
|
||||
{label: t('sortFields.fileName'), value: 'fileName'},
|
||||
{label: t('sortFields.filePath'), value: 'filePath'},
|
||||
{label: t('sortFields.addedOn'), value: 'addedOn'},
|
||||
{label: t('sortFields.author'), value: 'author'},
|
||||
{label: t('sortFields.authorSurnameVorname'), value: 'authorSurnameVorname'},
|
||||
{label: t('sortFields.seriesName'), value: 'seriesName'},
|
||||
{label: t('sortFields.seriesNumber'), value: 'seriesNumber'},
|
||||
{label: t('sortFields.personalRating'), value: 'personalRating'},
|
||||
{label: t('sortFields.publisher'), value: 'publisher'},
|
||||
{label: t('sortFields.publishedDate'), value: 'publishedDate'},
|
||||
{label: t('sortFields.lastReadTime'), value: 'lastReadTime'},
|
||||
{label: t('sortFields.readStatus'), value: 'readStatus'},
|
||||
{label: t('sortFields.dateFinished'), value: 'dateFinished'},
|
||||
{label: t('sortFields.readingProgress'), value: 'readingProgress'},
|
||||
{label: t('sortFields.bookType'), value: 'bookType'},
|
||||
{label: t('sortFields.pageCount'), value: 'pageCount'}
|
||||
];
|
||||
|
||||
this.sortDirectionOptions = [
|
||||
{label: t('sortDirections.asc'), value: 'asc'},
|
||||
{label: t('sortDirections.desc'), value: 'desc'}
|
||||
];
|
||||
}
|
||||
|
||||
getScrollerTitle(scroller: ScrollerConfig): string {
|
||||
if (scroller.type === ScrollerType.MAGIC_SHELF && scroller.magicShelfId) {
|
||||
return this.magicShelvesMap().get(scroller.magicShelfId) || 'dashboard.scroller.magicShelf';
|
||||
}
|
||||
|
||||
switch (scroller.type) {
|
||||
case ScrollerType.LAST_READ:
|
||||
return 'dashboard.scroller.continueReading';
|
||||
case ScrollerType.LAST_LISTENED:
|
||||
return 'dashboard.scroller.continueListening';
|
||||
case ScrollerType.LATEST_ADDED:
|
||||
return 'dashboard.scroller.recentlyAdded';
|
||||
case ScrollerType.RANDOM:
|
||||
return 'dashboard.scroller.discoverNew';
|
||||
default:
|
||||
return 'dashboard.scroller.default';
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
<ng-container *transloco="let t; prefix: 'dashboard.main'">
|
||||
<div class="dashboard-container">
|
||||
@if (isBooksLoading()) {
|
||||
<div class="loading-state">
|
||||
<p-progressSpinner
|
||||
class="spinner center-spinner"
|
||||
[style]="{'width': '60px', 'height': '60px'}"
|
||||
strokeWidth="3"
|
||||
fill="transparent"
|
||||
animationDuration="1.5s">
|
||||
</p-progressSpinner>
|
||||
</div>
|
||||
} @else {
|
||||
<div class="dashboard">
|
||||
<div class="dashboard-inner">
|
||||
@if (isLibrariesEmpty()) {
|
||||
<div class="dashboard-no-library">
|
||||
@if (userService.currentUser()?.permissions; as permissions) {
|
||||
<div>
|
||||
@if (permissions.admin || permissions.canManageLibrary) {
|
||||
<div>
|
||||
<h1 class="no-library-header">
|
||||
{{ t('welcomeTitle') }}<br>
|
||||
{{ t('welcomeSubtitle') }}
|
||||
</h1>
|
||||
<p class="welcome-description">
|
||||
{{ t('welcomeDescription') }}
|
||||
</p>
|
||||
<p-button
|
||||
[label]="t('createLibrary')"
|
||||
icon="pi pi-plus"
|
||||
class="p-button-rounded p-button-outlined"
|
||||
(click)="createNewLibrary()">
|
||||
</p-button>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
} @else {
|
||||
<div class="dashboard-settings-button">
|
||||
<p-button
|
||||
icon="pi pi-cog"
|
||||
severity="info"
|
||||
rounded
|
||||
text
|
||||
[pTooltip]="t('customizeDashboard')"
|
||||
tooltipPosition="left"
|
||||
(click)="openDashboardSettings()">
|
||||
</p-button>
|
||||
</div>
|
||||
|
||||
@if (dashboardConfig(); 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"
|
||||
[useSquareCovers]="scroller.type === ScrollerType.LAST_LISTENED"
|
||||
[books]="getBooksForScroller(scroller)">
|
||||
</app-dashboard-scroller>
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</ng-container>
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
.dashboard-container {
|
||||
height: calc(100dvh - 6.7rem);
|
||||
overflow-y: auto;
|
||||
position: relative;
|
||||
|
||||
&::before {
|
||||
content: '';
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
pointer-events: none;
|
||||
z-index: 0;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
width: 12px;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-track {
|
||||
background: rgba(20, 20, 30, 0.5);
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
scrollbar-width: thin;
|
||||
scrollbar-color: var(--primary-color) rgba(20, 20, 30, 0.5);
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.dashboard-container {
|
||||
height: calc(100dvh - 5rem);
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
width: 8px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.dashboard {
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
text-align: center;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.loading-state {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.dashboard-inner {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.welcome-description {
|
||||
color: #d1d5db;
|
||||
margin-bottom: 2rem;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
line-height: 1.625;
|
||||
}
|
||||
|
||||
.dashboard .no-library-header {
|
||||
font-size: 1.75rem;
|
||||
font-weight: 700;
|
||||
margin-bottom: 2rem;
|
||||
background: linear-gradient(135deg, #ffffff, #e2e8f0, var(--p-primary-500));
|
||||
-webkit-background-clip: text;
|
||||
-webkit-text-fill-color: transparent;
|
||||
background-clip: text;
|
||||
text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
|
||||
letter-spacing: -0.02em;
|
||||
}
|
||||
|
||||
.dashboard-no-library {
|
||||
padding: 3rem;
|
||||
background: var(--p-surface-900);
|
||||
border-radius: 24px;
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
backdrop-filter: blur(20px);
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.dashboard .p-dialog {
|
||||
max-width: 90%;
|
||||
}
|
||||
|
||||
::ng-deep .p-dialog-mask {
|
||||
background-color: rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
|
||||
::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;
|
||||
}
|
||||
}
|
||||
}
|
||||
+210
@@ -0,0 +1,210 @@
|
||||
import {Component, computed, inject, OnInit} from '@angular/core';
|
||||
import {Button} from 'primeng/button';
|
||||
import {DashboardScrollerComponent} from '../dashboard-scroller/dashboard-scroller.component';
|
||||
import {BookService} from '../../../book/service/book.service';
|
||||
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 {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
import {DashboardConfigService} from '../../services/dashboard-config.service';
|
||||
import {ScrollerConfig, ScrollerType} from '../../models/dashboard-config.model';
|
||||
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 {PageTitleService} from '../../../../shared/service/page-title.service';
|
||||
import {SortDirection, SortOption} from '../../../book/model/sort.model';
|
||||
import {LibraryService} from '../../../book/service/library.service';
|
||||
|
||||
const DEFAULT_MAX_ITEMS = 20;
|
||||
|
||||
@Component({
|
||||
selector: 'app-main-dashboard',
|
||||
templateUrl: './main-dashboard.component.html',
|
||||
styleUrls: ['./main-dashboard.component.scss'],
|
||||
imports: [
|
||||
Button,
|
||||
DashboardScrollerComponent,
|
||||
ProgressSpinner,
|
||||
TooltipModule,
|
||||
TranslocoDirective
|
||||
],
|
||||
standalone: true
|
||||
})
|
||||
export class MainDashboardComponent implements OnInit {
|
||||
|
||||
private bookService = inject(BookService);
|
||||
private libraryService = inject(LibraryService);
|
||||
private dialogLauncher = inject(DialogLauncherService);
|
||||
protected userService = inject(UserService);
|
||||
private dashboardConfigService = inject(DashboardConfigService);
|
||||
private magicShelfService = inject(MagicShelfService);
|
||||
private ruleEvaluatorService = inject(BookRuleEvaluatorService);
|
||||
private sortService = inject(SortService);
|
||||
private pageTitle = inject(PageTitleService);
|
||||
private readonly t = inject(TranslocoService);
|
||||
|
||||
readonly dashboardConfig = this.dashboardConfigService.config;
|
||||
readonly isBooksLoading = this.bookService.isBooksLoading;
|
||||
readonly isLibrariesEmpty = computed(() =>
|
||||
!this.libraryService.isLibrariesLoading() && this.libraryService.libraries().length === 0
|
||||
);
|
||||
readonly scrollerBooks = computed(() => {
|
||||
const config = this.dashboardConfig();
|
||||
const books = this.bookService.books();
|
||||
const scrollerMap = new Map<string, Book[]>();
|
||||
|
||||
for (const scroller of config.scrollers) {
|
||||
scrollerMap.set(scroller.id, this.getBooksForConfig(scroller, books, this.magicShelfService.shelves()));
|
||||
}
|
||||
|
||||
return scrollerMap;
|
||||
});
|
||||
|
||||
ScrollerType = ScrollerType;
|
||||
|
||||
ngOnInit(): void {
|
||||
this.pageTitle.setPageTitle(this.t.translate('dashboard.main.pageTitle'));
|
||||
}
|
||||
|
||||
getBooksForScroller(config: ScrollerConfig): Book[] {
|
||||
return this.scrollerBooks().get(config.id) ?? [];
|
||||
}
|
||||
|
||||
private getBooksForConfig(config: ScrollerConfig, books: Book[], magicShelves: {id?: number | null; filterJson: string}[]): Book[] {
|
||||
switch (config.type) {
|
||||
case ScrollerType.LAST_READ:
|
||||
return this.getLastReadBooks(books, config.maxItems || DEFAULT_MAX_ITEMS);
|
||||
case ScrollerType.LAST_LISTENED:
|
||||
return this.getLastListenedBooks(books, config.maxItems || DEFAULT_MAX_ITEMS);
|
||||
case ScrollerType.LATEST_ADDED:
|
||||
return this.getLatestAddedBooks(books, config.maxItems || DEFAULT_MAX_ITEMS);
|
||||
case ScrollerType.RANDOM:
|
||||
return this.getRandomBooks(books, config.maxItems || DEFAULT_MAX_ITEMS);
|
||||
case ScrollerType.MAGIC_SHELF:
|
||||
return this.getMagicShelfBooks(config, books, magicShelves);
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
private getLastReadBooks(books: Book[], maxItems: number): Book[] {
|
||||
const recentBooks = books.filter(book =>
|
||||
book.lastReadTime &&
|
||||
(book.readStatus === ReadStatus.READING || book.readStatus === ReadStatus.RE_READING || book.readStatus === ReadStatus.PAUSED) &&
|
||||
this.hasEbookProgress(book)
|
||||
);
|
||||
|
||||
return recentBooks.sort((a, b) => {
|
||||
const aTime = new Date(a.lastReadTime!).getTime();
|
||||
const bTime = new Date(b.lastReadTime!).getTime();
|
||||
return bTime - aTime;
|
||||
}).slice(0, maxItems);
|
||||
}
|
||||
|
||||
private getLastListenedBooks(books: Book[], maxItems: number): Book[] {
|
||||
const recentBooks = books.filter(book =>
|
||||
book.lastReadTime &&
|
||||
(book.readStatus === ReadStatus.READING || book.readStatus === ReadStatus.RE_READING || book.readStatus === ReadStatus.PAUSED) &&
|
||||
book.audiobookProgress
|
||||
);
|
||||
|
||||
return recentBooks.sort((a, b) => {
|
||||
const aTime = new Date(a.lastReadTime!).getTime();
|
||||
const bTime = new Date(b.lastReadTime!).getTime();
|
||||
return bTime - aTime;
|
||||
}).slice(0, maxItems);
|
||||
}
|
||||
|
||||
private hasEbookProgress(book: Book): boolean {
|
||||
return !!(book.epubProgress || book.pdfProgress || book.cbxProgress || book.koreaderProgress || book.koboProgress);
|
||||
}
|
||||
|
||||
private getLatestAddedBooks(books: Book[], maxItems: number): Book[] {
|
||||
const addedBooks = books.filter(book => book.addedOn);
|
||||
|
||||
return addedBooks.sort((a, b) => {
|
||||
const aTime = new Date(a.addedOn!).getTime();
|
||||
const bTime = new Date(b.addedOn!).getTime();
|
||||
return bTime - aTime;
|
||||
}).slice(0, maxItems);
|
||||
}
|
||||
|
||||
private getRandomBooks(books: Book[], maxItems: number): Book[] {
|
||||
const excludedStatuses = new Set<ReadStatus>([
|
||||
ReadStatus.READ,
|
||||
ReadStatus.PARTIALLY_READ,
|
||||
ReadStatus.READING,
|
||||
ReadStatus.PAUSED,
|
||||
ReadStatus.WONT_READ,
|
||||
ReadStatus.ABANDONED
|
||||
]);
|
||||
|
||||
const candidates = books.filter(book =>
|
||||
!book.readStatus || !excludedStatuses.has(book.readStatus)
|
||||
);
|
||||
|
||||
return this.shuffleBooks(candidates, maxItems);
|
||||
}
|
||||
|
||||
private getMagicShelfBooks(
|
||||
config: ScrollerConfig,
|
||||
books: Book[],
|
||||
magicShelves: {id?: number | null; filterJson: string}[]
|
||||
): Book[] {
|
||||
const shelf = magicShelves.find(currentShelf => currentShelf.id === config.magicShelfId);
|
||||
if (!shelf) {
|
||||
return [];
|
||||
}
|
||||
|
||||
let group: GroupRule;
|
||||
try {
|
||||
group = JSON.parse(shelf.filterJson);
|
||||
} catch (e) {
|
||||
console.error('Invalid filter JSON', e);
|
||||
return [];
|
||||
}
|
||||
|
||||
let filteredBooks = books.filter(book =>
|
||||
this.ruleEvaluatorService.evaluateGroup(book, group, books)
|
||||
);
|
||||
|
||||
if (config.maxItems) {
|
||||
filteredBooks = filteredBooks.slice(0, config.maxItems);
|
||||
}
|
||||
|
||||
if (config.sortField && config.sortDirection) {
|
||||
const sortOption = this.createSortOption(config.sortField, config.sortDirection);
|
||||
return this.sortService.applySort(filteredBooks, sortOption);
|
||||
}
|
||||
|
||||
return filteredBooks;
|
||||
}
|
||||
|
||||
private createSortOption(field: string, direction: string): SortOption {
|
||||
return {
|
||||
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.dialogLauncher.openDashboardSettingsDialog();
|
||||
}
|
||||
|
||||
createNewLibrary() {
|
||||
this.dialogLauncher.openLibraryCreateDialog();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user