Add an option to adjust the size of book covers in the grid view
This commit is contained in:
committed by
Aditya Chandel
parent
bbf922b525
commit
fb37b578f3
@@ -59,6 +59,7 @@ public class BookLoreUser {
|
||||
private String sortKey;
|
||||
private String sortDir;
|
||||
private String view;
|
||||
private Float coverSize;
|
||||
}
|
||||
|
||||
@Data
|
||||
|
||||
+1
@@ -95,6 +95,7 @@ public class DefaultUserSettingsProvider {
|
||||
.sortKey("title")
|
||||
.sortDir("ASC")
|
||||
.view("GRID")
|
||||
.coverSize(1.0F)
|
||||
.build())
|
||||
.overrides(null)
|
||||
.build();
|
||||
|
||||
@@ -32,6 +32,33 @@
|
||||
</i>
|
||||
</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>
|
||||
<a class="topbar-items topbar-item" (click)="sortMenu.toggle($event)">
|
||||
<i
|
||||
@@ -112,11 +139,18 @@
|
||||
</div>
|
||||
|
||||
<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">
|
||||
<div class="grid grid-cols-12 gap-4" #container>
|
||||
<div class="virtual-scroller-item" *ngFor="let book of scroll.viewPortItems">
|
||||
<div
|
||||
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
|
||||
[book]="book"
|
||||
[isCheckboxEnabled]="true"
|
||||
|
||||
@@ -18,19 +18,18 @@
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.virtual-scroller-item {
|
||||
height: 220px;
|
||||
width: 135px;
|
||||
}
|
||||
|
||||
.grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
|
||||
grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
|
||||
gap: 1.3rem;
|
||||
overflow: hidden;
|
||||
align-items: start;
|
||||
}
|
||||
|
||||
.virtual-scroller-item {
|
||||
transition: width 0.2s ease, height 0.2s ease;
|
||||
}
|
||||
|
||||
.book-browser-footer {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
|
||||
@@ -3,8 +3,7 @@ import {ActivatedRoute, Router} from '@angular/router';
|
||||
import {MenuItem, MessageService, PrimeTemplate} from 'primeng/api';
|
||||
import {LibraryService} from '../../service/library.service';
|
||||
import {BookService} from '../../service/book.service';
|
||||
import {map, switchMap} from 'rxjs/operators';
|
||||
import {filter, take} from 'rxjs/operators';
|
||||
import {debounceTime, filter, map, switchMap, take} from 'rxjs/operators';
|
||||
import {BehaviorSubject, combineLatest, Observable, of, Subject} from 'rxjs';
|
||||
import {ShelfService} from '../../service/shelf.service';
|
||||
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 {MetadataRefreshType} from '../../metadata/model/request/metadata-refresh-type.enum';
|
||||
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 {BookCardComponent} from './book-card/book-card.component';
|
||||
import {ProgressSpinner} from 'primeng/progressspinner';
|
||||
import {Menu} from 'primeng/menu';
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
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 {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 {OverlayPanelModule} from 'primeng/overlaypanel';
|
||||
import {Slider} from 'primeng/slider';
|
||||
import {Popover} from 'primeng/popover';
|
||||
|
||||
export enum EntityType {
|
||||
LIBRARY = 'Library',
|
||||
@@ -63,7 +65,7 @@ const SORT_DIRECTION = {
|
||||
standalone: true,
|
||||
templateUrl: './book-browser.component.html',
|
||||
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: [
|
||||
trigger('slideInOut', [
|
||||
state('void', style({
|
||||
@@ -139,8 +141,44 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
||||
lastAppliedSort: SortOption | null = null;
|
||||
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 {
|
||||
|
||||
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();
|
||||
|
||||
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 { ...bookState, books: filteredBooks };
|
||||
return {...bookState, books: filteredBooks};
|
||||
})
|
||||
);
|
||||
}
|
||||
@@ -578,11 +616,12 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
||||
take(1)
|
||||
)
|
||||
.subscribe(user => {
|
||||
const prefs = user.userSettings?.entityViewPreferences;
|
||||
const globalPrefs = prefs?.global;
|
||||
this.prefs = user.userSettings?.entityViewPreferences;
|
||||
const globalPrefs = this.prefs?.global;
|
||||
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.entityId === this.entity?.id
|
||||
);
|
||||
|
||||
@@ -16,6 +16,7 @@ export interface EntityViewPreference {
|
||||
sortKey: string;
|
||||
sortDir: 'ASC' | 'DESC';
|
||||
view: 'GRID' | 'TABLE';
|
||||
coverSize: number
|
||||
}
|
||||
|
||||
export interface EntityViewPreferenceOverride {
|
||||
@@ -116,6 +117,10 @@ export class UserService {
|
||||
});
|
||||
}
|
||||
|
||||
getCurrentUser(): User | null {
|
||||
return this.userStateSubject.getValue();
|
||||
}
|
||||
|
||||
getMyself(): Observable<User> {
|
||||
return this.http.get<User>(`${this.userUrl}/me`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user