Add toggle to watch folders

This commit is contained in:
aditya.chandel
2025-02-07 02:39:49 -07:00
parent 931718bdae
commit 581f6a32a5
5 changed files with 19 additions and 6 deletions
@@ -19,4 +19,5 @@ public class CreateLibraryRequest {
private String icon;
@NotEmpty
private List<LibraryPath> paths;
private boolean watch;
}
@@ -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<String> currentPaths = library.getLibraryPaths().stream().map(LibraryPathEntity::getPath).collect(Collectors.toSet());
Set<String> 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);
@@ -9,11 +9,11 @@
<div class="flex flex-col w-[40rem] h-[25rem]">
<div class="flex flex-auto justify-center items-center font-medium border-[var(--border-color)] border-2 border-dashed">
<div class="flex flex-col gap-10">
<div class="flex items-center gap-2">
<div class="flex items-center gap-8">
<p>Library Name: </p>
<input type="text" pInputText [(ngModel)]="chosenLibraryName" placeholder="Enter library name..."/>
</div>
<div class="flex items-center gap-5">
<div class="flex items-center gap-11">
<p>Library Icon:</p>
<div *ngIf="!selectedIcon">
<p-button label="Select Icon" icon="pi pi-search" (onClick)="openIconPicker()"></p-button>
@@ -23,6 +23,10 @@
<p-button icon="pi pi-times" (onClick)="clearSelectedIcon()" [rounded]="true" [text]="true" [outlined]="true" severity="danger"></p-button>
</div>
</div>
<div class="flex items-center gap-3">
<p>Monitor Folders: </p>
<p-toggleswitch [(ngModel)]="watch" />
</div>
</div>
<app-icon-picker (iconSelected)="onIconSelected($event)"></app-icon-picker>
</div>
@@ -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<DirectoryPickerComponent>;
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) => {
@@ -4,6 +4,7 @@ export interface Library {
id?: number;
name: string;
icon: string;
watch: boolean;
sort?: SortOption;
paths: LibraryPath[];
}