Merge pull request #465 from adityachandelgit/develop
Merge Develop into Master for Release
This commit is contained in:
@@ -3,30 +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">
|
||||
All Books
|
||||
</p>
|
||||
}
|
||||
@if (entityType === EntityType.UNSHELVED) {
|
||||
<p class="text-2xl whitespace-nowrap overflow-hidden text-ellipsis">
|
||||
Unshelved Books
|
||||
</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>
|
||||
<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
|
||||
}
|
||||
</div>
|
||||
} @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) {
|
||||
@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>
|
||||
@@ -49,8 +49,7 @@
|
||||
class="topbar-items topbar-item"
|
||||
(click)="sizeOverlay.toggle($event)"
|
||||
pTooltip="Adjust grid item scale"
|
||||
tooltipPosition="top"
|
||||
>
|
||||
tooltipPosition="top">
|
||||
<i class="pi pi-th-large"></i>
|
||||
</a>
|
||||
|
||||
@@ -109,8 +108,7 @@
|
||||
placeholder="Title, Series or Author..."
|
||||
[(ngModel)]="bookTitle"
|
||||
(ngModelChange)="onSearchTermChange($event)"
|
||||
class="search-input"
|
||||
/>
|
||||
class="search-input"/>
|
||||
@if (bookTitle) {
|
||||
<p-button
|
||||
icon="pi pi-times"
|
||||
@@ -162,14 +160,14 @@
|
||||
<div class="book-card-container">
|
||||
@if (currentViewMode === 'table' && books.length > 0) {
|
||||
<app-book-table [books]="books" (selectedBooksChange)="onSelectedBooksChange($event)"
|
||||
[sortOption]="selectedSort!"></app-book-table>
|
||||
[sortOption]="selectedSort!"></app-book-table>
|
||||
}
|
||||
@if (currentViewMode === 'grid') {
|
||||
<virtual-scroller class="virtual-scroller" #scroll [items]="books">
|
||||
<div
|
||||
class="grid"
|
||||
#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) {
|
||||
<div
|
||||
class="virtual-scroller-item"
|
||||
|
||||
@@ -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';
|
||||
@@ -47,7 +47,8 @@ const QUERY_PARAMS = {
|
||||
VIEW: 'view',
|
||||
SORT: 'sort',
|
||||
DIRECTION: 'direction',
|
||||
FILTER: 'filter'
|
||||
FILTER: 'filter',
|
||||
SIDEBAR: 'sidebar'
|
||||
};
|
||||
|
||||
const VIEW_MODES = {
|
||||
@@ -97,6 +98,9 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
||||
isDrawerVisible: boolean = false;
|
||||
dynamicDialogRef: DynamicDialogRef | undefined;
|
||||
EntityType = EntityType;
|
||||
currentFilterLabel: string | null = null;
|
||||
rawFilterParamFromUrl: string | null = null;
|
||||
hasSearchTerm: boolean = false;
|
||||
|
||||
@ViewChild(BookTableComponent) bookTableComponent!: BookTableComponent;
|
||||
@ViewChild(BookFilterComponent) bookFilterComponent!: BookFilterComponent;
|
||||
@@ -535,7 +539,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
||||
|
||||
this.router.navigate([], {
|
||||
queryParams: {
|
||||
[QUERY_PARAMS.FILTER]: this.bookFilterComponent.showFilters.toString()
|
||||
[QUERY_PARAMS.SIDEBAR]: this.bookFilterComponent.showFilters.toString()
|
||||
},
|
||||
queryParamsHandling: 'merge',
|
||||
replaceUrl: true
|
||||
@@ -575,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
|
||||
@@ -584,7 +588,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
||||
},
|
||||
queryParamsHandling: 'merge',
|
||||
replaceUrl: true
|
||||
});
|
||||
});*/
|
||||
}
|
||||
|
||||
updateSortOptions() {
|
||||
@@ -595,20 +599,65 @@ 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.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);
|
||||
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) {
|
||||
this.settingFiltersFromUrl = true;
|
||||
|
||||
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);
|
||||
|
||||
const firstFilter = rawFilterParam.split(',')[0];
|
||||
const [key, ...values] = firstFilter.split(':');
|
||||
const firstValue = values.join(':').split('|')[0];
|
||||
if (key && firstValue) {
|
||||
this.currentFilterLabel = this.capitalize(key) + ': ' + firstValue;
|
||||
} else {
|
||||
this.currentFilterLabel = 'All Books';
|
||||
}
|
||||
|
||||
this.rawFilterParamFromUrl = rawFilterParam;
|
||||
this.settingFiltersFromUrl = false;
|
||||
} else {
|
||||
this.rawFilterParamFromUrl = null;
|
||||
this.currentFilterLabel = 'All Books';
|
||||
}
|
||||
|
||||
this.userService.userState$
|
||||
.pipe(
|
||||
@@ -633,44 +682,58 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
||||
};
|
||||
|
||||
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 ? {
|
||||
label: matchedSort.label,
|
||||
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',
|
||||
field: 'addedOn',
|
||||
direction: SortDirection.DESCENDING
|
||||
};
|
||||
|
||||
this.currentViewMode = (viewParam === VIEW_MODES.TABLE || viewParam === VIEW_MODES.GRID) ? viewParam : effectivePrefs.view?.toLowerCase() ?? VIEW_MODES.GRID;
|
||||
this.bookFilterComponent.showFilters = filterParam === 'true' || (filterParam === null && this.filterVisibility);
|
||||
this.currentViewMode = (viewParam === VIEW_MODES.TABLE || viewParam === VIEW_MODES.GRID)
|
||||
? viewParam
|
||||
: effectivePrefs.view?.toLowerCase() ?? VIEW_MODES.GRID;
|
||||
|
||||
this.bookFilterComponent.showFilters = sidebarParam === 'true'
|
||||
|| (sidebarParam === null && this.filterVisibility);
|
||||
|
||||
this.updateSortOptions();
|
||||
|
||||
if (this.lastAppliedSort?.field !== this.selectedSort.field || this.lastAppliedSort?.direction !== this.selectedSort.direction) {
|
||||
this.lastAppliedSort = {...this.selectedSort};
|
||||
if (
|
||||
this.lastAppliedSort?.field !== this.selectedSort.field ||
|
||||
this.lastAppliedSort?.direction !== this.selectedSort.direction
|
||||
) {
|
||||
this.lastAppliedSort = { ...this.selectedSort };
|
||||
this.applySortOption(this.selectedSort);
|
||||
}
|
||||
|
||||
const queryParams: any = {
|
||||
[QUERY_PARAMS.VIEW]: this.currentViewMode,
|
||||
[QUERY_PARAMS.SORT]: this.selectedSort.field,
|
||||
[QUERY_PARAMS.DIRECTION]: this.selectedSort.direction === SortDirection.ASCENDING ? SORT_DIRECTION.ASCENDING : SORT_DIRECTION.DESCENDING,
|
||||
[QUERY_PARAMS.FILTER]: this.bookFilterComponent.showFilters.toString()
|
||||
[QUERY_PARAMS.DIRECTION]: this.selectedSort.direction === SortDirection.ASCENDING
|
||||
? SORT_DIRECTION.ASCENDING
|
||||
: SORT_DIRECTION.DESCENDING,
|
||||
[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 changed = Object.keys(queryParams).some(k => currentParams[k] !== queryParams[k]);
|
||||
|
||||
if (
|
||||
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]
|
||||
) {
|
||||
if (changed) {
|
||||
this.router.navigate([], {
|
||||
queryParams,
|
||||
replaceUrl: true
|
||||
@@ -682,6 +745,15 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
||||
});
|
||||
}
|
||||
|
||||
capitalize(str: string): string {
|
||||
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, {
|
||||
|
||||
@@ -92,11 +92,11 @@
|
||||
}
|
||||
|
||||
.info-btn {
|
||||
top: 18%;
|
||||
top: 21%;
|
||||
}
|
||||
|
||||
.read-btn {
|
||||
bottom: 18%;
|
||||
bottom: 21%;
|
||||
}
|
||||
|
||||
.cover-container:hover .info-btn,
|
||||
|
||||
@@ -254,8 +254,8 @@ export class BookCardComponent implements OnInit {
|
||||
}
|
||||
|
||||
isMetadataFullyLocked(metadata: BookMetadata): boolean {
|
||||
return Object.keys(metadata)
|
||||
.filter(key => key.endsWith('Locked'))
|
||||
.every(key => metadata[key] === true);
|
||||
const lockedKeys = Object.keys(metadata).filter(key => key.endsWith('Locked'));
|
||||
if (lockedKeys.length === 0) return false;
|
||||
return lockedKeys.every(key => metadata[key] === true);
|
||||
}
|
||||
}
|
||||
|
||||
+19
-1
@@ -238,7 +238,25 @@ export class BookFilterComponent implements OnInit {
|
||||
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() {
|
||||
|
||||
+1
-1
@@ -62,7 +62,7 @@
|
||||
<td class="min-w-[10rem] max-w-[15rem] overflow-hidden truncate" [title]="getAuthorNames(metadata.authors)">{{ getAuthorNames(metadata.authors) }}</td>
|
||||
<td class="min-w-[9rem] max-w-[13rem] overflow-hidden truncate" [title]="metadata.publisher">{{ metadata.publisher }}</td>
|
||||
<td class="min-w-[9rem] max-w-[13rem] overflow-hidden truncate" [title]="metadata.seriesName">{{ metadata.seriesName }}</td>
|
||||
<td class="min-w-[1rem] max-w-[1rem] overflow-hidden truncate" [title]="metadata.seriesNumber">{{ metadata.seriesNumber }}</td>
|
||||
<td class="min-w-[1rem] max-w-[4rem] overflow-hidden truncate" [title]="metadata.seriesNumber">{{ metadata.seriesNumber }}</td>
|
||||
<td class="min-w-[12rem] max-w-[18rem] overflow-hidden truncate" [title]="getGenres(metadata.categories)">{{ getGenres(metadata.categories) }}</td>
|
||||
<td class="min-w-[9rem] max-w-[9rem] overflow-hidden truncate">
|
||||
{{ metadata.publishedDate ? (metadata.publishedDate | date: 'dd-MMM-yyyy') : '' }}
|
||||
|
||||
@@ -100,9 +100,9 @@ export class BookTableComponent implements OnChanges {
|
||||
}
|
||||
|
||||
isMetadataFullyLocked(metadata: BookMetadata): boolean {
|
||||
return Object.keys(metadata)
|
||||
.filter(key => key.endsWith('Locked'))
|
||||
.every(key => metadata[key] === true);
|
||||
const lockedKeys = Object.keys(metadata).filter(key => key.endsWith('Locked'));
|
||||
if (lockedKeys.length === 0) return false;
|
||||
return lockedKeys.every(key => metadata[key] === true);
|
||||
}
|
||||
|
||||
formatFileSize(kb?: number): string {
|
||||
|
||||
+31
-4
@@ -38,7 +38,22 @@
|
||||
tooltipPosition="top">
|
||||
</i>
|
||||
</div>
|
||||
<p class="text-xl">{{ getAuthorNames(metadata?.authors || []) }}</p>
|
||||
<p class="text-lg">
|
||||
@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 class="flex items-center gap-2 pt-2">
|
||||
@@ -107,9 +122,9 @@
|
||||
<a class="flex items-center gap-1" [href]="'https://books.google.com/books?id=' + metadata.googleId" target="_blank" rel="noopener noreferrer">
|
||||
<img src="https://books.google.com/favicon.ico" alt="Google Books" class="w-5 h-5 object-contain transform transition duration-200 hover:scale-125 hover:drop-shadow-lg" />
|
||||
</a>
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
} @else {
|
||||
|
||||
<p-rating
|
||||
@@ -125,7 +140,19 @@
|
||||
</div>
|
||||
<div class="flex gap-2 pt-4 overflow-x-auto scrollbar-hide">
|
||||
@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 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 {MetadataRefreshType} from '../../model/request/metadata-refresh-type.enum';
|
||||
import {MetadataRefreshRequest} from '../../model/request/metadata-refresh-request.model';
|
||||
import {RouterLink} from '@angular/router';
|
||||
|
||||
@Component({
|
||||
selector: 'app-metadata-viewer',
|
||||
standalone: true,
|
||||
templateUrl: './metadata-viewer.component.html',
|
||||
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 {
|
||||
|
||||
|
||||
@@ -45,20 +45,32 @@ export class SortService {
|
||||
const {field, direction} = selectedSort;
|
||||
const extractor = this.fieldExtractors[field];
|
||||
|
||||
if (!extractor) return books;
|
||||
if (!extractor) {
|
||||
console.warn(`[SortService] No extractor for field: ${field}`);
|
||||
return books;
|
||||
}
|
||||
|
||||
return books.sort((a, b) => {
|
||||
const valueA = extractor(a);
|
||||
const valueB = extractor(b);
|
||||
return books.slice().sort((a, b) => {
|
||||
const aValue = extractor(a);
|
||||
const bValue = extractor(b);
|
||||
|
||||
if (valueA === null || valueA === undefined) return 1;
|
||||
if (valueB === null || valueB === undefined) return -1;
|
||||
let result: number;
|
||||
|
||||
if (direction === SortDirection.ASCENDING) {
|
||||
return valueA < valueB ? -1 : valueA > valueB ? 1 : 0;
|
||||
if (Array.isArray(aValue) && Array.isArray(bValue)) {
|
||||
const nameCompare = aValue[0]?.localeCompare?.(bValue[0]) ?? 0;
|
||||
result = nameCompare !== 0 ? nameCompare : (aValue[1] - bValue[1]);
|
||||
} else if (typeof aValue === 'string' && typeof bValue === 'string') {
|
||||
result = aValue.localeCompare(bValue);
|
||||
} else if (typeof aValue === 'number' && typeof bValue === 'number') {
|
||||
result = aValue - bValue;
|
||||
} else {
|
||||
return valueA > valueB ? -1 : valueA < valueB ? 1 : 0;
|
||||
// Handle nulls or mismatches
|
||||
if (aValue == null && bValue != null) return 1;
|
||||
if (aValue != null && bValue == null) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return direction === SortDirection.ASCENDING ? result : -result;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user