refactor(frontend): rename booklore-ui to frontend
- Frontend path: - rename the tracked Angular app tree from `booklore-ui/` to `frontend/` - preserve file contents during the move so this commit stays focused on the path change itself - Frontend docs: - update the moved frontend README and contribution guide where they refer to the renamed folder - keep those edits limited to path references introduced by the directory rename
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
<ng-container *transloco="let t; prefix: 'layout.menu'">
|
||||
<div class="menu-container">
|
||||
<div>
|
||||
<div class="home-menu-section">
|
||||
<ul class="layout-menu">
|
||||
@if (homeMenu(); as homeMenu) {
|
||||
@for (item of homeMenu; track item.label; let i = $index) {
|
||||
@if (!item.separator) {
|
||||
<li app-menuitem [item]="item" [index]="i" [root]="true" menuKey="home"></li>
|
||||
}
|
||||
}
|
||||
}
|
||||
</ul>
|
||||
<i class="pi pi-objects-column sidebar-width-btn"
|
||||
(click)="widthPanel.toggle($event)"></i>
|
||||
<p-popover #widthPanel appendTo="body">
|
||||
<div class="sidebar-width-popover">
|
||||
<label class="sidebar-width-popover-label">{{ sidebarWidth }}px</label>
|
||||
<p-slider
|
||||
[(ngModel)]="sidebarWidth"
|
||||
[min]="175"
|
||||
[max]="400"
|
||||
[step]="1"
|
||||
(onChange)="onSidebarWidthChange()"
|
||||
(onSlideEnd)="saveSidebarWidth()">
|
||||
</p-slider>
|
||||
</div>
|
||||
</p-popover>
|
||||
</div>
|
||||
|
||||
<ul class="layout-menu">
|
||||
@if (libraryMenu(); as libraryMenu) {
|
||||
@for (item of libraryMenu; track item.label; let i = $index) {
|
||||
@if (!item.separator) {
|
||||
<li app-menuitem [item]="item" [index]="i" [root]="true" menuKey="library"></li>
|
||||
}
|
||||
}
|
||||
}
|
||||
</ul>
|
||||
|
||||
<ul class="layout-menu">
|
||||
@if (shelfMenu(); as shelfMenu) {
|
||||
@for (item of shelfMenu; track item.label; let i = $index) {
|
||||
@if (!item.separator) {
|
||||
<li app-menuitem [item]="item" [index]="i" [root]="true" menuKey="shelf"></li>
|
||||
}
|
||||
}
|
||||
}
|
||||
</ul>
|
||||
|
||||
<ul class="layout-menu">
|
||||
@if (magicShelfMenu(); as shelfMenu) {
|
||||
@for (item of shelfMenu; track item.label; let i = $index) {
|
||||
@if (!item.separator) {
|
||||
<li app-menuitem [item]="item" [index]="i" [root]="true" menuKey="magicShelf"></li>
|
||||
}
|
||||
}
|
||||
}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@if (versionInfo) {
|
||||
<div class="version-info" style="margin-top: auto;">
|
||||
<div class="version-text">
|
||||
@if (isSemanticVersion(versionInfo.current)) {
|
||||
<a
|
||||
[href]="getVersionUrl(versionInfo.current)"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
class="version-link"
|
||||
>
|
||||
{{ versionInfo.current }}
|
||||
</a>
|
||||
} @else {
|
||||
<span class="version-label">{{ versionInfo.current }}</span>
|
||||
}
|
||||
</div>
|
||||
@if (isSemanticVersion(versionInfo.current) && versionInfo.latest && versionInfo.latest !== versionInfo.current) {
|
||||
<div>
|
||||
<a
|
||||
(click)="openChangelogDialog()"
|
||||
class="update-link"
|
||||
>
|
||||
{{ t('update') }}
|
||||
</a>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</ng-container>
|
||||
@@ -0,0 +1,78 @@
|
||||
.menu-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.home-menu-section {
|
||||
position: relative;
|
||||
|
||||
.sidebar-width-btn {
|
||||
position: absolute;
|
||||
top: 0.125rem;
|
||||
right: 0.5rem;
|
||||
font-size: 0.8rem;
|
||||
color: var(--p-surface-500);
|
||||
cursor: pointer;
|
||||
transition: color 0.2s ease;
|
||||
|
||||
&:hover {
|
||||
color: var(--p-primary-color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.sidebar-width-popover {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
min-width: 200px;
|
||||
padding: 0.25rem;
|
||||
|
||||
.sidebar-width-popover-label {
|
||||
font-size: 0.8rem;
|
||||
color: var(--p-text-muted-color);
|
||||
white-space: nowrap;
|
||||
min-width: 38px;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
p-slider {
|
||||
flex: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.version-info {
|
||||
padding: 1rem;
|
||||
text-align: center;
|
||||
width: 100%;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.version-text {
|
||||
color: #e5e7eb;
|
||||
}
|
||||
|
||||
.version-link {
|
||||
font-size: 0.875rem;
|
||||
|
||||
&:hover {
|
||||
text-decoration: underline;
|
||||
color: #f3f4f6;
|
||||
}
|
||||
}
|
||||
|
||||
.version-label {
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.update-link {
|
||||
cursor: pointer;
|
||||
color: #fb923c;
|
||||
font-size: 0.75rem;
|
||||
|
||||
&:hover {
|
||||
text-decoration: underline;
|
||||
color: #fdba74;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,349 @@
|
||||
import {Component, computed, effect, inject, OnInit, signal} from '@angular/core';
|
||||
import {toSignal} from '@angular/core/rxjs-interop';
|
||||
import {AppMenuitemComponent} from './app.menuitem.component';
|
||||
import {MenuModule} from 'primeng/menu';
|
||||
import {LibraryService} from '../../../../features/book/service/library.service';
|
||||
import {LibraryHealthService} from '../../../../features/book/service/library-health.service';
|
||||
import {ShelfService} from '../../../../features/book/service/shelf.service';
|
||||
import {BookService} from '../../../../features/book/service/book.service';
|
||||
import {LibraryShelfMenuService} from '../../../../features/book/service/library-shelf-menu.service';
|
||||
import {AppVersion, VersionService} from '../../../service/version.service';
|
||||
import {DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {UserService} from '../../../../features/settings/user-management/user.service';
|
||||
import {MagicShelfService} from '../../../../features/magic-shelf/service/magic-shelf.service';
|
||||
import {SeriesDataService} from '../../../../features/series-browser/service/series-data.service';
|
||||
import {AuthorService} from '../../../../features/author-browser/service/author.service';
|
||||
import {MenuItem} from 'primeng/api';
|
||||
import {DialogLauncherService} from '../../../services/dialog-launcher.service';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
import {Slider} from 'primeng/slider';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {Popover} from 'primeng/popover';
|
||||
import {LocalStorageService} from '../../../service/local-storage.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-menu',
|
||||
standalone: true,
|
||||
imports: [AppMenuitemComponent, MenuModule, TranslocoDirective, Slider, FormsModule, Popover],
|
||||
templateUrl: './app.menu.component.html',
|
||||
styleUrl: './app.menu.component.scss',
|
||||
})
|
||||
export class AppMenuComponent implements OnInit {
|
||||
versionInfo: AppVersion | null = null;
|
||||
dynamicDialogRef: DynamicDialogRef | undefined | null;
|
||||
|
||||
private libraryService = inject(LibraryService);
|
||||
private libraryHealthService = inject(LibraryHealthService);
|
||||
private shelfService = inject(ShelfService);
|
||||
private bookService = inject(BookService);
|
||||
private versionService = inject(VersionService);
|
||||
private libraryShelfMenuService = inject(LibraryShelfMenuService);
|
||||
private dialogLauncherService = inject(DialogLauncherService);
|
||||
private userService = inject(UserService);
|
||||
private magicShelfService = inject(MagicShelfService);
|
||||
private seriesDataService = inject(SeriesDataService);
|
||||
private authorService = inject(AuthorService);
|
||||
private t = inject(TranslocoService);
|
||||
private localStorageService = inject(LocalStorageService);
|
||||
|
||||
private activeLang = toSignal(this.t.langChanges$, {initialValue: this.t.getActiveLang()});
|
||||
private readonly currentUser = this.userService.currentUser;
|
||||
private allAuthors = this.authorService.allAuthors;
|
||||
|
||||
librarySortField = signal<'name' | 'id'>('name');
|
||||
librarySortOrder = signal<'asc' | 'desc'>('desc');
|
||||
shelfSortField = signal<'name' | 'id'>('name');
|
||||
shelfSortOrder = signal<'asc' | 'desc'>('asc');
|
||||
magicShelfSortField = signal<'name' | 'id'>('name');
|
||||
magicShelfSortOrder = signal<'asc' | 'desc'>('asc');
|
||||
sidebarWidth = 225;
|
||||
|
||||
private readonly libraryBookCounts = computed(() => {
|
||||
const counts = new Map<number, number>();
|
||||
for (const book of this.bookService.books()) {
|
||||
if (book.libraryId != null) {
|
||||
counts.set(book.libraryId, (counts.get(book.libraryId) ?? 0) + 1);
|
||||
}
|
||||
}
|
||||
return counts;
|
||||
});
|
||||
|
||||
private readonly shelfBookCounts = computed(() => {
|
||||
const currentUserId = this.currentUser()?.id;
|
||||
const counts = new Map<number, number>();
|
||||
let unshelvedCount = 0;
|
||||
|
||||
for (const book of this.bookService.books()) {
|
||||
if (!book.shelves || book.shelves.length === 0) {
|
||||
unshelvedCount++;
|
||||
} else {
|
||||
for (const shelf of book.shelves) {
|
||||
if (shelf.id != null) {
|
||||
counts.set(shelf.id, (counts.get(shelf.id) ?? 0) + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// For shelves not owned by the current user, fall back to the shelf's bookCount field
|
||||
for (const shelf of this.shelfService.shelves()) {
|
||||
if (shelf.userId !== currentUserId && shelf.id != null) {
|
||||
counts.set(shelf.id, shelf.bookCount || 0);
|
||||
}
|
||||
}
|
||||
|
||||
counts.set(-1, unshelvedCount); // sentinel key for unshelved count
|
||||
return counts;
|
||||
});
|
||||
|
||||
private readonly magicShelfBookCounts = computed(() => {
|
||||
const counts = new Map<number, number>();
|
||||
const shelves = this.magicShelfService.shelves();
|
||||
if (shelves.length === 0) return counts;
|
||||
|
||||
for (const shelf of shelves) {
|
||||
if (shelf.id != null) {
|
||||
counts.set(shelf.id, this.magicShelfService.getBookCountValue(shelf.id));
|
||||
}
|
||||
}
|
||||
return counts;
|
||||
});
|
||||
|
||||
readonly homeMenu = computed<MenuItem[]>(() => {
|
||||
this.activeLang();
|
||||
|
||||
return [
|
||||
{
|
||||
label: this.t.translate('layout.menu.home'),
|
||||
items: [
|
||||
{
|
||||
label: this.t.translate('layout.menu.dashboard'),
|
||||
icon: 'pi pi-fw pi-home',
|
||||
routerLink: ['/dashboard'],
|
||||
},
|
||||
{
|
||||
label: this.t.translate('layout.menu.allBooks'),
|
||||
type: 'All Books',
|
||||
icon: 'pi pi-fw pi-book',
|
||||
routerLink: ['/all-books'],
|
||||
bookCount: this.bookService.books().length,
|
||||
},
|
||||
{
|
||||
label: this.t.translate('layout.menu.series'),
|
||||
type: 'Series',
|
||||
icon: 'pi pi-fw pi-objects-column',
|
||||
routerLink: ['/series'],
|
||||
bookCount: this.seriesDataService.allSeries().length,
|
||||
},
|
||||
{
|
||||
label: this.t.translate('layout.menu.authors'),
|
||||
type: 'Authors',
|
||||
icon: 'pi pi-fw pi-users',
|
||||
routerLink: ['/authors'],
|
||||
bookCount: this.allAuthors()?.length ?? 0,
|
||||
},
|
||||
{
|
||||
label: this.t.translate('layout.menu.notebook'),
|
||||
icon: 'pi pi-fw pi-pencil',
|
||||
routerLink: ['/notebook'],
|
||||
}
|
||||
],
|
||||
},
|
||||
];
|
||||
});
|
||||
|
||||
readonly libraryMenu = computed<MenuItem[]>(() => {
|
||||
this.activeLang();
|
||||
const libCounts = this.libraryBookCounts();
|
||||
|
||||
const sortedLibraries = this.sortArray(
|
||||
this.libraryService.libraries(),
|
||||
this.librarySortField(),
|
||||
this.librarySortOrder()
|
||||
);
|
||||
|
||||
return [
|
||||
{
|
||||
label: this.t.translate('layout.menu.libraries'),
|
||||
type: 'library',
|
||||
hasDropDown: true,
|
||||
hasCreate: true,
|
||||
items: sortedLibraries.map((library) => ({
|
||||
menu: this.libraryShelfMenuService.initializeLibraryMenuItems(library),
|
||||
label: library.name,
|
||||
type: 'Library',
|
||||
icon: library.icon || undefined,
|
||||
iconType: (library.iconType || undefined) as 'PRIME_NG' | 'CUSTOM_SVG' | undefined,
|
||||
routerLink: [`/library/${library.id}/books`],
|
||||
bookCount: libCounts.get(library.id ?? 0) ?? 0,
|
||||
unhealthy: this.libraryHealthService.isUnhealthy(library.id ?? 0),
|
||||
})),
|
||||
},
|
||||
];
|
||||
});
|
||||
|
||||
readonly magicShelfMenu = computed<MenuItem[]>(() => {
|
||||
this.activeLang();
|
||||
|
||||
const sortedShelves = this.sortArray(
|
||||
this.magicShelfService.shelves(),
|
||||
this.magicShelfSortField(),
|
||||
this.magicShelfSortOrder()
|
||||
);
|
||||
|
||||
return [
|
||||
{
|
||||
label: this.t.translate('layout.menu.magicShelves'),
|
||||
type: 'magicShelf',
|
||||
hasDropDown: true,
|
||||
hasCreate: true,
|
||||
items: sortedShelves.map((shelf) => ({
|
||||
label: shelf.name,
|
||||
type: 'magicShelfItem',
|
||||
icon: shelf.icon || undefined,
|
||||
iconType: (shelf.iconType || undefined) as 'PRIME_NG' | 'CUSTOM_SVG' | undefined,
|
||||
menu: this.libraryShelfMenuService.initializeMagicShelfMenuItems(shelf),
|
||||
routerLink: [`/magic-shelf/${shelf.id}/books`],
|
||||
bookCount: this.magicShelfBookCounts().get(shelf.id ?? 0) ?? 0,
|
||||
})),
|
||||
},
|
||||
];
|
||||
});
|
||||
|
||||
readonly shelfMenu = computed<MenuItem[]>(() => {
|
||||
this.activeLang();
|
||||
const shelfCounts = this.shelfBookCounts();
|
||||
|
||||
const sortedShelves = this.sortArray(
|
||||
this.shelfService.shelves(),
|
||||
this.shelfSortField(),
|
||||
this.shelfSortOrder()
|
||||
);
|
||||
|
||||
const shelves = [...sortedShelves];
|
||||
const koboShelfIndex = shelves.findIndex(shelf => shelf.name === 'Kobo');
|
||||
let koboShelf = null;
|
||||
if (koboShelfIndex !== -1) {
|
||||
koboShelf = shelves.splice(koboShelfIndex, 1)[0];
|
||||
}
|
||||
|
||||
const shelfItems = shelves.map((shelf) => ({
|
||||
menu: this.libraryShelfMenuService.initializeShelfMenuItems(shelf),
|
||||
label: shelf.name,
|
||||
type: 'Shelf',
|
||||
icon: shelf.icon || undefined,
|
||||
iconType: (shelf.iconType || undefined) as 'PRIME_NG' | 'CUSTOM_SVG' | undefined,
|
||||
routerLink: [`/shelf/${shelf.id}/books`],
|
||||
bookCount: shelfCounts.get(shelf.id ?? 0) ?? 0,
|
||||
}));
|
||||
|
||||
const items: MenuItem[] = [{
|
||||
label: this.t.translate('layout.menu.unshelved'),
|
||||
type: 'Shelf',
|
||||
icon: 'pi pi-inbox',
|
||||
iconType: 'PRIME_NG' as 'PRIME_NG' | 'CUSTOM_SVG',
|
||||
routerLink: ['/unshelved-books'],
|
||||
bookCount: shelfCounts.get(-1) ?? 0,
|
||||
}];
|
||||
|
||||
if (koboShelf) {
|
||||
items.push({
|
||||
label: koboShelf.name,
|
||||
type: 'Shelf',
|
||||
icon: koboShelf.icon || undefined,
|
||||
iconType: (koboShelf.iconType || undefined) as 'PRIME_NG' | 'CUSTOM_SVG' | undefined,
|
||||
routerLink: [`/shelf/${koboShelf.id}/books`],
|
||||
bookCount: shelfCounts.get(koboShelf.id ?? 0) ?? 0,
|
||||
});
|
||||
}
|
||||
|
||||
items.push(...shelfItems);
|
||||
|
||||
return [
|
||||
{
|
||||
type: 'shelf',
|
||||
label: this.t.translate('layout.menu.shelves'),
|
||||
hasDropDown: true,
|
||||
hasCreate: true,
|
||||
items,
|
||||
},
|
||||
];
|
||||
});
|
||||
|
||||
private readonly syncSortPreferencesEffect = effect(() => {
|
||||
const user = this.currentUser();
|
||||
if (!user) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (user.userSettings.sidebarLibrarySorting) {
|
||||
this.librarySortField.set(this.validateSortField(user.userSettings.sidebarLibrarySorting.field));
|
||||
this.librarySortOrder.set(this.validateSortOrder(user.userSettings.sidebarLibrarySorting.order));
|
||||
}
|
||||
if (user.userSettings.sidebarShelfSorting) {
|
||||
this.shelfSortField.set(this.validateSortField(user.userSettings.sidebarShelfSorting.field));
|
||||
this.shelfSortOrder.set(this.validateSortOrder(user.userSettings.sidebarShelfSorting.order));
|
||||
}
|
||||
if (user.userSettings.sidebarMagicShelfSorting) {
|
||||
this.magicShelfSortField.set(this.validateSortField(user.userSettings.sidebarMagicShelfSorting.field));
|
||||
this.magicShelfSortOrder.set(this.validateSortOrder(user.userSettings.sidebarMagicShelfSorting.order));
|
||||
}
|
||||
});
|
||||
|
||||
ngOnInit(): void {
|
||||
this.sidebarWidth = this.localStorageService.get<number>('sidebarWidth') ?? 225;
|
||||
|
||||
this.versionService.getVersion().subscribe((data) => {
|
||||
this.versionInfo = data;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
onSidebarWidthChange(): void {
|
||||
document.documentElement.style.setProperty('--sidebar-width', this.sidebarWidth + 'px');
|
||||
}
|
||||
|
||||
saveSidebarWidth(): void {
|
||||
this.localStorageService.set('sidebarWidth', this.sidebarWidth);
|
||||
}
|
||||
|
||||
openChangelogDialog() {
|
||||
this.dialogLauncherService.openVersionChangelogDialog();
|
||||
}
|
||||
|
||||
getVersionUrl(version: string | undefined): string {
|
||||
if (!version) return '#';
|
||||
return version.startsWith('v')
|
||||
? `https://github.com/grimmory-tools/grimmory/releases/tag/${version}`
|
||||
: `https://github.com/grimmory-tools/grimmory/commit/${version}`;
|
||||
}
|
||||
|
||||
isSemanticVersion(version: string | undefined): boolean {
|
||||
if (!version) return false;
|
||||
const semanticVersionPattern = /^v\d+\.\d+\.\d+$/;
|
||||
return semanticVersionPattern.test(version);
|
||||
}
|
||||
|
||||
private sortArray<T extends { name?: string | null; id?: number | null }>(
|
||||
items: T[],
|
||||
field: 'name' | 'id',
|
||||
order: 'asc' | 'desc'
|
||||
): T[] {
|
||||
const sorted = [...items].sort((a, b) => {
|
||||
if (field === 'id') {
|
||||
return (a.id ?? 0) - (b.id ?? 0);
|
||||
}
|
||||
return (a.name ?? '').localeCompare(b.name ?? '');
|
||||
});
|
||||
|
||||
return order === 'desc' ? sorted.reverse() : sorted;
|
||||
}
|
||||
|
||||
private validateSortField(field: string): 'name' | 'id' {
|
||||
return field === 'id' ? 'id' : 'name';
|
||||
}
|
||||
|
||||
private validateSortOrder(order: string): 'asc' | 'desc' {
|
||||
return order === 'desc' ? 'desc' : 'asc';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
<ng-container>
|
||||
@if (root) {
|
||||
@if (item.hasDropDown) {
|
||||
<div class="layout-menuitem-root-text root-item-with-dropdown">
|
||||
<div class="root-item-label-container">
|
||||
<div>{{ item.label }}</div>
|
||||
@if (item.hasCreate) {
|
||||
<i
|
||||
class="pi pi-plus plus-icon"
|
||||
(click)="openDialog(item)"
|
||||
></i>
|
||||
}
|
||||
</div>
|
||||
<i
|
||||
(click)="toggleExpand(key)"
|
||||
[ngClass]="{
|
||||
'pi': true,
|
||||
'pi-angle-up': isExpanded(key),
|
||||
'pi-angle-down': !isExpanded(key)
|
||||
}"
|
||||
class="expand-icon"
|
||||
></i>
|
||||
</div>
|
||||
} @else {
|
||||
<div class="layout-menuitem-root-text root-item">
|
||||
<div>{{ item.label }}</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
<div>
|
||||
<div
|
||||
class="menu-item-container"
|
||||
[class.active-route-container]="isRouteActive"
|
||||
(click)="triggerLink()"
|
||||
>
|
||||
@if ((item.routerLink && !item.items)) {
|
||||
<a
|
||||
#link
|
||||
(click)="itemClick($event)"
|
||||
[ngClass]="item.class"
|
||||
class="menu-item-link"
|
||||
[class.active-route]="isRouteActive"
|
||||
[routerLink]="item.routerLink"
|
||||
[fragment]="item.fragment"
|
||||
[queryParamsHandling]="item.queryParamsHandling"
|
||||
[preserveFragment]="item.preserveFragment"
|
||||
[skipLocationChange]="item.skipLocationChange"
|
||||
[replaceUrl]="item.replaceUrl"
|
||||
[state]="item.state"
|
||||
[queryParams]="item.queryParams"
|
||||
[attr.target]="item.target"
|
||||
tabindex="0"
|
||||
pRipple
|
||||
>
|
||||
@if (item.unhealthy) {
|
||||
<span
|
||||
class="library-health-dot"
|
||||
[pTooltip]="'common.libraryPathInaccessible' | transloco"
|
||||
tooltipPosition="right"
|
||||
></span>
|
||||
}
|
||||
<app-icon-display
|
||||
[icon]="getIconSelection()"
|
||||
iconClass="layout-menuitem-icon"
|
||||
size="18px"
|
||||
[displayEmpty]="true"
|
||||
></app-icon-display>
|
||||
<span class="layout-menuitem-text menu-item-text">
|
||||
{{ item.label }}
|
||||
</span>
|
||||
</a>
|
||||
}
|
||||
|
||||
<span class="menu-item-end-content">
|
||||
@if (item.type === 'Library' || item.type === 'Shelf' || item.type === 'magicShelfItem') {
|
||||
@if ((item.type !== 'Library' || (admin || canManipulateLibrary)) && item.label !== 'Unshelved' && item.label !== 'Kobo') {
|
||||
<p-button
|
||||
(click)="entitymenu.toggle($event); $event.stopPropagation()"
|
||||
(mouseover)="hovered = true"
|
||||
(mouseleave)="hovered = false"
|
||||
[text]="true"
|
||||
[outlined]="false"
|
||||
[rounded]="true"
|
||||
[label]="hovered ? '' : item.bookCount?.toString() || ''"
|
||||
[icon]="hovered ? 'pi pi-ellipsis-v' : ''"
|
||||
class="entity-menu-button"
|
||||
></p-button>
|
||||
}
|
||||
<p-menu #entitymenu [model]="item.menu" [popup]="true" appendTo="body"></p-menu>
|
||||
}
|
||||
|
||||
@if (item.type === 'Library' && (!admin && !canManipulateLibrary) || item.type === 'All Books' || item.type === 'Series' || item.type === 'Authors' || item.label === 'Unshelved' || item.label === 'Kobo') {
|
||||
<p class="book-count">
|
||||
{{ formatCount(item.bookCount) }}
|
||||
</p>
|
||||
}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div [@children]="isExpanded(key) ? 'expanded' : 'collapsed'" class="submenu-container">
|
||||
@if (item.items) {
|
||||
<ul>
|
||||
@for (child of item.items; track child.routerLink?.[0] ?? child.label; let i = $index) {
|
||||
<li app-menuitem [item]="child" [index]="i" [parentKey]="key" [class]="child.badgeClass"></li>
|
||||
}
|
||||
</ul>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
@@ -0,0 +1,116 @@
|
||||
.plus-icon {
|
||||
color: var(--p-primary-color);
|
||||
transition: color 0.2s ease;
|
||||
font-size: 0.8rem;
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
color: var(--p-green-400);
|
||||
}
|
||||
}
|
||||
|
||||
.root-item-with-dropdown {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
cursor: pointer;
|
||||
padding-top: 1rem;
|
||||
}
|
||||
|
||||
.root-item-label-container {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 0.5rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.expand-icon {
|
||||
color: var(--p-surface-500);
|
||||
padding-right: 0.75rem;
|
||||
|
||||
&:hover {
|
||||
color: var(--p-surface-200);
|
||||
}
|
||||
}
|
||||
|
||||
.root-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.menu-item-container {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
background-color: var(--p-surface-800);
|
||||
border-radius: 8px;
|
||||
}
|
||||
}
|
||||
|
||||
.menu-item-container.active-route-container {
|
||||
background-color: color-mix(in srgb, var(--p-primary-300), transparent 93%);
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.menu-item-link {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
|
||||
.menu-item-text {
|
||||
width: 100%;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
margin-left: 0.35rem;
|
||||
font-size: 0.985rem;
|
||||
}
|
||||
|
||||
.menu-item-end-content {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.entity-menu-button {
|
||||
height: 30px;
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.book-count {
|
||||
color: var(--primary-color);
|
||||
padding-right: 0.75rem;
|
||||
}
|
||||
|
||||
.submenu-container {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.library-health-dot {
|
||||
display: inline-block;
|
||||
flex-shrink: 0;
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
border-radius: 50%;
|
||||
background-color: #ef4444;
|
||||
animation: pulse 2s ease-in-out infinite;
|
||||
}
|
||||
|
||||
@keyframes pulse {
|
||||
0%, 100% {
|
||||
opacity: 1;
|
||||
box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7);
|
||||
}
|
||||
50% {
|
||||
opacity: 0.85;
|
||||
box-shadow: 0 0 0 5px rgba(239, 68, 68, 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
import {Component, effect, ElementRef, HostBinding, inject, Input, OnDestroy, OnInit, ViewChild} from '@angular/core';
|
||||
import {NavigationEnd, Router, RouterLink} from '@angular/router';
|
||||
import {animate, state, style, transition, trigger} from '@angular/animations';
|
||||
import {Subscription} from 'rxjs';
|
||||
import {filter} from 'rxjs/operators';
|
||||
import {MenuService} from './service/app.menu.service';
|
||||
import {NgClass} from '@angular/common';
|
||||
import {Ripple} from 'primeng/ripple';
|
||||
import {Button} from 'primeng/button';
|
||||
import {Menu} from 'primeng/menu';
|
||||
import {UserService} from '../../../../features/settings/user-management/user.service';
|
||||
import {DialogLauncherService} from '../../../services/dialog-launcher.service';
|
||||
import {BookDialogHelperService} from '../../../../features/book/components/book-browser/book-dialog-helper.service';
|
||||
import {IconDisplayComponent} from '../../../components/icon-display/icon-display.component';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {MenuItem} from 'primeng/api';
|
||||
import {IconSelection} from '../../../service/icon-picker.service';
|
||||
import {TranslocoPipe} from '@jsverse/transloco';
|
||||
|
||||
@Component({
|
||||
selector: '[app-menuitem]',
|
||||
templateUrl: './app.menuitem.component.html',
|
||||
styleUrls: ['./app.menuitem.component.scss'],
|
||||
imports: [
|
||||
RouterLink,
|
||||
NgClass,
|
||||
Ripple,
|
||||
Button,
|
||||
Menu,
|
||||
IconDisplayComponent,
|
||||
Tooltip,
|
||||
TranslocoPipe
|
||||
],
|
||||
animations: [
|
||||
trigger('children', [
|
||||
state('collapsed', style({
|
||||
height: '0'
|
||||
})),
|
||||
state('expanded', style({
|
||||
height: '*'
|
||||
})),
|
||||
transition('collapsed <=> expanded', animate('400ms cubic-bezier(0.86, 0, 0.07, 1)'))
|
||||
])
|
||||
]
|
||||
})
|
||||
export class AppMenuitemComponent implements OnInit, OnDestroy {
|
||||
@Input() item: any;
|
||||
@Input() index!: number;
|
||||
@Input() @HostBinding('class.layout-root-menuitem') root!: boolean;
|
||||
@Input() parentKey!: string;
|
||||
@Input() menuKey!: string;
|
||||
@ViewChild('linkRef') linkRef!: ElementRef<HTMLAnchorElement>;
|
||||
|
||||
hovered = false;
|
||||
active = false;
|
||||
key: string = "";
|
||||
canManipulateLibrary: boolean = false;
|
||||
admin: boolean = false;
|
||||
expandedItems = new Set<string>();
|
||||
|
||||
get isRouteActive(): boolean {
|
||||
if (!this.item?.routerLink?.[0]) return false;
|
||||
return this.router.url.split('?')[0] === this.item.routerLink[0];
|
||||
}
|
||||
|
||||
private userService = inject(UserService);
|
||||
menuSourceSubscription: Subscription;
|
||||
menuResetSubscription: Subscription;
|
||||
private routerSubscription: Subscription;
|
||||
|
||||
constructor(
|
||||
public router: Router,
|
||||
private menuService: MenuService,
|
||||
private dialogLauncher: DialogLauncherService,
|
||||
private bookDialogHelperService: BookDialogHelperService
|
||||
) {
|
||||
effect(() => {
|
||||
const user = this.userService.currentUser();
|
||||
if (user) {
|
||||
this.canManipulateLibrary = user.permissions.canManageLibrary;
|
||||
this.admin = user.permissions.admin;
|
||||
}
|
||||
});
|
||||
|
||||
this.menuSourceSubscription = this.menuService.menuSource$.subscribe(value => {
|
||||
Promise.resolve(null).then(() => {
|
||||
if (value.routeEvent) {
|
||||
this.active = (value.key === this.key || value.key.startsWith(this.key + '-')) ? true : false;
|
||||
} else {
|
||||
if (value.key !== this.key && !value.key.startsWith(this.key + '-')) {
|
||||
this.active = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
this.menuResetSubscription = this.menuService.resetSource$.subscribe(() => {
|
||||
this.active = false;
|
||||
});
|
||||
|
||||
this.routerSubscription = this.router.events.pipe(filter(event => event instanceof NavigationEnd))
|
||||
.subscribe(() => {
|
||||
if (this.item.routerLink) {
|
||||
this.updateActiveStateFromRoute();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
const rootKey = this.menuKey ? this.menuKey + '-' : '';
|
||||
this.key = this.parentKey ? this.parentKey + '-' + this.index : rootKey + String(this.index);
|
||||
this.expandedItems.add(this.key);
|
||||
if (this.item.routerLink) {
|
||||
this.updateActiveStateFromRoute();
|
||||
}
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
this.menuSourceSubscription?.unsubscribe();
|
||||
this.menuResetSubscription?.unsubscribe();
|
||||
this.routerSubscription?.unsubscribe();
|
||||
}
|
||||
|
||||
toggleExpand(key: string) {
|
||||
if (this.expandedItems.has(key)) {
|
||||
this.expandedItems.delete(key);
|
||||
} else {
|
||||
this.expandedItems.add(key);
|
||||
}
|
||||
}
|
||||
|
||||
isExpanded(key: string): boolean {
|
||||
return this.expandedItems.has(key);
|
||||
}
|
||||
|
||||
updateActiveStateFromRoute() {
|
||||
const activeRoute = this.router.isActive(this.item.routerLink[0], {
|
||||
paths: 'exact',
|
||||
queryParams: 'ignored',
|
||||
matrixParams: 'ignored',
|
||||
fragment: 'ignored'
|
||||
});
|
||||
if (activeRoute) {
|
||||
this.menuService.onMenuStateChange({key: this.key, routeEvent: true});
|
||||
}
|
||||
}
|
||||
|
||||
itemClick(event: Event) {
|
||||
if (this.item.disabled) {
|
||||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
if (this.item.command) {
|
||||
this.item.command({originalEvent: event, item: this.item});
|
||||
}
|
||||
if (this.item.items) {
|
||||
this.active = !this.active;
|
||||
} else {
|
||||
this.active = true;
|
||||
}
|
||||
this.menuService.onMenuStateChange({key: this.key});
|
||||
}
|
||||
|
||||
openDialog(item: any) {
|
||||
if (item.type === 'library' && this.canManipulateLibrary) {
|
||||
this.dialogLauncher.openLibraryCreateDialog();
|
||||
}
|
||||
if (item.type === 'magicShelf') {
|
||||
this.dialogLauncher.openMagicShelfCreateDialog();
|
||||
}
|
||||
if (item.type === 'shelf') {
|
||||
this.bookDialogHelperService.openShelfCreatorDialog();
|
||||
}
|
||||
}
|
||||
|
||||
triggerLink() {
|
||||
if (this.item.routerLink && !this.item.items && this.linkRef) {
|
||||
this.linkRef.nativeElement.click();
|
||||
}
|
||||
}
|
||||
|
||||
formatCount(count: number | null | undefined): string {
|
||||
if (count == null) return '0';
|
||||
if (count >= 1000) return Math.floor(count / 1000) + 'K';
|
||||
return count.toString();
|
||||
}
|
||||
|
||||
getIconSelection(): IconSelection | null {
|
||||
if (!this.item.icon) return null;
|
||||
|
||||
return {
|
||||
type: this.item.iconType || 'PRIME_NG',
|
||||
value: this.item.icon
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Subject } from 'rxjs';
|
||||
import { MenuChangeEvent } from '../../../api/menuchangeevent';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class MenuService {
|
||||
|
||||
private menuSource = new Subject<MenuChangeEvent>();
|
||||
private resetSource = new Subject();
|
||||
|
||||
menuSource$ = this.menuSource.asObservable();
|
||||
resetSource$ = this.resetSource.asObservable();
|
||||
|
||||
onMenuStateChange(event: MenuChangeEvent) {
|
||||
this.menuSource.next(event);
|
||||
}
|
||||
|
||||
reset() {
|
||||
this.resetSource.next(true);
|
||||
}
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
<ng-container *transloco="let t; prefix: 'layout.changelog'">
|
||||
<div class="changelog-container">
|
||||
<div class="panel-header">
|
||||
<div class="header-icon-wrapper">
|
||||
<i class="pi pi-sparkles header-icon"></i>
|
||||
</div>
|
||||
<div class="header-text">
|
||||
<h2 class="panel-title">{{ t('title') }}</h2>
|
||||
<p class="panel-description">{{ t('description') }}</p>
|
||||
</div>
|
||||
<p-button
|
||||
icon="pi pi-times"
|
||||
[rounded]="true"
|
||||
[text]="true"
|
||||
severity="secondary"
|
||||
(click)="dialogRef.close()"
|
||||
class="close-button">
|
||||
</p-button>
|
||||
</div>
|
||||
|
||||
<div class="dialog-content">
|
||||
@if (loading) {
|
||||
<div class="loading-state">
|
||||
{{ t('loading') }}
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (!loading && changelog.length === 0) {
|
||||
<div class="empty-state">
|
||||
{{ t('empty') }}
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (!loading && changelog.length > 0) {
|
||||
<div class="changelog-list">
|
||||
@for (release of changelog; track release) {
|
||||
<div class="release-item">
|
||||
<p class="release-title">
|
||||
<a [href]="release.url" target="_blank" rel="noopener noreferrer" class="release-link">
|
||||
{{ release.name }} ({{ release.publishedAt | date: 'mediumDate' }})
|
||||
</a>
|
||||
</p>
|
||||
<div [innerHTML]="markdownToHtml(release.changelog)" class="release-content"></div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
+139
@@ -0,0 +1,139 @@
|
||||
@use '../../../../../shared/styles/panel-shared' as panel;
|
||||
|
||||
.changelog-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
max-height: 90dvh;
|
||||
}
|
||||
|
||||
.panel-header {
|
||||
@include panel.panel-header;
|
||||
}
|
||||
|
||||
.dialog-content {
|
||||
padding: 1.5rem;
|
||||
background: var(--card-background);
|
||||
border: 1px solid var(--border-color);
|
||||
border-top: none;
|
||||
border-radius: 0 0 10px 10px;
|
||||
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
|
||||
overflow-y: auto;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.loading-state,
|
||||
.empty-state {
|
||||
padding: 1rem;
|
||||
text-align: center;
|
||||
color: var(--text-secondary-color);
|
||||
}
|
||||
|
||||
.changelog-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1.5rem;
|
||||
}
|
||||
|
||||
.release-item {
|
||||
padding-bottom: 1rem;
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
|
||||
&:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
}
|
||||
|
||||
.release-title {
|
||||
font-weight: 700;
|
||||
font-size: 1.25rem;
|
||||
padding-bottom: 0.5rem;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.release-link {
|
||||
color: var(--primary-color);
|
||||
text-decoration: none;
|
||||
|
||||
&:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
}
|
||||
|
||||
.release-content {
|
||||
width: 100%;
|
||||
max-width: 100%;
|
||||
line-height: 1.75;
|
||||
color: var(--text-color);
|
||||
|
||||
:host ::ng-deep & {
|
||||
h1, h2, h3, h4, h5, h6 {
|
||||
margin-top: 1.5rem;
|
||||
margin-bottom: 0.75rem;
|
||||
font-weight: 600;
|
||||
line-height: 1.25;
|
||||
color: var(--text-color);
|
||||
|
||||
&:first-child {
|
||||
margin-top: 0;
|
||||
}
|
||||
}
|
||||
|
||||
h3 {
|
||||
margin-top: 0;
|
||||
font-size: 1.125rem;
|
||||
}
|
||||
|
||||
p {
|
||||
margin-top: 0.75rem;
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
|
||||
ul, ol {
|
||||
margin-top: 0.75rem;
|
||||
margin-bottom: 0.75rem;
|
||||
padding-left: 1.5rem;
|
||||
}
|
||||
|
||||
li {
|
||||
margin-top: 0.25rem;
|
||||
margin-bottom: 0.25rem;
|
||||
}
|
||||
|
||||
code {
|
||||
font-size: 0.875em;
|
||||
background: var(--surface-ground);
|
||||
padding: 0.125rem 0.375rem;
|
||||
border-radius: 0.25rem;
|
||||
}
|
||||
|
||||
pre {
|
||||
margin-top: 1rem;
|
||||
margin-bottom: 1rem;
|
||||
padding: 1rem;
|
||||
background: var(--surface-ground);
|
||||
border-radius: 0.5rem;
|
||||
overflow-x: auto;
|
||||
|
||||
code {
|
||||
background: transparent;
|
||||
padding: 0;
|
||||
}
|
||||
}
|
||||
|
||||
a {
|
||||
color: var(--primary-color);
|
||||
text-decoration: underline;
|
||||
|
||||
&:hover {
|
||||
text-decoration: none;
|
||||
}
|
||||
}
|
||||
|
||||
blockquote {
|
||||
margin: 1rem 0;
|
||||
padding-left: 1rem;
|
||||
border-left: 3px solid var(--border-color);
|
||||
color: var(--text-secondary-color);
|
||||
}
|
||||
}
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
import { Component, inject, OnInit } from '@angular/core';
|
||||
import { ReleaseNote, VersionService } from '../../../../service/version.service';
|
||||
|
||||
import showdown from 'showdown';
|
||||
import DOMPurify from 'dompurify';
|
||||
import {DatePipe} from '@angular/common';
|
||||
import {DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {Button} from 'primeng/button';
|
||||
import {TranslocoDirective} from '@jsverse/transloco';
|
||||
|
||||
@Component({
|
||||
selector: 'app-version-changelog-dialog',
|
||||
standalone: true,
|
||||
imports: [
|
||||
DatePipe,
|
||||
Button,
|
||||
TranslocoDirective
|
||||
],
|
||||
templateUrl: './version-changelog-dialog.component.html',
|
||||
styleUrl: './version-changelog-dialog.component.scss'
|
||||
})
|
||||
export class VersionChangelogDialogComponent implements OnInit {
|
||||
|
||||
private versionService = inject(VersionService);
|
||||
dialogRef = inject(DynamicDialogRef);
|
||||
|
||||
changelog: ReleaseNote[] = [];
|
||||
loading = true;
|
||||
|
||||
private converter = new showdown.Converter({ tables: true, emoji: true });
|
||||
|
||||
ngOnInit(): void {
|
||||
this.versionService.getChangelog().subscribe({
|
||||
next: (data) => {
|
||||
this.changelog = data;
|
||||
this.loading = false;
|
||||
},
|
||||
error: () => {
|
||||
this.loading = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
markdownToHtml(markdown: string): string {
|
||||
let html = this.converter.makeHtml(markdown);
|
||||
html = html.replace(/<h2\b([^>]*)>/g, '<h3$1>').replace(/<\/h2>/g, '</h3>');
|
||||
return DOMPurify.sanitize(html);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user