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