- Library paths are not identified by path ID.

- Revamp upload functionality.
This commit is contained in:
aditya.chandel
2025-01-16 18:11:28 -07:00
parent f6f5f718af
commit a11a42cd19
18 changed files with 281 additions and 69 deletions
@@ -0,0 +1,38 @@
<div
*ngIf="(libraryState$ | async)?.libraries as libraries"
class="flex flex-col gap-10 p-4 items-center justify-center min-w-[400px] max-w-[600px] w-full">
<p-dropdown
[options]="libraries"
optionLabel="name"
placeholder="Select Library"
[(ngModel)]="selectedLibrary"
class="w-full"></p-dropdown>
<p-dropdown
[options]="selectedLibrary?.paths"
optionLabel="path"
placeholder="Select Upload Location"
[(ngModel)]="selectedPath"
[disabled]="!selectedLibrary"
class="w-full"></p-dropdown>
<p-fileupload
#fu
mode="basic"
chooseLabel="Choose"
chooseIcon="pi pi-upload"
name="file"
[url]="getUploadUrl()"
accept=".pdf,.epub"
maxFileSize="104857600"
(onUpload)="onUpload($event)"
[disabled]="!selectedLibrary || !selectedPath"
class="w-full">
</p-fileupload>
<div class="flex flex-row items-center justify-between w-full">
<p-button label="Upload" (onClick)="fu.upload()" severity="primary" [disabled]="!fu.files.length" class=""/>
<p-button label="Clear" (click)="fu.clear()" severity="info" [disabled]="!fu.files.length" class=""/>
</div>
</div>
@@ -0,0 +1,48 @@
import {Component, inject, Input} from '@angular/core';
import {FileUpload, FileUploadEvent} from 'primeng/fileupload';
import {Button} from 'primeng/button';
import {LibraryService} from '../book/service/library.service';
import {Observable} from 'rxjs';
import {LibraryState} from '../book/model/state/library-state.model';
import {AsyncPipe, NgIf} from '@angular/common';
import {DropdownModule} from 'primeng/dropdown';
import {FormsModule} from '@angular/forms';
import {Library, LibraryPath} from '../book/model/library.model';
import {MessageService} from 'primeng/api';
import {DynamicDialogRef} from 'primeng/dynamicdialog';
@Component({
selector: 'app-book-uploader',
imports: [
FileUpload,
Button,
AsyncPipe,
DropdownModule,
FormsModule,
NgIf
],
templateUrl: './book-uploader.component.html',
styleUrl: './book-uploader.component.scss'
})
export class BookUploaderComponent {
private uploadUrl = 'http://localhost:8080/api/v1/files/upload';
private libraryService = inject(LibraryService);
private messageService = inject(MessageService);
private dynamicDialogRef = inject(DynamicDialogRef);
libraryState$: Observable<LibraryState> = this.libraryService.libraryState$;
selectedLibrary: Library | null = null;
selectedPath: LibraryPath | null = null;
getUploadUrl() {
return `${this.uploadUrl}?libraryId=${this.selectedLibrary?.id}&pathId=${this.selectedPath?.id}`;
}
onUpload($event: FileUploadEvent) {
this.dynamicDialogRef.close();
this.messageService.add({severity: 'success', summary: 'Success', detail: 'Book successfully uploaded'});
}
}
@@ -13,6 +13,7 @@ import {NgIf} from '@angular/common';
import {FormsModule} from '@angular/forms';
import {InputText} from 'primeng/inputtext';
import {BookService} from '../../service/book.service';
import {Library, LibraryPath} from '../../model/library.model';
@Component({
selector: 'app-library-creator',
@@ -97,21 +98,21 @@ export class LibraryCreatorComponent {
}
addLibrary() {
const newLibrary = {
const library: Library = {
name: this.libraryName,
paths: this.folders,
icon: this.selectedIcon ? this.selectedIcon.replace('pi pi-', '') : 'heart'
icon: this.selectedIcon?.replace('pi pi-', '') || 'heart',
paths: this.folders.map(folder => ({ path: folder }))
};
this.libraryService.createLibrary(newLibrary).subscribe({
this.libraryService.createLibrary(library).subscribe({
next: (createdLibrary) => {
this.router.navigate(
['/library', createdLibrary.id, 'books']
);
this.router.navigate(['/library', createdLibrary.id, 'books']);
},
error: (err) => {
console.error('Failed to create library:', err);
}
});
this.dynamicDialogRef.close();
}
@@ -5,5 +5,10 @@ export interface Library {
name: string;
icon: string;
sort?: SortOption;
paths: string[];
paths: LibraryPath[];
}
export interface LibraryPath {
id?: number;
path: string;
}
@@ -16,6 +16,7 @@ import {StyleClass} from 'primeng/styleclass';
import {Divider} from 'primeng/divider';
import {ThemeConfiguratorComponent} from '../theme-configurator/theme-configurator.component';
import {LiveNotificationBoxComponent} from '../../../core/component/live-notification-box/live-notification-box.component';
import {BookUploaderComponent} from '../../../book-uploader/book-uploader.component';
@Component({
selector: 'app-topbar',
@@ -88,12 +89,10 @@ export class AppTopBarComponent implements OnDestroy {
}
openFileUploadDialog() {
this.ref = this.dialogService.open(FileUploadComponent, {
header: 'Upload Book',
this.ref = this.dialogService.open(BookUploaderComponent, {
header: 'Book Uploader',
modal: true,
closable: true,
width: '600px',
height: '330px',
style: {
position: 'absolute',
top: '15%',