Icon support for library and shelf

This commit is contained in:
aditya.chandel
2024-12-26 16:55:11 -07:00
parent 6e8d978d6e
commit aba11ecaa8
28 changed files with 205 additions and 84 deletions
@@ -1,7 +1,7 @@
<div class="dialog-container">
<div class="checkbox-list">
<div *ngFor="let shelf of shelves$ | async" class="flex items-center">
<p-checkbox [inputId]="shelf.name" name="group" [value]="shelf" [(ngModel)]="selectedShelves" />
<p-checkbox [inputId]="shelf.name" name="group" [value]="shelf" [(ngModel)]="selectedShelves"/>
<label [for]="shelf.id" class="ml-2">{{ shelf.name }}</label>
</div>
</div>
@@ -17,13 +17,23 @@
</div>
</div>
</div>
<p-dialog [(visible)]="displayShelfDialog" header="Create Shelf" [modal]="true" [closable]="true" (onHide)="closeShelfDialog()" [style]="{ width: '400px', height: 'auto' }">
<app-icon-picker (iconSelected)="onIconSelected($event)"></app-icon-picker>
<p-dialog [(visible)]="displayShelfDialog" header="Create Shelf" [modal]="true" [draggable]="false" [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 class="field">
<label>Shelf Icon</label>
<div *ngIf="!selectedIcon">
<p-button label="Select Icon" icon="pi pi-search" (onClick)="openIconPicker()"></p-button>
</div>
<div *ngIf="selectedIcon" class="mt-2 flex align-items-center">
<i [class]="selectedIcon" class="mr-2"></i>
<p-button label="Remove" icon="pi pi-times" [text]="true" [outlined]="true" severity="warning" (onClick)="clearSelectedIcon()"></p-button>
</div>
</div>
</div>
<ng-template pTemplate="footer">
<p-button label="Cancel" severity="secondary" (onClick)="closeShelfDialog()" class="p-button-text"></p-button>
@@ -1,4 +1,4 @@
import {Component, OnInit} from '@angular/core';
import {Component, OnInit, ViewChild} from '@angular/core';
import {DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog';
import {Book} from '../../model/book.model';
import {MessageService} from 'primeng/api';
@@ -7,6 +7,7 @@ import {Observable} from 'rxjs';
import {BookService} from '../../service/book.service';
import {map, tap} from 'rxjs/operators';
import {Shelf} from '../../model/shelf.model';
import {IconPickerComponent} from '../icon-picker/icon-picker.component';
@Component({
selector: 'app-shelf-assigner',
@@ -22,6 +23,8 @@ export class ShelfAssignerComponent implements OnInit {
shelfName: string = '';
bookIds: Set<number> = new Set();
isMultiBooks: boolean = false;
selectedIcon: string | null = null;
@ViewChild(IconPickerComponent) iconPicker: IconPickerComponent | undefined;
constructor(
private shelfService: ShelfService,
@@ -46,7 +49,11 @@ export class ShelfAssignerComponent implements OnInit {
}
saveNewShelf(): void {
this.shelfService.createShelf(this.shelfName).subscribe(
const newShelf = {
name: this.shelfName,
icon: this.selectedIcon ? this.selectedIcon.replace('pi pi-', '') : 'heart'
};
this.shelfService.createShelf(newShelf).subscribe(
() => {
this.messageService.add({severity: 'info', summary: 'Success', detail: 'Shelf created: ' + this.shelfName});
this.displayShelfDialog = false;
@@ -99,4 +106,19 @@ export class ShelfAssignerComponent implements OnInit {
closeDialog(): void {
this.dynamicDialogRef.close();
}
openIconPicker() {
if (this.iconPicker) {
this.iconPicker.open();
}
}
clearSelectedIcon() {
this.selectedIcon = null;
}
onIconSelected(icon: string) {
this.selectedIcon = icon;
}
}