Add more sort options

This commit is contained in:
adityachandelgit
2025-04-21 19:41:33 -06:00
committed by Aditya Chandel
parent b15e1dc642
commit ff59e0b3ce
6 changed files with 37 additions and 30 deletions
@@ -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<void>();
@@ -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();
});
}
}
@@ -37,10 +37,10 @@
</td>
<td class="text-center">
<p-button
[icon]="metadata.allFieldsLocked ? 'pi pi-lock' : 'pi pi-lock-open'"
[severity]="metadata.allFieldsLocked ? 'danger' : 'success'"
[icon]="isMetadataFullyLocked(metadata) ? 'pi pi-lock' : 'pi pi-lock-open'"
[severity]="isMetadataFullyLocked(metadata) ? 'danger' : 'success'"
[text]="true"
[title]="metadata.allFieldsLocked ? 'Locked' : 'Unlocked'"
[title]="isMetadataFullyLocked(metadata) ? 'Locked' : 'Unlocked'"
size="small"
[style]="{ width: '1.5rem', height: '1.5rem', padding: '0', fontSize: '0.75rem' }"
(click)="toggleMetadataLock(metadata)">
@@ -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({