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;
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import { buildAllNavPages, buildHomeNavItems, buildQuickActionNavItems, findPageNavItem } from './nav-catalog';
|
||||
import {
|
||||
buildAllNavPages,
|
||||
buildCreateActionNavItems,
|
||||
buildHomeNavItems,
|
||||
buildQuickActionNavItems,
|
||||
findPageNavItem,
|
||||
} from './nav-catalog';
|
||||
|
||||
const translate = (key: string): string => key;
|
||||
|
||||
@@ -76,4 +82,22 @@ describe('nav-catalog', () => {
|
||||
'uploadBook',
|
||||
]);
|
||||
});
|
||||
|
||||
it('builds create-only actions without upload', () => {
|
||||
const handlers = {
|
||||
createLibrary: vi.fn(),
|
||||
createShelf: vi.fn(),
|
||||
createMagicShelf: vi.fn(),
|
||||
uploadBook: vi.fn(),
|
||||
};
|
||||
|
||||
expect(buildCreateActionNavItems(translate, {
|
||||
canManageLibrary: true,
|
||||
canUpload: true,
|
||||
}, handlers).map((item) => item.id)).toEqual([
|
||||
'createLibrary',
|
||||
'createShelf',
|
||||
'createMagicShelf',
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -133,7 +133,7 @@ const SECONDARY_PAGE_DEFINITIONS: readonly PageDefinition[] = [
|
||||
},
|
||||
] as const;
|
||||
|
||||
const ACTION_DEFINITIONS: readonly ActionDefinition[] = [
|
||||
const CREATE_ACTION_DEFINITIONS: readonly ActionDefinition[] = [
|
||||
{
|
||||
id: 'createLibrary',
|
||||
labelKey: 'layout.menu.createLibrary',
|
||||
@@ -153,6 +153,10 @@ const ACTION_DEFINITIONS: readonly ActionDefinition[] = [
|
||||
icon: 'pi-sparkles',
|
||||
run: (handlers) => handlers.createMagicShelf,
|
||||
},
|
||||
] as const;
|
||||
|
||||
const ACTION_DEFINITIONS: readonly ActionDefinition[] = [
|
||||
...CREATE_ACTION_DEFINITIONS,
|
||||
{
|
||||
id: 'uploadBook',
|
||||
labelKey: 'layout.menu.uploadBook',
|
||||
@@ -207,6 +211,21 @@ export function buildQuickActionNavItems(
|
||||
}));
|
||||
}
|
||||
|
||||
export function buildCreateActionNavItems(
|
||||
translate: TranslateFn,
|
||||
permissions: ShellNavPermissions,
|
||||
handlers: ShellActionHandlers,
|
||||
): NavItem[] {
|
||||
return CREATE_ACTION_DEFINITIONS
|
||||
.filter((definition) => isVisible(definition, permissions))
|
||||
.map((definition) => ({
|
||||
id: definition.id,
|
||||
label: translate(definition.labelKey),
|
||||
icon: definition.icon,
|
||||
action: definition.run(handlers),
|
||||
}));
|
||||
}
|
||||
|
||||
const ALL_PAGE_DEFINITIONS: readonly PageDefinition[] = [
|
||||
...HOME_PAGE_DEFINITIONS,
|
||||
...SECONDARY_PAGE_DEFINITIONS,
|
||||
|
||||
@@ -33,11 +33,25 @@ describe('VersionService', () => {
|
||||
expect(version).toEqual({current: '1.0.0', latest: '1.0.1'});
|
||||
});
|
||||
|
||||
const request = httpTestingController.expectOne(`${API_CONFIG.BASE_URL}/api/v1/version`);
|
||||
const request = httpTestingController.expectOne(req =>
|
||||
req.url === `${API_CONFIG.BASE_URL}/api/v1/version` && req.params.has('_')
|
||||
);
|
||||
expect(request.request.method).toBe('GET');
|
||||
request.flush({current: '1.0.0', latest: '1.0.1'});
|
||||
});
|
||||
|
||||
it('returns unknown version details when the version request fails', () => {
|
||||
service.getVersion().subscribe(version => {
|
||||
expect(version).toEqual({current: 'unknown', latest: 'unknown'});
|
||||
});
|
||||
|
||||
const request = httpTestingController.expectOne(req =>
|
||||
req.url === `${API_CONFIG.BASE_URL}/api/v1/version` && req.params.has('_')
|
||||
);
|
||||
expect(request.request.method).toBe('GET');
|
||||
request.flush('Version unavailable', {status: 500, statusText: 'Server Error'});
|
||||
});
|
||||
|
||||
it('fetches the changelog entries', () => {
|
||||
service.getChangelog().subscribe(entries => {
|
||||
expect(entries).toEqual([{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {inject, Injectable} from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import {HttpClient, HttpParams} from '@angular/common/http';
|
||||
import {catchError, Observable, of} from 'rxjs';
|
||||
import {API_CONFIG} from '../../core/config/api-config';
|
||||
|
||||
export interface AppVersion {
|
||||
@@ -24,7 +24,9 @@ export class VersionService {
|
||||
private versionUrl = `${API_CONFIG.BASE_URL}/api/v1/version`;
|
||||
|
||||
getVersion(): Observable<AppVersion> {
|
||||
return this.http.get<AppVersion>(this.versionUrl);
|
||||
return this.http.get<AppVersion>(this.versionUrl, {
|
||||
params: new HttpParams().set('_', Date.now().toString()),
|
||||
}).pipe(catchError(() => of({current: 'unknown', latest: 'unknown'})));
|
||||
}
|
||||
|
||||
getChangelog(): Observable<ReleaseNote[]> {
|
||||
|
||||
@@ -22,7 +22,8 @@
|
||||
}
|
||||
}
|
||||
|
||||
.menu-panel {
|
||||
.menu-panel,
|
||||
.user-account-popover {
|
||||
--menu-panel-padding: 4px;
|
||||
--menu-panel-gap: 1px;
|
||||
--menu-panel-min-width: 12rem;
|
||||
@@ -33,7 +34,9 @@
|
||||
--menu-item-gap: 8px;
|
||||
--menu-item-radius: 5px;
|
||||
--menu-item-icon-size: 16px;
|
||||
}
|
||||
|
||||
.menu-panel {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--menu-panel-gap);
|
||||
@@ -48,7 +51,8 @@
|
||||
font-size: var(--text-base);
|
||||
}
|
||||
|
||||
.menu-panel .menu-item {
|
||||
.menu-panel .menu-item,
|
||||
.user-account-popover .menu-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--menu-item-gap);
|
||||
@@ -66,23 +70,27 @@
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.menu-panel .menu-item:hover {
|
||||
.menu-panel .menu-item:hover,
|
||||
.user-account-popover .menu-item:hover {
|
||||
background-color: var(--surface-hover);
|
||||
}
|
||||
|
||||
.menu-panel .menu-item:focus-visible {
|
||||
.menu-panel .menu-item:focus-visible,
|
||||
.user-account-popover .menu-item:focus-visible {
|
||||
background-color: var(--surface-hover);
|
||||
box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--primary-color) 50%, transparent);
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.menu-panel .menu-item[aria-disabled="true"] {
|
||||
.menu-panel .menu-item[aria-disabled="true"],
|
||||
.user-account-popover .menu-item[aria-disabled="true"] {
|
||||
color: var(--text-color-secondary);
|
||||
cursor: not-allowed;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.menu-panel .menu-item i {
|
||||
.menu-panel .menu-item i,
|
||||
.user-account-popover .menu-item i {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
@@ -99,7 +107,8 @@
|
||||
}
|
||||
|
||||
@media #{variables.$mobile-shell-media-query} {
|
||||
.menu-panel {
|
||||
.menu-panel,
|
||||
.user-account-popover {
|
||||
--menu-panel-padding: 6px;
|
||||
--menu-panel-gap: 2px;
|
||||
--menu-item-padding-block: 8px;
|
||||
@@ -108,3 +117,165 @@
|
||||
--menu-item-gap: 10px;
|
||||
}
|
||||
}
|
||||
|
||||
.cdk-overlay-pane.user-account-popover-pane {
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
.user-account-popover {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: min(17.5rem, calc(100vw - 1rem));
|
||||
overflow: hidden;
|
||||
background: var(--page-background);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: var(--menu-panel-radius);
|
||||
box-shadow:
|
||||
0 18px 48px rgb(0 0 0 / 28%),
|
||||
0 4px 16px rgb(0 0 0 / 18%);
|
||||
color: var(--text-color);
|
||||
font: inherit;
|
||||
}
|
||||
|
||||
.user-account-popover-header {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
box-sizing: border-box;
|
||||
width: 100%;
|
||||
padding: 0.75rem;
|
||||
background: color-mix(in srgb, var(--surface-hover), var(--page-background) 35%);
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
.user-account-popover-title-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 0.5rem;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.user-account-popover-header h2 {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 0.5rem;
|
||||
min-width: 0;
|
||||
margin: 0;
|
||||
font-size: var(--text-lg);
|
||||
font-weight: 600;
|
||||
line-height: 1.15;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.user-account-popover-header h2 span {
|
||||
color: var(--text-color-secondary);
|
||||
font-size: var(--text-xs);
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.user-account-popover-icon-button {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex: 0 0 auto;
|
||||
width: 2rem;
|
||||
height: 2rem;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
border-radius: 8px;
|
||||
background: transparent;
|
||||
color: var(--surface-500);
|
||||
font-size: var(--text-base);
|
||||
cursor: pointer;
|
||||
transition:
|
||||
background-color var(--transition-fast),
|
||||
color var(--transition-fast);
|
||||
}
|
||||
|
||||
.user-account-popover-icon-button:hover,
|
||||
.user-account-popover-icon-button:focus-visible {
|
||||
background: var(--surface-hover);
|
||||
color: var(--text-color);
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.user-account-popover-header-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.user-account-popover .user-account-popover-settings,
|
||||
.user-account-popover .user-account-popover-update {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
align-self: flex-start;
|
||||
gap: var(--menu-item-gap);
|
||||
min-height: var(--menu-item-min-height);
|
||||
padding: var(--menu-item-padding-block) var(--menu-item-padding-inline);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: var(--menu-item-radius);
|
||||
background: transparent;
|
||||
color: var(--text-color);
|
||||
font: inherit;
|
||||
font-weight: 600;
|
||||
text-decoration: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.user-account-popover .user-account-popover-settings:hover,
|
||||
.user-account-popover .user-account-popover-settings:focus-visible {
|
||||
background: var(--surface-hover);
|
||||
color: var(--text-color);
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.user-account-popover .user-account-popover-update {
|
||||
border-color: color-mix(in srgb, var(--primary-color) 30%, transparent);
|
||||
background: color-mix(in srgb, var(--primary-color) 18%, transparent);
|
||||
color: var(--primary-color);
|
||||
}
|
||||
|
||||
.user-account-popover .user-account-popover-update:hover,
|
||||
.user-account-popover .user-account-popover-update:focus-visible {
|
||||
background: color-mix(in srgb, var(--primary-color) 26%, transparent);
|
||||
color: var(--primary-color);
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.user-account-popover-body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.25rem;
|
||||
padding: 0.375rem;
|
||||
}
|
||||
|
||||
.user-account-popover .user-account-popover-action {
|
||||
background: transparent;
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
.user-account-popover-footer {
|
||||
padding: 0.375rem;
|
||||
border-top: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
.user-account-popover .user-account-popover-logout {
|
||||
background: transparent;
|
||||
color: var(--p-red-400);
|
||||
}
|
||||
|
||||
.user-account-popover .user-account-popover-settings i,
|
||||
.user-account-popover .user-account-popover-update i,
|
||||
.user-account-popover .user-account-popover-logout i {
|
||||
color: currentcolor;
|
||||
}
|
||||
|
||||
.user-account-popover .user-account-popover-logout:hover,
|
||||
.user-account-popover .user-account-popover-logout:focus-visible {
|
||||
background: color-mix(in srgb, var(--p-red-500) 12%, transparent);
|
||||
outline: none;
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
"authors": "Authors",
|
||||
"notebook": "Notebook",
|
||||
"update": "(Update)",
|
||||
"updateAvailable": "Update Available",
|
||||
"versionCopied": "Version {{ version }} copied to clipboard.",
|
||||
"versionCopyFailed": "Unable to copy version {{ version }}.",
|
||||
"tools": "Tools",
|
||||
@@ -39,7 +40,7 @@
|
||||
"primaryNav": "Primary navigation",
|
||||
"resizeSidebar": "Resize sidebar",
|
||||
"search": "Search",
|
||||
"add": "Create or upload",
|
||||
"add": "Create",
|
||||
"createMagicShelf": "Create Magic Shelf",
|
||||
"editSidebar": "Edit sidebar",
|
||||
"doneEditing": "Done editing",
|
||||
|
||||
Reference in New Issue
Block a user