feat: add support for personal book ratings
- Introduced 'personalRating' field in book metadata - Added UI for 10-star rating input - Persist personal ratings via updateBookMetadata API - Updated filters and sorting to include personal rating range
This commit is contained in:
committed by
Aditya Chandel
parent
ce96fcff6d
commit
cd4e14c8ad
@@ -41,7 +41,6 @@ import {Popover} from 'primeng/popover';
|
||||
import {Slider} from 'primeng/slider';
|
||||
import {Select} from 'primeng/select';
|
||||
import {FilterSortPreferenceService} from './filters/filter-sorting-preferences.service';
|
||||
import {TieredMenu} from 'primeng/tieredmenu';
|
||||
import {Divider} from 'primeng/divider';
|
||||
|
||||
export enum EntityType {
|
||||
@@ -75,7 +74,7 @@ const SORT_DIRECTION = {
|
||||
standalone: true,
|
||||
templateUrl: './book-browser.component.html',
|
||||
styleUrls: ['./book-browser.component.scss'],
|
||||
imports: [Button, VirtualScrollerModule, BookCardComponent, AsyncPipe, ProgressSpinner, Menu, InputText, FormsModule, BookTableComponent, BookFilterComponent, Tooltip, NgClass, Fluid, PrimeTemplate, NgStyle, OverlayPanelModule, DropdownModule, Checkbox, Popover, Slider, Select, TieredMenu, Divider],
|
||||
imports: [Button, VirtualScrollerModule, BookCardComponent, AsyncPipe, ProgressSpinner, Menu, InputText, FormsModule, BookTableComponent, BookFilterComponent, Tooltip, NgClass, Fluid, PrimeTemplate, NgStyle, OverlayPanelModule, DropdownModule, Checkbox, Popover, Slider, Select, Divider],
|
||||
providers: [SeriesCollapseFilter],
|
||||
animations: [
|
||||
trigger('slideInOut', [
|
||||
|
||||
+71
-50
@@ -17,60 +17,79 @@ import {FilterSortPreferenceService} from '../filters/filter-sorting-preferences
|
||||
type Filter<T> = { value: T; bookCount: number };
|
||||
|
||||
export const ratingRanges = [
|
||||
{id: '0to1', label: '0 to 1', min: 0, max: 1},
|
||||
{id: '1to2', label: '1 to 2', min: 1, max: 2},
|
||||
{id: '2to3', label: '2 to 3', min: 2, max: 3},
|
||||
{id: '3to4', label: '3 to 4', min: 3, max: 4},
|
||||
{id: '4to4.5', label: '4 to 4.5', min: 4, max: 4.5},
|
||||
{id: '4.5plus', label: '4.5+', min: 4.5, max: Infinity}
|
||||
{id: '0to1', label: '0 to 1', min: 0, max: 1, sortIndex: 0},
|
||||
{id: '1to2', label: '1 to 2', min: 1, max: 2, sortIndex: 1},
|
||||
{id: '2to3', label: '2 to 3', min: 2, max: 3, sortIndex: 2},
|
||||
{id: '3to4', label: '3 to 4', min: 3, max: 4, sortIndex: 3},
|
||||
{id: '4to4.5', label: '4 to 4.5', min: 4, max: 4.5, sortIndex: 4},
|
||||
{id: '4.5plus', label: '4.5+', min: 4.5, max: Infinity, sortIndex: 5}
|
||||
];
|
||||
|
||||
export const ratingRanges10 = [
|
||||
{id: '0to1', label: '0 to 1', min: 0, max: 1, sortIndex: 0},
|
||||
{id: '1to2', label: '1 to 2', min: 1, max: 2, sortIndex: 1},
|
||||
{id: '2to3', label: '2 to 3', min: 2, max: 3, sortIndex: 2},
|
||||
{id: '3to4', label: '3 to 4', min: 3, max: 4, sortIndex: 3},
|
||||
{id: '4to5', label: '4 to 5', min: 4, max: 5, sortIndex: 4},
|
||||
{id: '5to6', label: '5 to 6', min: 5, max: 6, sortIndex: 5},
|
||||
{id: '6to7', label: '6 to 7', min: 6, max: 7, sortIndex: 6},
|
||||
{id: '7to8', label: '7 to 8', min: 7, max: 8, sortIndex: 7},
|
||||
{id: '8to9', label: '8 to 9', min: 8, max: 9, sortIndex: 8},
|
||||
{id: '9to10', label: '9 to 10', min: 9, max: 10, sortIndex: 9}
|
||||
];
|
||||
|
||||
export const fileSizeRanges = [
|
||||
{id: '<1mb', label: '< 1 MB', min: 0, max: 1024},
|
||||
{id: '1to10mb', label: '1–10 MB', min: 1024, max: 10240},
|
||||
{id: '10to50mb', label: '10–50 MB', min: 10240, max: 51200},
|
||||
{id: '50to100mb', label: '50–100 MB', min: 51200, max: 102400},
|
||||
{id: '250to500mb', label: '250–500 MB', min: 256000, max: 512000},
|
||||
{id: '500mbto1gb', label: '500 MB – 1 GB', min: 512000, max: 1048576},
|
||||
{id: '1to2gb', label: '1–2 GB', min: 1048576, max: 2097152},
|
||||
{id: '5plusgb', label: '5+ GB', min: 5242880, max: Infinity}
|
||||
{id: '<1mb', label: '< 1 MB', min: 0, max: 1024, sortIndex: 0},
|
||||
{id: '1to10mb', label: '1–10 MB', min: 1024, max: 10240, sortIndex: 1},
|
||||
{id: '10to50mb', label: '10–50 MB', min: 10240, max: 51200, sortIndex: 2},
|
||||
{id: '50to100mb', label: '50–100 MB', min: 51200, max: 102400, sortIndex: 3},
|
||||
{id: '250to500mb', label: '250–500 MB', min: 256000, max: 512000, sortIndex: 4},
|
||||
{id: '500mbto1gb', label: '0.5–1 GB', min: 512000, max: 1048576, sortIndex: 5},
|
||||
{id: '1to2gb', label: '1–2 GB', min: 1048576, max: 2097152, sortIndex: 6},
|
||||
{id: '5plusgb', label: '5+ GB', min: 5242880, max: Infinity, sortIndex: 7}
|
||||
];
|
||||
|
||||
export const pageCountRanges = [
|
||||
{id: '<50', label: '< 50 pages', min: 0, max: 50},
|
||||
{id: '50to100', label: '50–100 pages', min: 50, max: 100},
|
||||
{id: '100to200', label: '100–200 pages', min: 100, max: 200},
|
||||
{id: '200to400', label: '200–400 pages', min: 200, max: 400},
|
||||
{id: '400to600', label: '400–600 pages', min: 400, max: 600},
|
||||
{id: '600to1000', label: '600–1000 pages', min: 600, max: 1000},
|
||||
{id: '1000plus', label: '1000+ pages', min: 1000, max: Infinity}
|
||||
{id: '<50', label: '< 50 pages', min: 0, max: 50, sortIndex: 0},
|
||||
{id: '50to100', label: '50–100 pages', min: 50, max: 100, sortIndex: 1},
|
||||
{id: '100to200', label: '100–200 pages', min: 100, max: 200, sortIndex: 2},
|
||||
{id: '200to400', label: '200–400 pages', min: 200, max: 400, sortIndex: 3},
|
||||
{id: '400to600', label: '400–600 pages', min: 400, max: 600, sortIndex: 4},
|
||||
{id: '600to1000', label: '600–1000 pages', min: 600, max: 1000, sortIndex: 5},
|
||||
{id: '1000plus', label: '1000+ pages', min: 1000, max: Infinity, sortIndex: 6}
|
||||
];
|
||||
|
||||
export const matchScoreRanges = [
|
||||
{id: '0.95-1.0', min: 0.95, max: 1.01, name: 'Outstanding (95–100%)', sortIndex: 0},
|
||||
{id: '0.90-0.94', min: 0.90, max: 0.95, name: 'Excellent (90–94%)', sortIndex: 1},
|
||||
{id: '0.80-0.89', min: 0.80, max: 0.90, name: 'Great (80–89%)', sortIndex: 2},
|
||||
{id: '0.70-0.79', min: 0.70, max: 0.80, name: 'Good (70–79%)', sortIndex: 3},
|
||||
{id: '0.50-0.69', min: 0.50, max: 0.70, name: 'Fair (50–69%)', sortIndex: 4},
|
||||
{id: '0.30-0.49', min: 0.30, max: 0.50, name: 'Weak (30–49%)', sortIndex: 5},
|
||||
{id: '0.00-0.29', min: 0.00, max: 0.30, name: 'Poor (0–29%)', sortIndex: 6}
|
||||
{id: '0.95-1.0', min: 0.95, max: 1.01, label: 'Outstanding (95–100%)', sortIndex: 0},
|
||||
{id: '0.90-0.94', min: 0.90, max: 0.95, label: 'Excellent (90–94%)', sortIndex: 1},
|
||||
{id: '0.80-0.89', min: 0.80, max: 0.90, label: 'Great (80–89%)', sortIndex: 2},
|
||||
{id: '0.70-0.79', min: 0.70, max: 0.80, label: 'Good (70–79%)', sortIndex: 3},
|
||||
{id: '0.50-0.69', min: 0.50, max: 0.70, label: 'Fair (50–69%)', sortIndex: 4},
|
||||
{id: '0.30-0.49', min: 0.30, max: 0.50, label: 'Weak (30–49%)', sortIndex: 5},
|
||||
{id: '0.00-0.29', min: 0.00, max: 0.30, label: 'Poor (0–29%)', sortIndex: 6}
|
||||
];
|
||||
|
||||
const getLanguageFilter = (book: Book) => {
|
||||
function getLanguageFilter(book: Book): { id: string; name: string }[] {
|
||||
const lang = book.metadata?.language;
|
||||
return lang ? [{id: lang, name: lang}] : [];
|
||||
};
|
||||
|
||||
function getFileSizeRangeFilters(sizeKb?: number) {
|
||||
if (sizeKb == null) return [];
|
||||
const match = fileSizeRanges.find(r => sizeKb >= r.min && sizeKb < r.max);
|
||||
return match ? [{id: match.id, name: match.label}] : [];
|
||||
}
|
||||
|
||||
function getRatingRangeFilters(rating?: number) {
|
||||
function getFileSizeRangeFilters(sizeKb?: number): { id: string; name: string; sortIndex?: number }[] {
|
||||
if (sizeKb == null) return [];
|
||||
const match = fileSizeRanges.find(r => sizeKb >= r.min && sizeKb < r.max);
|
||||
return match ? [{id: match.id, name: match.label, sortIndex: match.sortIndex}] : [];
|
||||
}
|
||||
|
||||
function getRatingRangeFilters(rating?: number): { id: string; name: string; sortIndex?: number }[] {
|
||||
if (rating == null) return [];
|
||||
const match = ratingRanges.find(r => rating >= r.min && rating < r.max);
|
||||
return match ? [{id: match.id, name: match.label}] : [];
|
||||
return match ? [{id: match.id, name: match.label, sortIndex: match.sortIndex}] : [];
|
||||
}
|
||||
|
||||
function getRatingRangeFilters10(rating?: number): { id: string; name: string; sortIndex?: number }[] {
|
||||
if (rating == null) return [];
|
||||
const match = ratingRanges10.find(r => rating >= r.min && rating < r.max);
|
||||
return match ? [{id: match.id, name: match.label, sortIndex: match.sortIndex}] : [];
|
||||
}
|
||||
|
||||
function extractPublishedYearFilter(book: Book): { id: number; name: string }[] {
|
||||
@@ -81,20 +100,20 @@ function extractPublishedYearFilter(book: Book): { id: number; name: string }[]
|
||||
}
|
||||
|
||||
function getShelfStatusFilter(book: Book): { id: string; name: string }[] {
|
||||
const isShelved = book.shelves && book.shelves.length > 0;
|
||||
const isShelved = book.shelves?.length! > 0;
|
||||
return [{id: isShelved ? 'shelved' : 'unshelved', name: isShelved ? 'Shelved' : 'Unshelved'}];
|
||||
}
|
||||
|
||||
function getPageCountRangeFilters(pageCount?: number) {
|
||||
function getPageCountRangeFilters(pageCount?: number): { id: string; name: string; sortIndex?: number }[] {
|
||||
if (pageCount == null) return [];
|
||||
const match = pageCountRanges.find(r => pageCount >= r.min && pageCount < r.max);
|
||||
return match ? [{id: match.id, name: match.label}] : [];
|
||||
return match ? [{id: match.id, name: match.label, sortIndex: match.sortIndex}] : [];
|
||||
}
|
||||
|
||||
export function getMatchScoreRangeFilters(score?: number | null): { id: string; name: string; sortIndex?: number }[] {
|
||||
function getMatchScoreRangeFilters(score?: number | null): { id: string; name: string; sortIndex?: number }[] {
|
||||
if (score == null) return [];
|
||||
const match = matchScoreRanges.find(r => score >= r.min && score < r.max);
|
||||
return match ? [{id: match.id, name: match.name, sortIndex: match.sortIndex}] : [];
|
||||
return match ? [{id: match.id, name: match.label, sortIndex: match.sortIndex}] : [];
|
||||
}
|
||||
|
||||
@Component({
|
||||
@@ -138,6 +157,8 @@ export class BookFilterComponent implements OnInit, OnDestroy {
|
||||
category: 'Category',
|
||||
series: 'Series',
|
||||
publisher: 'Publisher',
|
||||
personalRating: 'Personal Rating',
|
||||
matchScore: 'Metadata Match Score',
|
||||
amazonRating: 'Amazon Rating',
|
||||
goodreadsRating: 'Goodreads Rating',
|
||||
hardcoverRating: 'Hardcover Rating',
|
||||
@@ -145,8 +166,7 @@ export class BookFilterComponent implements OnInit, OnDestroy {
|
||||
fileSize: 'File Size',
|
||||
shelfStatus: 'Shelf Status',
|
||||
pageCount: 'Page Count',
|
||||
language: 'Language',
|
||||
matchScore: 'Metadata Match Score'
|
||||
language: 'Language'
|
||||
};
|
||||
|
||||
private destroy$ = new Subject<void>();
|
||||
@@ -167,16 +187,17 @@ export class BookFilterComponent implements OnInit, OnDestroy {
|
||||
author: this.getFilterStream((book: Book) => book.metadata?.authors.map(name => ({id: name, name})) || [], 'id', 'name', sortMode),
|
||||
category: this.getFilterStream((book: Book) => book.metadata?.categories.map(name => ({id: name, name})) || [], 'id', 'name', sortMode),
|
||||
series: this.getFilterStream((book) => (book.metadata?.seriesName ? [{id: book.metadata.seriesName, name: book.metadata.seriesName}] : []), 'id', 'name', sortMode),
|
||||
matchScore: this.getFilterStream((book: Book) => getMatchScoreRangeFilters(book.metadataMatchScore), 'id', 'name', 'sortIndex'),
|
||||
publisher: this.getFilterStream((book) => (book.metadata?.publisher ? [{id: book.metadata.publisher, name: book.metadata.publisher}] : []), 'id', 'name', sortMode),
|
||||
matchScore: this.getFilterStream((book: Book) => getMatchScoreRangeFilters(book.metadataMatchScore), 'id', 'name', 'sortIndex'),
|
||||
personalRating: this.getFilterStream((book: Book) => getRatingRangeFilters10(book.metadata?.personalRating!), 'id', 'name', 'sortIndex'),
|
||||
amazonRating: this.getFilterStream((book: Book) => getRatingRangeFilters(book.metadata?.amazonRating!), 'id', 'name', 'sortIndex'),
|
||||
goodreadsRating: this.getFilterStream((book: Book) => getRatingRangeFilters(book.metadata?.goodreadsRating!), 'id', 'name', 'sortIndex'),
|
||||
hardcoverRating: this.getFilterStream((book: Book) => getRatingRangeFilters(book.metadata?.hardcoverRating!), 'id', 'name', 'sortIndex'),
|
||||
shelfStatus: this.getFilterStream(getShelfStatusFilter, 'id', 'name', sortMode),
|
||||
publishedDate: this.getFilterStream(extractPublishedYearFilter, 'id', 'name', sortMode),
|
||||
language: this.getFilterStream(getLanguageFilter, 'id', 'name', sortMode),
|
||||
fileSize: this.getFilterStream((book: Book) => getFileSizeRangeFilters(book.fileSizeKb), 'id', 'name', sortMode),
|
||||
amazonRating: this.getFilterStream((book: Book) => getRatingRangeFilters(book.metadata?.amazonRating!), 'id', 'name', sortMode),
|
||||
goodreadsRating: this.getFilterStream((book: Book) => getRatingRangeFilters(book.metadata?.goodreadsRating!), 'id', 'name', sortMode),
|
||||
hardcoverRating: this.getFilterStream((book: Book) => getRatingRangeFilters(book.metadata?.hardcoverRating!), 'id', 'name', sortMode),
|
||||
pageCount: this.getFilterStream((book: Book) => getPageCountRangeFilters(book.metadata?.pageCount!), 'id', 'name', sortMode),
|
||||
fileSize: this.getFilterStream((book: Book) => getFileSizeRangeFilters(book.fileSizeKb), 'id', 'name', 'sortIndex'),
|
||||
pageCount: this.getFilterStream((book: Book) => getPageCountRangeFilters(book.metadata?.pageCount!), 'id', 'name', 'sortIndex'),
|
||||
};
|
||||
|
||||
this.filterTypes = Object.keys(this.filterStreams);
|
||||
|
||||
@@ -2,7 +2,7 @@ import {Observable, combineLatest, of} from 'rxjs';
|
||||
import {map} from 'rxjs/operators';
|
||||
import {BookFilter} from './BookFilter';
|
||||
import {BookState} from '../../../model/state/book-state.model';
|
||||
import {fileSizeRanges, matchScoreRanges, pageCountRanges, ratingRanges} from '../book-filter/book-filter.component';
|
||||
import {fileSizeRanges, matchScoreRanges, pageCountRanges, ratingRanges, ratingRanges10} from '../book-filter/book-filter.component';
|
||||
|
||||
export function isRatingInRange(rating: number | undefined | null, rangeId: string): boolean {
|
||||
if (rating == null) return false;
|
||||
@@ -11,6 +11,13 @@ export function isRatingInRange(rating: number | undefined | null, rangeId: stri
|
||||
return rating >= range.min && rating < range.max;
|
||||
}
|
||||
|
||||
export function isRatingInRange10(rating: number | undefined | null, rangeId: string): boolean {
|
||||
if (rating == null) return false;
|
||||
const range = ratingRanges10.find(r => r.id === rangeId);
|
||||
if (!range) return false;
|
||||
return rating >= range.min && rating < range.max;
|
||||
}
|
||||
|
||||
export function isFileSizeInRange(fileSizeKb: number | undefined, rangeId: string): boolean {
|
||||
if (fileSizeKb == null) return false;
|
||||
const range = fileSizeRanges.find(r => r.id === rangeId);
|
||||
@@ -69,6 +76,8 @@ export class SideBarFilter implements BookFilter {
|
||||
return filterValues.some(range => isRatingInRange(book.metadata?.goodreadsRating, range));
|
||||
case 'hardcoverRating':
|
||||
return filterValues.some(range => isRatingInRange(book.metadata?.hardcoverRating, range));
|
||||
case 'personalRating':
|
||||
return filterValues.some(range => isRatingInRange10(book.metadata?.personalRating, range));
|
||||
case 'publishedDate':
|
||||
return filterValues.includes(new Date(book.metadata?.publishedDate || '').getFullYear());
|
||||
case 'fileSize':
|
||||
|
||||
Reference in New Issue
Block a user