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