WIP: App Settings
This commit is contained in:
@@ -4,6 +4,7 @@ import {BookBrowserComponent} from './book/components/book-browser/book-browser.
|
||||
import {MainDashboardComponent} from './dashboard/components/main-dashboard/main-dashboard.component';
|
||||
import {AppLayoutComponent} from './layout/component/layout-main/app.layout.component';
|
||||
import {EpubViewerComponent} from './epub-viewer/component/epub-viewer.component';
|
||||
import {SettingsComponent} from './core/component/settings/settings.component';
|
||||
|
||||
export const routes: Routes = [
|
||||
{
|
||||
@@ -15,6 +16,9 @@ export const routes: Routes = [
|
||||
{
|
||||
path: 'all-books', component: BookBrowserComponent,
|
||||
},
|
||||
{
|
||||
path: 'settings', component: SettingsComponent,
|
||||
},
|
||||
{
|
||||
path: 'library/:libraryId/books', component: BookBrowserComponent,
|
||||
},
|
||||
|
||||
@@ -77,7 +77,7 @@ export class BookBrowserComponent implements OnInit {
|
||||
EntityType = EntityType;
|
||||
|
||||
stateOptions: any[] = [{label: 'Grid', value: 'grid'}, {label: 'Table', value: 'table'}];
|
||||
value: string = 'table';
|
||||
value: string = 'grid';
|
||||
|
||||
@ViewChild(BookTableComponent) bookTableComponent!: BookTableComponent;
|
||||
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
import {Component, Input} from '@angular/core';
|
||||
import {LogNotification} from '../shared/websocket/model/log-notification.model';
|
||||
import {EventService} from '../shared/websocket/event.service';
|
||||
import {LogNotification} from '../../../shared/websocket/model/log-notification.model';
|
||||
import {EventService} from '../../../shared/websocket/event.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-live-notification-box',
|
||||
@@ -0,0 +1,83 @@
|
||||
<p class="text-3xl font-semibold">Preferences</p>
|
||||
<p-divider></p-divider>
|
||||
|
||||
<p class="text-xl font-medium pb-4 pt-6">PDF Reader Settings</p>
|
||||
|
||||
<div class="grid grid-cols-[auto,1fr] pl-6 gap-y-4 gap-x-4 items-center">
|
||||
|
||||
<p class="text-lg font-medium py-1">Page Spread:</p>
|
||||
<div class="flex gap-4 justify-start">
|
||||
<div *ngFor="let spread of spreads" class="flex items-center gap-2">
|
||||
<p-radiobutton
|
||||
[inputId]="spread.key"
|
||||
name="spread"
|
||||
[value]="spread.key"
|
||||
[(ngModel)]="selectedSpread"
|
||||
(ngModelChange)="onSpreadChange()">
|
||||
</p-radiobutton>
|
||||
<label [for]="spread.key">{{ spread.name }}</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p class="text-lg font-medium py-1">Page Zoom:</p>
|
||||
<div class="flex gap-4 justify-start">
|
||||
<div *ngFor="let zoom of zooms" class="flex items-center gap-2">
|
||||
<p-radiobutton
|
||||
[inputId]="zoom.key"
|
||||
name="zoom"
|
||||
[value]="zoom.key"
|
||||
[(ngModel)]="selectedZoom"
|
||||
(ngModelChange)="onZoomChange()">
|
||||
</p-radiobutton>
|
||||
<label [for]="zoom.key">{{ zoom.name }}</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p class="text-lg font-medium py-1">Show Sidebar:</p>
|
||||
<div class="flex justify-start">
|
||||
<p-toggleswitch
|
||||
[(ngModel)]="showSidebar"
|
||||
(ngModelChange)="onSidebarChange()">
|
||||
</p-toggleswitch>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p-divider></p-divider>
|
||||
|
||||
<p class="text-xl font-medium pb-4 pt-4">ePUB Reader Settings</p>
|
||||
|
||||
<div class="grid grid-cols-[auto,1fr] pl-6 gap-y-4 gap-x-4 items-center">
|
||||
|
||||
<p class="text-lg font-medium">Theme:</p>
|
||||
<div class="flex gap-4 justify-start">
|
||||
<p-select
|
||||
[options]="themes"
|
||||
[(ngModel)]="selectedTheme"
|
||||
optionLabel="name"
|
||||
optionValue="key"
|
||||
placeholder="Select a Theme"
|
||||
class="w-full md:w-56"
|
||||
(ngModelChange)="onThemeChange()">
|
||||
</p-select>
|
||||
</div>
|
||||
|
||||
<p class="text-lg font-medium">Font:</p>
|
||||
<div class="flex gap-4 justify-start">
|
||||
<p-select
|
||||
[options]="fonts"
|
||||
[(ngModel)]="selectedFont"
|
||||
optionLabel="name"
|
||||
optionValue="key"
|
||||
placeholder="Select a Font"
|
||||
class="w-full md:w-56"
|
||||
(ngModelChange)="onFontChange()">
|
||||
</p-select>
|
||||
</div>
|
||||
|
||||
<p class="text-lg font-medium py-1">Font Size:</p>
|
||||
<div class="flex gap-4 justify-start items-center">
|
||||
<p-button icon="pi pi-minus" rounded="true" (click)="decreaseFontSize()"></p-button>
|
||||
<p>{{ fontSize }}%</p>
|
||||
<p-button icon="pi pi-plus" rounded="true" (click)="increaseFontSize()"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,132 @@
|
||||
import {Component, OnInit} from '@angular/core';
|
||||
import {AppSettingsService} from '../../service/app-settings.service';
|
||||
import {Observable} from 'rxjs';
|
||||
import {AppSettings} from '../../model/app-settings.model';
|
||||
import {Select} from 'primeng/select';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {NgForOf} from '@angular/common';
|
||||
import {ToggleSwitch} from 'primeng/toggleswitch';
|
||||
import {RadioButton} from 'primeng/radiobutton';
|
||||
import {Divider} from 'primeng/divider';
|
||||
import {Button} from 'primeng/button';
|
||||
|
||||
@Component({
|
||||
selector: 'app-settings',
|
||||
templateUrl: './settings.component.html',
|
||||
imports: [
|
||||
Select,
|
||||
FormsModule,
|
||||
NgForOf,
|
||||
ToggleSwitch,
|
||||
RadioButton,
|
||||
Divider,
|
||||
Button
|
||||
],
|
||||
styleUrls: ['./settings.component.scss']
|
||||
})
|
||||
export class SettingsComponent implements OnInit {
|
||||
spreads = [
|
||||
{name: 'Even Spread', key: 'even_spread'},
|
||||
{name: 'Odd Spread', key: 'odd_spread'},
|
||||
{name: 'No Spread', key: 'no_spread'}
|
||||
];
|
||||
zooms = [
|
||||
{name: 'Auto Zoom', key: 'auto_zoom'},
|
||||
{name: 'Page Fit', key: 'page_fit'},
|
||||
{name: 'Page Width', key: 'page_width'},
|
||||
{name: 'Actual Size', key: 'actual_size'}
|
||||
];
|
||||
themes = [
|
||||
{name: 'White', key: 'white'},
|
||||
{name: 'Black', key: 'black'},
|
||||
{name: 'Grey', key: 'grey'},
|
||||
{name: 'Sepia', key: 'sepia'}
|
||||
];
|
||||
fonts = [
|
||||
{name: 'Serif', key: 'serif'},
|
||||
{name: 'Sans Serif', key: 'sans-serif'},
|
||||
{name: 'Roboto', key: 'roboto'},
|
||||
{name: 'Cursive', key: 'cursive'},
|
||||
{name: 'Monospace', key: 'monospace'}
|
||||
];
|
||||
|
||||
selectedSpread: any;
|
||||
selectedZoom: any;
|
||||
showSidebar = false;
|
||||
selectedTheme!: any;
|
||||
fontSize: number = 100;
|
||||
selectedFont: any;
|
||||
|
||||
appSettings$!: Observable<AppSettings | null>;
|
||||
|
||||
constructor(private appSettingsService: AppSettingsService) {
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.appSettings$ = this.appSettingsService.appSettings$;
|
||||
this.appSettings$.subscribe(settings => {
|
||||
if (settings) {
|
||||
this.populateSettings(settings);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
populateSettings(settings: AppSettings): void {
|
||||
if (settings.pdf) {
|
||||
const pdfSettings = settings.pdf;
|
||||
console.log(pdfSettings)
|
||||
|
||||
|
||||
this.selectedSpread = this.spreads.find(s => s.key === pdfSettings.spread)?.key;
|
||||
this.selectedZoom = this.zooms.find(z => z.key === pdfSettings.zoom)?.key;
|
||||
this.showSidebar = pdfSettings.sidebar;
|
||||
}
|
||||
|
||||
if (settings.epub) {
|
||||
const epubSettings = settings.epub;
|
||||
this.selectedTheme = this.themes.find(t => t.key === epubSettings.theme)?.key;
|
||||
|
||||
console.log(epubSettings.fontSize)
|
||||
this.fontSize = parseInt(epubSettings.fontSize, 10);
|
||||
this.selectedFont = this.fonts.find(f => f.key === epubSettings.font)?.key;
|
||||
}
|
||||
}
|
||||
|
||||
onThemeChange(): void {
|
||||
this.appSettingsService.saveAppSetting('epub', 'theme', this.selectedTheme);
|
||||
}
|
||||
|
||||
onFontChange(): void {
|
||||
this.appSettingsService.saveAppSetting('epub', 'font', this.selectedFont);
|
||||
}
|
||||
|
||||
onSpreadChange(): void {
|
||||
this.appSettingsService.saveAppSetting('pdf', 'spread', this.selectedSpread);
|
||||
}
|
||||
|
||||
onZoomChange(): void {
|
||||
this.appSettingsService.saveAppSetting('pdf', 'zoom', this.selectedZoom);
|
||||
}
|
||||
|
||||
onSidebarChange(): void {
|
||||
this.appSettingsService.saveAppSetting('pdf', 'sidebar', this.showSidebar.toString());
|
||||
}
|
||||
|
||||
onFontSizeChange(): void {
|
||||
this.appSettingsService.saveAppSetting('epub', 'fontSize', this.fontSize.toString());
|
||||
}
|
||||
|
||||
increaseFontSize(): void {
|
||||
if (this.fontSize < 250) {
|
||||
this.fontSize += 10;
|
||||
this.onFontSizeChange();
|
||||
}
|
||||
}
|
||||
|
||||
decreaseFontSize(): void {
|
||||
if (this.fontSize > 50) {
|
||||
this.fontSize -= 10;
|
||||
this.onFontSizeChange();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
export interface EpubSettings {
|
||||
theme: string;
|
||||
fontSize: string;
|
||||
font: string;
|
||||
}
|
||||
|
||||
export interface PdfSettings {
|
||||
spread: string;
|
||||
zoom: string;
|
||||
sidebar: boolean;
|
||||
}
|
||||
|
||||
export interface AppSettings {
|
||||
epub?: EpubSettings;
|
||||
pdf?: PdfSettings;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {HttpClient, HttpParams} from '@angular/common/http';
|
||||
import {BehaviorSubject} from 'rxjs';
|
||||
import {AppSettings} from '../model/app-settings.model';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class AppSettingsService {
|
||||
private apiUrl = 'http://localhost:8080/api/settings';
|
||||
|
||||
private appSettingsSubject = new BehaviorSubject<AppSettings | null>(null);
|
||||
appSettings$ = this.appSettingsSubject.asObservable();
|
||||
|
||||
constructor(private http: HttpClient) {
|
||||
this.loadAppSettings();
|
||||
}
|
||||
|
||||
loadAppSettings(): void {
|
||||
this.http.get<AppSettings>(this.apiUrl).subscribe({
|
||||
next: (settings: AppSettings) => {
|
||||
this.appSettingsSubject.next(settings);
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Error loading app settings:', error);
|
||||
this.appSettingsSubject.next(null);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
saveAppSetting(category: string, key: string, newValue: string): void {
|
||||
const params = new HttpParams()
|
||||
.set('category', category)
|
||||
.set('key', key)
|
||||
.set('newValue', newValue);
|
||||
|
||||
this.http.put(this.apiUrl, null, { params }).subscribe({
|
||||
next: () => {
|
||||
console.log('Setting saved successfully');
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Error saving setting:', error);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@
|
||||
<label for="font-type">Font Type:</label>
|
||||
<p-dropdown id="font-type" [options]="fontTypes" [(ngModel)]="selectedFontType" (onChange)="changeFontType($event)"></p-dropdown>
|
||||
<p-divider></p-divider>
|
||||
<label for="theme">Font Type:</label>
|
||||
<label for="theme">Theme:</label>
|
||||
<p-dropdown id="theme" [options]="themes" [(ngModel)]="selectedTheme" (onChange)="changeThemes($event)"></p-dropdown>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -119,8 +119,8 @@ export class EpubViewerComponent implements OnInit, OnDestroy {
|
||||
|
||||
increaseFontSize(): void {
|
||||
this.fontSize += 10;
|
||||
if (this.fontSize > 200) {
|
||||
this.fontSize = 200;
|
||||
if (this.fontSize > 300) {
|
||||
this.fontSize = 300;
|
||||
}
|
||||
this.updateFontSize();
|
||||
}
|
||||
@@ -205,7 +205,7 @@ export class EpubViewerComponent implements OnInit, OnDestroy {
|
||||
"body": {"background-color": "#000000", "color": "#f9f9f9", "font-family": "Arial, sans-serif"},
|
||||
"p": {"color": "#f9f9f9"},
|
||||
"h1, h2, h3, h4, h5, h6": {"color": "#f9f9f9"},
|
||||
"a": {"color": "#f9f9f9", "text-decoration": "underline"},
|
||||
"a": {"color": "#f9f9f9"},
|
||||
"img": {
|
||||
"-webkit-filter": "invert(1) hue-rotate(180deg)",
|
||||
"filter": "invert(1) hue-rotate(180deg)"
|
||||
@@ -218,7 +218,7 @@ export class EpubViewerComponent implements OnInit, OnDestroy {
|
||||
"body": {"background-color": "#f4ecd8", "color": "#6e4b3a", "font-family": "Georgia, serif"},
|
||||
"p": {"color": "#6e4b3a"},
|
||||
"h1, h2, h3, h4, h5, h6": {"color": "#6e4b3a"},
|
||||
"a": {"color": "#8b4513", "text-decoration": "underline"},
|
||||
"a": {"color": "#8b4513"},
|
||||
"img": {
|
||||
"-webkit-filter": "sepia(1) contrast(1.5)",
|
||||
"filter": "sepia(1) contrast(1.5)"
|
||||
@@ -231,7 +231,7 @@ export class EpubViewerComponent implements OnInit, OnDestroy {
|
||||
"body": {"background-color": "white", "color": "black", "font-family": "Arial, sans-serif"},
|
||||
"p": {"color": "black"},
|
||||
"h1, h2, h3, h4, h5, h6": {"color": "black"},
|
||||
"a": {"color": "#1e90ff", "text-decoration": "underline"},
|
||||
"a": {"color": "#1e90ff"},
|
||||
"img": {
|
||||
"-webkit-filter": "none",
|
||||
"filter": "none"
|
||||
@@ -244,7 +244,7 @@ export class EpubViewerComponent implements OnInit, OnDestroy {
|
||||
"body": {"background-color": "#404040", "color": "#d3d3d3", "font-family": "Arial, sans-serif"},
|
||||
"p": {"color": "#d3d3d3"},
|
||||
"h1, h2, h3, h4, h5, h6": {"color": "#d3d3d3"},
|
||||
"a": {"color": "#1e90ff", "text-decoration": "underline"},
|
||||
"a": {"color": "#1e90ff"},
|
||||
"img": {
|
||||
"filter": "none"
|
||||
},
|
||||
|
||||
@@ -33,6 +33,12 @@
|
||||
pTooltip="Upload book" tooltipPosition="top"></i>
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="topbar-item">
|
||||
<i class="pi pi-cog text-surface-700 dark:text-surface-100" (click)="navigateToSettings()"
|
||||
pTooltip="Upload book" tooltipPosition="top"></i>
|
||||
</a>
|
||||
</li>
|
||||
</div>
|
||||
|
||||
<p-divider layout="vertical" />
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {Component, ElementRef, OnDestroy, ViewChild} from '@angular/core';
|
||||
import {MenuItem} from 'primeng/api';
|
||||
import {LayoutService} from '../layout-main/service/app.layout.service';
|
||||
import {RouterLink} from '@angular/router';
|
||||
import {Router, RouterLink} from '@angular/router';
|
||||
import {DialogService as PrimeDialogService, DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {LibraryCreatorComponent} from '../../../book/components/library-creator/library-creator.component';
|
||||
import {TooltipModule} from 'primeng/tooltip';
|
||||
@@ -15,7 +15,7 @@ import {Button} from 'primeng/button';
|
||||
import {StyleClass} from 'primeng/styleclass';
|
||||
import {Divider} from 'primeng/divider';
|
||||
import {ThemeConfiguratorComponent} from '../theme-configurator/theme-configurator.component';
|
||||
import {LiveNotificationBoxComponent} from '../../../live-notification-box/live-notification-box.component';
|
||||
import {LiveNotificationBoxComponent} from '../../../core/component/live-notification-box/live-notification-box.component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-topbar',
|
||||
@@ -47,7 +47,8 @@ export class AppTopBarComponent implements OnDestroy {
|
||||
@ViewChild('topbarmenubutton') topbarMenuButton!: ElementRef;
|
||||
@ViewChild('topbarmenu') menu!: ElementRef;
|
||||
|
||||
constructor(public layoutService: LayoutService, public dialogService: PrimeDialogService, private eventService: EventService) {
|
||||
constructor(public layoutService: LayoutService, public dialogService: PrimeDialogService,
|
||||
private eventService: EventService, private router: Router) {
|
||||
this.eventService.eventHighlight$.subscribe(highlight => {
|
||||
this.eventHighlight = highlight;
|
||||
});
|
||||
@@ -106,4 +107,8 @@ export class AppTopBarComponent implements OnDestroy {
|
||||
}
|
||||
clearTimeout(this.eventTimeout);
|
||||
}
|
||||
|
||||
navigateToSettings() {
|
||||
this.router.navigate(['/settings']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@
|
||||
list-style-type: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
gap: 0.5rem;
|
||||
gap: 0.3rem;
|
||||
align-items: center;
|
||||
|
||||
li {
|
||||
|
||||
Reference in New Issue
Block a user