diff --git a/booklore-ui/src/app/book/components/book-browser/book-browser.component.ts b/booklore-ui/src/app/book/components/book-browser/book-browser.component.ts index f7acee6c6..f85d3fa85 100644 --- a/booklore-ui/src/app/book/components/book-browser/book-browser.component.ts +++ b/booklore-ui/src/app/book/components/book-browser/book-browser.component.ts @@ -93,7 +93,6 @@ export class BookBrowserComponent implements OnInit, AfterViewInit { private dialogService = inject(DialogService); private sortService = inject(SortService); private libraryShelfMenuService = inject(LibraryShelfMenuService); - private confirmationService = inject(ConfirmationService); protected resetFilterSubject = new Subject(); @@ -101,16 +100,20 @@ export class BookBrowserComponent implements OnInit, AfterViewInit { sortOptions: any[] = [ {label: 'Title', icon: '', field: 'title', command: () => this.sortBooks('title')}, {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: 'Published', icon: '', field: 'publishedDate', command: () => this.sortBooks('publishedDate')}, - {label: 'Pages', icon: '', field: 'pageCount', command: () => this.sortBooks('pageCount')}, - {label: 'Rating', icon: '', field: 'rating', command: () => this.sortBooks('rating')}, - {label: 'Reviews', icon: '', field: 'reviewCount', command: () => this.sortBooks('reviewCount')}, + {label: 'Published Date', icon: '', field: 'publishedDate', command: () => this.sortBooks('publishedDate')}, + {label: 'Rating (Legacy)', icon: '', field: 'rating', command: () => this.sortBooks('rating')}, + {label: 'Amazon Rating', icon: '', field: 'amazonRating', command: () => this.sortBooks('amazonRating')}, + {label: 'Goodreads Rating', icon: '', field: 'goodreadsRating', command: () => this.sortBooks('goodreadsRating')}, + {label: 'Pages', icon: '', field: 'pageCount', command: () => this.sortBooks('pageCount')} ]; selectedSort: SortOption = { - label: 'Title', - field: 'title', + label: 'Added On', + field: 'addedOn', 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 { this.bookOrAuthor$.next(newTitle); } @@ -496,7 +486,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit { } }); this.dynamicDialogRef.onClose.subscribe(() => { - this.deselectAllBooks(); + this.deselectAllBooks(); }); } } diff --git a/booklore-ui/src/app/book/components/book-browser/book-table/book-table.component.html b/booklore-ui/src/app/book/components/book-browser/book-table/book-table.component.html index 55e71648e..f20caebca 100644 --- a/booklore-ui/src/app/book/components/book-browser/book-table/book-table.component.html +++ b/booklore-ui/src/app/book/components/book-browser/book-table/book-table.component.html @@ -37,10 +37,10 @@ diff --git a/booklore-ui/src/app/book/components/book-browser/book-table/book-table.component.ts b/booklore-ui/src/app/book/components/book-browser/book-table/book-table.component.ts index f71ffc311..b3e2c12aa 100644 --- a/booklore-ui/src/app/book/components/book-browser/book-table/book-table.component.ts +++ b/booklore-ui/src/app/book/components/book-browser/book-table/book-table.component.ts @@ -99,8 +99,17 @@ export class BookTableComponent implements OnChanges { 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 { - 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({ next: () => { this.messageService.add({ diff --git a/booklore-ui/src/app/book/model/book.model.ts b/booklore-ui/src/app/book/model/book.model.ts index 48b2e4d00..5c5aefd6b 100644 --- a/booklore-ui/src/app/book/model/book.model.ts +++ b/booklore-ui/src/app/book/model/book.model.ts @@ -44,7 +44,6 @@ export interface BookMetadata { providerBookId?: string; thumbnailUrl?: string | null; - allFieldsLocked?: boolean; titleLocked?: boolean; subtitleLocked?: boolean; publisherLocked?: boolean; diff --git a/booklore-ui/src/app/book/service/sort.service.ts b/booklore-ui/src/app/book/service/sort.service.ts index 57848b11f..89a59e417 100644 --- a/booklore-ui/src/app/book/service/sort.service.ts +++ b/booklore-ui/src/app/book/service/sort.service.ts @@ -10,11 +10,21 @@ export class SortService { private readonly fieldExtractors: Record any> = { title: (book) => book.metadata?.title?.toLowerCase() || 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, pageCount: (book) => book.metadata?.pageCount || null, rating: (book) => book.metadata?.rating || 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[] { diff --git a/booklore-ui/src/app/metadata/book-metadata-center/book-metadata-center.component.ts b/booklore-ui/src/app/metadata/book-metadata-center/book-metadata-center.component.ts index 1843a0739..ccc4abaed 100644 --- a/booklore-ui/src/app/metadata/book-metadata-center/book-metadata-center.component.ts +++ b/booklore-ui/src/app/metadata/book-metadata-center/book-metadata-center.component.ts @@ -8,7 +8,7 @@ import {distinctUntilChanged, filter, map, switchMap, take} from 'rxjs/operators import {BookService} from '../../book/service/book.service'; import {AppSettingsService} from '../../core/service/app-settings.service'; 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 {MetadataEditorComponent} from './metadata-editor/metadata-editor.component'; import {MetadataSearcherComponent} from './metadata-searcher/metadata-searcher.component'; @@ -27,8 +27,7 @@ import {MetadataSearcherComponent} from './metadata-searcher/metadata-searcher.c MetadataViewerComponent, TabPanel, MetadataEditorComponent, - MetadataSearcherComponent, - NgTemplateOutlet + MetadataSearcherComponent ] }) export class BookMetadataCenterComponent implements OnInit, OnDestroy {