feat(ui): add enhanced user popover + rearrange sidebar (#1246)
Co-authored-by: brios <127139797+balazs-szucs@users.noreply.github.com>
This commit is contained in:
@@ -71,6 +71,20 @@
|
||||
[positions]="mobileMenuPositions"
|
||||
></app-menu>
|
||||
|
||||
@if (canUploadBooks()) {
|
||||
<button
|
||||
type="button"
|
||||
class="sidebar-icon-button sidebar-mobile-landscape-action"
|
||||
[attr.aria-label]="t('uploadBook')"
|
||||
[pTooltip]="t('uploadBook')"
|
||||
[tooltipDisabled]="!layoutService.isDesktop()"
|
||||
tooltipPosition="bottom"
|
||||
(click)="openUploadDialog()"
|
||||
>
|
||||
<i class="pi pi-upload" aria-hidden="true"></i>
|
||||
</button>
|
||||
}
|
||||
|
||||
<button
|
||||
type="button"
|
||||
class="sidebar-icon-button sidebar-mobile-landscape-action"
|
||||
@@ -85,29 +99,6 @@
|
||||
<i class="pi pi-bell" aria-hidden="true"></i>
|
||||
</button>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
ngMenuTrigger
|
||||
#moreMobileTrigger="ngMenuTrigger"
|
||||
#moreMobileOrigin
|
||||
[menu]="moreMobileMenu.menuRef()"
|
||||
class="sidebar-icon-button sidebar-mobile-landscape-action"
|
||||
[attr.aria-label]="t('more')"
|
||||
[pTooltip]="t('more')"
|
||||
[tooltipDisabled]="!layoutService.isDesktop()"
|
||||
tooltipPosition="bottom"
|
||||
>
|
||||
<i class="pi pi-ellipsis-h" aria-hidden="true"></i>
|
||||
</button>
|
||||
|
||||
<app-menu
|
||||
#moreMobileMenu="appMenu"
|
||||
[origin]="moreMobileOrigin"
|
||||
[open]="moreMobileTrigger.expanded()"
|
||||
[items]="moreMenuItems()"
|
||||
[positions]="mobileMenuPositions"
|
||||
></app-menu>
|
||||
|
||||
<p-popover #notificationsPopover appendTo="body" styleClass="sidebar-flyout-popover" (onShow)="notificationsOpen.set(true); applySidebarOverlayPosition(notificationsPopover)" (onHide)="notificationsOpen.set(false)">
|
||||
<app-unified-notification-popover-component></app-unified-notification-popover-component>
|
||||
</p-popover>
|
||||
@@ -115,23 +106,16 @@
|
||||
@if (currentUser(); as user) {
|
||||
<button
|
||||
type="button"
|
||||
ngMenuTrigger
|
||||
#userMobileTrigger="ngMenuTrigger"
|
||||
#userMobileOrigin
|
||||
[menu]="userMobileMenu.menuRef()"
|
||||
cdkOverlayOrigin
|
||||
#userMobileOrigin="cdkOverlayOrigin"
|
||||
class="sidebar-icon-button sidebar-mobile-user-button"
|
||||
[attr.aria-label]="t('profile')"
|
||||
aria-haspopup="dialog"
|
||||
[attr.aria-expanded]="userPopoverOpen() ? 'true' : 'false'"
|
||||
(click)="toggleUserPopover(userMobileOrigin)"
|
||||
>
|
||||
<span class="sidebar-user-avatar" aria-hidden="true">{{ userInitials() }}</span>
|
||||
</button>
|
||||
|
||||
<app-menu
|
||||
#userMobileMenu="appMenu"
|
||||
[origin]="userMobileOrigin"
|
||||
[open]="userMobileTrigger.expanded()"
|
||||
[items]="userMenuItems()"
|
||||
[positions]="mobileMenuPositions"
|
||||
></app-menu>
|
||||
}
|
||||
|
||||
<button
|
||||
@@ -193,6 +177,21 @@
|
||||
[positions]="footerMenuPositions()"
|
||||
></app-menu>
|
||||
|
||||
@if (canUploadBooks()) {
|
||||
<button
|
||||
type="button"
|
||||
class="sidebar-action-link sidebar-footer-action"
|
||||
[attr.aria-label]="t('uploadBook')"
|
||||
[pTooltip]="t('uploadBook')"
|
||||
[tooltipDisabled]="!layoutService.isDesktop()"
|
||||
tooltipPosition="top"
|
||||
(click)="openUploadDialog()"
|
||||
>
|
||||
<i class="pi pi-upload" aria-hidden="true"></i>
|
||||
<span>{{ t('uploadBook') }}</span>
|
||||
</button>
|
||||
}
|
||||
|
||||
<button
|
||||
type="button"
|
||||
class="sidebar-action-link sidebar-footer-action"
|
||||
@@ -206,43 +205,21 @@
|
||||
<span>{{ t('notifications') }}</span>
|
||||
</button>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
ngMenuTrigger
|
||||
#moreFooterTrigger="ngMenuTrigger"
|
||||
#moreFooterOrigin
|
||||
[menu]="moreFooterMenu.menuRef()"
|
||||
class="sidebar-action-link sidebar-footer-action"
|
||||
[attr.aria-label]="t('more')"
|
||||
[pTooltip]="t('more')"
|
||||
[tooltipDisabled]="!layoutService.isDesktop()"
|
||||
tooltipPosition="top"
|
||||
>
|
||||
<i class="pi pi-ellipsis-h" aria-hidden="true"></i>
|
||||
<span>{{ t('more') }}</span>
|
||||
</button>
|
||||
|
||||
<app-menu
|
||||
#moreFooterMenu="appMenu"
|
||||
[origin]="moreFooterOrigin"
|
||||
[open]="moreFooterTrigger.expanded()"
|
||||
[items]="moreMenuItems()"
|
||||
[positions]="footerMenuPositions()"
|
||||
></app-menu>
|
||||
</div>
|
||||
@if (currentUser(); as user) {
|
||||
<div class="sidebar-footer-bottom">
|
||||
<button
|
||||
type="button"
|
||||
ngMenuTrigger
|
||||
#userFooterTrigger="ngMenuTrigger"
|
||||
#userFooterOrigin
|
||||
[menu]="userFooterMenu.menuRef()"
|
||||
cdkOverlayOrigin
|
||||
#userFooterOrigin="cdkOverlayOrigin"
|
||||
class="sidebar-user-trigger"
|
||||
[attr.aria-label]="t('profile')"
|
||||
[pTooltip]="user.name || user.username"
|
||||
[tooltipDisabled]="!layoutService.desktopSidebarCollapsed()"
|
||||
tooltipPosition="right"
|
||||
aria-haspopup="dialog"
|
||||
[attr.aria-expanded]="userPopoverOpen() ? 'true' : 'false'"
|
||||
(click)="toggleUserPopover(userFooterOrigin)"
|
||||
>
|
||||
<span class="sidebar-user-avatar" aria-hidden="true">{{ userInitials() }}</span>
|
||||
<span class="sidebar-user-meta">
|
||||
@@ -271,14 +248,6 @@
|
||||
></i>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<app-menu
|
||||
#userFooterMenu="appMenu"
|
||||
[origin]="userFooterOrigin"
|
||||
[open]="userFooterTrigger.expanded()"
|
||||
[items]="userMenuItems()"
|
||||
[positions]="aboveMenuPositions"
|
||||
></app-menu>
|
||||
} @else {
|
||||
<div class="sidebar-footer-bottom">
|
||||
<button
|
||||
@@ -301,5 +270,99 @@
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@if (currentUser(); as user) {
|
||||
@if (userPopoverOrigin(); as userOrigin) {
|
||||
<ng-template
|
||||
cdkConnectedOverlay
|
||||
[cdkConnectedOverlayOrigin]="userOrigin"
|
||||
[cdkConnectedOverlayOpen]="userPopoverOpen()"
|
||||
[cdkConnectedOverlayPositions]="aboveMenuPositions"
|
||||
[cdkConnectedOverlayViewportMargin]="8"
|
||||
[cdkConnectedOverlayPush]="true"
|
||||
[cdkConnectedOverlayFlexibleDimensions]="true"
|
||||
[cdkConnectedOverlayHasBackdrop]="true"
|
||||
cdkConnectedOverlayBackdropClass="cdk-overlay-transparent-backdrop"
|
||||
cdkConnectedOverlayPanelClass="user-account-popover-pane"
|
||||
(backdropClick)="closeUserPopover()"
|
||||
(detach)="closeUserPopover()"
|
||||
(overlayKeydown)="onUserPopoverKeydown($event)"
|
||||
>
|
||||
<section
|
||||
class="user-account-popover"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
cdkTrapFocus
|
||||
cdkTrapFocusAutoCapture
|
||||
[attr.aria-label]="'settingsProfile.title' | transloco"
|
||||
>
|
||||
<header class="user-account-popover-header">
|
||||
<div class="user-account-popover-title-row">
|
||||
<h2>Grimmory <span>{{ appVersionLabel() }}</span></h2>
|
||||
<button
|
||||
type="button"
|
||||
class="user-account-popover-icon-button"
|
||||
cdkFocusInitial
|
||||
[attr.aria-label]="t('documentation')"
|
||||
(click)="openDocumentation()"
|
||||
>
|
||||
<i class="pi pi-question-circle" aria-hidden="true"></i>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="user-account-popover-header-actions">
|
||||
<button
|
||||
type="button"
|
||||
class="user-account-popover-settings"
|
||||
(click)="openSettings()"
|
||||
>
|
||||
<i class="pi pi-cog" aria-hidden="true"></i>
|
||||
<span>{{ t('settings') }}</span>
|
||||
</button>
|
||||
|
||||
@if (updateAvailable()) {
|
||||
<button
|
||||
type="button"
|
||||
class="user-account-popover-update"
|
||||
(click)="openChangelogDialog()"
|
||||
>
|
||||
<i class="pi pi-arrow-up-right" aria-hidden="true"></i>
|
||||
<span>{{ t('updateAvailable') }}</span>
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="user-account-popover-body">
|
||||
@if (!user.permissions.demoUser) {
|
||||
<button type="button" class="menu-item user-account-popover-action" (click)="openAccountSettings()">
|
||||
<i class="pi pi-user-edit" aria-hidden="true"></i>
|
||||
<span>{{ 'settingsProfile.title' | transloco }}</span>
|
||||
</button>
|
||||
}
|
||||
|
||||
@if (canAccessReadingStats()) {
|
||||
<button
|
||||
type="button"
|
||||
class="menu-item user-account-popover-action"
|
||||
(click)="openReadingStats()"
|
||||
>
|
||||
<i class="pi pi-chart-bar" aria-hidden="true"></i>
|
||||
<span>{{ t('readingStats') }}</span>
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
|
||||
<footer class="user-account-popover-footer">
|
||||
<button type="button" class="menu-item user-account-popover-logout" (click)="logout()">
|
||||
<i class="pi pi-sign-out" aria-hidden="true"></i>
|
||||
<span>{{ t('logout') }}</span>
|
||||
</button>
|
||||
</footer>
|
||||
</section>
|
||||
</ng-template>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
|
||||
</ng-container>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { computed, signal, WritableSignal } from '@angular/core';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { BehaviorSubject } from 'rxjs';
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import { getTranslocoModule } from '../../../core/testing/transloco-testing';
|
||||
@@ -15,6 +16,7 @@ import { SeriesDataService } from '../../../features/series-browser/service/seri
|
||||
import { UserService } from '../../../features/settings/user-management/user.service';
|
||||
import { CommandPaletteService } from '../../../features/command-palette/command-palette.service';
|
||||
import { AuthService } from '../../service/auth.service';
|
||||
import { AppVersion, VersionService } from '../../service/version.service';
|
||||
import { DialogLauncherService } from '../../services/dialog-launcher.service';
|
||||
import { LayoutService } from '../layout.service';
|
||||
|
||||
@@ -50,6 +52,7 @@ describe('AppSidebarComponent', () => {
|
||||
let component: AppSidebarComponent;
|
||||
let commandPaletteService: { open: ReturnType<typeof vi.fn> };
|
||||
let currentUser: WritableSignal<TestUser | null>;
|
||||
let versionInfo: BehaviorSubject<AppVersion>;
|
||||
const sidebarCollapsed = signal(false);
|
||||
const isDesktop = signal(true);
|
||||
const layoutService = {
|
||||
@@ -65,6 +68,7 @@ describe('AppSidebarComponent', () => {
|
||||
beforeEach(() => {
|
||||
commandPaletteService = { open: vi.fn() };
|
||||
currentUser = signal<TestUser | null>(null);
|
||||
versionInfo = new BehaviorSubject<AppVersion>({ current: '1.2.3', latest: '1.2.3' });
|
||||
|
||||
TestBed.configureTestingModule({
|
||||
imports: [AppSidebarComponent, getTranslocoModule()],
|
||||
@@ -92,6 +96,7 @@ describe('AppSidebarComponent', () => {
|
||||
{ provide: CommandPaletteService, useValue: commandPaletteService },
|
||||
{ provide: BookDialogHelperService, useValue: { openShelfCreatorDialog: vi.fn() } },
|
||||
{ provide: AuthService, useValue: { logout: vi.fn() } },
|
||||
{ provide: VersionService, useValue: { getVersion: vi.fn(() => versionInfo) } },
|
||||
{ provide: LayoutService, useValue: layoutService },
|
||||
{ provide: UserService, useValue: { currentUser } },
|
||||
{ provide: MagicShelfService, useValue: { shelves: signal([]), bookCountByMagicShelfId: signal(new Map()) } },
|
||||
@@ -182,6 +187,32 @@ describe('AppSidebarComponent', () => {
|
||||
expect(component.userInitials()).toBe('');
|
||||
});
|
||||
|
||||
it('normalizes semantic version labels with or without a leading v', () => {
|
||||
const sidebar = component as unknown as { appVersionLabel: () => string };
|
||||
|
||||
versionInfo.next({ current: '1.2.3', latest: '1.2.3' });
|
||||
expect(sidebar.appVersionLabel()).toBe('v1.2.3');
|
||||
|
||||
versionInfo.next({ current: 'v1.2.3', latest: '1.2.3' });
|
||||
expect(sidebar.appVersionLabel()).toBe('v1.2.3');
|
||||
|
||||
versionInfo.next({ current: 'development', latest: 'v1.2.3' });
|
||||
expect(sidebar.appVersionLabel()).toBe('development');
|
||||
});
|
||||
|
||||
it('compares update versions numerically after normalizing a leading v', () => {
|
||||
const sidebar = component as unknown as { updateAvailable: () => boolean };
|
||||
|
||||
versionInfo.next({ current: '1.2.3', latest: 'v1.2.3' });
|
||||
expect(sidebar.updateAvailable()).toBe(false);
|
||||
|
||||
versionInfo.next({ current: 'v1.10.0', latest: 'v1.2.0' });
|
||||
expect(sidebar.updateAvailable()).toBe(false);
|
||||
|
||||
versionInfo.next({ current: '1.2.3', latest: 'v1.2.4' });
|
||||
expect(sidebar.updateAvailable()).toBe(true);
|
||||
});
|
||||
|
||||
it('anchors notifications above the trigger and keeps them inside the viewport on mobile', () => {
|
||||
layoutService.isDesktop.set(false);
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import { Component, Renderer2, RendererStyleFlags2, computed, inject, signal } from '@angular/core';
|
||||
import { RouterLink } from '@angular/router';
|
||||
import { Router, RouterLink } from '@angular/router';
|
||||
import { AppSidebarSectionComponent } from './app.sidebar-section.component';
|
||||
import { MenuTrigger } from '@angular/aria/menu';
|
||||
import { Popover } from 'primeng/popover';
|
||||
import { CdkTrapFocus } from '@angular/cdk/a11y';
|
||||
import { CdkConnectedOverlay, CdkOverlayOrigin } from '@angular/cdk/overlay';
|
||||
import { BookDialogHelperService } from '../../../features/book/components/book-browser/book-dialog-helper.service';
|
||||
import { UnifiedNotificationBoxComponent } from '../../components/unified-notification-popover/unified-notification-popover-component';
|
||||
import { MenuComponent } from '../../components/menu/menu.component';
|
||||
@@ -29,13 +31,15 @@ import { TranslocoDirective, TranslocoPipe, TranslocoService } from '@jsverse/tr
|
||||
import { Tooltip } from 'primeng/tooltip';
|
||||
import { toSignal } from '@angular/core/rxjs-interop';
|
||||
import { NavItem, SidebarSection } from '../navigation/nav-item.model';
|
||||
import { buildQuickActionNavItems, findPageNavItem } from '../navigation/nav-catalog';
|
||||
import { buildCreateActionNavItems } from '../navigation/nav-catalog';
|
||||
import {
|
||||
buildHomeSection,
|
||||
buildLibrarySection,
|
||||
buildMagicShelfSection,
|
||||
buildShelfSection,
|
||||
buildToolsSection,
|
||||
} from './sidebar-sections';
|
||||
import { VersionService } from '../../service/version.service';
|
||||
|
||||
const DOCUMENTATION_URL = 'https://grimmory.org/docs/getting-started';
|
||||
|
||||
@@ -53,6 +57,34 @@ function detectSearchShortcut(userAgent: string): string {
|
||||
return /Mac|iPhone|iPad|iPod/i.test(userAgent) ? '⌘K' : 'Ctrl+K';
|
||||
}
|
||||
|
||||
type SemanticVersion = readonly [number, number, number];
|
||||
|
||||
function parseSemanticVersion(version: string | undefined): SemanticVersion | null {
|
||||
const match = /^v?(\d+)\.(\d+)\.(\d+)$/.exec(version?.trim() ?? '');
|
||||
return match ? [Number(match[1]), Number(match[2]), Number(match[3])] : null;
|
||||
}
|
||||
|
||||
function formatVersionLabel(version: string): string {
|
||||
const value = version.trim();
|
||||
if (!value) return 'unknown';
|
||||
const semanticVersion = parseSemanticVersion(value);
|
||||
return semanticVersion ? `v${semanticVersion.join('.')}` : value;
|
||||
}
|
||||
|
||||
function isSemanticVersion(version: string | undefined): boolean {
|
||||
return parseSemanticVersion(version) !== null;
|
||||
}
|
||||
|
||||
function isNewerVersion(latest: string | undefined, current: string | undefined): boolean {
|
||||
const latestVersion = parseSemanticVersion(latest);
|
||||
const currentVersion = parseSemanticVersion(current);
|
||||
if (!latestVersion || !currentVersion) return false;
|
||||
|
||||
if (latestVersion[0] !== currentVersion[0]) return latestVersion[0] > currentVersion[0];
|
||||
if (latestVersion[1] !== currentVersion[1]) return latestVersion[1] > currentVersion[1];
|
||||
return latestVersion[2] > currentVersion[2];
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-sidebar',
|
||||
imports: [
|
||||
@@ -65,6 +97,9 @@ function detectSearchShortcut(userAgent: string): string {
|
||||
TranslocoPipe,
|
||||
Tooltip,
|
||||
MenuTrigger,
|
||||
CdkTrapFocus,
|
||||
CdkConnectedOverlay,
|
||||
CdkOverlayOrigin,
|
||||
],
|
||||
templateUrl: './app.sidebar.component.html',
|
||||
styleUrl: './app.sidebar.component.scss',
|
||||
@@ -79,8 +114,10 @@ export class AppSidebarComponent {
|
||||
private readonly commandPaletteService = inject(CommandPaletteService);
|
||||
private readonly bookDialogHelperService = inject(BookDialogHelperService);
|
||||
private readonly authService = inject(AuthService);
|
||||
private readonly router = inject(Router);
|
||||
readonly layoutService = inject(LayoutService);
|
||||
private readonly userService = inject(UserService);
|
||||
private readonly versionService = inject(VersionService);
|
||||
private readonly magicShelfService = inject(MagicShelfService);
|
||||
private readonly seriesDataService = inject(SeriesDataService);
|
||||
private readonly authorService = inject(AuthorService);
|
||||
@@ -89,8 +126,26 @@ export class AppSidebarComponent {
|
||||
|
||||
readonly currentUser = this.userService.currentUser;
|
||||
private readonly allAuthors = this.authorService.allAuthors;
|
||||
private readonly activeLang = toSignal(this.t.langChanges$, { initialValue: this.t.getActiveLang() });
|
||||
protected readonly activeLang = toSignal(this.t.langChanges$, { initialValue: this.t.getActiveLang() });
|
||||
protected readonly versionInfo = toSignal(this.versionService.getVersion(), { initialValue: null });
|
||||
protected readonly appVersionLabel = computed(() => formatVersionLabel(this.versionInfo()?.current ?? '...'));
|
||||
protected readonly updateAvailable = computed(() => {
|
||||
const version = this.versionInfo();
|
||||
return isSemanticVersion(version?.current)
|
||||
&& isSemanticVersion(version?.latest)
|
||||
&& isNewerVersion(version?.latest, version?.current);
|
||||
});
|
||||
private readonly translate = (key: string): string => this.t.translate(key);
|
||||
protected readonly userPopoverOpen = signal(false);
|
||||
protected readonly userPopoverOrigin = signal<CdkOverlayOrigin | null>(null);
|
||||
protected readonly canAccessReadingStats = computed(() => {
|
||||
const user = this.currentUser();
|
||||
return !!user && (user.permissions.admin || user.permissions.canAccessUserStats);
|
||||
});
|
||||
protected readonly canUploadBooks = computed(() => {
|
||||
const user = this.currentUser();
|
||||
return !!user && (user.permissions.admin || user.permissions.canUpload);
|
||||
});
|
||||
|
||||
readonly searchShortcutLabel = detectSearchShortcut(
|
||||
typeof navigator !== 'undefined' ? navigator.userAgent : ''
|
||||
@@ -126,6 +181,7 @@ export class AppSidebarComponent {
|
||||
this.translate,
|
||||
{ menuItems: this.libraryShelfMenuService },
|
||||
),
|
||||
...buildToolsSection(this.translate, this.currentUser()?.permissions ?? {}),
|
||||
];
|
||||
});
|
||||
|
||||
@@ -134,14 +190,13 @@ export class AppSidebarComponent {
|
||||
const user = this.currentUser();
|
||||
if (!user) return [];
|
||||
|
||||
const actions = buildQuickActionNavItems(this.translate, user.permissions, {
|
||||
const actions = buildCreateActionNavItems(this.translate, user.permissions, {
|
||||
createLibrary: () => this.dialogLauncherService.openLibraryCreateDialog(),
|
||||
createShelf: () => this.bookDialogHelperService.openShelfCreatorDialog(),
|
||||
createMagicShelf: () => this.dialogLauncherService.openMagicShelfCreateDialog(),
|
||||
uploadBook: () => this.dialogLauncherService.openFileUploadDialog(),
|
||||
});
|
||||
const bookdrop = findPageNavItem('bookdrop', this.translate, user.permissions);
|
||||
return this.toMenuEntries(bookdrop ? [...actions, bookdrop] : actions);
|
||||
return this.toMenuEntries(actions);
|
||||
});
|
||||
|
||||
readonly userInitials = computed(() => {
|
||||
@@ -157,52 +212,6 @@ export class AppSidebarComponent {
|
||||
this.layoutService.desktopSidebarCollapsed() ? BESIDE_RIGHT_BOTTOM : ABOVE_ALIGN_LEFT,
|
||||
);
|
||||
|
||||
readonly userMenuItems = computed<MenuEntry[]>(() => {
|
||||
this.activeLang();
|
||||
const user = this.currentUser();
|
||||
if (!user) return [];
|
||||
|
||||
const items: MenuEntry[] = [];
|
||||
|
||||
if (!user.permissions.demoUser) {
|
||||
items.push({
|
||||
label: this.t.translate('layout.menu.account'),
|
||||
icon: 'pi pi-user',
|
||||
action: () => this.dialogLauncherService.openUserProfileDialog(),
|
||||
});
|
||||
}
|
||||
|
||||
items.push({
|
||||
label: this.t.translate('layout.menu.documentation'),
|
||||
icon: 'pi pi-info-circle',
|
||||
action: () => window.open(DOCUMENTATION_URL, '_blank', 'noopener,noreferrer'),
|
||||
});
|
||||
|
||||
items.push({ separator: true });
|
||||
|
||||
items.push({
|
||||
label: this.t.translate('layout.menu.logout'),
|
||||
icon: 'pi pi-sign-out',
|
||||
action: () => this.authService.logout(),
|
||||
});
|
||||
|
||||
return items;
|
||||
});
|
||||
|
||||
readonly moreMenuItems = computed<MenuEntry[]>(() => {
|
||||
this.activeLang();
|
||||
const user = this.currentUser();
|
||||
if (!user) return [];
|
||||
|
||||
const perms = user.permissions;
|
||||
return this.toMenuEntries([
|
||||
findPageNavItem('settings', this.translate, perms),
|
||||
findPageNavItem('libraryStats', this.translate, perms),
|
||||
findPageNavItem('readingStats', this.translate, perms),
|
||||
findPageNavItem('metadataManager', this.translate, perms),
|
||||
]);
|
||||
});
|
||||
|
||||
openSearch(): void {
|
||||
this.commandPaletteService.open();
|
||||
}
|
||||
@@ -211,6 +220,61 @@ export class AppSidebarComponent {
|
||||
this.layoutService.closeMobileSidebar();
|
||||
}
|
||||
|
||||
protected toggleUserPopover(origin: CdkOverlayOrigin): void {
|
||||
if (this.userPopoverOpen() && this.userPopoverOrigin() === origin) {
|
||||
this.closeUserPopover();
|
||||
return;
|
||||
}
|
||||
|
||||
this.userPopoverOrigin.set(origin);
|
||||
this.userPopoverOpen.set(true);
|
||||
}
|
||||
|
||||
protected closeUserPopover(): void {
|
||||
this.userPopoverOpen.set(false);
|
||||
}
|
||||
|
||||
protected openDocumentation(): void {
|
||||
window.open(DOCUMENTATION_URL, '_blank', 'noopener,noreferrer');
|
||||
this.closeUserPopover();
|
||||
}
|
||||
|
||||
protected openAccountSettings(): void {
|
||||
this.dialogLauncherService.openUserProfileDialog();
|
||||
this.closeUserPopover();
|
||||
}
|
||||
|
||||
protected openSettings(): void {
|
||||
this.router.navigate(['/settings']);
|
||||
this.closeUserPopover();
|
||||
}
|
||||
|
||||
protected openChangelogDialog(): void {
|
||||
this.dialogLauncherService.openVersionChangelogDialog();
|
||||
this.closeUserPopover();
|
||||
}
|
||||
|
||||
protected openReadingStats(): void {
|
||||
this.router.navigate(['/reading-stats']);
|
||||
this.closeUserPopover();
|
||||
}
|
||||
|
||||
protected openUploadDialog(): void {
|
||||
this.dialogLauncherService.openFileUploadDialog();
|
||||
}
|
||||
|
||||
protected logout(): void {
|
||||
this.authService.logout();
|
||||
this.closeUserPopover();
|
||||
}
|
||||
|
||||
protected onUserPopoverKeydown(event: KeyboardEvent): void {
|
||||
if (event.key === 'Escape') {
|
||||
event.preventDefault();
|
||||
this.closeUserPopover();
|
||||
}
|
||||
}
|
||||
|
||||
private readonly anchorByOverlay = new WeakMap<Popover, { trigger: HTMLElement; placement: 'above' | 'below' }>();
|
||||
|
||||
protected applySidebarOverlayPosition(overlay: Popover): void {
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
buildLibrarySection,
|
||||
buildMagicShelfSection,
|
||||
buildShelfSection,
|
||||
buildToolsSection,
|
||||
} from './sidebar-sections';
|
||||
|
||||
const translate = (key: string): string => key;
|
||||
@@ -69,6 +70,29 @@ describe('buildHomeSection', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('buildToolsSection', () => {
|
||||
it('returns no section when the user has no tool permissions', () => {
|
||||
expect(buildToolsSection(translate, {})).toEqual([]);
|
||||
});
|
||||
|
||||
it('builds a permission-gated tools section', () => {
|
||||
const [section] = buildToolsSection(translate, {
|
||||
canAccessLibraryStats: true,
|
||||
canEditMetadata: true,
|
||||
canAccessBookdrop: true,
|
||||
canAccessUserStats: true,
|
||||
});
|
||||
|
||||
expect(section.id).toBe('tools');
|
||||
expect(section.expandable).toBe(true);
|
||||
expect(section.items.map((item) => item.id)).toEqual([
|
||||
'libraryStats',
|
||||
'metadataManager',
|
||||
'bookdrop',
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('buildLibrarySection', () => {
|
||||
it('returns no section when no libraries are persisted', () => {
|
||||
expect(buildLibrarySection([], new Map(), { field: 'name', order: 'asc' }, translate, libraryDeps)).toEqual([]);
|
||||
|
||||
@@ -6,7 +6,7 @@ import { LibraryShelfMenuService } from '../../../features/book/service/library-
|
||||
import { SortPref } from '../sidebar-sort-preferences';
|
||||
|
||||
import { SidebarLeaf, SidebarSection } from '../navigation/nav-item.model';
|
||||
import { buildHomeNavItems } from '../navigation/nav-catalog';
|
||||
import { buildHomeNavItems, findPageNavItem, ShellNavPermissions } from '../navigation/nav-catalog';
|
||||
|
||||
export interface HomeCounts {
|
||||
allBooks: number;
|
||||
@@ -60,6 +60,27 @@ export function buildHomeSection(translate: TranslateFn, counts: HomeCounts): Si
|
||||
}];
|
||||
}
|
||||
|
||||
export function buildToolsSection(
|
||||
translate: TranslateFn,
|
||||
permissions: ShellNavPermissions,
|
||||
): SidebarSection[] {
|
||||
const items = [
|
||||
findPageNavItem('libraryStats', translate, permissions),
|
||||
findPageNavItem('metadataManager', translate, permissions),
|
||||
findPageNavItem('bookdrop', translate, permissions),
|
||||
].filter((item): item is SidebarLeaf => !!item);
|
||||
|
||||
if (items.length === 0) return [];
|
||||
|
||||
return [{
|
||||
id: 'tools',
|
||||
menuKey: 'tools',
|
||||
label: translate('layout.menu.tools'),
|
||||
expandable: true,
|
||||
items,
|
||||
}];
|
||||
}
|
||||
|
||||
function homeItemBookCount(itemId: string, counts: HomeCounts): number | undefined {
|
||||
switch (itemId) {
|
||||
case 'allBooks': return counts.allBooks;
|
||||
|
||||
Reference in New Issue
Block a user