Add validations to library creator stepper
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
<div class="layout-topbar">
|
||||
|
||||
<a class="layout-topbar-logo" routerLink="">
|
||||
<img src="assets/layout/images/{{layoutService.config().colorScheme === 'light' ? 'logo-dark' : 'logo-white'}}.svg"
|
||||
<img src="assets/layout/images/{{'logo-dark'}}.svg"
|
||||
alt="logo">
|
||||
<span>BookLore</span>
|
||||
<span class="flex">
|
||||
<p>Book</p>
|
||||
<p class="half-title">lore</p>
|
||||
</span>
|
||||
</a>
|
||||
|
||||
<p-button
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
<div class="library-name-icon-parent">
|
||||
<div class="library-name-div">
|
||||
<p>Library Name: </p>
|
||||
<input type="text" pInputText [(ngModel)]="value" placeholder="Enter library name..."/>
|
||||
<input type="text" pInputText [(ngModel)]="libraryName" placeholder="Enter library name..."/>
|
||||
</div>
|
||||
<div class="library-icon-div">
|
||||
<p>Library Icon:</p>
|
||||
@@ -27,7 +27,7 @@
|
||||
<app-icon-picker (iconSelected)="onIconSelected($event)"></app-icon-picker>
|
||||
</div>
|
||||
<div class="flex pt-6 justify-end">
|
||||
<p-button label="Next" icon="pi pi-arrow-right" iconPos="right" (onClick)="activateCallback(2)" />
|
||||
<p-button label="Next" icon="pi pi-arrow-right" iconPos="right" [disabled]="!isLibraryDetailsValid()" (onClick)="activateCallback(2)" />
|
||||
</div>
|
||||
</div>
|
||||
</ng-template>
|
||||
@@ -64,7 +64,7 @@
|
||||
</div>
|
||||
<div class="flex pt-6 justify-between">
|
||||
<p-button label="Back" icon="pi pi-arrow-left" iconPos="right" (onClick)="activateCallback(1)" />
|
||||
<p-button severity="success" label="Save" icon="pi pi-save" (onClick)="addLibrary()"></p-button>
|
||||
<p-button severity="success" label="Save" icon="pi pi-save" [disabled]="!isDirectorySelectionValid()" (onClick)="addLibrary()"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
</ng-template>
|
||||
|
||||
@@ -14,17 +14,19 @@ import {IconPickerComponent} from '../icon-picker/icon-picker.component';
|
||||
providers: [MessageService]
|
||||
})
|
||||
export class LibraryCreatorComponent {
|
||||
value: string = '';
|
||||
folders: string[] = [];
|
||||
ref: DynamicDialogRef | undefined;
|
||||
|
||||
@ViewChild(IconPickerComponent) iconPicker: IconPickerComponent | undefined;
|
||||
|
||||
libraryName: string = '';
|
||||
folders: string[] = [];
|
||||
ref: DynamicDialogRef | undefined;
|
||||
selectedIcon: string | null = null;
|
||||
|
||||
constructor(
|
||||
private dialogService: DialogService,
|
||||
private dynamicDialogRef: DynamicDialogRef,
|
||||
private libraryService: LibraryService,
|
||||
private messageService: MessageService,
|
||||
private router: Router) {
|
||||
}
|
||||
|
||||
@@ -67,9 +69,17 @@ export class LibraryCreatorComponent {
|
||||
this.selectedIcon = null;
|
||||
}
|
||||
|
||||
isLibraryDetailsValid(): boolean {
|
||||
return !!this.libraryName.trim() && !!this.selectedIcon;
|
||||
}
|
||||
|
||||
isDirectorySelectionValid(): boolean {
|
||||
return this.folders.length > 0;
|
||||
}
|
||||
|
||||
addLibrary() {
|
||||
const newLibrary = {
|
||||
name: this.value,
|
||||
name: this.libraryName,
|
||||
paths: this.folders,
|
||||
icon: this.selectedIcon ? this.selectedIcon.replace('pi pi-', '') : 'heart'
|
||||
};
|
||||
@@ -86,30 +96,23 @@ export class LibraryCreatorComponent {
|
||||
this.dynamicDialogRef.close();
|
||||
}
|
||||
|
||||
/*validateLibraryNameAndProceed(nextCallback: any) {
|
||||
if (this.value.trim()) {
|
||||
this.libraryServiceV2.checkLibraryNameExists(this.value).subscribe(
|
||||
(response) => {
|
||||
const libraryExists = response && response.name === this.value;
|
||||
if (libraryExists) {
|
||||
validateLibraryNameAndProceed(nextCallback: any) {
|
||||
if (this.libraryName.trim()) {
|
||||
this.libraryService.libraryState$.subscribe(
|
||||
libraryState => {
|
||||
let library = libraryState.libraries?.find(library => library.name === this.libraryName.trim());
|
||||
if(library) {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Library Name Exists',
|
||||
detail: 'This library name is already taken.',
|
||||
});
|
||||
} else {
|
||||
nextCallback.emit();
|
||||
nextCallback();
|
||||
}
|
||||
},
|
||||
(error) => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Error',
|
||||
detail: 'An error occurred while checking the library name.',
|
||||
});
|
||||
}
|
||||
);
|
||||
)
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user