Link author and genre clicks to filtered book list
This commit is contained in:
committed by
Aditya Chandel
parent
8ce687d659
commit
a358b657e6
@@ -20,7 +20,7 @@
|
|||||||
}
|
}
|
||||||
@if (userService.userState$ | async; as userData) {
|
@if (userService.userState$ | async; as userData) {
|
||||||
<div>
|
<div>
|
||||||
@if (entityType !== EntityType.ALL_BOOKS && entityType !== EntityType.UNSHELVED && (userData.permissions.admin || userData.permissions.canManipulateLibrary) ) {
|
@if (entityType !== EntityType.ALL_BOOKS && entityType !== EntityType.UNSHELVED && (userData.permissions.admin || userData.permissions.canManipulateLibrary)) {
|
||||||
<div>
|
<div>
|
||||||
<p-button icon="pi pi-ellipsis-v" [rounded]="true" [text]="true" severity="info" (click)="entitymenu.toggle($event)"></p-button>
|
<p-button icon="pi pi-ellipsis-v" [rounded]="true" [text]="true" severity="info" (click)="entitymenu.toggle($event)"></p-button>
|
||||||
<p-menu #entitymenu [model]="entityOptions" [popup]="true" appendTo="body"></p-menu>
|
<p-menu #entitymenu [model]="entityOptions" [popup]="true" appendTo="body"></p-menu>
|
||||||
@@ -49,8 +49,7 @@
|
|||||||
class="topbar-items topbar-item"
|
class="topbar-items topbar-item"
|
||||||
(click)="sizeOverlay.toggle($event)"
|
(click)="sizeOverlay.toggle($event)"
|
||||||
pTooltip="Adjust grid item scale"
|
pTooltip="Adjust grid item scale"
|
||||||
tooltipPosition="top"
|
tooltipPosition="top">
|
||||||
>
|
|
||||||
<i class="pi pi-th-large"></i>
|
<i class="pi pi-th-large"></i>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
@@ -109,8 +108,7 @@
|
|||||||
placeholder="Title, Series or Author..."
|
placeholder="Title, Series or Author..."
|
||||||
[(ngModel)]="bookTitle"
|
[(ngModel)]="bookTitle"
|
||||||
(ngModelChange)="onSearchTermChange($event)"
|
(ngModelChange)="onSearchTermChange($event)"
|
||||||
class="search-input"
|
class="search-input"/>
|
||||||
/>
|
|
||||||
@if (bookTitle) {
|
@if (bookTitle) {
|
||||||
<p-button
|
<p-button
|
||||||
icon="pi pi-times"
|
icon="pi pi-times"
|
||||||
@@ -162,14 +160,14 @@
|
|||||||
<div class="book-card-container">
|
<div class="book-card-container">
|
||||||
@if (currentViewMode === 'table' && books.length > 0) {
|
@if (currentViewMode === 'table' && books.length > 0) {
|
||||||
<app-book-table [books]="books" (selectedBooksChange)="onSelectedBooksChange($event)"
|
<app-book-table [books]="books" (selectedBooksChange)="onSelectedBooksChange($event)"
|
||||||
[sortOption]="selectedSort!"></app-book-table>
|
[sortOption]="selectedSort!"></app-book-table>
|
||||||
}
|
}
|
||||||
@if (currentViewMode === 'grid') {
|
@if (currentViewMode === 'grid') {
|
||||||
<virtual-scroller class="virtual-scroller" #scroll [items]="books">
|
<virtual-scroller class="virtual-scroller" #scroll [items]="books">
|
||||||
<div
|
<div
|
||||||
class="grid"
|
class="grid"
|
||||||
#container
|
#container
|
||||||
[ngStyle]="{'grid-template-columns': 'repeat(auto-fit, minmax(' + gridColumnMinWidth + ', 1fr))'}">
|
[ngStyle]="{'grid-template-columns': 'repeat(auto-fill, minmax(' + gridColumnMinWidth + ', 1fr))'}">
|
||||||
@for (book of scroll.viewPortItems; track book) {
|
@for (book of scroll.viewPortItems; track book) {
|
||||||
<div
|
<div
|
||||||
class="virtual-scroller-item"
|
class="virtual-scroller-item"
|
||||||
|
|||||||
@@ -47,7 +47,8 @@ const QUERY_PARAMS = {
|
|||||||
VIEW: 'view',
|
VIEW: 'view',
|
||||||
SORT: 'sort',
|
SORT: 'sort',
|
||||||
DIRECTION: 'direction',
|
DIRECTION: 'direction',
|
||||||
FILTER: 'filter'
|
FILTER: 'filter',
|
||||||
|
SIDEBAR: 'sidebar'
|
||||||
};
|
};
|
||||||
|
|
||||||
const VIEW_MODES = {
|
const VIEW_MODES = {
|
||||||
@@ -535,7 +536,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
|||||||
|
|
||||||
this.router.navigate([], {
|
this.router.navigate([], {
|
||||||
queryParams: {
|
queryParams: {
|
||||||
[QUERY_PARAMS.FILTER]: this.bookFilterComponent.showFilters.toString()
|
[QUERY_PARAMS.SIDEBAR]: this.bookFilterComponent.showFilters.toString()
|
||||||
},
|
},
|
||||||
queryParamsHandling: 'merge',
|
queryParamsHandling: 'merge',
|
||||||
replaceUrl: true
|
replaceUrl: true
|
||||||
@@ -608,7 +609,21 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
|||||||
const viewParam = paramMap.get(QUERY_PARAMS.VIEW);
|
const viewParam = paramMap.get(QUERY_PARAMS.VIEW);
|
||||||
const sortParam = paramMap.get(QUERY_PARAMS.SORT);
|
const sortParam = paramMap.get(QUERY_PARAMS.SORT);
|
||||||
const directionParam = paramMap.get(QUERY_PARAMS.DIRECTION);
|
const directionParam = paramMap.get(QUERY_PARAMS.DIRECTION);
|
||||||
const filterParam = paramMap.get(QUERY_PARAMS.FILTER);
|
const sidebarParam = paramMap.get(QUERY_PARAMS.SIDEBAR);
|
||||||
|
const rawFilterParam = paramMap.get(QUERY_PARAMS.FILTER);
|
||||||
|
|
||||||
|
const parsedFilters: Record<string, string[]> = {};
|
||||||
|
if (rawFilterParam) {
|
||||||
|
rawFilterParam.split(',').forEach(pair => {
|
||||||
|
const [key, ...valueParts] = pair.split(':');
|
||||||
|
const value = valueParts.join(':');
|
||||||
|
if (key && value) {
|
||||||
|
parsedFilters[key] = value.split('|').map(v => v.trim()).filter(Boolean);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.selectedFilter.next(parsedFilters);
|
||||||
|
this.bookFilterComponent.setFilters?.(parsedFilters);
|
||||||
|
}
|
||||||
|
|
||||||
this.userService.userState$
|
this.userService.userState$
|
||||||
.pipe(
|
.pipe(
|
||||||
@@ -633,26 +648,39 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const userSortKey = effectivePrefs.sortKey;
|
const userSortKey = effectivePrefs.sortKey;
|
||||||
const userSortDir = effectivePrefs.sortDir?.toUpperCase() === 'DESC' ? SortDirection.DESCENDING : SortDirection.ASCENDING;
|
const userSortDir = effectivePrefs.sortDir?.toUpperCase() === 'DESC'
|
||||||
|
? SortDirection.DESCENDING
|
||||||
|
: SortDirection.ASCENDING;
|
||||||
|
|
||||||
const matchedSort = this.sortOptions.find(opt => opt.field === sortParam) || this.sortOptions.find(opt => opt.field === userSortKey);
|
const matchedSort = this.sortOptions.find(opt => opt.field === sortParam)
|
||||||
|
|| this.sortOptions.find(opt => opt.field === userSortKey);
|
||||||
|
|
||||||
this.selectedSort = matchedSort ? {
|
this.selectedSort = matchedSort ? {
|
||||||
label: matchedSort.label,
|
label: matchedSort.label,
|
||||||
field: matchedSort.field,
|
field: matchedSort.field,
|
||||||
direction: directionParam ? (directionParam === SORT_DIRECTION.DESCENDING ? SortDirection.DESCENDING : SortDirection.ASCENDING) : userSortDir
|
direction: directionParam?.toUpperCase() === SORT_DIRECTION.DESCENDING
|
||||||
|
? SortDirection.DESCENDING
|
||||||
|
: SortDirection.ASCENDING
|
||||||
} : {
|
} : {
|
||||||
label: 'Added On',
|
label: 'Added On',
|
||||||
field: 'addedOn',
|
field: 'addedOn',
|
||||||
direction: SortDirection.DESCENDING
|
direction: SortDirection.DESCENDING
|
||||||
};
|
};
|
||||||
|
|
||||||
this.currentViewMode = (viewParam === VIEW_MODES.TABLE || viewParam === VIEW_MODES.GRID) ? viewParam : effectivePrefs.view?.toLowerCase() ?? VIEW_MODES.GRID;
|
this.currentViewMode = (viewParam === VIEW_MODES.TABLE || viewParam === VIEW_MODES.GRID)
|
||||||
this.bookFilterComponent.showFilters = filterParam === 'true' || (filterParam === null && this.filterVisibility);
|
? viewParam
|
||||||
|
: effectivePrefs.view?.toLowerCase() ?? VIEW_MODES.GRID;
|
||||||
|
|
||||||
|
this.bookFilterComponent.showFilters = sidebarParam === 'true'
|
||||||
|
|| (sidebarParam === null && this.filterVisibility);
|
||||||
|
|
||||||
this.updateSortOptions();
|
this.updateSortOptions();
|
||||||
|
|
||||||
if (this.lastAppliedSort?.field !== this.selectedSort.field || this.lastAppliedSort?.direction !== this.selectedSort.direction) {
|
if (
|
||||||
this.lastAppliedSort = {...this.selectedSort};
|
this.lastAppliedSort?.field !== this.selectedSort.field ||
|
||||||
|
this.lastAppliedSort?.direction !== this.selectedSort.direction
|
||||||
|
) {
|
||||||
|
this.lastAppliedSort = { ...this.selectedSort };
|
||||||
this.applySortOption(this.selectedSort);
|
this.applySortOption(this.selectedSort);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -660,17 +688,16 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
|||||||
[QUERY_PARAMS.VIEW]: this.currentViewMode,
|
[QUERY_PARAMS.VIEW]: this.currentViewMode,
|
||||||
[QUERY_PARAMS.SORT]: this.selectedSort.field,
|
[QUERY_PARAMS.SORT]: this.selectedSort.field,
|
||||||
[QUERY_PARAMS.DIRECTION]: this.selectedSort.direction === SortDirection.ASCENDING ? SORT_DIRECTION.ASCENDING : SORT_DIRECTION.DESCENDING,
|
[QUERY_PARAMS.DIRECTION]: this.selectedSort.direction === SortDirection.ASCENDING ? SORT_DIRECTION.ASCENDING : SORT_DIRECTION.DESCENDING,
|
||||||
[QUERY_PARAMS.FILTER]: this.bookFilterComponent.showFilters.toString()
|
[QUERY_PARAMS.SIDEBAR]: this.bookFilterComponent.showFilters.toString(),
|
||||||
|
[QUERY_PARAMS.FILTER]: Object.entries(parsedFilters)
|
||||||
|
.map(([k, v]) => `${k}:${v.join('|')}`)
|
||||||
|
.join(',')
|
||||||
};
|
};
|
||||||
|
|
||||||
const currentParams = this.activatedRoute.snapshot.queryParams;
|
const currentParams = this.activatedRoute.snapshot.queryParams;
|
||||||
|
const changed = Object.keys(queryParams).some(k => currentParams[k] !== queryParams[k]);
|
||||||
|
|
||||||
if (
|
if (changed) {
|
||||||
currentParams[QUERY_PARAMS.VIEW] !== queryParams[QUERY_PARAMS.VIEW] ||
|
|
||||||
currentParams[QUERY_PARAMS.SORT] !== queryParams[QUERY_PARAMS.SORT] ||
|
|
||||||
currentParams[QUERY_PARAMS.DIRECTION] !== queryParams[QUERY_PARAMS.DIRECTION] ||
|
|
||||||
currentParams[QUERY_PARAMS.FILTER] !== queryParams[QUERY_PARAMS.FILTER]
|
|
||||||
) {
|
|
||||||
this.router.navigate([], {
|
this.router.navigate([], {
|
||||||
queryParams,
|
queryParams,
|
||||||
replaceUrl: true
|
replaceUrl: true
|
||||||
|
|||||||
@@ -92,11 +92,11 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.info-btn {
|
.info-btn {
|
||||||
top: 18%;
|
top: 21%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.read-btn {
|
.read-btn {
|
||||||
bottom: 18%;
|
bottom: 21%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.cover-container:hover .info-btn,
|
.cover-container:hover .info-btn,
|
||||||
|
|||||||
+19
-1
@@ -238,7 +238,25 @@ export class BookFilterComponent implements OnInit {
|
|||||||
this.activeFilters[filterType].push(value);
|
this.activeFilters[filterType].push(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.filterSelected.emit({...this.activeFilters});
|
if (Object.keys(this.activeFilters).length === 0) {
|
||||||
|
this.filterSelected.emit(null);
|
||||||
|
} else {
|
||||||
|
this.filterSelected.emit({ ...this.activeFilters });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setFilters(filters: Record<string, any>) {
|
||||||
|
this.activeFilters = {};
|
||||||
|
|
||||||
|
for (const [key, value] of Object.entries(filters)) {
|
||||||
|
if (Array.isArray(value)) {
|
||||||
|
this.activeFilters[key] = [...value];
|
||||||
|
} else {
|
||||||
|
this.activeFilters[key] = [value];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.filterSelected.emit({ ...this.activeFilters });
|
||||||
}
|
}
|
||||||
|
|
||||||
clearActiveFilter() {
|
clearActiveFilter() {
|
||||||
|
|||||||
+29
-2
@@ -38,7 +38,22 @@
|
|||||||
tooltipPosition="top">
|
tooltipPosition="top">
|
||||||
</i>
|
</i>
|
||||||
</div>
|
</div>
|
||||||
<p class="text-xl">{{ getAuthorNames(metadata?.authors || []) }}</p>
|
<p class="text-xl">
|
||||||
|
@for (author of metadata?.authors; track author; let isLast = $last) {
|
||||||
|
<a
|
||||||
|
class="underline hover:opacity-80"
|
||||||
|
[routerLink]="['/all-books']"
|
||||||
|
[queryParams]="{
|
||||||
|
view: 'grid',
|
||||||
|
sort: 'title',
|
||||||
|
direction: 'asc',
|
||||||
|
sidebar: true,
|
||||||
|
filter: 'author:' + author
|
||||||
|
}"
|
||||||
|
>{{ author }}</a>
|
||||||
|
@if (!isLast) {<span>, </span>}
|
||||||
|
}
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex items-center gap-2 pt-2">
|
<div class="flex items-center gap-2 pt-2">
|
||||||
@@ -125,7 +140,19 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="flex gap-2 pt-4 overflow-x-auto scrollbar-hide">
|
<div class="flex gap-2 pt-4 overflow-x-auto scrollbar-hide">
|
||||||
@for (category of metadata.categories; track category) {
|
@for (category of metadata.categories; track category) {
|
||||||
<p-tag [value]="category" class="shrink-0"></p-tag>
|
<a
|
||||||
|
[routerLink]="['/all-books']"
|
||||||
|
[queryParams]="{
|
||||||
|
view: 'grid',
|
||||||
|
sort: 'title',
|
||||||
|
direction: 'asc',
|
||||||
|
sidebar: true,
|
||||||
|
filter: 'category:' + category
|
||||||
|
}"
|
||||||
|
class="shrink-0 no-underline"
|
||||||
|
>
|
||||||
|
<p-tag [value]="category"></p-tag>
|
||||||
|
</a>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
<div class="grid gap-x-20 gap-y-2 pt-6" style="grid-template-columns: repeat(5, max-content);">
|
<div class="grid gap-x-20 gap-y-2 pt-6" style="grid-template-columns: repeat(5, max-content);">
|
||||||
|
|||||||
+2
-1
@@ -27,13 +27,14 @@ import {ToggleButton} from 'primeng/togglebutton';
|
|||||||
import {MetadataFetchOptionsComponent} from '../../metadata-options-dialog/metadata-fetch-options/metadata-fetch-options.component';
|
import {MetadataFetchOptionsComponent} from '../../metadata-options-dialog/metadata-fetch-options/metadata-fetch-options.component';
|
||||||
import {MetadataRefreshType} from '../../model/request/metadata-refresh-type.enum';
|
import {MetadataRefreshType} from '../../model/request/metadata-refresh-type.enum';
|
||||||
import {MetadataRefreshRequest} from '../../model/request/metadata-refresh-request.model';
|
import {MetadataRefreshRequest} from '../../model/request/metadata-refresh-request.model';
|
||||||
|
import {RouterLink} from '@angular/router';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-metadata-viewer',
|
selector: 'app-metadata-viewer',
|
||||||
standalone: true,
|
standalone: true,
|
||||||
templateUrl: './metadata-viewer.component.html',
|
templateUrl: './metadata-viewer.component.html',
|
||||||
styleUrl: './metadata-viewer.component.scss',
|
styleUrl: './metadata-viewer.component.scss',
|
||||||
imports: [Button, AsyncPipe, Rating, FormsModule, Tag, Divider, SplitButton, NgClass, Tooltip, DecimalPipe, InfiniteScrollDirective, BookCardComponent, ButtonDirective, Editor, ProgressBar, ToggleButton]
|
imports: [Button, AsyncPipe, Rating, FormsModule, Tag, Divider, SplitButton, NgClass, Tooltip, DecimalPipe, InfiniteScrollDirective, BookCardComponent, ButtonDirective, Editor, ProgressBar, ToggleButton, RouterLink]
|
||||||
})
|
})
|
||||||
export class MetadataViewerComponent implements OnInit, OnChanges {
|
export class MetadataViewerComponent implements OnInit, OnChanges {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user