Add more sort options
This commit is contained in:
committed by
Aditya Chandel
parent
b15e1dc642
commit
ff59e0b3ce
@@ -93,7 +93,6 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
|||||||
private dialogService = inject(DialogService);
|
private dialogService = inject(DialogService);
|
||||||
private sortService = inject(SortService);
|
private sortService = inject(SortService);
|
||||||
private libraryShelfMenuService = inject(LibraryShelfMenuService);
|
private libraryShelfMenuService = inject(LibraryShelfMenuService);
|
||||||
private confirmationService = inject(ConfirmationService);
|
|
||||||
|
|
||||||
protected resetFilterSubject = new Subject<void>();
|
protected resetFilterSubject = new Subject<void>();
|
||||||
|
|
||||||
@@ -101,16 +100,20 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
|||||||
sortOptions: any[] = [
|
sortOptions: any[] = [
|
||||||
{label: 'Title', icon: '', field: 'title', command: () => this.sortBooks('title')},
|
{label: 'Title', icon: '', field: 'title', command: () => this.sortBooks('title')},
|
||||||
{label: 'Author', icon: '', field: 'author', command: () => this.sortBooks('author')},
|
{label: 'Author', icon: '', field: 'author', command: () => this.sortBooks('author')},
|
||||||
|
{label: 'Last Read', field: 'lastReadTime', command: () => this.sortBooks('lastReadTime')},
|
||||||
|
{label: 'Added On', field: 'addedOn', command: () => this.sortBooks('addedOn')},
|
||||||
|
{label: 'Locked', icon: '', field: 'locked', command: () => this.sortBooks('locked')},
|
||||||
{label: 'Publisher', icon: '', field: 'publisher', command: () => this.sortBooks('publisher')},
|
{label: 'Publisher', icon: '', field: 'publisher', command: () => this.sortBooks('publisher')},
|
||||||
{label: 'Published', icon: '', field: 'publishedDate', command: () => this.sortBooks('publishedDate')},
|
{label: 'Published Date', icon: '', field: 'publishedDate', command: () => this.sortBooks('publishedDate')},
|
||||||
{label: 'Pages', icon: '', field: 'pageCount', command: () => this.sortBooks('pageCount')},
|
{label: 'Rating (Legacy)', icon: '', field: 'rating', command: () => this.sortBooks('rating')},
|
||||||
{label: 'Rating', icon: '', field: 'rating', command: () => this.sortBooks('rating')},
|
{label: 'Amazon Rating', icon: '', field: 'amazonRating', command: () => this.sortBooks('amazonRating')},
|
||||||
{label: 'Reviews', icon: '', field: 'reviewCount', command: () => this.sortBooks('reviewCount')},
|
{label: 'Goodreads Rating', icon: '', field: 'goodreadsRating', command: () => this.sortBooks('goodreadsRating')},
|
||||||
|
{label: 'Pages', icon: '', field: 'pageCount', command: () => this.sortBooks('pageCount')}
|
||||||
];
|
];
|
||||||
|
|
||||||
selectedSort: SortOption = {
|
selectedSort: SortOption = {
|
||||||
label: 'Title',
|
label: 'Added On',
|
||||||
field: 'title',
|
field: 'addedOn',
|
||||||
direction: SortDirection.DESCENDING,
|
direction: SortDirection.DESCENDING,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -386,19 +389,6 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private setSelectedSortFromEntity(entity: Library | Shelf | null): void {
|
|
||||||
if (entity?.sort) {
|
|
||||||
const {field, direction} = entity.sort;
|
|
||||||
this.selectedSort = this.sortOptions.find(option => option.field === field && option.direction === direction) || null;
|
|
||||||
} else {
|
|
||||||
this.selectedSort = {
|
|
||||||
label: 'Title',
|
|
||||||
field: 'title',
|
|
||||||
direction: SortDirection.ASCENDING,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onBookTitleChange(newTitle: string): void {
|
onBookTitleChange(newTitle: string): void {
|
||||||
this.bookOrAuthor$.next(newTitle);
|
this.bookOrAuthor$.next(newTitle);
|
||||||
}
|
}
|
||||||
@@ -496,7 +486,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.dynamicDialogRef.onClose.subscribe(() => {
|
this.dynamicDialogRef.onClose.subscribe(() => {
|
||||||
this.deselectAllBooks();
|
this.deselectAllBooks();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -37,10 +37,10 @@
|
|||||||
</td>
|
</td>
|
||||||
<td class="text-center">
|
<td class="text-center">
|
||||||
<p-button
|
<p-button
|
||||||
[icon]="metadata.allFieldsLocked ? 'pi pi-lock' : 'pi pi-lock-open'"
|
[icon]="isMetadataFullyLocked(metadata) ? 'pi pi-lock' : 'pi pi-lock-open'"
|
||||||
[severity]="metadata.allFieldsLocked ? 'danger' : 'success'"
|
[severity]="isMetadataFullyLocked(metadata) ? 'danger' : 'success'"
|
||||||
[text]="true"
|
[text]="true"
|
||||||
[title]="metadata.allFieldsLocked ? 'Locked' : 'Unlocked'"
|
[title]="isMetadataFullyLocked(metadata) ? 'Locked' : 'Unlocked'"
|
||||||
size="small"
|
size="small"
|
||||||
[style]="{ width: '1.5rem', height: '1.5rem', padding: '0', fontSize: '0.75rem' }"
|
[style]="{ width: '1.5rem', height: '1.5rem', padding: '0', fontSize: '0.75rem' }"
|
||||||
(click)="toggleMetadataLock(metadata)">
|
(click)="toggleMetadataLock(metadata)">
|
||||||
|
|||||||
+10
-1
@@ -99,8 +99,17 @@ export class BookTableComponent implements OnChanges {
|
|||||||
return genres?.join(', ') || '';
|
return genres?.join(', ') || '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isMetadataFullyLocked(metadata: BookMetadata): boolean {
|
||||||
|
return Object.keys(metadata)
|
||||||
|
.filter(key => key.endsWith('Locked'))
|
||||||
|
.every(key => metadata[key] === true);
|
||||||
|
}
|
||||||
|
|
||||||
toggleMetadataLock(metadata: BookMetadata): void {
|
toggleMetadataLock(metadata: BookMetadata): void {
|
||||||
const lockAction = metadata.allFieldsLocked ? 'UNLOCK' : 'LOCK';
|
const lockKeys = Object.keys(metadata).filter(key => key.endsWith('Locked'));
|
||||||
|
const allLocked = lockKeys.every(key => metadata[key] === true);
|
||||||
|
const lockAction = allLocked ? 'UNLOCK' : 'LOCK';
|
||||||
|
|
||||||
this.bookService.toggleAllLock(new Set([metadata.bookId]), lockAction).subscribe({
|
this.bookService.toggleAllLock(new Set([metadata.bookId]), lockAction).subscribe({
|
||||||
next: () => {
|
next: () => {
|
||||||
this.messageService.add({
|
this.messageService.add({
|
||||||
|
|||||||
@@ -44,7 +44,6 @@ export interface BookMetadata {
|
|||||||
providerBookId?: string;
|
providerBookId?: string;
|
||||||
thumbnailUrl?: string | null;
|
thumbnailUrl?: string | null;
|
||||||
|
|
||||||
allFieldsLocked?: boolean;
|
|
||||||
titleLocked?: boolean;
|
titleLocked?: boolean;
|
||||||
subtitleLocked?: boolean;
|
subtitleLocked?: boolean;
|
||||||
publisherLocked?: boolean;
|
publisherLocked?: boolean;
|
||||||
|
|||||||
@@ -10,11 +10,21 @@ export class SortService {
|
|||||||
private readonly fieldExtractors: Record<string, (book: Book) => any> = {
|
private readonly fieldExtractors: Record<string, (book: Book) => any> = {
|
||||||
title: (book) => book.metadata?.title?.toLowerCase() || null,
|
title: (book) => book.metadata?.title?.toLowerCase() || null,
|
||||||
author: (book) => book.metadata?.authors?.map(a => a.toLowerCase()).join(", ") || null,
|
author: (book) => book.metadata?.authors?.map(a => a.toLowerCase()).join(", ") || null,
|
||||||
publishedDate: (book) =>book.metadata?.publishedDate === null ? null : new Date(book.metadata?.publishedDate!).getTime(),
|
publishedDate: (book) => book.metadata?.publishedDate === null ? null : new Date(book.metadata?.publishedDate!).getTime(),
|
||||||
publisher: (book) => book.metadata?.publisher || null,
|
publisher: (book) => book.metadata?.publisher || null,
|
||||||
pageCount: (book) => book.metadata?.pageCount || null,
|
pageCount: (book) => book.metadata?.pageCount || null,
|
||||||
rating: (book) => book.metadata?.rating || null,
|
rating: (book) => book.metadata?.rating || null,
|
||||||
reviewCount: (book) => book.metadata?.reviewCount || null,
|
reviewCount: (book) => book.metadata?.reviewCount || null,
|
||||||
|
amazonRating: (book) => book.metadata?.amazonRating || null,
|
||||||
|
amazonReviewCount: (book) => book.metadata?.amazonReviewCount || null,
|
||||||
|
goodreadsRating: (book) => book.metadata?.goodreadsRating || null,
|
||||||
|
goodreadsReviewCount: (book) => book.metadata?.goodreadsReviewCount || null,
|
||||||
|
locked: (book) =>
|
||||||
|
Object.keys(book.metadata ?? {})
|
||||||
|
.filter((key) => key.endsWith('Locked'))
|
||||||
|
.every((key) => book.metadata?.[key] === true),
|
||||||
|
lastReadTime: (book) => book.lastReadTime ? new Date(book.lastReadTime).getTime() : null,
|
||||||
|
addedOn: (book) => book.addedOn ? new Date(book.addedOn).getTime() : null
|
||||||
};
|
};
|
||||||
|
|
||||||
applySort(books: Book[], selectedSort: SortOption | null): Book[] {
|
applySort(books: Book[], selectedSort: SortOption | null): Book[] {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import {distinctUntilChanged, filter, map, switchMap, take} from 'rxjs/operators
|
|||||||
import {BookService} from '../../book/service/book.service';
|
import {BookService} from '../../book/service/book.service';
|
||||||
import {AppSettingsService} from '../../core/service/app-settings.service';
|
import {AppSettingsService} from '../../core/service/app-settings.service';
|
||||||
import {Tab, TabList, TabPanel, TabPanels, Tabs} from 'primeng/tabs';
|
import {Tab, TabList, TabPanel, TabPanels, Tabs} from 'primeng/tabs';
|
||||||
import {NgIf, NgTemplateOutlet} from '@angular/common';
|
import {NgIf} from '@angular/common';
|
||||||
import {MetadataViewerComponent} from './metadata-viewer/metadata-viewer.component';
|
import {MetadataViewerComponent} from './metadata-viewer/metadata-viewer.component';
|
||||||
import {MetadataEditorComponent} from './metadata-editor/metadata-editor.component';
|
import {MetadataEditorComponent} from './metadata-editor/metadata-editor.component';
|
||||||
import {MetadataSearcherComponent} from './metadata-searcher/metadata-searcher.component';
|
import {MetadataSearcherComponent} from './metadata-searcher/metadata-searcher.component';
|
||||||
@@ -27,8 +27,7 @@ import {MetadataSearcherComponent} from './metadata-searcher/metadata-searcher.c
|
|||||||
MetadataViewerComponent,
|
MetadataViewerComponent,
|
||||||
TabPanel,
|
TabPanel,
|
||||||
MetadataEditorComponent,
|
MetadataEditorComponent,
|
||||||
MetadataSearcherComponent,
|
MetadataSearcherComponent
|
||||||
NgTemplateOutlet
|
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class BookMetadataCenterComponent implements OnInit, OnDestroy {
|
export class BookMetadataCenterComponent implements OnInit, OnDestroy {
|
||||||
|
|||||||
Reference in New Issue
Block a user