Add support for uploading and assigning custom SVG icons to libraries… (#1788)
* Add support for uploading and assigning custom SVG icons to libraries and shelves * Add few default icons
This commit is contained in:
+12
-3
@@ -60,11 +60,20 @@
|
||||
} @else {
|
||||
<div class="selected-icon-display">
|
||||
<div class="icon-preview">
|
||||
<i [class]="selectedIcon"></i>
|
||||
<app-icon-display
|
||||
[icon]="selectedIcon"
|
||||
size="24px"
|
||||
/>
|
||||
</div>
|
||||
<div class="icon-info">
|
||||
<span class="icon-label">Selected Icon</span>
|
||||
<span class="icon-name">{{ selectedIcon }}</span>
|
||||
<span class="icon-name">
|
||||
@if (selectedIcon.type === 'PRIME_NG') {
|
||||
{{ selectedIcon.value }}
|
||||
} @else {
|
||||
{{ selectedIcon.value }}
|
||||
}
|
||||
</span>
|
||||
</div>
|
||||
<p-button
|
||||
icon="pi pi-times"
|
||||
@@ -106,7 +115,7 @@
|
||||
label="Create Shelf"
|
||||
icon="pi pi-plus"
|
||||
severity="success"
|
||||
(onClick)="saveNewShelf()"
|
||||
(onClick)="createShelf()"
|
||||
[disabled]="!shelfName.trim()"
|
||||
/>
|
||||
</div>
|
||||
|
||||
+12
-6
@@ -249,9 +249,19 @@
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 3px 8px rgba(0, 0, 0, 0.2);
|
||||
|
||||
i {
|
||||
font-size: 1.25rem;
|
||||
app-icon-display {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: var(--primary-contrast-color);
|
||||
|
||||
::ng-deep i {
|
||||
color: var(--primary-contrast-color);
|
||||
}
|
||||
|
||||
::ng-deep img {
|
||||
filter: brightness(0) invert(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -281,10 +291,6 @@
|
||||
.icon-preview {
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
|
||||
i {
|
||||
font-size: 1.125rem;
|
||||
}
|
||||
}
|
||||
|
||||
.icon-info {
|
||||
|
||||
+27
-20
@@ -2,12 +2,13 @@ import {Component, inject} from '@angular/core';
|
||||
import {DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {ShelfService} from '../../service/shelf.service';
|
||||
import {IconPickerService} from '../../../../shared/service/icon-picker.service';
|
||||
import {IconPickerService, IconSelection} from '../../../../shared/service/icon-picker.service';
|
||||
import {Shelf} from '../../model/shelf.model';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {Button} from 'primeng/button';
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {IconDisplayComponent} from '../../../../shared/components/icon-display/icon-display.component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-shelf-creator',
|
||||
@@ -17,7 +18,8 @@ import {Tooltip} from 'primeng/tooltip';
|
||||
FormsModule,
|
||||
Button,
|
||||
InputText,
|
||||
Tooltip
|
||||
Tooltip,
|
||||
IconDisplayComponent
|
||||
],
|
||||
styleUrl: './shelf-creator.component.scss',
|
||||
})
|
||||
@@ -28,24 +30,7 @@ export class ShelfCreatorComponent {
|
||||
private iconPickerService = inject(IconPickerService);
|
||||
|
||||
shelfName: string = '';
|
||||
selectedIcon: string | null = null;
|
||||
|
||||
saveNewShelf(): void {
|
||||
const newShelf: Partial<Shelf> = {
|
||||
name: this.shelfName,
|
||||
icon: this.selectedIcon ? this.selectedIcon.replace('pi pi-', '') : 'heart'
|
||||
};
|
||||
this.shelfService.createShelf(newShelf as Shelf).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({severity: 'info', summary: 'Success', detail: `Shelf created: ${this.shelfName}`});
|
||||
this.dynamicDialogRef.close(true);
|
||||
},
|
||||
error: (e) => {
|
||||
this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to create shelf'});
|
||||
console.error('Error creating shelf:', e);
|
||||
}
|
||||
});
|
||||
}
|
||||
selectedIcon: IconSelection | null = null;
|
||||
|
||||
openIconPicker(): void {
|
||||
this.iconPickerService.open().subscribe(icon => {
|
||||
@@ -62,4 +47,26 @@ export class ShelfCreatorComponent {
|
||||
cancel(): void {
|
||||
this.dynamicDialogRef.close();
|
||||
}
|
||||
|
||||
createShelf(): void {
|
||||
const iconValue = this.selectedIcon?.value || 'bookmark';
|
||||
const iconType = this.selectedIcon?.type || 'PRIME_NG';
|
||||
|
||||
const newShelf: Partial<Shelf> = {
|
||||
name: this.shelfName,
|
||||
icon: iconValue,
|
||||
iconType: iconType
|
||||
};
|
||||
|
||||
this.shelfService.createShelf(newShelf as Shelf).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({severity: 'info', summary: 'Success', detail: `Shelf created: ${this.shelfName}`});
|
||||
this.dynamicDialogRef.close(true);
|
||||
},
|
||||
error: (e) => {
|
||||
this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to create shelf'});
|
||||
console.error('Error creating shelf:', e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
+5
-1
@@ -36,7 +36,11 @@
|
||||
@if (selectedIcon) {
|
||||
<div class="icon-container">
|
||||
<div class="icon-wrapper">
|
||||
<i [class]="selectedIcon" class="icon"></i>
|
||||
<app-icon-display
|
||||
[icon]="selectedIcon"
|
||||
size="24px"
|
||||
iconClass="icon"
|
||||
/>
|
||||
</div>
|
||||
<p-button icon="pi pi-times" (onClick)="clearSelectedIcon()" [rounded]="true" [text]="true" severity="danger"></p-button>
|
||||
</div>
|
||||
|
||||
+16
-6
@@ -1,13 +1,14 @@
|
||||
import {Component, inject, OnInit} from '@angular/core';
|
||||
import {ShelfService} from '../../service/shelf.service';
|
||||
import {DialogService, DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {Button} from 'primeng/button';
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
|
||||
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
|
||||
import {Shelf} from '../../model/shelf.model';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {IconPickerService} from '../../../../shared/service/icon-picker.service';
|
||||
import {IconPickerService, IconSelection} from '../../../../shared/service/icon-picker.service';
|
||||
import {IconDisplayComponent} from '../../../../shared/components/icon-display/icon-display.component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-shelf-edit-dialog',
|
||||
@@ -15,7 +16,8 @@ import {IconPickerService} from '../../../../shared/service/icon-picker.service'
|
||||
Button,
|
||||
InputText,
|
||||
ReactiveFormsModule,
|
||||
FormsModule
|
||||
FormsModule,
|
||||
IconDisplayComponent
|
||||
],
|
||||
templateUrl: './shelf-edit-dialog.component.html',
|
||||
standalone: true,
|
||||
@@ -30,7 +32,7 @@ export class ShelfEditDialogComponent implements OnInit {
|
||||
private iconPickerService = inject(IconPickerService);
|
||||
|
||||
shelfName: string = '';
|
||||
selectedIcon: string | null = null;
|
||||
selectedIcon: IconSelection | null = null;
|
||||
shelf!: Shelf | undefined;
|
||||
|
||||
ngOnInit(): void {
|
||||
@@ -38,7 +40,11 @@ export class ShelfEditDialogComponent implements OnInit {
|
||||
this.shelf = this.shelfService.getShelfById(shelfId);
|
||||
if (this.shelf) {
|
||||
this.shelfName = this.shelf.name;
|
||||
this.selectedIcon = 'pi pi-' + this.shelf.icon;
|
||||
if (this.shelf.iconType === 'PRIME_NG') {
|
||||
this.selectedIcon = {type: 'PRIME_NG', value: `pi pi-${this.shelf.icon}`};
|
||||
} else {
|
||||
this.selectedIcon = {type: 'CUSTOM_SVG', value: this.shelf.icon};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,9 +61,13 @@ export class ShelfEditDialogComponent implements OnInit {
|
||||
}
|
||||
|
||||
save() {
|
||||
const iconValue = this.selectedIcon?.value || 'bookmark';
|
||||
const iconType = this.selectedIcon?.type || 'PRIME_NG';
|
||||
|
||||
const shelf: Shelf = {
|
||||
name: this.shelfName,
|
||||
icon: this.selectedIcon?.replace('pi pi-', '') || 'heart'
|
||||
icon: iconValue,
|
||||
iconType: iconType
|
||||
};
|
||||
|
||||
this.shelfService.updateShelf(shelf, this.shelf?.id).subscribe({
|
||||
|
||||
@@ -7,6 +7,7 @@ export interface Library {
|
||||
id?: number;
|
||||
name: string;
|
||||
icon: string;
|
||||
iconType?: 'PRIME_NG' | 'CUSTOM_SVG';
|
||||
watch: boolean;
|
||||
fileNamingPattern?: string;
|
||||
sort?: SortOption;
|
||||
|
||||
@@ -4,5 +4,6 @@ export interface Shelf {
|
||||
id?: number;
|
||||
name: string;
|
||||
icon: string;
|
||||
iconType?: 'PRIME_NG' | 'CUSTOM_SVG';
|
||||
sort?: SortOption;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user