Add checkbox to enable or disable automatic book match search on opening book details
This commit is contained in:
committed by
Aditya Chandel
parent
bb5c0d473c
commit
2ef67f450a
@@ -0,0 +1,100 @@
|
||||
<div class="p-4">
|
||||
<p-button outlined="true" label="Create User" (onClick)="openCreateUserDialog()"></p-button>
|
||||
|
||||
<p-table [value]="users" class="mt-4">
|
||||
<ng-template pTemplate="header">
|
||||
<tr>
|
||||
<th>Username</th>
|
||||
<th>Full Name</th>
|
||||
<th>Email</th>
|
||||
<th>Assigned Libraries</th>
|
||||
<th style="width: 100px;">Can Upload</th>
|
||||
<th style="width: 100px;">Can Download</th>
|
||||
<th style="width: 100px;">Can Edit Metadata</th>
|
||||
<th style="width: 100px;">Can Email Books</th>
|
||||
<th style="width: 100px;">Edit</th>
|
||||
<th style="width: 100px;">Change Password</th>
|
||||
<th style="width: 100px;">Delete</th>
|
||||
</tr>
|
||||
</ng-template>
|
||||
|
||||
<ng-template pTemplate="body" let-user>
|
||||
<tr>
|
||||
<td>{{ user.username }}</td>
|
||||
<td>
|
||||
<input *ngIf="user.isEditing" type="text" [(ngModel)]="user.name" class="p-inputtext w-full"/>
|
||||
<span *ngIf="!user.isEditing">{{ user.name }}</span>
|
||||
</td>
|
||||
<td>
|
||||
<input *ngIf="user.isEditing" type="email" [(ngModel)]="user.email" class="p-inputtext w-full"/>
|
||||
<span *ngIf="!user.isEditing">{{ user.email }}</span>
|
||||
</td>
|
||||
<td>
|
||||
<p-multiSelect
|
||||
*ngIf="user.isEditing"
|
||||
[options]="allLibraries"
|
||||
optionLabel="name"
|
||||
optionValue="id"
|
||||
[(ngModel)]="editingLibraryIds"
|
||||
placeholder="Select Libraries"
|
||||
appendTo="body">
|
||||
</p-multiSelect>
|
||||
<span *ngIf="!user.isEditing">
|
||||
{{ user.libraryNames }}
|
||||
</span>
|
||||
</td>
|
||||
<td class="text-center">
|
||||
<p-checkbox [binary]="true" [(ngModel)]="user.permissions.canUpload" *ngIf="user.isEditing"></p-checkbox>
|
||||
<p-checkbox [binary]="true" [(ngModel)]="user.permissions.canUpload" disabled *ngIf="!user.isEditing"></p-checkbox>
|
||||
</td>
|
||||
<td class="text-center">
|
||||
<p-checkbox [binary]="true" [(ngModel)]="user.permissions.canDownload" *ngIf="user.isEditing"></p-checkbox>
|
||||
<p-checkbox [binary]="true" [(ngModel)]="user.permissions.canDownload" disabled *ngIf="!user.isEditing"></p-checkbox>
|
||||
</td>
|
||||
<td class="text-center">
|
||||
<p-checkbox [binary]="true" [(ngModel)]="user.permissions.canEditMetadata" *ngIf="user.isEditing"></p-checkbox>
|
||||
<p-checkbox [binary]="true" [(ngModel)]="user.permissions.canEditMetadata" disabled *ngIf="!user.isEditing"></p-checkbox>
|
||||
</td>
|
||||
<td class="text-center">
|
||||
<p-checkbox [binary]="true" [(ngModel)]="user.permissions.canEmailBook" *ngIf="user.isEditing"></p-checkbox>
|
||||
<p-checkbox [binary]="true" [(ngModel)]="user.permissions.canEmailBook" disabled *ngIf="!user.isEditing"></p-checkbox>
|
||||
</td>
|
||||
<td class="text-center">
|
||||
<ng-container *ngIf="user.username !== 'admin'">
|
||||
<p-button *ngIf="!user.isEditing" icon="pi pi-pencil" outlined="true" severity="info" (onClick)="toggleEdit(user)"></p-button>
|
||||
<p-button *ngIf="user.isEditing" icon="pi pi-check" outlined="true" severity="success" (onClick)="saveUser(user)"></p-button>
|
||||
<p-button *ngIf="user.isEditing" icon="pi pi-times" outlined="true" severity="danger" (onClick)="toggleEdit(user)"></p-button>
|
||||
</ng-container>
|
||||
<p-button *ngIf="user.username === 'admin'"
|
||||
icon="pi pi-pencil"
|
||||
outlined="true"
|
||||
severity="primary"
|
||||
[ngStyle]="{'visibility': 'hidden'}">
|
||||
</p-button>
|
||||
</td>
|
||||
<td class="text-center">
|
||||
<ng-container *ngIf="user.username !== 'admin'">
|
||||
<p-button icon="pi pi-key" outlined="true" severity="warn" (onClick)="openChangePasswordDialog(user)"></p-button>
|
||||
</ng-container>
|
||||
</td>
|
||||
<td class="text-center">
|
||||
<ng-container *ngIf="user.username !== 'admin'">
|
||||
<p-button icon="pi pi-trash" outlined="true" severity="danger" (onClick)="deleteUser(user)"></p-button>
|
||||
</ng-container>
|
||||
</td>
|
||||
</tr>
|
||||
</ng-template>
|
||||
</p-table>
|
||||
|
||||
<p-dialog header="Change Password" [(visible)]="isPasswordDialogVisible" [modal]="true" [closable]="false" [style]="{width: '20vw'}">
|
||||
<div class="flex flex-col gap-8 items-center">
|
||||
<p-password [(ngModel)]="newPassword" placeholder="New Password" [feedback]="false" class="w-full" fluid></p-password>
|
||||
<p-password [(ngModel)]="confirmNewPassword" placeholder="Confirm Password" [feedback]="false" class="w-full" fluid></p-password>
|
||||
<p *ngIf="passwordError" class="p-error text-red-500 w-full text-left">{{ passwordError }}</p>
|
||||
<div class="flex gap-4 w-full justify-end">
|
||||
<p-button label="Cancel" icon="pi pi-times" severity="secondary" (onClick)="isPasswordDialogVisible = false"></p-button>
|
||||
<p-button label="Change" icon="pi pi-check" severity="success" (onClick)="submitPasswordChange()"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
</p-dialog>
|
||||
</div>
|
||||
@@ -0,0 +1,203 @@
|
||||
import {Component, inject, OnInit} from '@angular/core';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {Button} from 'primeng/button';
|
||||
import {DialogService, DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {CreateUserDialogComponent} from './create-user-dialog/create-user-dialog.component';
|
||||
import {TableModule} from 'primeng/table';
|
||||
import {NgIf, NgStyle} from '@angular/common';
|
||||
import {User, UserService} from '../../user.service';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {Checkbox} from 'primeng/checkbox';
|
||||
import {MultiSelect} from 'primeng/multiselect';
|
||||
import {Library} from '../../book/model/library.model';
|
||||
import {LibraryService} from '../../book/service/library.service';
|
||||
import {Dialog} from 'primeng/dialog';
|
||||
import {Password} from 'primeng/password';
|
||||
|
||||
@Component({
|
||||
selector: 'app-admin',
|
||||
imports: [
|
||||
FormsModule,
|
||||
Button,
|
||||
TableModule,
|
||||
NgIf,
|
||||
Checkbox,
|
||||
NgStyle,
|
||||
MultiSelect,
|
||||
Dialog,
|
||||
Password,
|
||||
],
|
||||
templateUrl: './admin.component.html',
|
||||
styleUrls: ['./admin.component.scss'],
|
||||
})
|
||||
export class AdminComponent implements OnInit {
|
||||
ref: DynamicDialogRef | undefined;
|
||||
private dialogService = inject(DialogService);
|
||||
private userService = inject(UserService);
|
||||
private libraryService = inject(LibraryService);
|
||||
private messageService = inject(MessageService);
|
||||
|
||||
users: User[] = [];
|
||||
editingLibraryIds: number[] = [];
|
||||
allLibraries: Library[] = [];
|
||||
|
||||
isPasswordDialogVisible = false;
|
||||
selectedUser: User | null = null;
|
||||
newPassword = '';
|
||||
confirmNewPassword = '';
|
||||
passwordError = '';
|
||||
|
||||
ngOnInit() {
|
||||
this.loadUsers();
|
||||
this.libraryService.getAllLibrariesFromAPI().subscribe({
|
||||
next: (libraries) => {
|
||||
this.allLibraries = libraries;
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Error',
|
||||
detail: 'Failed to load libraries',
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
loadUsers() {
|
||||
this.userService.getUsers().subscribe({
|
||||
next: (data) => {
|
||||
this.users = data.map((user) => ({
|
||||
...user,
|
||||
isEditing: false,
|
||||
selectedLibraryIds: user.assignedLibraries?.map((lib) => lib.id) || [],
|
||||
libraryNames:
|
||||
user.assignedLibraries?.map((lib) => lib.name).join(', ') || '',
|
||||
}));
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Error',
|
||||
detail: 'Failed to fetch users',
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
openCreateUserDialog() {
|
||||
this.ref = this.dialogService.open(CreateUserDialogComponent, {
|
||||
header: 'Create New User',
|
||||
modal: true,
|
||||
closable: true,
|
||||
style: {position: 'absolute', top: '15%'},
|
||||
});
|
||||
this.ref.onClose.subscribe((result) => {
|
||||
if (result) {
|
||||
this.loadUsers();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
toggleEdit(user: any) {
|
||||
user.isEditing = !user.isEditing;
|
||||
if (user.isEditing) {
|
||||
this.editingLibraryIds = [...user.selectedLibraryIds];
|
||||
} else {
|
||||
user.libraryNames =
|
||||
user.assignedLibraries
|
||||
?.map((lib: Library) => lib.name)
|
||||
.join(', ') || '';
|
||||
}
|
||||
}
|
||||
|
||||
saveUser(user: any) {
|
||||
user.selectedLibraryIds = [...this.editingLibraryIds];
|
||||
this.userService
|
||||
.updateUser(user.id, {
|
||||
name: user.name,
|
||||
email: user.email,
|
||||
permissions: user.permissions,
|
||||
assignedLibraries: user.selectedLibraryIds,
|
||||
})
|
||||
.subscribe({
|
||||
next: () => {
|
||||
user.isEditing = false;
|
||||
this.loadUsers();
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Success',
|
||||
detail: 'User updated successfully',
|
||||
});
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Error',
|
||||
detail: 'Failed to update user',
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
deleteUser(user: User) {
|
||||
if (confirm(`Are you sure you want to delete ${user.username}?`)) {
|
||||
this.userService.deleteUser(user.id).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Success',
|
||||
detail: `User ${user.username} deleted successfully`,
|
||||
});
|
||||
this.loadUsers();
|
||||
},
|
||||
error: (err) => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Error',
|
||||
detail:
|
||||
err.error?.message ||
|
||||
`Failed to delete user ${user.username}`,
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
openChangePasswordDialog(user: User) {
|
||||
this.selectedUser = user;
|
||||
this.newPassword = '';
|
||||
this.confirmNewPassword = '';
|
||||
this.passwordError = '';
|
||||
this.isPasswordDialogVisible = true;
|
||||
}
|
||||
|
||||
submitPasswordChange() {
|
||||
if (!this.newPassword || !this.confirmNewPassword) {
|
||||
this.passwordError = 'Both fields are required';
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.newPassword !== this.confirmNewPassword) {
|
||||
this.passwordError = 'Passwords do not match';
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.selectedUser) {
|
||||
this.userService
|
||||
.changeUserPassword(this.selectedUser.id, this.newPassword)
|
||||
.subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Success',
|
||||
detail: 'Password changed successfully',
|
||||
});
|
||||
this.isPasswordDialogVisible = false;
|
||||
},
|
||||
error: (err) => {
|
||||
this.passwordError = err;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
<form [formGroup]="userForm" (ngSubmit)="createUser()" class="space-y-6 p-6">
|
||||
|
||||
<div class="flex items-center gap-4">
|
||||
<label class="w-40 text-right font-medium">Full Name:</label>
|
||||
<input type="text" pInputText formControlName="name" placeholder="Enter full name..." class="w-full md:w-80"/>
|
||||
</div>
|
||||
<small class="text-red-500 pl-44" *ngIf="userForm.get('name')?.invalid && (userForm.get('name')?.dirty || userForm.get('name')?.touched)">
|
||||
Name is required and must be at least 3 characters.
|
||||
</small>
|
||||
|
||||
<div class="flex items-center gap-4">
|
||||
<label class="w-40 text-right font-medium">Email:</label>
|
||||
<input type="email" pInputText formControlName="email" placeholder="Enter email..." class="w-full md:w-80"/>
|
||||
</div>
|
||||
<small class="text-red-500 pl-44" *ngIf="userForm.get('email')?.invalid && (userForm.get('email')?.dirty || userForm.get('email')?.touched)">
|
||||
Enter a valid email address.
|
||||
</small>
|
||||
|
||||
<div class="flex items-center gap-4">
|
||||
<label class="w-40 text-right font-medium">Username:</label>
|
||||
<input type="text" pInputText formControlName="username" placeholder="Enter username..." class="w-full md:w-80"/>
|
||||
</div>
|
||||
<small class="text-red-500 pl-44" *ngIf="userForm.get('username')?.invalid && (userForm.get('username')?.dirty || userForm.get('username')?.touched)">
|
||||
Username is required.
|
||||
</small>
|
||||
|
||||
<div class="flex items-center gap-4">
|
||||
<label class="w-40 text-right font-medium">Password:</label>
|
||||
<input type="password" pInputText formControlName="password" placeholder="Enter password..." class="w-full md:w-80"/>
|
||||
</div>
|
||||
<small class="text-red-500 pl-44" *ngIf="userForm.get('password')?.invalid && (userForm.get('password')?.dirty || userForm.get('password')?.touched)">
|
||||
Password must be at least 6 characters long.
|
||||
</small>
|
||||
|
||||
<div class="flex items-center gap-4">
|
||||
<label class="w-40 text-right font-medium">Accessible Libraries:</label>
|
||||
<p-multiselect
|
||||
[options]="libraries"
|
||||
formControlName="selectedLibraries"
|
||||
placeholder="Select Libraries"
|
||||
optionLabel="name"
|
||||
display="chip"
|
||||
class="w-full md:w-80"
|
||||
appendTo="body">
|
||||
</p-multiselect>
|
||||
</div>
|
||||
<small class="text-red-500 pl-44" *ngIf="userForm.get('selectedLibraries')?.invalid && (userForm.get('selectedLibraries')?.dirty || userForm.get('selectedLibraries')?.touched)">
|
||||
At least one library must be selected.
|
||||
</small>
|
||||
|
||||
<div>
|
||||
<p class="text-right w-40 font-medium">Permissions:</p>
|
||||
<div class="flex flex-col gap-2 pl-44">
|
||||
<div class="flex items-center gap-2">
|
||||
<p-checkbox formControlName="permissionUpload" [binary]="true"></p-checkbox>
|
||||
<label>Upload Books</label>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center gap-2">
|
||||
<p-checkbox formControlName="permissionDownload" [binary]="true"></p-checkbox>
|
||||
<label>Download Books</label>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center gap-2">
|
||||
<p-checkbox formControlName="permissionEditMetadata" [binary]="true"></p-checkbox>
|
||||
<label>Edit Metadata</label>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center gap-2">
|
||||
<p-checkbox formControlName="permissionEmailBook" [binary]="true"></p-checkbox>
|
||||
<label>Email Book</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex justify-end">
|
||||
<p-button label="Create User" [disabled]="userForm.invalid" type="submit">
|
||||
</p-button>
|
||||
</div>
|
||||
</form>
|
||||
@@ -0,0 +1,90 @@
|
||||
import {Component, inject, OnInit} from '@angular/core';
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
import {FormBuilder, FormGroup, FormsModule, ReactiveFormsModule, Validators} from '@angular/forms';
|
||||
import {Checkbox} from 'primeng/checkbox';
|
||||
import {MultiSelectModule} from 'primeng/multiselect';
|
||||
import {Library} from '../../../book/model/library.model';
|
||||
import {Button} from 'primeng/button';
|
||||
import {LibraryService} from '../../../book/service/library.service';
|
||||
import {UserService} from '../../../user.service';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {NgIf} from '@angular/common';
|
||||
|
||||
@Component({
|
||||
selector: 'app-create-user-dialog',
|
||||
standalone: true,
|
||||
imports: [
|
||||
InputText,
|
||||
ReactiveFormsModule,
|
||||
FormsModule,
|
||||
Checkbox,
|
||||
MultiSelectModule,
|
||||
Button,
|
||||
NgIf
|
||||
],
|
||||
templateUrl: './create-user-dialog.component.html',
|
||||
styleUrl: './create-user-dialog.component.scss'
|
||||
})
|
||||
export class CreateUserDialogComponent implements OnInit {
|
||||
userForm!: FormGroup;
|
||||
libraries: Library[] = [];
|
||||
|
||||
private fb = inject(FormBuilder);
|
||||
private libraryService = inject(LibraryService);
|
||||
private userService = inject(UserService);
|
||||
private messageService = inject(MessageService);
|
||||
private ref = inject(DynamicDialogRef);
|
||||
|
||||
ngOnInit() {
|
||||
this.libraries = this.libraryService.getLibrariesFromState();
|
||||
|
||||
this.userForm = this.fb.group({
|
||||
name: ['', [Validators.required, Validators.minLength(3)]],
|
||||
email: ['', [Validators.required, Validators.email]],
|
||||
username: ['', Validators.required],
|
||||
password: ['', [Validators.required, Validators.minLength(6)]],
|
||||
selectedLibraries: [[], Validators.required],
|
||||
permissionUpload: [false],
|
||||
permissionDownload: [false],
|
||||
permissionEditMetadata: [false],
|
||||
permissionEmailBook: [false]
|
||||
});
|
||||
}
|
||||
|
||||
createUser() {
|
||||
if (this.userForm.invalid) {
|
||||
this.messageService.add({
|
||||
severity: 'warn',
|
||||
summary: 'Validation Error',
|
||||
detail: 'Please correct errors before submitting.'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const userData = {
|
||||
...this.userForm.value,
|
||||
selectedLibraries: this.userForm.value.selectedLibraries.map((lib: Library) => lib.id)
|
||||
};
|
||||
|
||||
this.userService.createUser(userData).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'User Created',
|
||||
detail: 'The user has been successfully created.'
|
||||
});
|
||||
this.ref.close(true);
|
||||
},
|
||||
error: (err) => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'User Creation Failed',
|
||||
detail: err?.error?.message
|
||||
? `Unable to create user: ${err.error.message}`
|
||||
: 'An unexpected error occurred while creating the user. Please try again later.'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
<div class="w-full h-[calc(100vh-12.1rem)] overflow-y-auto border rounded-lg p-4 enclosing-container">
|
||||
|
||||
<p class="text-xl pb-4 pt-6">
|
||||
Book Reader Settings: Global or Per-Book
|
||||
<i class="pi pi-info-circle text-sky-600"
|
||||
pTooltip="Choose whether you want to apply the same settings (like font, theme, spread, zoom, etc.) to all your books by default, or have individual setting for each book."
|
||||
tooltipPosition="right"
|
||||
style="cursor: pointer;">
|
||||
</i>
|
||||
</p>
|
||||
|
||||
<div class="grid grid-cols-[auto,1fr] pl-6 gap-y-4 gap-x-4 items-center">
|
||||
|
||||
<p class="text-lg py-1">PDF:</p>
|
||||
<div class="flex gap-4 justify-start">
|
||||
<div *ngFor="let item of individualOrGlobal" class="flex items-center gap-2">
|
||||
<p-radiobutton
|
||||
[inputId]="item"
|
||||
name="spread"
|
||||
[value]="item"
|
||||
[(ngModel)]="selectedPdfScope"
|
||||
(ngModelChange)="onPdfScopeChange()">
|
||||
</p-radiobutton>
|
||||
<label [for]="item">{{ item }}</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p class="text-lg py-1">Epub:</p>
|
||||
<div class="flex gap-4 justify-start">
|
||||
<div *ngFor="let item of individualOrGlobal" class="flex items-center gap-2">
|
||||
<p-radiobutton
|
||||
[inputId]="item"
|
||||
name="spread"
|
||||
[value]="item"
|
||||
[(ngModel)]="selectedEpubScope"
|
||||
(ngModelChange)="onEpubScopeChange()">
|
||||
</p-radiobutton>
|
||||
<label [for]="item">{{ item }}</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p-divider></p-divider>
|
||||
|
||||
<p class="text-xl pb-6 pt-6">
|
||||
PDF Reader: Global Preferences
|
||||
<i class="pi pi-info-circle text-sky-600"
|
||||
pTooltip="These settings apply globally to all PDFs. You can customize how PDFs are displayed, including page spread type, zoom level, and sidebar visibility."
|
||||
tooltipPosition="right"
|
||||
style="cursor: pointer;"></i>
|
||||
</p>
|
||||
|
||||
<div class="grid grid-cols-[auto,1fr] pl-6 gap-y-4 gap-x-4 items-center">
|
||||
|
||||
<p class="text-lg 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 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>
|
||||
</div>
|
||||
|
||||
<p-divider></p-divider>
|
||||
|
||||
<p class="text-xl pb-6 pt-6">
|
||||
Epub Reader: Global Preferences
|
||||
<i class="pi pi-info-circle text-sky-600"
|
||||
pTooltip="These settings apply globally to all EPUBs. Customize how EPUBs are displayed, including themes, font types, and font sizes." tooltipPosition="right"
|
||||
style="cursor: pointer;"></i>
|
||||
</p>
|
||||
|
||||
<div class="grid grid-cols-[auto,1fr] pl-6 gap-y-4 gap-x-4 items-center">
|
||||
|
||||
<p class="text-lg">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:</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 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>
|
||||
</div>
|
||||
@@ -0,0 +1,3 @@
|
||||
.enclosing-container {
|
||||
border-color: var(--p-content-border-color);
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
import {Component, inject, OnInit} from '@angular/core';
|
||||
import {Observable} from 'rxjs';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {NgForOf} from '@angular/common';
|
||||
import {Select} from 'primeng/select';
|
||||
import {RadioButton} from 'primeng/radiobutton';
|
||||
import {Divider} from 'primeng/divider';
|
||||
import {Button} from 'primeng/button';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {User, UserBookPreferences, UserService} from '../../user.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-book-preferences',
|
||||
templateUrl: './book-preferences.component.html',
|
||||
standalone: true,
|
||||
styleUrls: ['./book-preferences.component.scss'],
|
||||
imports: [Select, FormsModule, NgForOf, RadioButton, Divider, Button, Tooltip]
|
||||
})
|
||||
export class BookPreferences implements OnInit {
|
||||
readonly spreads = [
|
||||
{ name: 'Even Spread', key: 'even' },
|
||||
{ name: 'Odd Spread', key: 'odd' },
|
||||
{ name: 'No Spread', key: 'off' }
|
||||
];
|
||||
|
||||
readonly zooms = [
|
||||
{ name: 'Auto Zoom', key: 'auto' },
|
||||
{ name: 'Page Fit', key: 'page-fit' },
|
||||
{ name: 'Page Width', key: 'page-width' },
|
||||
{ name: 'Actual Size', key: 'page-actual' }
|
||||
];
|
||||
|
||||
readonly themes = [
|
||||
{ name: 'White', key: 'white' },
|
||||
{ name: 'Black', key: 'black' },
|
||||
{ name: 'Grey', key: 'grey' },
|
||||
{ name: 'Sepia', key: 'sepia' }
|
||||
];
|
||||
|
||||
readonly fonts = [
|
||||
{ name: 'Serif', key: 'serif' },
|
||||
{ name: 'Sans Serif', key: 'sans-serif' },
|
||||
{ name: 'Roboto', key: 'roboto' },
|
||||
{ name: 'Cursive', key: 'cursive' },
|
||||
{ name: 'Monospace', key: 'monospace' }
|
||||
];
|
||||
|
||||
readonly individualOrGlobal = ['Global', 'Individual'];
|
||||
|
||||
selectedSpread!: 'off' | 'even' | 'odd';
|
||||
selectedZoom!: string;
|
||||
showSidebar = false;
|
||||
selectedTheme!: string;
|
||||
fontSize = 100;
|
||||
selectedFont!: string;
|
||||
selectedPdfScope!: string;
|
||||
selectedEpubScope!: string;
|
||||
|
||||
private readonly userService = inject(UserService);
|
||||
userData$: Observable<User | null> = this.userService.userData$;
|
||||
|
||||
ngOnInit(): void {
|
||||
this.userData$.subscribe(userData => {
|
||||
if (userData) this.populateSettings(userData.bookPreferences);
|
||||
});
|
||||
}
|
||||
|
||||
private populateSettings(prefs: UserBookPreferences): void {
|
||||
this.selectedPdfScope = prefs.perBookSetting.pdf;
|
||||
this.selectedEpubScope = prefs.perBookSetting.epub;
|
||||
this.selectedSpread = prefs.pdfReaderSetting.pageSpread;
|
||||
this.selectedZoom = prefs.pdfReaderSetting.pageZoom;
|
||||
this.showSidebar = prefs.pdfReaderSetting.showSidebar;
|
||||
this.selectedTheme = prefs.epubReaderSetting.theme;
|
||||
this.fontSize = prefs.epubReaderSetting.fontSize;
|
||||
this.selectedFont = prefs.epubReaderSetting.font;
|
||||
}
|
||||
|
||||
private updatePreference<T>(updateFn: (prefs: UserBookPreferences) => void): void {
|
||||
const user = this.userService.getLocalUser();
|
||||
if (user) {
|
||||
updateFn(user.bookPreferences);
|
||||
this.userService.updateBookPreferences(user.id, user.bookPreferences);
|
||||
}
|
||||
}
|
||||
|
||||
onThemeChange(): void {
|
||||
this.updatePreference(prefs => prefs.epubReaderSetting.theme = this.selectedTheme);
|
||||
}
|
||||
|
||||
onFontChange(): void {
|
||||
this.updatePreference(prefs => prefs.epubReaderSetting.font = this.selectedFont);
|
||||
}
|
||||
|
||||
onSpreadChange(): void {
|
||||
this.updatePreference(prefs => prefs.pdfReaderSetting.pageSpread = this.selectedSpread);
|
||||
}
|
||||
|
||||
onZoomChange(): void {
|
||||
this.updatePreference(prefs => prefs.pdfReaderSetting.pageZoom = this.selectedZoom);
|
||||
}
|
||||
|
||||
onFontSizeChange(): void {
|
||||
this.updatePreference(prefs => prefs.epubReaderSetting.fontSize = this.fontSize);
|
||||
}
|
||||
|
||||
onPdfScopeChange(): void {
|
||||
this.updatePreference(prefs => prefs.perBookSetting.pdf = this.selectedPdfScope);
|
||||
}
|
||||
|
||||
onEpubScopeChange(): void {
|
||||
this.updatePreference(prefs => prefs.perBookSetting.epub = this.selectedEpubScope);
|
||||
}
|
||||
|
||||
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,62 @@
|
||||
<div class="w-full h-[calc(100vh-12.1rem)] overflow-y-auto border rounded-lg p-4 enclosing-container">
|
||||
|
||||
<p class="text-xl pb-4 pt-6">Book Cover Image</p>
|
||||
<div class="grid grid-cols-[auto,1fr] pl-6 gap-y-4 gap-x-4 items-center">
|
||||
<p class="text-lg py-1">Resolution:
|
||||
<i class="pi pi-info-circle text-sky-600"
|
||||
pTooltip="Specifies the resolution of the generated cover image. Higher resolutions result in sharper images but may increase file size. This setting will apply to future books, or else use 'Regenerate' button."
|
||||
tooltipPosition="right"
|
||||
style="cursor: pointer;">
|
||||
</i>
|
||||
</p>
|
||||
<div class="flex gap-4 justify-start">
|
||||
<p-select
|
||||
[options]="resolutionOptions"
|
||||
[(ngModel)]="selectedResolution"
|
||||
(ngModelChange)="onResolutionChange()"
|
||||
placeholder="Select Resolution">
|
||||
</p-select>
|
||||
</div>
|
||||
|
||||
<p class="text-lg py-1">Regenerate Covers?
|
||||
<i class="pi pi-info-circle text-sky-600"
|
||||
pTooltip="This option will regenerate the covers for all EPUB and PDF books (except locked ones) using the selected resolution."
|
||||
tooltipPosition="right"
|
||||
style="cursor: pointer;">
|
||||
</i>
|
||||
</p>
|
||||
<p-button label="Regenerate" icon="pi pi-refresh" (onClick)="regenerateCovers()"></p-button>
|
||||
</div>
|
||||
|
||||
<p-divider></p-divider>
|
||||
|
||||
<p class="text-xl pb-4 pt-8">Auto Book Search
|
||||
<i class="pi pi-info-circle text-sky-600"
|
||||
pTooltip="If enabled, Booklore will automatically perform a metadata match/search when the book information tab is opened."
|
||||
tooltipPosition="right"
|
||||
style="cursor: pointer;">
|
||||
</i>
|
||||
</p>
|
||||
<div class="grid grid-cols-[auto,1fr] pl-6 gap-y-4 gap-x-4 items-center">
|
||||
<p class="text-lg py-1">Enable:</p>
|
||||
<div class="flex gap-4 justify-start">
|
||||
<p-toggleswitch
|
||||
[(ngModel)]="autoMetadataChecked"
|
||||
(onChange)="onAutoMetaChange($event)"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p-divider></p-divider>
|
||||
|
||||
<p class="text-xl pb-4 pt-8">
|
||||
Quick Book Match Preferences
|
||||
<i class="pi pi-info-circle text-sky-600"
|
||||
pTooltip="Choose how metadata fields (title, description, authors, categories, cover) are retrieved by setting priority providers. You can apply the same provider settings to all fields or customize them individually. Enable ‘Refresh Covers’ to update book covers, and ‘Merge Categories’ to consolidate categories/genres from all sources while preserving the existing categories/genres in the book."
|
||||
tooltipPosition="right"
|
||||
style="cursor: pointer;">
|
||||
</i>
|
||||
</p>
|
||||
<app-metadata-advanced-fetch-options (metadataOptionsSubmitted)="onMetadataSubmit($event)" [currentMetadataOptions]="currentMetadataOptions"></app-metadata-advanced-fetch-options>
|
||||
|
||||
</div>
|
||||
@@ -0,0 +1,3 @@
|
||||
.enclosing-container {
|
||||
border-color: var(--p-content-border-color);
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
import {Component, inject, OnInit} from '@angular/core';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {Observable} from 'rxjs';
|
||||
|
||||
import {Divider} from 'primeng/divider';
|
||||
import {DropdownModule} from 'primeng/dropdown';
|
||||
import {Select} from 'primeng/select';
|
||||
import {Button} from 'primeng/button';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {ToggleSwitch} from 'primeng/toggleswitch';
|
||||
import {MessageService} from 'primeng/api';
|
||||
|
||||
import {AppSettingsService} from '../../core/service/app-settings.service';
|
||||
import {BookService} from '../../book/service/book.service';
|
||||
import {AppSettings} from '../../core/model/app-settings.model';
|
||||
import {MetadataRefreshOptions} from '../../metadata/model/request/metadata-refresh-options.model';
|
||||
import {MetadataAdvancedFetchOptionsComponent} from '../../metadata/metadata-options-dialog/metadata-advanced-fetch-options/metadata-advanced-fetch-options.component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-global-preferences',
|
||||
standalone: true,
|
||||
imports: [
|
||||
Divider,
|
||||
DropdownModule,
|
||||
Select,
|
||||
Button,
|
||||
Tooltip,
|
||||
ToggleSwitch,
|
||||
FormsModule,
|
||||
MetadataAdvancedFetchOptionsComponent
|
||||
],
|
||||
templateUrl: './global-preferences.component.html',
|
||||
styleUrl: './global-preferences.component.scss'
|
||||
})
|
||||
export class GlobalPreferencesComponent implements OnInit {
|
||||
resolutionOptions = [
|
||||
{label: '250x350', value: '250x350'},
|
||||
{label: '375x525', value: '375x525'},
|
||||
{label: '500x700', value: '500x700'},
|
||||
{label: '625x875', value: '625x875'}
|
||||
];
|
||||
|
||||
selectedResolution = '250x350';
|
||||
currentMetadataOptions!: MetadataRefreshOptions;
|
||||
autoMetadataChecked = false;
|
||||
|
||||
private appSettingsService = inject(AppSettingsService);
|
||||
private bookService = inject(BookService);
|
||||
private messageService = inject(MessageService);
|
||||
|
||||
appSettings$: Observable<AppSettings | null> = this.appSettingsService.appSettings$;
|
||||
|
||||
ngOnInit(): void {
|
||||
this.appSettings$.subscribe(settings => {
|
||||
if (settings?.coverSettings) {
|
||||
this.selectedResolution = settings.coverSettings.resolution;
|
||||
}
|
||||
if (settings?.metadataRefreshOptions) {
|
||||
this.currentMetadataOptions = settings.metadataRefreshOptions;
|
||||
}
|
||||
this.autoMetadataChecked = settings?.autoBookSearch ?? false;
|
||||
});
|
||||
}
|
||||
|
||||
onResolutionChange(): void {
|
||||
if (this.selectedResolution) {
|
||||
this.saveSetting('cover_image_resolution', this.selectedResolution);
|
||||
}
|
||||
}
|
||||
|
||||
onAutoMetaChange(event: { checked: boolean }): void {
|
||||
this.saveSetting('auto_book_search', event.checked);
|
||||
}
|
||||
|
||||
onMetadataSubmit(metadataRefreshOptions: MetadataRefreshOptions): void {
|
||||
this.saveSetting('quick_book_match', metadataRefreshOptions);
|
||||
}
|
||||
|
||||
regenerateCovers(): void {
|
||||
this.bookService.regenerateCovers().subscribe({
|
||||
next: () =>
|
||||
this.showMessage('success', 'Cover Regeneration Started', 'Book covers are being regenerated.'),
|
||||
error: () =>
|
||||
this.showMessage('error', 'Error', 'Failed to start cover regeneration.')
|
||||
});
|
||||
}
|
||||
|
||||
private saveSetting(key: string, value: unknown): void {
|
||||
this.appSettingsService.saveSettings([{key, newValue: value}]).subscribe({
|
||||
next: () =>
|
||||
this.showMessage('success', 'Settings Saved', 'The settings were successfully saved!'),
|
||||
error: () =>
|
||||
this.showMessage('error', 'Error', 'There was an error saving the settings.')
|
||||
});
|
||||
}
|
||||
|
||||
private showMessage(severity: 'success' | 'error', summary: string, detail: string): void {
|
||||
this.messageService.add({severity, summary, detail});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<div class="card" *ngIf="userService.userData$ | async as userData">
|
||||
<p-tabs value="0">
|
||||
<p-tablist>
|
||||
<p-tab value="0">Book Preferences</p-tab>
|
||||
<ng-container *ngIf="userData.permissions.admin">
|
||||
<p-tab value="1">User Management</p-tab>
|
||||
</ng-container>
|
||||
<ng-container *ngIf="userData.permissions.admin">
|
||||
<p-tab value="2">Email</p-tab>
|
||||
</ng-container>
|
||||
<ng-container *ngIf="userData.permissions.admin">
|
||||
<p-tab value="3">Global Preferences</p-tab>
|
||||
</ng-container>
|
||||
</p-tablist>
|
||||
|
||||
<p-tabpanels>
|
||||
<p-tabpanel value="0">
|
||||
<app-book-preferences></app-book-preferences>
|
||||
</p-tabpanel>
|
||||
<ng-container *ngIf="userData.permissions.admin">
|
||||
<p-tabpanel value="1">
|
||||
<app-admin></app-admin>
|
||||
</p-tabpanel>
|
||||
</ng-container>
|
||||
<ng-container *ngIf="userData.permissions.admin">
|
||||
<p-tabpanel value="2">
|
||||
<app-email></app-email>
|
||||
</p-tabpanel>
|
||||
</ng-container>
|
||||
<ng-container *ngIf="userData.permissions.admin">
|
||||
<p-tabpanel value="3">
|
||||
<app-global-preferences></app-global-preferences>
|
||||
</p-tabpanel>
|
||||
</ng-container>
|
||||
</p-tabpanels>
|
||||
</p-tabs>
|
||||
</div>
|
||||
@@ -0,0 +1,32 @@
|
||||
import {Component, inject} from '@angular/core';
|
||||
import {Tab, TabList, TabPanel, TabPanels, Tabs} from 'primeng/tabs';
|
||||
import {BookPreferences} from './book-preferences/book-preferences.component';
|
||||
import {AdminComponent} from './admin/admin.component';
|
||||
import {UserService} from '../user.service';
|
||||
import {AsyncPipe, NgIf} from '@angular/common';
|
||||
import {EmailComponent} from './email/email.component';
|
||||
import {GlobalPreferencesComponent} from './global-preferences/global-preferences.component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-settings',
|
||||
imports: [
|
||||
Tabs,
|
||||
TabList,
|
||||
Tab,
|
||||
TabPanels,
|
||||
TabPanel,
|
||||
BookPreferences,
|
||||
AdminComponent,
|
||||
NgIf,
|
||||
AsyncPipe,
|
||||
EmailComponent,
|
||||
GlobalPreferencesComponent
|
||||
],
|
||||
templateUrl: './settings.component.html',
|
||||
styleUrl: './settings.component.scss'
|
||||
})
|
||||
export class SettingsComponent {
|
||||
|
||||
protected userService = inject(UserService);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user