-
+
diff --git a/booklore-ui/src/app/shared/components/icon-picker/icon-picker-component.scss b/booklore-ui/src/app/shared/components/icon-picker/icon-picker-component.scss
index cf68332a8..3e6cd6672 100644
--- a/booklore-ui/src/app/shared/components/icon-picker/icon-picker-component.scss
+++ b/booklore-ui/src/app/shared/components/icon-picker/icon-picker-component.scss
@@ -10,10 +10,10 @@
cursor: pointer;
justify-content: space-evenly;
align-items: flex-start;
-}
-.icon-item > i {
- font-size: 1.25rem;
+ > i {
+ font-size: 1.25rem;
+ }
}
.icon-search {
@@ -25,22 +25,30 @@
margin-bottom: 15px;
margin-top: 15px;
box-sizing: border-box;
-}
-.icon-search:focus {
- border-color: var(--primary-color);
- outline: none;
-}
+ &:focus {
+ border-color: var(--primary-color);
+ outline: none;
+ }
-.icon-search::placeholder {
- color: var(--text-secondary-color);
- opacity: 1;
+ &::placeholder {
+ color: var(--text-secondary-color);
+ opacity: 1;
+ }
}
.svg-paste-container {
+ display: flex;
+ flex-direction: column;
+ gap: 20px;
+}
+
+.svg-input-section {
display: flex;
flex-direction: column;
gap: 15px;
+ padding-bottom: 20px;
+ border-bottom: 1px solid var(--border-color);
}
.svg-textarea {
@@ -129,25 +137,6 @@
}
}
-.svg-icon-item {
- display: flex;
- flex-direction: column;
- align-items: flex-start;
- justify-content: flex-start;
- gap: 0.5rem;
- border: 1px solid transparent;
- border-radius: 4px;
- transition: all 0.2s;
- height: 24px;
- width: 24px;
-
- .svg-icon-image {
- height: 20px;
- width: 20px;
- object-fit: contain;
- }
-}
-
.pagination-controls {
display: flex;
justify-content: center;
@@ -155,36 +144,16 @@
gap: 1rem;
padding: 1rem;
margin-top: 1rem;
- border-top: 1px solid #e0e0e0;
-
- .pagination-button {
- padding: 0.5rem 1rem;
- border: 1px solid #ddd;
- background: white;
- border-radius: 4px;
- cursor: pointer;
-
- &:hover:not(:disabled) {
- background: #f5f5f5;
- }
-
- &:disabled {
- opacity: 0.5;
- cursor: not-allowed;
- }
- }
+ border-top: 1px solid var(--border-color);
.pagination-info {
color: #666;
font-size: 0.9rem;
+ font-weight: 500;
}
}
.svg-trash-area {
- position: fixed;
- right: 32px;
- bottom: 32px;
- z-index: 100;
display: flex;
align-items: center;
gap: 10px;
@@ -194,7 +163,6 @@
padding: 12px 22px;
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.30);
color: var(--text-secondary-color);
- font-size: 16px;
transition: border-color 0.2s, background 0.2s, color 0.2s;
i.pi-trash {
@@ -225,3 +193,117 @@
}
}
}
+
+.svg-entries-section {
+ display: flex;
+ flex-direction: column;
+ gap: 15px;
+
+ .entries-header {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+
+ .entries-title {
+ margin: 0;
+ font-size: 16px;
+ font-weight: 600;
+ color: var(--text-primary-color);
+ }
+ }
+
+ .entries-grid {
+ display: grid;
+ grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
+ gap: 15px;
+ max-height: 400px;
+ overflow-y: auto;
+ padding: 10px 0;
+ }
+
+ .entry-card {
+ border: 1px solid var(--border-color);
+ border-radius: 6px;
+ padding: 12px;
+ background-color: var(--surface-ground);
+ transition: box-shadow 0.2s;
+
+ &:hover {
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
+ }
+
+ &.has-error {
+ border-color: #e74c3c;
+ background-color: #fff5f5;
+ }
+
+ .entry-header {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ margin-bottom: 10px;
+
+ .entry-name {
+ font-size: 13px;
+ font-weight: 600;
+ color: var(--text-primary-color);
+ word-break: break-all;
+ white-space: nowrap;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ }
+
+ .entry-remove {
+ background: none;
+ border: none;
+ cursor: pointer;
+ padding: 4px;
+ color: #e74c3c;
+ transition: color 0.2s;
+
+ &:hover {
+ color: #c0392b;
+ }
+
+ i {
+ font-size: 14px;
+ }
+ }
+ }
+
+ .entry-preview {
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ min-height: 80px;
+ max-height: 100px;
+ background-color: var(--ground-background);
+ border-radius: 4px;
+ padding: 8px;
+ overflow: hidden;
+
+ ::ng-deep svg {
+ max-width: 100%;
+ max-height: 100%;
+ width: auto;
+ height: auto;
+ }
+ }
+
+ .entry-error {
+ margin-top: 8px;
+ color: #e74c3c;
+ font-size: 12px;
+ font-weight: 500;
+ line-height: 1.4;
+ word-break: break-word;
+ }
+ }
+
+ .batch-actions {
+ display: flex;
+ justify-content: flex-end;
+ padding-top: 10px;
+ border-top: 1px solid var(--border-color);
+ }
+}
diff --git a/booklore-ui/src/app/shared/components/icon-picker/icon-picker-component.ts b/booklore-ui/src/app/shared/components/icon-picker/icon-picker-component.ts
index 441bd0b45..4b3788960 100644
--- a/booklore-ui/src/app/shared/components/icon-picker/icon-picker-component.ts
+++ b/booklore-ui/src/app/shared/components/icon-picker/icon-picker-component.ts
@@ -2,6 +2,7 @@ import {Component, inject, OnInit} from '@angular/core';
import {FormsModule} from '@angular/forms';
import {DynamicDialogRef} from 'primeng/dynamicdialog';
import {IconService} from '../../services/icon.service';
+import {IconCacheService} from '../../services/icon-cache.service';
import {DomSanitizer, SafeHtml} from '@angular/platform-browser';
import {UrlHelperService} from '../../service/url-helper.service';
import {MessageService} from 'primeng/api';
@@ -9,6 +10,26 @@ import {IconCategoriesHelper} from '../../helpers/icon-categories.helper';
import {Button} from 'primeng/button';
import {TabsModule} from 'primeng/tabs';
+interface SvgEntry {
+ name: string;
+ content: string;
+ preview: SafeHtml | null;
+ error: string;
+}
+
+interface IconSaveResult {
+ iconName: string;
+ success: boolean;
+ errorMessage: string;
+}
+
+interface SvgIconBatchResponse {
+ totalRequested: number;
+ successCount: number;
+ failureCount: number;
+ results: IconSaveResult[];
+}
+
@Component({
selector: 'app-icon-picker-component',
imports: [
@@ -35,12 +56,12 @@ export class IconPickerComponent implements OnInit {
SVG_TOO_LARGE: 'SVG content must not exceed 1MB',
PARSE_ERROR: 'Failed to parse SVG content',
LOAD_ICONS_ERROR: 'Failed to load SVG icons. Please try again.',
- SAVE_ERROR: 'Failed to save SVG. Please try again.',
DELETE_ERROR: 'Failed to delete icon. Please try again.'
};
ref = inject(DynamicDialogRef);
iconService = inject(IconService);
+ iconCache = inject(IconCacheService);
sanitizer = inject(DomSanitizer);
urlHelper = inject(UrlHelperService);
messageService = inject(MessageService);
@@ -65,9 +86,12 @@ export class IconPickerComponent implements OnInit {
svgContent: string = '';
svgName: string = '';
svgPreview: SafeHtml | null = null;
- isLoading: boolean = false;
errorMessage: string = '';
+ svgEntries: SvgEntry[] = [];
+ isSavingBatch: boolean = false;
+ batchErrorMessage: string = '';
+
svgIcons: string[] = [];
svgSearchText: string = '';
currentSvgPage: number = 0;
@@ -110,6 +134,8 @@ export class IconPickerComponent implements OnInit {
this.currentSvgPage = response.number;
this.totalSvgPages = response.totalPages;
this.isLoadingSvgIcons = false;
+
+ this.preloadSvgContent(response.content);
},
error: () => {
this.isLoadingSvgIcons = false;
@@ -118,13 +144,28 @@ export class IconPickerComponent implements OnInit {
});
}
- getSvgIconUrl(iconName: string): string {
- return this.urlHelper.getIconUrl(iconName);
+ private preloadSvgContent(iconNames: string[]): void {
+ iconNames.forEach(iconName => {
+ if (!this.iconCache.isCached(iconName)) {
+ this.loadSvgContent(iconName);
+ }
+ });
}
- onImageError(event: Event): void {
- const img = event.target as HTMLImageElement;
- img.src = 'data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"%3E%3Ccircle cx="12" cy="12" r="10"/%3E%3Cline x1="15" y1="9" x2="9" y2="15"/%3E%3Cline x1="9" y1="9" x2="15" y2="15"/%3E%3C/svg%3E';
+ private loadSvgContent(iconName: string): void {
+ this.iconService.getSanitizedSvgContent(iconName).subscribe({
+ next: () => {
+ },
+ error: () => {
+ const errorSvg = '
';
+ const sanitized = this.sanitizer.bypassSecurityTrustHtml(errorSvg);
+ this.iconCache.cacheIcon(iconName, errorSvg, sanitized);
+ }
+ });
+ }
+
+ getSvgContent(iconName: string): SafeHtml | null {
+ return this.iconCache.getCachedSanitized(iconName) || null;
}
selectSvgIcon(iconName: string): void {
@@ -155,30 +196,105 @@ export class IconPickerComponent implements OnInit {
}
}
- saveSvg(): void {
+ addSvgEntry(): void {
const validationError = this.validateSvgInput();
if (validationError) {
this.errorMessage = validationError;
return;
}
- this.isLoading = true;
- this.errorMessage = '';
+ const existingIndex = this.svgEntries.findIndex(entry => entry.name === this.svgName);
+ if (existingIndex !== -1) {
+ this.svgEntries[existingIndex] = {
+ name: this.svgName,
+ content: this.svgContent,
+ preview: this.svgPreview,
+ error: ''
+ };
+ } else {
+ this.svgEntries.push({
+ name: this.svgName,
+ content: this.svgContent,
+ preview: this.svgPreview,
+ error: ''
+ });
+ }
- this.iconService.saveSvgIcon(this.svgContent, this.svgName).subscribe({
- next: () => {
- this.isLoading = false;
- this.handleSuccessfulSave();
+ this.resetSvgForm();
+ this.errorMessage = '';
+ }
+
+ removeSvgEntry(index: number): void {
+ this.svgEntries.splice(index, 1);
+ }
+
+ clearAllEntries(): void {
+ this.svgEntries = [];
+ this.batchErrorMessage = '';
+ }
+
+ saveAllSvgs(): void {
+ if (this.svgEntries.length === 0) {
+ this.batchErrorMessage = 'No SVG icons to save';
+ return;
+ }
+
+ this.isSavingBatch = true;
+ this.batchErrorMessage = '';
+
+ this.svgEntries.forEach(entry => entry.error = '');
+
+ const svgData = this.svgEntries.map(entry => ({
+ svgName: entry.name,
+ svgData: entry.content
+ }));
+
+ this.iconService.saveBatchSvgIcons(svgData).subscribe({
+ next: (response: SvgIconBatchResponse) => {
+ this.isSavingBatch = false;
+ this.handleBatchSaveResponse(response);
},
error: (error) => {
- this.isLoading = false;
- this.errorMessage = error.error?.details?.join(', ')
- || error.error?.message
- || this.ERROR_MESSAGES.SAVE_ERROR;
+ this.isSavingBatch = false;
+ this.batchErrorMessage = error.error?.message || 'Failed to save SVG icons. Please try again.';
}
});
}
+ private handleBatchSaveResponse(response: SvgIconBatchResponse): void {
+ if (response.failureCount === 0) {
+ this.handleSuccessfulBatchSave();
+ return;
+ }
+
+ response.results.forEach(result => {
+ if (!result.success) {
+ const entryIndex = this.svgEntries.findIndex(entry => entry.name === result.iconName);
+ if (entryIndex !== -1) {
+ this.svgEntries[entryIndex].error = result.errorMessage;
+ }
+ }
+ });
+
+ const successfulNames = response.results
+ .filter(result => result.success)
+ .map(result => result.iconName);
+
+ this.svgEntries = this.svgEntries.filter(entry => !successfulNames.includes(entry.name));
+
+ if (response.successCount > 0) {
+ this.messageService.add({
+ severity: 'warn',
+ summary: 'Partial Success',
+ detail: `${response.successCount} of ${response.totalRequested} icon(s) saved successfully. ${response.failureCount} failed.`,
+ life: 5000
+ });
+ this.loadSvgIcons(0);
+ } else {
+ this.batchErrorMessage = `Failed to save ${response.failureCount} icon(s). Please fix the errors and try again.`;
+ }
+ }
+
private validateSvgInput(): string | null {
if (!this.svgContent.trim()) {
return this.ERROR_MESSAGES.NO_CONTENT;
@@ -207,12 +323,17 @@ export class IconPickerComponent implements OnInit {
return null;
}
- private handleSuccessfulSave(): void {
+ private handleSuccessfulBatchSave(): void {
+ this.messageService.add({
+ severity: 'success',
+ summary: 'Icons Saved',
+ detail: `${this.svgEntries.length} SVG icon(s) saved successfully.`,
+ life: 3000
+ });
+
this.activeTabIndex = '1';
- if (!this.svgIcons.includes(this.svgName)) {
- this.svgIcons.unshift(this.svgName);
- }
- this.selectedSvgIcon = this.svgName;
+ this.loadSvgIcons(0);
+ this.clearAllEntries();
this.resetSvgForm();
}
diff --git a/booklore-ui/src/app/shared/layout/component/layout-menu/app.menuitem.component.html b/booklore-ui/src/app/shared/layout/component/layout-menu/app.menuitem.component.html
index 6818163c6..288eac810 100644
--- a/booklore-ui/src/app/shared/layout/component/layout-menu/app.menuitem.component.html
+++ b/booklore-ui/src/app/shared/layout/component/layout-menu/app.menuitem.component.html
@@ -56,7 +56,7 @@