From 581f6a32a5e87f807deac34f5298f5ee783c8d9f Mon Sep 17 00:00:00 2001 From: "aditya.chandel" <> Date: Fri, 7 Feb 2025 02:39:49 -0700 Subject: [PATCH] Add toggle to watch folders --- .../model/dto/request/CreateLibraryRequest.java | 1 + .../booklore/service/LibraryService.java | 2 ++ .../library-creator/library-creator.component.html | 8 ++++++-- .../library-creator/library-creator.component.ts | 13 +++++++++---- booklore-ui/src/app/book/model/library.model.ts | 1 + 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/booklore-api/src/main/java/com/adityachandel/booklore/model/dto/request/CreateLibraryRequest.java b/booklore-api/src/main/java/com/adityachandel/booklore/model/dto/request/CreateLibraryRequest.java index 78b37422e..dad71deea 100644 --- a/booklore-api/src/main/java/com/adityachandel/booklore/model/dto/request/CreateLibraryRequest.java +++ b/booklore-api/src/main/java/com/adityachandel/booklore/model/dto/request/CreateLibraryRequest.java @@ -19,4 +19,5 @@ public class CreateLibraryRequest { private String icon; @NotEmpty private List paths; + private boolean watch; } diff --git a/booklore-api/src/main/java/com/adityachandel/booklore/service/LibraryService.java b/booklore-api/src/main/java/com/adityachandel/booklore/service/LibraryService.java index a4a2a8b36..0472555c1 100644 --- a/booklore-api/src/main/java/com/adityachandel/booklore/service/LibraryService.java +++ b/booklore-api/src/main/java/com/adityachandel/booklore/service/LibraryService.java @@ -50,6 +50,7 @@ public class LibraryService { LibraryEntity library = libraryRepository.findById(libraryId).orElseThrow(() -> ApiError.LIBRARY_NOT_FOUND.createException(libraryId)); library.setName(request.getName()); library.setIcon(request.getIcon()); + library.setWatch(request.isWatch()); Set currentPaths = library.getLibraryPaths().stream().map(LibraryPathEntity::getPath).collect(Collectors.toSet()); Set updatedPaths = request.getPaths().stream().map(LibraryPath::getPath).collect(Collectors.toSet()); @@ -110,6 +111,7 @@ public class LibraryService { .collect(Collectors.toList()) ) .icon(request.getIcon()) + .watch(request.isWatch()) .build(); libraryEntity = libraryRepository.save(libraryEntity); diff --git a/booklore-ui/src/app/book/components/library-creator/library-creator.component.html b/booklore-ui/src/app/book/components/library-creator/library-creator.component.html index 1e3685a14..66835e64b 100644 --- a/booklore-ui/src/app/book/components/library-creator/library-creator.component.html +++ b/booklore-ui/src/app/book/components/library-creator/library-creator.component.html @@ -9,11 +9,11 @@
-
+

Library Name:

-
+

Library Icon:

@@ -23,6 +23,10 @@
+
+

Monitor Folders:

+ +
diff --git a/booklore-ui/src/app/book/components/library-creator/library-creator.component.ts b/booklore-ui/src/app/book/components/library-creator/library-creator.component.ts index 522bf7836..1aa2daa87 100644 --- a/booklore-ui/src/app/book/components/library-creator/library-creator.component.ts +++ b/booklore-ui/src/app/book/components/library-creator/library-creator.component.ts @@ -12,12 +12,13 @@ import {NgIf} from '@angular/common'; import {FormsModule} from '@angular/forms'; import {InputText} from 'primeng/inputtext'; import {Library} from '../../model/library.model'; +import {ToggleSwitch} from 'primeng/toggleswitch'; @Component({ selector: 'app-library-creator', standalone: true, templateUrl: './library-creator.component.html', - imports: [Button, TableModule, StepPanel, IconPickerComponent, NgIf, FormsModule, InputText, Stepper, StepList, Step, StepPanels], + imports: [Button, TableModule, StepPanel, IconPickerComponent, NgIf, FormsModule, InputText, Stepper, StepList, Step, StepPanels, ToggleSwitch], styleUrl: './library-creator.component.scss' }) export class LibraryCreatorComponent implements OnInit { @@ -32,6 +33,7 @@ export class LibraryCreatorComponent implements OnInit { library!: Library | undefined; editModeLibraryName: string = ''; directoryPickerDialogRef!: DynamicDialogRef; + watch: boolean = false; private dialogService = inject(DialogService); private dynamicDialogRef = inject(DynamicDialogRef); @@ -47,10 +49,11 @@ export class LibraryCreatorComponent implements OnInit { this.mode = data.mode; this.library = this.libraryService.findLibraryById(data.libraryId); if (this.library) { - const {name, icon, paths} = this.library; + const {name, icon, paths, watch} = this.library; this.chosenLibraryName = name; this.editModeLibraryName = name; this.selectedIcon = `pi pi-${icon}`; + this.watch = watch; this.folders = paths.map(path => path.path); } } @@ -106,7 +109,8 @@ export class LibraryCreatorComponent implements OnInit { const library: Library = { name: this.chosenLibraryName, icon: this.selectedIcon?.replace('pi pi-', '') || 'heart', - paths: this.folders.map(folder => ({path: folder})) + paths: this.folders.map(folder => ({path: folder})), + watch: this.watch }; this.libraryService.updateLibrary(library, this.library?.id).subscribe({ next: () => { @@ -122,7 +126,8 @@ export class LibraryCreatorComponent implements OnInit { const library: Library = { name: this.chosenLibraryName, icon: this.selectedIcon?.replace('pi pi-', '') || 'heart', - paths: this.folders.map(folder => ({path: folder})) + paths: this.folders.map(folder => ({path: folder})), + watch: this.watch }; this.libraryService.createLibrary(library).subscribe({ next: (createdLibrary) => { diff --git a/booklore-ui/src/app/book/model/library.model.ts b/booklore-ui/src/app/book/model/library.model.ts index a7c186596..4f4b4810e 100644 --- a/booklore-ui/src/app/book/model/library.model.ts +++ b/booklore-ui/src/app/book/model/library.model.ts @@ -4,6 +4,7 @@ export interface Library { id?: number; name: string; icon: string; + watch: boolean; sort?: SortOption; paths: LibraryPath[]; }