Add an option to adjust the size of book covers in the grid view

This commit is contained in:
aditya.chandel
2025-06-02 22:45:16 -06:00
committed by Aditya Chandel
parent bbf922b525
commit fb37b578f3
6 changed files with 98 additions and 19 deletions
@@ -59,6 +59,7 @@ public class BookLoreUser {
private String sortKey; private String sortKey;
private String sortDir; private String sortDir;
private String view; private String view;
private Float coverSize;
} }
@Data @Data
@@ -95,6 +95,7 @@ public class DefaultUserSettingsProvider {
.sortKey("title") .sortKey("title")
.sortDir("ASC") .sortDir("ASC")
.view("GRID") .view("GRID")
.coverSize(1.0F)
.build()) .build())
.overrides(null) .overrides(null)
.build(); .build();
@@ -32,6 +32,33 @@
</i> </i>
</a> </a>
<div>
<a
class="topbar-items topbar-item"
(click)="sizeOverlay.toggle($event)"
pTooltip="Adjust grid item scale"
tooltipPosition="top"
>
<i class="pi pi-th-large"></i>
</a>
<p-popover #sizeOverlay [dismissable]="true" appendTo="body">
<div style="width: 220px; padding: 8px;">
<p-slider
[(ngModel)]="scaleFactor"
[min]="0.5"
[max]="1.5"
[step]="0.01"
[style]="{ width: '100%' }"
(onChange)="updateScale()"
></p-slider>
<div style="text-align: center; margin-top: 8px;">
{{ scaleFactor.toFixed(2) }}x
</div>
</div>
</p-popover>
</div>
<div> <div>
<a class="topbar-items topbar-item" (click)="sortMenu.toggle($event)"> <a class="topbar-items topbar-item" (click)="sortMenu.toggle($event)">
<i <i
@@ -112,11 +139,18 @@
</div> </div>
<div class="book-card-container" *ngIf="bookState?.books as books"> <div class="book-card-container" *ngIf="bookState?.books as books">
<app-book-table *ngIf="currentViewMode === 'table' && books.length > 0" [books]="books" (selectedBooksChange)="onSelectedBooksChange($event)" [sortOption]="selectedSort!"></app-book-table> <app-book-table *ngIf="currentViewMode === 'table' && books.length > 0" [books]="books" (selectedBooksChange)="onSelectedBooksChange($event)"
[sortOption]="selectedSort!"></app-book-table>
<virtual-scroller *ngIf="currentViewMode === 'grid'" class="virtual-scroller" #scroll [items]="books"> <virtual-scroller *ngIf="currentViewMode === 'grid'" class="virtual-scroller" #scroll [items]="books">
<div class="grid grid-cols-12 gap-4" #container> <div
<div class="virtual-scroller-item" *ngFor="let book of scroll.viewPortItems"> class="grid"
#container
[ngStyle]="{'grid-template-columns': 'repeat(auto-fit, minmax(' + gridColumnMinWidth + ', 1fr))'}">
<div
class="virtual-scroller-item"
*ngFor="let book of scroll.viewPortItems"
[ngStyle]="{width: currentCardSize.width + 'px', height: currentCardSize.height + 'px'}">
<app-book-card <app-book-card
[book]="book" [book]="book"
[isCheckboxEnabled]="true" [isCheckboxEnabled]="true"
@@ -18,19 +18,18 @@
overflow-y: auto; overflow-y: auto;
} }
.virtual-scroller-item {
height: 220px;
width: 135px;
}
.grid { .grid {
display: grid; display: grid;
grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
gap: 1.3rem; gap: 1.3rem;
overflow: hidden; overflow: hidden;
align-items: start; align-items: start;
} }
.virtual-scroller-item {
transition: width 0.2s ease, height 0.2s ease;
}
.book-browser-footer { .book-browser-footer {
position: absolute; position: absolute;
bottom: 0; bottom: 0;
@@ -3,8 +3,7 @@ import {ActivatedRoute, Router} from '@angular/router';
import {MenuItem, MessageService, PrimeTemplate} from 'primeng/api'; import {MenuItem, MessageService, PrimeTemplate} from 'primeng/api';
import {LibraryService} from '../../service/library.service'; import {LibraryService} from '../../service/library.service';
import {BookService} from '../../service/book.service'; import {BookService} from '../../service/book.service';
import {map, switchMap} from 'rxjs/operators'; import {debounceTime, filter, map, switchMap, take} from 'rxjs/operators';
import {filter, take} from 'rxjs/operators';
import {BehaviorSubject, combineLatest, Observable, of, Subject} from 'rxjs'; import {BehaviorSubject, combineLatest, Observable, of, Subject} from 'rxjs';
import {ShelfService} from '../../service/shelf.service'; import {ShelfService} from '../../service/shelf.service';
import {ShelfAssignerComponent} from '../shelf-assigner/shelf-assigner.component'; import {ShelfAssignerComponent} from '../shelf-assigner/shelf-assigner.component';
@@ -21,18 +20,21 @@ import {animate, state, style, transition, trigger} from '@angular/animations';
import {MetadataFetchOptionsComponent} from '../../metadata/metadata-options-dialog/metadata-fetch-options/metadata-fetch-options.component'; import {MetadataFetchOptionsComponent} from '../../metadata/metadata-options-dialog/metadata-fetch-options/metadata-fetch-options.component';
import {MetadataRefreshType} from '../../metadata/model/request/metadata-refresh-type.enum'; import {MetadataRefreshType} from '../../metadata/model/request/metadata-refresh-type.enum';
import {Button} from 'primeng/button'; import {Button} from 'primeng/button';
import {AsyncPipe, NgClass, NgForOf, NgIf} from '@angular/common'; import {AsyncPipe, NgClass, NgForOf, NgIf, NgStyle} from '@angular/common';
import {VirtualScrollerModule} from '@iharbeck/ngx-virtual-scroller'; import {VirtualScrollerModule} from '@iharbeck/ngx-virtual-scroller';
import {BookCardComponent} from './book-card/book-card.component'; import {BookCardComponent} from './book-card/book-card.component';
import {ProgressSpinner} from 'primeng/progressspinner'; import {ProgressSpinner} from 'primeng/progressspinner';
import {Menu} from 'primeng/menu'; import {Menu} from 'primeng/menu';
import {InputText} from 'primeng/inputtext'; import {InputText} from 'primeng/inputtext';
import {FormsModule} from '@angular/forms'; import {FormsModule} from '@angular/forms';
import {BookFilterComponent, fileSizeRanges, isFileSizeInRange, isPageCountInRange, isRatingInRange, pageCountRanges, ratingRanges} from './book-filter/book-filter.component'; import {BookFilterComponent, isFileSizeInRange, isPageCountInRange, isRatingInRange} from './book-filter/book-filter.component';
import {Tooltip} from 'primeng/tooltip'; import {Tooltip} from 'primeng/tooltip';
import {Fluid} from 'primeng/fluid'; import {Fluid} from 'primeng/fluid';
import {UserService} from '../../../settings/user-management/user.service'; import {EntityViewPreferences, UserService} from '../../../settings/user-management/user.service';
import {LockUnlockMetadataDialogComponent} from './lock-unlock-metadata-dialog/lock-unlock-metadata-dialog.component'; import {LockUnlockMetadataDialogComponent} from './lock-unlock-metadata-dialog/lock-unlock-metadata-dialog.component';
import {OverlayPanelModule} from 'primeng/overlaypanel';
import {Slider} from 'primeng/slider';
import {Popover} from 'primeng/popover';
export enum EntityType { export enum EntityType {
LIBRARY = 'Library', LIBRARY = 'Library',
@@ -63,7 +65,7 @@ const SORT_DIRECTION = {
standalone: true, standalone: true,
templateUrl: './book-browser.component.html', templateUrl: './book-browser.component.html',
styleUrls: ['./book-browser.component.scss'], styleUrls: ['./book-browser.component.scss'],
imports: [Button, NgIf, VirtualScrollerModule, BookCardComponent, AsyncPipe, ProgressSpinner, Menu, NgForOf, InputText, FormsModule, BookTableComponent, BookFilterComponent, Tooltip, NgClass, Fluid, PrimeTemplate], imports: [Button, NgIf, VirtualScrollerModule, BookCardComponent, AsyncPipe, ProgressSpinner, Menu, NgForOf, InputText, FormsModule, BookTableComponent, BookFilterComponent, Tooltip, NgClass, Fluid, PrimeTemplate, NgStyle, OverlayPanelModule, Slider, Popover],
animations: [ animations: [
trigger('slideInOut', [ trigger('slideInOut', [
state('void', style({ state('void', style({
@@ -139,8 +141,44 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
lastAppliedSort: SortOption | null = null; lastAppliedSort: SortOption | null = null;
filterVisibility = true; filterVisibility = true;
prefs!: EntityViewPreferences;
baseWidth = 135;
baseHeight = 220;
scaleFactor = 1.0;
get currentCardSize() {
return {
width: Math.round(this.baseWidth * this.scaleFactor),
height: Math.round(this.baseHeight * this.scaleFactor)
};
}
get gridColumnMinWidth(): string {
return `${this.currentCardSize.width}px`;
}
updateScale(): void {
this.scaleChange$.next(this.scaleFactor);
}
private scaleChange$ = new Subject<number>();
ngOnInit(): void { ngOnInit(): void {
this.scaleChange$.pipe(debounceTime(1000)).subscribe(scale => {
const user = this.userService.getCurrentUser();
if (!user || !this.prefs) return;
this.prefs.global = this.prefs.global ?? {};
this.prefs.global.coverSize = scale;
this.userService.updateUserSetting(user.id, 'entityViewPreferences', this.prefs);
this.messageService.add({
severity: 'success',
summary: 'Cover Size Saved',
detail: `Cover size set to ${scale.toFixed(2)}x.`
});
});
this.bookService.loadBooks(); this.bookService.loadBooks();
const currentPath = this.activatedRoute.snapshot.routeConfig?.path; const currentPath = this.activatedRoute.snapshot.routeConfig?.path;
@@ -327,7 +365,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
}); });
return mode === 'and' ? matches.every(m => m) : matches.some(m => m); return mode === 'and' ? matches.every(m => m) : matches.some(m => m);
}); });
return { ...bookState, books: filteredBooks }; return {...bookState, books: filteredBooks};
}) })
); );
} }
@@ -578,11 +616,12 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
take(1) take(1)
) )
.subscribe(user => { .subscribe(user => {
const prefs = user.userSettings?.entityViewPreferences; this.prefs = user.userSettings?.entityViewPreferences;
const globalPrefs = prefs?.global; const globalPrefs = this.prefs?.global;
const currentEntityTypeStr = this.entityType ? this.entityType.toString().toUpperCase() : undefined; const currentEntityTypeStr = this.entityType ? this.entityType.toString().toUpperCase() : undefined;
this.scaleFactor = user.userSettings.entityViewPreferences?.global?.coverSize ?? 1.0;
const override = prefs?.overrides?.find(o => const override = this.prefs?.overrides?.find(o =>
o.entityType?.toUpperCase() === currentEntityTypeStr && o.entityType?.toUpperCase() === currentEntityTypeStr &&
o.entityId === this.entity?.id o.entityId === this.entity?.id
); );
@@ -16,6 +16,7 @@ export interface EntityViewPreference {
sortKey: string; sortKey: string;
sortDir: 'ASC' | 'DESC'; sortDir: 'ASC' | 'DESC';
view: 'GRID' | 'TABLE'; view: 'GRID' | 'TABLE';
coverSize: number
} }
export interface EntityViewPreferenceOverride { export interface EntityViewPreferenceOverride {
@@ -116,6 +117,10 @@ export class UserService {
}); });
} }
getCurrentUser(): User | null {
return this.userStateSubject.getValue();
}
getMyself(): Observable<User> { getMyself(): Observable<User> {
return this.http.get<User>(`${this.userUrl}/me`); return this.http.get<User>(`${this.userUrl}/me`);
} }