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
+31
View File
@@ -0,0 +1,31 @@
import {NgModule} from '@angular/core';
import {RouterModule, Routes} from '@angular/router';
import {AppLayoutComponent} from './layout/app.layout.component';
import {LibraryBrowserComponent} from './book/component/library-browser/library-browser.component';
import {PdfViewerComponent} from './book/component/pdf-viewer/pdf-viewer.component';
import {DashboardComponent} from './book/component/dashboard/dashboard.component';
const routes: Routes = [
{
path: '', component: AppLayoutComponent,
children: [
{
path: '', component: DashboardComponent,
},
{
path: 'library/:libraryId/books', component: LibraryBrowserComponent,
}
]
},
{
path: 'pdf-viewer/book/:bookId',
component: PdfViewerComponent
}
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule {
}
+1
View File
@@ -0,0 +1 @@
<router-outlet></router-outlet>
+13
View File
@@ -0,0 +1,13 @@
import {Component} from '@angular/core';
import {LibraryService} from './book/service/library.service';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
standalone: false,
styleUrl: './app.component.scss'
})
export class AppComponent {
constructor(private libraryService: LibraryService) {
}
}
+51
View File
@@ -0,0 +1,51 @@
import {NgModule} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {AppRoutingModule} from './app-routing.module';
import {AppComponent} from './app.component';
import {AppLayoutModule} from './layout/app.layout.module';
import {FormsModule} from '@angular/forms';
import {DialogService} from 'primeng/dynamicdialog';
import {DirectoryPickerComponent} from './book/component/directory-picker/directory-picker.component';
import {InputTextModule} from 'primeng/inputtext';
import {TableModule} from 'primeng/table';
import {Button} from 'primeng/button';
import {LibraryCreatorComponent} from './book/component/library-creator/library-creator.component';
import {StepperModule} from 'primeng/stepper';
import {IconFieldModule} from 'primeng/iconfield';
import {InputIconModule} from 'primeng/inputicon';
import {ToggleButtonModule} from 'primeng/togglebutton';
import {PasswordModule} from 'primeng/password';
import {ToastModule} from 'primeng/toast';
import { LibraryBrowserComponent } from './book/component/library-browser/library-browser.component';
import {InfiniteScrollDirective} from 'ngx-infinite-scroll';
import { SearchComponent } from './book/component/search/search.component';
@NgModule({
declarations: [
AppComponent,
DirectoryPickerComponent,
LibraryCreatorComponent,
LibraryBrowserComponent
],
imports: [
BrowserModule,
AppRoutingModule,
AppLayoutModule,
FormsModule,
InputTextModule,
TableModule,
Button,
StepperModule,
IconFieldModule,
InputIconModule,
ToggleButtonModule,
PasswordModule,
ToastModule,
InfiniteScrollDirective,
SearchComponent,
],
providers: [DialogService],
bootstrap: [AppComponent]
})
export class AppModule { }
@@ -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 });
}
}
@@ -0,0 +1,4 @@
export interface MenuChangeEvent {
key: string;
routeEvent?: boolean;
}
@@ -0,0 +1,5 @@
<div class="layout-footer">
<img src="assets/layout/images/{{layoutService.config().colorScheme === 'light' ? 'logo-dark' : 'logo-white'}}.svg" alt="Logo" height="20" class="mr-2"/>
by
<span class="font-medium ml-2">PrimeNG</span>
</div>
@@ -0,0 +1,10 @@
import { Component } from '@angular/core';
import { LayoutService } from "./service/app.layout.service";
@Component({
selector: 'app-footer',
templateUrl: './app.footer.component.html'
})
export class AppFooterComponent {
constructor(public layoutService: LayoutService) { }
}
@@ -0,0 +1,14 @@
<div class="layout-wrapper" [ngClass]="containerClass">
<app-topbar></app-topbar>
<div class="layout-sidebar layout-sidebar-custom">
<app-sidebar></app-sidebar>
</div>
<div class="layout-main-container layout-main-container-custom">
<div class="layout-main" >
<router-outlet ></router-outlet>
</div>
<app-footer></app-footer>
</div>
<app-config></app-config>
<div class="layout-mask"></div>
</div>
@@ -0,0 +1,132 @@
import { Component, OnDestroy, Renderer2, ViewChild } from '@angular/core';
import {NavigationEnd, Router, RouterOutlet} from '@angular/router';
import { filter, Subscription } from 'rxjs';
import { LayoutService } from "./service/app.layout.service";
import { AppSidebarComponent } from "./app.sidebar.component";
import { AppTopBarComponent } from './app.topbar.component';
import {AppFooterComponent} from "./app.footer.component";
import {AppConfigComponent} from "./config/app.config.component";
import {NgClass} from '@angular/common';
@Component({
selector: 'app-layout',
imports: [
RouterOutlet,
AppFooterComponent,
AppConfigComponent,
AppSidebarComponent,
AppTopBarComponent,
NgClass
],
templateUrl: './app.layout.component.html'
})
export class AppLayoutComponent implements OnDestroy {
overlayMenuOpenSubscription: Subscription;
menuOutsideClickListener: any;
profileMenuOutsideClickListener: any;
@ViewChild(AppSidebarComponent) appSidebar!: AppSidebarComponent;
@ViewChild(AppTopBarComponent) appTopbar!: AppTopBarComponent;
constructor(public layoutService: LayoutService, public renderer: Renderer2, public router: Router) {
this.overlayMenuOpenSubscription = this.layoutService.overlayOpen$.subscribe(() => {
if (!this.menuOutsideClickListener) {
this.menuOutsideClickListener = this.renderer.listen('document', 'click', event => {
const isOutsideClicked = !(this.appSidebar.el.nativeElement.isSameNode(event.target) || this.appSidebar.el.nativeElement.contains(event.target)
|| this.appTopbar.menuButton.nativeElement.isSameNode(event.target) || this.appTopbar.menuButton.nativeElement.contains(event.target));
if (isOutsideClicked) {
this.hideMenu();
}
});
}
if (!this.profileMenuOutsideClickListener) {
this.profileMenuOutsideClickListener = this.renderer.listen('document', 'click', event => {
const isOutsideClicked = !(this.appTopbar.menu.nativeElement.isSameNode(event.target) || this.appTopbar.menu.nativeElement.contains(event.target)
|| this.appTopbar.topbarMenuButton.nativeElement.isSameNode(event.target) || this.appTopbar.topbarMenuButton.nativeElement.contains(event.target));
if (isOutsideClicked) {
this.hideProfileMenu();
}
});
}
if (this.layoutService.state.staticMenuMobileActive) {
this.blockBodyScroll();
}
});
this.router.events.pipe(filter(event => event instanceof NavigationEnd))
.subscribe(() => {
this.hideMenu();
this.hideProfileMenu();
});
}
hideMenu() {
this.layoutService.state.overlayMenuActive = false;
this.layoutService.state.staticMenuMobileActive = false;
this.layoutService.state.menuHoverActive = false;
if (this.menuOutsideClickListener) {
this.menuOutsideClickListener();
this.menuOutsideClickListener = null;
}
this.unblockBodyScroll();
}
hideProfileMenu() {
this.layoutService.state.profileSidebarVisible = false;
if (this.profileMenuOutsideClickListener) {
this.profileMenuOutsideClickListener();
this.profileMenuOutsideClickListener = null;
}
}
blockBodyScroll(): void {
if (document.body.classList) {
document.body.classList.add('blocked-scroll');
}
else {
document.body.className += ' blocked-scroll';
}
}
unblockBodyScroll(): void {
if (document.body.classList) {
document.body.classList.remove('blocked-scroll');
}
else {
document.body.className = document.body.className.replace(new RegExp('(^|\\b)' +
'blocked-scroll'.split(' ').join('|') + '(\\b|$)', 'gi'), ' ');
}
}
get containerClass() {
return {
'layout-theme-light': this.layoutService.config().colorScheme === 'light',
'layout-theme-dark': this.layoutService.config().colorScheme === 'dark',
'layout-overlay': this.layoutService.config().menuMode === 'overlay',
'layout-static': this.layoutService.config().menuMode === 'static',
'layout-static-inactive': this.layoutService.state.staticMenuDesktopInactive && this.layoutService.config().menuMode === 'static',
'layout-overlay-active': this.layoutService.state.overlayMenuActive,
'layout-mobile-active': this.layoutService.state.staticMenuMobileActive,
'p-input-filled': this.layoutService.config().inputStyle === 'filled',
'p-ripple-disabled': !this.layoutService.config().ripple
}
}
ngOnDestroy() {
if (this.overlayMenuOpenSubscription) {
this.overlayMenuOpenSubscription.unsubscribe();
}
if (this.menuOutsideClickListener) {
this.menuOutsideClickListener();
}
}
}
@@ -0,0 +1,47 @@
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { HttpClientModule } from '@angular/common/http';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { InputTextModule } from 'primeng/inputtext';
import { SidebarModule } from 'primeng/sidebar';
import { BadgeModule } from 'primeng/badge';
import { RadioButtonModule } from 'primeng/radiobutton';
import { InputSwitchModule } from 'primeng/inputswitch';
import { RippleModule } from 'primeng/ripple';
import { AppMenuComponent } from './app.menu.component';
import { AppMenuitemComponent } from './app.menuitem.component';
import { RouterModule } from '@angular/router';
import { AppTopBarComponent } from './app.topbar.component';
import { AppFooterComponent } from './app.footer.component';
import { AppConfigModule } from './config/config.module';
import { AppSidebarComponent } from "./app.sidebar.component";
import { AppLayoutComponent } from "./app.layout.component";
@NgModule({
declarations: [
],
imports: [
BrowserModule,
FormsModule,
HttpClientModule,
BrowserAnimationsModule,
InputTextModule,
SidebarModule,
BadgeModule,
RadioButtonModule,
InputSwitchModule,
RippleModule,
RouterModule,
AppConfigModule,
AppMenuitemComponent,
AppTopBarComponent,
AppFooterComponent,
AppMenuComponent,
AppSidebarComponent,
AppLayoutComponent
],
exports: [AppLayoutComponent]
})
export class AppLayoutModule { }
@@ -0,0 +1,13 @@
<ul class="layout-menu">
<ng-container *ngFor="let item of home; let i = index;">
<li app-menuitem *ngIf="!item.separator" [item]="item" [index]="i" [root]="true"></li>
<li *ngIf="item.separator" class="menu-separator"></li>
</ng-container>
</ul>
<ul class="layout-menu">
<ng-container *ngFor="let item of libraryMenu(); let i = index;">
<li app-menuitem *ngIf="!item.separator" [item]="item" [index]="i" [root]="true"></li>
<li *ngIf="item.separator" class="menu-separator"></li>
</ng-container>
</ul>
@@ -0,0 +1,47 @@
import {Component, computed, OnInit} from '@angular/core';
import {AppMenuitemComponent} from './app.menuitem.component';
import {NgForOf, NgIf} from '@angular/common';
import {MenuModule} from 'primeng/menu';
import {LibraryService} from '../book/service/library.service';
import {Library} from '../book/model/library.model';
@Component({
selector: 'app-menu',
imports: [AppMenuitemComponent, NgIf, NgForOf, MenuModule],
templateUrl: './app.menu.component.html',
})
export class AppMenuComponent implements OnInit {
home: any[] = [];
libraries: any;
libraryMenu = computed(() => [
{
label: 'Library',
separator: false,
items: this.libraries().map((lib: Library) => ({
label: lib.name,
icon: 'pi pi-fw pi-home',
routerLink: [`/library/${lib.id}/books`]
})),
},
]);
constructor(private libraryService: LibraryService) {
this.libraries = this.libraryService.libraries;
}
ngOnInit() {
this.populateHome();
}
private populateHome() {
this.home = [
{
label: 'Home',
items: [
{label: 'Dashboard', icon: 'pi pi-fw pi-home', routerLink: ['/']},
],
},
];
}
}
@@ -0,0 +1,23 @@
import { Injectable } from '@angular/core';
import { Subject } from 'rxjs';
import { MenuChangeEvent } from './api/menuchangeevent';
@Injectable({
providedIn: 'root'
})
export class MenuService {
private menuSource = new Subject<MenuChangeEvent>();
private resetSource = new Subject();
menuSource$ = this.menuSource.asObservable();
resetSource$ = this.resetSource.asObservable();
onMenuStateChange(event: MenuChangeEvent) {
this.menuSource.next(event);
}
reset() {
this.resetSource.next(true);
}
}
@@ -0,0 +1,163 @@
import { ChangeDetectorRef, Component, Host, HostBinding, Input, OnDestroy, OnInit } from '@angular/core';
import {NavigationEnd, Router, RouterLink, RouterLinkActive} from '@angular/router';
import { animate, state, style, transition, trigger } from '@angular/animations';
import { Subscription } from 'rxjs';
import { filter } from 'rxjs/operators';
import { MenuService } from './app.menu.service';
import { LayoutService } from './service/app.layout.service';
import {NgClass, NgForOf, NgIf} from '@angular/common';
import {Ripple} from 'primeng/ripple';
@Component({
// eslint-disable-next-line @angular-eslint/component-selector
selector: '[app-menuitem]',
template: `
<ng-container>
<div *ngIf="root && item.visible !== false" class="layout-menuitem-root-text">{{ item.label }}</div>
<a *ngIf="(!item.routerLink || item.items) && item.visible !== false" [attr.href]="item.url"
(click)="itemClick($event)"
[ngClass]="item.class" [attr.target]="item.target" tabindex="0" pRipple>
<i [ngClass]="item.icon" class="layout-menuitem-icon"></i>
<span class="layout-menuitem-text">{{ item.label }}</span>
<i class="pi pi-fw pi-angle-down layout-submenu-toggler" *ngIf="item.items"></i>
</a>
<a *ngIf="(item.routerLink && !item.items) && item.visible !== false" (click)="itemClick($event)"
[ngClass]="item.class"
[routerLink]="item.routerLink" routerLinkActive="active-route"
[routerLinkActiveOptions]="item.routerLinkActiveOptions||{ paths: 'exact', queryParams: 'ignored', matrixParams: 'ignored', fragment: 'ignored' }"
[fragment]="item.fragment" [queryParamsHandling]="item.queryParamsHandling"
[preserveFragment]="item.preserveFragment"
[skipLocationChange]="item.skipLocationChange" [replaceUrl]="item.replaceUrl" [state]="item.state"
[queryParams]="item.queryParams"
[attr.target]="item.target" tabindex="0" pRipple>
<i [ngClass]="item.icon" class="layout-menuitem-icon"></i>
<span class="layout-menuitem-text">{{ item.label }}</span>
<i class="pi pi-fw pi-angle-down layout-submenu-toggler" *ngIf="item.items"></i>
</a>
<ul *ngIf="item.items && item.visible !== false" [@children]="submenuAnimation">
<ng-template ngFor let-child let-i="index" [ngForOf]="item.items">
<li app-menuitem [item]="child" [index]="i" [parentKey]="key" [class]="child.badgeClass"></li>
</ng-template>
</ul>
</ng-container>
`,
imports: [
RouterLink,
RouterLinkActive,
NgClass,
NgForOf,
Ripple,
NgIf
],
animations: [
trigger('children', [
state('collapsed', style({
height: '0'
})),
state('expanded', style({
height: '*'
})),
transition('collapsed <=> expanded', animate('400ms cubic-bezier(0.86, 0, 0.07, 1)'))
])
]
})
export class AppMenuitemComponent implements OnInit, OnDestroy {
@Input() item: any;
@Input() index!: number;
@Input() @HostBinding('class.layout-root-menuitem') root!: boolean;
@Input() parentKey!: string;
active = false;
menuSourceSubscription: Subscription;
menuResetSubscription: Subscription;
key: string = "";
constructor(public layoutService: LayoutService, private cd: ChangeDetectorRef, public router: Router, private menuService: MenuService) {
this.menuSourceSubscription = this.menuService.menuSource$.subscribe(value => {
Promise.resolve(null).then(() => {
if (value.routeEvent) {
this.active = (value.key === this.key || value.key.startsWith(this.key + '-')) ? true : false;
}
else {
if (value.key !== this.key && !value.key.startsWith(this.key + '-')) {
this.active = false;
}
}
});
});
this.menuResetSubscription = this.menuService.resetSource$.subscribe(() => {
this.active = false;
});
this.router.events.pipe(filter(event => event instanceof NavigationEnd))
.subscribe(params => {
if (this.item.routerLink) {
this.updateActiveStateFromRoute();
}
});
}
ngOnInit() {
this.key = this.parentKey ? this.parentKey + '-' + this.index : String(this.index);
if (this.item.routerLink) {
this.updateActiveStateFromRoute();
}
}
updateActiveStateFromRoute() {
let activeRoute = this.router.isActive(this.item.routerLink[0], { paths: 'exact', queryParams: 'ignored', matrixParams: 'ignored', fragment: 'ignored' });
if (activeRoute) {
this.menuService.onMenuStateChange({ key: this.key, routeEvent: true });
}
}
itemClick(event: Event) {
// avoid processing disabled items
if (this.item.disabled) {
event.preventDefault();
return;
}
// execute command
if (this.item.command) {
this.item.command({ originalEvent: event, item: this.item });
}
// toggle active state
if (this.item.items) {
this.active = !this.active;
}
this.menuService.onMenuStateChange({ key: this.key });
}
get submenuAnimation() {
return this.root ? 'expanded' : (this.active ? 'expanded' : 'collapsed');
}
@HostBinding('class.active-menuitem')
get activeClass() {
return this.active && !this.root;
}
ngOnDestroy() {
if (this.menuSourceSubscription) {
this.menuSourceSubscription.unsubscribe();
}
if (this.menuResetSubscription) {
this.menuResetSubscription.unsubscribe();
}
}
}
@@ -0,0 +1 @@
<app-menu></app-menu>
@@ -0,0 +1,3 @@
.layout-sidebar-custom {
width: 250px !important;
}
@@ -0,0 +1,15 @@
import { Component, ElementRef } from '@angular/core';
import { LayoutService } from "./service/app.layout.service";
import {AppMenuComponent} from './app.menu.component';
@Component({
selector: 'app-sidebar',
imports: [
AppMenuComponent
],
templateUrl: './app.sidebar.component.html'
})
export class AppSidebarComponent {
constructor(public layoutService: LayoutService, public el: ElementRef) { }
}
@@ -0,0 +1,36 @@
<div class="layout-topbar">
<a class="layout-topbar-logo" routerLink="">
<img src="assets/layout/images/{{layoutService.config().colorScheme === 'light' ? 'logo-dark' : 'logo-white'}}.svg"
alt="logo">
<span>BookLore</span>
</a>
<button #menubutton class="p-link layout-menu-button layout-topbar-button" (click)="layoutService.onMenuToggle()">
<i class="pi pi-bars"></i>
</button>
<app-search></app-search>
<button #topbarmenubutton class="p-link layout-topbar-menu-button layout-topbar-button"
(click)="layoutService.showProfileSidebar()">
<i class="pi pi-ellipsis-v"></i>
</button>
<div #topbarmenu class="layout-topbar-menu">
<button
class="p-link layout-menu-button layout-topbar-button"
(click)="openLibraryCreatorDialog()"
pTooltip="Create New Library"
tooltipPosition="top">
<i class="pi pi-plus-circle"></i>
</button>
<button class="p-link layout-topbar-button">
<i class="pi pi-user"></i>
<span>Profile</span>
</button>
<button class="p-link layout-topbar-button" [routerLink]="'/documentation'">
<i class="pi pi-cog"></i>
<span>Settings</span>
</button>
</div>
</div>
@@ -0,0 +1,48 @@
import {Component, ElementRef, OnDestroy, ViewChild,} from '@angular/core';
import {MenuItem} from 'primeng/api';
import {LayoutService} from './service/app.layout.service';
import {RouterLink} from '@angular/router';
import {DialogService as PrimeDialogService, DynamicDialogRef} from 'primeng/dynamicdialog';
import {LibraryCreatorComponent} from '../book/component/library-creator/library-creator.component';
import {TooltipModule} from 'primeng/tooltip';
import {FormsModule} from '@angular/forms';
import {InputTextModule} from 'primeng/inputtext';
import {SearchComponent} from '../book/component/search/search.component';
@Component({
selector: 'app-topbar',
imports: [
RouterLink,
TooltipModule,
FormsModule,
InputTextModule,
SearchComponent,
],
templateUrl: './app.topbar.component.html',
})
export class AppTopBarComponent implements OnDestroy {
items!: MenuItem[];
ref: DynamicDialogRef | undefined;
@ViewChild('menubutton') menuButton!: ElementRef;
@ViewChild('topbarmenubutton') topbarMenuButton!: ElementRef;
@ViewChild('topbarmenu') menu!: ElementRef;
constructor(public layoutService: LayoutService, public dialogService: PrimeDialogService) {
}
openLibraryCreatorDialog(): void {
this.ref = this.dialogService.open(LibraryCreatorComponent, {
header: "Create New Library",
modal: false,
width: '50%',
height: '50%',
});
}
ngOnDestroy(): void {
if (this.ref) {
this.ref.close();
}
}
}
@@ -0,0 +1,242 @@
<button class="layout-config-button p-link" type="button" (click)="onConfigButtonClick()">
<i class="pi pi-cog"></i>
</button>
<p-sidebar [(visible)]="visible" position="right" [transitionOptions]="'.3s cubic-bezier(0, 0, 0.2, 1)'" styleClass="layout-config-sidebar w-20rem">
<h5>Scale</h5>
<div class="flex align-items-center">
<button icon="pi pi-minus" type="button" pButton (click)="decrementScale()" class="p-button-text p-button-rounded w-2rem h-2rem mr-2" [disabled]="scale === scales[0]"></button>
<div class="flex gap-2 align-items-center">
<i class="pi pi-circle-fill text-300" *ngFor="let s of scales" [ngClass]="{'text-primary-500': s === scale}"></i>
</div>
<button icon="pi pi-plus" type="button" pButton (click)="incrementScale()" class="p-button-text p-button-rounded w-2rem h-2rem ml-2" [disabled]="scale === scales[scales.length - 1]"></button>
</div>
<ng-container *ngIf="!minimal">
<h5>Menu Type</h5>
<div class="field-radiobutton">
<p-radioButton name="menuMode" value="static" [(ngModel)]="menuMode" inputId="mode1"></p-radioButton>
<label for="mode1">Static</label>
</div>
<div class="field-radiobutton">
<p-radioButton name="menuMode" value="overlay" [(ngModel)]="menuMode" inputId="mode2"></p-radioButton>
<label for="mode2">Overlay</label>
</div>
</ng-container>
<ng-container *ngIf="!minimal">
<h5>Input Style</h5>
<div class="flex">
<div class="field-radiobutton flex-1">
<p-radioButton name="inputStyle" value="outlined" [(ngModel)]="inputStyle" inputId="outlined_input"></p-radioButton>
<label for="outlined_input">Outlined</label>
</div>
<div class="field-radiobutton flex-1">
<p-radioButton name="inputStyle" value="filled" [(ngModel)]="inputStyle" inputId="filled_input"></p-radioButton>
<label for="filled_input">Filled</label>
</div>
</div>
<h5>Ripple Effect</h5>
<p-inputSwitch [(ngModel)]="ripple"></p-inputSwitch>
</ng-container>
<h5>Bootstrap</h5>
<div class="grid">
<div class="col-3">
<button class="p-link w-2rem h-2rem" (click)="changeTheme('bootstrap4-light-blue', 'light')">
<img src="assets/layout/images/themes/bootstrap4-light-blue.svg" class="w-2rem h-2rem" alt="Bootstrap Light Blue">
</button>
</div>
<div class="col-3">
<button class="p-link w-2rem h-2rem" (click)="changeTheme('bootstrap4-light-purple', 'light')">
<img src="assets/layout/images/themes/bootstrap4-light-purple.svg" class="w-2rem h-2rem" alt="Bootstrap Light Purple">
</button>
</div>
<div class="col-3">
<button class="p-link w-2rem h-2rem" (click)="changeTheme('bootstrap4-dark-blue', 'dark')">
<img src="assets/layout/images/themes/bootstrap4-dark-blue.svg" class="w-2rem h-2rem" alt="Bootstrap Dark Blue">
</button>
</div>
<div class="col-3">
<button class="p-link w-2rem h-2rem" (click)="changeTheme('bootstrap4-dark-purple', 'dark')">
<img src="assets/layout/images/themes/bootstrap4-dark-purple.svg" class="w-2rem h-2rem" alt="Bootstrap Dark Purple">
</button>
</div>
</div>
<h5>Material Design</h5>
<div class="grid">
<div class="col-3">
<button class="p-link w-2rem h-2rem" (click)="changeTheme('md-light-indigo', 'light')">
<img src="assets/layout/images/themes/md-light-indigo.svg" class="w-2rem h-2rem" alt="Material Light Indigo">
</button>
</div>
<div class="col-3">
<button class="p-link w-2rem h-2rem" (click)="changeTheme('md-light-deeppurple', 'light')">
<img src="assets/layout/images/themes/md-light-deeppurple.svg" class="w-2rem h-2rem" alt="Material Light DeepPurple">
</button>
</div>
<div class="col-3">
<button class="p-link w-2rem h-2rem" (click)="changeTheme('md-dark-indigo', 'dark')">
<img src="assets/layout/images/themes/md-dark-indigo.svg" class="w-2rem h-2rem" alt="Material Dark Indigo">
</button>
</div>
<div class="col-3">
<button class="p-link w-2rem h-2rem" (click)="changeTheme('md-dark-deeppurple', 'dark')">
<img src="assets/layout/images/themes/md-dark-deeppurple.svg" class="w-2rem h-2rem" alt="Material Dark DeepPurple">
</button>
</div>
</div>
<h5>Material Design Compact</h5>
<div class="grid">
<div class="col-3">
<button class="p-link w-2rem h-2rem" (click)="changeTheme('mdc-light-indigo', 'light')">
<img src="assets/layout/images/themes/md-light-indigo.svg" class="w-2rem h-2rem" alt="Material Light Indigo">
</button>
</div>
<div class="col-3">
<button class="p-link w-2rem h-2rem" (click)="changeTheme('mdc-light-deeppurple', 'light')">
<img src="assets/layout/images/themes/md-light-deeppurple.svg" class="w-2rem h-2rem" alt="Material Light Deep Purple">
</button>
</div>
<div class="col-3">
<button class="p-link w-2rem h-2rem" (click)="changeTheme('mdc-dark-indigo', 'dark')">
<img src="assets/layout/images/themes/md-dark-indigo.svg" class="w-2rem h-2rem" alt="Material Dark Indigo">
</button>
</div>
<div class="col-3">
<button class="p-link w-2rem h-2rem" (click)="changeTheme('mdc-dark-deeppurple', 'dark')">
<img src="assets/layout/images/themes/md-dark-deeppurple.svg" class="w-2rem h-2rem" alt="Material Dark Deep Purple">
</button>
</div>
</div>
<h5>Tailwind</h5>
<div class="grid">
<div class="col-3">
<button class="p-link w-2rem h-2rem" (click)="changeTheme('tailwind-light', 'light')">
<img src="assets/layout/images/themes/tailwind-light.png" class="w-2rem h-2rem" alt="Tailwind Light">
</button>
</div>
</div>
<h5>Fluent UI</h5>
<div class="grid">
<div class="col-3">
<button class="p-link w-2rem h-2rem" (click)="changeTheme('fluent-light', 'light')">
<img src="assets/layout/images/themes/fluent-light.png" class="w-2rem h-2rem" alt="Fluent Light">
</button>
</div>
</div>
<h5>PrimeOne Design - 2022</h5>
<div class="grid">
<div class="col-3">
<button class="p-link w-2rem h-2rem" (click)="changeTheme('lara-light-indigo', 'light')">
<img src="assets/layout/images/themes/lara-light-indigo.png" class="w-2rem h-2rem" alt="Lara Light Indigo">
</button>
</div>
<div class="col-3">
<button class="p-link w-2rem h-2rem" (click)="changeTheme('lara-light-blue', 'light')">
<img src="assets/layout/images/themes/lara-light-blue.png" class="w-2rem h-2rem" alt="Lara Light Blue">
</button>
</div>
<div class="col-3">
<button class="p-link w-2rem h-2rem" (click)="changeTheme('lara-light-purple', 'light')">
<img src="assets/layout/images/themes/lara-light-purple.png" class="w-2rem h-2rem" alt="Lara Light Purple">
</button>
</div>
<div class="col-3">
<button class="p-link w-2rem h-2rem" (click)="changeTheme('lara-light-teal', 'light')">
<img src="assets/layout/images/themes/lara-light-teal.png" class="w-2rem h-2rem" alt="Lara Light Teal">
</button>
</div>
<div class="col-3">
<button class="p-link w-2rem h-2rem" (click)="changeTheme('lara-dark-indigo', 'dark')">
<img src="assets/layout/images/themes/lara-dark-indigo.png" class="w-2rem h-2rem" alt="Lara Dark Indigo">
</button>
</div>
<div class="col-3">
<button class="p-link w-2rem h-2rem" (click)="changeTheme('lara-dark-blue', 'dark')">
<img src="assets/layout/images/themes/lara-dark-blue.png" class="w-2rem h-2rem" alt="Lara Dark Blue">
</button>
</div>
<div class="col-3">
<button class="p-link w-2rem h-2rem" (click)="changeTheme('lara-dark-purple', 'dark')">
<img src="assets/layout/images/themes/lara-dark-purple.png" class="w-2rem h-2rem" alt="Lara Dark Purple">
</button>
</div>
<div class="col-3">
<button class="p-link w-2rem h-2rem" (click)="changeTheme('lara-dark-teal', 'dark')">
<img src="assets/layout/images/themes/lara-dark-teal.png" class="w-2rem h-2rem" alt="Lara Dark Teal">
</button>
</div>
</div>
<h5>PrimeOne Design - 2021</h5>
<div class="grid">
<div class="col-3">
<button class="p-link w-2rem h-2rem" (click)="changeTheme('saga-blue', 'light')">
<img src="assets/layout/images/themes/saga-blue.png" class="w-2rem h-2rem" alt="Saga Blue">
</button>
</div>
<div class="col-3">
<button class="p-link w-2rem h-2rem" (click)="changeTheme('saga-green', 'light')">
<img src="assets/layout/images/themes/saga-green.png" class="w-2rem h-2rem" alt="Saga Green">
</button>
</div>
<div class="col-3">
<button class="p-link w-2rem h-2rem" (click)="changeTheme('saga-orange', 'light')">
<img src="assets/layout/images/themes/saga-orange.png" class="w-2rem h-2rem" alt="Saga Orange">
</button>
</div>
<div class="col-3">
<button class="p-link w-2rem h-2rem" (click)="changeTheme('saga-purple', 'light')">
<img src="assets/layout/images/themes/saga-purple.png" class="w-2rem h-2rem" alt="Saga Purple">
</button>
</div>
<div class="col-3">
<button class="p-link w-2rem h-2rem" (click)="changeTheme('vela-blue', 'dark')">
<img src="assets/layout/images/themes/vela-blue.png" class="w-2rem h-2rem" alt="Vela Blue">
</button>
</div>
<div class="col-3">
<button class="p-link w-2rem h-2rem" (click)="changeTheme('vela-green', 'dark')">
<img src="assets/layout/images/themes/vela-green.png" class="w-2rem h-2rem" alt="Vela Green">
</button>
</div>
<div class="col-3">
<button class="p-link w-2rem h-2rem" (click)="changeTheme('vela-orange', 'dark')">
<img src="assets/layout/images/themes/vela-orange.png" class="w-2rem h-2rem" alt="Vela Orange">
</button>
</div>
<div class="col-3">
<button class="p-link w-2rem h-2rem" (click)="changeTheme('vela-purple', 'dark')">
<img src="assets/layout/images/themes/vela-purple.png" class="w-2rem h-2rem" alt="Vela Purple">
</button>
</div>
<div class="col-3">
<button class="p-link w-2rem h-2rem" (click)="changeTheme('arya-blue', 'dark')">
<img src="assets/layout/images/themes/arya-blue.png" class="w-2rem h-2rem" alt="Arya Blue">
</button>
</div>
<div class="col-3">
<button class="p-link w-2rem h-2rem" (click)="changeTheme('arya-green', 'dark')">
<img src="assets/layout/images/themes/arya-green.png" class="w-2rem h-2rem" alt="Arya Green">
</button>
</div>
<div class="col-3">
<button class="p-link w-2rem h-2rem" (click)="changeTheme('arya-orange', 'dark')">
<img src="assets/layout/images/themes/arya-orange.png" class="w-2rem h-2rem" alt="Arya Orange">
</button>
</div>
<div class="col-3">
<button class="p-link w-2rem h-2rem" (click)="changeTheme('arya-purple', 'dark')">
<img src="assets/layout/images/themes/arya-purple.png" class="w-2rem h-2rem" alt="Arya Purple">
</button>
</div>
</div>
</p-sidebar>
@@ -0,0 +1,115 @@
import { Component, Input } from '@angular/core';
import { LayoutService } from '../service/app.layout.service';
import { MenuService } from '../app.menu.service';
import {RadioButtonModule} from 'primeng/radiobutton';
import {FormsModule} from '@angular/forms';
import {InputSwitchModule} from 'primeng/inputswitch';
import {NgClass, NgForOf, NgIf, NgOptimizedImage} from '@angular/common';
import {SidebarModule} from 'primeng/sidebar';
import {ButtonDirective} from 'primeng/button';
@Component({
selector: 'app-config',
templateUrl: './app.config.component.html',
imports: [
RadioButtonModule,
FormsModule,
InputSwitchModule,
NgIf,
SidebarModule,
NgClass,
ButtonDirective,
NgForOf
]
})
export class AppConfigComponent {
@Input() minimal: boolean = false;
scales: number[] = [12, 13, 14, 15, 16];
constructor(
public layoutService: LayoutService,
public menuService: MenuService
) {}
get visible(): boolean {
return this.layoutService.state.configSidebarVisible;
}
set visible(_val: boolean) {
this.layoutService.state.configSidebarVisible = _val;
}
get scale(): number {
return this.layoutService.config().scale;
}
set scale(_val: number) {
this.layoutService.config.update((config) => ({
...config,
scale: _val,
}));
}
get menuMode(): string {
return this.layoutService.config().menuMode;
}
set menuMode(_val: string) {
this.layoutService.config.update((config) => ({
...config,
menuMode: _val,
}));
}
get inputStyle(): string {
return this.layoutService.config().inputStyle;
}
set inputStyle(_val: string) {
this.layoutService.config().inputStyle = _val;
}
get ripple(): boolean {
return this.layoutService.config().ripple;
}
set ripple(_val: boolean) {
this.layoutService.config.update((config) => ({
...config,
ripple: _val,
}));
}
set theme(val: string) {
this.layoutService.config.update((config) => ({
...config,
theme: val,
}));
}
get theme(): string {
return this.layoutService.config().theme;
}
set colorScheme(val: string) {
this.layoutService.config.update((config) => ({
...config,
colorScheme: val,
}));
}
get colorScheme(): string {
return this.layoutService.config().colorScheme;
}
onConfigButtonClick() {
this.layoutService.showConfigSidebar();
}
changeTheme(theme: string, colorScheme: string) {
this.theme = theme;
this.colorScheme = colorScheme;
}
decrementScale() {
this.scale--;
}
incrementScale() {
this.scale++;
}
}
@@ -0,0 +1,27 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { SidebarModule } from 'primeng/sidebar';
import { RadioButtonModule } from 'primeng/radiobutton';
import { ButtonModule } from 'primeng/button';
import { InputSwitchModule } from 'primeng/inputswitch';
import { AppConfigComponent } from './app.config.component';
@NgModule({
imports: [
CommonModule,
FormsModule,
SidebarModule,
RadioButtonModule,
ButtonModule,
InputSwitchModule,
AppConfigComponent
],
declarations: [
],
exports: [
AppConfigComponent
]
})
export class AppConfigModule { }
@@ -0,0 +1,159 @@
import { Injectable, effect, signal } from '@angular/core';
import { Subject } from 'rxjs';
export interface AppConfig {
inputStyle: string;
colorScheme: string;
theme: string;
ripple: boolean;
menuMode: string;
scale: number;
}
interface LayoutState {
staticMenuDesktopInactive: boolean;
overlayMenuActive: boolean;
profileSidebarVisible: boolean;
configSidebarVisible: boolean;
staticMenuMobileActive: boolean;
menuHoverActive: boolean;
}
@Injectable({
providedIn: 'root',
})
export class LayoutService {
_config: AppConfig = {
ripple: false,
inputStyle: 'outlined',
menuMode: 'static',
colorScheme: 'light',
theme: 'lara-light-indigo',
scale: 14,
};
config = signal<AppConfig>(this._config);
state: LayoutState = {
staticMenuDesktopInactive: false,
overlayMenuActive: false,
profileSidebarVisible: false,
configSidebarVisible: false,
staticMenuMobileActive: false,
menuHoverActive: false,
};
private configUpdate = new Subject<AppConfig>();
private overlayOpen = new Subject<any>();
configUpdate$ = this.configUpdate.asObservable();
overlayOpen$ = this.overlayOpen.asObservable();
constructor() {
effect(() => {
const config = this.config();
if (this.updateStyle(config)) {
this.changeTheme();
}
this.changeScale(config.scale);
this.onConfigUpdate();
});
}
updateStyle(config: AppConfig) {
return (
config.theme !== this._config.theme ||
config.colorScheme !== this._config.colorScheme
);
}
onMenuToggle() {
if (this.isOverlay()) {
this.state.overlayMenuActive = !this.state.overlayMenuActive;
if (this.state.overlayMenuActive) {
this.overlayOpen.next(null);
}
}
if (this.isDesktop()) {
this.state.staticMenuDesktopInactive =
!this.state.staticMenuDesktopInactive;
} else {
this.state.staticMenuMobileActive =
!this.state.staticMenuMobileActive;
if (this.state.staticMenuMobileActive) {
this.overlayOpen.next(null);
}
}
}
showProfileSidebar() {
this.state.profileSidebarVisible = !this.state.profileSidebarVisible;
if (this.state.profileSidebarVisible) {
this.overlayOpen.next(null);
}
}
showConfigSidebar() {
this.state.configSidebarVisible = true;
}
isOverlay() {
return this.config().menuMode === 'overlay';
}
isDesktop() {
return window.innerWidth > 991;
}
isMobile() {
return !this.isDesktop();
}
onConfigUpdate() {
this._config = { ...this.config() };
this.configUpdate.next(this.config());
}
changeTheme() {
const config = this.config();
const themeLink = <HTMLLinkElement>document.getElementById('theme-css');
const themeLinkHref = themeLink.getAttribute('href')!;
const newHref = themeLinkHref
.split('/')
.map((el) =>
el == this._config.theme
? (el = config.theme)
: el == `theme-${this._config.colorScheme}`
? (el = `theme-${config.colorScheme}`)
: el
)
.join('/');
this.replaceThemeLink(newHref);
}
replaceThemeLink(href: string) {
const id = 'theme-css';
let themeLink = <HTMLLinkElement>document.getElementById(id);
const cloneLinkElement = <HTMLLinkElement>themeLink.cloneNode(true);
cloneLinkElement.setAttribute('href', href);
cloneLinkElement.setAttribute('id', id + '-clone');
themeLink.parentNode!.insertBefore(
cloneLinkElement,
themeLink.nextSibling
);
cloneLinkElement.addEventListener('load', () => {
themeLink.remove();
cloneLinkElement.setAttribute('id', id);
});
}
changeScale(value: number) {
document.documentElement.style.fontSize = `${value}px`;
}
}