Refactor settings page: standardize styling and reorganize components
- Apply consistent styling across the settings page for a unified look. - Move components into appropriate packages for better project structure.
This commit is contained in:
committed by
Aditya Chandel
parent
3f12d5994f
commit
277b82263d
@@ -7,7 +7,7 @@ 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';
|
||||
import {User, UserBookPreferences, UserService} from '../user-management/user.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-book-preferences',
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
tooltipPosition="right"
|
||||
style="cursor: pointer;"></i>
|
||||
</h2>
|
||||
<p-button outlined="true" label="Create New Provider" (onClick)="openCreateProviderDialog()"></p-button>
|
||||
<p-button outlined="true" icon="pi pi-plus" label="Create New Provider" (onClick)="openCreateProviderDialog()"></p-button>
|
||||
</div>
|
||||
|
||||
<p-table [value]="emailProviders">
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
tooltipPosition="right"
|
||||
style="cursor: pointer;"></i>
|
||||
</h2>
|
||||
<p-button outlined="true" label="Add New Recipient" (onClick)="openAddRecipientDialog()"></p-button>
|
||||
<p-button outlined="true" icon="pi pi-plus" label="Add New Recipient" (onClick)="openAddRecipientDialog()"></p-button>
|
||||
</div>
|
||||
|
||||
<p-table [value]="recipientEmails">
|
||||
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
<p class="text-xl">
|
||||
Uploaded Files Pattern
|
||||
<i class="pi pi-info-circle text-sky-600"
|
||||
pTooltip="Define a naming pattern for future uploads using available metadata. Existing files will remain unchanged."
|
||||
tooltipPosition="right"
|
||||
style="cursor: pointer;">
|
||||
</i>
|
||||
</p>
|
||||
<div class="flex flex-col space-y-6 p-4 m-4 custom-border">
|
||||
<div>
|
||||
<h2 class="mb-3 text-lg">Enter Custom File Naming Pattern:</h2>
|
||||
<div class="flex gap-4 items-center">
|
||||
<input
|
||||
type="text"
|
||||
[(ngModel)]="uploadPattern"
|
||||
class="p-inputtext w-[500px]"
|
||||
placeholder="e.g., {title} - {authors}"
|
||||
(input)="onPatternChange(uploadPattern)"
|
||||
/>
|
||||
<p-button
|
||||
label="Save"
|
||||
icon="pi pi-check"
|
||||
(onClick)="savePattern()"
|
||||
severity="primary"
|
||||
outlined="true"
|
||||
[disabled]="!!errorMessage">
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<h3 class="mb-2">Preview:</h3>
|
||||
<p class="text-lg text-green-500">{{ generatePreview() }}</p>
|
||||
</div>
|
||||
|
||||
<div class="text-gray-400">
|
||||
<h3 class="mb-1 font-bold">Example Patterns:</h3>
|
||||
<div class="overflow-x-auto">
|
||||
<table class=" table-auto">
|
||||
<colgroup>
|
||||
<col style="width: auto;"/>
|
||||
<col style="width: 20px;"/>
|
||||
<col/>
|
||||
</colgroup>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td class="pr-2 break-words text-left">{title} - {authors}/filename.pdf</td>
|
||||
<td class="text-gray-300 text-center">→</td>
|
||||
<td class="pl-2 break-words text-left">/The Book Thief - Markus Zusak/filename.pdf</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="pr-2 break-words text-left">{title}/{authors}/filename.pdf</td>
|
||||
<td class="text-gray-300 text-center">→</td>
|
||||
<td class="pl-2 break-words text-left">/The Book Thief/Markus Zusak/filename.pdf</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="pr-2 break-words text-left">{title} ({authors})/filename.pdf</td>
|
||||
<td class="text-gray-300 text-center">→</td>
|
||||
<td class="pl-2 break-words text-left">/The Book Thief (Markus Zusak)/filename.pdf</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="pr-2 break-words text-left">{title}/filename.pdf</td>
|
||||
<td class="text-gray-300 text-center">→</td>
|
||||
<td class="pl-2 break-words text-left">/The Book Thief/filename.pdf</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="pr-2 break-words text-left">EMPTY</td>
|
||||
<td class="text-gray-300 text-center">→</td>
|
||||
<td class="pl-2 break-words text-left">/filename.pdf</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="text text-gray-400">
|
||||
<strong>Note:</strong>
|
||||
<ul class="list-disc pl-6">
|
||||
<li>Only the placeholders {title} and {authors} are supported. These values will be extracted from the metadata of the uploaded PDF or EPUB file.</li>
|
||||
<li>Multiple authors will be joined using commas.</li>
|
||||
<li>If <code>{title}</code> is used but is missing in uploaded book's metadata, the path will fall back to <code>/filename.pdf</code>.</li>
|
||||
<li>If <code>{authors}</code> is used but is missing in uploaded book's metadata, the path will fall back to <code>{title}/filename.pdf</code> if the title exists, otherwise <code>/filename.pdf</code>.
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
.custom-border {
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: var(--card-border);
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
import {Component, inject, OnInit} from '@angular/core';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {Button} from 'primeng/button';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {AppSettingsService} from '../../../core/service/app-settings.service';
|
||||
import {Observable} from 'rxjs';
|
||||
import {AppSettings} from '../../../core/model/app-settings.model';
|
||||
import {filter, take} from 'rxjs/operators';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
|
||||
@Component({
|
||||
selector: 'app-file-upload-pattern',
|
||||
templateUrl: './file-upload-pattern.component.html',
|
||||
standalone: true,
|
||||
imports: [FormsModule, Button, Tooltip],
|
||||
styleUrls: ['./file-upload-pattern.component.scss']
|
||||
})
|
||||
export class FileUploadPatternComponent implements OnInit {
|
||||
title: string = 'The Book Thief';
|
||||
authors: string = 'Markus Zusak';
|
||||
uploadPattern: string = '';
|
||||
errorMessage: string = '';
|
||||
|
||||
private appSettingsService = inject(AppSettingsService);
|
||||
private messageService = inject(MessageService);
|
||||
|
||||
appSettings$: Observable<AppSettings | null> = this.appSettingsService.appSettings$;
|
||||
|
||||
ngOnInit(): void {
|
||||
this.appSettings$.pipe(
|
||||
filter(settings => settings != null),
|
||||
take(1)
|
||||
).subscribe(settings => {
|
||||
this.uploadPattern = settings?.uploadPattern || '';
|
||||
});
|
||||
}
|
||||
|
||||
generatePreview(): string {
|
||||
let path = this.uploadPattern
|
||||
.replace('{title}', this.title)
|
||||
.replace('{authors}', this.authors)
|
||||
.replace(/\/+$/, '')
|
||||
.trim();
|
||||
|
||||
return path ? `/${path}/filename.pdf` : '/filename.pdf';
|
||||
}
|
||||
|
||||
validatePattern(pattern: string): void {
|
||||
const isValid = /^[\w\s\-{}\/().]*$/.test(pattern);
|
||||
this.errorMessage = isValid ? '' : 'Pattern contains invalid characters.';
|
||||
}
|
||||
|
||||
onPatternChange(pattern: string): void {
|
||||
this.uploadPattern = pattern;
|
||||
this.validatePattern(pattern);
|
||||
}
|
||||
|
||||
savePattern(): void {
|
||||
this.saveSetting('upload_file_pattern', this.uploadPattern);
|
||||
}
|
||||
|
||||
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});
|
||||
}
|
||||
}
|
||||
@@ -1,38 +1,54 @@
|
||||
<div class="w-full h-[calc(100vh-12.1rem)] overflow-y-auto border rounded-lg p-4 enclosing-container">
|
||||
<div class="w-full h-[calc(100vh-12.1rem)] overflow-y-auto border rounded-lg 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:
|
||||
<div class="p-4">
|
||||
<div class="flex items-center gap-2 pb-4 pt-6">
|
||||
<p class="text-xl">Book Cover Image</p>
|
||||
<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."
|
||||
pTooltip="Settings related to book cover images, such as resolution and regeneration options."
|
||||
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 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"
|
||||
outlined="true"
|
||||
(onClick)="regenerateCovers()"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p-divider></p-divider>
|
||||
<div class="pt-2 pb-6">
|
||||
<p-divider></p-divider>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-row gap-11">
|
||||
<div class="flex flex-row gap-11 p-4">
|
||||
<div>
|
||||
<p class="text-xl pb-4 pt-8">Auto Book Search
|
||||
<p class="text-xl pb-4">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"
|
||||
@@ -50,7 +66,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<p class="text-xl pb-4 pt-8">Similar Book Recommendation
|
||||
<p class="text-xl pb-4">Similar Book Recommendation
|
||||
<i class="pi pi-info-circle text-sky-600"
|
||||
pTooltip="Enable or disable similar book recommendations entirely."
|
||||
tooltipPosition="right"
|
||||
@@ -69,24 +85,36 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p-divider></p-divider>
|
||||
<div class="pt-2 pb-6">
|
||||
<p-divider></p-divider>
|
||||
</div>
|
||||
|
||||
<app-opds-settings></app-opds-settings>
|
||||
<div class="p-4">
|
||||
<app-opds-settings></app-opds-settings>
|
||||
</div>
|
||||
|
||||
<p-divider></p-divider>
|
||||
<div class="pt-2 pb-6">
|
||||
<p-divider></p-divider>
|
||||
</div>
|
||||
|
||||
<app-file-upload-pattern></app-file-upload-pattern>
|
||||
<div class="p-4">
|
||||
<app-file-upload-pattern></app-file-upload-pattern>
|
||||
</div>
|
||||
|
||||
<p-divider></p-divider>
|
||||
<div class="pt-2 pb-6">
|
||||
<p-divider></p-divider>
|
||||
</div>
|
||||
|
||||
<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 class="p-4">
|
||||
<p class="text-xl">
|
||||
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>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -16,8 +16,8 @@ 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';
|
||||
import {filter, take} from 'rxjs/operators';
|
||||
import {FileUploadPatternComponent} from '../../file-upload-pattern/file-upload-pattern.component';
|
||||
import {OpdsSettingsComponent} from '../../opds-settings/opds-settings.component';
|
||||
import {FileUploadPatternComponent} from './file-upload-pattern/file-upload-pattern.component';
|
||||
import {OpdsSettingsComponent} from './opds-settings/opds-settings.component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-global-preferences',
|
||||
|
||||
+180
@@ -0,0 +1,180 @@
|
||||
<p class="text-xl flex items-center gap-2">
|
||||
OPDS Server Settings
|
||||
<i
|
||||
class="pi pi-info-circle text-sky-600"
|
||||
pTooltip="OPDS allows your book collection to be accessed by compatible reading apps through your private server."
|
||||
tooltipPosition="right"
|
||||
style="cursor: pointer;">
|
||||
</i>
|
||||
</p>
|
||||
<div class="flex flex-col space-y-6 p-4 m-4 custom-border">
|
||||
|
||||
<div class="flex items-center gap-4">
|
||||
<p class="text-lg py-1">OPDS Server Enabled:</p>
|
||||
<p-toggleswitch
|
||||
[(ngModel)]="opdsEnabled"
|
||||
(onChange)="toggleOpdsServer()">
|
||||
</p-toggleswitch>
|
||||
</div>
|
||||
|
||||
<div *ngIf="opdsEnabled" class="flex items-center gap-2 mt-4">
|
||||
<p class="text-lg py-1">OPDS Endpoint:</p>
|
||||
<div class="flex items-center gap-4">
|
||||
<input
|
||||
class="min-w-[500px] max-w-[800px]"
|
||||
type="text"
|
||||
pInputText
|
||||
[value]="opdsEndpoint"
|
||||
readonly/>
|
||||
<p-button
|
||||
icon="pi pi-copy"
|
||||
severity="info"
|
||||
(onClick)="copyOpdsEndpoint()"
|
||||
label="Copy"
|
||||
outlined="true">
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div *ngIf="opdsEnabled" class="mt-6">
|
||||
|
||||
|
||||
<div class="flex justify-between items-center">
|
||||
<h2 class="text-lg flex items-center gap-2">
|
||||
Current OPDS Users:
|
||||
</h2>
|
||||
<p-button
|
||||
label="Create OPDS User"
|
||||
icon="pi pi-plus"
|
||||
outlined="true"
|
||||
(onClick)="openCreateUserDialog()">
|
||||
</p-button>
|
||||
</div>
|
||||
|
||||
<div class="mt-3">
|
||||
<p-table [value]="users" [responsiveLayout]="'scroll'">
|
||||
<ng-template pTemplate="header">
|
||||
<tr>
|
||||
<th>Username</th>
|
||||
<th>Password</th>
|
||||
<th>Reset Password</th>
|
||||
<th>Delete</th>
|
||||
</tr>
|
||||
</ng-template>
|
||||
<ng-template pTemplate="body" let-user>
|
||||
<tr>
|
||||
<td>{{ user.username }}</td>
|
||||
<td class="flex items-center gap-2">
|
||||
<p-password
|
||||
[(ngModel)]="dummyPassword"
|
||||
[disabled]="true">
|
||||
</p-password>
|
||||
<i
|
||||
class="pi pi-info-circle text-sky-600"
|
||||
pTooltip="The password is hidden for security reasons and is only visible once during creation. You can reset the password if needed."
|
||||
tooltipPosition="right"
|
||||
style="cursor: pointer;">
|
||||
</i>
|
||||
</td>
|
||||
<td>
|
||||
<p-button
|
||||
icon="pi pi-key"
|
||||
severity="warn"
|
||||
size="small"
|
||||
outlined="true"
|
||||
(onClick)="openResetPasswordDialog(user)">
|
||||
</p-button>
|
||||
</td>
|
||||
<td>
|
||||
<p-button
|
||||
icon="pi pi-trash"
|
||||
severity="danger"
|
||||
size="small"
|
||||
outlined="true"
|
||||
(onClick)="deleteUser(user.id)">
|
||||
</p-button>
|
||||
</td>
|
||||
</tr>
|
||||
</ng-template>
|
||||
</p-table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p-dialog
|
||||
header="Create New OPDS User"
|
||||
[(visible)]="createUserDialogVisible"
|
||||
[modal]="true"
|
||||
[style]="{ width: '400px' }">
|
||||
<div>
|
||||
<div>
|
||||
<label for="username">Username</label>
|
||||
<input id="username" type="text" pInputText [(ngModel)]="newUser.username" class="w-full"/>
|
||||
</div>
|
||||
|
||||
<div class="mt-4">
|
||||
<div class="flex items-center gap-2">
|
||||
<label for="password">Password</label>
|
||||
<i
|
||||
class="pi pi-info-circle text-yellow-500"
|
||||
pTooltip="Password can only be seen now. It won’t be retrievable later. Please save it securely."
|
||||
tooltipPosition="right"
|
||||
style="cursor: pointer;">
|
||||
</i>
|
||||
</div>
|
||||
<input id="password" pInputText [(ngModel)]="newUser.password" class="w-full"/>
|
||||
</div>
|
||||
|
||||
<div class="flex justify-end mt-6 gap-4">
|
||||
<p-button
|
||||
label="Cancel"
|
||||
icon="pi pi-times"
|
||||
severity="secondary"
|
||||
(onClick)="cancelCreateUser()">
|
||||
</p-button>
|
||||
<p-button
|
||||
label="Save"
|
||||
icon="pi pi-check"
|
||||
severity="success"
|
||||
(onClick)="saveNewUser()">
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
</p-dialog>
|
||||
|
||||
<p-dialog
|
||||
header="Reset User Password"
|
||||
[(visible)]="resetPasswordDialogVisible"
|
||||
[modal]="true"
|
||||
[style]="{ width: '400px' }">
|
||||
<div>
|
||||
<p class="mb-6 mt-2">Reset password for: <b>{{ selectedUser?.username }}</b></p>
|
||||
<div>
|
||||
<div class="flex items-center">
|
||||
<label for="newPassword">New Password</label>
|
||||
<i
|
||||
class="pi pi-info-circle text-yellow-500 ml-2"
|
||||
pTooltip="Password can only be seen now. It won’t be retrievable later. Please save it securely."
|
||||
tooltipPosition="right"
|
||||
style="cursor: pointer;">
|
||||
</i>
|
||||
</div>
|
||||
<input id="newPassword" pInputText [(ngModel)]="newPassword" class="w-full"/>
|
||||
</div>
|
||||
|
||||
<div class="flex justify-end mt-4 gap-4">
|
||||
<p-button
|
||||
label="Cancel"
|
||||
icon="pi pi-times"
|
||||
severity="secondary"
|
||||
(onClick)="cancelResetPassword()">
|
||||
</p-button>
|
||||
<p-button
|
||||
label="Save"
|
||||
icon="pi pi-check"
|
||||
severity="success"
|
||||
(onClick)="confirmResetPassword()">
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
</p-dialog>
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
.custom-border {
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: var(--card-border);
|
||||
}
|
||||
+188
@@ -0,0 +1,188 @@
|
||||
import {Component, inject, OnInit} from '@angular/core';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {NgIf} from '@angular/common';
|
||||
import {TableModule} from 'primeng/table';
|
||||
import {Button} from 'primeng/button';
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
import {Dialog} from 'primeng/dialog';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {filter, take} from 'rxjs/operators';
|
||||
|
||||
import {OpdsUser, OpdsUserService} from './opds-user.service';
|
||||
import {AppSettingsService} from '../../../core/service/app-settings.service';
|
||||
import {AppSettings} from '../../../core/model/app-settings.model';
|
||||
import {Password} from 'primeng/password';
|
||||
import {API_CONFIG} from '../../../config/api-config';
|
||||
import {ToggleSwitch} from 'primeng/toggleswitch';
|
||||
|
||||
@Component({
|
||||
selector: 'app-opds-settings',
|
||||
standalone: true,
|
||||
imports: [
|
||||
FormsModule,
|
||||
NgIf,
|
||||
TableModule,
|
||||
Button,
|
||||
InputText,
|
||||
Dialog,
|
||||
Tooltip,
|
||||
Password,
|
||||
ToggleSwitch
|
||||
],
|
||||
templateUrl: './opds-settings.component.html',
|
||||
styleUrl: './opds-settings.component.scss'
|
||||
})
|
||||
export class OpdsSettingsComponent implements OnInit {
|
||||
opdsEnabled = false;
|
||||
users: OpdsUser[] = [];
|
||||
selectedUser: OpdsUser | null = null;
|
||||
createUserDialogVisible = false;
|
||||
resetPasswordDialogVisible = false;
|
||||
newUser = {username: '', password: ''};
|
||||
newPassword = '';
|
||||
opdsEndpoint: string = `${API_CONFIG.BASE_URL}/api/v1/opds/catalog`;
|
||||
dummyPassword: string = '********************************';
|
||||
|
||||
private readonly appSettings$ = inject(AppSettingsService).appSettings$;
|
||||
private readonly opdsUserService = inject(OpdsUserService);
|
||||
private readonly messageService = inject(MessageService);
|
||||
private readonly appSettingsService = inject(AppSettingsService);
|
||||
|
||||
ngOnInit(): void {
|
||||
this.appSettings$
|
||||
.pipe(
|
||||
filter((settings): settings is AppSettings => settings != null),
|
||||
take(1)
|
||||
)
|
||||
.subscribe(settings => {
|
||||
this.opdsEnabled = settings.opdsServerEnabled ?? false;
|
||||
if (this.opdsEnabled) {
|
||||
this.loadUsers();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
toggleOpdsServer(): void {
|
||||
this.saveSetting('opds_server_enabled', this.opdsEnabled);
|
||||
if (this.opdsEnabled) {
|
||||
this.loadUsers();
|
||||
} else {
|
||||
this.users = [];
|
||||
}
|
||||
}
|
||||
|
||||
loadUsers(): void {
|
||||
this.opdsUserService.getUsers().subscribe({
|
||||
next: (users) => this.users = users,
|
||||
error: () => this.showError('Load Users Failed', 'Unable to fetch users.')
|
||||
});
|
||||
}
|
||||
|
||||
openCreateUserDialog(): void {
|
||||
this.newUser = {username: '', password: ''};
|
||||
this.createUserDialogVisible = true;
|
||||
}
|
||||
|
||||
cancelCreateUser(): void {
|
||||
this.createUserDialogVisible = false;
|
||||
}
|
||||
|
||||
saveNewUser(): void {
|
||||
const {username, password} = this.newUser;
|
||||
|
||||
if (username.trim() && password.trim()) {
|
||||
this.opdsUserService.createUser(this.newUser).subscribe({
|
||||
next: () => {
|
||||
this.createUserDialogVisible = false;
|
||||
this.loadUsers();
|
||||
this.showSuccess('User Created', 'New OPDS user created successfully.');
|
||||
},
|
||||
error: (err) => {
|
||||
const errorMessage = err?.error?.message || 'Unable to create user.';
|
||||
this.showError('Create User Failed', errorMessage);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.showWarning('Invalid Input', 'Username and Password are required.');
|
||||
}
|
||||
}
|
||||
|
||||
openResetPasswordDialog(user: OpdsUser): void {
|
||||
this.selectedUser = user;
|
||||
this.newPassword = '';
|
||||
this.resetPasswordDialogVisible = true;
|
||||
}
|
||||
|
||||
cancelResetPassword(): void {
|
||||
this.resetPasswordDialogVisible = false;
|
||||
this.selectedUser = null;
|
||||
this.newPassword = '';
|
||||
}
|
||||
|
||||
copyOpdsEndpoint() {
|
||||
navigator.clipboard.writeText(this.opdsEndpoint)
|
||||
.then(() => {
|
||||
})
|
||||
.catch(err => {
|
||||
});
|
||||
}
|
||||
|
||||
confirmResetPassword(): void {
|
||||
if (this.selectedUser && this.newPassword.trim()) {
|
||||
this.opdsUserService.resetPassword(this.selectedUser.id, this.newPassword).subscribe({
|
||||
next: () => {
|
||||
this.resetPasswordDialogVisible = false;
|
||||
this.showSuccess('Password Reset', 'User password reset successfully.');
|
||||
},
|
||||
error: (err) => {
|
||||
const errorMessage = err?.error?.message || 'Unable to reset password.';
|
||||
this.showError('Reset Password Failed', errorMessage);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.showWarning('Invalid Input', 'New password is required.');
|
||||
}
|
||||
}
|
||||
|
||||
deleteUser(userId: number): void {
|
||||
this.opdsUserService.deleteUser(userId).subscribe({
|
||||
next: () => {
|
||||
this.loadUsers();
|
||||
this.showSuccess('User Deleted', 'User deleted successfully.');
|
||||
},
|
||||
error: () => {
|
||||
this.showError('Delete User Failed', 'Unable to delete user.');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private saveSetting(key: string, value: unknown): void {
|
||||
this.appSettingsService.saveSettings([{key, newValue: value}]).subscribe({
|
||||
next: () => {
|
||||
let successMessage = 'Settings saved successfully.';
|
||||
if (key === 'opds_server_enabled') {
|
||||
successMessage = (value === true)
|
||||
? 'OPDS Server Enabled.'
|
||||
: 'OPDS Server Disabled.';
|
||||
}
|
||||
this.showSuccess('Settings Saved', successMessage);
|
||||
},
|
||||
error: () => {
|
||||
this.showError('Error', 'There was an error saving the settings.');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private showSuccess(summary: string, detail: string): void {
|
||||
this.messageService.add({severity: 'success', summary, detail});
|
||||
}
|
||||
|
||||
private showError(summary: string, detail: string): void {
|
||||
this.messageService.add({severity: 'error', summary, detail});
|
||||
}
|
||||
|
||||
private showWarning(summary: string, detail: string): void {
|
||||
this.messageService.add({severity: 'warn', summary, detail});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import {inject, Injectable} from '@angular/core';
|
||||
import {API_CONFIG} from '../../../config/api-config';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {Observable} from 'rxjs';
|
||||
|
||||
export interface OpdsUser {
|
||||
id: number;
|
||||
username: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class OpdsUserService {
|
||||
|
||||
private readonly url = `${API_CONFIG.BASE_URL}/api/v1/opds-users`;
|
||||
|
||||
private http = inject(HttpClient);
|
||||
|
||||
constructor() {
|
||||
}
|
||||
|
||||
createUser(userData: Omit<OpdsUser, 'id'>): Observable<void> {
|
||||
return this.http.post<void>(this.url, userData);
|
||||
}
|
||||
|
||||
getUsers(): Observable<OpdsUser[]> {
|
||||
return this.http.get<OpdsUser[]>(this.url);
|
||||
}
|
||||
|
||||
deleteUser(userId: number): Observable<void> {
|
||||
return this.http.delete<void>(`${this.url}/${userId}`);
|
||||
}
|
||||
|
||||
resetPassword(resetPasswordUserId: number, newPassword: string): Observable<void> {
|
||||
const resetPayload = {
|
||||
password: newPassword
|
||||
};
|
||||
return this.http.put<void>(`${this.url}/${resetPasswordUserId}/reset-password`, resetPayload);
|
||||
}
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
<p-divider></p-divider>
|
||||
|
||||
<div class="min-w-[300px] md:min-w-[500px]">
|
||||
|
||||
<section>
|
||||
<div class="flex flex-col gap-4">
|
||||
<h2 class="text-xl font-semibold">User Profile</h2>
|
||||
<div class="px-4 py-2">
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||
<div>
|
||||
<label class="block text-sm font-medium mb-1">Username</label>
|
||||
<p *ngIf="!isEditing" class="text-lg">{{ currentUser?.username || 'N/A' }}</p>
|
||||
<input *ngIf="isEditing" disabled id="username" type="text" pInputText [(ngModel)]="editUserData.username" class="w-full"/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="block text-sm font-medium mb-1">Full Name</label>
|
||||
<p *ngIf="!isEditing" class="text-lg">{{ currentUser?.name || 'N/A' }}</p>
|
||||
<input *ngIf="isEditing" id="fullname" type="text" pInputText [(ngModel)]="editUserData.name" class="w-full"/>
|
||||
</div>
|
||||
|
||||
<div class="md:col-span-2">
|
||||
<label class="block text-sm font-medium mb-1">Email</label>
|
||||
<p *ngIf="!isEditing" class="text-lg">{{ currentUser?.email || 'N/A' }}</p>
|
||||
<input *ngIf="isEditing" id="email" type="email" pInputText [(ngModel)]="editUserData.email" class="w-full"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex justify-start mt-6">
|
||||
<div *ngIf="!isEditing">
|
||||
<p-button label="Edit" severity="info" icon="pi pi-pencil" (onClick)="toggleEdit()"></p-button>
|
||||
</div>
|
||||
<div *ngIf="isEditing" class="flex gap-2">
|
||||
<p-button label="Cancel" severity="secondary" icon="pi pi-times" (onClick)="toggleEdit()"></p-button>
|
||||
<p-button label="Save" severity="success" icon="pi pi-check" (onClick)="updateProfile()"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<p-divider></p-divider>
|
||||
|
||||
<section class="space-y-6 pt-4">
|
||||
<div class="flex flex-col gap-4">
|
||||
<h2 class="text-xl font-semibold">Change Password</h2>
|
||||
<div class="change-password-wrapper">
|
||||
<div class="px-4 py-2">
|
||||
<form [formGroup]="changePasswordForm" (ngSubmit)="submitPasswordChange()">
|
||||
<div class="p-field mb-4">
|
||||
<label for="currentPassword">Current Password</label>
|
||||
<p-password id="currentPassword" formControlName="currentPassword" [feedback]="false" fluid></p-password>
|
||||
<p-message *ngIf="changePasswordForm.get('currentPassword')?.invalid && changePasswordForm.get('currentPassword')?.touched" severity="error" text="Current password is required."></p-message>
|
||||
</div>
|
||||
|
||||
<div class="p-field mb-4">
|
||||
<label for="newPassword">New Password (at least 6 characters)</label>
|
||||
<p-password id="newPassword" formControlName="newPassword" [feedback]="false" fluid></p-password>
|
||||
<p-message *ngIf="changePasswordForm.get('newPassword')?.errors?.['minlength'] && changePasswordForm.get('newPassword')?.touched" severity="error" text="Password must be at least 6 characters long."></p-message>
|
||||
</div>
|
||||
|
||||
<div class="p-field mb-4">
|
||||
<label for="confirmNewPassword">Confirm New Password</label>
|
||||
<p-password id="confirmNewPassword" formControlName="confirmNewPassword" [feedback]="false" fluid></p-password>
|
||||
<p-message *ngIf="passwordsMismatch" severity="error" text="Passwords do not match."></p-message>
|
||||
</div>
|
||||
|
||||
<div class="flex justify-start pt-4">
|
||||
<p-button type="submit" severity="info" label="Change Password" icon="pi pi-key" [disabled]="changePasswordForm.invalid" class="p-fluid"></p-button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
</div>
|
||||
|
||||
<div *ngIf="!currentUser" class="flex items-center justify-center min-h-[50vh] text-lg">
|
||||
Loading user data...
|
||||
</div>
|
||||
+151
@@ -0,0 +1,151 @@
|
||||
import {Component, inject, OnDestroy, OnInit} from '@angular/core';
|
||||
import {Button} from 'primeng/button';
|
||||
import {Divider} from 'primeng/divider';
|
||||
import {FormBuilder, FormGroup, Validators, FormsModule, ReactiveFormsModule} from '@angular/forms';
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
import {NgIf} from '@angular/common';
|
||||
import {Password} from 'primeng/password';
|
||||
import {User, UserService} from '../../user-management/user.service';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {Subscription} from 'rxjs';
|
||||
import {Message} from 'primeng/message';
|
||||
|
||||
@Component({
|
||||
selector: 'app-user-profile-dialog',
|
||||
imports: [
|
||||
Button,
|
||||
Divider,
|
||||
FormsModule,
|
||||
ReactiveFormsModule,
|
||||
InputText,
|
||||
NgIf,
|
||||
Password,
|
||||
Message
|
||||
],
|
||||
templateUrl: './user-profile-dialog.component.html',
|
||||
styleUrls: ['./user-profile-dialog.component.scss']
|
||||
})
|
||||
export class UserProfileDialogComponent implements OnInit, OnDestroy {
|
||||
|
||||
isEditing = false;
|
||||
currentUser: User | null = null;
|
||||
editUserData: Partial<User> = {};
|
||||
private userSubscription: Subscription | null = null;
|
||||
|
||||
changePasswordForm: FormGroup;
|
||||
|
||||
protected readonly userService = inject(UserService);
|
||||
private readonly messageService = inject(MessageService);
|
||||
private readonly fb = inject(FormBuilder);
|
||||
|
||||
constructor() {
|
||||
this.changePasswordForm = this.fb.group(
|
||||
{
|
||||
currentPassword: ['', Validators.required],
|
||||
newPassword: ['', [Validators.required, Validators.minLength(6)]],
|
||||
confirmNewPassword: ['', [Validators.required, Validators.minLength(6)]]
|
||||
},
|
||||
{
|
||||
validators: [UserProfileDialogComponent.passwordsMatchValidator]
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.userSubscription = this.userService.userData$.subscribe(user => {
|
||||
this.currentUser = user;
|
||||
this.resetEditForm();
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.userSubscription?.unsubscribe();
|
||||
}
|
||||
|
||||
static passwordsMatchValidator(form: FormGroup) {
|
||||
const newPassword = form.get('newPassword')?.value;
|
||||
const confirmPassword = form.get('confirmNewPassword')?.value;
|
||||
return newPassword === confirmPassword ? null : {mismatch: true};
|
||||
}
|
||||
|
||||
get passwordsMismatch() {
|
||||
return this.changePasswordForm.hasError('mismatch') &&
|
||||
this.changePasswordForm.get('confirmNewPassword')?.touched;
|
||||
}
|
||||
|
||||
toggleEdit(): void {
|
||||
this.isEditing = !this.isEditing;
|
||||
if (this.isEditing) {
|
||||
this.resetEditForm();
|
||||
}
|
||||
}
|
||||
|
||||
resetEditForm(): void {
|
||||
if (this.currentUser) {
|
||||
this.editUserData = {
|
||||
username: this.currentUser.username,
|
||||
name: this.currentUser.name,
|
||||
email: this.currentUser.email,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
updateProfile(): void {
|
||||
if (!this.currentUser) {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Error',
|
||||
detail: 'User data not available.',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.editUserData.name === this.currentUser.name && this.editUserData.email === this.currentUser.email) {
|
||||
this.messageService.add({severity: 'info', summary: 'Info', detail: 'No changes detected.'});
|
||||
this.isEditing = false;
|
||||
return;
|
||||
}
|
||||
|
||||
this.userService.updateUser(this.currentUser.id, this.editUserData).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({severity: 'success', summary: 'Success', detail: 'Profile updated successfully'});
|
||||
this.isEditing = false;
|
||||
this.resetEditForm();
|
||||
},
|
||||
error: (err) => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Error',
|
||||
detail: err.error?.message || 'Failed to update profile',
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
submitPasswordChange(): void {
|
||||
if (this.changePasswordForm.invalid) {
|
||||
this.changePasswordForm.markAllAsTouched();
|
||||
return;
|
||||
}
|
||||
|
||||
const {currentPassword, newPassword} = this.changePasswordForm.value;
|
||||
|
||||
this.userService.changePassword(currentPassword, newPassword).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({severity: 'success', summary: 'Success', detail: 'Password changed successfully'});
|
||||
this.resetPasswordForm();
|
||||
},
|
||||
error: (err) => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Error',
|
||||
detail: err?.message || 'Failed to change password',
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
resetPasswordForm(): void {
|
||||
this.changePasswordForm.reset();
|
||||
}
|
||||
}
|
||||
@@ -1,29 +1,31 @@
|
||||
<div class="card" *ngIf="userService.userData$ | async as userData">
|
||||
<p-tabs [(value)]="activeTab">
|
||||
<p-tablist>
|
||||
<p-tab [value]="SettingsTab.BookReader">Book Reader</p-tab>
|
||||
<ng-container *ngIf="userData.permissions.admin">
|
||||
<p-tab [value]="SettingsTab.UserManagement">User Management</p-tab>
|
||||
<p-tab [value]="SettingsTab.Email">Email</p-tab>
|
||||
<p-tab [value]="SettingsTab.GlobalSettings">Global Settings</p-tab>
|
||||
</ng-container>
|
||||
</p-tablist>
|
||||
<div *ngIf="userService.userData$ | async as userData">
|
||||
<div class="rounded-xl overflow-hidden">
|
||||
<p-tabs [(value)]="activeTab">
|
||||
<p-tablist>
|
||||
<p-tab [value]="SettingsTab.BookReader">Book Reader</p-tab>
|
||||
<ng-container *ngIf="userData.permissions.admin">
|
||||
<p-tab [value]="SettingsTab.UserManagement">User Management</p-tab>
|
||||
<p-tab [value]="SettingsTab.Email">Email Setting</p-tab>
|
||||
<p-tab [value]="SettingsTab.GlobalSettings">Other Settings</p-tab>
|
||||
</ng-container>
|
||||
</p-tablist>
|
||||
|
||||
<p-tabpanels>
|
||||
<p-tabpanel [value]="SettingsTab.BookReader">
|
||||
<app-book-preferences></app-book-preferences>
|
||||
</p-tabpanel>
|
||||
<ng-container *ngIf="userData.permissions.admin">
|
||||
<p-tabpanel [value]="SettingsTab.UserManagement">
|
||||
<app-admin></app-admin>
|
||||
<p-tabpanels>
|
||||
<p-tabpanel [value]="SettingsTab.BookReader">
|
||||
<app-book-preferences></app-book-preferences>
|
||||
</p-tabpanel>
|
||||
<p-tabpanel [value]="SettingsTab.Email">
|
||||
<app-email></app-email>
|
||||
</p-tabpanel>
|
||||
<p-tabpanel [value]="SettingsTab.GlobalSettings">
|
||||
<app-global-preferences></app-global-preferences>
|
||||
</p-tabpanel>
|
||||
</ng-container>
|
||||
</p-tabpanels>
|
||||
</p-tabs>
|
||||
<ng-container *ngIf="userData.permissions.admin">
|
||||
<p-tabpanel [value]="SettingsTab.UserManagement">
|
||||
<app-user-management></app-user-management>
|
||||
</p-tabpanel>
|
||||
<p-tabpanel [value]="SettingsTab.Email">
|
||||
<app-email></app-email>
|
||||
</p-tabpanel>
|
||||
<p-tabpanel [value]="SettingsTab.GlobalSettings">
|
||||
<app-global-preferences></app-global-preferences>
|
||||
</p-tabpanel>
|
||||
</ng-container>
|
||||
</p-tabpanels>
|
||||
</p-tabs>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import {Component, inject, OnDestroy, OnInit} 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 {UserService} from './user-management/user.service';
|
||||
import {AsyncPipe, NgIf} from '@angular/common';
|
||||
import {EmailComponent} from './email/email.component';
|
||||
import {GlobalPreferencesComponent} from './global-preferences/global-preferences.component';
|
||||
import {ActivatedRoute, Router} from '@angular/router';
|
||||
import {Subscription} from 'rxjs';
|
||||
import {UserManagementComponent} from './user-management/user-management.component';
|
||||
|
||||
export enum SettingsTab {
|
||||
BookReader = 'book-reader',
|
||||
@@ -25,11 +25,11 @@ export enum SettingsTab {
|
||||
TabPanels,
|
||||
TabPanel,
|
||||
BookPreferences,
|
||||
AdminComponent,
|
||||
NgIf,
|
||||
AsyncPipe,
|
||||
EmailComponent,
|
||||
GlobalPreferencesComponent
|
||||
GlobalPreferencesComponent,
|
||||
UserManagementComponent
|
||||
],
|
||||
templateUrl: './settings.component.html',
|
||||
styleUrl: './settings.component.scss'
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ 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 {UserService} from '../user.service';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {NgIf} from '@angular/common';
|
||||
+10
-4
@@ -1,5 +1,11 @@
|
||||
<div class="p-4">
|
||||
<p-button outlined="true" label="Create User" (onClick)="openCreateUserDialog()"></p-button>
|
||||
<div class="w-full h-[calc(100vh-12.1rem)] overflow-y-auto border rounded-lg p-4 enclosing-container">
|
||||
|
||||
<div class="flex justify-between items-center pb-2 pt-4">
|
||||
<h2 class="text-xl flex items-center gap-2">
|
||||
Current Booklore Users
|
||||
</h2>
|
||||
<p-button outlined="true" label="Create BookLore User" icon="pi pi-plus" (onClick)="openCreateUserDialog()"></p-button>
|
||||
</div>
|
||||
|
||||
<p-table [value]="users" class="mt-4">
|
||||
<ng-template pTemplate="header">
|
||||
@@ -88,8 +94,8 @@
|
||||
|
||||
<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-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>
|
||||
@@ -0,0 +1,3 @@
|
||||
.enclosing-container {
|
||||
border-color: var(--p-content-border-color);
|
||||
}
|
||||
+7
-5
@@ -5,7 +5,7 @@ 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 {User, UserService} from './user.service';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {Checkbox} from 'primeng/checkbox';
|
||||
import {MultiSelect} from 'primeng/multiselect';
|
||||
@@ -13,9 +13,10 @@ import {Library} from '../../book/model/library.model';
|
||||
import {LibraryService} from '../../book/service/library.service';
|
||||
import {Dialog} from 'primeng/dialog';
|
||||
import {Password} from 'primeng/password';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
|
||||
@Component({
|
||||
selector: 'app-admin',
|
||||
selector: 'app-user-management',
|
||||
imports: [
|
||||
FormsModule,
|
||||
Button,
|
||||
@@ -26,11 +27,12 @@ import {Password} from 'primeng/password';
|
||||
MultiSelect,
|
||||
Dialog,
|
||||
Password,
|
||||
Tooltip,
|
||||
],
|
||||
templateUrl: './admin.component.html',
|
||||
styleUrls: ['./admin.component.scss'],
|
||||
templateUrl: './user-management.component.html',
|
||||
styleUrls: ['./user-management.component.scss'],
|
||||
})
|
||||
export class AdminComponent implements OnInit {
|
||||
export class UserManagementComponent implements OnInit {
|
||||
ref: DynamicDialogRef | undefined;
|
||||
private dialogService = inject(DialogService);
|
||||
private userService = inject(UserService);
|
||||
@@ -0,0 +1,148 @@
|
||||
import {inject, Injectable, Injector} from '@angular/core';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {BehaviorSubject, Observable, tap, throwError} from 'rxjs';
|
||||
import {API_CONFIG} from '../../config/api-config';
|
||||
import {RxStompService} from '../../shared/websocket/rx-stomp.service';
|
||||
import {Library} from '../../book/model/library.model';
|
||||
import {catchError} from 'rxjs/operators';
|
||||
|
||||
export interface User {
|
||||
id: number;
|
||||
username: string;
|
||||
name: string;
|
||||
email: string;
|
||||
assignedLibraries: Library[];
|
||||
permissions: {
|
||||
admin: boolean;
|
||||
canUpload: boolean;
|
||||
canDownload: boolean;
|
||||
canEmailBook: boolean;
|
||||
canEditMetadata: boolean;
|
||||
canManipulateLibrary: boolean;
|
||||
};
|
||||
bookPreferences: UserBookPreferences;
|
||||
}
|
||||
|
||||
export interface UserBookPreferences {
|
||||
perBookSetting: {
|
||||
pdf: string;
|
||||
epub: string;
|
||||
};
|
||||
pdfReaderSetting: {
|
||||
pageSpread: 'off' | 'even' | 'odd';
|
||||
pageZoom: string;
|
||||
showSidebar: boolean;
|
||||
};
|
||||
epubReaderSetting: {
|
||||
theme: string;
|
||||
font: string;
|
||||
fontSize: number;
|
||||
};
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class UserService {
|
||||
private readonly apiUrl = `${API_CONFIG.BASE_URL}/api/v1/auth/register`;
|
||||
private readonly userUrl = `${API_CONFIG.BASE_URL}/api/v1/users`;
|
||||
|
||||
private http = inject(HttpClient);
|
||||
private injector = inject(Injector);
|
||||
|
||||
private rxStompService?: RxStompService;
|
||||
|
||||
private userDataSubject = new BehaviorSubject<User | null>(null);
|
||||
userData$ = this.userDataSubject.asObservable();
|
||||
|
||||
constructor() {
|
||||
this.getMyself().subscribe(user => {
|
||||
this.userDataSubject.next(user);
|
||||
this.startWebSocket();
|
||||
});
|
||||
}
|
||||
|
||||
getMyself(): Observable<User> {
|
||||
return this.http.get<User>(`${this.userUrl}/me`);
|
||||
}
|
||||
|
||||
getLocalUser(): User | null {
|
||||
return this.userDataSubject.getValue();
|
||||
}
|
||||
|
||||
createUser(userData: Omit<User, 'id'>): Observable<void> {
|
||||
return this.http.post<void>(this.apiUrl, userData);
|
||||
}
|
||||
|
||||
getUsers(): Observable<User[]> {
|
||||
return this.http.get<User[]>(this.userUrl);
|
||||
}
|
||||
|
||||
updateUser(userId: number, updateData: Partial<User>): Observable<User> {
|
||||
return this.http.put<User>(`${this.userUrl}/${userId}`, updateData).pipe(
|
||||
tap(user => {
|
||||
this.userDataSubject.next(user);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
deleteUser(userId: number): Observable<void> {
|
||||
return this.http.delete<void>(`${this.userUrl}/${userId}`);
|
||||
}
|
||||
|
||||
changeUserPassword(userId: number, newPassword: string): Observable<void> {
|
||||
const payload = {
|
||||
userId: userId,
|
||||
newPassword: newPassword
|
||||
};
|
||||
return this.http.put<void>(`${this.userUrl}/change-user-password`, payload).pipe(
|
||||
catchError((error) => {
|
||||
const errorMessage = error?.error?.message || 'An unexpected error occurred. Please try again.';
|
||||
return throwError(() => new Error(errorMessage));
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
changePassword(currentPassword: string, newPassword: string): Observable<void> {
|
||||
const payload = {
|
||||
currentPassword: currentPassword,
|
||||
newPassword: newPassword
|
||||
};
|
||||
return this.http.put<void>(`${this.userUrl}/change-password`, payload).pipe(
|
||||
catchError((error) => {
|
||||
const errorMessage = error?.error?.message || 'An unexpected error occurred. Please try again.';
|
||||
return throwError(() => new Error(errorMessage));
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
updateBookPreferences(userId: number, prefs: UserBookPreferences): void {
|
||||
this.http.put<void>(`${this.userUrl}/${userId}/book-preferences`, prefs)
|
||||
.subscribe(() => {
|
||||
const currentUser = this.userDataSubject.getValue();
|
||||
if (currentUser) {
|
||||
const updatedUser = {...currentUser, bookPreferences: {...prefs}};
|
||||
this.userDataSubject.next(updatedUser);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private startWebSocket(): void {
|
||||
const token = this.getToken();
|
||||
if (token) {
|
||||
const rxStompService = this.getRxStompService();
|
||||
rxStompService.activate();
|
||||
}
|
||||
}
|
||||
|
||||
private getRxStompService(): RxStompService {
|
||||
if (!this.rxStompService) {
|
||||
this.rxStompService = this.injector.get(RxStompService);
|
||||
}
|
||||
return this.rxStompService;
|
||||
}
|
||||
|
||||
getToken(): string | null {
|
||||
return localStorage.getItem('accessToken');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user