Improve Angular project structure and code organization (#1328)
This commit is contained in:
+181
@@ -0,0 +1,181 @@
|
||||
<p-confirmDialog></p-confirmDialog>
|
||||
|
||||
<div class="main-container enclosing-container">
|
||||
<div class="settings-header">
|
||||
<h2 class="settings-title">
|
||||
<i class="pi pi-tablet"></i>
|
||||
Kobo Integration Settings
|
||||
<app-external-doc-link docType="kobo"></app-external-doc-link>
|
||||
</h2>
|
||||
<p class="settings-description">
|
||||
Configure Kobo device integration to sync your library books and reading progress with your Kobo e-reader.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@if (hasKoboTokenPermission) {
|
||||
<div class="settings-content">
|
||||
<div class="preferences-section">
|
||||
<div class="section-header">
|
||||
<h3 class="section-title">
|
||||
<i class="pi pi-sync"></i>
|
||||
Sync Configuration
|
||||
</h3>
|
||||
<p class="section-description">
|
||||
Enable and configure synchronization between your Booklore library and Kobo device.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="settings-card">
|
||||
<form #koboForm="ngForm">
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">Enable Kobo Sync</label>
|
||||
<p-toggle-switch
|
||||
id="syncEnabled"
|
||||
name="syncEnabled"
|
||||
[(ngModel)]="koboSyncSettings.syncEnabled"
|
||||
(ngModelChange)="onSyncToggle()">
|
||||
</p-toggle-switch>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
Turn on synchronization to automatically sync your library books to your Kobo device.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (koboSyncSettings.syncEnabled) {
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<label class="setting-label">Kobo Sync Token</label>
|
||||
<p class="setting-description">
|
||||
Your unique sync token for authenticating with your Kobo device. Keep this secure.
|
||||
</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<div class="token-input-group">
|
||||
<input
|
||||
pInputText
|
||||
id="koboToken"
|
||||
[(ngModel)]="koboSyncSettings.token"
|
||||
[type]="showToken ? 'text' : 'password'"
|
||||
readonly
|
||||
name="koboToken"
|
||||
class="token-input"
|
||||
/>
|
||||
<p-button
|
||||
icon="pi pi-copy"
|
||||
outlined="true"
|
||||
severity="info"
|
||||
size="small"
|
||||
(onClick)="copyText(koboSyncSettings.token)">
|
||||
</p-button>
|
||||
<p-button
|
||||
[icon]="showToken ? 'pi pi-eye-slash' : 'pi pi-eye'"
|
||||
outlined="true"
|
||||
severity="info"
|
||||
size="small"
|
||||
(onClick)="toggleShowToken()">
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<label class="setting-label">Token Management</label>
|
||||
<p class="setting-description">
|
||||
Regenerate your sync token if needed. This will invalidate the current token.
|
||||
</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<p-button
|
||||
icon="pi pi-refresh"
|
||||
outlined="true"
|
||||
severity="warn"
|
||||
size="small"
|
||||
label="Regenerate Token"
|
||||
(onClick)="confirmRegenerateToken()"
|
||||
[disabled]="!credentialsSaved">
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (isAdmin) {
|
||||
<div class="preferences-section">
|
||||
<div class="section-header">
|
||||
<h3 class="section-title">
|
||||
<i class="pi pi-cog"></i>
|
||||
Administrator Settings
|
||||
</h3>
|
||||
<p class="section-description">
|
||||
Configure advanced Kobo sync settings that affect all users on this server.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="settings-card">
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">Convert to KEPUB</label>
|
||||
<p-toggle-switch
|
||||
id="convertToKepub"
|
||||
[(ngModel)]="koboSettings.convertToKepub"
|
||||
(ngModelChange)="onToggleChange()">
|
||||
</p-toggle-switch>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
<strong>Pros:</strong> KEPUB format enables enhanced Kobo features like better typography, reading stats, and faster page turns.
|
||||
<br>
|
||||
<strong>Cons:</strong> Conversion takes extra processing time and may occasionally fail for complex layouts.
|
||||
Books over the size limit below will skip conversion automatically.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">Conversion Size Limit: {{ koboSettings.conversionLimitInMb }} MB</label>
|
||||
<div class="slider-container">
|
||||
<p-slider
|
||||
id="conversionLimit"
|
||||
[(ngModel)]="koboSettings.conversionLimitInMb"
|
||||
[min]="1"
|
||||
[max]="250"
|
||||
[step]="1"
|
||||
(ngModelChange)="onSliderChange()">
|
||||
</p-slider>
|
||||
</div>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
Large files (100MB+) can cause conversion timeouts and server strain. Lower limits ensure faster syncing but may skip conversion of larger books.
|
||||
<br>
|
||||
<strong>Recommended:</strong> 50-100MB for most libraries. Very large books will sync as regular EPUB regardless of this setting.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
} @else {
|
||||
<div class="settings-content">
|
||||
<div class="access-denied-card">
|
||||
<i class="pi pi-lock"></i>
|
||||
<div class="access-denied-content">
|
||||
<h3>Access Restricted</h3>
|
||||
<p>
|
||||
Access to Kobo sync is restricted.
|
||||
<br>
|
||||
Please contact your administrator to request permission.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
+215
@@ -0,0 +1,215 @@
|
||||
.main-container {
|
||||
width: 100%;
|
||||
padding: 1rem;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.enclosing-container {
|
||||
border-color: var(--p-content-border-color);
|
||||
background: var(--p-content-background);
|
||||
}
|
||||
|
||||
.settings-header {
|
||||
margin-top: 1rem;
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.settings-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
font-size: 1.25rem;
|
||||
font-weight: 700;
|
||||
color: var(--p-text-color);
|
||||
margin: 0 0 0.75rem 0;
|
||||
|
||||
.pi {
|
||||
color: var(--p-primary-color);
|
||||
font-size: 1.25rem;
|
||||
}
|
||||
}
|
||||
|
||||
.settings-description {
|
||||
color: var(--p-text-muted-color);
|
||||
font-size: 0.875rem;
|
||||
line-height: 1.5;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.settings-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2rem;
|
||||
}
|
||||
|
||||
.preferences-section {
|
||||
@media (min-width: 768px) {
|
||||
padding: 0 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
.section-header {
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
font-size: 1.125rem;
|
||||
font-weight: 600;
|
||||
color: var(--p-text-color);
|
||||
margin: 0 0 0.5rem 0;
|
||||
|
||||
.pi {
|
||||
color: var(--p-primary-color);
|
||||
}
|
||||
}
|
||||
|
||||
.section-description {
|
||||
color: var(--p-text-muted-color);
|
||||
font-size: 0.875rem;
|
||||
line-height: 1.5;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.settings-card {
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
border-radius: 8px;
|
||||
background: var(--p-content-background);
|
||||
padding: 1.5rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1.5rem;
|
||||
}
|
||||
|
||||
.setting-item {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 2rem;
|
||||
padding: 0.25rem 0;
|
||||
|
||||
&:last-child {
|
||||
border-bottom: none;
|
||||
padding-bottom: 0;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
.setting-info {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
|
||||
.setting-label {
|
||||
display: block;
|
||||
font-weight: 600;
|
||||
color: var(--p-text-color);
|
||||
font-size: 1rem;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.setting-label-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
margin-bottom: 0.5rem;
|
||||
flex-wrap: wrap;
|
||||
|
||||
.setting-label {
|
||||
margin-bottom: 0;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.slider-container {
|
||||
flex: 1;
|
||||
min-width: 200px;
|
||||
max-width: 300px;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
min-width: 180px;
|
||||
max-width: 250px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.setting-description {
|
||||
color: var(--p-text-muted-color);
|
||||
font-size: 0.875rem;
|
||||
line-height: 1.5;
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.setting-control {
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
align-items: flex-end;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
align-items: flex-start;
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.token-input-group {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
width: 100%;
|
||||
max-width: 500px;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.token-input {
|
||||
flex: 1;
|
||||
min-width: 200px;
|
||||
}
|
||||
}
|
||||
|
||||
.slider-container {
|
||||
width: 250px;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
width: 200px;
|
||||
}
|
||||
}
|
||||
|
||||
.access-denied-card {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
padding: 1rem;
|
||||
border-radius: 8px;
|
||||
background: rgba(220, 38, 38, 0.1);
|
||||
border: 1px solid rgba(220, 38, 38, 0.3);
|
||||
color: var(--p-red-400);
|
||||
max-width: 500px;
|
||||
|
||||
.pi {
|
||||
font-size: 1.25rem;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.access-denied-content {
|
||||
h3 {
|
||||
margin: 0 0 0.5rem 0;
|
||||
font-size: 1rem;
|
||||
font-weight: 600;
|
||||
color: var(--p-red-300);
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 0;
|
||||
font-size: 0.875rem;
|
||||
line-height: 1.5;
|
||||
}
|
||||
}
|
||||
}
|
||||
+225
@@ -0,0 +1,225 @@
|
||||
import {Component, inject, OnDestroy, OnInit} from '@angular/core';
|
||||
import {ConfirmationService, MessageService} from 'primeng/api';
|
||||
import {Clipboard} from '@angular/cdk/clipboard';
|
||||
import {KoboService, KoboSyncSettings} from './kobo.service';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {Button} from 'primeng/button';
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
import {ConfirmDialog} from 'primeng/confirmdialog';
|
||||
import {UserService} from '../../../user-management/user.service';
|
||||
import {Subject} from 'rxjs';
|
||||
import {debounceTime, filter, take, takeUntil} from 'rxjs/operators';
|
||||
import {ToggleSwitch} from 'primeng/toggleswitch';
|
||||
import {Slider} from 'primeng/slider';
|
||||
import {AppSettingsService} from '../../../../../shared/service/app-settings.service';
|
||||
import {SettingsHelperService} from '../../../../../shared/service/settings-helper.service';
|
||||
import {AppSettingKey, KoboSettings} from '../../../../../shared/model/app-settings.model';
|
||||
import {ShelfService} from '../../../../book/service/shelf.service';
|
||||
import {ExternalDocLinkComponent} from '../../../../../shared/components/external-doc-link/external-doc-link.component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-kobo-sync-setting-component',
|
||||
standalone: true,
|
||||
templateUrl: './kobo-sync-settings-component.html',
|
||||
styleUrl: './kobo-sync-settings-component.scss',
|
||||
imports: [FormsModule, Button, InputText, ConfirmDialog, ToggleSwitch, Slider, ExternalDocLinkComponent],
|
||||
providers: [MessageService, ConfirmationService]
|
||||
})
|
||||
export class KoboSyncSettingsComponent implements OnInit, OnDestroy {
|
||||
private koboService = inject(KoboService);
|
||||
private messageService = inject(MessageService);
|
||||
private confirmationService = inject(ConfirmationService);
|
||||
private clipboard = inject(Clipboard);
|
||||
protected userService = inject(UserService);
|
||||
protected appSettingsService = inject(AppSettingsService);
|
||||
protected settingsHelperService = inject(SettingsHelperService);
|
||||
private shelfService = inject(ShelfService);
|
||||
|
||||
private readonly destroy$ = new Subject<void>();
|
||||
private readonly sliderChange$ = new Subject<void>();
|
||||
|
||||
hasKoboTokenPermission = false;
|
||||
isAdmin = false;
|
||||
credentialsSaved = false;
|
||||
showToken = false;
|
||||
|
||||
koboSettings: KoboSettings = {
|
||||
convertToKepub: false,
|
||||
conversionLimitInMb: 100
|
||||
};
|
||||
|
||||
koboSyncSettings: KoboSyncSettings = {
|
||||
token: '',
|
||||
syncEnabled: false
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.setupSliderDebouncing();
|
||||
this.setupUserStateSubscription();
|
||||
}
|
||||
|
||||
private setupSliderDebouncing() {
|
||||
this.sliderChange$.pipe(
|
||||
debounceTime(500),
|
||||
takeUntil(this.destroy$)
|
||||
).subscribe(() => {
|
||||
this.saveSettings();
|
||||
});
|
||||
}
|
||||
|
||||
private setupUserStateSubscription() {
|
||||
let prevHasKoboTokenPermission = false;
|
||||
let prevIsAdmin = false;
|
||||
this.userService.userState$.pipe(
|
||||
filter(userState => !!userState?.user && userState.loaded),
|
||||
takeUntil(this.destroy$)
|
||||
).subscribe(userState => {
|
||||
const currHasKoboTokenPermission = (userState.user?.permissions.canSyncKobo) ?? false;
|
||||
const currIsAdmin = userState.user?.permissions.admin ?? false;
|
||||
|
||||
if (currHasKoboTokenPermission && !prevHasKoboTokenPermission) {
|
||||
this.hasKoboTokenPermission = true;
|
||||
this.loadKoboUserSettings();
|
||||
} else {
|
||||
this.hasKoboTokenPermission = currHasKoboTokenPermission;
|
||||
}
|
||||
|
||||
if (currIsAdmin && !prevIsAdmin) {
|
||||
this.isAdmin = true;
|
||||
this.loadKoboAdminSettings();
|
||||
} else {
|
||||
this.isAdmin = currIsAdmin;
|
||||
}
|
||||
|
||||
prevHasKoboTokenPermission = currHasKoboTokenPermission;
|
||||
prevIsAdmin = currIsAdmin;
|
||||
});
|
||||
}
|
||||
|
||||
private loadKoboUserSettings() {
|
||||
this.koboService.getUser().subscribe({
|
||||
next: (settings: KoboSyncSettings) => {
|
||||
this.koboSyncSettings.token = settings.token;
|
||||
this.koboSyncSettings.syncEnabled = settings.syncEnabled;
|
||||
this.credentialsSaved = !!settings.token;
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to load Kobo settings'});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private loadKoboAdminSettings() {
|
||||
this.appSettingsService.appSettings$
|
||||
.pipe(
|
||||
filter(settings => settings != null),
|
||||
take(1),
|
||||
)
|
||||
.subscribe(settings => {
|
||||
this.koboSettings.convertToKepub = settings?.koboSettings?.convertToKepub ?? true;
|
||||
this.koboSettings.conversionLimitInMb = settings?.koboSettings?.conversionLimitInMb ?? 100;
|
||||
});
|
||||
}
|
||||
|
||||
copyText(text: string) {
|
||||
this.clipboard.copy(text);
|
||||
this.messageService.add({severity: 'success', summary: 'Copied', detail: 'Token copied to clipboard'});
|
||||
}
|
||||
|
||||
toggleShowToken() {
|
||||
this.showToken = !this.showToken;
|
||||
}
|
||||
|
||||
confirmRegenerateToken() {
|
||||
this.confirmationService.confirm({
|
||||
message: 'This will generate a new token and invalidate the previous one. Continue?',
|
||||
header: 'Confirm Regeneration',
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
accept: () => this.regenerateToken()
|
||||
});
|
||||
}
|
||||
|
||||
private regenerateToken() {
|
||||
this.koboService.createOrUpdateToken().subscribe({
|
||||
next: (settings) => {
|
||||
this.koboSyncSettings.token = settings.token;
|
||||
this.credentialsSaved = true;
|
||||
this.messageService.add({severity: 'success', summary: 'Token regenerated', detail: 'New token generated successfully'});
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to regenerate token'});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onToggleChange() {
|
||||
this.saveSettings();
|
||||
}
|
||||
|
||||
onSliderChange() {
|
||||
this.sliderChange$.next();
|
||||
}
|
||||
|
||||
onSyncToggle() {
|
||||
if (!this.koboSyncSettings.syncEnabled) {
|
||||
this.confirmationService.confirm({
|
||||
message: 'Disabling Kobo sync will delete your Kobo shelf. Are you sure you want to proceed?',
|
||||
header: 'Confirm Disable',
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
accept: () => this.performToggle(false),
|
||||
reject: () => {
|
||||
this.koboSyncSettings.syncEnabled = true;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.performToggle(true);
|
||||
}
|
||||
}
|
||||
|
||||
private performToggle(enabled: boolean) {
|
||||
this.koboService.toggleSync(enabled).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Sync Updated',
|
||||
detail: enabled
|
||||
? 'Kobo sync enabled'
|
||||
: 'Kobo sync disabled'
|
||||
});
|
||||
this.shelfService.reloadShelves();
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Error',
|
||||
detail: 'Failed to update sync setting'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
saveSettings() {
|
||||
this.settingsHelperService.saveSetting(AppSettingKey.KOBO_SETTINGS, this.koboSettings)
|
||||
.subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Settings Saved',
|
||||
detail: 'Kobo settings updated successfully'
|
||||
});
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Save Failed',
|
||||
detail: 'Failed to save Kobo settings'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
import {inject, Injectable} from '@angular/core';
|
||||
import {HttpClient, HttpParams} from '@angular/common/http';
|
||||
import {Observable} from 'rxjs';
|
||||
import {API_CONFIG} from '../../../../../core/config/api-config';
|
||||
|
||||
export interface KoboSyncSettings {
|
||||
token: string;
|
||||
syncEnabled: boolean;
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class KoboService {
|
||||
private readonly baseUrl = `${API_CONFIG.BASE_URL}/api/v1/kobo-settings`;
|
||||
private readonly http = inject(HttpClient);
|
||||
|
||||
getUser(): Observable<KoboSyncSettings> {
|
||||
return this.http.get<KoboSyncSettings>(`${this.baseUrl}`);
|
||||
}
|
||||
|
||||
createOrUpdateToken(): Observable<KoboSyncSettings> {
|
||||
return this.http.put<KoboSyncSettings>(`${this.baseUrl}`, null);
|
||||
}
|
||||
|
||||
toggleSync(enabled: boolean): Observable<void> {
|
||||
const params = new HttpParams().set('enabled', enabled.toString());
|
||||
return this.http.put<void>(`${this.baseUrl}/sync`, null, { params });
|
||||
}
|
||||
}
|
||||
+191
@@ -0,0 +1,191 @@
|
||||
<p-toast position="top-right"></p-toast>
|
||||
|
||||
<div class="main-container enclosing-container">
|
||||
<div class="settings-header">
|
||||
<h2 class="settings-title">
|
||||
<i class="pi pi-mobile"></i>
|
||||
KOReader Sync Settings
|
||||
<app-external-doc-link docType="koReader"></app-external-doc-link>
|
||||
</h2>
|
||||
<p class="settings-description">
|
||||
Configure KOReader integration to sync your reading progress between your device and Booklore library.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@if (hasPermission) {
|
||||
<div class="settings-content">
|
||||
<div class="preferences-section">
|
||||
<div class="section-header">
|
||||
<h3 class="section-title">
|
||||
<i class="pi pi-sync"></i>
|
||||
Sync Configuration
|
||||
</h3>
|
||||
<p class="section-description">
|
||||
Enable and configure synchronization between your Booklore library and KOReader device.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="settings-card">
|
||||
<form #koreaderForm="ngForm">
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">Enable KOReader Sync</label>
|
||||
<p-toggle-switch
|
||||
name="syncEnabled"
|
||||
[(ngModel)]="koReaderSyncEnabled"
|
||||
(ngModelChange)="onToggleEnabled($event)"
|
||||
inputId="syncEnabled"
|
||||
[disabled]="!credentialsSaved">
|
||||
</p-toggle-switch>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
Turn on synchronization to automatically sync your reading progress.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">KOReader API Path</label>
|
||||
<div class="token-input-group">
|
||||
<input
|
||||
pInputText
|
||||
id="koreaderEndpoint"
|
||||
[value]="koreaderEndpoint"
|
||||
readonly
|
||||
class="token-input"/>
|
||||
<p-button
|
||||
icon="pi pi-copy"
|
||||
outlined="true"
|
||||
severity="info"
|
||||
size="small"
|
||||
(onClick)="copyText(koreaderEndpoint)">
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
The API endpoint path for your KOReader sync service.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">KOReader Username</label>
|
||||
<div class="token-input-group">
|
||||
<input
|
||||
pInputText
|
||||
id="username"
|
||||
name="username"
|
||||
required
|
||||
[(ngModel)]="koReaderUsername"
|
||||
#usernameModel="ngModel"
|
||||
[class.p-invalid]="usernameModel.invalid && usernameModel.touched"
|
||||
[disabled]="editMode"
|
||||
class="token-input"/>
|
||||
<p-button
|
||||
icon="pi pi-copy"
|
||||
outlined="true"
|
||||
severity="info"
|
||||
size="small"
|
||||
(onClick)="copyText(koReaderUsername)">
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
Your username for authenticating with the KOReader sync service.
|
||||
</p>
|
||||
@if (editMode && usernameModel.invalid && usernameModel.touched) {
|
||||
<small class="error-message">
|
||||
Username is required.
|
||||
</small>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">KOReader Password</label>
|
||||
<div class="token-input-group">
|
||||
<input
|
||||
pInputText
|
||||
id="password"
|
||||
name="password"
|
||||
required
|
||||
minlength="6"
|
||||
[type]="showPassword ? 'text' : 'password'"
|
||||
[(ngModel)]="koReaderPassword"
|
||||
#passwordModel="ngModel"
|
||||
[class.p-invalid]="passwordModel.invalid && passwordModel.touched"
|
||||
[disabled]="editMode"
|
||||
class="token-input-password"/>
|
||||
<p-button
|
||||
icon="pi pi-copy"
|
||||
outlined="true"
|
||||
severity="info"
|
||||
size="small"
|
||||
(onClick)="copyText(koReaderPassword)">
|
||||
</p-button>
|
||||
<p-button
|
||||
[icon]="showPassword ? 'pi pi-eye-slash' : 'pi pi-eye'"
|
||||
outlined="true"
|
||||
severity="info"
|
||||
size="small"
|
||||
(onClick)="toggleShowPassword()">
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
Your password for authenticating with the KOReader sync service.
|
||||
</p>
|
||||
@if (editMode && passwordModel.invalid && passwordModel.touched) {
|
||||
<small class="error-message">
|
||||
Password must be at least 6 characters.
|
||||
</small>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">Settings Management</label>
|
||||
<p-button
|
||||
[icon]="!editMode ? 'pi pi-save' : 'pi pi-pencil'"
|
||||
outlined="true"
|
||||
[severity]="!editMode ? 'success' : 'warn'"
|
||||
[label]="!editMode ? 'Save' : 'Edit'"
|
||||
size="small"
|
||||
(onClick)="onEditSave()"
|
||||
[disabled]="!editMode && !canSave">
|
||||
</p-button>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
Save your credentials or edit existing settings.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
} @else {
|
||||
<div class="settings-content">
|
||||
<div class="access-denied-card">
|
||||
<i class="pi pi-lock"></i>
|
||||
<div class="access-denied-content">
|
||||
<h3>Access Restricted</h3>
|
||||
<p>
|
||||
Access to KOReader sync is restricted.
|
||||
<br>
|
||||
Please contact your administrator to request permission.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
+241
@@ -0,0 +1,241 @@
|
||||
.main-container {
|
||||
width: 100%;
|
||||
padding: 1rem;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.enclosing-container {
|
||||
border-color: var(--p-content-border-color);
|
||||
background: var(--p-content-background);
|
||||
}
|
||||
|
||||
.settings-header {
|
||||
margin-top: 1rem;
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.settings-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
font-size: 1.25rem;
|
||||
font-weight: 700;
|
||||
color: var(--p-text-color);
|
||||
margin: 0 0 0.75rem 0;
|
||||
|
||||
.pi {
|
||||
color: var(--p-primary-color);
|
||||
font-size: 1.25rem;
|
||||
}
|
||||
}
|
||||
|
||||
.settings-description {
|
||||
color: var(--p-text-muted-color);
|
||||
font-size: 0.875rem;
|
||||
line-height: 1.5;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.settings-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2rem;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
padding-left: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.preferences-section {
|
||||
|
||||
@media (max-width: 768px) {
|
||||
padding: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.section-header {
|
||||
margin-bottom: 1rem;
|
||||
margin-left: 1rem;
|
||||
margin-right: 1rem;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
font-size: 1.125rem;
|
||||
font-weight: 600;
|
||||
color: var(--p-text-color);
|
||||
margin: 0 0 0.5rem 0;
|
||||
|
||||
.pi {
|
||||
color: var(--p-primary-color);
|
||||
}
|
||||
}
|
||||
|
||||
.section-description {
|
||||
color: var(--p-text-muted-color);
|
||||
font-size: 0.875rem;
|
||||
line-height: 1.5;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.settings-card {
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
border-radius: 8px;
|
||||
background: var(--p-content-background);
|
||||
padding: 1rem 1.5rem 1.5rem 1.5rem;
|
||||
margin-left: 1rem;
|
||||
margin-right: 1rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2rem;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
padding: 1rem;
|
||||
margin-left: 0;
|
||||
margin-right: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.setting-item {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 2rem;
|
||||
padding: 0.5rem 0;
|
||||
|
||||
&:last-child {
|
||||
border-bottom: none;
|
||||
padding-bottom: 0;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
padding: 0.5rem 0;
|
||||
}
|
||||
}
|
||||
|
||||
.setting-info {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
|
||||
.setting-label {
|
||||
display: block;
|
||||
font-weight: 600;
|
||||
color: var(--p-text-color);
|
||||
font-size: 1rem;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.setting-label-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
margin-bottom: 0.5rem;
|
||||
flex-wrap: wrap;
|
||||
|
||||
.setting-label {
|
||||
margin-bottom: 0;
|
||||
flex-shrink: 0;
|
||||
min-width: 150px;
|
||||
}
|
||||
|
||||
.token-input-group {
|
||||
flex: 1;
|
||||
min-width: 300px;
|
||||
max-width: 500px;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
min-width: 250px;
|
||||
max-width: 100%;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.setting-description {
|
||||
color: var(--p-text-muted-color);
|
||||
font-size: 0.875rem;
|
||||
line-height: 1.5;
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.setting-control {
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
align-items: flex-end;
|
||||
min-width: 350px;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
align-items: flex-start;
|
||||
width: 100%;
|
||||
min-width: unset;
|
||||
}
|
||||
}
|
||||
|
||||
.token-input-group {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
width: 100%;
|
||||
|
||||
.token-input {
|
||||
flex: 1;
|
||||
min-width: 200px;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
min-width: 150px;
|
||||
}
|
||||
}
|
||||
|
||||
.token-input-password {
|
||||
flex: 1;
|
||||
min-width: 200px;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
min-width: 150px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.error-message {
|
||||
color: var(--p-red-500);
|
||||
font-size: 0.75rem;
|
||||
margin-top: 0.25rem;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.access-denied-card {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
padding: 1rem;
|
||||
border-radius: 8px;
|
||||
background: rgba(220, 38, 38, 0.1);
|
||||
border: 1px solid rgba(220, 38, 38, 0.3);
|
||||
color: var(--p-red-400);
|
||||
max-width: 500px;
|
||||
|
||||
.pi {
|
||||
font-size: 1.25rem;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.access-denied-content {
|
||||
h3 {
|
||||
margin: 0 0 0.5rem 0;
|
||||
font-size: 1rem;
|
||||
font-weight: 600;
|
||||
color: var(--p-red-300);
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 0;
|
||||
font-size: 0.875rem;
|
||||
line-height: 1.5;
|
||||
}
|
||||
}
|
||||
}
|
||||
+136
@@ -0,0 +1,136 @@
|
||||
import {Component, inject, OnDestroy, OnInit} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
import {ToggleSwitch} from 'primeng/toggleswitch';
|
||||
import {Button} from 'primeng/button';
|
||||
import {ToastModule} from 'primeng/toast';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {KoreaderService} from './koreader.service';
|
||||
import {UserService} from '../../../user-management/user.service';
|
||||
import {filter, takeUntil} from 'rxjs/operators';
|
||||
import {Subject} from 'rxjs';
|
||||
import {ExternalDocLinkComponent} from '../../../../../shared/components/external-doc-link/external-doc-link.component';
|
||||
|
||||
@Component({
|
||||
standalone: true,
|
||||
selector: 'app-koreader-settings-component',
|
||||
imports: [
|
||||
CommonModule,
|
||||
FormsModule,
|
||||
InputText,
|
||||
ToggleSwitch,
|
||||
Button,
|
||||
ToastModule,
|
||||
ExternalDocLinkComponent
|
||||
],
|
||||
providers: [MessageService],
|
||||
templateUrl: './koreader-settings-component.html',
|
||||
styleUrls: ['./koreader-settings-component.scss']
|
||||
})
|
||||
export class KoreaderSettingsComponent implements OnInit, OnDestroy {
|
||||
editMode = true;
|
||||
showPassword = false;
|
||||
koReaderSyncEnabled = false;
|
||||
koReaderUsername = '';
|
||||
koReaderPassword = '';
|
||||
credentialsSaved = false;
|
||||
readonly koreaderEndpoint = `${window.location.origin}/api/koreader`;
|
||||
|
||||
private readonly messageService = inject(MessageService);
|
||||
private readonly koreaderService = inject(KoreaderService);
|
||||
private readonly userService = inject(UserService);
|
||||
|
||||
private readonly destroy$ = new Subject<void>();
|
||||
hasPermission = false;
|
||||
|
||||
ngOnInit() {
|
||||
let prevHasPermission = false;
|
||||
this.userService.userState$.pipe(
|
||||
filter(userState => !!userState?.user && userState.loaded),
|
||||
takeUntil(this.destroy$)
|
||||
).subscribe(userState => {
|
||||
const currHasPermission = (userState.user?.permissions.canSyncKoReader || userState.user?.permissions.admin) ?? false;
|
||||
this.hasPermission = currHasPermission;
|
||||
if (currHasPermission && !prevHasPermission) {
|
||||
this.loadKoreaderSettings();
|
||||
}
|
||||
prevHasPermission = currHasPermission;
|
||||
});
|
||||
}
|
||||
|
||||
private loadKoreaderSettings() {
|
||||
this.koreaderService.getUser().subscribe({
|
||||
next: koreaderUser => {
|
||||
this.koReaderUsername = koreaderUser.username;
|
||||
this.koReaderPassword = koreaderUser.password;
|
||||
this.koReaderSyncEnabled = koreaderUser.syncEnabled;
|
||||
this.credentialsSaved = true;
|
||||
},
|
||||
error: err => {
|
||||
if (err.status !== 404) {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Load Error',
|
||||
detail: 'Unable to retrieve KOReader account. Please try again.'
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get canSave(): boolean {
|
||||
const u = this.koReaderUsername?.trim() ?? '';
|
||||
const p = this.koReaderPassword ?? '';
|
||||
return u.length > 0 && p.length >= 6;
|
||||
}
|
||||
|
||||
onEditSave() {
|
||||
if (!this.editMode) {
|
||||
this.saveCredentials();
|
||||
}
|
||||
this.editMode = !this.editMode;
|
||||
}
|
||||
|
||||
onToggleEnabled(enabled: boolean) {
|
||||
this.koreaderService.toggleSync(enabled).subscribe({
|
||||
next: () => {
|
||||
this.koReaderSyncEnabled = enabled;
|
||||
this.messageService.add({severity: 'success', summary: 'Sync Updated', detail: `KOReader sync has been ${enabled ? 'enabled' : 'disabled'}.`});
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({severity: 'error', summary: 'Update Failed', detail: 'Unable to update KOReader sync setting. Please try again.'});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
toggleShowPassword() {
|
||||
this.showPassword = !this.showPassword;
|
||||
}
|
||||
|
||||
saveCredentials() {
|
||||
this.koreaderService.createUser(this.koReaderUsername, this.koReaderPassword)
|
||||
.subscribe({
|
||||
next: () => {
|
||||
this.credentialsSaved = true;
|
||||
this.messageService.add({severity: 'success', summary: 'Saved', detail: 'KOReader account saved successfully.'});
|
||||
},
|
||||
error: () =>
|
||||
this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to save KOReader credentials. Please try again.'})
|
||||
});
|
||||
}
|
||||
|
||||
copyText(text: string) {
|
||||
if (!text) {
|
||||
return;
|
||||
}
|
||||
navigator.clipboard.writeText(text).catch(err => {
|
||||
console.error('Copy failed', err);
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
import {inject, Injectable} from '@angular/core';
|
||||
import {Observable} from 'rxjs';
|
||||
import {API_CONFIG} from '../../../../../core/config/api-config';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
|
||||
|
||||
export interface KoreaderUser {
|
||||
username: string;
|
||||
password: string;
|
||||
syncEnabled: boolean;
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class KoreaderService {
|
||||
|
||||
private readonly url = `${API_CONFIG.BASE_URL}/api/v1/koreader-users`;
|
||||
|
||||
private http = inject(HttpClient);
|
||||
|
||||
createUser(username: string, password: string): Observable<KoreaderUser> {
|
||||
const payload: any = {username, password};
|
||||
return this.http.put<KoreaderUser>(`${this.url}/me`, payload);
|
||||
}
|
||||
|
||||
getUser(): Observable<KoreaderUser> {
|
||||
return this.http.get<KoreaderUser>(`${this.url}/me`);
|
||||
}
|
||||
|
||||
toggleSync(enabled: boolean): Observable<void> {
|
||||
return this.http.patch<void>(`${this.url}/me/sync`, null, {
|
||||
params: {enabled: enabled.toString()}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<div class="w-full h-[calc(100dvh-10.5rem)] md:h-[calc(100dvh-11.65rem)] overflow-y-auto border rounded-lg enclosing-container">
|
||||
<div class="pb-6">
|
||||
<app-koreader-settings-component></app-koreader-settings-component>
|
||||
</div>
|
||||
<p-divider></p-divider>
|
||||
<div class="py-4">
|
||||
<app-kobo-sync-setting-component></app-kobo-sync-setting-component>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,3 @@
|
||||
.enclosing-container {
|
||||
border-color: var(--p-content-border-color);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import {Component} from '@angular/core';
|
||||
import {Divider} from 'primeng/divider';
|
||||
import {KoreaderSettingsComponent} from './component/koreader-settings/koreader-settings-component';
|
||||
import {KoboSyncSettingsComponent} from './component/kobo-sync-settings/kobo-sync-settings-component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-device-settings-component',
|
||||
imports: [
|
||||
KoreaderSettingsComponent,
|
||||
KoboSyncSettingsComponent,
|
||||
Divider
|
||||
],
|
||||
templateUrl: './device-settings-component.html',
|
||||
styleUrl: './device-settings-component.scss'
|
||||
})
|
||||
export class DeviceSettingsComponent {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user