feat(read-status): Add Read Status tracking and filtering support
- Introduced `ReadStatus` enum and added `readStatus` field to `BookEntity` - Updated database schema with Flyway migration to store read status - Extended DTOs and backend API to handle read status updates - Added `updateBookReadStatus()` in backend service and controller - Integrated read status in Angular: display, update, and toast feedback - Added read status filters and labels across book listing, sidebar filter, and viewer - Refactored `MetadataViewerComponent` and extracted read status UI logic - Simplified read status label resolution using a mapping function
This commit is contained in:
committed by
Aditya Chandel
parent
cd4e14c8ad
commit
6bfbff5d34
+24
-11
@@ -168,23 +168,37 @@
|
||||
}
|
||||
</div>
|
||||
<div class="grid gap-x-20 gap-y-2 pt-6" style="grid-template-columns: repeat(5, max-content);">
|
||||
<p class="whitespace-nowrap flex items-center gap-2">
|
||||
<span class="font-bold">File Type:</span>
|
||||
<span
|
||||
class="inline-block px-2 py-0.5 rounded-full text-xs font-bold text-white"
|
||||
[ngClass]="getFileTypeColorClass(getFileExtension(book?.filePath))">
|
||||
{{ getFileExtension(book?.filePath) || '-' }}
|
||||
</span>
|
||||
</p>
|
||||
<div>
|
||||
<p class="whitespace-nowrap flex items-center gap-2">
|
||||
<span class="font-bold">Read Status:</span>
|
||||
<p-tag
|
||||
class="cursor-pointer text-white"
|
||||
[severity]="getStatusSeverity(selectedReadStatus)"
|
||||
(click)="menu.toggle($event)">
|
||||
{{ getStatusLabel(selectedReadStatus) }}
|
||||
</p-tag>
|
||||
<p-menu #menu [popup]="true" [model]="readStatusMenuItems"></p-menu>
|
||||
</p>
|
||||
</div>
|
||||
<p class="whitespace-nowrap"><span class="font-bold">Publisher:</span> {{ book?.metadata!.publisher || '-' }}</p>
|
||||
<p class="whitespace-nowrap"><span class="font-bold">Published:</span> {{ book?.metadata!.publishedDate || '-' }}</p>
|
||||
<p class="whitespace-nowrap"><span class="font-bold">Language:</span> {{ book?.metadata!.language || '-' }}</p>
|
||||
<p class="whitespace-nowrap"><span class="font-bold">ISBN 10:</span> {{ book?.metadata!.isbn10 || '-' }}</p>
|
||||
|
||||
<p class="whitespace-nowrap flex items-center gap-2">
|
||||
<span class="font-bold">File Type:</span>
|
||||
<span
|
||||
class="inline-block px-2 py-0.5 rounded-lg text-xs font-bold text-gray-200"
|
||||
[ngClass]="getFileTypeColorClass(getFileExtension(book?.filePath))">
|
||||
{{ getFileExtension(book?.filePath) || '-' }}
|
||||
</span>
|
||||
</p>
|
||||
|
||||
<p class="whitespace-nowrap flex items-center gap-2">
|
||||
<span class="font-bold">Metadata Score:</span>
|
||||
@if (book?.metadataMatchScore != null) {
|
||||
<span
|
||||
class="inline-block px-2 py-0.5 rounded-full text-xs font-bold text-white border"
|
||||
class="inline-block px-2 py-0.5 rounded-lg text-xs font-bold text-gray-200 border"
|
||||
[ngClass]="getMatchScoreColorClass(book?.metadataMatchScore!)">
|
||||
{{ (book?.metadataMatchScore! * 100) | number:'1.0-0' }}%
|
||||
</span>
|
||||
@@ -192,8 +206,6 @@
|
||||
<span>-</span>
|
||||
}
|
||||
</p>
|
||||
<p class="whitespace-nowrap"><span class="font-bold">Page Count:</span> {{ book?.metadata!.pageCount || '-' }}</p>
|
||||
<p class="whitespace-nowrap"><span class="font-bold">File Size:</span> {{ getFileSizeInMB(book) }}</p>
|
||||
<p class="whitespace-nowrap flex items-center gap-2">
|
||||
<span class="font-bold">Progress:</span>
|
||||
<span
|
||||
@@ -202,6 +214,7 @@
|
||||
{{ getProgressPercent(book) !== null ? getProgressPercent(book) + '%' : 'N/A' }}
|
||||
</span>
|
||||
</p>
|
||||
<p class="whitespace-nowrap"><span class="font-bold">File Size:</span> {{ getFileSizeInMB(book) }}</p>
|
||||
<p class="whitespace-nowrap"><span class="font-bold">ISBN 13:</span> {{ book?.metadata!.isbn13 || '-' }}</p>
|
||||
</div>
|
||||
<div class="pt-2 flex items-center gap-2 w-full">
|
||||
|
||||
+71
-6
@@ -6,7 +6,7 @@ import {BookService} from '../../../service/book.service';
|
||||
import {Rating, RatingRateEvent} from 'primeng/rating';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {Tag} from 'primeng/tag';
|
||||
import {Book, BookMetadata, BookRecommendation} from '../../../model/book.model';
|
||||
import {Book, BookMetadata, BookRecommendation, ReadStatus} from '../../../model/book.model';
|
||||
import {Divider} from 'primeng/divider';
|
||||
import {UrlHelperService} from '../../../../utilities/service/url-helper.service';
|
||||
import {UserService} from '../../../../settings/user-management/user.service';
|
||||
@@ -64,6 +64,18 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
|
||||
showFilePath = false;
|
||||
isAutoFetching = false;
|
||||
|
||||
readStatusOptions = [
|
||||
{label: 'Unread', value: ReadStatus.UNREAD},
|
||||
{label: 'Reading', value: ReadStatus.READING},
|
||||
{label: 'Re-reading', value: ReadStatus.RE_READING},
|
||||
{label: 'Partially Read', value: ReadStatus.PARTIALLY_READ},
|
||||
{label: 'Paused', value: ReadStatus.PAUSED},
|
||||
{label: 'Read', value: ReadStatus.READ},
|
||||
{label: 'Won’t Read', value: ReadStatus.WONT_READ},
|
||||
{label: 'Abandoned', value: ReadStatus.ABANDONED}
|
||||
];
|
||||
|
||||
selectedReadStatus: ReadStatus = ReadStatus.UNREAD;
|
||||
|
||||
ngOnInit(): void {
|
||||
this.emailMenuItems$ = this.book$.pipe(
|
||||
@@ -148,15 +160,16 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
|
||||
this.book$
|
||||
.pipe(
|
||||
takeUntilDestroyed(this.destroyRef),
|
||||
map(book => book?.metadata),
|
||||
filter((metadata): metadata is BookMetadata => metadata != null)
|
||||
filter((book): book is Book => book != null && book.metadata != null)
|
||||
)
|
||||
.subscribe(metadata => {
|
||||
.subscribe(book => {
|
||||
const metadata = book.metadata;
|
||||
this.isAutoFetching = false;
|
||||
this.loadBooksInSeriesAndFilterRecommended(metadata.bookId);
|
||||
this.loadBooksInSeriesAndFilterRecommended(metadata!.bookId);
|
||||
if (this.quillEditor?.quill) {
|
||||
this.quillEditor.quill.root.innerHTML = metadata.description;
|
||||
this.quillEditor.quill.root.innerHTML = metadata!.description;
|
||||
}
|
||||
this.selectedReadStatus = book.readStatus ?? ReadStatus.UNREAD;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -327,4 +340,56 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getStatusSeverity(status: string): 'success' | 'secondary' | 'info' | 'warn' | 'danger' | undefined {
|
||||
const normalized = status?.toUpperCase();
|
||||
if (['UNREAD', 'PAUSED'].includes(normalized)) return 'secondary';
|
||||
if (['READING', 'RE_READING'].includes(normalized)) return 'info';
|
||||
if (['READ'].includes(normalized)) return 'success';
|
||||
if (['PARTIALLY_READ'].includes(normalized)) return 'warn';
|
||||
if (['WONT_READ', 'ABANDONED'].includes(normalized)) return 'danger';
|
||||
return undefined;
|
||||
}
|
||||
|
||||
readStatusMenuItems = this.readStatusOptions.map(option => ({
|
||||
label: option.label,
|
||||
command: () => this.updateReadStatus(option.value)
|
||||
}));
|
||||
|
||||
getStatusLabel(value: string): string {
|
||||
return this.readStatusOptions.find(o => o.value === value)?.label ?? 'Unknown';
|
||||
}
|
||||
|
||||
updateReadStatus(status: ReadStatus): void {
|
||||
if (!status) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.book$.pipe(take(1)).subscribe(book => {
|
||||
if (!book || !book.id) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.bookService.updateBookReadStatus(book.id, status).subscribe({
|
||||
next: () => {
|
||||
this.selectedReadStatus = status;
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Read Status Updated',
|
||||
detail: `Marked as "${this.getStatusLabel(status)}"`,
|
||||
life: 2000
|
||||
});
|
||||
},
|
||||
error: (err) => {
|
||||
console.error('Failed to update read status:', err);
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Update Failed',
|
||||
detail: 'Could not update read status.',
|
||||
life: 3000
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user