Initial commit

This commit is contained in:
aditya.chandel
2024-12-13 12:58:23 -07:00
commit baff376b9c
414 changed files with 552987 additions and 0 deletions
@@ -0,0 +1,11 @@
<div class="dashboard">
<h1 *ngIf="isLibrariesEmpty" class="no-library-header">
Looks like you haven't added a library yet. Let's add one!
</h1>
<p-button *ngIf="isLibrariesEmpty"
label="Add a Library"
icon="pi pi-plus"
styleClass="p-button-rounded p-button-outlined"
(click)="createNewLibrary($event)">
</p-button>
</div>
@@ -0,0 +1,27 @@
.dashboard {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
margin-top: 5rem;
text-align: center;
.no-library-header {
font-size: 1.5rem;
font-weight: 600;
margin-bottom: 1rem;
color: var(--text-color)
}
.p-dialog {
max-width: 90%; /* Ensure the dialog doesn't overflow the viewport */
}
}
::ng-deep .p-dialog-mask {
background-color: rgba(0, 0, 0, 0.5); /* Darken the background with 50% opacity */
}
/* You can also adjust the blur if you want */
::ng-deep .p-dialog-mask {
backdrop-filter: blur(3px); /* Optional: Apply blur to the background */
}
@@ -0,0 +1,51 @@
import { Component, WritableSignal } from '@angular/core';
import { LibraryService } from '../../service/library.service';
import { Library } from '../../model/library.model';
import { Button } from 'primeng/button';
import { NgIf } from '@angular/common';
import { LibraryCreatorComponent } from '../library-creator/library-creator.component';
import { DialogService, DynamicDialogRef } from 'primeng/dynamicdialog';
@Component({
selector: 'app-home-page',
templateUrl: './dashboard.component.html',
imports: [
Button,
NgIf
],
styleUrls: ['./dashboard.component.scss'],
providers: [DialogService], // Ensure the DialogService is available
})
export class DashboardComponent {
private libraries: WritableSignal<Library[]>;
ref: DynamicDialogRef | undefined;
constructor(private libraryService: LibraryService, public dialogService: DialogService) {
this.libraries = this.libraryService.libraries;
}
get isLibrariesEmpty(): boolean {
return this.libraries()?.length === 1;
}
createNewLibrary(event: MouseEvent) {
const buttonRect = (event.target as HTMLElement).getBoundingClientRect();
const dialogWidthPercentage = 50; // Use percentage-based width
const viewportWidth = window.innerWidth;
const dialogWidth = (dialogWidthPercentage / 100) * viewportWidth;
const leftPosition = buttonRect.left + (buttonRect.width / 2) - (dialogWidth / 2);
this.ref = this.dialogService.open(LibraryCreatorComponent, {
modal: true,
width: `${dialogWidthPercentage}%`, // Dynamic width
height: 'auto', // Let height adapt to content
style: {
position: 'absolute',
top: `${buttonRect.bottom + 10}px`, // Position below the button
left: `${Math.max(leftPosition, 0)}px`, // Ensure it stays within the viewport
},
});
}
}
@@ -0,0 +1,33 @@
<div style="margin-bottom: 1.5rem; display: flex; align-items: center; gap: 1rem;">
<input
id="disabled-input"
type="text"
pInputText
[value]="selectedProductName"
[disabled]="true"
[ngStyle]="{ 'width': '100%', 'padding': '0.5rem', 'font-size': '1rem' }"
/>
<p-button label="Select" severity="success" [ngStyle]="{ 'width': '100px' }" (click)="onSelect()"/>
</div>
<ng-container>
<div style="overflow-x: auto;">
<p-table [value]="paths" [tableStyle]="{ 'min-width': '50rem' }" class="product-table">
<ng-template pTemplate="header">
<tr>
<th [style.width]="'10%'">Type</th>
<th [style.width]="'90%'">Name</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-product>
<tr (click)="onRowClick(product)">
<td>
<i *ngIf="product === '...'" class="pi pi-arrow-up"></i>
<i *ngIf="product !== '...'" class="pi pi-folder-open"></i>
</td>
<td>{{ product }}</td>
</tr>
</ng-template>
</p-table>
</div>
</ng-container>
@@ -0,0 +1,53 @@
import {Component, OnInit} from '@angular/core';
import {DynamicDialogRef} from 'primeng/dynamicdialog';
import {UtilityService} from '../../service/utility.service';
@Component({
selector: 'app-directory-picker-v2',
standalone: false,
templateUrl: './directory-picker.component.html',
styleUrls: ['./directory-picker.component.scss']
})
export class DirectoryPickerComponent implements OnInit {
value: any;
paths: string[] = ['...'];
selectedProductName: string = '';
constructor(private utilityService: UtilityService, private dynamicDialogRef: DynamicDialogRef) {
}
ngOnInit() {
const initialPath = '/';
this.getFolders(initialPath);
}
getFolders(path: string): void {
this.utilityService.getFolders(path).subscribe(
(folders: string[]) => {
this.paths = ['...', ...folders];
},
(error) => {
console.error('Error fetching folders:', error);
}
);
}
onRowClick(path: string): void {
if (path === '...') {
if (this.selectedProductName === '' || this.selectedProductName === '/') {
this.getFolders('/');
} else {
const result = this.selectedProductName.substring(0, this.selectedProductName.lastIndexOf('/')) || '/';
this.selectedProductName = result;
this.getFolders(result);
}
} else {
this.selectedProductName = path;
this.getFolders(path);
}
}
onSelect(): void {
this.dynamicDialogRef.close(this.selectedProductName);
}
}
@@ -0,0 +1,11 @@
<div class="book-list" infiniteScroll [infiniteScrollDistance]="2" [infiniteScrollThrottle]="50" (scrolled)="loadMore()">
<div class="book-item" *ngFor="let book of books">
<img [src]="coverImageSrc(book.id)" class="book-cover placeholder" alt="Cover of {{ book.title }}" loading="lazy"/>
<div class="book-info">
<h4>{{ book.title }}</h4>
<p>{{ getAuthorNames(book) }}</p>
<p-button label="View" icon="pi pi-eye" class="view-btn" (click)="openBook(book.id)"></p-button>
</div>
</div>
</div>
@@ -0,0 +1,105 @@
.book-list {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(145px, 1fr));
gap: 20px;
}
.book-item {
color: #fff;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
overflow: hidden;
transition: transform 0.3s ease-in-out;
display: flex;
flex-direction: column;
justify-content: space-between;
height: auto;
background-color: var(--surface-card);
border-radius: 8px;
position: relative; /* Positioning container for the button and overlay */
}
.book-cover {
width: 100%;
height: 225px; /* Adjust this as per the image height */
object-fit: cover;
background-color: #444;
transition: background-color 0.3s ease, filter 0.3s ease; /* Add transition for blur effect */
position: relative; /* Make this the reference point for the overlay */
}
/* Blur and overlay effect */
.book-item:hover .book-cover {
filter: blur(2px); /* Apply blur effect to the image */
}
.book-item:hover .book-cover::after {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5); /* Semi-transparent black overlay */
z-index: 0; /* Put overlay behind the button */
}
.book-info {
padding: 10px;
text-align: center;
display: flex;
flex-direction: column;
justify-content: flex-start;
flex-grow: 1;
z-index: 1; /* Ensure the text stays above the overlay */
}
h4 {
font-size: 1rem;
color: var(--text-color);
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
max-width: 100%;
text-align: center;
margin-bottom: 5px;
}
p {
color: var(--text-color-secondary);
font-size: 0.8rem;
line-height: 1.4;
margin-top: 0;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
max-width: 100%;
margin-bottom: auto;
}
.authors {
font-weight: bold;
}
.no-authors {
color: #888;
font-style: italic;
}
/* PrimeNG button styling */
.view-btn {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%); /* Center button on the image */
display: none; /* Hide by default */
z-index: 1; /* Ensure it appears over the image */
}
.book-item:hover .view-btn {
display: block; /* Show the button when the card is hovered */
}
.infinite-scroll {
margin-top: 20px;
}
@@ -0,0 +1,63 @@
import { Component, OnInit } from '@angular/core';
import { BookService } from '../../service/book.service';
import { Book } from '../../model/book.model';
import { ActivatedRoute } from '@angular/router';
@Component({
selector: 'app-library-browser-v2',
standalone: false,
templateUrl: './library-browser.component.html',
styleUrls: ['./library-browser.component.scss'],
})
export class LibraryBrowserComponent implements OnInit {
books: Book[] = [];
private libraryId: number = 1;
private currentPage: number = 0;
constructor(private bookService: BookService, private route: ActivatedRoute) {}
ngOnInit(): void {
this.route.paramMap.subscribe((params) => {
const libraryId = params.get('libraryId');
if (libraryId) {
this.libraryId = +libraryId;
this.resetState();
this.loadBooks();
}
});
}
resetState(): void {
this.books = [];
this.currentPage = 0;
}
loadBooks(): void {
this.bookService.loadBooks(this.libraryId, this.currentPage).subscribe({
next: (response) => {
this.books = [...this.books, ...response.content];
this.currentPage++;
},
error: (err) => {
console.error('Error loading books:', err);
},
});
}
coverImageSrc(bookId: number): string {
return this.bookService.getBookCoverUrl(bookId);
}
loadMore(): void {
this.loadBooks();
}
getAuthorNames(book: Book): string {
return book.authors?.map((author) => author.name).join(', ') || 'No authors available';
}
openBook(bookId: number): void {
const url = `/pdf-viewer/book/${bookId}`;
window.open(url, '_blank');
}
}
@@ -0,0 +1,60 @@
<p-stepper>
<p-stepperPanel header="Library Name">
<ng-template pTemplate="content" let-nextCallback="nextCallback" let-index="index">
<div class="flex flex-column h-21rem">
<div
class="border-2 border-dashed surface-border border-round surface-ground flex-auto flex justify-content-center align-items-center font-medium">
<input
type="text"
pInputText
[(ngModel)]="value"
placeholder="Enter library name..."/>
</div>
</div>
<div class="flex pt-4 justify-content-end">
<p-button
label="Next"
icon="pi pi-arrow-right"
iconPos="right"
(onClick)="nextCallback.emit()"/>
</div>
</ng-template>
</p-stepperPanel>
<p-stepperPanel header="Media Location">
<ng-template pTemplate="content" let-prevCallback="prevCallback" let-index="index">
<div class="flex flex-column">
<div
class="border-2 border-dashed surface-border border-round surface-ground flex-auto flex align-items-start"
style="padding-top: 2.5rem;">
<div class="flex flex-column justify-content-center align-items-center w-100">
<p-button
severity="secondary"
label="Browse for media folders"
(onClick)="show()">
</p-button>
<p-table [value]="folders" styleClass="p-datatable-striped" class="p-table-custom mt-3">
<ng-template pTemplate="body" let-folder let-i="rowIndex">
<tr>
<td class="tr-custom">{{ folder }}</td>
<td class="tr-custom td-x-custom">
<p-button
icon="pi pi-times"
[rounded]="true"
[text]="true"
severity="danger"
(onClick)="removeFolder(i)"
/>
</td>
</tr>
</ng-template>
</p-table>
</div>
</div>
</div>
<div class="flex pt-4 justify-content-between">
<p-button label="Back" icon="pi pi-arrow-left" (onClick)="prevCallback.emit()"/>
<p-button severity="success" label="Save" icon="pi pi-save" (onClick)="addLibrary()"></p-button>
</div>
</ng-template>
</p-stepperPanel>
</p-stepper>
@@ -0,0 +1,44 @@
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
position: relative;
height: 100%; /* Fills the parent container */
}
.textbox {
padding: 10px;
margin-bottom: 20px; /* Space between textbox and button */
}
.button {
position: absolute;
bottom: 10px;
left: 10px;
}
.tr-custom {
padding: 0.25rem 0.5rem !important;
border: 0px !important;
}
.p-table-custom {
margin: 1.5rem !important;
min-width: 35rem !important;
max-height: 11.25rem !important;
overflow: scroll;
}
.td-x-custom {
text-align: right;
}
.mt-3 {
margin-top: 1rem; /* Adds spacing between the button and the table */
}
.w-100 {
width: 100%; /* Ensures full-width alignment for consistent layout */
}
@@ -0,0 +1,92 @@
import {Component} from '@angular/core';
import {DialogService, DynamicDialogRef} from 'primeng/dynamicdialog';
import {DirectoryPickerComponent} from '../directory-picker/directory-picker.component';
import {MessageService} from 'primeng/api';
import {LibraryService} from '../../service/library.service';
@Component({
selector: 'app-library-creator',
standalone: false,
templateUrl: './library-creator.component.html',
styleUrl: './library-creator.component.scss',
providers: [MessageService]
})
export class LibraryCreatorComponent {
value: string = '';
folders: string[] = [];
ref: DynamicDialogRef | undefined;
constructor(
public dialogService: DialogService,
private dynamicDialogRef: DynamicDialogRef,
private messageService: MessageService,
private libraryServiceV2: LibraryService
) {}
show() {
this.ref = this.dialogService.open(DirectoryPickerComponent, {
header: 'Select Media Directory',
modal: false,
width: '50%',
height: '75%',
contentStyle: { overflow: 'auto' },
baseZIndex: 10
});
this.ref.onClose.subscribe((selectedFolder: string) => {
if (selectedFolder) {
this.addFolder(selectedFolder);
}
});
}
addFolder(folder: string): void {
this.folders.push(folder);
}
removeFolder(index: number): void {
this.folders.splice(index, 1);
}
addLibrary() {
const newLibrary = {
name: this.value,
paths: this.folders,
};
this.libraryServiceV2.createLibrary(newLibrary).subscribe({
next: (createdLibrary) => {
console.log('Library successfully created:', createdLibrary);
},
error: (err) => {
console.error('Failed to create library:', err);
}
});
this.dynamicDialogRef.close();
}
validateLibraryNameAndProceed(nextCallback: any) {
if (this.value.trim()) {
this.libraryServiceV2.checkLibraryNameExists(this.value).subscribe(
(response) => {
const libraryExists = response && response.name === this.value;
if (libraryExists) {
this.messageService.add({
severity: 'error',
summary: 'Library Name Exists',
detail: 'This library name is already taken.',
});
} else {
nextCallback.emit();
}
},
(error) => {
this.messageService.add({
severity: 'error',
summary: 'Error',
detail: 'An error occurred while checking the library name.',
});
}
);
}
}
}
@@ -0,0 +1,15 @@
<ngx-extended-pdf-viewer
[src]="getSrc()"
[handTool]="handTool"
[height]="'auto'"
[page]="page"
[rotation]="rotation"
[scrollMode]="scrollMode"
[sidebarVisible]="sidebarVisible"
[zoom]="zoom"
[spread]="spread"
(pageChange)="onPageChange($event)"
(zoomChange)="onZoomChange($event)"
(sidebarVisibleChange)="onSidebarVisibleChange($event)"
(spreadChange)="onSpreadChange($event)">
</ngx-extended-pdf-viewer>
@@ -0,0 +1,92 @@
import { ChangeDetectorRef, Component, NgZone, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { NgxExtendedPdfViewerModule, ScrollModeType } from 'ngx-extended-pdf-viewer';
import { BookService } from '../../service/book.service';
@Component({
selector: 'app-pdf-viewer',
standalone: true,
imports: [NgxExtendedPdfViewerModule],
templateUrl: './pdf-viewer.component.html',
})
export class PdfViewerComponent implements OnInit {
bookId!: number;
handTool = true;
page = 1;
rotation: 0 | 90 | 180 | 270 = 0;
scrollMode: ScrollModeType = ScrollModeType.page;
sidebarVisible = false;
spread: 'off' | 'even' | 'odd' = 'odd';
src = '';
zoom: number | string = 'page-fit';
private isInitialLoad = true;
constructor(
private bookService: BookService,
private zone: NgZone,
private route: ActivatedRoute
) {}
ngOnInit(): void {
this.route.paramMap.subscribe((params) => {
this.bookId = +params.get('bookId')!;
this.loadBook(this.bookId);
});
}
private loadBook(bookId: number): void {
this.bookService.getBook(bookId).subscribe((book) => {
this.zone.run(() => {
const { pageNumber, zoom, sidebar_visible, spread } = book.viewerSetting;
this.page = pageNumber || 1;
this.zoom = zoom || 'page-fit';
this.sidebarVisible = sidebar_visible || false;
this.spread = spread || 'odd';
this.isInitialLoad = false;
});
});
}
private updateViewerSetting(): void {
if (this.isInitialLoad) return;
const updatedViewerSetting = {
pageNumber: this.page,
zoom: this.zoom,
sidebar_visible: this.sidebarVisible,
spread: this.spread,
};
this.bookService.updateViewerSetting(updatedViewerSetting, this.bookId).subscribe();
}
onPageChange(page: number): void {
if (page !== this.page) {
this.page = page;
this.updateViewerSetting();
}
}
onZoomChange(zoom: string | number): void {
if (zoom !== this.zoom) {
this.zoom = zoom;
this.updateViewerSetting();
}
}
onSidebarVisibleChange(visible: boolean): void {
if (visible !== this.sidebarVisible) {
this.sidebarVisible = visible;
this.updateViewerSetting();
}
}
onSpreadChange(spread: 'off' | 'even' | 'odd'): void {
if (spread !== this.spread) {
this.spread = spread;
this.updateViewerSetting();
}
}
getSrc(): string {
return this.bookService.getBookDataUrl(this.bookId);
}
}
@@ -0,0 +1,21 @@
<div class="search-container" #searchContainer>
<span class="p-input-icon-left">
<i class="pi pi-search"></i>
<input
type="text"
pInputText
[(ngModel)]="searchQuery"
(input)="onSearchInputChange()"
placeholder="Search books..."
class="search-input"
#searchInput/>
<button *ngIf="searchQuery" pButton icon="pi pi-times" (click)="clearSearch()" class="clear-btn" type="button" aria-label="Clear Search"></button>
</span>
<div class="search-dropdown layout-menu" [class.show]="books.length > 0">
<div class="search-dropdown-item" *ngFor="let book of books" (click)="onBookClick(book)">
<img [src]="getBookCoverUrl(book.id)" alt="Book Cover" class="search-book-cover" />
<span class="search-book-name">{{ book.title }}</span>
</div>
</div>
</div>
@@ -0,0 +1,77 @@
.search-container {
margin-left: 20px;
position: relative; /* Ensure the dropdown is positioned relative to the container */
}
.search-dropdown {
position: absolute;
left: 0; /* Align the dropdown to the left of the container */
background-color: var(--surface-overlay); /* Use theme's background color */
border: 1px solid var(--surface-border);
border-radius: var(--border-radius);
z-index: 1000;
max-height: 300px; /* Limit the height of the dropdown */
overflow-y: auto; /* Scroll if the content exceeds max-height */
width: 600px; /* Ensures the dropdown has the same width as the search bar */
opacity: 0;
height: 0;
transition: opacity 0.3s ease, height 0.3s ease;
}
/* Show the dropdown */
.search-dropdown.show {
opacity: 1;
height: auto;
}
/* Dropdown item styles */
.search-dropdown-item {
display: flex;
align-items: center;
padding: 10px;
cursor: pointer;
transition: background-color 0.3s;
/* Hover effect */
&:hover {
background-color: var(--surface-hover);
}
}
/* Book cover styling */
.search-book-cover {
width: 25px; /* Set a fixed width */
height: 37px; /* Set a fixed height */
object-fit: cover; /* Ensure the image fits the area without distortion */
max-width: 100px; /* Max width to prevent images from becoming too big */
max-height: 150px; /* Max height to maintain consistency */
border-radius: 4px; /* Rounded corners */
margin-right: 10px; /* Space between the image and the title */
}
/* Book title styling */
.search-book-name {
font-size: 14px;
font-weight: 500;
color: var(--text-color);
flex-grow: 1; /* Allow the title to take up the remaining space */
}
/* Optionally customize the transition duration or timing */
.search-dropdown.show {
opacity: 1;
height: auto;
transition: opacity 0.3s ease, height 0.4s ease-in-out;
}
.clear-btn {
color: var(--text-color-secondary);
position: absolute;
right: 10px;
top: 50%;
transform: translateY(-50%);
background: none;
border: none;
cursor: pointer;
font-size: 12px;
}
@@ -0,0 +1,79 @@
import { Component, OnDestroy, OnInit } from '@angular/core';
import { Subject, Subscription } from 'rxjs';
import { debounceTime, distinctUntilChanged, switchMap, catchError } from 'rxjs/operators';
import { Book } from '../../model/book.model';
import { BookService } from '../../service/book.service';
import { FormsModule } from '@angular/forms';
import { InputTextModule } from 'primeng/inputtext';
import { NgForOf, NgIf } from '@angular/common';
import { ButtonDirective } from 'primeng/button';
@Component({
selector: 'app-search',
templateUrl: './search.component.html',
imports: [
FormsModule,
InputTextModule,
NgForOf,
NgIf,
ButtonDirective
],
styleUrls: ['./search.component.scss']
})
export class SearchComponent implements OnInit, OnDestroy {
searchQuery: string = '';
books: Book[] = [];
#searchSubject = new Subject<string>();
#subscription!: Subscription;
constructor(private bookService: BookService) {}
ngOnInit(): void {
this.initializeSearch();
}
initializeSearch(): void {
this.#subscription = this.#searchSubject.pipe(
debounceTime(500),
distinctUntilChanged(),
switchMap((query) => this.bookService.searchBooks(query).pipe(
catchError((error) => {
console.error('Error while searching books:', error);
return [];
})
))
).subscribe({
next: (result: Book[]) => this.books = result,
error: (error) => console.error('Subscription error:', error)
});
}
onSearchInputChange(): void {
this.#searchSubject.next(this.searchQuery.trim());
}
onBookClick(book: Book): void {
this.clearSearch();
this.openBook(book.id);
}
openBook(bookId: number): void {
const url = `/pdf-viewer/book/${bookId}`;
window.open(url, '_blank');
}
getBookCoverUrl(bookId: number): string {
return this.bookService.getBookCoverUrl(bookId);
}
clearSearch(): void {
this.searchQuery = '';
this.books = [];
}
ngOnDestroy(): void {
if (this.#subscription) {
this.#subscription.unsubscribe();
}
}
}
@@ -0,0 +1,4 @@
export interface Author {
id: number;
name: string;
}
@@ -0,0 +1,26 @@
import {Author} from './author.model';
export interface Book {
id: number;
libraryId: number;
title: string;
authors: Author[];
viewerSetting: BookViewerSetting;
}
export interface BookViewerSetting {
pageNumber: number;
zoom: number | string;
sidebar_visible: boolean;
spread: 'off' | 'even' | 'odd';
}
export interface PaginatedBooksResponse {
content: Book[];
totalElements: number;
totalPages: number;
size: number;
number: number;
first: boolean;
last: boolean;
}
@@ -0,0 +1,12 @@
export interface Library {
id?: number;
name: string;
paths: string[];
}
export interface LibraryApiResponse {
content: Library[];
totalElements: number;
totalPages: number;
numberOfElements: number;
}
@@ -0,0 +1,45 @@
import { Observable } from 'rxjs';
import { Book, PaginatedBooksResponse } from '../model/book.model';
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
@Injectable({
providedIn: 'root',
})
export class BookService {
private readonly pageSize = 25;
private readonly libraryUrl = 'http://localhost:8080/v1/library';
private readonly bookUrl = 'http://localhost:8080/v1/book';
constructor(private http: HttpClient) {}
getBook(bookId: number): Observable<Book> {
return this.http.get<Book>(`${this.bookUrl}/${bookId}`);
}
loadBooks(libraryId: number, page: number): Observable<PaginatedBooksResponse> {
return this.http.get<PaginatedBooksResponse>(
`${this.libraryUrl}/${libraryId}/book?page=${page}&size=${this.pageSize}`
);
}
searchBooks(query: string): Observable<Book[]> {
if (query.length < 3) {
return new Observable<Book[]>();
}
return this.http.get<Book[]>(`${this.bookUrl}/search?title=${encodeURIComponent(query)}`);
}
updateViewerSetting(viewerSetting: any, bookId: number): Observable<void> {
const url = `${this.bookUrl}/${bookId}/viewer-setting`;
return this.http.put<void>(url, viewerSetting);
}
getBookDataUrl(bookId: number): string {
return `${this.bookUrl}/${bookId}/data`;
}
getBookCoverUrl(bookId: number): string {
return `${this.bookUrl}/${bookId}/cover`;
}
}
@@ -0,0 +1,53 @@
import { Injectable, signal } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { catchError, map, tap } from 'rxjs/operators';
import { Observable, of } from 'rxjs';
import { Library, LibraryApiResponse } from '../model/library.model';
@Injectable({
providedIn: 'root'
})
export class LibraryService {
private libraryUrl: string = 'http://localhost:8080/v1/library';
libraries = signal<Library[]>([]);
constructor(private http: HttpClient) {
this.getLibrariesFromAPI();
}
getLibrariesFromAPI(): void {
this.http.get<LibraryApiResponse>(this.libraryUrl).pipe(
map(response => response.content),
catchError(error => {
console.error('Error loading libraries:', error);
return of([]);
})
).subscribe(
(libraries) => {
this.libraries.set(libraries);
}
);
}
createLibrary(newLibrary: Library): Observable<Library> {
return this.http.post<Library>(this.libraryUrl, newLibrary).pipe(
tap((createdLibrary) => {
this.libraries.set([...this.libraries(), createdLibrary]);
}),
catchError(error => {
console.error('Error creating library:', error);
throw error;
})
);
}
checkLibraryNameExists(name: string): Observable<any> {
return this.http.get<Library>(`${this.libraryUrl}/search?name=${name}`).pipe(
catchError(error => {
console.error('Error checking library name:', error);
return of(null);
})
);
}
}
@@ -0,0 +1,18 @@
import { Injectable } from '@angular/core';
import {Observable} from 'rxjs';
import {HttpClient, HttpParams} from '@angular/common/http';
@Injectable({
providedIn: 'root'
})
export class UtilityService {
private pathUrl = 'http://localhost:8080/v1/path';
constructor(private http: HttpClient) { }
getFolders(path: string): Observable<string[]> {
const params = new HttpParams().set('path', path);
return this.http.get<string[]>(this.pathUrl, { params });
}
}