Dynamic page title reflecting active book filters and entity context

This commit is contained in:
aditya.chandel
2025-06-06 08:24:48 -06:00
committed by Aditya Chandel
parent 88421fb420
commit 2ee0b4cc2c
2 changed files with 51 additions and 29 deletions
@@ -3,34 +3,30 @@
<div class="flex justify-between items-center p-2 rounded-t-xl mb-4 bg-[var(--card-background)]">
<div class="flex items-center pl-2">
@if (entityType$ | async; as entityType) {
@if (entityType !== EntityType.ALL_BOOKS && entityType !== EntityType.UNSHELVED) {
<p class="text-2xl whitespace-nowrap overflow-hidden text-ellipsis">
{{ entityType }}: {{ (entity$ | async)?.name }}
</p>
}
@if (entityType === EntityType.ALL_BOOKS) {
<p class="text-2xl whitespace-nowrap overflow-hidden text-ellipsis">
@if (currentFilterLabel) {
<p class="text-2xl whitespace-nowrap overflow-hidden text-ellipsis">
@if (entityType === EntityType.ALL_BOOKS) {
@if (currentFilterLabel && rawFilterParamFromUrl) {
{{ currentFilterLabel }}
} @else if (hasSidebarFilters || hasSearchTerm) {
All Books (Filtered)
} @else {
All Books
}
</p>
}
@if (entityType === EntityType.UNSHELVED) {
<p class="text-2xl whitespace-nowrap overflow-hidden text-ellipsis">
Unshelved Books
</p>
}
} @else if (entityType === EntityType.UNSHELVED) {
{{ (hasSidebarFilters || hasSearchTerm) ? 'Unshelved Books (Filtered)' : 'Unshelved Books' }}
} @else {
{{ entityType }}: {{ (entity$ | async)?.name }}{{ (hasSidebarFilters || hasSearchTerm) ? ' (Filtered)' : '' }}
}
</p>
@if (userService.userState$ | async; as userData) {
<div>
@if (entityType !== EntityType.ALL_BOOKS && entityType !== EntityType.UNSHELVED && (userData.permissions.admin || userData.permissions.canManipulateLibrary)) {
<div>
<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>
</div>
}
</div>
@if (entityType !== EntityType.ALL_BOOKS && entityType !== EntityType.UNSHELVED &&
(userData.permissions.admin || userData.permissions.canManipulateLibrary)) {
<div>
<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>
</div>
}
}
}
</div>
@@ -20,7 +20,7 @@ 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, NgStyle } from '@angular/common';
import {AsyncPipe, NgClass, NgStyle} from '@angular/common';
import {VirtualScrollerModule} from '@iharbeck/ngx-virtual-scroller';
import {BookCardComponent} from './book-card/book-card.component';
import {ProgressSpinner} from 'primeng/progressspinner';
@@ -99,6 +99,8 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
dynamicDialogRef: DynamicDialogRef | undefined;
EntityType = EntityType;
currentFilterLabel: string | null = null;
rawFilterParamFromUrl: string | null = null;
hasSearchTerm: boolean = false;
@ViewChild(BookTableComponent) bookTableComponent!: BookTableComponent;
@ViewChild(BookFilterComponent) bookFilterComponent!: BookFilterComponent;
@@ -577,7 +579,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
this.updateSortOptions();
this.applySortOption(this.selectedSort);
this.router.navigate([], {
/*this.router.navigate([], {
queryParams: {
sort: this.selectedSort.field,
direction: this.selectedSort.direction === SortDirection.ASCENDING
@@ -586,7 +588,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
},
queryParamsHandling: 'merge',
replaceUrl: true
});
});*/
}
updateSortOptions() {
@@ -597,16 +599,27 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
}));
}
private settingFiltersFromUrl = false;
ngAfterViewInit() {
this.bookFilterComponent.filterSelected.subscribe((filters: Record<string, any> | null) => {
if (this.settingFiltersFromUrl) return;
this.selectedFilter.next(filters);
this.currentFilterLabel = "All Books";
this.rawFilterParamFromUrl = null;
const hasSidebarFilters = !!filters && Object.keys(filters).length > 0;
this.currentFilterLabel = hasSidebarFilters ? 'All Books (Filtered)' : 'All Books';
});
this.bookFilterComponent.filterModeChanged.subscribe((mode: 'and' | 'or') => {
this.selectedFilterMode.next(mode);
});
this.searchTerm$.subscribe(term => {
this.hasSearchTerm = !!term && term.trim().length > 0;
});
this.activatedRoute.queryParamMap.subscribe(paramMap => {
const viewParam = paramMap.get(QUERY_PARAMS.VIEW);
const sortParam = paramMap.get(QUERY_PARAMS.SORT);
@@ -615,7 +628,10 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
const rawFilterParam = paramMap.get(QUERY_PARAMS.FILTER);
const parsedFilters: Record<string, string[]> = {};
if (rawFilterParam) {
this.settingFiltersFromUrl = true;
rawFilterParam.split(',').forEach(pair => {
const [key, ...valueParts] = pair.split(':');
const value = valueParts.join(':');
@@ -623,6 +639,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
parsedFilters[key] = value.split('|').map(v => v.trim()).filter(Boolean);
}
});
this.selectedFilter.next(parsedFilters);
this.bookFilterComponent.setFilters?.(parsedFilters);
@@ -632,10 +649,14 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
if (key && firstValue) {
this.currentFilterLabel = this.capitalize(key) + ': ' + firstValue;
} else {
this.currentFilterLabel = null;
this.currentFilterLabel = 'All Books';
}
this.rawFilterParamFromUrl = rawFilterParam;
this.settingFiltersFromUrl = false;
} else {
this.currentFilterLabel = null;
this.rawFilterParamFromUrl = null;
this.currentFilterLabel = 'All Books';
}
this.userService.userState$
@@ -728,6 +749,11 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
return str.charAt(0).toUpperCase() + str.slice(1);
}
get hasSidebarFilters(): boolean {
return this.selectedFilter && Object.keys(this.selectedFilter.getValue() || {}).length > 0;
}
lockUnlockMetadata() {
const count = this.selectedBooks.size;
this.dynamicDialogRef = this.dialogService.open(LockUnlockMetadataDialogComponent, {