feat: add annotation notebook with server-side pagination (#2736)
Co-authored-by: acx10 <acx10@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,54 @@
|
|||||||
|
package org.booklore.controller;
|
||||||
|
|
||||||
|
import org.booklore.model.dto.NotebookBookOption;
|
||||||
|
import org.booklore.model.dto.NotebookEntry;
|
||||||
|
import org.booklore.service.book.NotebookService;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RequestMapping("/api/v1/notebook")
|
||||||
|
@Tag(name = "Notebook", description = "Endpoints for the annotation notebook view")
|
||||||
|
public class NotebookController {
|
||||||
|
|
||||||
|
private final NotebookService notebookService;
|
||||||
|
|
||||||
|
@Operation(summary = "Get paginated notebook entries")
|
||||||
|
@GetMapping
|
||||||
|
public Page<NotebookEntry> getNotebookEntries(
|
||||||
|
@RequestParam(defaultValue = "0") int page,
|
||||||
|
@RequestParam(defaultValue = "50") int size,
|
||||||
|
@RequestParam(required = false) Set<String> types,
|
||||||
|
@RequestParam(required = false) Long bookId,
|
||||||
|
@RequestParam(required = false) String search,
|
||||||
|
@RequestParam(defaultValue = "desc") String sort) {
|
||||||
|
return notebookService.getNotebookEntries(page, size, types, bookId, search, sort);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "Get all notebook entries for export")
|
||||||
|
@GetMapping("/export")
|
||||||
|
public List<NotebookEntry> exportNotebookEntries(
|
||||||
|
@RequestParam(required = false) Set<String> types,
|
||||||
|
@RequestParam(required = false) Long bookId,
|
||||||
|
@RequestParam(required = false) String search,
|
||||||
|
@RequestParam(defaultValue = "desc") String sort) {
|
||||||
|
return notebookService.getAllNotebookEntries(types, bookId, search, sort);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "Get books that have annotations")
|
||||||
|
@GetMapping("/books")
|
||||||
|
public List<NotebookBookOption> getBooksWithAnnotations(
|
||||||
|
@RequestParam(required = false) String search) {
|
||||||
|
return notebookService.getBooksWithAnnotations(search);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package org.booklore.model.dto;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class NotebookBookOption {
|
||||||
|
private Long bookId;
|
||||||
|
private String bookTitle;
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package org.booklore.model.dto;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class NotebookEntry {
|
||||||
|
private Long id;
|
||||||
|
private String type;
|
||||||
|
private Long bookId;
|
||||||
|
private String bookTitle;
|
||||||
|
private String text;
|
||||||
|
private String note;
|
||||||
|
private String color;
|
||||||
|
private String style;
|
||||||
|
private String chapterTitle;
|
||||||
|
private LocalDateTime createdAt;
|
||||||
|
private LocalDateTime updatedAt;
|
||||||
|
}
|
||||||
@@ -31,4 +31,7 @@ public interface AnnotationRepository extends JpaRepository<AnnotationEntity, Lo
|
|||||||
long countByBookIdAndUserId(Long bookId, Long userId);
|
long countByBookIdAndUserId(Long bookId, Long userId);
|
||||||
|
|
||||||
void deleteByBookIdAndUserId(Long bookId, Long userId);
|
void deleteByBookIdAndUserId(Long bookId, Long userId);
|
||||||
|
|
||||||
|
@Query("SELECT a FROM AnnotationEntity a JOIN FETCH a.book b JOIN FETCH b.metadata WHERE a.userId = :userId ORDER BY a.createdAt DESC")
|
||||||
|
List<AnnotationEntity> findByUserIdOrderByCreatedAtDesc(@Param("userId") Long userId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,4 +29,7 @@ public interface BookMarkRepository extends JpaRepository<BookMarkEntity, Long>
|
|||||||
|
|
||||||
// New: count bookmarks per book
|
// New: count bookmarks per book
|
||||||
long countByBookIdAndUserId(Long bookId, Long userId);
|
long countByBookIdAndUserId(Long bookId, Long userId);
|
||||||
|
|
||||||
|
@Query("SELECT b FROM BookMarkEntity b JOIN FETCH b.book bk JOIN FETCH bk.metadata WHERE b.userId = :userId ORDER BY b.createdAt DESC")
|
||||||
|
List<BookMarkEntity> findByUserIdOrderByCreatedAtDesc(@Param("userId") Long userId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,4 +31,7 @@ public interface BookNoteV2Repository extends JpaRepository<BookNoteV2Entity, Lo
|
|||||||
long countByBookIdAndUserId(Long bookId, Long userId);
|
long countByBookIdAndUserId(Long bookId, Long userId);
|
||||||
|
|
||||||
void deleteByBookIdAndUserId(Long bookId, Long userId);
|
void deleteByBookIdAndUserId(Long bookId, Long userId);
|
||||||
|
|
||||||
|
@Query("SELECT n FROM BookNoteV2Entity n JOIN FETCH n.book b JOIN FETCH b.metadata WHERE n.userId = :userId ORDER BY n.createdAt DESC")
|
||||||
|
List<BookNoteV2Entity> findByUserIdOrderByCreatedAtDesc(@Param("userId") Long userId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,84 @@
|
|||||||
|
package org.booklore.repository;
|
||||||
|
|
||||||
|
import org.booklore.model.entity.AnnotationEntity;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.data.repository.Repository;
|
||||||
|
import org.springframework.data.repository.query.Param;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public interface NotebookEntryRepository extends Repository<AnnotationEntity, Long> {
|
||||||
|
|
||||||
|
String ENTRIES_UNION =
|
||||||
|
"SELECT a.id, 'HIGHLIGHT' AS type, a.user_id, a.book_id, bm.title AS book_title, " +
|
||||||
|
"a.text, a.note, a.color, a.style, a.chapter_title, a.created_at, a.updated_at " +
|
||||||
|
"FROM annotations a JOIN book_metadata bm ON bm.book_id = a.book_id " +
|
||||||
|
"UNION ALL " +
|
||||||
|
"SELECT n.id, 'NOTE' AS type, n.user_id, n.book_id, bm.title AS book_title, " +
|
||||||
|
"n.selected_text, n.note_content, n.color, NULL, n.chapter_title, n.created_at, n.updated_at " +
|
||||||
|
"FROM book_notes_v2 n JOIN book_metadata bm ON bm.book_id = n.book_id " +
|
||||||
|
"UNION ALL " +
|
||||||
|
"SELECT b.id, 'BOOKMARK' AS type, b.user_id, b.book_id, bm.title AS book_title, " +
|
||||||
|
"b.title, b.notes, b.color, NULL, NULL, b.created_at, b.updated_at " +
|
||||||
|
"FROM book_marks b JOIN book_metadata bm ON bm.book_id = b.book_id";
|
||||||
|
|
||||||
|
String ENTRIES_FILTER =
|
||||||
|
" WHERE t.user_id = :userId AND t.type IN (:types)" +
|
||||||
|
" AND (:bookId IS NULL OR t.book_id = :bookId)" +
|
||||||
|
" AND (:search IS NULL" +
|
||||||
|
" OR t.text LIKE :search ESCAPE '\\\\'" +
|
||||||
|
" OR t.note LIKE :search ESCAPE '\\\\'" +
|
||||||
|
" OR t.book_title LIKE :search ESCAPE '\\\\'" +
|
||||||
|
" OR t.chapter_title LIKE :search ESCAPE '\\\\')";
|
||||||
|
|
||||||
|
interface EntryProjection {
|
||||||
|
Long getId();
|
||||||
|
String getType();
|
||||||
|
Long getBookId();
|
||||||
|
String getBookTitle();
|
||||||
|
String getText();
|
||||||
|
String getNote();
|
||||||
|
String getColor();
|
||||||
|
String getStyle();
|
||||||
|
String getChapterTitle();
|
||||||
|
LocalDateTime getCreatedAt();
|
||||||
|
LocalDateTime getUpdatedAt();
|
||||||
|
}
|
||||||
|
|
||||||
|
interface BookProjection {
|
||||||
|
Long getBookId();
|
||||||
|
String getBookTitle();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Query(value = "SELECT t.id, t.type, t.book_id AS bookId, t.book_title AS bookTitle, " +
|
||||||
|
"t.text, t.note, t.color, t.style, t.chapter_title AS chapterTitle, " +
|
||||||
|
"t.created_at AS createdAt, t.updated_at AS updatedAt " +
|
||||||
|
"FROM (" + ENTRIES_UNION + ") t" + ENTRIES_FILTER,
|
||||||
|
countQuery = "SELECT COUNT(*) FROM (" + ENTRIES_UNION + ") t" + ENTRIES_FILTER,
|
||||||
|
nativeQuery = true)
|
||||||
|
Page<EntryProjection> findEntries(@Param("userId") Long userId,
|
||||||
|
@Param("types") Set<String> types,
|
||||||
|
@Param("bookId") Long bookId,
|
||||||
|
@Param("search") String search,
|
||||||
|
Pageable pageable);
|
||||||
|
|
||||||
|
@Query(value = "SELECT DISTINCT t.book_id AS bookId, t.book_title AS bookTitle FROM (" +
|
||||||
|
"SELECT a.book_id, bm.title AS book_title FROM annotations a " +
|
||||||
|
"JOIN book_metadata bm ON bm.book_id = a.book_id WHERE a.user_id = :userId " +
|
||||||
|
"UNION " +
|
||||||
|
"SELECT n.book_id, bm.title AS book_title FROM book_notes_v2 n " +
|
||||||
|
"JOIN book_metadata bm ON bm.book_id = n.book_id WHERE n.user_id = :userId " +
|
||||||
|
"UNION " +
|
||||||
|
"SELECT b.book_id, bm.title AS book_title FROM book_marks b " +
|
||||||
|
"JOIN book_metadata bm ON bm.book_id = b.book_id WHERE b.user_id = :userId" +
|
||||||
|
") t WHERE (:search IS NULL OR t.book_title LIKE :search ESCAPE '\\\\') " +
|
||||||
|
"ORDER BY t.book_title",
|
||||||
|
nativeQuery = true)
|
||||||
|
List<BookProjection> findBooksWithAnnotations(@Param("userId") Long userId,
|
||||||
|
@Param("search") String search,
|
||||||
|
Pageable pageable);
|
||||||
|
}
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
package org.booklore.service.book;
|
||||||
|
|
||||||
|
import org.booklore.config.security.service.AuthenticationService;
|
||||||
|
import org.booklore.model.dto.NotebookBookOption;
|
||||||
|
import org.booklore.model.dto.NotebookEntry;
|
||||||
|
import org.booklore.repository.NotebookEntryRepository;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.PageRequest;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.data.domain.Sort;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class NotebookService {
|
||||||
|
|
||||||
|
private static final int EXPORT_LIMIT = 50_000;
|
||||||
|
private static final int BOOK_OPTIONS_LIMIT = 50;
|
||||||
|
|
||||||
|
private final NotebookEntryRepository repository;
|
||||||
|
private final AuthenticationService authenticationService;
|
||||||
|
|
||||||
|
@Transactional(readOnly = true)
|
||||||
|
public Page<NotebookEntry> getNotebookEntries(int page, int size, Set<String> types, Long bookId,
|
||||||
|
String search, String sort) {
|
||||||
|
Long userId = authenticationService.getAuthenticatedUser().getId();
|
||||||
|
Pageable pageable = PageRequest.of(page, size, toSort(sort));
|
||||||
|
return repository.findEntries(userId, types, bookId, wrapSearch(search), pageable)
|
||||||
|
.map(NotebookService::toDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(readOnly = true)
|
||||||
|
public List<NotebookEntry> getAllNotebookEntries(Set<String> types, Long bookId, String search, String sort) {
|
||||||
|
Long userId = authenticationService.getAuthenticatedUser().getId();
|
||||||
|
Pageable pageable = PageRequest.of(0, EXPORT_LIMIT, toSort(sort));
|
||||||
|
return repository.findEntries(userId, types, bookId, wrapSearch(search), pageable)
|
||||||
|
.map(NotebookService::toDto)
|
||||||
|
.getContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(readOnly = true)
|
||||||
|
public List<NotebookBookOption> getBooksWithAnnotations(String search) {
|
||||||
|
Long userId = authenticationService.getAuthenticatedUser().getId();
|
||||||
|
return repository.findBooksWithAnnotations(userId, wrapSearch(search), Pageable.ofSize(BOOK_OPTIONS_LIMIT))
|
||||||
|
.stream()
|
||||||
|
.map(p -> new NotebookBookOption(p.getBookId(), p.getBookTitle()))
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String wrapSearch(String search) {
|
||||||
|
if (search == null || search.isBlank()) return null;
|
||||||
|
return "%" + escapeLike(search) + "%";
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String escapeLike(String input) {
|
||||||
|
return input.trim()
|
||||||
|
.replace("\\", "\\\\")
|
||||||
|
.replace("%", "\\%")
|
||||||
|
.replace("_", "\\_");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Sort toSort(String sort) {
|
||||||
|
return "asc".equalsIgnoreCase(sort)
|
||||||
|
? Sort.by("createdAt").ascending()
|
||||||
|
: Sort.by("createdAt").descending();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static NotebookEntry toDto(NotebookEntryRepository.EntryProjection p) {
|
||||||
|
return NotebookEntry.builder()
|
||||||
|
.id(p.getId())
|
||||||
|
.type(p.getType())
|
||||||
|
.bookId(p.getBookId())
|
||||||
|
.bookTitle(p.getBookTitle())
|
||||||
|
.text(p.getText())
|
||||||
|
.note(p.getNote())
|
||||||
|
.color(p.getColor())
|
||||||
|
.style(p.getStyle())
|
||||||
|
.chapterTitle(p.getChapterTitle())
|
||||||
|
.createdAt(p.getCreatedAt())
|
||||||
|
.updatedAt(p.getUpdatedAt())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
CREATE INDEX IF NOT EXISTS idx_annotations_user_created ON annotations (user_id, created_at);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_book_notes_v2_user_created ON book_notes_v2 (user_id, created_at);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_book_marks_user_created ON book_marks (user_id, created_at);
|
||||||
@@ -26,6 +26,7 @@ import {EditMetadataGuard} from './core/security/guards/edit-metdata.guard';
|
|||||||
import {EbookReaderComponent} from './features/readers/ebook-reader';
|
import {EbookReaderComponent} from './features/readers/ebook-reader';
|
||||||
import {LibraryStatsComponent} from './features/stats/component/library-stats/library-stats.component';
|
import {LibraryStatsComponent} from './features/stats/component/library-stats/library-stats.component';
|
||||||
import {AudiobookPlayerComponent} from './features/readers/audiobook-player';
|
import {AudiobookPlayerComponent} from './features/readers/audiobook-player';
|
||||||
|
import {NotebookComponent} from './features/notebook/components/notebook/notebook.component';
|
||||||
|
|
||||||
export const routes: Routes = [
|
export const routes: Routes = [
|
||||||
{
|
{
|
||||||
@@ -57,6 +58,7 @@ export const routes: Routes = [
|
|||||||
{path: 'metadata-manager', component: MetadataManagerComponent, canActivate: [EditMetadataGuard]},
|
{path: 'metadata-manager', component: MetadataManagerComponent, canActivate: [EditMetadataGuard]},
|
||||||
{path: 'library-stats', component: LibraryStatsComponent, canActivate: [LibraryStatsGuard]},
|
{path: 'library-stats', component: LibraryStatsComponent, canActivate: [LibraryStatsGuard]},
|
||||||
{path: 'reading-stats', component: UserStatsComponent, canActivate: [UserStatsGuard]},
|
{path: 'reading-stats', component: UserStatsComponent, canActivate: [UserStatsGuard]},
|
||||||
|
{path: 'notebook', component: NotebookComponent, canActivate: [AuthGuard]},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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,279 @@
|
|||||||
|
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: [], totalElements: 0, totalPages: 0, number: 0, size: 0, first: true, last: true, empty: true
|
||||||
|
};
|
||||||
|
|
||||||
|
@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.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)) {
|
||||||
|
groupMap.set(entry.bookId, {
|
||||||
|
bookId: entry.bookId,
|
||||||
|
bookTitle: entry.bookTitle,
|
||||||
|
thumbnailUrl: this.urlHelper.getThumbnailUrl1(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;
|
||||||
|
createdAt: string;
|
||||||
|
updatedAt?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface NotebookPage {
|
||||||
|
content: NotebookEntry[];
|
||||||
|
totalElements: number;
|
||||||
|
totalPages: number;
|
||||||
|
number: number;
|
||||||
|
size: number;
|
||||||
|
first: boolean;
|
||||||
|
last: boolean;
|
||||||
|
empty: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
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});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -89,6 +89,11 @@ export class AppMenuComponent implements OnInit {
|
|||||||
icon: 'pi pi-fw pi-book',
|
icon: 'pi pi-fw pi-book',
|
||||||
routerLink: ['/all-books'],
|
routerLink: ['/all-books'],
|
||||||
bookCount$: of(bookState.books ? bookState.books.length : 0),
|
bookCount$: of(bookState.books ? bookState.books.length : 0),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: this.t.translate('layout.menu.notebook'),
|
||||||
|
icon: 'pi pi-fw pi-pencil',
|
||||||
|
routerLink: ['/notebook'],
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -23,8 +23,9 @@ import layout from './layout.json';
|
|||||||
import libraryCreator from './library-creator.json';
|
import libraryCreator from './library-creator.json';
|
||||||
import bookdrop from './bookdrop.json';
|
import bookdrop from './bookdrop.json';
|
||||||
import metadata from './metadata.json';
|
import metadata from './metadata.json';
|
||||||
|
import notebook from './notebook.json';
|
||||||
|
|
||||||
// To add a new domain: create the JSON file and add it here.
|
// To add a new domain: create the JSON file and add it here.
|
||||||
// Settings tabs each get their own file: settings-email, settings-reader, settings-view, etc.
|
// Settings tabs each get their own file: settings-email, settings-reader, settings-view, etc.
|
||||||
const translations: Translation = {common, auth, nav, dashboard, settings, settingsEmail, settingsReader, settingsView, settingsMeta, settingsLibMeta, settingsApp, settingsUsers, settingsNaming, settingsOpds, settingsTasks, settingsAuth, settingsDevice, settingsProfile, app, shared, layout, libraryCreator, bookdrop, metadata};
|
const translations: Translation = {common, auth, nav, dashboard, settings, settingsEmail, settingsReader, settingsView, settingsMeta, settingsLibMeta, settingsApp, settingsUsers, settingsNaming, settingsOpds, settingsTasks, settingsAuth, settingsDevice, settingsProfile, app, shared, layout, libraryCreator, bookdrop, metadata, notebook};
|
||||||
export default translations;
|
export default translations;
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
"shelves": "Shelves",
|
"shelves": "Shelves",
|
||||||
"magicShelves": "Magic Shelves",
|
"magicShelves": "Magic Shelves",
|
||||||
"unshelved": "Unshelved",
|
"unshelved": "Unshelved",
|
||||||
|
"notebook": "Notebook",
|
||||||
"update": "(Update)"
|
"update": "(Update)"
|
||||||
},
|
},
|
||||||
"changelog": {
|
"changelog": {
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"pageTitle": "Notebook",
|
||||||
|
"pageDescription": "All your highlights, notes, and bookmarks across your library in one place.",
|
||||||
|
"searchPlaceholder": "Search annotations...",
|
||||||
|
"filterAll": "All",
|
||||||
|
"filterHighlights": "Highlights",
|
||||||
|
"filterNotes": "Notes",
|
||||||
|
"filterBookmarks": "Bookmarks",
|
||||||
|
"filterByBook": "Filter by book",
|
||||||
|
"allBooks": "All Books",
|
||||||
|
"sortNewest": "Newest first",
|
||||||
|
"sortOldest": "Oldest first",
|
||||||
|
"export": "Export",
|
||||||
|
"exportMarkdown": "Export as Markdown",
|
||||||
|
"noEntries": "No annotations yet",
|
||||||
|
"noEntriesHint": "Start highlighting and taking notes while reading!",
|
||||||
|
"noResults": "No results match your filters",
|
||||||
|
"chapter": "Chapter",
|
||||||
|
"highlight": "Highlight",
|
||||||
|
"note": "Note",
|
||||||
|
"bookmark": "Bookmark",
|
||||||
|
"annotation": "annotation",
|
||||||
|
"annotations": "annotations"
|
||||||
|
}
|
||||||
@@ -23,8 +23,9 @@ import layout from './layout.json';
|
|||||||
import libraryCreator from './library-creator.json';
|
import libraryCreator from './library-creator.json';
|
||||||
import bookdrop from './bookdrop.json';
|
import bookdrop from './bookdrop.json';
|
||||||
import metadata from './metadata.json';
|
import metadata from './metadata.json';
|
||||||
|
import notebook from './notebook.json';
|
||||||
|
|
||||||
// To add a new domain: create the JSON file and add it here.
|
// To add a new domain: create the JSON file and add it here.
|
||||||
// Settings tabs each get their own file: settings-email, settings-reader, settings-view, etc.
|
// Settings tabs each get their own file: settings-email, settings-reader, settings-view, etc.
|
||||||
const translations: Translation = {common, auth, nav, dashboard, settings, settingsEmail, settingsReader, settingsView, settingsMeta, settingsLibMeta, settingsApp, settingsUsers, settingsNaming, settingsOpds, settingsTasks, settingsAuth, settingsDevice, settingsProfile, app, shared, layout, libraryCreator, bookdrop, metadata};
|
const translations: Translation = {common, auth, nav, dashboard, settings, settingsEmail, settingsReader, settingsView, settingsMeta, settingsLibMeta, settingsApp, settingsUsers, settingsNaming, settingsOpds, settingsTasks, settingsAuth, settingsDevice, settingsProfile, app, shared, layout, libraryCreator, bookdrop, metadata, notebook};
|
||||||
export default translations;
|
export default translations;
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
"shelves": "Estantes",
|
"shelves": "Estantes",
|
||||||
"magicShelves": "Estantes mágicos",
|
"magicShelves": "Estantes mágicos",
|
||||||
"unshelved": "Sin estante",
|
"unshelved": "Sin estante",
|
||||||
|
"notebook": "Cuaderno",
|
||||||
"update": "(Actualizar)"
|
"update": "(Actualizar)"
|
||||||
},
|
},
|
||||||
"changelog": {
|
"changelog": {
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"pageTitle": "Cuaderno",
|
||||||
|
"pageDescription": "Todos tus resaltados, notas y marcadores de tu biblioteca en un solo lugar.",
|
||||||
|
"searchPlaceholder": "Buscar anotaciones...",
|
||||||
|
"filterAll": "Todos",
|
||||||
|
"filterHighlights": "Resaltados",
|
||||||
|
"filterNotes": "Notas",
|
||||||
|
"filterBookmarks": "Marcadores",
|
||||||
|
"filterByBook": "Filtrar por libro",
|
||||||
|
"allBooks": "Todos los libros",
|
||||||
|
"sortNewest": "Más recientes primero",
|
||||||
|
"sortOldest": "Más antiguos primero",
|
||||||
|
"export": "Exportar",
|
||||||
|
"exportMarkdown": "Exportar como Markdown",
|
||||||
|
"noEntries": "Aún no hay anotaciones",
|
||||||
|
"noEntriesHint": "¡Empieza a resaltar y tomar notas mientras lees!",
|
||||||
|
"noResults": "Ningún resultado coincide con tus filtros",
|
||||||
|
"chapter": "Capítulo",
|
||||||
|
"highlight": "Resaltado",
|
||||||
|
"note": "Nota",
|
||||||
|
"bookmark": "Marcador",
|
||||||
|
"annotation": "anotación",
|
||||||
|
"annotations": "anotaciones"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user