Improve Angular project structure and code organization (#1328)
This commit is contained in:
@@ -0,0 +1,141 @@
|
||||
@if ((libraryState$ | async)?.libraries; as libraries) {
|
||||
<div
|
||||
class="flex flex-col gap-8 p-4 items-center justify-center w-full max-w-[700px]">
|
||||
<div class="flex flex-col items-center gap-2 w-full">
|
||||
<label class="text-sm text-stone-400">Upload Destination</label>
|
||||
<p-selectbutton
|
||||
[options]="stateOptions"
|
||||
[(ngModel)]="value"
|
||||
[allowEmpty]="false"
|
||||
optionLabel="label"
|
||||
optionValue="value">
|
||||
</p-selectbutton>
|
||||
</div>
|
||||
@if (value === 'library') {
|
||||
<p-select
|
||||
[options]="libraries"
|
||||
optionLabel="name"
|
||||
placeholder="Select Library"
|
||||
[(ngModel)]="selectedLibrary"
|
||||
class="w-full"></p-select>
|
||||
<p-select
|
||||
[options]="selectedLibrary?.paths"
|
||||
optionLabel="path"
|
||||
placeholder="Select Subpath"
|
||||
[(ngModel)]="selectedPath"
|
||||
[disabled]="!selectedLibrary"
|
||||
class="w-full"></p-select>
|
||||
}
|
||||
<p-fileupload class="w-full" name="file"
|
||||
[maxFileSize]="maxFileSizeBytes"
|
||||
[customUpload]="true"
|
||||
[multiple]="true" accept=".pdf,.epub,.cbz,.cbr,.cb7"
|
||||
(onSelect)="onFilesSelect($event)"
|
||||
(uploadHandler)="uploadFiles($event)"
|
||||
[disabled]="value === 'library' ? (!selectedLibrary || !selectedPath) : false">
|
||||
<ng-template #header let-files let-chooseCallback="chooseCallback" let-clearCallback="clearCallback" let-uploadCallback="uploadCallback">
|
||||
<div class="flex flex-col items-center justify-center flex-1 gap-4">
|
||||
<div class="flex gap-4">
|
||||
<p-button
|
||||
(onClick)="choose($event, chooseCallback)"
|
||||
icon="pi pi-images"
|
||||
[rounded]="true"
|
||||
[outlined]="true"
|
||||
[disabled]="isChooseDisabled()"
|
||||
pTooltip="Choose files to upload"
|
||||
tooltipPosition="top"/>
|
||||
|
||||
<p-button
|
||||
(onClick)="uploadEvent(uploadCallback)"
|
||||
icon="pi pi-cloud-upload"
|
||||
[rounded]="true"
|
||||
[outlined]="true"
|
||||
severity="success"
|
||||
[disabled]="isUploadDisabled()"
|
||||
pTooltip="Start uploading selected files"
|
||||
tooltipPosition="top"/>
|
||||
|
||||
<p-button
|
||||
(onClick)="onClear(clearCallback)"
|
||||
icon="pi pi-times"
|
||||
[rounded]="true"
|
||||
[outlined]="true"
|
||||
severity="danger"
|
||||
[disabled]="!filesPresent() || isUploading"
|
||||
pTooltip="Clear selected files"
|
||||
tooltipPosition="top"/>
|
||||
</div>
|
||||
<div>Click the upload icon to upload the files.</div>
|
||||
</div>
|
||||
</ng-template>
|
||||
<ng-template #content let-files let-removeFileCallback="removeFileCallback">
|
||||
<div class="flex flex-col gap-8 px-4">
|
||||
@if (files?.length > 0) {
|
||||
<div>
|
||||
<div class="max-h-96 max-w-[22rem] md:max-w-none overflow-y-auto pr-2">
|
||||
<div class="flex flex-wrap">
|
||||
@for (uploadFile of this.files; track uploadFile; let i = $index) {
|
||||
<div class="flex justify-between items-center w-full gap-4">
|
||||
<div class="flex items-center gap-4 overflow-hidden flex-1">
|
||||
<p-badge [value]="uploadFile.status === 'Pending' ? 'Ready to Upload' : uploadFile.status" [severity]="getBadgeSeverity(uploadFile.status)"
|
||||
class="shrink-0"/>
|
||||
<span class="font-semibold text-ellipsis whitespace-nowrap overflow-hidden flex-1">
|
||||
{{ uploadFile.file.name }}
|
||||
</span>
|
||||
<div class="shrink-0">{{ formatSize(uploadFile.file.size) }}</div>
|
||||
</div>
|
||||
@switch (uploadFile.status) {
|
||||
@case ('Pending') {
|
||||
<p-button
|
||||
icon="pi pi-times"
|
||||
(click)="onRemoveTemplatingFile($event, uploadFile.file, removeFileCallback, i)"
|
||||
severity="danger"
|
||||
[text]="true"/>
|
||||
}
|
||||
@case ('Uploading') {
|
||||
<i
|
||||
class="pi pi-spin pi-spinner p-3"
|
||||
style="color: slateblue"
|
||||
pTooltip="Uploading"
|
||||
tooltipPosition="top">
|
||||
</i>
|
||||
}
|
||||
@case ('Uploaded') {
|
||||
<i
|
||||
class="pi pi-check p-3"
|
||||
style="color: green"
|
||||
pTooltip="Uploaded"
|
||||
tooltipPosition="top">
|
||||
</i>
|
||||
}
|
||||
@case ('Failed') {
|
||||
<i
|
||||
class="pi pi-exclamation-triangle p-3"
|
||||
style="color: darkred"
|
||||
pTooltip="{{ uploadFile.errorMessage || 'Upload failed' }}"
|
||||
tooltipPosition="top">
|
||||
</i>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</ng-template>
|
||||
<ng-template #file></ng-template>
|
||||
<ng-template #empty>
|
||||
<div class="flex items-center justify-center flex-col text-center">
|
||||
<i class="pi pi-cloud-upload !border-2 !rounded-full !p-8 !text-4xl"></i>
|
||||
<p class="mt-6 mb-2">Drag and drop files here to upload.</p>
|
||||
<p class="mt-2 mb-2">
|
||||
Only <strong>.pdf</strong>, <strong>.epub</strong>, <strong>.cbz</strong>, <strong>.cbr</strong>, and <strong>.cb7</strong> files are supported (max size: 100 MB per
|
||||
file).
|
||||
</p>
|
||||
</div>
|
||||
</ng-template>
|
||||
</p-fileupload>
|
||||
</div>
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
:host ::ng-deep .p-fileupload-content p-progressbar {
|
||||
display: none !important;
|
||||
}
|
||||
@@ -0,0 +1,226 @@
|
||||
import {Component, inject, OnInit} from '@angular/core';
|
||||
import {FileSelectEvent, FileUpload, FileUploadHandlerEvent} from 'primeng/fileupload';
|
||||
import {Button} from 'primeng/button';
|
||||
import {AsyncPipe} from '@angular/common';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {Select} from 'primeng/select';
|
||||
import {Badge} from 'primeng/badge';
|
||||
import {LibraryService} from '../../../features/book/service/library.service';
|
||||
import {Library, LibraryPath} from '../../../features/book/model/library.model';
|
||||
import {LibraryState} from '../../../features/book/model/state/library-state.model';
|
||||
import {Observable} from 'rxjs';
|
||||
import {API_CONFIG} from '../../../core/config/api-config';
|
||||
import {Book} from '../../../features/book/model/book.model';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {AppSettingsService} from '../../service/app-settings.service';
|
||||
import {filter, take} from 'rxjs/operators';
|
||||
import {AppSettings} from '../../model/app-settings.model';
|
||||
import {SelectButton} from 'primeng/selectbutton';
|
||||
|
||||
interface UploadingFile {
|
||||
file: File;
|
||||
status: 'Pending' | 'Uploading' | 'Uploaded' | 'Failed';
|
||||
errorMessage?: string;
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-book-uploader',
|
||||
standalone: true,
|
||||
imports: [
|
||||
FileUpload,
|
||||
Button,
|
||||
AsyncPipe,
|
||||
FormsModule,
|
||||
Select,
|
||||
Badge,
|
||||
Tooltip,
|
||||
SelectButton
|
||||
],
|
||||
templateUrl: './book-uploader.component.html',
|
||||
styleUrl: './book-uploader.component.scss'
|
||||
})
|
||||
export class BookUploaderComponent implements OnInit {
|
||||
files: UploadingFile[] = [];
|
||||
isUploading: boolean = false;
|
||||
_selectedLibrary: Library | null = null;
|
||||
selectedPath: LibraryPath | null = null;
|
||||
|
||||
private readonly libraryService = inject(LibraryService);
|
||||
private readonly messageService = inject(MessageService);
|
||||
private readonly appSettingsService = inject(AppSettingsService);
|
||||
private readonly http = inject(HttpClient);
|
||||
|
||||
readonly libraryState$: Observable<LibraryState> = this.libraryService.libraryState$;
|
||||
appSettings$: Observable<AppSettings | null> = this.appSettingsService.appSettings$;
|
||||
maxFileSizeBytes?: number;
|
||||
stateOptions = [
|
||||
{label: 'Library', value: 'library'},
|
||||
{label: 'Bookdrop', value: 'bookdrop'}
|
||||
];
|
||||
value = 'library';
|
||||
|
||||
ngOnInit(): void {
|
||||
this.appSettings$
|
||||
.pipe(
|
||||
filter(settings => settings != null),
|
||||
take(1)
|
||||
)
|
||||
.subscribe(settings => {
|
||||
this.maxFileSizeBytes = (settings?.maxFileUploadSizeInMb ?? 100) * 1024 * 1024;
|
||||
});
|
||||
|
||||
this.libraryState$.subscribe(state => {
|
||||
if (state?.libraries?.length !== 1 || this.selectedLibrary) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.selectedLibrary = state.libraries[0];
|
||||
});
|
||||
}
|
||||
|
||||
get selectedLibrary(): Library | null {
|
||||
return this._selectedLibrary;
|
||||
}
|
||||
|
||||
set selectedLibrary(library: Library | null) {
|
||||
this._selectedLibrary = library;
|
||||
|
||||
if(library?.paths?.length === 1) {
|
||||
this.selectedPath = library.paths[0];
|
||||
}
|
||||
}
|
||||
|
||||
hasPendingFiles(): boolean {
|
||||
return this.files.some(f => f.status === 'Pending');
|
||||
}
|
||||
|
||||
filesPresent(): boolean {
|
||||
return this.files.length > 0;
|
||||
}
|
||||
|
||||
choose(_event: any, chooseCallback: () => void): void {
|
||||
chooseCallback();
|
||||
}
|
||||
|
||||
onClear(clearCallback: () => void): void {
|
||||
clearCallback();
|
||||
this.files = [];
|
||||
}
|
||||
|
||||
onFilesSelect(event: FileSelectEvent): void {
|
||||
const newFiles = event.currentFiles;
|
||||
for (const file of newFiles) {
|
||||
const exists = this.files.some(f => f.file.name === file.name && f.file.size === file.size);
|
||||
if (!exists) {
|
||||
this.files.unshift({file, status: 'Pending'});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onRemoveTemplatingFile(_event: any, _file: File, removeFileCallback: (event: any, index: number) => void, index: number): void {
|
||||
removeFileCallback(_event, index);
|
||||
}
|
||||
|
||||
uploadEvent(uploadCallback: () => void): void {
|
||||
uploadCallback();
|
||||
}
|
||||
|
||||
uploadFiles(event: FileUploadHandlerEvent): void {
|
||||
if (this.value === 'library' && (!this.selectedLibrary || !this.selectedPath)) {
|
||||
this.messageService.add({
|
||||
severity: 'warn',
|
||||
summary: 'Missing Data',
|
||||
detail: 'Please select a library and path before uploading.',
|
||||
life: 4000
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const filesToUpload = this.files.filter(f => f.status === 'Pending');
|
||||
if (filesToUpload.length === 0) return;
|
||||
|
||||
this.isUploading = true;
|
||||
this.uploadBatch(filesToUpload, 0, 5);
|
||||
}
|
||||
|
||||
private uploadBatch(files: UploadingFile[], startIndex: number, batchSize: number): void {
|
||||
const batch = files.slice(startIndex, startIndex + batchSize);
|
||||
if (batch.length === 0) {
|
||||
this.isUploading = false;
|
||||
return;
|
||||
}
|
||||
|
||||
let pending = batch.length;
|
||||
|
||||
for (const uploadFile of batch) {
|
||||
uploadFile.status = 'Uploading';
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('file', uploadFile.file);
|
||||
|
||||
let uploadUrl: string;
|
||||
if (this.value === 'library') {
|
||||
const libraryId = this.selectedLibrary!.id!.toString();
|
||||
const pathId = this.selectedPath!.id!.toString();
|
||||
formData.append('libraryId', libraryId);
|
||||
formData.append('pathId', pathId);
|
||||
uploadUrl = `${API_CONFIG.BASE_URL}/api/v1/files/upload`;
|
||||
} else {
|
||||
uploadUrl = `${API_CONFIG.BASE_URL}/api/v1/files/upload/bookdrop`;
|
||||
}
|
||||
|
||||
this.http.post<Book>(uploadUrl, formData).subscribe({
|
||||
next: () => {
|
||||
uploadFile.status = 'Uploaded';
|
||||
if (--pending === 0) {
|
||||
this.uploadBatch(files, startIndex + batchSize, batchSize);
|
||||
}
|
||||
},
|
||||
error: (err) => {
|
||||
uploadFile.status = 'Failed';
|
||||
uploadFile.errorMessage = err?.error?.message || 'Upload failed due to unknown error.';
|
||||
console.error('Upload failed for', uploadFile.file.name, err);
|
||||
if (--pending === 0) {
|
||||
this.uploadBatch(files, startIndex + batchSize, batchSize);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
isChooseDisabled(): boolean {
|
||||
if (this.value === 'bookdrop') {
|
||||
return this.isUploading;
|
||||
}
|
||||
return !this.selectedLibrary || !this.selectedPath || this.isUploading;
|
||||
}
|
||||
|
||||
isUploadDisabled(): boolean {
|
||||
return this.isChooseDisabled() || !this.filesPresent() || !this.hasPendingFiles();
|
||||
}
|
||||
|
||||
formatSize(bytes: number): string {
|
||||
const k = 1024;
|
||||
const dm = 2;
|
||||
if (bytes < k) return `${bytes} B`;
|
||||
if (bytes < k * k) return `${(bytes / k).toFixed(dm)} KB`;
|
||||
return `${(bytes / (k * k)).toFixed(dm)} MB`;
|
||||
}
|
||||
|
||||
getBadgeSeverity(status: UploadingFile['status']): 'info' | 'warn' | 'success' | 'danger' {
|
||||
switch (status) {
|
||||
case 'Pending':
|
||||
return 'warn';
|
||||
case 'Uploading':
|
||||
return 'info';
|
||||
case 'Uploaded':
|
||||
return 'success';
|
||||
case 'Failed':
|
||||
return 'danger';
|
||||
default:
|
||||
return 'info';
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<div class="change-password-container">
|
||||
<div class="change-password-wrapper">
|
||||
<p-card class="change-password-card p-fluid">
|
||||
|
||||
<ng-template pTemplate="content">
|
||||
<form #changePasswordForm="ngForm" (ngSubmit)="changePassword()">
|
||||
<div class="p-field">
|
||||
<label for="currentPassword">Current Password</label>
|
||||
<p-password id="currentPassword" [(ngModel)]="currentPassword" name="currentPassword" [feedback]="false" required fluid></p-password>
|
||||
</div>
|
||||
|
||||
<div class="p-field">
|
||||
<label for="newPassword">New Password</label>
|
||||
<p-password id="newPassword" [(ngModel)]="newPassword" name="newPassword" [feedback]="false" required fluid></p-password>
|
||||
</div>
|
||||
|
||||
<div class="p-field">
|
||||
<label for="confirmNewPassword">Confirm New Password</label>
|
||||
<p-password id="confirmNewPassword" [(ngModel)]="confirmNewPassword" name="confirmNewPassword" [feedback]="false" required fluid></p-password>
|
||||
@if (!passwordsMatch && confirmNewPassword) {
|
||||
<p-message severity="error" text="New passwords do not match."></p-message>
|
||||
}
|
||||
</div>
|
||||
|
||||
<p-button type="submit" label="Change Password" icon="pi pi-key" class="p-fluid"></p-button>
|
||||
|
||||
@if (errorMessage) {
|
||||
<p-message severity="error" text="{{ errorMessage }}"></p-message>
|
||||
}
|
||||
@if (successMessage) {
|
||||
<p-message severity="success" text="{{ successMessage }}"></p-message>
|
||||
}
|
||||
</form>
|
||||
</ng-template>
|
||||
</p-card>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,28 @@
|
||||
.change-password-container {
|
||||
@apply flex items-center justify-center min-h-screen bg-gradient-to-br from-blue-900 via-cyan-600 to-blue-400 relative;
|
||||
}
|
||||
|
||||
.change-password-wrapper {
|
||||
@apply flex flex-col items-center gap-6 absolute top-1/4 transform -translate-y-1/4;
|
||||
}
|
||||
|
||||
.app-title {
|
||||
@apply text-5xl font-extrabold text-white drop-shadow-lg;
|
||||
text-shadow: 0px 4px 6px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
.change-password-card {
|
||||
@apply w-96 shadow-lg rounded-xl bg-opacity-90 backdrop-blur-lg;
|
||||
}
|
||||
|
||||
form {
|
||||
@apply flex flex-col gap-4;
|
||||
}
|
||||
|
||||
.p-field {
|
||||
@apply flex flex-col gap-2;
|
||||
}
|
||||
|
||||
p-button {
|
||||
@apply mt-4;
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
import {Component, inject} from '@angular/core';
|
||||
import {Button} from 'primeng/button';
|
||||
import {Card} from 'primeng/card';
|
||||
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
|
||||
import {Message} from 'primeng/message';
|
||||
|
||||
import {Password} from 'primeng/password';
|
||||
import {MessageService, PrimeTemplate} from 'primeng/api';
|
||||
import {UserService} from '../../../features/settings/user-management/user.service';
|
||||
import {AuthService} from '../../service/auth.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-change-password',
|
||||
standalone: true,
|
||||
imports: [
|
||||
Button,
|
||||
Card,
|
||||
FormsModule,
|
||||
Message,
|
||||
Password,
|
||||
PrimeTemplate,
|
||||
ReactiveFormsModule
|
||||
],
|
||||
templateUrl: './change-password.component.html',
|
||||
styleUrl: './change-password.component.scss'
|
||||
})
|
||||
export class ChangePasswordComponent {
|
||||
currentPassword: string = '';
|
||||
newPassword: string = '';
|
||||
confirmNewPassword: string = '';
|
||||
errorMessage: string | null = null;
|
||||
successMessage: string | null = null;
|
||||
|
||||
protected userService = inject(UserService);
|
||||
protected authService = inject(AuthService);
|
||||
protected messageService = inject(MessageService);
|
||||
|
||||
get passwordsMatch(): boolean {
|
||||
return this.newPassword === this.confirmNewPassword;
|
||||
}
|
||||
|
||||
changePassword() {
|
||||
this.errorMessage = null;
|
||||
this.successMessage = null;
|
||||
|
||||
if (!this.currentPassword || !this.newPassword || !this.confirmNewPassword) {
|
||||
this.errorMessage = 'All fields are required.';
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.passwordsMatch) {
|
||||
this.errorMessage = 'New passwords do not match.';
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.currentPassword === this.newPassword) {
|
||||
this.errorMessage = 'New password cannot be the same as the current password.';
|
||||
return;
|
||||
}
|
||||
|
||||
this.userService.changePassword(this.currentPassword, this.newPassword).subscribe({
|
||||
next: () => {
|
||||
this.successMessage = 'Password changed successfully!';
|
||||
this.logout();
|
||||
},
|
||||
error: (err) => {
|
||||
this.errorMessage = err.message;
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Password Change Failed',
|
||||
detail: this.errorMessage ?? 'An unknown error occurred.'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
logout() {
|
||||
this.authService.logout();
|
||||
window.location.href = '/login';
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
<div class="h-[50rem] md:h-[50rem] md:w-[50rem] w-[25rem] flex flex-col">
|
||||
<div class="mb-6 flex items-center gap-4">
|
||||
<input
|
||||
id="disabled-input"
|
||||
type="text"
|
||||
pInputText
|
||||
[value]="selectedProductName"
|
||||
[disabled]="true"
|
||||
class="w-full p-2 text-base"
|
||||
/>
|
||||
<p-button label="Select" severity="success" (click)="onSelect()"></p-button>
|
||||
</div>
|
||||
<p-table [value]="paths" styleClass="responsive-table" class="flex-grow overflow-y-auto">
|
||||
<ng-template pTemplate="header">
|
||||
<tr>
|
||||
<th class="w-[1%]"></th>
|
||||
<th class="w-[99%]">Name</th>
|
||||
</tr>
|
||||
</ng-template>
|
||||
|
||||
<ng-template pTemplate="body" let-product>
|
||||
<tr class="cursor-pointer hover:bg-white/10" (click)="onRowClick(product)">
|
||||
<td>
|
||||
@if (product === '...') {
|
||||
<i class="pi pi-arrow-up"></i>
|
||||
}
|
||||
@if (product !== '...') {
|
||||
<i class="pi pi-folder-open"></i>
|
||||
}
|
||||
</td>
|
||||
<td>{{ product }}</td>
|
||||
</tr>
|
||||
</ng-template>
|
||||
</p-table>
|
||||
</div>
|
||||
@@ -0,0 +1,8 @@
|
||||
.responsive-table {
|
||||
min-width: 50rem;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
min-width: 100% !important;
|
||||
width: 100% !important;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
import {Component, inject, OnInit} from '@angular/core';
|
||||
import {DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {UtilityService} from './utility.service';
|
||||
import {Button} from 'primeng/button';
|
||||
import {TableModule} from 'primeng/table';
|
||||
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
|
||||
@Component({
|
||||
selector: 'app-directory-picker-v2',
|
||||
standalone: true,
|
||||
templateUrl: './directory-picker.component.html',
|
||||
imports: [
|
||||
Button,
|
||||
TableModule,
|
||||
InputText
|
||||
],
|
||||
styleUrls: ['./directory-picker.component.scss']
|
||||
})
|
||||
export class DirectoryPickerComponent implements OnInit {
|
||||
value: any;
|
||||
paths: string[] = ['...'];
|
||||
selectedProductName: string = '';
|
||||
|
||||
private utilityService = inject(UtilityService);
|
||||
private dynamicDialogRef = inject(DynamicDialogRef);
|
||||
|
||||
ngOnInit() {
|
||||
const initialPath = '/';
|
||||
this.getFolders(initialPath);
|
||||
}
|
||||
|
||||
getFolders(path: string): void {
|
||||
this.utilityService.getFolders(path).subscribe(
|
||||
(folders: string[]) => {
|
||||
this.paths = ['...', ...folders];
|
||||
},
|
||||
(error) => {
|
||||
console.error('Error fetching folders:', error);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
onRowClick(path: string): void {
|
||||
if (path === '...') {
|
||||
if (this.selectedProductName === '' || this.selectedProductName === '/') {
|
||||
this.getFolders('/');
|
||||
} else {
|
||||
const result = this.selectedProductName.substring(0, this.selectedProductName.lastIndexOf('/')) || '/';
|
||||
this.selectedProductName = result;
|
||||
this.getFolders(result);
|
||||
}
|
||||
} else {
|
||||
this.selectedProductName = path;
|
||||
this.getFolders(path);
|
||||
}
|
||||
}
|
||||
|
||||
onSelect(): void {
|
||||
this.dynamicDialogRef.close(this.selectedProductName);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import {inject, Injectable} from '@angular/core';
|
||||
import {Observable} from 'rxjs';
|
||||
import {HttpClient, HttpParams} from '@angular/common/http';
|
||||
import {API_CONFIG} from '../../../core/config/api-config';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class UtilityService {
|
||||
|
||||
private pathUrl = `${API_CONFIG.BASE_URL}/api/v1/path`;
|
||||
|
||||
private http = inject(HttpClient);
|
||||
|
||||
getFolders(path: string): Observable<string[]> {
|
||||
const params = new HttpParams().set('path', path);
|
||||
return this.http.get<string[]>(this.pathUrl, {params});
|
||||
}
|
||||
}
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
<div class="dialog-container">
|
||||
<div class="info-message">
|
||||
<i class="pi pi-exclamation-triangle"></i>
|
||||
<p>{{ totalRecords }} duplicate file groups have been detected in your library. To maintain data integrity and ensure optimal performance, please review and remove these duplicate entries from your file system.</p>
|
||||
</div>
|
||||
|
||||
<div class="table-container">
|
||||
<p-table
|
||||
#dataTable
|
||||
[value]="(duplicateFiles$ | async) || []"
|
||||
[scrollable]="true"
|
||||
scrollHeight="100%"
|
||||
[paginator]="false"
|
||||
[rows]="15"
|
||||
[rowHover]="true">
|
||||
|
||||
<ng-template pTemplate="body" let-group>
|
||||
<tr>
|
||||
<td>
|
||||
<div class="hash-group">
|
||||
<div class="hash-header">
|
||||
<i class="pi pi-copy"></i>
|
||||
<span class="hash-label">Hash:</span>
|
||||
<span class="hash-value">{{ group.hash }}</span>
|
||||
<span class="file-count">({{ group.files.length }} files)</span>
|
||||
</div>
|
||||
|
||||
<div class="files-list">
|
||||
@for (file of (group.files || []); track file.fullPath) {
|
||||
<div class="file-item-compact">
|
||||
<div class="file-icon">
|
||||
<i class="pi pi-file"></i>
|
||||
</div>
|
||||
<div class="file-details">
|
||||
<div class="filename">{{ file.fileName }}</div>
|
||||
<div class="file-path" [title]="file.fullPath">{{ file.fullPath }}</div>
|
||||
<div class="library-info">
|
||||
<i class="pi pi-database"></i>
|
||||
<span>{{ file.libraryName }}</span>
|
||||
<span class="timestamp">{{ file.timestamp | date:'short' }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</ng-template>
|
||||
|
||||
<ng-template pTemplate="emptymessage">
|
||||
<tr>
|
||||
<td class="empty-message">
|
||||
<div class="empty-content">
|
||||
<i class="pi pi-info-circle"></i>
|
||||
<span>No duplicate files detected</span>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</ng-template>
|
||||
</p-table>
|
||||
</div>
|
||||
|
||||
<div class="bottom-fixed-area">
|
||||
<div class="paginator-container">
|
||||
<p-paginator
|
||||
[first]="first"
|
||||
[rows]="rows"
|
||||
[totalRecords]="totalRecords"
|
||||
[showCurrentPageReport]="true"
|
||||
currentPageReportTemplate="Showing {first} to {last} of {totalRecords} duplicate file groups"
|
||||
(onPageChange)="onPageChange($event)">
|
||||
</p-paginator>
|
||||
</div>
|
||||
|
||||
<div class="dialog-actions">
|
||||
<p-button
|
||||
label="Acknowledge"
|
||||
icon="pi pi-check"
|
||||
(click)="acknowledgeAndClose()">
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
+235
@@ -0,0 +1,235 @@
|
||||
.dialog-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.table-container {
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
margin-bottom: 100px;
|
||||
|
||||
::ng-deep .p-datatable {
|
||||
height: 100%;
|
||||
|
||||
.p-datatable-wrapper {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.p-datatable-tbody > tr > td {
|
||||
border: none !important;
|
||||
padding: 0.5rem 0.5rem;
|
||||
}
|
||||
|
||||
.p-datatable-tbody > tr {
|
||||
border: none !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.bottom-fixed-area {
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
background: var(--surface-ground);
|
||||
z-index: 1000;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.paginator-container {
|
||||
::ng-deep .p-paginator {
|
||||
border: none;
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
}
|
||||
}
|
||||
|
||||
.dialog-actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.duplicate-files-content {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.hash-group {
|
||||
background: rgba(255, 255, 255, 0.03);
|
||||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||
border-radius: 8px;
|
||||
padding: 1rem;
|
||||
margin: 0.5rem 0;
|
||||
}
|
||||
|
||||
.hash-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
margin-bottom: 0.75rem;
|
||||
padding-bottom: 0.5rem;
|
||||
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
|
||||
|
||||
i {
|
||||
color: var(--primary-color);
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.hash-label {
|
||||
font-weight: 600;
|
||||
color: rgba(255, 255, 255, 0.9);
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.hash-value {
|
||||
font-family: 'Courier New', monospace;
|
||||
color: rgba(255, 255, 255, 0.7);
|
||||
font-size: 1rem;
|
||||
font-weight: 900;
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
padding: 0.25rem 0.5rem;
|
||||
border-radius: 4px;
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.file-count {
|
||||
background: var(--primary-color);
|
||||
color: white;
|
||||
padding: 0.25rem 0.5rem;
|
||||
border-radius: 12px;
|
||||
font-size: 0.8rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
|
||||
.files-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.file-item-compact {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 0.75rem;
|
||||
padding: 0.75rem;
|
||||
border-radius: 6px;
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||
transition: all 0.2s ease;
|
||||
margin-left: 1rem;
|
||||
}
|
||||
|
||||
.file-icon {
|
||||
background: var(--primary-color);
|
||||
color: white;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
border-radius: 4px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-shrink: 0;
|
||||
|
||||
i {
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
}
|
||||
|
||||
.file-details {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.25rem;
|
||||
}
|
||||
|
||||
.filename {
|
||||
font-family: 'Courier New', monospace;
|
||||
font-weight: 600;
|
||||
font-size: 0.95rem;
|
||||
color: rgba(255, 255, 255, 0.9);
|
||||
word-break: break-word;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
.file-path {
|
||||
font-size: 0.95rem;
|
||||
color: rgba(255, 255, 255, 0.7);
|
||||
font-family: 'Courier New', monospace;
|
||||
word-break: break-all;
|
||||
line-height: 1.2;
|
||||
max-height: 2.4em;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.library-info {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.4rem;
|
||||
font-size: 0.9rem;
|
||||
color: rgba(255, 255, 255, 0.8);
|
||||
margin-top: 0.1rem;
|
||||
|
||||
i {
|
||||
color: var(--primary-color);
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
|
||||
.timestamp {
|
||||
margin-left: auto;
|
||||
font-size: 0.8rem;
|
||||
color: rgba(255, 255, 255, 0.6);
|
||||
}
|
||||
}
|
||||
|
||||
.empty-message {
|
||||
text-align: center !important;
|
||||
padding: 3rem 1rem !important;
|
||||
|
||||
.empty-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
opacity: 0.6;
|
||||
|
||||
i {
|
||||
font-size: 1.5rem;
|
||||
}
|
||||
|
||||
span {
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.info-message {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 0.75rem;
|
||||
padding: 1rem;
|
||||
margin-bottom: 1rem;
|
||||
background: rgba(234, 88, 12, 0.1);
|
||||
border: 1px solid rgba(234, 88, 12, 0.3);
|
||||
border-radius: 0.375rem;
|
||||
color: #fbbf24;
|
||||
|
||||
i {
|
||||
color: #f59e0b;
|
||||
font-size: 1.125rem;
|
||||
margin-top: 0.125rem;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 0;
|
||||
line-height: 1.5;
|
||||
font-size: 1rem;
|
||||
}
|
||||
}
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { DynamicDialogRef, DynamicDialogConfig } from 'primeng/dynamicdialog';
|
||||
import { TableModule } from 'primeng/table';
|
||||
import { ButtonModule } from 'primeng/button';
|
||||
import { TooltipModule } from 'primeng/tooltip';
|
||||
import { PaginatorModule } from 'primeng/paginator';
|
||||
import { Observable, map } from 'rxjs';
|
||||
import {DuplicateFileNotification} from '../../../websocket/model/duplicate-file-notification.model';
|
||||
import {DuplicateFileService} from '../../../websocket/duplicate-file.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-duplicate-files-dialog',
|
||||
standalone: true,
|
||||
imports: [CommonModule, TableModule, ButtonModule, TooltipModule, PaginatorModule],
|
||||
templateUrl: './duplicate-files-dialog.component.html',
|
||||
styleUrls: ['./duplicate-files-dialog.component.scss']
|
||||
})
|
||||
export class DuplicateFilesDialogComponent implements OnInit {
|
||||
duplicateFiles$: Observable<{ hash: string; files: DuplicateFileNotification[] }[]>;
|
||||
totalRecords = 0;
|
||||
first = 0;
|
||||
rows = 15;
|
||||
|
||||
constructor(
|
||||
public ref: DynamicDialogRef,
|
||||
public config: DynamicDialogConfig,
|
||||
private duplicateFileService: DuplicateFileService
|
||||
) {
|
||||
this.duplicateFiles$ = this.config.data.duplicateFiles$.pipe(
|
||||
map((files: DuplicateFileNotification[] | null) => {
|
||||
if (!files) return [];
|
||||
|
||||
// Group files by hash
|
||||
const groupedFiles = files.reduce((acc, file) => {
|
||||
if (!acc[file.hash]) {
|
||||
acc[file.hash] = [];
|
||||
}
|
||||
acc[file.hash].push(file);
|
||||
return acc;
|
||||
}, {} as { [hash: string]: DuplicateFileNotification[] });
|
||||
|
||||
const groups = Object.entries(groupedFiles).map(([hash, files]) => ({
|
||||
hash,
|
||||
files: files.sort((a, b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime())
|
||||
}));
|
||||
|
||||
this.totalRecords = groups.length;
|
||||
return groups.slice(this.first, this.first + this.rows);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
ngOnInit() {}
|
||||
|
||||
onPageChange(event: any) {
|
||||
this.first = event.first;
|
||||
this.rows = event.rows;
|
||||
this.duplicateFiles$ = this.config.data.duplicateFiles$.pipe(
|
||||
map((files: DuplicateFileNotification[] | null) => {
|
||||
if (!files) return [];
|
||||
|
||||
const groupedFiles = files.reduce((acc, file) => {
|
||||
if (!acc[file.hash]) {
|
||||
acc[file.hash] = [];
|
||||
}
|
||||
acc[file.hash].push(file);
|
||||
return acc;
|
||||
}, {} as { [hash: string]: DuplicateFileNotification[] });
|
||||
|
||||
const groups = Object.entries(groupedFiles).map(([hash, files]) => ({
|
||||
hash,
|
||||
files: files.sort((a, b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime())
|
||||
}));
|
||||
|
||||
this.totalRecords = groups.length;
|
||||
return groups.slice(this.first, this.first + this.rows);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
acknowledgeAndClose() {
|
||||
this.duplicateFileService.clearDuplicateFiles();
|
||||
this.ref.close();
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
@if (duplicateFilesCount$ | async; as count) {
|
||||
@if (count > 0) {
|
||||
<div class="flex flex-col p-4 space-y-2 live-border">
|
||||
<div class="flex items-center justify-between">
|
||||
<div class="flex items-center gap-2">
|
||||
<i class="pi pi-exclamation-triangle text-yellow-500"></i>
|
||||
<span class="font-normal text-zinc-200">{{ count }} duplicate files detected</span>
|
||||
</div>
|
||||
<p-tag [value]="count.toString()" severity="warn" [rounded]="true"></p-tag>
|
||||
</div>
|
||||
<p-button
|
||||
label="View Details"
|
||||
icon="pi pi-list"
|
||||
outlined
|
||||
size="small"
|
||||
severity="info"
|
||||
fluid
|
||||
(click)="openDialog()">
|
||||
</p-button>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
.duplicate-files-content {
|
||||
max-height: 500px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.live-border {
|
||||
background: var(--card-background);
|
||||
border: 1px solid var(--primary-color);
|
||||
border-radius: 0.5rem;
|
||||
}
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
import {Component, inject, OnDestroy} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {DialogModule} from 'primeng/dialog';
|
||||
import {ButtonModule} from 'primeng/button';
|
||||
import {TableModule} from 'primeng/table';
|
||||
import {TagModule} from 'primeng/tag';
|
||||
import {Observable} from 'rxjs';
|
||||
import {map} from 'rxjs/operators';
|
||||
import {DuplicateFileService} from '../../websocket/duplicate-file.service';
|
||||
import {DuplicateFileNotification} from '../../websocket/model/duplicate-file-notification.model';
|
||||
import {DialogService, DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {DuplicateFilesDialogComponent} from './duplicate-files-dialog/duplicate-files-dialog.component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-duplicate-files-notification',
|
||||
standalone: true,
|
||||
imports: [CommonModule, DialogModule, ButtonModule, TableModule, TagModule],
|
||||
templateUrl: './duplicate-files-notification.component.html',
|
||||
styleUrls: ['./duplicate-files-notification.component.scss'],
|
||||
providers: [DialogService]
|
||||
})
|
||||
export class DuplicateFilesNotificationComponent implements OnDestroy {
|
||||
displayDialog = false;
|
||||
|
||||
private duplicateFileService = inject(DuplicateFileService);
|
||||
private ref: DynamicDialogRef | undefined;
|
||||
|
||||
duplicateFiles$ = this.duplicateFileService.duplicateFiles$;
|
||||
duplicateFilesCount$: Observable<number> = this.duplicateFiles$.pipe(
|
||||
map(files => files?.length || 0)
|
||||
);
|
||||
|
||||
constructor(
|
||||
private dialogService: DialogService
|
||||
) {
|
||||
}
|
||||
|
||||
openDialog() {
|
||||
this.ref = this.dialogService.open(DuplicateFilesDialogComponent, {
|
||||
header: 'Duplicate Files Detected',
|
||||
width: '80dvw',
|
||||
height: '75dvh',
|
||||
contentStyle: {overflow: 'hidden'},
|
||||
maximizable: true,
|
||||
modal: true,
|
||||
data: {
|
||||
duplicateFiles$: this.duplicateFiles$
|
||||
}
|
||||
});
|
||||
|
||||
this.ref.onClose.subscribe((result: any) => {
|
||||
if (result) {
|
||||
// Handle any result from dialog if needed
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
closeDialog() {
|
||||
this.displayDialog = false;
|
||||
}
|
||||
|
||||
clearAllDuplicates() {
|
||||
this.duplicateFileService.clearDuplicateFiles();
|
||||
this.closeDialog();
|
||||
}
|
||||
|
||||
removeDuplicate(file: DuplicateFileNotification) {
|
||||
this.duplicateFileService.removeDuplicateFile(file.fullPath, file.libraryId);
|
||||
}
|
||||
|
||||
formatTimestamp(timestamp: string): string {
|
||||
return new Date(timestamp).toLocaleString();
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
if (this.ref) {
|
||||
this.ref.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<p>empty works!</p>
|
||||
@@ -0,0 +1,11 @@
|
||||
import { Component } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'app-empty',
|
||||
imports: [],
|
||||
templateUrl: './empty.component.html',
|
||||
styleUrl: './empty.component.scss'
|
||||
})
|
||||
export class EmptyComponent {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
<div class="p-fluid px-4 py-2 rounded-xl flex flex-col h-full">
|
||||
|
||||
<div class="px-4 mx-2 mb-4 py-3 rounded-lg border border-[var(--border-color)] transition-all">
|
||||
<p class="text-[var(--primary-color)] font-semibold mb-1">
|
||||
File Organization Preview
|
||||
</p>
|
||||
<div class="text-sm text-gray-300 space-y-3">
|
||||
<p>
|
||||
Your files will be automatically renamed, organized, and can be moved between libraries based on your preferences.
|
||||
Check the preview below to see how your files will look, select target libraries if needed, then click <span class="font-semibold text-green-400">Move Files</span> to organize them.
|
||||
</p>
|
||||
<p>
|
||||
<i class="pi pi-lightbulb text-blue-400 mr-1"></i>
|
||||
<span class="text-blue-300">Want to change how files are named? Go to <strong>Settings → File Naming Pattern</strong>. Each library can have its own naming pattern!</span>
|
||||
</p>
|
||||
<p class="text-yellow-500 font-medium flex items-center gap-2">
|
||||
<i class="pi pi-exclamation-triangle text-yellow-400"></i>
|
||||
This will actually move and rename files on your computer across different library folders. Make sure you're happy with the preview first!
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex gap-4 mb-4 px-2 items-center w-full">
|
||||
<div class="flex-1">
|
||||
<div class="flex items-center justify-between cursor-pointer" (click)="togglePatternsCollapsed()">
|
||||
<p-button
|
||||
outlined
|
||||
[icon]="patternsCollapsed ? 'pi pi-chevron-right' : 'pi pi-chevron-down'"
|
||||
iconPos="right"
|
||||
size="small"
|
||||
severity="info"
|
||||
[label]="patternsCollapsed ? 'Show Naming Rules' : 'Hide Naming Rules'">
|
||||
</p-button>
|
||||
</div>
|
||||
|
||||
@if (!patternsCollapsed) {
|
||||
<div class="space-y-2 mt-2">
|
||||
@for (pattern of libraryPatterns; track pattern.libraryId) {
|
||||
<div class="p-3 border border-zinc-700 rounded-lg bg-zinc-800">
|
||||
<div class="flex justify-between items-start">
|
||||
<div class="flex-1">
|
||||
<p class="text-xs text-gray-400 mb-1">Library: {{ pattern.libraryName }}</p>
|
||||
<code class="text-[var(--primary-color)] font-mono text-sm">{{ pattern.pattern || 'No pattern available' }}</code>
|
||||
<p class="text-xs text-gray-400 mt-1">Source: {{ pattern.source }}</p>
|
||||
</div>
|
||||
<span class="text-xs bg-blue-600 text-white px-2 py-1 rounded ml-2">{{ pattern.bookCount }} book{{ pattern.bookCount > 1 ? 's' : '' }}</span>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex gap-4 mb-4 px-2 items-center">
|
||||
<div class="flex items-center gap-3">
|
||||
<label class="text-sm font-medium text-gray-300">Set all files to:</label>
|
||||
<p-select
|
||||
[options]="availableLibraries"
|
||||
[(ngModel)]="defaultTargetLibraryId"
|
||||
optionLabel="name"
|
||||
optionValue="id"
|
||||
placeholder="Select default library"
|
||||
(onChange)="onDefaultLibraryChange()"
|
||||
class="min-w-[200px]"
|
||||
size="small"
|
||||
appendTo="body"
|
||||
></p-select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex-grow overflow-y-auto">
|
||||
<p-table
|
||||
[value]="filePreviews"
|
||||
[responsiveLayout]="'scroll'"
|
||||
class="block min-w-full"
|
||||
>
|
||||
<ng-template pTemplate="header">
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Current Path</th>
|
||||
<th>Target Library</th>
|
||||
<th></th>
|
||||
<th>New Path</th>
|
||||
</tr>
|
||||
</ng-template>
|
||||
<ng-template pTemplate="body" let-preview let-i="rowIndex">
|
||||
<tr>
|
||||
<td class="text-center">{{ preview.bookId }}</td>
|
||||
<td class="w-auto">
|
||||
<p>
|
||||
<span class="text-gray-400 select-none">{{ preview.currentLibraryName }}/</span><span class="text-gray-200">{{ preview.relativeOriginalPath }}</span>
|
||||
</p>
|
||||
</td>
|
||||
<td class="w-auto">
|
||||
<p-select
|
||||
[options]="availableLibraries"
|
||||
[(ngModel)]="preview.targetLibraryId"
|
||||
optionLabel="name"
|
||||
optionValue="id"
|
||||
placeholder="Select Library"
|
||||
(onChange)="onLibraryChange(preview)"
|
||||
[disabled]="preview.isMoved"
|
||||
class="w-full"
|
||||
appendTo="body"
|
||||
size="small"
|
||||
></p-select>
|
||||
</td>
|
||||
<td class="w-auto text-[var(--primary-color)] text-center">→</td>
|
||||
<td class="w-auto">
|
||||
<p>
|
||||
<span class="text-gray-400 select-none">{{ preview.targetLibraryName }}/</span><span class="text-gray-200">{{ preview.relativeNewPath }}</span>
|
||||
</p>
|
||||
</td>
|
||||
<td class="w-auto text-center">
|
||||
@if (preview.isMoved) {
|
||||
<i class="pi pi-check-circle text-green-600"></i>
|
||||
}
|
||||
</td>
|
||||
</tr>
|
||||
</ng-template>
|
||||
</p-table>
|
||||
</div>
|
||||
|
||||
<p-divider></p-divider>
|
||||
|
||||
<div class="flex justify-end items-center gap-4 flex-shrink-0 px-4 pt-4">
|
||||
@if (movedFileCount > 0) {
|
||||
<span class="text-green-500 flex items-center font-semibold drop-shadow-sm select-none">
|
||||
{{ movedFileCount }} file{{ movedFileCount > 1 ? 's' : '' }} successfully moved
|
||||
<i
|
||||
class="pi pi-check-circle ml-2 text-green-500 animate-bounce"
|
||||
style="animation-duration: 1.5s;"
|
||||
aria-label="Success"
|
||||
role="img"
|
||||
></i>
|
||||
</span>
|
||||
}
|
||||
@if (movedFileCount === 0) {
|
||||
<p-button
|
||||
[label]="loading ? 'Moving...' : 'Move Files'"
|
||||
[icon]="loading ? 'pi pi-spin pi-spinner' : 'pi pi-arrows-h'"
|
||||
severity="success"
|
||||
(click)="saveChanges()"
|
||||
[disabled]="loading || filePreviews.length === 0"
|
||||
></p-button>
|
||||
<p-button
|
||||
label="Cancel"
|
||||
icon="pi pi-times"
|
||||
severity="danger"
|
||||
(click)="cancel()"
|
||||
></p-button>
|
||||
} @else {
|
||||
<p-button
|
||||
label="Close"
|
||||
icon="pi pi-times"
|
||||
severity="success"
|
||||
(click)="cancel()"
|
||||
></p-button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,3 @@
|
||||
:host ::ng-deep .p-datatable-tbody > tr > td {
|
||||
padding: 0.5rem 1rem !important;
|
||||
}
|
||||
@@ -0,0 +1,321 @@
|
||||
import {Component, inject, OnDestroy} from '@angular/core';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {Button} from 'primeng/button';
|
||||
import {TableModule} from 'primeng/table';
|
||||
import {Divider} from 'primeng/divider';
|
||||
import {DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {filter, take, takeUntil} from 'rxjs/operators';
|
||||
import {Subject} from 'rxjs';
|
||||
|
||||
import {BookService} from '../../../features/book/service/book.service';
|
||||
import {Book} from '../../../features/book/model/book.model';
|
||||
import {FileMoveRequest, FileOperationsService} from '../../service/file-operations-service';
|
||||
import {LibraryService} from "../../../features/book/service/library.service";
|
||||
import {AppSettingsService} from '../../service/app-settings.service';
|
||||
import {Select} from 'primeng/select';
|
||||
|
||||
interface FilePreview {
|
||||
bookId: number;
|
||||
originalPath: string;
|
||||
relativeOriginalPath: string;
|
||||
currentLibraryId: number | null;
|
||||
currentLibraryName: string;
|
||||
targetLibraryId: number | null;
|
||||
targetLibraryName: string;
|
||||
newPath: string;
|
||||
relativeNewPath: string;
|
||||
isMoved?: boolean;
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-file-mover-component',
|
||||
standalone: true,
|
||||
imports: [Button, FormsModule, TableModule, Divider, Select],
|
||||
templateUrl: './file-mover-component.html',
|
||||
styleUrl: './file-mover-component.scss'
|
||||
})
|
||||
export class FileMoverComponent implements OnDestroy {
|
||||
private config = inject(DynamicDialogConfig);
|
||||
private ref = inject(DynamicDialogRef);
|
||||
private bookService = inject(BookService);
|
||||
private libraryService = inject(LibraryService);
|
||||
private fileOperationsService = inject(FileOperationsService);
|
||||
private messageService = inject(MessageService);
|
||||
private appSettingsService = inject(AppSettingsService);
|
||||
private destroy$ = new Subject<void>();
|
||||
|
||||
libraryPatterns: {
|
||||
libraryId: number | null;
|
||||
libraryName: string;
|
||||
pattern: string;
|
||||
source: string;
|
||||
bookCount: number;
|
||||
}[] = [];
|
||||
defaultMovePattern = '';
|
||||
loading = false;
|
||||
patternsCollapsed = false;
|
||||
|
||||
bookIds: Set<number> = new Set();
|
||||
books: Book[] = [];
|
||||
availableLibraries: { id: number | null; name: string }[] = [];
|
||||
filePreviews: FilePreview[] = [];
|
||||
defaultTargetLibraryId: number | null = null;
|
||||
|
||||
constructor() {
|
||||
this.bookIds = new Set(this.config.data?.bookIds ?? []);
|
||||
this.books = this.bookService.getBooksByIdsFromState([...this.bookIds]);
|
||||
this.loadAvailableLibraries();
|
||||
this.loadDefaultPattern();
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
}
|
||||
|
||||
private loadDefaultPattern(): void {
|
||||
this.appSettingsService.appSettings$.pipe(
|
||||
filter(settings => settings != null),
|
||||
take(1),
|
||||
takeUntil(this.destroy$)
|
||||
).subscribe(settings => {
|
||||
this.defaultMovePattern = settings?.uploadPattern || '';
|
||||
this.loadLibraryPatterns();
|
||||
});
|
||||
}
|
||||
|
||||
private loadLibraryPatterns(): void {
|
||||
this.libraryService.libraryState$.pipe(
|
||||
filter(state => state.loaded && state.libraries != null),
|
||||
take(1),
|
||||
takeUntil(this.destroy$)
|
||||
).subscribe(state => {
|
||||
const booksByLibrary = new Map<number | null, Book[]>();
|
||||
this.books.forEach(book => {
|
||||
const libraryId =
|
||||
book.libraryId ??
|
||||
book.libraryPath?.id ??
|
||||
(book as any).library?.id ??
|
||||
null;
|
||||
if (!booksByLibrary.has(libraryId)) {
|
||||
booksByLibrary.set(libraryId, []);
|
||||
}
|
||||
booksByLibrary.get(libraryId)!.push(book);
|
||||
});
|
||||
|
||||
this.libraryPatterns = Array.from(booksByLibrary.entries()).map(([libraryId, books]) => {
|
||||
let libraryName = 'Unknown Library';
|
||||
let pattern = this.defaultMovePattern;
|
||||
let source = 'App Default';
|
||||
|
||||
if (libraryId) {
|
||||
const library = state.libraries?.find(lib => lib.id === libraryId);
|
||||
if (library) {
|
||||
libraryName = library.name;
|
||||
if (library.fileNamingPattern) {
|
||||
pattern = library.fileNamingPattern;
|
||||
source = 'Library Setting';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
libraryId,
|
||||
libraryName,
|
||||
pattern,
|
||||
source,
|
||||
bookCount: books.length
|
||||
};
|
||||
});
|
||||
|
||||
this.applyPattern();
|
||||
});
|
||||
}
|
||||
|
||||
private loadAvailableLibraries(): void {
|
||||
this.libraryService.libraryState$.pipe(
|
||||
filter(state => state.loaded && state.libraries != null),
|
||||
take(1),
|
||||
takeUntil(this.destroy$)
|
||||
).subscribe(state => {
|
||||
this.availableLibraries = state.libraries?.map(lib => ({id: lib.id ?? null, name: lib.name})) || [];
|
||||
});
|
||||
}
|
||||
|
||||
applyPattern(): void {
|
||||
this.filePreviews = this.books.map(book => {
|
||||
const fileName = book.fileName ?? '';
|
||||
const fileSubPath = book.fileSubPath ? `${book.fileSubPath.replace(/\/+$/g, '')}/` : '';
|
||||
|
||||
const relativeOriginalPath = `${fileSubPath}${fileName}`;
|
||||
|
||||
const currentLibraryId = book.libraryId ?? book.libraryPath?.id ?? (book as any).library?.id ?? null;
|
||||
const currentLibraryName = this.getLibraryNameById(currentLibraryId);
|
||||
|
||||
const targetLibraryId = currentLibraryId;
|
||||
const targetLibraryName = currentLibraryName;
|
||||
|
||||
const preview: FilePreview = {
|
||||
bookId: book.id,
|
||||
originalPath: this.getFullPath(currentLibraryId, relativeOriginalPath),
|
||||
relativeOriginalPath,
|
||||
currentLibraryId,
|
||||
currentLibraryName,
|
||||
targetLibraryId,
|
||||
targetLibraryName,
|
||||
newPath: '',
|
||||
relativeNewPath: ''
|
||||
};
|
||||
|
||||
this.updatePreviewPaths(preview, book);
|
||||
return preview;
|
||||
});
|
||||
}
|
||||
|
||||
onDefaultLibraryChange(): void {
|
||||
this.filePreviews.forEach(preview => {
|
||||
if (!preview.isMoved) {
|
||||
preview.targetLibraryId = this.defaultTargetLibraryId;
|
||||
preview.targetLibraryName = this.getLibraryNameById(this.defaultTargetLibraryId);
|
||||
|
||||
const book = this.books.find(b => b.id === preview.bookId);
|
||||
if (book) {
|
||||
this.updatePreviewPaths(preview, book);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onLibraryChange(preview: FilePreview): void {
|
||||
preview.targetLibraryName = this.getLibraryNameById(preview.targetLibraryId);
|
||||
const book = this.books.find(b => b.id === preview.bookId);
|
||||
if (book) {
|
||||
this.updatePreviewPaths(preview, book);
|
||||
}
|
||||
}
|
||||
|
||||
private updatePreviewPaths(preview: FilePreview, book: Book): void {
|
||||
const meta = book.metadata!;
|
||||
const fileName = book.fileName ?? '';
|
||||
const extension = fileName.match(/\.[^.]+$/)?.[0] ?? '';
|
||||
|
||||
const libraryPattern = this.libraryPatterns.find(p => p.libraryId === preview.targetLibraryId);
|
||||
const pattern = libraryPattern?.pattern || this.defaultMovePattern;
|
||||
|
||||
const values: Record<string, string> = {
|
||||
authors: this.sanitize(meta.authors?.join(', ') || 'Unknown Author'),
|
||||
title: this.sanitize(meta.title || 'Untitled'),
|
||||
year: this.formatYear(meta.publishedDate),
|
||||
series: this.sanitize(meta.seriesName || ''),
|
||||
seriesIndex: this.formatSeriesIndex(meta.seriesNumber ?? undefined),
|
||||
language: this.sanitize(meta.language || ''),
|
||||
publisher: this.sanitize(meta.publisher || ''),
|
||||
isbn: this.sanitize(meta.isbn13 || meta.isbn10 || ''),
|
||||
currentFilename: this.sanitize(fileName)
|
||||
};
|
||||
|
||||
let newPath: string;
|
||||
|
||||
if (!pattern?.trim()) {
|
||||
newPath = fileName;
|
||||
} else {
|
||||
newPath = pattern.replace(/<([^<>]+)>/g, (_, block) => {
|
||||
const placeholders = [...block.matchAll(/{(.*?)}/g)].map(m => m[1]);
|
||||
const allHaveValues = placeholders.every(key => values[key]?.trim());
|
||||
return allHaveValues
|
||||
? block.replace(/{(.*?)}/g, (_: string, key: string) => values[key] ?? '')
|
||||
: '';
|
||||
});
|
||||
|
||||
newPath = newPath.replace(/{(.*?)}/g, (_, key) => values[key] ?? '');
|
||||
|
||||
if (!newPath.endsWith(extension)) {
|
||||
newPath += extension;
|
||||
}
|
||||
}
|
||||
|
||||
preview.relativeNewPath = newPath;
|
||||
preview.newPath = this.getFullPath(preview.targetLibraryId, newPath);
|
||||
}
|
||||
|
||||
private getLibraryNameById(libraryId: number | null): string {
|
||||
if (libraryId === null) return 'Unknown Library';
|
||||
return this.availableLibraries.find(lib => lib.id === libraryId)?.name || 'Unknown Library';
|
||||
}
|
||||
|
||||
private getFullPath(libraryId: number | null, relativePath: string): string {
|
||||
const libraryPath = libraryId ? this.libraryService.getLibraryPathById(libraryId)?.replace(/\/+$/g, '') : '';
|
||||
return libraryPath ? `${libraryPath}/${relativePath}`.replace(/\/\/+/g, '/') : relativePath;
|
||||
}
|
||||
|
||||
get movedFileCount(): number {
|
||||
return this.filePreviews.filter(p => p.isMoved).length;
|
||||
}
|
||||
|
||||
sanitize(input: string | undefined): string {
|
||||
return input?.replace(/[\\/:*?"<>|]/g, '')
|
||||
.replace(/[\x00-\x1F\x7F]/g, '')
|
||||
.replace(/\s+/g, ' ')
|
||||
.trim() ?? '';
|
||||
}
|
||||
|
||||
formatYear(dateStr?: string): string {
|
||||
if (!dateStr) return '';
|
||||
const yearMatch = dateStr.match(/^(\d{4})/);
|
||||
if (yearMatch) {
|
||||
return yearMatch[1];
|
||||
}
|
||||
const date = new Date(dateStr);
|
||||
return isNaN(date.getTime()) ? '' : date.getUTCFullYear().toString();
|
||||
}
|
||||
|
||||
formatSeriesIndex(seriesNumber?: number): string {
|
||||
if (seriesNumber == null) return '';
|
||||
return this.sanitize(seriesNumber.toString());
|
||||
}
|
||||
|
||||
saveChanges(): void {
|
||||
this.loading = true;
|
||||
|
||||
const request: FileMoveRequest = {
|
||||
bookIds: [...this.bookIds],
|
||||
moves: this.filePreviews.map(preview => ({
|
||||
bookId: preview.bookId,
|
||||
targetLibraryId: preview.targetLibraryId
|
||||
}))
|
||||
};
|
||||
|
||||
this.fileOperationsService.moveFiles(request).pipe(
|
||||
takeUntil(this.destroy$)
|
||||
).subscribe({
|
||||
next: () => {
|
||||
this.loading = false;
|
||||
this.filePreviews.forEach(p => (p.isMoved = true));
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Files Organized!',
|
||||
detail: `Successfully organized ${this.filePreviews.length} file${this.filePreviews.length === 1 ? '' : 's'}.`,
|
||||
life: 3000
|
||||
});
|
||||
},
|
||||
error: () => {
|
||||
this.loading = false;
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Oops! Something went wrong',
|
||||
detail: 'We had trouble organizing your files. Please try again.',
|
||||
life: 3000
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
cancel(): void {
|
||||
this.ref.close();
|
||||
}
|
||||
|
||||
togglePatternsCollapsed(): void {
|
||||
this.patternsCollapsed = !this.patternsCollapsed;
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
<div class="flex flex-col items-center justify-center p-2 md:p-6 rounded-lg border border-neutral-700" style="max-width: 700px; margin: auto;">
|
||||
<div class="mb-4 w-full text-center">
|
||||
<span class="inline-block px-3 py-1 rounded-full bg-blue-800/60 text-blue-200 text-xs font-semibold tracking-wide mb-2">
|
||||
Open Source & Community Driven
|
||||
</span>
|
||||
<h2 class="text-2xl font-bold text-white mb-2 tracking-tight">
|
||||
Booklore
|
||||
</h2>
|
||||
<p class="text-base text-zinc-200 leading-relaxed">
|
||||
Booklore is designed to help you manage your book collection with ease and enjoyment.<br>
|
||||
If you find Booklore valuable, please consider supporting its continued development.
|
||||
</p>
|
||||
</div>
|
||||
<div class="mb-4 w-full text-center">
|
||||
<p class="text-zinc-200 italic text-sm">
|
||||
Your feedback and support help me keep Booklore improving for everyone.<br>
|
||||
<span class="text-zinc-300">- Aditya (Creator of Booklore)</span>
|
||||
</p>
|
||||
</div>
|
||||
<div class="flex md:flex-row flex-col justify-center items-center gap-3 w-full mb-4">
|
||||
<a href="https://github.com/booklore-app/booklore" target="_blank" rel="noopener noreferrer" class="sm:w-auto">
|
||||
<p-button
|
||||
label="Star on GitHub"
|
||||
icon="pi pi-github"
|
||||
outlined
|
||||
severity="success"
|
||||
[style]="{ 'min-width': '160px' }">
|
||||
</p-button>
|
||||
</a>
|
||||
<a href="https://opencollective.com/booklore" target="_blank" rel="noopener noreferrer" class="sm:w-auto">
|
||||
<p-button
|
||||
label="Open Collective"
|
||||
icon="pi pi-globe"
|
||||
severity="info"
|
||||
outlined>
|
||||
</p-button>
|
||||
</a>
|
||||
<a href="https://account.venmo.com/u/AdityaChandel" target="_blank" rel="noopener noreferrer" class="sm:w-auto">
|
||||
<p-button
|
||||
label="Buy me a coffee"
|
||||
icon="pi pi-heart"
|
||||
outlined
|
||||
severity="danger">
|
||||
</p-button>
|
||||
</a>
|
||||
</div>
|
||||
<div class="w-full text-center mt-2">
|
||||
<span class="block mb-1 font-medium text-green-300 text-sm">Booklore will always remain free for everyone. That is my commitment to you.</span>
|
||||
<div class="text-gray-400 text-sm space-y-2 mt-2">
|
||||
<p>
|
||||
<span class="font-semibold text-blue-300">Open Collective</span> contributions directly support development, infrastructure, and ongoing improvements.
|
||||
</p>
|
||||
<p>
|
||||
<span class="font-semibold text-red-300">Venmo</span> is a wonderful way to show personal appreciation, think of it as buying me a coffee for my hard work.
|
||||
</p>
|
||||
<p class="text-yellow-200 pt-2">
|
||||
Every contribution, no matter the size, helps keep Booklore open, growing, and accessible to all.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,16 @@
|
||||
import { Component } from '@angular/core';
|
||||
import {Button} from 'primeng/button';
|
||||
|
||||
@Component({
|
||||
selector: 'app-github-support-dialog',
|
||||
imports: [
|
||||
Button
|
||||
],
|
||||
templateUrl: './github-support-dialog.html',
|
||||
styleUrl: './github-support-dialog.scss'
|
||||
})
|
||||
export class GithubSupportDialog {
|
||||
openGithub(): void {
|
||||
window.open('https://github.com/adityachandelgit/booklore', '_blank');
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
<input type="text" placeholder="Search icons..." [(ngModel)]="searchText" class="icon-search"/>
|
||||
|
||||
<div class="icon-grid">
|
||||
@for (icon of filteredIcons(); track icon) {
|
||||
<div
|
||||
class="icon-item"
|
||||
(click)="selectIcon(icon)"
|
||||
[class.selected]="icon === selectedIcon">
|
||||
<i [class]="icon"></i>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
.icon-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(25px, 1fr));
|
||||
gap: 30px;
|
||||
}
|
||||
|
||||
.icon-item {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.icon-search {
|
||||
width: 100%;
|
||||
padding: 8px 12px;
|
||||
font-size: 16px;
|
||||
border: 1px solid var(--text-color-secondary);
|
||||
border-radius: 4px;
|
||||
margin-bottom: 15px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.icon-search:focus {
|
||||
border-color: var(--primary-color);
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.icon-search::placeholder {
|
||||
color: var(--text-color-secondary);
|
||||
opacity: 1;
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
import {Component, EventEmitter, inject, Output} from '@angular/core';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
|
||||
@Component({
|
||||
selector: 'app-icon-picker-component',
|
||||
imports: [
|
||||
FormsModule
|
||||
],
|
||||
templateUrl: './icon-picker-component.html',
|
||||
styleUrl: './icon-picker-component.scss'
|
||||
})
|
||||
export class IconPickerComponent {
|
||||
|
||||
iconCategories: string[] = [
|
||||
"address-book", "align-center", "align-justify", "align-left", "align-right", "amazon", "android",
|
||||
"angle-double-down", "angle-double-left", "angle-double-right", "angle-double-up", "angle-down", "angle-left",
|
||||
"angle-right", "angle-up", "apple", "arrow-circle-down", "arrow-circle-left", "arrow-circle-right", "arrow-circle-up",
|
||||
"arrow-down", "arrow-down-left", "arrow-down-left-and-arrow-up-right-to-center", "arrow-down-right", "arrow-left",
|
||||
"arrow-right", "arrow-right-arrow-left", "arrow-up", "arrow-up-left", "arrow-up-right", "arrow-up-right-and-arrow-down-left-from-center",
|
||||
"arrows-alt", "arrows-h", "arrows-v", "asterisk", "at", "backward", "ban", "barcode", "bars", "bell", "bell-slash",
|
||||
"bitcoin", "bolt", "book", "bookmark", "bookmark-fill", "box", "briefcase", "building", "building-columns", "bullseye",
|
||||
"calculator", "calendar", "calendar-clock", "calendar-minus", "calendar-plus", "calendar-times", "camera", "car",
|
||||
"caret-down", "caret-left", "caret-right", "caret-up", "cart-arrow-down", "cart-minus", "cart-plus", "chart-bar",
|
||||
"chart-line", "chart-pie", "chart-scatter", "check", "check-circle", "check-square", "chevron-circle-down",
|
||||
"chevron-circle-left", "chevron-circle-right", "chevron-circle-up", "chevron-down", "chevron-left", "chevron-right",
|
||||
"chevron-up", "circle", "circle-fill", "circle-off", "circle-on", "clipboard", "clock", "clone", "cloud", "cloud-download",
|
||||
"cloud-upload", "code", "cog", "comment", "comments", "compass", "copy", "credit-card", "crown", "database", "delete-left",
|
||||
"desktop", "directions", "directions-alt", "discord", "dollar", "download", "eject", "ellipsis-h", "ellipsis-v",
|
||||
"envelope", "equals", "eraser", "ethereum", "euro", "exclamation-circle", "exclamation-triangle", "expand",
|
||||
"external-link", "eye", "eye-slash", "face-smile", "facebook", "fast-backward", "fast-forward", "file", "file-arrow-up",
|
||||
"file-check", "file-edit", "file-excel", "file-export", "file-import", "file-o", "file-pdf", "file-plus", "file-word",
|
||||
"filter", "filter-fill", "filter-slash", "flag", "flag-fill", "folder", "folder-open", "folder-plus", "forward", "gauge",
|
||||
"gift", "github", "globe", "google", "graduation-cap", "hammer", "hashtag", "headphones", "heart", "heart-fill", "history",
|
||||
"home", "hourglass", "id-card", "image", "images", "inbox", "indian-rupee", "info", "info-circle", "instagram", "key",
|
||||
"language", "lightbulb", "link", "linkedin", "list", "list-check", "lock", "lock-open", "map", "map-marker", "mars", "megaphone",
|
||||
"microchip", "microchip-ai", "microphone", "microsoft", "minus", "minus-circle", "mobile", "money-bill", "moon", "objects-column",
|
||||
"palette", "paperclip", "pause", "pause-circle", "paypal", "pen-to-square", "pencil", "percentage", "phone", "pinterest", "play",
|
||||
"play-circle", "plus", "plus-circle", "pound", "power-off", "prime", "print", "qrcode", "question", "question-circle", "receipt",
|
||||
"reddit", "refresh", "replay", "reply", "save", "search", "search-minus", "search-plus", "send", "server", "share-alt", "shield",
|
||||
"shop", "shopping-bag", "shopping-cart", "sign-in", "sign-out", "sitemap", "slack", "sliders-h", "sliders-v", "sort",
|
||||
"sort-alpha-down", "sort-alpha-down-alt", "sort-alpha-up", "sort-alpha-up-alt", "sort-alt", "sort-alt-slash",
|
||||
"sort-amount-down", "sort-amount-down-alt", "sort-amount-up", "sort-amount-up-alt", "sort-down", "sort-down-fill",
|
||||
"sort-numeric-down", "sort-numeric-down-alt", "sort-numeric-up", "sort-numeric-up-alt", "sort-up", "sort-up-fill", "sparkles",
|
||||
"spinner", "spinner-dotted", "star", "star-fill", "star-half", "star-half-fill", "step-backward", "step-backward-alt",
|
||||
"step-forward", "step-forward-alt", "stop", "stop-circle", "stopwatch", "sun", "sync", "table", "tablet", "tag", "tags",
|
||||
"telegram", "th-large", "thumbs-down", "thumbs-down-fill", "thumbs-up", "thumbs-up-fill", "thumbtack", "ticket", "tiktok",
|
||||
"times", "times-circle", "trash", "trophy", "truck", "turkish-lira", "twitch", "twitter", "undo", "unlock", "upload", "user",
|
||||
"user-edit", "user-minus", "user-plus", "users", "venus", "verified", "video", "vimeo", "volume-down", "volume-off",
|
||||
"volume-up", "wallet", "warehouse", "wave-pulse", "whatsapp", "wifi", "window-maximize", "window-minimize", "wrench",
|
||||
"youtube"
|
||||
];
|
||||
|
||||
searchText: string = '';
|
||||
selectedIcon: string | null = null;
|
||||
icons: string[] = this.createIconList(this.iconCategories);
|
||||
|
||||
ref = inject(DynamicDialogRef);
|
||||
|
||||
createIconList(categories: string[]): string[] {
|
||||
return categories.map(iconName => `pi pi-${iconName}`);
|
||||
}
|
||||
|
||||
filteredIcons(): string[] {
|
||||
if (!this.searchText) return this.icons;
|
||||
return this.icons.filter(icon => icon.toLowerCase().includes(this.searchText.toLowerCase()));
|
||||
}
|
||||
|
||||
selectIcon(icon: string) {
|
||||
this.selectedIcon = icon;
|
||||
this.ref.close(icon);
|
||||
}
|
||||
|
||||
cancel() {
|
||||
this.ref.close();
|
||||
}
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
<div class="flex flex-col p-4 space-y-2 live-border">
|
||||
<p class="text-xs text-zinc-400">{{ latestNotification.timestamp }}</p>
|
||||
<p class="font-normal text-zinc-200">{{ latestNotification.message }}</p>
|
||||
</div>
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
.live-border {
|
||||
background: var(--card-background);
|
||||
border: 1px solid var(--primary-color);
|
||||
border-radius: 0.5rem;
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
import {Component, inject} from '@angular/core';
|
||||
import {NotificationEventService} from '../../websocket/notification-event.service';
|
||||
import {LogNotification} from '../../websocket/model/log-notification.model';
|
||||
|
||||
@Component({
|
||||
selector: 'app-live-notification-box',
|
||||
standalone: true,
|
||||
templateUrl: './live-notification-box.component.html',
|
||||
styleUrls: ['./live-notification-box.component.scss'],
|
||||
host: {
|
||||
class: 'config-panel'
|
||||
},
|
||||
})
|
||||
export class LiveNotificationBoxComponent {
|
||||
latestNotification: LogNotification = {message: 'No recent notifications...'};
|
||||
|
||||
private notificationService = inject(NotificationEventService);
|
||||
|
||||
constructor() {
|
||||
this.notificationService.latestNotification$.subscribe(notification => {
|
||||
this.latestNotification = notification;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import {Component, OnInit, OnDestroy, inject} from '@angular/core';
|
||||
import { Subscription } from 'rxjs';
|
||||
import {LoadingService} from '../../../core/service/loading.service';
|
||||
import {LoadingService} from '../../service/loading.service';
|
||||
import {ProgressSpinner} from 'primeng/progressspinner';
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
<div class="flex items-center justify-center min-h-screen min-w-[100vw] overflow-hidden"
|
||||
style="background: linear-gradient(60deg, var(--primary-color) 0%, #1e3a8a 100%);">
|
||||
<div class="flex flex-col items-center justify-center -mt-48 w-[90%] sm:w-auto sm:min-w-[400px] md:min-w-[500px]">
|
||||
<div class="w-full" style="border-radius: 56px; padding: 0.3rem; background: linear-gradient(180deg, var(--primary-color) 10%, rgba(33, 150, 243, 0) 30%)">
|
||||
<div class="w-full bg-surface-900 pt-8 pb-14 px-8 sm:px-12" style="border-radius: 53px">
|
||||
<div class="text-center mb-8">
|
||||
<svg class="mb-8 w-14 h-14 mx-auto" viewBox="0 0 126 126" fill="var(--primary-color)" xmlns="http://www.w3.org/2000/svg">
|
||||
<path
|
||||
d="M59 4.79297C71.5051 11.5557 80 24.7854 80 40C80 40.5959 79.987 41.1888 79.9609 41.7783C79.8609 44.0406 81.7355 46 84 46C106.091 46 124 63.9086 124 86C124 108.091 106.091 126 84 126H10C4.47715 126 0 121.523 0 116V39.0068L0.0126953 38.9941C0.357624 25.0252 7.86506 12.8347 19 5.95215V63.832C19 64.8345 20.0676 65.4391 20.9121 64.9902L21.0771 64.8867L38.2227 52.3428C38.6819 52.0068 39.3064 52.0068 39.7656 52.3428L56.9229 64.8945L57.0879 64.998C57.9324 65.447 59 64.8423 59 63.8398V4.79297Z"/>
|
||||
<path
|
||||
d="M40 0C43.8745 0 47.6199 0.552381 51.1631 1.58008V50.9697L44.3926 46.0176L44.0879 45.8037C40.9061 43.6679 36.7098 43.7393 33.5957 46.0176L26.8369 50.9619V2.21875C30.9593 0.782634 35.3881 0 40 0Z"
|
||||
fill="white"/>
|
||||
</svg>
|
||||
<div class="text-3xl font-medium mb-4">Welcome to Booklore</div>
|
||||
<span class="font-medium">Sign in to continue</span>
|
||||
</div>
|
||||
|
||||
@if (showOidcBypassInfo) {
|
||||
<div class="mb-4 p-3 rounded-md bg-yellow-900/30 border border-yellow-600/50 w-full">
|
||||
<div class="flex flex-col items-center">
|
||||
<div class="flex items-center gap-2 text-yellow-200 text-sm mb-2">
|
||||
<i class="pi pi-exclamation-triangle"></i>
|
||||
<span class="font-medium">OIDC Authentication Issues Detected</span>
|
||||
</div>
|
||||
<p class="text-xs text-yellow-300 mb-3 text-center">
|
||||
{{ oidcBypassMessage }}
|
||||
</p>
|
||||
<div class="flex gap-4">
|
||||
<p-button
|
||||
size="small"
|
||||
severity="warn"
|
||||
label="Retry OIDC"
|
||||
icon="pi pi-refresh"
|
||||
(click)="retryOidc()"
|
||||
/>
|
||||
<p-button
|
||||
size="small"
|
||||
severity="success"
|
||||
label="Use Local Login"
|
||||
icon="pi pi-times"
|
||||
(click)="dismissOidcWarning()"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
<form class="flex flex-col gap-4 w-full" #loginForm="ngForm" (ngSubmit)="login()">
|
||||
<div class="flex flex-col gap-2">
|
||||
<label for="username" class="text-lg font-medium">Username</label>
|
||||
<input
|
||||
fluid
|
||||
pInputText
|
||||
id="username"
|
||||
name="username"
|
||||
required
|
||||
[(ngModel)]="username"
|
||||
placeholder="Enter your username"
|
||||
class="w-full"
|
||||
autocomplete="username"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col gap-2">
|
||||
<label for="password" class="text-lg font-medium">Password</label>
|
||||
<p-password
|
||||
id="password"
|
||||
name="password"
|
||||
required
|
||||
[(ngModel)]="password"
|
||||
[feedback]="false"
|
||||
placeholder="Enter your password"
|
||||
[toggleMask]="true"
|
||||
class="mb-4"
|
||||
[fluid]="true"
|
||||
autocomplete="current-password"
|
||||
></p-password>
|
||||
</div>
|
||||
|
||||
<p-button
|
||||
fluid
|
||||
type="submit"
|
||||
label="Login"
|
||||
icon="pi pi-sign-in"
|
||||
[disabled]="!loginForm.valid || !username || !password"
|
||||
class="w-full">
|
||||
</p-button>
|
||||
|
||||
@if (errorMessage) {
|
||||
<p-message severity="error">{{ errorMessage }}</p-message>
|
||||
}
|
||||
|
||||
@if (oidcEnabled && !isOidcBypassed) {
|
||||
<div class="flex items-center gap-2 my-2">
|
||||
<hr class="flex-grow" style="border: none; border-top: 1px solid var(--border-color);"/>
|
||||
<span class="text-gray-300">or</span>
|
||||
<hr class="flex-grow" style="border: none; border-top: 1px solid var(--border-color);"/>
|
||||
</div>
|
||||
|
||||
<p-button
|
||||
fluid
|
||||
severity="info"
|
||||
[label]="isOidcLoginInProgress ? 'Redirecting to ' + oidcName + '...' : 'Login with ' + oidcName"
|
||||
[icon]="isOidcLoginInProgress ? 'pi pi-spin pi-spinner' : 'pi pi-id-card'"
|
||||
[disabled]="isOidcLoginInProgress"
|
||||
(click)="loginWithOidc()"
|
||||
class="w-full bg-gray-800 text-white hover:bg-gray-700"/>
|
||||
|
||||
<div class="text-center">
|
||||
<button
|
||||
type="button"
|
||||
class="text-xs text-gray-400 hover:text-gray-300 underline"
|
||||
(click)="bypassOidc()">
|
||||
Having trouble with {{ oidcName }}? Use local login only
|
||||
</button>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (oidcEnabled && isOidcBypassed) {
|
||||
<div class="text-center mt-4">
|
||||
<button
|
||||
type="button"
|
||||
class="text-xs text-blue-400 hover:text-blue-300 underline"
|
||||
(click)="enableOidc()">
|
||||
Re-enable {{ oidcName }} login
|
||||
</button>
|
||||
</div>
|
||||
}
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,146 @@
|
||||
import {Component, inject, OnDestroy, OnInit} from '@angular/core';
|
||||
import {AuthService} from '../../service/auth.service';
|
||||
import {Router} from '@angular/router';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {Password} from 'primeng/password';
|
||||
import {Button} from 'primeng/button';
|
||||
import {Message} from 'primeng/message';
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
import {OAuthService} from 'angular-oauth2-oidc';
|
||||
import {Observable, Subject} from 'rxjs';
|
||||
import {filter, take} from 'rxjs/operators';
|
||||
import {getOidcErrorCount, isOidcBypassed, resetOidcBypass} from '../../../core/auth-initializer';
|
||||
import {AppSettingsService, PublicAppSettings} from '../../service/app-settings.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-login',
|
||||
imports: [
|
||||
FormsModule,
|
||||
Password,
|
||||
Button,
|
||||
Message,
|
||||
InputText
|
||||
],
|
||||
templateUrl: './login.component.html',
|
||||
styleUrls: ['./login.component.scss']
|
||||
})
|
||||
export class LoginComponent implements OnInit, OnDestroy {
|
||||
username = '';
|
||||
password = '';
|
||||
errorMessage = '';
|
||||
oidcEnabled = false;
|
||||
oidcName = 'OIDC';
|
||||
isOidcBypassed = false;
|
||||
showOidcBypassInfo = false;
|
||||
oidcBypassMessage = '';
|
||||
isOidcLoginInProgress = false;
|
||||
|
||||
private authService = inject(AuthService);
|
||||
private oAuthService = inject(OAuthService);
|
||||
private appSettingsService = inject(AppSettingsService);
|
||||
private router = inject(Router);
|
||||
|
||||
publicAppSettings$: Observable<PublicAppSettings | null> = this.appSettingsService.publicAppSettings$;
|
||||
|
||||
private destroy$ = new Subject<void>();
|
||||
|
||||
ngOnInit(): void {
|
||||
this.publicAppSettings$
|
||||
.pipe(
|
||||
filter(settings => settings != null),
|
||||
take(1)
|
||||
)
|
||||
.subscribe(publicSettings => {
|
||||
this.oidcEnabled = publicSettings!.oidcEnabled;
|
||||
this.oidcName = publicSettings!.oidcProviderDetails?.providerName || 'OIDC';
|
||||
this.checkOidcBypassStatus();
|
||||
});
|
||||
}
|
||||
|
||||
private checkOidcBypassStatus(): void {
|
||||
this.isOidcBypassed = isOidcBypassed();
|
||||
const errorCount = getOidcErrorCount();
|
||||
|
||||
if (this.oidcEnabled && (this.isOidcBypassed || errorCount > 0)) {
|
||||
this.showOidcBypassInfo = true;
|
||||
|
||||
if (this.isOidcBypassed && errorCount >= 3) {
|
||||
this.oidcBypassMessage = `${this.oidcName} authentication has been automatically disabled after ${errorCount} consecutive failures (including timeouts). You can retry or continue with local login.`;
|
||||
} else if (this.isOidcBypassed) {
|
||||
this.oidcBypassMessage = `${this.oidcName} authentication has been manually disabled. You can re-enable it or continue with local login.`;
|
||||
} else if (errorCount > 0) {
|
||||
this.oidcBypassMessage = `${this.oidcName} authentication encountered ${errorCount} error(s), possibly due to timeouts or server issues.`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
login(): void {
|
||||
this.authService.internalLogin({username: this.username, password: this.password}).subscribe({
|
||||
next: (response) => {
|
||||
if (response.isDefaultPassword === 'true') {
|
||||
this.router.navigate(['/change-password']);
|
||||
} else {
|
||||
this.router.navigate(['/dashboard']);
|
||||
}
|
||||
},
|
||||
error: (error) => {
|
||||
if (error.status === 0) {
|
||||
this.errorMessage = 'Cannot connect to the server. Please check your connection and try again.';
|
||||
} else {
|
||||
this.errorMessage = error?.error?.message || 'An unexpected error occurred. Please try again.';
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
loginWithOidc(): void {
|
||||
if (this.isOidcLoginInProgress) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.isOidcLoginInProgress = true;
|
||||
this.errorMessage = '';
|
||||
|
||||
try {
|
||||
setTimeout(() => {
|
||||
this.isOidcLoginInProgress = false;
|
||||
}, 5000);
|
||||
this.oAuthService.initCodeFlow();
|
||||
} catch (error) {
|
||||
console.error('OIDC login initiation failed:', error);
|
||||
this.errorMessage = 'Failed to initiate OIDC login. Please try again or use local login.';
|
||||
this.isOidcLoginInProgress = false;
|
||||
}
|
||||
}
|
||||
|
||||
bypassOidc(): void {
|
||||
localStorage.setItem('booklore-oidc-bypass', 'true');
|
||||
this.isOidcBypassed = true;
|
||||
this.showOidcBypassInfo = false;
|
||||
}
|
||||
|
||||
enableOidc(): void {
|
||||
resetOidcBypass();
|
||||
this.isOidcBypassed = false;
|
||||
this.showOidcBypassInfo = false;
|
||||
this.isOidcLoginInProgress = false;
|
||||
window.location.reload();
|
||||
}
|
||||
|
||||
retryOidc(): void {
|
||||
resetOidcBypass();
|
||||
this.isOidcBypassed = false;
|
||||
this.showOidcBypassInfo = false;
|
||||
this.isOidcLoginInProgress = false;
|
||||
window.location.reload();
|
||||
}
|
||||
|
||||
dismissOidcWarning(): void {
|
||||
this.showOidcBypassInfo = false;
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
}
|
||||
}
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
<div class="task-border mt-4">
|
||||
@if (Object.keys(activeTasks).length > 0) {
|
||||
@for (task of activeTasks | keyvalue; track task; let idx = $index) {
|
||||
<div class="task-card p-4">
|
||||
|
||||
<div class="flex items-center justify-between mb-2">
|
||||
<div class="flex items-center gap-2">
|
||||
<p class="text-sm font-semibold text-[var(--primary-color)]">Metadata Fetch Task</p>
|
||||
</div>
|
||||
<div class="flex items-center gap-1">
|
||||
@if (task.value.review) {
|
||||
<p-tag
|
||||
value="Review"
|
||||
severity="warn"
|
||||
class="text-xs">
|
||||
</p-tag>
|
||||
} @else {
|
||||
<p-tag
|
||||
value="Auto"
|
||||
severity="success"
|
||||
class="text-xs">
|
||||
</p-tag>
|
||||
}
|
||||
<p-tag
|
||||
[value]="getStatusLabel(task.value.status)"
|
||||
[severity]="getTagSeverity(task.value.status)"
|
||||
class="text-xs"
|
||||
></p-tag>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="task-message text-gray-200">
|
||||
{{ task.value.message }}
|
||||
</div>
|
||||
|
||||
<div class="task-progress-info text-sm text-gray-300">
|
||||
Book <strong>{{ task.value.status === 'COMPLETED' || task.value.completed >= task.value.total ? task.value.total : task.value.completed + 1 }}</strong>
|
||||
of {{ task.value.total }}
|
||||
</div>
|
||||
|
||||
<p-progressBar
|
||||
[style]="{ height: '15px' }"
|
||||
[value]="getProgressPercent(task.value)"
|
||||
[showValue]="true">
|
||||
</p-progressBar>
|
||||
|
||||
@if (task.value.status === 'COMPLETED' || task.value.status === 'ERROR') {
|
||||
<div class="action-buttons mt-4 flex justify-end gap-2">
|
||||
@if (task.value.review) {
|
||||
<p-button
|
||||
label="Review"
|
||||
severity="info"
|
||||
icon="pi pi-search"
|
||||
size="small"
|
||||
outlined
|
||||
(click)="reviewTask(task.key)">
|
||||
</p-button>
|
||||
}
|
||||
|
||||
<p-button
|
||||
[label]="task.value.review ? 'Discard' : 'Dismiss'"
|
||||
icon="pi pi-times"
|
||||
[severity]="task.value.review ? 'danger' : 'secondary'"
|
||||
size="small"
|
||||
[pTooltip]="task.value.review ? 'Preserve current metadata, discard new fetched metadata' : ''"
|
||||
[tooltipPosition]="task.value.review ? 'top' : undefined"
|
||||
outlined
|
||||
(click)="clearTask(task.key)">
|
||||
</p-button>
|
||||
</div>
|
||||
} @else if (task.value.status === 'IN_PROGRESS') {
|
||||
<div class="action-buttons mt-4 flex justify-end gap-2">
|
||||
<p-button
|
||||
label="Cancel"
|
||||
icon="pi pi-stop"
|
||||
severity="danger"
|
||||
size="small"
|
||||
pTooltip="Cancel this task"
|
||||
tooltipPosition="top"
|
||||
outlined
|
||||
(click)="cancelTask(task.key)">
|
||||
</p-button>
|
||||
</div>
|
||||
}
|
||||
|
||||
</div>
|
||||
|
||||
@if (idx < Object.keys(activeTasks).length - 1) {
|
||||
<p-divider></p-divider>
|
||||
}
|
||||
}
|
||||
}
|
||||
</div>
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
.task-border {
|
||||
background: var(--card-background);
|
||||
border: 1px solid var(--primary-color);
|
||||
border-radius: 0.5rem;
|
||||
}
|
||||
|
||||
.task-header {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.task-message {
|
||||
font-size: 1rem;
|
||||
color: var(--text-color);
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.task-progress-info {
|
||||
font-size: 0.875rem;
|
||||
color: var(--text-secondary-color);
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.review-button {
|
||||
text-align: right;
|
||||
margin-top: 0.75rem;
|
||||
}
|
||||
|
||||
.review-indicator {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
+172
@@ -0,0 +1,172 @@
|
||||
import {Component, inject, OnDestroy, OnInit} from '@angular/core';
|
||||
import {Subject} from 'rxjs';
|
||||
import {takeUntil} from 'rxjs/operators';
|
||||
import {KeyValuePipe} from '@angular/common';
|
||||
import {ProgressBarModule} from 'primeng/progressbar';
|
||||
import {ButtonModule} from 'primeng/button';
|
||||
import {Divider} from 'primeng/divider';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {DialogService} from 'primeng/dynamicdialog';
|
||||
import {MessageService} from 'primeng/api';
|
||||
|
||||
import {MetadataBatchProgressNotification, MetadataBatchStatus, MetadataBatchStatusLabels} from '../../model/metadata-batch-progress.model';
|
||||
import {MetadataProgressService} from '../../service/metadata-progress-service';
|
||||
import {MetadataReviewDialogComponent} from '../../../features/metadata/component/metadata-review-dialog-component/metadata-review-dialog-component';
|
||||
import {MetadataTaskService} from '../../../features/book/service/metadata-task';
|
||||
import {TaskService} from '../../services/task.service';
|
||||
import {Tag} from 'primeng/tag';
|
||||
|
||||
@Component({
|
||||
selector: 'app-metadata-progress-widget',
|
||||
templateUrl: './metadata-progress-widget-component.html',
|
||||
styleUrls: ['./metadata-progress-widget-component.scss'],
|
||||
standalone: true,
|
||||
imports: [KeyValuePipe, ProgressBarModule, ButtonModule, Divider, Tooltip, Tag]
|
||||
})
|
||||
export class MetadataProgressWidgetComponent implements OnInit, OnDestroy {
|
||||
activeTasks: { [taskId: string]: MetadataBatchProgressNotification } = {};
|
||||
|
||||
private destroy$ = new Subject<void>();
|
||||
private dialogService = inject(DialogService);
|
||||
private metadataProgressService = inject(MetadataProgressService);
|
||||
private metadataTaskService = inject(MetadataTaskService);
|
||||
private taskService = inject(TaskService);
|
||||
private messageService = inject(MessageService);
|
||||
|
||||
private lastUpdateMap = new Map<string, number>();
|
||||
private timeoutHandles = new Map<string, any>();
|
||||
private readonly TASK_STALL_TIMEOUT_MS = 60 * 1000; // 1 minute
|
||||
|
||||
ngOnInit(): void {
|
||||
this.metadataProgressService.activeTasks$
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
.subscribe(tasks => {
|
||||
this.activeTasks = tasks;
|
||||
this.checkForStalledTasks(tasks);
|
||||
});
|
||||
}
|
||||
|
||||
private checkForStalledTasks(tasks: { [taskId: string]: MetadataBatchProgressNotification }): void {
|
||||
const now = Date.now();
|
||||
|
||||
for (const taskId of this.timeoutHandles.keys()) {
|
||||
if (!tasks[taskId]) {
|
||||
clearTimeout(this.timeoutHandles.get(taskId));
|
||||
this.timeoutHandles.delete(taskId);
|
||||
this.lastUpdateMap.delete(taskId);
|
||||
}
|
||||
}
|
||||
|
||||
for (const [taskId, task] of Object.entries(tasks)) {
|
||||
this.lastUpdateMap.set(taskId, now);
|
||||
|
||||
if (this.timeoutHandles.has(taskId)) {
|
||||
clearTimeout(this.timeoutHandles.get(taskId));
|
||||
}
|
||||
|
||||
this.timeoutHandles.set(
|
||||
taskId,
|
||||
setTimeout(() => {
|
||||
this.markTaskStalled(taskId);
|
||||
}, this.TASK_STALL_TIMEOUT_MS)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private markTaskStalled(taskId: string): void {
|
||||
const task = this.activeTasks[taskId];
|
||||
if (!task) return;
|
||||
if (task.status !== MetadataBatchStatus.COMPLETED && task.status !== 'ERROR') {
|
||||
this.activeTasks[taskId] = {
|
||||
...task,
|
||||
status: MetadataBatchStatus.ERROR,
|
||||
message: 'Task stalled or backend unavailable'
|
||||
};
|
||||
this.activeTasks = {...this.activeTasks};
|
||||
}
|
||||
}
|
||||
|
||||
getProgressPercent(task: MetadataBatchProgressNotification): number {
|
||||
if (task.total <= 0) return 0;
|
||||
if (task.status === 'COMPLETED') return 100;
|
||||
return Math.round((task.completed / task.total) * 100);
|
||||
}
|
||||
|
||||
clearTask(taskId: string): void {
|
||||
this.metadataTaskService.deleteTask(taskId).subscribe(() => {
|
||||
this.metadataProgressService.clearTask(taskId);
|
||||
clearTimeout(this.timeoutHandles.get(taskId));
|
||||
this.timeoutHandles.delete(taskId);
|
||||
this.lastUpdateMap.delete(taskId);
|
||||
});
|
||||
}
|
||||
|
||||
reviewTask(taskId: string): void {
|
||||
this.dialogService.open(MetadataReviewDialogComponent, {
|
||||
showHeader: false,
|
||||
width: '90vw',
|
||||
height: '90vh',
|
||||
data: {taskId},
|
||||
closable: false,
|
||||
modal: true
|
||||
});
|
||||
}
|
||||
|
||||
cancelTask(taskId: string): void {
|
||||
this.taskService.cancelTask(taskId).subscribe({
|
||||
next: () => {
|
||||
const task = this.activeTasks[taskId];
|
||||
if (task) {
|
||||
this.activeTasks[taskId] = {
|
||||
...task,
|
||||
status: MetadataBatchStatus.ERROR,
|
||||
message: 'Task cancelled by user'
|
||||
};
|
||||
this.activeTasks = {...this.activeTasks};
|
||||
}
|
||||
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Cancellation Scheduled',
|
||||
detail: 'Task cancellation has been successfully scheduled'
|
||||
});
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Failed to cancel task:', error);
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Cancel Failed',
|
||||
detail: 'Failed to cancel the task. Please try again.'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
for (const timeout of this.timeoutHandles.values()) {
|
||||
clearTimeout(timeout);
|
||||
}
|
||||
this.timeoutHandles.clear();
|
||||
this.lastUpdateMap.clear();
|
||||
}
|
||||
|
||||
getTagSeverity(status: 'IN_PROGRESS' | 'COMPLETED' | 'ERROR'): 'info' | 'success' | 'danger' {
|
||||
switch (status) {
|
||||
case 'COMPLETED':
|
||||
return 'success';
|
||||
case 'ERROR':
|
||||
return 'danger';
|
||||
case 'IN_PROGRESS':
|
||||
default:
|
||||
return 'info';
|
||||
}
|
||||
}
|
||||
|
||||
getStatusLabel(status: MetadataBatchStatus): string {
|
||||
return MetadataBatchStatusLabels[status] ?? status;
|
||||
}
|
||||
|
||||
protected readonly Object = Object;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import { inject, Injectable } from '@angular/core';
|
||||
import { CanActivate, Router } from '@angular/router';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Observable, map, catchError, of } from 'rxjs';
|
||||
import { API_CONFIG } from '../../../core/config/api-config';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class LoginGuard implements CanActivate {
|
||||
private readonly url = `${API_CONFIG.BASE_URL}/api/v1/setup`;
|
||||
private http = inject(HttpClient);
|
||||
private router = inject(Router);
|
||||
|
||||
canActivate(): Observable<boolean> {
|
||||
return this.http.get<{ data: boolean }>(`${this.url}/status`).pipe(
|
||||
map(res => {
|
||||
if (!res.data) {
|
||||
this.router.navigate(['/setup']);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}),
|
||||
catchError(() => {
|
||||
this.router.navigate(['/setup']);
|
||||
return of(false);
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import {inject, Injectable} from '@angular/core';
|
||||
import { CanActivate, Router } from '@angular/router';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Observable, map } from 'rxjs';
|
||||
import {API_CONFIG} from '../../../core/config/api-config';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class SetupRedirectGuard implements CanActivate {
|
||||
private readonly url = `${API_CONFIG.BASE_URL}/api/v1/setup`;
|
||||
|
||||
private http = inject(HttpClient);
|
||||
private router = inject(Router);
|
||||
|
||||
canActivate(): Observable<boolean> {
|
||||
return this.http.get<{ data: boolean }>(`${this.url}/status`).pipe(
|
||||
map(res => {
|
||||
if (!res.data) {
|
||||
this.router.navigate(['/setup']);
|
||||
} else {
|
||||
this.router.navigate(['/dashboard']);
|
||||
}
|
||||
return false;
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
<div class="flex items-center justify-center min-h-screen min-w-[100vw] overflow-hidden"
|
||||
style="background: linear-gradient(60deg, var(--primary-color) 0%, #1e3a8a 100%);">
|
||||
<div class="flex flex-col items-center justify-center -mt-48">
|
||||
<div style="border-radius: 56px; padding: 0.3rem; background: linear-gradient(180deg, var(--primary-color) 10%, rgba(33, 150, 243, 0) 30%)">
|
||||
<div class="w-full bg-surface-900 py-16 px-8 sm:px-16" style="border-radius: 53px">
|
||||
<div class="text-center mb-8">
|
||||
<svg class="mb-8 w-16 h-16 mx-auto" viewBox="0 0 126 126" fill="var(--primary-color)" xmlns="http://www.w3.org/2000/svg">
|
||||
<path
|
||||
d="M59 4.79297C71.5051 11.5557 80 24.7854 80 40C80 40.5959 79.987 41.1888 79.9609 41.7783C79.8609 44.0406 81.7355 46 84 46C106.091 46 124 63.9086 124 86C124 108.091 106.091 126 84 126H10C4.47715 126 0 121.523 0 116V39.0068L0.0126953 38.9941C0.357624 25.0252 7.86506 12.8347 19 5.95215V63.832C19 64.8345 20.0676 65.4391 20.9121 64.9902L21.0771 64.8867L38.2227 52.3428C38.6819 52.0068 39.3064 52.0068 39.7656 52.3428L56.9229 64.8945L57.0879 64.998C57.9324 65.447 59 64.8423 59 63.8398V4.79297Z"/>
|
||||
<path
|
||||
d="M40 0C43.8745 0 47.6199 0.552381 51.1631 1.58008V50.9697L44.3926 46.0176L44.0879 45.8037C40.9061 43.6679 36.7098 43.7393 33.5957 46.0176L26.8369 50.9619V2.21875C30.9593 0.782634 35.3881 0 40 0Z"
|
||||
fill="white"/>
|
||||
</svg>
|
||||
<div class="text-3xl font-medium mb-4">Welcome to Booklore</div>
|
||||
<span class="text-xl">Setup Initial Admin Account</span>
|
||||
</div>
|
||||
|
||||
<form class="flex flex-col gap-4" [formGroup]="setupForm" (ngSubmit)="onSubmit()">
|
||||
|
||||
<div class="flex flex-col gap-2">
|
||||
<label for="username" class="text-lg font-medium">Username</label>
|
||||
<input
|
||||
pInputText
|
||||
id="username"
|
||||
name="username"
|
||||
required
|
||||
formControlName="username"
|
||||
placeholder="Enter your username"
|
||||
class="w-full md:w-[30rem]"
|
||||
/>
|
||||
@if (setupForm.get('username')?.invalid && setupForm.get('username')?.touched) {
|
||||
<small class="text-red-500">
|
||||
Username is required.
|
||||
</small>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col gap-2">
|
||||
<label for="name" class="text-lg font-medium">Name</label>
|
||||
<input
|
||||
pInputText
|
||||
id="name"
|
||||
name="name"
|
||||
required
|
||||
formControlName="name"
|
||||
placeholder="Enter your full name"
|
||||
class="w-full md:w-[30rem]"
|
||||
/>
|
||||
@if (setupForm.get('name')?.invalid && setupForm.get('name')?.touched) {
|
||||
<small class="text-red-500">
|
||||
Name is required.
|
||||
</small>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col gap-2">
|
||||
<label for="email" class="text-lg font-medium">Email</label>
|
||||
<input
|
||||
pInputText
|
||||
id="email"
|
||||
name="email"
|
||||
required
|
||||
formControlName="email"
|
||||
placeholder="Enter your email"
|
||||
class="w-full md:w-[30rem]"
|
||||
/>
|
||||
@if (setupForm.get('email')?.invalid && setupForm.get('email')?.touched) {
|
||||
<small class="text-red-500">
|
||||
Valid email is required.
|
||||
</small>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col gap-2">
|
||||
<label for="password" class="text-lg font-medium">Password</label>
|
||||
<input
|
||||
pInputText
|
||||
id="password"
|
||||
name="password"
|
||||
required
|
||||
formControlName="password"
|
||||
placeholder="Enter new password"
|
||||
class="w-full md:w-[30rem]"
|
||||
/>
|
||||
@if (setupForm.get('password')?.invalid && setupForm.get('password')?.touched) {
|
||||
<small class="text-red-500">
|
||||
Minimum 6 characters required.
|
||||
</small>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col gap-3 mt-4">
|
||||
<p-button
|
||||
fluid
|
||||
type="submit"
|
||||
[label]="loading ? 'Creating…' : 'Create Admin Account'"
|
||||
[disabled]="loading || setupForm.invalid"
|
||||
icon="pi pi-user-plus"
|
||||
>
|
||||
</p-button>
|
||||
|
||||
@if (error) {
|
||||
<p-message severity="error" text="{{ error }}"></p-message>
|
||||
}
|
||||
@if (success) {
|
||||
<p-message severity="success" text="Admin account created! Redirecting…"></p-message>
|
||||
}
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,58 @@
|
||||
import {Component} from '@angular/core';
|
||||
import {FormBuilder, FormGroup, ReactiveFormsModule, Validators} from '@angular/forms';
|
||||
import {Router} from '@angular/router';
|
||||
import {SetupService} from './setup.service';
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
import {Button} from 'primeng/button';
|
||||
import {Message} from 'primeng/message';
|
||||
|
||||
@Component({
|
||||
selector: 'app-setup',
|
||||
templateUrl: './setup.component.html',
|
||||
styleUrls: ['./setup.component.scss'],
|
||||
standalone: true,
|
||||
imports: [
|
||||
ReactiveFormsModule,
|
||||
InputText,
|
||||
Button,
|
||||
Message
|
||||
]
|
||||
})
|
||||
export class SetupComponent {
|
||||
setupForm: FormGroup;
|
||||
loading = false;
|
||||
error: string | null = null;
|
||||
success = false;
|
||||
|
||||
constructor(
|
||||
private fb: FormBuilder,
|
||||
private setupService: SetupService,
|
||||
private router: Router
|
||||
) {
|
||||
this.setupForm = this.fb.group({
|
||||
name: ['', [Validators.required]],
|
||||
username: ['', [Validators.required]],
|
||||
email: ['', [Validators.required, Validators.email]],
|
||||
password: ['', [Validators.required, Validators.minLength(6)]],
|
||||
});
|
||||
}
|
||||
|
||||
onSubmit(): void {
|
||||
if (this.setupForm.invalid) return;
|
||||
|
||||
this.loading = true;
|
||||
this.error = null;
|
||||
|
||||
this.setupService.createAdmin(this.setupForm.value).subscribe({
|
||||
next: () => {
|
||||
this.success = true;
|
||||
setTimeout(() => this.router.navigate(['/login']), 1500);
|
||||
},
|
||||
error: (err) => {
|
||||
this.loading = false;
|
||||
this.error =
|
||||
err?.error?.message || 'Failed to create admin user. Try again.';
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import {inject, Injectable} from '@angular/core';
|
||||
import {
|
||||
CanActivate,
|
||||
Router,
|
||||
UrlTree
|
||||
} from '@angular/router';
|
||||
import {Observable} from 'rxjs';
|
||||
import {map} from 'rxjs/operators';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {API_CONFIG} from '../../../core/config/api-config';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class SetupGuard implements CanActivate {
|
||||
|
||||
private readonly url = `${API_CONFIG.BASE_URL}/api/v1/setup`;
|
||||
|
||||
private http = inject(HttpClient);
|
||||
private router = inject(Router);
|
||||
|
||||
canActivate(): Observable<boolean | UrlTree> {
|
||||
return this.http.get<any>(`${this.url}/status`).pipe(
|
||||
map(response => {
|
||||
if (response?.data === true) {
|
||||
return this.router.createUrlTree(['/login']);
|
||||
}
|
||||
return true;
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import {inject, Injectable} from '@angular/core';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {Observable} from 'rxjs';
|
||||
import {API_CONFIG} from '../../../core/config/api-config';
|
||||
|
||||
export interface SetupPayload {
|
||||
email: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
@Injectable({providedIn: 'root'})
|
||||
export class SetupService {
|
||||
|
||||
private readonly url = `${API_CONFIG.BASE_URL}/api/v1/setup`;
|
||||
|
||||
private http = inject(HttpClient);
|
||||
|
||||
createAdmin(payload: SetupPayload): Observable<void> {
|
||||
return this.http.post<void>(this.url, payload);
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
<div class="metadata-progress-box flex gap-4 flex-col w-[25rem] max-h-[60vh] overflow-y-auto">
|
||||
<app-live-notification-box/>
|
||||
@if (hasDuplicateFiles$ | async) {
|
||||
<app-duplicate-files-notification/>
|
||||
}
|
||||
@if (hasMetadataTasks$ | async) {
|
||||
<app-metadata-progress-widget/>
|
||||
}
|
||||
@if (hasPendingBookdropFiles$ | async) {
|
||||
<app-bookdrop-files-widget-component/>
|
||||
}
|
||||
</div>
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
.metadata-progress-box {
|
||||
overflow-y: auto;
|
||||
border-radius: 0.5rem;
|
||||
}
|
||||
|
||||
::ng-deep .p-divider-horizontal {
|
||||
margin: 0 !important;
|
||||
padding: 0 !important;
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
import {Component, inject} from '@angular/core';
|
||||
import {LiveNotificationBoxComponent} from '../live-notification-box/live-notification-box.component';
|
||||
import {MetadataProgressService} from '../../service/metadata-progress-service';
|
||||
import {map} from 'rxjs/operators';
|
||||
import {AsyncPipe} from '@angular/common';
|
||||
import {BookdropFileService} from '../../../features/bookdrop/service/bookdrop-file.service';
|
||||
import {DuplicateFilesNotificationComponent} from '../duplicate-files-notification/duplicate-files-notification.component';
|
||||
import {DuplicateFileService} from '../../websocket/duplicate-file.service';
|
||||
import {BookdropFilesWidgetComponent} from '../../../features/bookdrop/component/bookdrop-files-widget/bookdrop-files-widget.component';
|
||||
import {MetadataProgressWidgetComponent} from '../metadata-progress-widget/metadata-progress-widget-component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-unified-notification-popover-component',
|
||||
imports: [
|
||||
LiveNotificationBoxComponent,
|
||||
MetadataProgressWidgetComponent,
|
||||
AsyncPipe,
|
||||
BookdropFilesWidgetComponent,
|
||||
DuplicateFilesNotificationComponent
|
||||
],
|
||||
templateUrl: './unified-notification-popover-component.html',
|
||||
standalone: true,
|
||||
styleUrl: './unified-notification-popover-component.scss'
|
||||
})
|
||||
export class UnifiedNotificationBoxComponent {
|
||||
metadataProgressService = inject(MetadataProgressService);
|
||||
bookdropFileService = inject(BookdropFileService);
|
||||
duplicateFileService = inject(DuplicateFileService);
|
||||
|
||||
hasMetadataTasks$ = this.metadataProgressService.activeTasks$.pipe(
|
||||
map(tasks => Object.keys(tasks).length > 0)
|
||||
);
|
||||
|
||||
hasPendingBookdropFiles$ = this.bookdropFileService.hasPendingFiles$;
|
||||
|
||||
hasDuplicateFiles$ = this.duplicateFileService.duplicateFiles$.pipe(
|
||||
map(files => files && files.length > 0)
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user