Merge pull request #683 from adityachandelgit/develop
Merge Develop into Master for release
This commit is contained in:
@@ -58,23 +58,31 @@ public class BookService {
|
|||||||
public List<Book> getBookDTOs(boolean includeDescription) {
|
public List<Book> getBookDTOs(boolean includeDescription) {
|
||||||
BookLoreUser user = authenticationService.getAuthenticatedUser();
|
BookLoreUser user = authenticationService.getAuthenticatedUser();
|
||||||
boolean isAdmin = user.getPermissions().isAdmin();
|
boolean isAdmin = user.getPermissions().isAdmin();
|
||||||
List<Book> books;
|
|
||||||
if (isAdmin) {
|
List<Book> books = isAdmin
|
||||||
books = bookQueryService.getAllBooks(includeDescription);
|
? bookQueryService.getAllBooks(includeDescription)
|
||||||
} else {
|
: bookQueryService.getAllBooksByLibraryIds(
|
||||||
Set<Long> libraryIds = user.getAssignedLibraries().stream()
|
user.getAssignedLibraries().stream()
|
||||||
.map(Library::getId)
|
.map(Library::getId)
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet()),
|
||||||
books = bookQueryService.getAllBooksByLibraryIds(libraryIds, includeDescription);
|
includeDescription
|
||||||
}
|
);
|
||||||
Map<Long, UserBookProgressEntity> progressMap = userProgressService.fetchUserProgress(user.getId(), books.stream().map(Book::getId).collect(Collectors.toSet()));
|
|
||||||
|
Map<Long, UserBookProgressEntity> progressMap =
|
||||||
|
userProgressService.fetchUserProgress(
|
||||||
|
user.getId(),
|
||||||
|
books.stream().map(Book::getId).collect(Collectors.toSet())
|
||||||
|
);
|
||||||
|
|
||||||
books.forEach(book -> {
|
books.forEach(book -> {
|
||||||
UserBookProgressEntity progress = progressMap.get(book.getId());
|
UserBookProgressEntity progress = progressMap.get(book.getId());
|
||||||
if (progress != null) {
|
if (progress != null) {
|
||||||
setBookProgress(book, progress);
|
setBookProgress(book, progress);
|
||||||
book.setLastReadTime(progress.getLastReadTime());
|
book.setLastReadTime(progress.getLastReadTime());
|
||||||
|
book.setReadStatus(String.valueOf(progress.getReadStatus()));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return books;
|
return books;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+34
-31
@@ -1,6 +1,5 @@
|
|||||||
@if (showFilter) {
|
@if (showFilter) {
|
||||||
<div
|
<div class="h-[calc(100vh-6.1rem)] rounded-xl bg-[var(--card-background)] flex flex-col">
|
||||||
class="h-[calc(100vh-6.1rem)] rounded-xl bg-[var(--card-background)]">
|
|
||||||
|
|
||||||
<div class="flex items-center justify-between px-4 py-4">
|
<div class="flex items-center justify-between px-4 py-4">
|
||||||
<span class="text font-semibold">Filter Mode</span>
|
<span class="text font-semibold">Filter Mode</span>
|
||||||
@@ -14,39 +13,43 @@
|
|||||||
styleClass="h-8"></p-selectButton>
|
styleClass="h-8"></p-selectButton>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p-accordion [value]="expandedPanels">
|
<div class="flex-1 overflow-y-auto pb-4">
|
||||||
@for (filterType of filterTypes; track filterType; let i = $index) {
|
<p-accordion [value]="expandedPanels">
|
||||||
<p-accordion-panel [value]="i">
|
@for (filterType of filterTypes; track filterType; let i = $index) {
|
||||||
<p-accordion-header>
|
<p-accordion-panel [value]="i">
|
||||||
<span class="inline-flex items-center gap-1">
|
<p-accordion-header>
|
||||||
{{ filterLabels[filterType] || (filterType | titlecase) }}
|
<span class="inline-flex items-center gap-1">
|
||||||
@if (activeFilters[filterType]?.length) {
|
{{ filterLabels[filterType] || (filterType | titlecase) }}
|
||||||
<span class="text-sm text-[var(--primary-color)]">
|
@if (activeFilters[filterType]?.length) {
|
||||||
({{ activeFilters[filterType].length }})
|
<span class="text-sm text-[var(--primary-color)]">
|
||||||
|
({{ activeFilters[filterType].length }})
|
||||||
|
</span>
|
||||||
|
}
|
||||||
</span>
|
</span>
|
||||||
}
|
</p-accordion-header>
|
||||||
</span>
|
|
||||||
</p-accordion-header>
|
|
||||||
|
|
||||||
<p-accordion-content class="h-[27.5rem] !overflow-y-auto">
|
<p-accordion-content class="h-[27.5rem]">
|
||||||
@if (filterStreams[filterType] | async; as filters) {
|
@if (filterStreams[filterType] | async; as filters) {
|
||||||
<div>
|
<div>
|
||||||
@for (filter of filters; track filter) {
|
@for (filter of filters; track filter) {
|
||||||
<div class="cursor-pointer transition-colors duration-200 ease-in-out pb-1 flex items-center gap-2"
|
<div
|
||||||
[ngClass]="{
|
class="cursor-pointer transition-colors duration-200 ease-in-out pb-1 flex items-center gap-2"
|
||||||
|
[ngClass]="{
|
||||||
'text-[var(--primary-color)]':
|
'text-[var(--primary-color)]':
|
||||||
activeFilters[filterType]?.includes(filter.value?.id || filter.value)
|
activeFilters[filterType]?.includes(filter.value?.id || filter.value)
|
||||||
}"
|
}"
|
||||||
(click)="handleFilterClick(filterType, filter.value?.id || filter.value)">
|
(click)="handleFilterClick(filterType, filter.value?.id || filter.value)">
|
||||||
<p-badge [value]="filter.bookCount"></p-badge>
|
<p-badge [value]="filter.bookCount"></p-badge>
|
||||||
{{ filter.value.name || filter.value }}
|
{{ filter.value.name || filter.value }}
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
</p-accordion-content>
|
</p-accordion-content>
|
||||||
</p-accordion-panel>
|
</p-accordion-panel>
|
||||||
}
|
}
|
||||||
</p-accordion>
|
</p-accordion>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-6
@@ -1,6 +1,6 @@
|
|||||||
import {Component, EventEmitter, inject, Input, OnDestroy, OnInit, Output} from '@angular/core';
|
import {Component, EventEmitter, inject, Input, OnDestroy, OnInit, Output} from '@angular/core';
|
||||||
import {BehaviorSubject, combineLatest, Observable, of, Subject, takeUntil} from 'rxjs';
|
import {combineLatest, Observable, of, Subject, takeUntil} from 'rxjs';
|
||||||
import {distinctUntilChanged, filter, map, take} from 'rxjs/operators';
|
import {distinctUntilChanged, map} from 'rxjs/operators';
|
||||||
import {BookService} from '../../../service/book.service';
|
import {BookService} from '../../../service/book.service';
|
||||||
import {Library} from '../../../model/library.model';
|
import {Library} from '../../../model/library.model';
|
||||||
import {Shelf} from '../../../model/shelf.model';
|
import {Shelf} from '../../../model/shelf.model';
|
||||||
@@ -25,7 +25,7 @@ export const ratingRanges = [
|
|||||||
{id: '4.5plus', label: '4.5+', min: 4.5, max: Infinity, sortIndex: 5}
|
{id: '4.5plus', label: '4.5+', min: 4.5, max: Infinity, sortIndex: 5}
|
||||||
];
|
];
|
||||||
|
|
||||||
export const ratingOptions10 = Array.from({ length: 10 }, (_, i) => ({
|
export const ratingOptions10 = Array.from({length: 10}, (_, i) => ({
|
||||||
id: `${i + 1}`,
|
id: `${i + 1}`,
|
||||||
label: `${i + 1}`,
|
label: `${i + 1}`,
|
||||||
value: i + 1,
|
value: i + 1,
|
||||||
@@ -83,7 +83,7 @@ function getRatingRangeFilters(rating?: number): { id: string; name: string; sor
|
|||||||
function getRatingRangeFilters10(rating?: number): { id: string; name: string; sortIndex?: number }[] {
|
function getRatingRangeFilters10(rating?: number): { id: string; name: string; sortIndex?: number }[] {
|
||||||
if (!rating || rating < 1 || rating > 10) return [];
|
if (!rating || rating < 1 || rating > 10) return [];
|
||||||
const idx = ratingOptions10.find(r => r.value === rating || +r.id === rating);
|
const idx = ratingOptions10.find(r => r.value === rating || +r.id === rating);
|
||||||
return idx ? [{ id: idx.id, name: idx.label, sortIndex: idx.sortIndex }] : [];
|
return idx ? [{id: idx.id, name: idx.label, sortIndex: idx.sortIndex}] : [];
|
||||||
}
|
}
|
||||||
|
|
||||||
function extractPublishedYearFilter(book: Book): { id: number; name: string }[] {
|
function extractPublishedYearFilter(book: Book): { id: number; name: string }[] {
|
||||||
@@ -119,10 +119,11 @@ const readStatusLabels: Record<ReadStatus, string> = {
|
|||||||
[ReadStatus.READ]: 'Read',
|
[ReadStatus.READ]: 'Read',
|
||||||
[ReadStatus.WONT_READ]: 'Won’t Read',
|
[ReadStatus.WONT_READ]: 'Won’t Read',
|
||||||
[ReadStatus.ABANDONED]: 'Abandoned',
|
[ReadStatus.ABANDONED]: 'Abandoned',
|
||||||
|
[ReadStatus.UNSET]: 'Unset'
|
||||||
};
|
};
|
||||||
|
|
||||||
function getReadStatusName(status?: ReadStatus | null): string {
|
function getReadStatusName(status?: ReadStatus | null): string {
|
||||||
return status != null ? readStatusLabels[status] ?? 'Unknown' : 'Unknown';
|
return status != null ? readStatusLabels[status] ?? 'Unset' : 'Unset';
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@@ -198,7 +199,13 @@ export class BookFilterComponent implements OnInit, OnDestroy {
|
|||||||
category: this.getFilterStream((book: Book) => book.metadata?.categories!.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),
|
series: this.getFilterStream((book) => (book.metadata?.seriesName ? [{id: book.metadata.seriesName, name: book.metadata.seriesName}] : []), 'id', 'name', sortMode),
|
||||||
publisher: this.getFilterStream((book) => (book.metadata?.publisher ? [{id: book.metadata.publisher, name: book.metadata.publisher}] : []), 'id', 'name', sortMode),
|
publisher: this.getFilterStream((book) => (book.metadata?.publisher ? [{id: book.metadata.publisher, name: book.metadata.publisher}] : []), 'id', 'name', sortMode),
|
||||||
readStatus: this.getFilterStream((book: Book) => [{id: book.readStatus ?? ReadStatus.UNREAD, name: getReadStatusName(book.readStatus)}], 'id', 'name', sortMode),
|
readStatus: this.getFilterStream((book: Book) => {
|
||||||
|
let status = book.readStatus;
|
||||||
|
if (status == null || !(status in readStatusLabels)) {
|
||||||
|
status = ReadStatus.UNSET;
|
||||||
|
}
|
||||||
|
return [{id: status, name: getReadStatusName(status)}];
|
||||||
|
}, 'id', 'name', sortMode),
|
||||||
matchScore: this.getFilterStream((book: Book) => getMatchScoreRangeFilters(book.metadataMatchScore), 'id', 'name', 'sortIndex'),
|
matchScore: this.getFilterStream((book: Book) => getMatchScoreRangeFilters(book.metadataMatchScore), 'id', 'name', 'sortIndex'),
|
||||||
personalRating: this.getFilterStream((book: Book) => getRatingRangeFilters10(book.metadata?.personalRating!), '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'),
|
amazonRating: this.getFilterStream((book: Book) => getRatingRangeFilters(book.metadata?.amazonRating!), 'id', 'name', 'sortIndex'),
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import {map} from 'rxjs/operators';
|
|||||||
import {BookFilter} from './BookFilter';
|
import {BookFilter} from './BookFilter';
|
||||||
import {BookState} from '../../../model/state/book-state.model';
|
import {BookState} from '../../../model/state/book-state.model';
|
||||||
import {fileSizeRanges, matchScoreRanges, pageCountRanges, ratingRanges} from '../book-filter/book-filter.component';
|
import {fileSizeRanges, matchScoreRanges, pageCountRanges, ratingRanges} from '../book-filter/book-filter.component';
|
||||||
|
import {Book, ReadStatus} from '../../../model/book.model';
|
||||||
|
|
||||||
export function isRatingInRange(rating: number | undefined | null, rangeId: string): boolean {
|
export function isRatingInRange(rating: number | undefined | null, rangeId: string): boolean {
|
||||||
if (rating == null) return false;
|
if (rating == null) return false;
|
||||||
@@ -37,6 +38,11 @@ export function isMatchScoreInRange(score: number | undefined | null, rangeId: s
|
|||||||
return score >= range.min && score < range.max;
|
return score >= range.min && score < range.max;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function doesBookMatchReadStatus(book: Book, selected: string[]): boolean {
|
||||||
|
const status = book.readStatus ?? ReadStatus.UNSET;
|
||||||
|
return selected.includes(status);
|
||||||
|
}
|
||||||
|
|
||||||
export class SideBarFilter implements BookFilter {
|
export class SideBarFilter implements BookFilter {
|
||||||
|
|
||||||
constructor(private selectedFilter$: Observable<any>, private selectedFilterMode$: Observable<'and' | 'or'>) {
|
constructor(private selectedFilter$: Observable<any>, private selectedFilterMode$: Observable<'and' | 'or'>) {
|
||||||
@@ -69,7 +75,7 @@ export class SideBarFilter implements BookFilter {
|
|||||||
? filterValues.every(val => book.metadata?.seriesName === val)
|
? filterValues.every(val => book.metadata?.seriesName === val)
|
||||||
: filterValues.some(val => book.metadata?.seriesName === val);
|
: filterValues.some(val => book.metadata?.seriesName === val);
|
||||||
case 'readStatus':
|
case 'readStatus':
|
||||||
return filterValues.some(val => book.readStatus === val);
|
return doesBookMatchReadStatus(book, filterValues);
|
||||||
case 'amazonRating':
|
case 'amazonRating':
|
||||||
return filterValues.some(range => isRatingInRange(book.metadata?.amazonRating, range));
|
return filterValues.some(range => isRatingInRange(book.metadata?.amazonRating, range));
|
||||||
case 'goodreadsRating':
|
case 'goodreadsRating':
|
||||||
|
|||||||
+1
-1
@@ -466,7 +466,7 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
getStatusLabel(value: string): string {
|
getStatusLabel(value: string): string {
|
||||||
return this.readStatusOptions.find(o => o.value === value)?.label.toUpperCase() ?? 'N/A';
|
return this.readStatusOptions.find(o => o.value === value)?.label.toUpperCase() ?? 'UNSET';
|
||||||
}
|
}
|
||||||
|
|
||||||
updateReadStatus(status: ReadStatus): void {
|
updateReadStatus(status: ReadStatus): void {
|
||||||
|
|||||||
@@ -222,5 +222,6 @@ export enum ReadStatus {
|
|||||||
PARTIALLY_READ = 'PARTIALLY_READ',
|
PARTIALLY_READ = 'PARTIALLY_READ',
|
||||||
PAUSED = 'PAUSED',
|
PAUSED = 'PAUSED',
|
||||||
WONT_READ = 'WONT_READ',
|
WONT_READ = 'WONT_READ',
|
||||||
ABANDONED = 'ABANDONED'
|
ABANDONED = 'ABANDONED',
|
||||||
|
UNSET = 'UNSET'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -403,6 +403,19 @@ export class BookService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateBookReadStatus(id: number, status: ReadStatus): Observable<void> {
|
||||||
|
return this.http.put<void>(`${this.url}/${id}/read-status`, {status}).pipe(
|
||||||
|
tap(() => {
|
||||||
|
const currentState = this.bookStateSubject.value;
|
||||||
|
if (!currentState.books) return;
|
||||||
|
const updatedBooks = currentState.books.map(book =>
|
||||||
|
book.id === id ? {...book, readStatus: status} : book
|
||||||
|
);
|
||||||
|
this.bookStateSubject.next({...currentState, books: updatedBooks});
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*------------------ All the websocket handlers go below ------------------*/
|
/*------------------ All the websocket handlers go below ------------------*/
|
||||||
|
|
||||||
@@ -506,8 +519,4 @@ export class BookService {
|
|||||||
getBackupMetadata(bookId: number) {
|
getBackupMetadata(bookId: number) {
|
||||||
return this.http.get<any>(`${this.url}/${bookId}/metadata/restore`);
|
return this.http.get<any>(`${this.url}/${bookId}/metadata/restore`);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateBookReadStatus(id: number, status: ReadStatus): Observable<void> {
|
|
||||||
return this.http.put<void>(`${this.url}/${id}/read-status`, {status});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user