refactor(ui): fix prime menu positioning + cleanup (#1377)

This commit is contained in:
Alex
2026-05-20 18:14:47 +01:00
committed by GitHub
parent e46305e082
commit 1e763b1e89
12 changed files with 237 additions and 432 deletions
@@ -90,7 +90,7 @@
[popup]="true"
appendTo="body"
styleClass="sidebar-entity-menu"
(onShow)="positionContextMenu(entitymenu)"
(onShow)="markContextMenuOpen()"
(onHide)="closeContextMenu()"
></p-menu>
} @else if (currentItem.bookCount) {
@@ -1,4 +1,4 @@
import { ChangeDetectionStrategy, Component, Renderer2, RendererStyleFlags2, computed, inject, input, signal } from '@angular/core';
import { ChangeDetectionStrategy, Component, computed, inject, input, signal } from '@angular/core';
import { RouterLink } from '@angular/router';
import { Menu } from 'primeng/menu';
import { Tooltip } from 'primeng/tooltip';
@@ -35,8 +35,6 @@ export class AppSidebarItemRowComponent {
private readonly userService = inject(UserService);
readonly layoutService = inject(LayoutService);
private readonly renderer = inject(Renderer2);
private contextMenuTrigger: HTMLElement | null = null;
readonly isRouteActive = computed(() => {
const route = this.item().routerLink?.[0];
@@ -58,43 +56,15 @@ export class AppSidebarItemRowComponent {
}
openContextMenu(event: Event, menu: Menu): void {
this.contextMenuTrigger = event.currentTarget instanceof HTMLElement
? event.currentTarget
: null;
menu.toggle(event);
event.stopPropagation();
}
positionContextMenu(menu: Menu): void {
markContextMenuOpen(): void {
this.menuOpen.set(true);
if (this.layoutService.isDesktop()) return;
const trigger = this.contextMenuTrigger;
const panel = menu.container;
if (!trigger || !(panel instanceof HTMLElement)) return;
const gutter = 8;
const rect = trigger.getBoundingClientRect();
const panelWidth = panel.offsetWidth;
const panelHeight = panel.offsetHeight;
const spaceAbove = rect.top - gutter;
const spaceBelow = window.innerHeight - rect.bottom - gutter;
const placeBelow = spaceBelow >= panelHeight || spaceBelow >= spaceAbove;
const availableHeight = Math.max(placeBelow ? spaceBelow : spaceAbove, 0);
const left = Math.max(Math.min(rect.right + gutter, window.innerWidth - panelWidth - gutter), gutter);
const top = placeBelow
? rect.bottom + gutter
: rect.top - Math.min(panelHeight, availableHeight) - gutter;
const flags = RendererStyleFlags2.DashCase;
this.renderer.setStyle(panel, '--sidebar-popover-left', `${left}px`, flags);
this.renderer.setStyle(panel, '--sidebar-popover-top', `${Math.max(top, gutter)}px`, flags);
this.renderer.setStyle(panel, '--sidebar-popover-max-height', `${availableHeight}px`, flags);
}
closeContextMenu(): void {
this.menuOpen.set(false);
this.contextMenuTrigger = null;
}
getIconSelection(): IconSelection | null {
@@ -50,26 +50,27 @@
<button
type="button"
ngMenuTrigger
#addMobileTrigger="ngMenuTrigger"
#addMobileOrigin
[menu]="addMobileMenu.menuRef()"
class="sidebar-icon-button sidebar-mobile-landscape-action"
[pTooltip]="t('add')"
[tooltipDisabled]="!layoutService.isDesktop()"
tooltipPosition="bottom"
[attr.aria-label]="t('add')"
aria-haspopup="menu"
[attr.aria-expanded]="addMenuOpen() ? 'true' : 'false'"
(click)="toggleAddMenu($event, addMenu)"
>
<i class="pi pi-plus" aria-hidden="true"></i>
</button>
<app-menu
#addMobileMenu="appMenu"
[origin]="addMobileOrigin"
[open]="addMobileTrigger.expanded()"
[items]="addMenuItems()"
[positions]="mobileMenuPositions"
></app-menu>
<p-menu
#addMenu
[model]="addMenuItems()"
[popup]="true"
appendTo="body"
styleClass="sidebar-create-menu"
(onShow)="addMenuOpen.set(true)"
(onHide)="addMenuOpen.set(false)"
></p-menu>
@if (canUploadBooks()) {
<button
@@ -87,6 +88,8 @@
<button
type="button"
cdkOverlayOrigin
#notificationsMobileOrigin="cdkOverlayOrigin"
class="sidebar-icon-button sidebar-mobile-landscape-action sidebar-notification-button"
[attr.aria-label]="t('notifications')"
[pTooltip]="t('notifications')"
@@ -94,7 +97,7 @@
tooltipPosition="bottom"
aria-haspopup="dialog"
[attr.aria-expanded]="notificationsOpen() ? 'true' : 'false'"
(click)="openSidebarOverlay($event, notificationsPopover, 'below')"
(click)="toggleHeaderNotificationsPopover(notificationsMobileOrigin)"
>
<span class="sidebar-notification-button-content">
<i class="pi pi-bell" aria-hidden="true"></i>
@@ -104,10 +107,6 @@
</span>
</button>
<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>
@if (currentUser(); as user) {
<button
type="button"
@@ -160,28 +159,19 @@
<div class="sidebar-footer-actions">
<button
type="button"
ngMenuTrigger
#addFooterTrigger="ngMenuTrigger"
#addFooterOrigin
[menu]="addFooterMenu.menuRef()"
class="sidebar-action-link sidebar-footer-action sidebar-toolbar-button"
[pTooltip]="t('add')"
[tooltipDisabled]="!layoutService.isDesktop()"
tooltipPosition="top"
[attr.aria-label]="t('add')"
aria-haspopup="menu"
[attr.aria-expanded]="addMenuOpen() ? 'true' : 'false'"
(click)="toggleAddMenu($event, addMenu)"
>
<i class="pi pi-plus" aria-hidden="true"></i>
<span class="sidebar-footer-action-label">{{ t('add') }}</span>
</button>
<app-menu
#addFooterMenu="appMenu"
[origin]="addFooterOrigin"
[open]="addFooterTrigger.expanded()"
[items]="addMenuItems()"
[positions]="footerMenuPositions()"
></app-menu>
@if (canUploadBooks()) {
<button
type="button"
@@ -199,12 +189,16 @@
<button
type="button"
cdkOverlayOrigin
#notificationsFooterOrigin="cdkOverlayOrigin"
class="sidebar-action-link sidebar-footer-action sidebar-notification-button"
[attr.aria-label]="t('notifications')"
[pTooltip]="t('notifications')"
[tooltipDisabled]="!layoutService.isDesktop()"
tooltipPosition="top"
(click)="openSidebarOverlay($event, notificationsPopover, layoutService.isDesktop() ? 'below' : 'above')"
aria-haspopup="dialog"
[attr.aria-expanded]="notificationsOpen() ? 'true' : 'false'"
(click)="toggleFooterNotificationsPopover(notificationsFooterOrigin)"
>
<span class="sidebar-notification-button-content">
<i class="pi pi-bell" aria-hidden="true"></i>
@@ -281,6 +275,36 @@
}
</div>
@if (notificationPopoverOrigin(); as notificationsOrigin) {
<ng-template
cdkConnectedOverlay
[cdkConnectedOverlayOrigin]="notificationsOrigin"
[cdkConnectedOverlayOpen]="notificationsOpen()"
[cdkConnectedOverlayPositions]="notificationPopoverPositions()"
[cdkConnectedOverlayViewportMargin]="8"
[cdkConnectedOverlayPush]="true"
[cdkConnectedOverlayFlexibleDimensions]="true"
[cdkConnectedOverlayHasBackdrop]="true"
cdkConnectedOverlayBackdropClass="cdk-overlay-transparent-backdrop"
cdkConnectedOverlayPanelClass="sidebar-notification-popover-pane"
(backdropClick)="closeNotificationsPopover()"
(detach)="closeNotificationsPopover()"
>
<section
class="sidebar-notification-popover surface-page"
role="dialog"
aria-modal="true"
tabindex="-1"
cdkTrapFocus
cdkTrapFocusAutoCapture
[attr.aria-label]="t('notifications')"
(keydown)="onNotificationsPopoverKeydown($event)"
>
<app-unified-notification-popover-component></app-unified-notification-popover-component>
</section>
</ng-template>
}
@if (currentUser(); as user) {
@if (userPopoverOrigin(); as userOrigin) {
<ng-template
@@ -16,8 +16,7 @@
margin-bottom: var(--sidebar-header-gap-after);
}
.sidebar-header > p-menu,
.sidebar-header > p-popover {
.sidebar-header > p-menu {
display: none;
}
@@ -1,4 +1,5 @@
import { computed, signal, WritableSignal } from '@angular/core';
import { CdkOverlayOrigin } from '@angular/cdk/overlay';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { BehaviorSubject } from 'rxjs';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
@@ -26,25 +27,6 @@ import { LayoutService } from '../layout.service';
import { AppSidebarComponent } from './app.sidebar.component';
interface PopoverOverlay {
container: HTMLElement;
toggle: (event: MouseEvent) => void;
}
function createRect(top: number, bottom: number, left: number): DOMRect {
return {
x: left,
y: top,
top,
bottom,
left,
right: left + 40,
width: 40,
height: bottom - top,
toJSON: () => ({}),
} as DOMRect;
}
interface TestUser {
name: string;
username: string;
@@ -131,10 +113,6 @@ describe('AppSidebarComponent', () => {
component = fixture.componentInstance;
layoutService.isDesktop.set(true);
layoutService.closeMobileSidebar.mockReset();
vi.spyOn(window, 'requestAnimationFrame').mockImplementation((callback: FrameRequestCallback): number => {
callback(0);
return 0;
});
});
afterEach(() => {
@@ -154,33 +132,33 @@ describe('AppSidebarComponent', () => {
expect(layoutService.closeMobileSidebar).toHaveBeenCalled();
});
it('anchors above-placement overlays from the trigger top edge when the sidebar is expanded', () => {
const trigger = document.createElement('button');
vi.spyOn(trigger, 'getBoundingClientRect').mockReturnValue(createRect(100, 148, 40));
const container = document.createElement('div');
const overlay = { container, toggle: vi.fn() };
const popoverHarness = component as unknown as { applySidebarOverlayPosition(overlay: PopoverOverlay): void };
it('opens the notifications overlay from the selected origin', () => {
const origin = {} as CdkOverlayOrigin;
const sidebar = component as unknown as {
notificationsOpen: () => boolean;
notificationPopoverOrigin: () => CdkOverlayOrigin | null;
toggleFooterNotificationsPopover(origin: CdkOverlayOrigin): void;
};
component.openSidebarOverlay({ currentTarget: trigger } as unknown as MouseEvent, overlay as never, 'above');
popoverHarness.applySidebarOverlayPosition(overlay);
sidebar.toggleFooterNotificationsPopover(origin);
expect(overlay.toggle).toHaveBeenCalled();
expect(container.style.getPropertyValue('--sidebar-popover-top')).toBe('92px');
expect(container.style.getPropertyValue('--sidebar-popover-left')).toBe('40px');
expect(sidebar.notificationsOpen()).toBe(true);
expect(sidebar.notificationPopoverOrigin()).toBe(origin);
});
it('anchors below-placement overlays from the trigger bottom edge', () => {
const trigger = document.createElement('button');
vi.spyOn(trigger, 'getBoundingClientRect').mockReturnValue(createRect(220, 260, 24));
const container = document.createElement('div');
const overlay = { container, toggle: vi.fn() };
const popoverHarness = component as unknown as { applySidebarOverlayPosition(overlay: PopoverOverlay): void };
it('closes the notifications overlay when the same origin is toggled again', () => {
const origin = {} as CdkOverlayOrigin;
const sidebar = component as unknown as {
notificationsOpen: () => boolean;
notificationPopoverOrigin: () => CdkOverlayOrigin | null;
toggleFooterNotificationsPopover(origin: CdkOverlayOrigin): void;
};
component.openSidebarOverlay({ currentTarget: trigger } as unknown as MouseEvent, overlay as never, 'below');
popoverHarness.applySidebarOverlayPosition(overlay);
sidebar.toggleFooterNotificationsPopover(origin);
sidebar.toggleFooterNotificationsPopover(origin);
expect(container.style.getPropertyValue('--sidebar-popover-top')).toBe('268px');
expect(container.style.getPropertyValue('--sidebar-popover-left')).toBe('');
expect(sidebar.notificationsOpen()).toBe(false);
expect(sidebar.notificationPopoverOrigin()).toBeNull();
});
it('derives user initials from a multi-part display name', () => {
@@ -233,21 +211,40 @@ describe('AppSidebarComponent', () => {
expect(sidebar.updateAvailable()).toBe(true);
});
it('anchors notifications above the trigger and keeps them inside the viewport on mobile', () => {
layoutService.isDesktop.set(false);
it('moves the notifications overlay when another origin is selected', () => {
const firstOrigin = {} as CdkOverlayOrigin;
const secondOrigin = {} as CdkOverlayOrigin;
const sidebar = component as unknown as {
notificationsOpen: () => boolean;
notificationPopoverOrigin: () => CdkOverlayOrigin | null;
toggleFooterNotificationsPopover(origin: CdkOverlayOrigin): void;
toggleHeaderNotificationsPopover(origin: CdkOverlayOrigin): void;
};
const trigger = document.createElement('button');
vi.spyOn(trigger, 'getBoundingClientRect').mockReturnValue(createRect(220, 260, 980));
const container = document.createElement('div');
Object.defineProperty(container, 'offsetWidth', { value: 120, configurable: true });
const overlay = { container, toggle: vi.fn() };
const popoverHarness = component as unknown as { applySidebarOverlayPosition(overlay: PopoverOverlay): void };
sidebar.toggleFooterNotificationsPopover(firstOrigin);
sidebar.toggleHeaderNotificationsPopover(secondOrigin);
component.openSidebarOverlay({ currentTarget: trigger } as unknown as MouseEvent, overlay as never, 'above');
popoverHarness.applySidebarOverlayPosition(overlay);
expect(sidebar.notificationsOpen()).toBe(true);
expect(sidebar.notificationPopoverOrigin()).toBe(secondOrigin);
});
expect(container.style.getPropertyValue('--sidebar-popover-top')).toBe('212px');
expect(container.style.getPropertyValue('--sidebar-popover-left')).toBe(`${window.innerWidth - 128}px`);
it('closes the notifications overlay when Escape is pressed inside the dialog', () => {
const origin = {} as CdkOverlayOrigin;
const event = new KeyboardEvent('keydown', { key: 'Escape' });
const preventDefault = vi.spyOn(event, 'preventDefault');
const sidebar = component as unknown as {
notificationsOpen: () => boolean;
notificationPopoverOrigin: () => CdkOverlayOrigin | null;
toggleFooterNotificationsPopover(origin: CdkOverlayOrigin): void;
onNotificationsPopoverKeydown(event: KeyboardEvent): void;
};
sidebar.toggleFooterNotificationsPopover(origin);
sidebar.onNotificationsPopoverKeydown(event);
expect(preventDefault).toHaveBeenCalled();
expect(sidebar.notificationsOpen()).toBe(false);
expect(sidebar.notificationPopoverOrigin()).toBeNull();
});
it('aggregates metadata tasks and pending bookdrop files into the sidebar badge count', () => {
@@ -1,20 +1,12 @@
import { Component, DestroyRef, Renderer2, RendererStyleFlags2, computed, inject, signal } from '@angular/core';
import { Component, DestroyRef, computed, inject, signal } from '@angular/core';
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 { Menu } from 'primeng/menu';
import { CdkTrapFocus } from '@angular/cdk/a11y';
import { CdkConnectedOverlay, CdkOverlayOrigin } from '@angular/cdk/overlay';
import { CdkConnectedOverlay, CdkOverlayOrigin, ConnectedPosition } 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 { AppButtonDirective } from '../../components/button/app-button.directive';
import { MenuComponent } from '../../components/menu/menu.component';
import { MenuEntry } from '../../components/menu/menu-item.model';
import {
ABOVE_ALIGN_LEFT,
BELOW_ALIGN_LEFT,
BESIDE_RIGHT_BOTTOM,
} from '../../components/menu/menu-positions';
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';
@@ -30,8 +22,7 @@ import { AuthService } from '../../service/auth.service';
import { LayoutService } from '../layout.service';
import { TranslocoDirective, TranslocoPipe, TranslocoService } from '@jsverse/transloco';
import { Tooltip } from 'primeng/tooltip';
import { MessageService } from 'primeng/api';
import { VersionService } from '../../service/version.service';
import type { MenuItem } from 'primeng/api';
import { takeUntilDestroyed, toSignal } from '@angular/core/rxjs-interop';
import { NavItem, SidebarSection } from '../navigation/nav-item.model';
import { buildCreateActionNavItems } from '../navigation/nav-catalog';
@@ -42,11 +33,30 @@ import {
buildShelfSection,
buildToolsSection,
} from './sidebar-sections';
import { VersionService } from '../../service/version.service';
import { MetadataProgressService } from '../../service/metadata-progress.service';
import { BookdropFileService } from '../../../features/bookdrop/service/bookdrop-file.service';
import { MetadataBatchProgressNotification, MetadataBatchStatus } from '../../model/metadata-batch-progress.model';
const DOCUMENTATION_URL = 'https://grimmory.org/docs/getting-started';
const ABOVE_ALIGN_LEFT: ConnectedPosition[] = [
{ originX: 'start', originY: 'top', overlayX: 'start', overlayY: 'bottom', offsetY: -8 },
{ originX: 'start', originY: 'bottom', overlayX: 'start', overlayY: 'top', offsetY: 8 },
];
const RIGHT_ALIGN_TOP: ConnectedPosition[] = [
{ originX: 'end', originY: 'top', overlayX: 'start', overlayY: 'top', offsetX: 8 },
{ originX: 'end', originY: 'bottom', overlayX: 'start', overlayY: 'bottom', offsetX: 8 },
{ originX: 'start', originY: 'top', overlayX: 'end', overlayY: 'top', offsetX: -8 },
{ originX: 'start', originY: 'bottom', overlayX: 'end', overlayY: 'bottom', offsetX: -8 },
];
const ABOVE_ALIGN_CENTER: ConnectedPosition[] = [
{ originX: 'center', originY: 'top', overlayX: 'center', overlayY: 'bottom', offsetY: -8 },
{ originX: 'center', originY: 'bottom', overlayX: 'center', overlayY: 'top', offsetY: 8 },
];
const BELOW_ALIGN_CENTER: ConnectedPosition[] = [
{ originX: 'center', originY: 'bottom', overlayX: 'center', overlayY: 'top', offsetY: 8 },
{ originX: 'center', originY: 'top', overlayX: 'center', overlayY: 'bottom', offsetY: -8 },
];
function computeInitials(name: string | null | undefined, username: string | null | undefined): string {
const source = (name?.trim() || username?.trim() || '').trim();
@@ -95,14 +105,12 @@ function isNewerVersion(latest: string | undefined, current: string | undefined)
imports: [
AppSidebarSectionComponent,
AppButtonDirective,
Popover,
Menu,
UnifiedNotificationBoxComponent,
MenuComponent,
RouterLink,
TranslocoDirective,
TranslocoPipe,
Tooltip,
MenuTrigger,
CdkTrapFocus,
CdkConnectedOverlay,
CdkOverlayOrigin,
@@ -120,6 +128,7 @@ 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);
@@ -127,12 +136,9 @@ export class AppSidebarComponent {
private readonly seriesDataService = inject(SeriesDataService);
private readonly authorService = inject(AuthorService);
private readonly t = inject(TranslocoService);
private readonly renderer = inject(Renderer2);
private readonly router = inject(Router);
private readonly messageService = inject(MessageService);
private readonly destroyRef = inject(DestroyRef);
private readonly metadataProgressService = inject(MetadataProgressService);
private readonly bookdropFileService = inject(BookdropFileService);
private readonly destroyRef = inject(DestroyRef);
private readonly metadataProgressService = inject(MetadataProgressService);
private readonly bookdropFileService = inject(BookdropFileService);
readonly currentUser = this.userService.currentUser;
private readonly allAuthors = this.authorService.allAuthors;
@@ -195,7 +201,7 @@ private readonly bookdropFileService = inject(BookdropFileService);
];
});
readonly addMenuItems = computed<MenuEntry[]>(() => {
readonly addMenuItems = computed<MenuItem[]>(() => {
this.activeLang();
const user = this.currentUser();
if (!user) return [];
@@ -206,7 +212,7 @@ private readonly bookdropFileService = inject(BookdropFileService);
createMagicShelf: () => void this.dialogLauncherService.openMagicShelfCreateDialog().catch(() => undefined),
uploadBook: () => void this.dialogLauncherService.openFileUploadDialog().catch(() => undefined),
});
return this.toMenuEntries(actions);
return this.toMenuItems(actions);
});
readonly userInitials = computed(() => {
@@ -215,15 +221,17 @@ private readonly bookdropFileService = inject(BookdropFileService);
});
protected readonly notificationsOpen = signal(false);
protected readonly notificationPopoverOrigin = signal<CdkOverlayOrigin | null>(null);
private readonly notificationPopoverMobilePositions = signal<ConnectedPosition[]>(ABOVE_ALIGN_CENTER);
protected readonly addMenuOpen = signal(false);
protected readonly aboveMenuPositions = ABOVE_ALIGN_LEFT;
protected readonly notificationPopoverPositions = computed(() =>
this.layoutService.isDesktop() ? RIGHT_ALIGN_TOP : this.notificationPopoverMobilePositions()
);
protected progressHighlight = false;
protected completedTaskCount = 0;
protected hasPendingBookdropFiles = false;
protected readonly mobileMenuPositions = BELOW_ALIGN_LEFT;
protected readonly aboveMenuPositions = ABOVE_ALIGN_LEFT;
protected readonly footerMenuPositions = computed(() =>
this.layoutService.desktopSidebarCollapsed() ? BESIDE_RIGHT_BOTTOM : ABOVE_ALIGN_LEFT,
);
private readonly latestTasks: Record<string, MetadataBatchProgressNotification> = {};
constructor() {
@@ -276,28 +284,29 @@ private readonly bookdropFileService = inject(BookdropFileService);
}
protected openAccountSettings(): void {
void this.dialogLauncherService.openUserProfileDialog().catch(() => undefined);
this.closeUserPopover();
void this.dialogLauncherService.openUserProfileDialog().catch(() => undefined);
this.closeUserPopover();
}
protected openSettings(): void {
this.router.navigate(['/settings']);
this.closeUserPopover();
this.router.navigate(['/settings']);
this.closeUserPopover();
}
protected openChangelogDialog(): void {
void this.dialogLauncherService.openVersionChangelogDialog().catch(() => undefined);
this.closeUserPopover();
void this.dialogLauncherService.openVersionChangelogDialog().catch(() => undefined);
this.closeUserPopover();
}
protected openReadingStats(): void {
this.router.navigate(['/reading-stats']);
this.closeUserPopover();
this.router.navigate(['/reading-stats']);
this.closeUserPopover();
}
protected openUploadDialog(): void {
void this.dialogLauncherService.openFileUploadDialog().catch(() => undefined);
void this.dialogLauncherService.openFileUploadDialog().catch(() => undefined);
}
protected logout(): void {
this.authService.logout();
this.closeUserPopover();
@@ -310,81 +319,70 @@ private readonly bookdropFileService = inject(BookdropFileService);
}
}
private readonly anchorByOverlay = new WeakMap<Popover, { trigger: HTMLElement; placement: 'above' | 'below' }>();
protected applySidebarOverlayPosition(overlay: Popover): void {
const anchor = this.anchorByOverlay.get(overlay);
const panel = overlay.container;
if (!anchor || !panel) return;
window.requestAnimationFrame(() => {
this.positionSidebarOverlay(anchor, panel);
});
}
private positionSidebarOverlay(
anchor: { trigger: HTMLElement; placement: 'above' | 'below' },
panel: HTMLElement,
): void {
const rect = anchor.trigger.getBoundingClientRect();
const panelWidth = panel.offsetWidth;
const panelHeight = panel.offsetHeight;
const left = Math.max(Math.min(rect.left, window.innerWidth - panelWidth - 8), 8);
const maxTop = Math.max(window.innerHeight - panelHeight - 8, 8);
const anchorAbove = anchor.placement === 'above' && !this.layoutService.desktopSidebarCollapsed();
const requestedTop = anchorAbove
? rect.top - panelHeight - 8
: rect.bottom + 8;
const top = Math.max(Math.min(requestedTop, maxTop), 8);
const flags = RendererStyleFlags2.DashCase;
this.renderer.setStyle(panel, '--sidebar-popover-top', `${top}px`, flags);
this.renderer.setStyle(panel, '--sidebar-popover-max-height', `${Math.max(window.innerHeight - top - 8, 0)}px`, flags);
if (anchorAbove || !this.layoutService.isDesktop()) {
this.renderer.setStyle(panel, '--sidebar-popover-left', `${left}px`, flags);
} else {
this.renderer.removeStyle(panel, '--sidebar-popover-left', flags);
protected onNotificationsPopoverKeydown(event: KeyboardEvent): void {
if (event.key === 'Escape') {
event.preventDefault();
this.closeNotificationsPopover();
}
}
private toMenuEntries(items: readonly (NavItem | null | undefined)[]): MenuEntry[] {
return items.flatMap((item): MenuEntry[] =>
private toMenuItems(items: readonly (NavItem | null | undefined)[]): MenuItem[] {
return items.flatMap((item): MenuItem[] =>
item ? [{
label: item.label,
icon: item.icon ? `pi ${item.icon}` : undefined,
routerLink: item.routerLink,
action: item.action,
command: item.action,
}] : []
);
}
openSidebarOverlay(event: MouseEvent, overlay: Popover, placement: 'above' | 'below'): void {
if (event.currentTarget instanceof HTMLElement) {
this.anchorByOverlay.set(overlay, { trigger: event.currentTarget, placement });
protected toggleAddMenu(event: MouseEvent, menu: Menu): void {
menu.toggle(event);
}
protected toggleHeaderNotificationsPopover(origin: CdkOverlayOrigin): void {
this.toggleNotificationsPopover(origin, BELOW_ALIGN_CENTER);
}
protected toggleFooterNotificationsPopover(origin: CdkOverlayOrigin): void {
this.toggleNotificationsPopover(origin, ABOVE_ALIGN_CENTER);
}
private toggleNotificationsPopover(origin: CdkOverlayOrigin, mobilePositions = ABOVE_ALIGN_CENTER): void {
if (this.notificationsOpen() && this.notificationPopoverOrigin() === origin) {
this.closeNotificationsPopover();
return;
}
overlay.toggle(event);
this.notificationPopoverMobilePositions.set(mobilePositions);
this.notificationPopoverOrigin.set(origin);
this.notificationsOpen.set(true);
}
private subscribeToMetadataProgress(): void {
this.metadataProgressService.progressUpdates$
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((progress) => {
this.progressHighlight = progress.status === MetadataBatchStatus.IN_PROGRESS;
});
}
private replaceLatestTasks(tasks: Record<string, MetadataBatchProgressNotification>): void {
for (const key of Object.keys(this.latestTasks)) {
delete this.latestTasks[key];
protected closeNotificationsPopover(): void {
this.notificationsOpen.set(false);
this.notificationPopoverOrigin.set(null);
}
Object.assign(this.latestTasks, tasks);
}
private updateCompletedTaskCount(): void {
const metadataTaskCount = Object.keys(this.latestTasks).length;
const bookdropFileTaskCount = this.hasPendingBookdropFiles ? 1 : 0;
this.completedTaskCount = metadataTaskCount + bookdropFileTaskCount;
}
private subscribeToMetadataProgress(): void {
this.metadataProgressService.progressUpdates$
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((progress) => {
this.progressHighlight = progress.status === MetadataBatchStatus.IN_PROGRESS;
});
}
private replaceLatestTasks(tasks: Record<string, MetadataBatchProgressNotification>): void {
for (const key of Object.keys(this.latestTasks)) {
delete this.latestTasks[key];
}
Object.assign(this.latestTasks, tasks);
}
private updateCompletedTaskCount(): void {
const metadataTaskCount = Object.keys(this.latestTasks).length;
const bookdropFileTaskCount = this.hasPendingBookdropFiles ? 1 : 0;
this.completedTaskCount = metadataTaskCount + bookdropFileTaskCount;
}
}