refactor(frontend): rename booklore-ui to frontend
- Frontend path: - rename the tracked Angular app tree from `booklore-ui/` to `frontend/` - preserve file contents during the move so this commit stays focused on the path change itself - Frontend docs: - update the moved frontend README and contribution guide where they refer to the renamed folder - keep those edits limited to path references introduced by the directory rename
This commit is contained in:
@@ -0,0 +1,203 @@
|
||||
<ng-container *transloco="let t">
|
||||
<div class="main-container">
|
||||
|
||||
<!-- Page Header -->
|
||||
<div class="settings-header">
|
||||
<h2 class="settings-title">
|
||||
<i class="pi pi-pencil"></i>
|
||||
{{ t('notebook.pageTitle') }}
|
||||
</h2>
|
||||
<p class="settings-description">{{ t('notebook.pageDescription') }}</p>
|
||||
</div>
|
||||
|
||||
<!-- Filters Card -->
|
||||
<div class="settings-card">
|
||||
<div class="filters-bar">
|
||||
<div class="filters-left">
|
||||
<span class="p-input-icon-left search-wrapper">
|
||||
<i class="pi pi-search"></i>
|
||||
<input
|
||||
pInputText
|
||||
type="text"
|
||||
[(ngModel)]="searchQuery"
|
||||
(ngModelChange)="onSearchChange()"
|
||||
[placeholder]="t('notebook.searchPlaceholder')"
|
||||
class="search-input"
|
||||
/>
|
||||
</span>
|
||||
|
||||
<p-select
|
||||
[(ngModel)]="selectedBookId"
|
||||
[options]="bookOptions"
|
||||
optionLabel="label"
|
||||
optionValue="value"
|
||||
[filter]="true"
|
||||
filterBy="label"
|
||||
[lazy]="true"
|
||||
[virtualScroll]="true"
|
||||
[virtualScrollItemSize]="38"
|
||||
[showClear]="true"
|
||||
appendTo="body"
|
||||
(ngModelChange)="onFilterChange()"
|
||||
(onFilter)="onBookFilter($event)"
|
||||
[placeholder]="t('notebook.filterByBook')"
|
||||
[panelStyle]="{'min-width': '300px'}"
|
||||
class="book-select"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="filters-right">
|
||||
<div class="type-filters">
|
||||
<button
|
||||
class="option-button"
|
||||
[class.selected]="showHighlights"
|
||||
(click)="showHighlights = !showHighlights; onFilterChange()"
|
||||
>
|
||||
<i class="pi pi-highlighter"></i>
|
||||
<span class="option-text">{{ t('notebook.filterHighlights') }}</span>
|
||||
</button>
|
||||
<button
|
||||
class="option-button"
|
||||
[class.selected]="showNotes"
|
||||
(click)="showNotes = !showNotes; onFilterChange()"
|
||||
>
|
||||
<i class="pi pi-file-edit"></i>
|
||||
<span class="option-text">{{ t('notebook.filterNotes') }}</span>
|
||||
</button>
|
||||
<button
|
||||
class="option-button"
|
||||
[class.selected]="showBookmarks"
|
||||
(click)="showBookmarks = !showBookmarks; onFilterChange()"
|
||||
>
|
||||
<i class="pi pi-bookmark"></i>
|
||||
<span class="option-text">{{ t('notebook.filterBookmarks') }}</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<p-button
|
||||
[icon]="sortNewest ? 'pi pi-sort-amount-down' : 'pi pi-sort-amount-up'"
|
||||
[pTooltip]="sortNewest ? t('notebook.sortNewest') : t('notebook.sortOldest')"
|
||||
tooltipPosition="bottom"
|
||||
[outlined]="true"
|
||||
size="small"
|
||||
(onClick)="toggleSort()"
|
||||
/>
|
||||
<p-button
|
||||
icon="pi pi-download"
|
||||
[label]="t('notebook.export')"
|
||||
[outlined]="true"
|
||||
size="small"
|
||||
severity="info"
|
||||
(onClick)="exportMarkdown()"
|
||||
[disabled]="totalEntries === 0 || exporting"
|
||||
[loading]="exporting"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Scrollable Content Area -->
|
||||
<div class="entries-scroll-area">
|
||||
<!-- Loading State -->
|
||||
@if (loading) {
|
||||
<div class="settings-card">
|
||||
<div class="state-container">
|
||||
<i class="pi pi-spin pi-spinner"></i>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
<!-- Empty State: No annotations at all -->
|
||||
@if (!loading && totalEntries === 0 && !searchQuery.trim() && selectedBookId === null && showHighlights && showNotes && showBookmarks) {
|
||||
<div class="settings-card">
|
||||
<div class="state-container">
|
||||
<div class="state-icon">
|
||||
<i class="pi pi-pencil"></i>
|
||||
</div>
|
||||
<p class="state-title">{{ t('notebook.noEntries') }}</p>
|
||||
<p class="state-hint">{{ t('notebook.noEntriesHint') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
<!-- Empty State: No results match filters -->
|
||||
@if (!loading && totalEntries === 0 && (searchQuery.trim() || selectedBookId !== null || !showHighlights || !showNotes || !showBookmarks)) {
|
||||
<div class="settings-card">
|
||||
<div class="state-container">
|
||||
<div class="state-icon warn">
|
||||
<i class="pi pi-filter-slash"></i>
|
||||
</div>
|
||||
<p class="state-title">{{ t('notebook.noResults') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
<!-- Book Groups -->
|
||||
@if (!loading && filteredGroups.length > 0) {
|
||||
@for (group of filteredGroups; track group.bookId) {
|
||||
<div class="settings-card book-group-card">
|
||||
<!-- Book Header -->
|
||||
<div class="book-group-header" (click)="toggleGroup(group.bookId)">
|
||||
<img [src]="group.thumbnailUrl" [alt]="group.bookTitle" class="book-thumbnail" />
|
||||
<div class="book-info">
|
||||
<span class="book-title">{{ group.bookTitle }}</span>
|
||||
<span class="book-entry-count">
|
||||
{{ group.entries.length }} {{ group.entries.length === 1 ? t('notebook.annotation') : t('notebook.annotations') }}
|
||||
</span>
|
||||
</div>
|
||||
<i class="pi toggle-icon" [class.pi-chevron-down]="!isGroupCollapsed(group.bookId)" [class.pi-chevron-right]="isGroupCollapsed(group.bookId)"></i>
|
||||
</div>
|
||||
|
||||
<!-- Entries -->
|
||||
@if (!isGroupCollapsed(group.bookId)) {
|
||||
<div class="entries-list">
|
||||
@for (entry of group.entries; track entry.id + '-' + entry.type) {
|
||||
<div
|
||||
class="entry-item"
|
||||
[style.border-left-color]="entry.color || 'var(--p-primary-color)'"
|
||||
>
|
||||
<div class="entry-top-row">
|
||||
<div class="entry-type-badge" [class]="'type-' + entry.type.toLowerCase()">
|
||||
<i [class]="getTypeIcon(entry.type)"></i>
|
||||
<span>{{ getTypeLabel(entry.type) }}</span>
|
||||
</div>
|
||||
@if (entry.chapterTitle) {
|
||||
<span class="entry-chapter">
|
||||
<i class="pi pi-list"></i>
|
||||
{{ entry.chapterTitle }}
|
||||
</span>
|
||||
}
|
||||
<span class="entry-date">{{ entry.createdAt | date:'mediumDate' }}</span>
|
||||
</div>
|
||||
@if (entry.text) {
|
||||
<div class="entry-text">{{ entry.text }}</div>
|
||||
}
|
||||
@if (entry.note) {
|
||||
<div class="entry-note">
|
||||
<i class="pi pi-comment"></i>
|
||||
<span>{{ entry.note }}</span>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
|
||||
<!-- Pagination -->
|
||||
@if (totalEntries > pageSize) {
|
||||
<div class="settings-card pagination-card">
|
||||
<p-paginator
|
||||
[rows]="pageSize"
|
||||
[totalRecords]="totalEntries"
|
||||
[first]="first"
|
||||
[rowsPerPageOptions]="[25, 50, 100]"
|
||||
(onPageChange)="onPageChange($event)"
|
||||
/>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
@@ -0,0 +1,368 @@
|
||||
@use '../../../../shared/styles/settings-shared' as settings;
|
||||
|
||||
// Page container — override mixin's overflow so only the content area scrolls
|
||||
.main-container {
|
||||
@include settings.settings-page-container;
|
||||
overflow-y: hidden;
|
||||
height: calc(100dvh - 5rem);
|
||||
|
||||
@media (min-width: 768px) {
|
||||
height: calc(100dvh - 5.6rem);
|
||||
}
|
||||
}
|
||||
|
||||
// Scrollable content area below the fixed header + filters
|
||||
.entries-scroll-area {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow-y: auto;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1.5rem;
|
||||
}
|
||||
|
||||
@include settings.settings-page-header;
|
||||
|
||||
.settings-header {
|
||||
margin-top: 0;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.settings-title {
|
||||
@include settings.settings-page-title;
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
|
||||
.settings-description {
|
||||
@include settings.settings-page-description;
|
||||
}
|
||||
|
||||
// Cards
|
||||
.settings-card {
|
||||
@include settings.settings-card;
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// FILTERS BAR
|
||||
// ============================================================================
|
||||
.filters-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 1rem;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.filters-left {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
flex-wrap: wrap;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.filters-right {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.search-wrapper {
|
||||
position: relative;
|
||||
|
||||
i {
|
||||
position: absolute;
|
||||
left: 0.75rem;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
color: var(--p-text-muted-color);
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.search-input {
|
||||
padding-left: 2.25rem;
|
||||
width: 200px;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
}
|
||||
|
||||
::ng-deep .book-select {
|
||||
min-width: 200px;
|
||||
}
|
||||
|
||||
// Type filter toggle buttons (settings-button-group pattern)
|
||||
.type-filters {
|
||||
@include settings.settings-button-group;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// STATES: Loading / Empty
|
||||
// ============================================================================
|
||||
.state-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 3rem 2rem;
|
||||
text-align: center;
|
||||
color: var(--p-text-muted-color);
|
||||
|
||||
.pi-spinner {
|
||||
font-size: 2rem;
|
||||
color: var(--p-primary-color);
|
||||
}
|
||||
}
|
||||
|
||||
.state-icon {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 56px;
|
||||
height: 56px;
|
||||
background: color-mix(in srgb, var(--p-primary-color) 12%, transparent);
|
||||
color: var(--p-primary-color);
|
||||
border-radius: 50%;
|
||||
margin-bottom: 1rem;
|
||||
|
||||
.pi {
|
||||
font-size: 1.5rem;
|
||||
}
|
||||
|
||||
&.warn {
|
||||
background: color-mix(in srgb, var(--p-orange-500) 12%, transparent);
|
||||
color: var(--p-orange-500);
|
||||
}
|
||||
}
|
||||
|
||||
.state-title {
|
||||
font-size: 1rem;
|
||||
font-weight: 600;
|
||||
color: var(--p-text-color);
|
||||
margin: 0 0 0.25rem;
|
||||
}
|
||||
|
||||
.state-hint {
|
||||
font-size: 0.875rem;
|
||||
color: var(--p-text-muted-color);
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// BOOK GROUP CARDS
|
||||
// ============================================================================
|
||||
.book-group-card {
|
||||
gap: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.book-group-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
padding: 1rem 1.25rem;
|
||||
cursor: pointer;
|
||||
transition: background 0.15s ease;
|
||||
border-radius: 8px;
|
||||
|
||||
&:hover {
|
||||
background: color-mix(in srgb, var(--p-text-color) 4%, transparent);
|
||||
}
|
||||
}
|
||||
|
||||
.book-thumbnail {
|
||||
width: 36px;
|
||||
height: 50px;
|
||||
object-fit: cover;
|
||||
border-radius: 4px;
|
||||
flex-shrink: 0;
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
}
|
||||
|
||||
.book-info {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.125rem;
|
||||
}
|
||||
|
||||
.book-title {
|
||||
font-weight: 600;
|
||||
font-size: 1rem;
|
||||
color: var(--p-text-color);
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.book-entry-count {
|
||||
font-size: 0.8125rem;
|
||||
color: var(--p-text-muted-color);
|
||||
}
|
||||
|
||||
.toggle-icon {
|
||||
color: var(--p-text-muted-color);
|
||||
font-size: 0.875rem;
|
||||
flex-shrink: 0;
|
||||
transition: transform 0.2s ease;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// ENTRIES LIST
|
||||
// ============================================================================
|
||||
.entries-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
padding: 0 1.25rem 1.25rem;
|
||||
}
|
||||
|
||||
.entry-item {
|
||||
padding: 0.75rem 1rem;
|
||||
border-radius: 6px;
|
||||
border-left: 3px solid var(--p-primary-color);
|
||||
background: color-mix(in srgb, var(--ground-background) 50%, var(--p-surface-800) 50%);
|
||||
transition: background 0.15s ease;
|
||||
|
||||
&:hover {
|
||||
background: color-mix(in srgb, var(--ground-background) 40%, var(--p-surface-800) 60%);
|
||||
}
|
||||
}
|
||||
|
||||
.entry-top-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.625rem;
|
||||
margin-bottom: 0.5rem;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.entry-type-badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.3rem;
|
||||
padding: 0.125rem 0.5rem;
|
||||
border-radius: 12px;
|
||||
font-size: 0.75rem;
|
||||
font-weight: 600;
|
||||
|
||||
.pi {
|
||||
font-size: 0.6875rem;
|
||||
}
|
||||
|
||||
&.type-highlight {
|
||||
background: color-mix(in srgb, var(--p-yellow-500) 15%, transparent);
|
||||
color: var(--p-yellow-500);
|
||||
}
|
||||
|
||||
&.type-note {
|
||||
background: color-mix(in srgb, var(--p-blue-500) 15%, transparent);
|
||||
color: var(--p-blue-400);
|
||||
}
|
||||
|
||||
&.type-bookmark {
|
||||
background: color-mix(in srgb, var(--p-green-500) 15%, transparent);
|
||||
color: var(--p-green-400);
|
||||
}
|
||||
}
|
||||
|
||||
.entry-chapter {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.3rem;
|
||||
font-size: 0.8125rem;
|
||||
color: var(--p-text-muted-color);
|
||||
|
||||
.pi {
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
}
|
||||
|
||||
.entry-date {
|
||||
margin-left: auto;
|
||||
font-size: 0.75rem;
|
||||
color: var(--p-text-muted-color);
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.entry-text {
|
||||
color: var(--p-text-color);
|
||||
font-size: 0.875rem;
|
||||
line-height: 1.55;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
.entry-note {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 0.375rem;
|
||||
margin-top: 0.5rem;
|
||||
padding-top: 0.5rem;
|
||||
border-top: 1px dashed var(--p-content-border-color);
|
||||
color: var(--p-text-muted-color);
|
||||
font-size: 0.8125rem;
|
||||
font-style: italic;
|
||||
line-height: 1.5;
|
||||
|
||||
.pi {
|
||||
font-size: 0.75rem;
|
||||
margin-top: 0.125rem;
|
||||
flex-shrink: 0;
|
||||
color: var(--p-primary-color);
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// PAGINATION
|
||||
// ============================================================================
|
||||
.pagination-card {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
padding: 0.5rem;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// RESPONSIVE
|
||||
// ============================================================================
|
||||
@media (max-width: 768px) {
|
||||
.filters-bar {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
}
|
||||
|
||||
.filters-left,
|
||||
.filters-right {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.search-wrapper .search-input {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
::ng-deep .book-select {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.type-filters {
|
||||
width: 100%;
|
||||
justify-content: stretch;
|
||||
|
||||
.option-button {
|
||||
flex: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.entry-top-row {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 0.375rem;
|
||||
}
|
||||
|
||||
.entry-date {
|
||||
margin-left: 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,283 @@
|
||||
import {Component, inject, OnDestroy, OnInit} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {of, Subject} from 'rxjs';
|
||||
import {debounceTime, switchMap, takeUntil} from 'rxjs/operators';
|
||||
import {InputTextModule} from 'primeng/inputtext';
|
||||
import {Select} from 'primeng/select';
|
||||
import {Button} from 'primeng/button';
|
||||
import {TooltipModule} from 'primeng/tooltip';
|
||||
import {Paginator} from 'primeng/paginator';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
import {NotebookService} from '../../service/notebook.service';
|
||||
import {NotebookEntry, NotebookPage} from '../../model/notebook.model';
|
||||
import {UrlHelperService} from '../../../../shared/service/url-helper.service';
|
||||
import {PageTitleService} from '../../../../shared/service/page-title.service';
|
||||
|
||||
interface BookGroup {
|
||||
bookId: number;
|
||||
bookTitle: string;
|
||||
thumbnailUrl: string;
|
||||
entries: NotebookEntry[];
|
||||
}
|
||||
|
||||
interface BookOption {
|
||||
label: string;
|
||||
value: number;
|
||||
}
|
||||
|
||||
const EMPTY_PAGE: NotebookPage = {
|
||||
content: [],
|
||||
page: { totalElements: 0, totalPages: 0, number: 0, size: 0 },
|
||||
};
|
||||
|
||||
@Component({
|
||||
selector: 'app-notebook',
|
||||
standalone: true,
|
||||
imports: [
|
||||
CommonModule,
|
||||
FormsModule,
|
||||
InputTextModule,
|
||||
Select,
|
||||
Button,
|
||||
TooltipModule,
|
||||
Paginator,
|
||||
TranslocoDirective,
|
||||
],
|
||||
templateUrl: './notebook.component.html',
|
||||
styleUrls: ['./notebook.component.scss'],
|
||||
})
|
||||
export class NotebookComponent implements OnInit, OnDestroy {
|
||||
private readonly destroy$ = new Subject<void>();
|
||||
private readonly searchSubject = new Subject<void>();
|
||||
private readonly loadTrigger$ = new Subject<void>();
|
||||
private readonly bookFilterSubject = new Subject<string>();
|
||||
private readonly notebookService = inject(NotebookService);
|
||||
private readonly urlHelper = inject(UrlHelperService);
|
||||
private readonly pageTitle = inject(PageTitleService);
|
||||
private readonly t = inject(TranslocoService);
|
||||
|
||||
filteredGroups: BookGroup[] = [];
|
||||
totalEntries = 0;
|
||||
loading = true;
|
||||
exporting = false;
|
||||
|
||||
searchQuery = '';
|
||||
showHighlights = true;
|
||||
showNotes = true;
|
||||
showBookmarks = true;
|
||||
sortNewest = true;
|
||||
|
||||
bookOptions: BookOption[] = [];
|
||||
selectedBookId: number | null = null;
|
||||
|
||||
page = 0;
|
||||
pageSize = 50;
|
||||
first = 0;
|
||||
|
||||
private collapsedGroups = new Set<number>();
|
||||
|
||||
ngOnInit(): void {
|
||||
this.pageTitle.setPageTitle(this.t.translate('notebook.pageTitle'));
|
||||
|
||||
this.loadTrigger$.pipe(
|
||||
switchMap(() => {
|
||||
const types = this.activeTypes;
|
||||
if (types.length === 0) {
|
||||
return of(EMPTY_PAGE);
|
||||
}
|
||||
this.loading = true;
|
||||
return this.notebookService.getNotebookEntries(
|
||||
this.page, this.pageSize, types, this.selectedBookId, this.searchQuery, this.sortDirection
|
||||
);
|
||||
}),
|
||||
takeUntil(this.destroy$)
|
||||
).subscribe(result => {
|
||||
this.totalEntries = result.page.totalElements;
|
||||
this.groupEntries(result.content);
|
||||
this.loading = false;
|
||||
});
|
||||
|
||||
this.searchSubject.pipe(
|
||||
debounceTime(300),
|
||||
takeUntil(this.destroy$)
|
||||
).subscribe(() => {
|
||||
this.page = 0;
|
||||
this.first = 0;
|
||||
this.loadTrigger$.next();
|
||||
});
|
||||
|
||||
this.bookFilterSubject.pipe(
|
||||
debounceTime(300),
|
||||
switchMap(filter => this.notebookService.getBooksWithAnnotations(filter || undefined)),
|
||||
takeUntil(this.destroy$)
|
||||
).subscribe(books => {
|
||||
this.updateBookOptions(books.map(b => ({label: b.bookTitle, value: b.bookId})));
|
||||
});
|
||||
|
||||
this.loadBooks();
|
||||
this.loadTrigger$.next();
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
}
|
||||
|
||||
onSearchChange(): void {
|
||||
this.searchSubject.next();
|
||||
}
|
||||
|
||||
onFilterChange(): void {
|
||||
this.page = 0;
|
||||
this.first = 0;
|
||||
this.loadTrigger$.next();
|
||||
}
|
||||
|
||||
onBookFilter(event: { filter: string }): void {
|
||||
this.bookFilterSubject.next(event.filter);
|
||||
}
|
||||
|
||||
onPageChange(event: { page?: number; first?: number; rows?: number }): void {
|
||||
this.page = event.page ?? 0;
|
||||
this.first = event.first ?? 0;
|
||||
this.pageSize = event.rows ?? this.pageSize;
|
||||
this.loadTrigger$.next();
|
||||
}
|
||||
|
||||
private get activeTypes(): string[] {
|
||||
const types: string[] = [];
|
||||
if (this.showHighlights) types.push('HIGHLIGHT');
|
||||
if (this.showNotes) types.push('NOTE');
|
||||
if (this.showBookmarks) types.push('BOOKMARK');
|
||||
return types;
|
||||
}
|
||||
|
||||
private get sortDirection(): string {
|
||||
return this.sortNewest ? 'desc' : 'asc';
|
||||
}
|
||||
|
||||
private loadBooks(): void {
|
||||
this.notebookService.getBooksWithAnnotations()
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
.subscribe(books => {
|
||||
this.bookOptions = books.map(b => ({label: b.bookTitle, value: b.bookId}));
|
||||
});
|
||||
}
|
||||
|
||||
private updateBookOptions(options: BookOption[]): void {
|
||||
if (this.selectedBookId !== null && !options.some(o => o.value === this.selectedBookId)) {
|
||||
const current = this.bookOptions.find(o => o.value === this.selectedBookId);
|
||||
if (current) {
|
||||
options = [current, ...options];
|
||||
}
|
||||
}
|
||||
this.bookOptions = options;
|
||||
}
|
||||
|
||||
private groupEntries(entries: NotebookEntry[]): void {
|
||||
const groupMap = new Map<number, BookGroup>();
|
||||
for (const entry of entries) {
|
||||
if (!groupMap.has(entry.bookId)) {
|
||||
const isAudiobook = entry.primaryBookType === 'AUDIOBOOK';
|
||||
groupMap.set(entry.bookId, {
|
||||
bookId: entry.bookId,
|
||||
bookTitle: entry.bookTitle,
|
||||
thumbnailUrl: isAudiobook
|
||||
? this.urlHelper.getAudiobookThumbnailUrl(entry.bookId)
|
||||
: this.urlHelper.getDirectThumbnailUrl(entry.bookId),
|
||||
entries: [],
|
||||
});
|
||||
}
|
||||
groupMap.get(entry.bookId)!.entries.push(entry);
|
||||
}
|
||||
this.filteredGroups = Array.from(groupMap.values());
|
||||
}
|
||||
|
||||
toggleSort(): void {
|
||||
this.sortNewest = !this.sortNewest;
|
||||
this.page = 0;
|
||||
this.first = 0;
|
||||
this.loadTrigger$.next();
|
||||
}
|
||||
|
||||
toggleGroup(bookId: number): void {
|
||||
if (this.collapsedGroups.has(bookId)) {
|
||||
this.collapsedGroups.delete(bookId);
|
||||
} else {
|
||||
this.collapsedGroups.add(bookId);
|
||||
}
|
||||
}
|
||||
|
||||
isGroupCollapsed(bookId: number): boolean {
|
||||
return this.collapsedGroups.has(bookId);
|
||||
}
|
||||
|
||||
getTypeIcon(type: string): string {
|
||||
switch (type) {
|
||||
case 'HIGHLIGHT': return 'pi pi-highlighter';
|
||||
case 'NOTE': return 'pi pi-file-edit';
|
||||
case 'BOOKMARK': return 'pi pi-bookmark';
|
||||
default: return 'pi pi-circle';
|
||||
}
|
||||
}
|
||||
|
||||
getTypeLabel(type: string): string {
|
||||
switch (type) {
|
||||
case 'HIGHLIGHT': return this.t.translate('notebook.highlight');
|
||||
case 'NOTE': return this.t.translate('notebook.note');
|
||||
case 'BOOKMARK': return this.t.translate('notebook.bookmark');
|
||||
default: return type;
|
||||
}
|
||||
}
|
||||
|
||||
exportMarkdown(): void {
|
||||
const types = this.activeTypes;
|
||||
if (types.length === 0) return;
|
||||
|
||||
this.exporting = true;
|
||||
this.notebookService.getExportEntries(
|
||||
types, this.selectedBookId, this.searchQuery, this.sortDirection
|
||||
).pipe(takeUntil(this.destroy$)).subscribe(entries => {
|
||||
this.generateMarkdownDownload(entries);
|
||||
this.exporting = false;
|
||||
});
|
||||
}
|
||||
|
||||
private generateMarkdownDownload(entries: NotebookEntry[]): void {
|
||||
const groupMap = new Map<number, { bookTitle: string; entries: NotebookEntry[] }>();
|
||||
for (const entry of entries) {
|
||||
if (!groupMap.has(entry.bookId)) {
|
||||
groupMap.set(entry.bookId, {bookTitle: entry.bookTitle, entries: []});
|
||||
}
|
||||
groupMap.get(entry.bookId)!.entries.push(entry);
|
||||
}
|
||||
|
||||
let md = '# Notebook Export\n\n';
|
||||
for (const group of groupMap.values()) {
|
||||
md += `## ${group.bookTitle}\n\n`;
|
||||
let currentChapter = '';
|
||||
for (const entry of group.entries) {
|
||||
if (entry.chapterTitle && entry.chapterTitle !== currentChapter) {
|
||||
currentChapter = entry.chapterTitle;
|
||||
md += `### ${currentChapter}\n\n`;
|
||||
}
|
||||
if (entry.text) {
|
||||
md += `> ${entry.text}\n\n`;
|
||||
}
|
||||
if (entry.note) {
|
||||
md += `**Note:** ${entry.note}\n\n`;
|
||||
}
|
||||
md += '---\n\n';
|
||||
}
|
||||
}
|
||||
|
||||
const blob = new Blob([md], {type: 'text/markdown'});
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = 'notebook-export.md';
|
||||
a.click();
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
export interface NotebookEntry {
|
||||
id: number;
|
||||
type: 'HIGHLIGHT' | 'NOTE' | 'BOOKMARK';
|
||||
bookId: number;
|
||||
bookTitle: string;
|
||||
text: string;
|
||||
note?: string;
|
||||
color?: string;
|
||||
style?: string;
|
||||
chapterTitle?: string;
|
||||
primaryBookType?: string;
|
||||
createdAt: string;
|
||||
updatedAt?: string;
|
||||
}
|
||||
|
||||
export interface NotebookPage {
|
||||
content: NotebookEntry[];
|
||||
page: {
|
||||
totalElements: number;
|
||||
totalPages: number;
|
||||
number: number;
|
||||
size: number;
|
||||
};
|
||||
}
|
||||
|
||||
export interface NotebookBookOption {
|
||||
bookId: number;
|
||||
bookTitle: string;
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
import {Injectable, inject} from '@angular/core';
|
||||
import {HttpClient, HttpParams} from '@angular/common/http';
|
||||
import {Observable} from 'rxjs';
|
||||
import {API_CONFIG} from '../../../core/config/api-config';
|
||||
import {NotebookBookOption, NotebookEntry, NotebookPage} from '../model/notebook.model';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class NotebookService {
|
||||
|
||||
private readonly url = `${API_CONFIG.BASE_URL}/api/v1/notebook`;
|
||||
private readonly http = inject(HttpClient);
|
||||
|
||||
getNotebookEntries(page: number, size: number, types: string[], bookId: number | null,
|
||||
search: string, sort: string): Observable<NotebookPage> {
|
||||
let params = new HttpParams()
|
||||
.set('page', page)
|
||||
.set('size', size)
|
||||
.set('sort', sort);
|
||||
|
||||
for (const type of types) {
|
||||
params = params.append('types', type);
|
||||
}
|
||||
if (bookId !== null) {
|
||||
params = params.set('bookId', bookId);
|
||||
}
|
||||
if (search.trim()) {
|
||||
params = params.set('search', search.trim());
|
||||
}
|
||||
|
||||
return this.http.get<NotebookPage>(this.url, {params});
|
||||
}
|
||||
|
||||
getExportEntries(types: string[], bookId: number | null, search: string,
|
||||
sort: string): Observable<NotebookEntry[]> {
|
||||
let params = new HttpParams().set('sort', sort);
|
||||
|
||||
for (const type of types) {
|
||||
params = params.append('types', type);
|
||||
}
|
||||
if (bookId !== null) {
|
||||
params = params.set('bookId', bookId);
|
||||
}
|
||||
if (search.trim()) {
|
||||
params = params.set('search', search.trim());
|
||||
}
|
||||
|
||||
return this.http.get<NotebookEntry[]>(`${this.url}/export`, {params});
|
||||
}
|
||||
|
||||
getBooksWithAnnotations(search?: string): Observable<NotebookBookOption[]> {
|
||||
let params = new HttpParams();
|
||||
if (search?.trim()) {
|
||||
params = params.set('search', search.trim());
|
||||
}
|
||||
return this.http.get<NotebookBookOption[]>(`${this.url}/books`, {params});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user