feat(icons): Made icons for libraries and shelves optional with no default icons. (#2599)
* feat(icons): Made icons for libraries and shelves optional with no default icon displayed. * Added tests for making sure the API handles nullable icons for Shelves and Libraries. * Fixed some issues identified during PR review. * Rebased on develop.
This commit is contained in:
+7
-6
@@ -45,17 +45,18 @@
|
||||
/>
|
||||
</div>
|
||||
<label [for]="'shelf-' + shelf.id" class="shelf-label">
|
||||
<div class="shelf-icon-wrapper">
|
||||
@if (shelf.icon) {
|
||||
@if (shelf.icon) {
|
||||
<div class="shelf-icon-wrapper">
|
||||
<app-icon-display
|
||||
[icon]="getShelfIcon(shelf)"
|
||||
size="20px"
|
||||
iconClass="shelf-icon"
|
||||
/>
|
||||
} @else {
|
||||
<i class="pi pi-bookmark shelf-icon"></i>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
} @else {
|
||||
<div class="shelf-icon-wrapper-empty">
|
||||
</div>
|
||||
}
|
||||
<span class="shelf-name">{{ shelf.name }}</span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
+6
-3
@@ -153,12 +153,15 @@
|
||||
cursor: pointer;
|
||||
min-width: 0;
|
||||
|
||||
.shelf-icon-wrapper, .shelf-icon-wrapper-empty {
|
||||
width: 34px;
|
||||
height: 34px;
|
||||
}
|
||||
|
||||
.shelf-icon-wrapper {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 34px;
|
||||
height: 34px;
|
||||
background: var(--overlay-background);
|
||||
border-radius: 8px;
|
||||
flex-shrink: 0;
|
||||
@@ -187,7 +190,7 @@
|
||||
.shelf-label {
|
||||
gap: 0.5rem;
|
||||
|
||||
.shelf-icon-wrapper {
|
||||
.shelf-icon-wrapper, .shelf-icon-wrapper-empty {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
|
||||
|
||||
+3
-3
@@ -123,10 +123,10 @@ export class ShelfAssignerComponent implements OnInit {
|
||||
}
|
||||
|
||||
getShelfIcon(shelf: Shelf): IconSelection {
|
||||
if (shelf.iconType === 'PRIME_NG') {
|
||||
return {type: 'PRIME_NG', value: `pi pi-${shelf.icon}`};
|
||||
if (shelf.iconType === 'CUSTOM_SVG') {
|
||||
return {type: 'CUSTOM_SVG', value: shelf.icon ?? ""};
|
||||
} else {
|
||||
return {type: 'CUSTOM_SVG', value: shelf.icon};
|
||||
return {type: 'PRIME_NG', value: `pi pi-${shelf.icon}`};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -55,8 +55,8 @@ export class ShelfCreatorComponent {
|
||||
}
|
||||
|
||||
createShelf(): void {
|
||||
const iconValue = this.selectedIcon?.value || 'bookmark';
|
||||
const iconType = this.selectedIcon?.type || 'PRIME_NG';
|
||||
const iconValue = this.selectedIcon?.value ?? null;
|
||||
const iconType = this.selectedIcon?.type ?? null;
|
||||
|
||||
const newShelf: Partial<Shelf> = {
|
||||
name: this.shelfName,
|
||||
|
||||
+8
-6
@@ -47,10 +47,12 @@ export class ShelfEditDialogComponent implements OnInit {
|
||||
if (this.shelf) {
|
||||
this.shelfName = this.shelf.name;
|
||||
this.isPublic = this.shelf.publicShelf ?? false;
|
||||
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};
|
||||
if (this.shelf.iconType && 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};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -68,8 +70,8 @@ export class ShelfEditDialogComponent implements OnInit {
|
||||
}
|
||||
|
||||
save() {
|
||||
const iconValue = this.selectedIcon?.value || 'bookmark';
|
||||
const iconType = this.selectedIcon?.type || 'PRIME_NG';
|
||||
const iconValue = this.selectedIcon?.value ?? null;
|
||||
const iconType = this.selectedIcon?.type ?? null;
|
||||
|
||||
const shelf: Shelf = {
|
||||
name: this.shelfName,
|
||||
|
||||
@@ -4,8 +4,8 @@ import {BookType} from './book.model';
|
||||
export interface Library {
|
||||
id?: number;
|
||||
name: string;
|
||||
icon: string;
|
||||
iconType?: 'PRIME_NG' | 'CUSTOM_SVG';
|
||||
icon?: string | null;
|
||||
iconType?: 'PRIME_NG' | 'CUSTOM_SVG' | null;
|
||||
watch: boolean;
|
||||
fileNamingPattern?: string;
|
||||
sort?: SortOption;
|
||||
|
||||
@@ -3,8 +3,8 @@ import {SortOption} from './sort.model';
|
||||
export interface Shelf {
|
||||
id?: number;
|
||||
name: string;
|
||||
icon: string;
|
||||
iconType?: 'PRIME_NG' | 'CUSTOM_SVG';
|
||||
icon?: string | null;
|
||||
iconType?: 'PRIME_NG' | 'CUSTOM_SVG' | null;
|
||||
sort?: SortOption;
|
||||
publicShelf?: boolean;
|
||||
userId?: number;
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
|
||||
<div class="form-field">
|
||||
<label>
|
||||
Icon <span class="required">*</span>
|
||||
Icon (Optional)
|
||||
</label>
|
||||
@if (!selectedIcon) {
|
||||
<button class="icon-picker-trigger" (click)="openIconPicker()" type="button">
|
||||
|
||||
@@ -70,11 +70,13 @@ export class LibraryCreatorComponent implements OnInit {
|
||||
this.chosenLibraryName = name;
|
||||
this.editModeLibraryName = name;
|
||||
|
||||
if (iconType === 'CUSTOM_SVG') {
|
||||
this.selectedIcon = {type: 'CUSTOM_SVG', value: icon};
|
||||
} else {
|
||||
const value = icon.slice(0, 6) === 'pi pi-' ? icon : `pi pi-${icon}`;
|
||||
this.selectedIcon = {type: 'PRIME_NG', value: value};
|
||||
if (icon != null && iconType) {
|
||||
if (iconType === 'CUSTOM_SVG') {
|
||||
this.selectedIcon = {type: 'CUSTOM_SVG', value: icon};
|
||||
} else {
|
||||
const value = icon.slice(0, 6) === 'pi pi-' ? icon : `pi pi-${icon}`;
|
||||
this.selectedIcon = {type: 'PRIME_NG', value: value};
|
||||
}
|
||||
}
|
||||
|
||||
this.watch = watch;
|
||||
@@ -186,7 +188,7 @@ export class LibraryCreatorComponent implements OnInit {
|
||||
}
|
||||
|
||||
isLibraryDetailsValid(): boolean {
|
||||
return !!this.chosenLibraryName.trim() && !!this.selectedIcon;
|
||||
return !!this.chosenLibraryName.trim();
|
||||
}
|
||||
|
||||
isDirectorySelectionValid(): boolean {
|
||||
@@ -207,8 +209,8 @@ export class LibraryCreatorComponent implements OnInit {
|
||||
}
|
||||
}
|
||||
|
||||
const iconValue = this.selectedIcon?.value || 'heart';
|
||||
const iconType = this.selectedIcon?.type || 'PRIME_NG';
|
||||
const iconValue = this.selectedIcon?.value ?? null;
|
||||
const iconType = this.selectedIcon?.type ?? null;
|
||||
|
||||
const library: Library = {
|
||||
name: this.chosenLibraryName,
|
||||
|
||||
@@ -29,22 +29,36 @@
|
||||
<div class="icon-picker-section">
|
||||
<div class="icon-picker-wrapper">
|
||||
<label>Shelf Icon</label>
|
||||
<div class="icon-display-container" (click)="openIconPicker()">
|
||||
@if (selectedIcon) {
|
||||
<app-icon-display
|
||||
[icon]="selectedIcon"
|
||||
[size]="'16px'"
|
||||
iconClass="selected-icon"
|
||||
alt="Selected shelf icon">
|
||||
</app-icon-display>
|
||||
<span class="icon-label">Click to change</span>
|
||||
} @else {
|
||||
@if (selectedIcon) {
|
||||
<div class="selected-icon-display">
|
||||
<div class="icon-display-container" (click)="openIconPicker()" (keydown.enter)="openIconPicker()" tabindex="0" role="button">
|
||||
<app-icon-display
|
||||
[icon]="selectedIcon"
|
||||
[size]="'16px'"
|
||||
iconClass="selected-icon"
|
||||
alt="Selected shelf icon">
|
||||
</app-icon-display>
|
||||
<span class="icon-label">Click to change</span>
|
||||
</div>
|
||||
<p-button
|
||||
icon="pi pi-times"
|
||||
severity="danger"
|
||||
[outlined]="true"
|
||||
[rounded]="true"
|
||||
size="small"
|
||||
(onClick)="clearSelectedIcon()"
|
||||
pTooltip="Remove icon"
|
||||
tooltipPosition="left"
|
||||
/>
|
||||
</div>
|
||||
} @else {
|
||||
<div class="icon-display-container" (click)="openIconPicker()" (keydown.enter)="openIconPicker()" tabindex="0" role="button">
|
||||
<div class="icon-placeholder">
|
||||
<i class="pi pi-plus"></i>
|
||||
<span>Select Icon</span>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
@if (isAdmin) {
|
||||
|
||||
@@ -74,6 +74,12 @@
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.selected-icon-display {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.icon-display-container {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
@@ -89,6 +95,11 @@
|
||||
border-color: var(--primary-color);
|
||||
}
|
||||
|
||||
&:focus {
|
||||
outline: 2px solid var(--primary-color);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
.selected-icon {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import {IconPickerService, IconSelection} from '../../../shared/service/icon-pic
|
||||
import {CheckboxChangeEvent, CheckboxModule} from "primeng/checkbox";
|
||||
import {UserService} from "../../settings/user-management/user.service";
|
||||
import {IconDisplayComponent} from '../../../shared/components/icon-display/icon-display.component';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {BookService} from '../../book/service/book.service';
|
||||
import {ShelfService} from '../../book/service/shelf.service';
|
||||
import {Shelf} from '../../book/model/shelf.model';
|
||||
@@ -167,7 +168,8 @@ const FIELD_CONFIGS: Record<RuleField, FullFieldConfig> = {
|
||||
MultiSelect,
|
||||
AutoComplete,
|
||||
CheckboxModule,
|
||||
IconDisplayComponent
|
||||
IconDisplayComponent,
|
||||
Tooltip
|
||||
]
|
||||
})
|
||||
export class MagicShelfComponent implements OnInit {
|
||||
@@ -271,7 +273,7 @@ export class MagicShelfComponent implements OnInit {
|
||||
|
||||
this.form = new FormGroup({
|
||||
name: new FormControl<string | null>(data?.name ?? null, {nonNullable: true, validators: [Validators.required]}),
|
||||
icon: new FormControl<string | null>(iconValue, {nonNullable: true, validators: [Validators.required]}),
|
||||
icon: new FormControl<string | null>(iconValue),
|
||||
isPublic: new FormControl<boolean>(data?.isPublic ?? false),
|
||||
group: data?.filterJson ? this.buildGroupFromData(JSON.parse(data.filterJson)) : this.createGroup()
|
||||
});
|
||||
@@ -285,7 +287,7 @@ export class MagicShelfComponent implements OnInit {
|
||||
} else {
|
||||
this.form = new FormGroup({
|
||||
name: new FormControl<string | null>(null, {nonNullable: true, validators: [Validators.required]}),
|
||||
icon: new FormControl<string | null>(null, {nonNullable: true, validators: [Validators.required]}),
|
||||
icon: new FormControl<string | null>(null),
|
||||
isPublic: new FormControl<boolean>(false),
|
||||
group: this.createGroup()
|
||||
});
|
||||
@@ -477,6 +479,11 @@ export class MagicShelfComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
clearSelectedIcon(): void {
|
||||
this.selectedIcon = null;
|
||||
this.form.get('icon')?.setValue(null);
|
||||
}
|
||||
|
||||
private hasAtLeastOneValidRule(group: GroupFormGroup): boolean {
|
||||
const rulesArray = group.get('rules') as FormArray;
|
||||
|
||||
|
||||
@@ -11,8 +11,8 @@ import {GroupRule} from '../component/magic-shelf-component';
|
||||
export interface MagicShelf {
|
||||
id?: number | null;
|
||||
name: string;
|
||||
icon?: string;
|
||||
iconType?: 'PRIME_NG' | 'CUSTOM_SVG';
|
||||
icon?: string | null;
|
||||
iconType?: 'PRIME_NG' | 'CUSTOM_SVG' | null;
|
||||
filterJson: string;
|
||||
isPublic?: boolean;
|
||||
}
|
||||
@@ -98,7 +98,7 @@ export class MagicShelfService {
|
||||
const payload: MagicShelf = {
|
||||
id: data.id,
|
||||
name: data.name ?? '',
|
||||
icon: data.icon ?? 'pi pi-book',
|
||||
icon: data.icon,
|
||||
iconType: data.iconType,
|
||||
filterJson: JSON.stringify(data.group),
|
||||
isPublic: data.isPublic ?? false
|
||||
|
||||
Reference in New Issue
Block a user