Move components
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
<div class="dialog-container">
|
||||
<div class="checkbox-list">
|
||||
<div *ngFor="let shelf of shelves()" class="flex items-center">
|
||||
<p-checkbox [inputId]="shelf.name" name="group" [value]="shelf" [(ngModel)]="selectedShelves" />
|
||||
<label [for]="shelf.id" class="ml-2">{{ shelf.name }}</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Divider and Bottom Section -->
|
||||
<div class="bottom-section">
|
||||
<p-divider></p-divider>
|
||||
<div class="bottom-container">
|
||||
<p-button outlined="true" label="Create Shelf" (onClick)="createShelfDialog()"></p-button>
|
||||
<div>
|
||||
<p-button class="spacing-right" severity="secondary" label="Cancel" (onClick)="closeDialog()"></p-button>
|
||||
<p-button label="Save" (onClick)="updateBooksShelves()"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p-dialog [(visible)]="displayShelfDialog" header="Create Shelf" [modal]="true" [closable]="true" (onHide)="closeShelfDialog()" [style]="{ width: '400px', height: 'auto' }">
|
||||
<div class="p-fluid">
|
||||
<div class="field">
|
||||
<label for="shelfName">Shelf Name</label>
|
||||
<input id="shelfName" type="text" pInputText [(ngModel)]="shelfName"/>
|
||||
</div>
|
||||
</div>
|
||||
<ng-template pTemplate="footer">
|
||||
<p-button label="Cancel" severity="secondary" (onClick)="closeShelfDialog()" class="p-button-text"></p-button>
|
||||
<p-button label="Save" (onClick)="saveNewShelf()"></p-button>
|
||||
</ng-template>
|
||||
</p-dialog>
|
||||
</div>
|
||||
@@ -0,0 +1,49 @@
|
||||
.dialog-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.bottom-section {
|
||||
margin-top: auto;
|
||||
}
|
||||
|
||||
.bottom-container {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
p-divider {
|
||||
margin: 1rem 0;
|
||||
border-color: var(--text-color-secondary);
|
||||
}
|
||||
|
||||
.spacing-right {
|
||||
margin-right: 1rem;
|
||||
}
|
||||
|
||||
p-dialog .p-dialog-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
gap: 1rem; /* Adds space between elements inside the dialog */
|
||||
}
|
||||
|
||||
p-dialog .p-dialog-footer {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.dialog-container .checkbox-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem; /* Adds gap between each checkbox row */
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.checkbox-list .flex {
|
||||
margin-bottom: 0.5rem; /* Optional: adds a smaller gap between each checkbox item */
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
import {Component, computed, OnInit} from '@angular/core';
|
||||
import {LibraryAndBookService} from '../../service/library-and-book.service';
|
||||
import {DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {Book} from '../../model/book.model';
|
||||
import {MessageService} from 'primeng/api';
|
||||
|
||||
@Component({
|
||||
selector: 'app-shelf-assigner',
|
||||
standalone: false,
|
||||
|
||||
templateUrl: './shelf-assigner.component.html',
|
||||
styleUrl: './shelf-assigner.component.scss'
|
||||
})
|
||||
export class ShelfAssignerComponent implements OnInit {
|
||||
|
||||
shelves = computed(() => {
|
||||
return this.libraryBookService.shelves();
|
||||
});
|
||||
|
||||
book: Book;
|
||||
selectedShelves: any[] = [];
|
||||
displayShelfDialog: boolean = false;
|
||||
shelfName: string = '';
|
||||
|
||||
constructor(
|
||||
private libraryBookService: LibraryAndBookService, private dynamicDialogConfig: DynamicDialogConfig,
|
||||
private dynamicDialogRef: DynamicDialogRef, private messageService: MessageService) {
|
||||
this.book = this.dynamicDialogConfig.data.book;
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
if (this.book.shelves) {
|
||||
const bookShelfIds = this.book.shelves.map(shelf => shelf.id);
|
||||
this.selectedShelves = this.shelves().filter(shelf => bookShelfIds.includes(shelf.id));
|
||||
}
|
||||
}
|
||||
|
||||
saveNewShelf() {
|
||||
this.libraryBookService.createShelf(this.shelfName).subscribe(
|
||||
() => {
|
||||
this.messageService.add({severity: 'info', summary: 'Success', detail: 'Shelf created: ' + this.shelfName});
|
||||
this.displayShelfDialog = false;
|
||||
},
|
||||
(error) => {
|
||||
this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to create shelf'});
|
||||
console.error('Error creating shelf:', error);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
updateBooksShelves() {
|
||||
const shelfIds = this.selectedShelves.map((shelf) => shelf.id);
|
||||
this.libraryBookService.assignShelvesToBook(this.book, shelfIds).subscribe(
|
||||
() => {
|
||||
this.messageService.add({severity: 'info', summary: 'Success', detail: 'Book\'s shelves updated'});
|
||||
this.dynamicDialogRef.close();
|
||||
},
|
||||
(error) => {
|
||||
this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to update book\'s shelves'});
|
||||
this.dynamicDialogRef.close();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
createShelfDialog(): void {
|
||||
this.displayShelfDialog = true;
|
||||
}
|
||||
|
||||
closeShelfDialog(): void {
|
||||
this.displayShelfDialog = false;
|
||||
}
|
||||
|
||||
closeDialog() {
|
||||
this.dynamicDialogRef.close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user