WIP: Rearrange code
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
<p-stepper [value]="1" class="basis-[50rem]">
|
||||
<p-step-list>
|
||||
<p-step [value]="1">Library Details</p-step>
|
||||
<p-step [value]="2">Select Directory</p-step>
|
||||
</p-step-list>
|
||||
<p-step-panels>
|
||||
<p-step-panel [value]="1">
|
||||
<ng-template #content let-activateCallback="activateCallback">
|
||||
<div class="flex flex-col h-48 stepper-content-custom">
|
||||
<div class="border-2 border-dashed border-surface-200 dark:border-surface-700 rounded bg-surface-50 dark:bg-surface-950 flex-auto flex justify-center items-center font-medium">
|
||||
<div class="library-name-icon-parent">
|
||||
<div class="library-name-div">
|
||||
<p>Library Name: </p>
|
||||
<input type="text" pInputText [(ngModel)]="libraryName" placeholder="Enter library name..."/>
|
||||
</div>
|
||||
<div class="library-icon-div">
|
||||
<p>Library Icon:</p>
|
||||
<div *ngIf="!selectedIcon">
|
||||
<p-button label="Select Icon" icon="pi pi-search" (onClick)="openIconPicker()"></p-button>
|
||||
</div>
|
||||
<div *ngIf="selectedIcon" class="selected-icon-container">
|
||||
<i [class]="selectedIcon" style="font-size: 1.25rem; margin-right: 0.75rem;"></i>
|
||||
<p-button icon="pi pi-times" (onClick)="clearSelectedIcon()" [rounded]="true" [text]="true" [outlined]="true" class="remove-icon-button" severity="danger"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<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" [disabled]="!isLibraryDetailsValid()" (onClick)="validateLibraryNameAndProceed(activateCallback)" />
|
||||
</div>
|
||||
</div>
|
||||
</ng-template>
|
||||
</p-step-panel>
|
||||
|
||||
<p-step-panel [value]="2">
|
||||
<ng-template #content let-activateCallback="activateCallback">
|
||||
<div class="flex flex-col h-48 stepper-content-custom">
|
||||
<div class="border-2 border-dashed border-surface-200 dark:border-surface-700 rounded bg-surface-50 dark:bg-surface-950 flex-auto flex justify-center items-center font-medium">
|
||||
<div class="flex flex-col justify-center items-center w-100">
|
||||
<p-button
|
||||
severity="info"
|
||||
label="Add book folders"
|
||||
[outlined]="true"
|
||||
(onClick)="show()">
|
||||
</p-button>
|
||||
<p-table [value]="folders" styleClass="p-datatable-striped" class="p-table-custom mt-4">
|
||||
<ng-template pTemplate="body" let-folder let-i="rowIndex">
|
||||
<tr>
|
||||
<td class="tr-custom">{{ folder }}</td>
|
||||
<td class="tr-custom td-x-custom">
|
||||
<p-button
|
||||
icon="pi pi-times"
|
||||
[rounded]="true"
|
||||
[text]="true"
|
||||
severity="danger"
|
||||
(onClick)="removeFolder(i)"
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
</ng-template>
|
||||
</p-table>
|
||||
</div>
|
||||
</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" [disabled]="!isDirectorySelectionValid()" (onClick)="addLibrary()"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
</ng-template>
|
||||
</p-step-panel>
|
||||
</p-step-panels>
|
||||
</p-stepper>
|
||||
@@ -0,0 +1,95 @@
|
||||
.library-name-icon-parent {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 2.5rem;
|
||||
}
|
||||
|
||||
.library-name-div {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.library-icon-div {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.library-name-div label,
|
||||
.library-icon-div label {
|
||||
margin-right: 0.5rem;
|
||||
}
|
||||
|
||||
.library-name-div input {
|
||||
width: 200px;
|
||||
}
|
||||
|
||||
.library-icon-div p-button {
|
||||
margin-left: 0.8rem;
|
||||
}
|
||||
|
||||
.p-stepperPanel {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.p-stepperPanel .flex {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.p-stepperPanel .justify-content-end {
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.p-stepperPanel .mt-3 {
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
.p-table-custom {
|
||||
min-width: 35rem !important;
|
||||
max-height: 11.25rem !important;
|
||||
overflow: scroll;
|
||||
}
|
||||
|
||||
.tr-custom {
|
||||
padding: 0.25rem 0.5rem !important;
|
||||
border: 0px !important;
|
||||
}
|
||||
|
||||
.td-x-custom {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.w-100 {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.p-button {
|
||||
margin-left: 0.5rem;
|
||||
}
|
||||
|
||||
.selected-icon-container {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-left: 1rem;
|
||||
|
||||
i {
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
.remove-icon-button {
|
||||
margin-left: 0.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
.stepper-content-custom {
|
||||
height: 335px;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.p {
|
||||
color: var(--text-color);
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
import {Component, ViewChild} from '@angular/core';
|
||||
import {DialogService, DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {DirectoryPickerComponent} from '../../../utilities/directory-picker/directory-picker.component';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {Router} from '@angular/router';
|
||||
import {LibraryService} from '../../service/library.service';
|
||||
import {IconPickerComponent} from '../../../utilities/icon-picker/icon-picker.component';
|
||||
import {take} from 'rxjs';
|
||||
|
||||
@Component({
|
||||
selector: 'app-library-creator',
|
||||
standalone: false,
|
||||
templateUrl: './library-creator.component.html',
|
||||
styleUrl: './library-creator.component.scss'
|
||||
})
|
||||
export class LibraryCreatorComponent {
|
||||
|
||||
@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) {
|
||||
}
|
||||
|
||||
show() {
|
||||
this.ref = this.dialogService.open(DirectoryPickerComponent, {
|
||||
header: 'Select Media Directory',
|
||||
modal: true,
|
||||
width: '50%',
|
||||
height: '75%',
|
||||
contentStyle: {overflow: 'auto'},
|
||||
baseZIndex: 10
|
||||
});
|
||||
|
||||
this.ref.onClose.subscribe((selectedFolder: string) => {
|
||||
if (selectedFolder) {
|
||||
this.addFolder(selectedFolder);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
addFolder(folder: string): void {
|
||||
this.folders.push(folder);
|
||||
}
|
||||
|
||||
removeFolder(index: number): void {
|
||||
this.folders.splice(index, 1);
|
||||
}
|
||||
|
||||
openIconPicker() {
|
||||
if (this.iconPicker) {
|
||||
this.iconPicker.open();
|
||||
}
|
||||
}
|
||||
|
||||
onIconSelected(icon: string) {
|
||||
this.selectedIcon = icon;
|
||||
}
|
||||
|
||||
clearSelectedIcon() {
|
||||
this.selectedIcon = null;
|
||||
}
|
||||
|
||||
isLibraryDetailsValid(): boolean {
|
||||
return !!this.libraryName.trim() && !!this.selectedIcon;
|
||||
}
|
||||
|
||||
isDirectorySelectionValid(): boolean {
|
||||
return this.folders.length > 0;
|
||||
}
|
||||
|
||||
addLibrary() {
|
||||
const newLibrary = {
|
||||
name: this.libraryName,
|
||||
paths: this.folders,
|
||||
icon: this.selectedIcon ? this.selectedIcon.replace('pi pi-', '') : 'heart'
|
||||
};
|
||||
this.libraryService.createLibrary(newLibrary).subscribe({
|
||||
next: (createdLibrary) => {
|
||||
this.router.navigate(
|
||||
['/library', createdLibrary.id, 'books']
|
||||
);
|
||||
},
|
||||
error: (err) => {
|
||||
console.error('Failed to create library:', err);
|
||||
}
|
||||
});
|
||||
this.dynamicDialogRef.close();
|
||||
}
|
||||
|
||||
validateLibraryNameAndProceed(activateCallback: Function) {
|
||||
if (this.libraryName.trim()) {
|
||||
const libraryName = this.libraryName.trim();
|
||||
this.libraryService.libraryState$
|
||||
.pipe(take(1))
|
||||
.subscribe(libraryState => {
|
||||
const library = libraryState.libraries?.find(library => library.name === libraryName);
|
||||
if (library) {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Library Name Exists',
|
||||
detail: 'This library name is already taken.',
|
||||
});
|
||||
} else {
|
||||
activateCallback(2);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user