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,4 @@
|
||||
export interface MenuChangeEvent {
|
||||
key: string;
|
||||
routeEvent?: boolean;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<div class="layout-wrapper" [ngClass]="containerClass">
|
||||
<app-topbar></app-topbar>
|
||||
<div class="layout-sidebar">
|
||||
<app-sidebar></app-sidebar>
|
||||
</div>
|
||||
<div class="layout-main-container">
|
||||
<div class="layout-main">
|
||||
<router-outlet></router-outlet>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layout-mask"></div>
|
||||
</div>
|
||||
@@ -0,0 +1,125 @@
|
||||
import {Component, OnDestroy, OnInit, Renderer2, ViewChild} from '@angular/core';
|
||||
import {NavigationEnd, Router, RouterOutlet} from '@angular/router';
|
||||
import {filter, Subscription} from 'rxjs';
|
||||
import {LayoutService} from "./service/app.layout.service";
|
||||
import {AppSidebarComponent} from "../layout-sidebar/app.sidebar.component";
|
||||
import {AppTopBarComponent} from '../layout-topbar/app.topbar.component';
|
||||
import {NgClass} from '@angular/common';
|
||||
import {ToastModule} from 'primeng/toast';
|
||||
import {LocalStorageService} from '../../../service/local-storage.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-layout',
|
||||
imports: [
|
||||
RouterOutlet,
|
||||
AppSidebarComponent,
|
||||
AppTopBarComponent,
|
||||
NgClass,
|
||||
ToastModule
|
||||
],
|
||||
templateUrl: './app.layout.component.html'
|
||||
})
|
||||
export class AppLayoutComponent implements OnInit, OnDestroy {
|
||||
|
||||
overlayMenuOpenSubscription: Subscription;
|
||||
|
||||
menuOutsideClickListener: (() => void) | null = null;
|
||||
|
||||
profileMenuOutsideClickListener: (() => void) | null = null;
|
||||
|
||||
@ViewChild(AppSidebarComponent) appSidebar!: AppSidebarComponent;
|
||||
|
||||
@ViewChild(AppTopBarComponent) appTopbar!: AppTopBarComponent;
|
||||
|
||||
constructor(public layoutService: LayoutService, public renderer: Renderer2, public router: Router, private localStorageService: LocalStorageService) {
|
||||
this.overlayMenuOpenSubscription = this.layoutService.overlayOpen$.subscribe(() => {
|
||||
if (!this.menuOutsideClickListener) {
|
||||
this.menuOutsideClickListener = this.renderer.listen('document', 'click', (event) => {
|
||||
if (this.isOutsideClicked(event)) {
|
||||
this.hideMenu();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (this.layoutService.state.staticMenuMobileActive) {
|
||||
this.blockBodyScroll();
|
||||
}
|
||||
});
|
||||
|
||||
this.router.events.pipe(filter(event => event instanceof NavigationEnd))
|
||||
.subscribe(() => {
|
||||
this.hideMenu();
|
||||
this.hideProfileMenu();
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
const width = this.localStorageService.get<number>('sidebarWidth') ?? 225;
|
||||
document.documentElement.style.setProperty('--sidebar-width', width + 'px');
|
||||
}
|
||||
|
||||
isOutsideClicked(event: MouseEvent): boolean {
|
||||
const sidebarEl = document.querySelector('.layout-sidebar');
|
||||
const topbarEl = document.querySelector('.layout-menu-button');
|
||||
const eventTarget = event.target as Node;
|
||||
const clickedInsideSidebar = sidebarEl?.isSameNode(eventTarget) || sidebarEl?.contains(eventTarget);
|
||||
const clickedInsideTopbar = topbarEl?.isSameNode(eventTarget) || topbarEl?.contains(eventTarget);
|
||||
return !(clickedInsideSidebar || clickedInsideTopbar);
|
||||
}
|
||||
|
||||
hideMenu() {
|
||||
this.layoutService.state.overlayMenuActive = false;
|
||||
this.layoutService.state.staticMenuMobileActive = false;
|
||||
this.layoutService.state.menuHoverActive = false;
|
||||
if (this.menuOutsideClickListener) {
|
||||
this.menuOutsideClickListener();
|
||||
this.menuOutsideClickListener = null;
|
||||
}
|
||||
this.unblockBodyScroll();
|
||||
}
|
||||
|
||||
hideProfileMenu() {
|
||||
this.layoutService.state.profileSidebarVisible = false;
|
||||
if (this.profileMenuOutsideClickListener) {
|
||||
this.profileMenuOutsideClickListener();
|
||||
this.profileMenuOutsideClickListener = null;
|
||||
}
|
||||
}
|
||||
|
||||
blockBodyScroll(): void {
|
||||
if (document.body.classList) {
|
||||
document.body.classList.add('blocked-scroll');
|
||||
} else {
|
||||
document.body.className += ' blocked-scroll';
|
||||
}
|
||||
}
|
||||
|
||||
unblockBodyScroll(): void {
|
||||
if (document.body.classList) {
|
||||
document.body.classList.remove('blocked-scroll');
|
||||
} else {
|
||||
document.body.className = document.body.className.replace(new RegExp('(^|\\b)' +
|
||||
'blocked-scroll'.split(' ').join('|') + '(\\b|$)', 'gi'), ' ');
|
||||
}
|
||||
}
|
||||
|
||||
get containerClass() {
|
||||
return {
|
||||
'layout-overlay': this.layoutService.config().menuMode === 'overlay',
|
||||
'layout-static': this.layoutService.config().menuMode === 'static',
|
||||
'layout-static-inactive': this.layoutService.state.staticMenuDesktopInactive && this.layoutService.config().menuMode === 'static',
|
||||
'layout-overlay-active': this.layoutService.state.overlayMenuActive,
|
||||
'layout-mobile-active': this.layoutService.state.staticMenuMobileActive
|
||||
}
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
if (this.overlayMenuOpenSubscription) {
|
||||
this.overlayMenuOpenSubscription.unsubscribe();
|
||||
}
|
||||
|
||||
if (this.menuOutsideClickListener) {
|
||||
this.menuOutsideClickListener();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
import {Injectable, effect, signal} from '@angular/core';
|
||||
import {Subject} from 'rxjs';
|
||||
|
||||
export interface AppConfig {
|
||||
inputStyle: string;
|
||||
colorScheme: string;
|
||||
theme: string;
|
||||
ripple: boolean;
|
||||
menuMode: string;
|
||||
scale: number;
|
||||
}
|
||||
|
||||
interface LayoutState {
|
||||
staticMenuDesktopInactive: boolean;
|
||||
overlayMenuActive: boolean;
|
||||
profileSidebarVisible: boolean;
|
||||
configSidebarVisible: boolean;
|
||||
staticMenuMobileActive: boolean;
|
||||
menuHoverActive: boolean;
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class LayoutService {
|
||||
_config: AppConfig = {
|
||||
ripple: false,
|
||||
inputStyle: 'outlined',
|
||||
menuMode: 'static',
|
||||
colorScheme: 'light',
|
||||
theme: 'lara-light-indigo',
|
||||
scale: 14,
|
||||
};
|
||||
|
||||
config = signal<AppConfig>(this._config);
|
||||
|
||||
state: LayoutState = {
|
||||
staticMenuDesktopInactive: false,
|
||||
overlayMenuActive: false,
|
||||
profileSidebarVisible: false,
|
||||
configSidebarVisible: false,
|
||||
staticMenuMobileActive: false,
|
||||
menuHoverActive: false,
|
||||
};
|
||||
|
||||
private configUpdate = new Subject<AppConfig>();
|
||||
private overlayOpen = new Subject<unknown>();
|
||||
overlayOpen$ = this.overlayOpen.asObservable();
|
||||
|
||||
constructor() {
|
||||
effect(() => {
|
||||
const config = this.config();
|
||||
if (this.updateStyle(config)) {
|
||||
this.changeTheme();
|
||||
}
|
||||
this.changeScale(config.scale);
|
||||
this.onConfigUpdate();
|
||||
});
|
||||
}
|
||||
|
||||
updateStyle(config: AppConfig) {
|
||||
return (
|
||||
config.theme !== this._config.theme ||
|
||||
config.colorScheme !== this._config.colorScheme
|
||||
);
|
||||
}
|
||||
|
||||
onMenuToggle() {
|
||||
if (this.isOverlay()) {
|
||||
this.state.overlayMenuActive = !this.state.overlayMenuActive;
|
||||
if (this.state.overlayMenuActive) {
|
||||
this.overlayOpen.next(null);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.isDesktop()) {
|
||||
this.state.staticMenuDesktopInactive = !this.state.staticMenuDesktopInactive;
|
||||
} else {
|
||||
this.state.staticMenuMobileActive = !this.state.staticMenuMobileActive;
|
||||
if (this.state.staticMenuMobileActive) {
|
||||
this.overlayOpen.next(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
isOverlay() {
|
||||
return this.config().menuMode === 'overlay';
|
||||
}
|
||||
|
||||
isDesktop() {
|
||||
return window.innerWidth > 991;
|
||||
}
|
||||
|
||||
onConfigUpdate() {
|
||||
this._config = {...this.config()};
|
||||
this.configUpdate.next(this.config());
|
||||
}
|
||||
|
||||
changeTheme() {
|
||||
const config = this.config();
|
||||
const themeLink = document.getElementById('theme-css') as HTMLLinkElement;
|
||||
const themeLinkHref = themeLink.getAttribute('href')!;
|
||||
const newHref = themeLinkHref
|
||||
.split('/')
|
||||
.map((el) =>
|
||||
el == this._config.theme
|
||||
? (el = config.theme)
|
||||
: el == `theme-${this._config.colorScheme}`
|
||||
? (el = `theme-${config.colorScheme}`)
|
||||
: el
|
||||
)
|
||||
.join('/');
|
||||
|
||||
this.replaceThemeLink(newHref);
|
||||
}
|
||||
|
||||
replaceThemeLink(href: string) {
|
||||
const id = 'theme-css';
|
||||
const themeLink = document.getElementById(id) as HTMLLinkElement;
|
||||
const cloneLinkElement = themeLink.cloneNode(true) as HTMLLinkElement;
|
||||
|
||||
cloneLinkElement.setAttribute('href', href);
|
||||
cloneLinkElement.setAttribute('id', id + '-clone');
|
||||
|
||||
themeLink.parentNode!.insertBefore(
|
||||
cloneLinkElement,
|
||||
themeLink.nextSibling
|
||||
);
|
||||
cloneLinkElement.addEventListener('load', () => {
|
||||
themeLink.remove();
|
||||
cloneLinkElement.setAttribute('id', id);
|
||||
});
|
||||
}
|
||||
|
||||
changeScale(value: number) {
|
||||
document.documentElement.style.fontSize = `${value}px`;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<app-menu></app-menu>
|
||||
@@ -0,0 +1,15 @@
|
||||
import { Component, ElementRef } from '@angular/core';
|
||||
import { LayoutService } from "../layout-main/service/app.layout.service";
|
||||
import {AppMenuComponent} from '../layout-menu/app.menu.component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-sidebar',
|
||||
imports: [
|
||||
AppMenuComponent
|
||||
],
|
||||
templateUrl: './app.sidebar.component.html'
|
||||
})
|
||||
export class AppSidebarComponent {
|
||||
constructor(public layoutService: LayoutService, public el: ElementRef) { }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,309 @@
|
||||
<ng-container *transloco="let t; prefix: 'layout.topbar'">
|
||||
<div class="layout-topbar">
|
||||
|
||||
<a class="layout-topbar-logo topbar-logo" routerLink="">
|
||||
<!--
|
||||
<svg class="logo-icon half-title" viewBox="0 0 126 126" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
|
||||
<path
|
||||
d="M59 4.79297C71.5051 11.5557 80 24.7854 80 40C80 40.5959 79.987 41.1888 79.9609 41.7783C79.8609 44.0406 81.7355 46 84 46C106.091 46 124 63.9086 124 86C124 108.091 106.091 126 84 126H10C4.47715 126 0 121.523 0 116V39.0068L0.0126953 38.9941C0.357624 25.0252 7.86506 12.8347 19 5.95215V63.832C19 64.8345 20.0676 65.4391 20.9121 64.9902L21.0771 64.8867L38.2227 52.3428C38.6819 52.0068 39.3064 52.0068 39.7656 52.3428L56.9229 64.8945L57.0879 64.998C57.9324 65.447 59 64.8423 59 63.8398V4.79297Z"/>
|
||||
<path
|
||||
d="M40 0C43.8745 0 47.6199 0.552381 51.1631 1.58008V50.9697L44.3926 46.0176L44.0879 45.8037C40.9061 43.6679 36.7098 43.7393 33.5957 46.0176L26.8369 50.9619V2.21875C30.9593 0.782634 35.3881 0 40 0Z"
|
||||
fill="white"/>
|
||||
</svg>
|
||||
-->
|
||||
<span class="logo-text">Grimmory</span>
|
||||
</a>
|
||||
|
||||
<p-button
|
||||
class="layout-menu-button"
|
||||
#menubutton
|
||||
icon="pi pi-bars"
|
||||
[rounded]="true"
|
||||
[outlined]="true"
|
||||
(click)="toggleMenu()"
|
||||
[ngClass]="{ 'rotate-right': !isMenuVisible, 'rotate-left': isMenuVisible }"
|
||||
>
|
||||
</p-button>
|
||||
|
||||
<div class="topbar-content">
|
||||
<app-book-searcher class="topbar-search"></app-book-searcher>
|
||||
<ul class="topbar-items topbar-desktop-items">
|
||||
<div class="topbar-action-group">
|
||||
@if (user(); as currentUser) {
|
||||
@if (currentUser.permissions?.canAccessBookdrop || currentUser.permissions?.admin) {
|
||||
<li>
|
||||
<a class="topbar-item" (click)="navigateToBookdrop()" [pTooltip]="t('bookdrop')" tooltipPosition="bottom">
|
||||
<i class="pi pi-inbox topbar-icon"></i>
|
||||
</a>
|
||||
</li>
|
||||
}
|
||||
@if (currentUser.permissions?.canManageLibrary || currentUser.permissions?.admin) {
|
||||
<li>
|
||||
<a class="topbar-item" (click)="openLibraryCreatorDialog()" [pTooltip]="t('createNewLibrary')" tooltipPosition="bottom">
|
||||
<i class="pi pi-plus-circle topbar-icon"></i>
|
||||
</a>
|
||||
</li>
|
||||
}
|
||||
@if (currentUser.permissions?.canUpload || currentUser.permissions?.admin) {
|
||||
<li>
|
||||
<a class="topbar-item" (click)="openFileUploadDialog()" [pTooltip]="t('uploadBook')" tooltipPosition="bottom">
|
||||
<i class="pi pi-upload topbar-icon"></i>
|
||||
</a>
|
||||
</li>
|
||||
}
|
||||
}
|
||||
@if (hasStatsAccess) {
|
||||
<li>
|
||||
<button
|
||||
class="topbar-item"
|
||||
(click)="shouldShowStatsMenu ? statsMenu?.toggle($event) : handleStatsButtonClick($event)"
|
||||
[pTooltip]="statsTooltip"
|
||||
tooltipPosition="bottom">
|
||||
<svg class="multi-color-chart-icon" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" style="width: 1.25rem; height: 1.25rem;">
|
||||
<rect x="2" y="13" width="4" height="9" rx="1" fill="#ef4444"/>
|
||||
<rect x="7.5" y="3" width="4" height="19" rx="1" fill="#f59e0b"/>
|
||||
<rect x="13" y="9" width="4" height="13" rx="1" fill="#3b82f6"/>
|
||||
<rect x="18.5" y="5" width="4" height="17" rx="1" fill="#10b981"/>
|
||||
</svg>
|
||||
</button>
|
||||
@if (shouldShowStatsMenu) {
|
||||
<p-menu #statsMenu [model]="statsMenuItems" [popup]="true" appendTo="body"/>
|
||||
}
|
||||
</li>
|
||||
}
|
||||
@if (user(); as currentUser) {
|
||||
@if (currentUser.permissions?.canManageLibrary || currentUser.permissions?.admin) {
|
||||
<li>
|
||||
<a class="topbar-item" (click)="navigateToMetadataManager()" [pTooltip]="t('metadataManager')" tooltipPosition="bottom">
|
||||
<i class="pi pi-sparkles topbar-icon"></i>
|
||||
</a>
|
||||
</li>
|
||||
}
|
||||
}
|
||||
<li>
|
||||
<a class="topbar-item" (click)="navigateToSettings()" [pTooltip]="t('settings')" tooltipPosition="bottom">
|
||||
<i class="pi pi-cog topbar-icon"></i>
|
||||
</a>
|
||||
</li>
|
||||
</div>
|
||||
|
||||
<p-divider layout="vertical"/>
|
||||
|
||||
|
||||
<div class="topbar-action-group">
|
||||
<li class="topbar-item-relative">
|
||||
<button
|
||||
type="button"
|
||||
class="topbar-item"
|
||||
(click)="notificationPopover.toggle($event)"
|
||||
>
|
||||
<i
|
||||
class="pi"
|
||||
[ngClass]="iconClass"
|
||||
[ngStyle]="{ color: iconColor }"
|
||||
style="font-size: 1.25rem"
|
||||
[class.pulsating]="iconPulsating"
|
||||
[attr.aria-label]="t('notificationAriaLabel')"
|
||||
></i>
|
||||
</button>
|
||||
|
||||
@if (shouldShowNotificationBadge) {
|
||||
<span class="notification-badge">{{ completedTaskCount }}</span>
|
||||
}
|
||||
|
||||
<p-popover #notificationPopover>
|
||||
<app-unified-notification-popover-component></app-unified-notification-popover-component>
|
||||
</p-popover>
|
||||
</li>
|
||||
|
||||
<li class="topbar-item-relative">
|
||||
<button
|
||||
type="button"
|
||||
class="topbar-item"
|
||||
(click)="langMenu.toggle($event)"
|
||||
[pTooltip]="t('language')"
|
||||
tooltipPosition="bottom">
|
||||
<i class="pi pi-language topbar-icon"></i>
|
||||
</button>
|
||||
<p-menu #langMenu [model]="langMenuItems" [popup]="true" appendTo="body"/>
|
||||
</li>
|
||||
<li class="topbar-item-relative">
|
||||
<button type="button"
|
||||
class="topbar-item config-item"
|
||||
enterActiveClass="animate-scalein"
|
||||
enterFromClass="hidden"
|
||||
leaveActiveClass="animate-fadeout"
|
||||
leaveToClass="hidden"
|
||||
pStyleClass="@next" [hideOnOutsideClick]="true">
|
||||
<i class="pi pi-palette"></i>
|
||||
</button>
|
||||
<app-theme-configurator></app-theme-configurator>
|
||||
</li>
|
||||
</div>
|
||||
<p-divider layout="vertical"/>
|
||||
<div class="topbar-action-group">
|
||||
<li>
|
||||
<a class="topbar-item"
|
||||
href="https://grimmory.org/docs/getting-started"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
[pTooltip]="t('documentation')"
|
||||
tooltipPosition="bottom">
|
||||
<i class="pi pi-info-circle topbar-icon"></i>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<!-- Show Profile only to non-demo users -->
|
||||
@if (user(); as currentUser) {
|
||||
@if (!currentUser.permissions?.demoUser) {
|
||||
<li>
|
||||
<button class="topbar-item" (click)="openUserProfileDialog()" [pTooltip]="t('profile')" tooltipPosition="bottom">
|
||||
<i class="pi pi-user topbar-icon"></i>
|
||||
</button>
|
||||
</li>
|
||||
}
|
||||
}
|
||||
|
||||
<li>
|
||||
<button class="topbar-item" (click)="logout()" [pTooltip]="t('logout')" tooltipPosition="left">
|
||||
<i class="pi pi-sign-out topbar-icon"></i>
|
||||
</button>
|
||||
</li>
|
||||
</div>
|
||||
</ul>
|
||||
<!-- Trigger Button -->
|
||||
<div class="mobile-trigger">
|
||||
<p-button
|
||||
icon="pi pi-ellipsis-v"
|
||||
outlined
|
||||
(click)="mobileMenu.toggle($event)"
|
||||
/>
|
||||
<p-popover #mobileMenu>
|
||||
<ul class="mobile-menu-list">
|
||||
@if (user(); as currentUser) {
|
||||
@if (currentUser.permissions?.canAccessBookdrop || currentUser.permissions?.admin) {
|
||||
<li>
|
||||
<button
|
||||
class="mobile-menu-item"
|
||||
(click)="navigateToBookdrop(); mobileMenu.hide()"
|
||||
>
|
||||
<i class="pi pi-inbox topbar-icon"></i>
|
||||
{{ t('bookdrop') }}
|
||||
</button>
|
||||
</li>
|
||||
}
|
||||
@if (currentUser.permissions?.canManageLibrary || currentUser.permissions?.admin) {
|
||||
<li>
|
||||
<button
|
||||
class="mobile-menu-item"
|
||||
(click)="openLibraryCreatorDialog(); mobileMenu.hide()"
|
||||
>
|
||||
<i class="pi pi-plus-circle topbar-icon"></i>
|
||||
{{ t('createLibrary') }}
|
||||
</button>
|
||||
</li>
|
||||
}
|
||||
@if (currentUser.permissions?.canUpload || currentUser.permissions?.admin) {
|
||||
<li>
|
||||
<button
|
||||
class="mobile-menu-item"
|
||||
(click)="openFileUploadDialog(); mobileMenu.hide()"
|
||||
>
|
||||
<i class="pi pi-upload topbar-icon"></i>
|
||||
{{ t('uploadBook') }}
|
||||
</button>
|
||||
</li>
|
||||
}
|
||||
@if (currentUser.permissions?.canAccessLibraryStats || currentUser.permissions?.admin) {
|
||||
<li>
|
||||
<button
|
||||
class="mobile-menu-item"
|
||||
(click)="navigateToStats(); mobileMenu.hide()"
|
||||
>
|
||||
<i class="pi pi-chart-line topbar-icon"></i>
|
||||
{{ t('libraryStats') }}
|
||||
</button>
|
||||
</li>
|
||||
}
|
||||
@if (currentUser.permissions?.canAccessUserStats || currentUser.permissions?.admin) {
|
||||
<li>
|
||||
<button
|
||||
class="mobile-menu-item"
|
||||
(click)="navigateToUserStats(); mobileMenu.hide()"
|
||||
>
|
||||
<i class="pi pi-users topbar-icon"></i>
|
||||
{{ t('readingStats') }}
|
||||
</button>
|
||||
</li>
|
||||
}
|
||||
@if (currentUser.permissions?.canManageLibrary || currentUser.permissions?.admin) {
|
||||
<li>
|
||||
<button
|
||||
class="mobile-menu-item"
|
||||
(click)="navigateToMetadataManager(); mobileMenu.hide()"
|
||||
>
|
||||
<i class="pi pi-sparkles topbar-icon"></i>
|
||||
{{ t('metadataManager') }}
|
||||
</button>
|
||||
</li>
|
||||
}
|
||||
}
|
||||
<li>
|
||||
<button
|
||||
class="mobile-menu-item"
|
||||
(click)="navigateToSettings(); mobileMenu.hide()"
|
||||
>
|
||||
<i class="pi pi-cog topbar-icon"></i>
|
||||
{{ t('settings') }}
|
||||
</button>
|
||||
</li>
|
||||
<li>
|
||||
<a
|
||||
class="mobile-menu-item"
|
||||
href="https://grimmory.org/docs/getting-started"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer">
|
||||
<i class="pi pi-info-circle topbar-icon"></i>
|
||||
{{ t('documentation') }}
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<button
|
||||
class="mobile-menu-item"
|
||||
(click)="langMenuMobile.toggle($event)"
|
||||
>
|
||||
<i class="pi pi-language topbar-icon"></i>
|
||||
{{ t('language') }}
|
||||
</button>
|
||||
<p-menu #langMenuMobile [model]="langMenuItems" [popup]="true"/>
|
||||
</li>
|
||||
|
||||
@if (user(); as currentUser) {
|
||||
@if (!currentUser.permissions?.demoUser) {
|
||||
<li>
|
||||
<button
|
||||
class="mobile-menu-item"
|
||||
(click)="openUserProfileDialog(); mobileMenu.hide()"
|
||||
>
|
||||
<i class="pi pi-user topbar-icon"></i>
|
||||
{{ t('profile') }}
|
||||
</button>
|
||||
</li>
|
||||
}
|
||||
}
|
||||
|
||||
<li>
|
||||
<button
|
||||
class="mobile-menu-item"
|
||||
(click)="logout(); mobileMenu.hide()"
|
||||
>
|
||||
<i class="pi pi-sign-out topbar-icon"></i>
|
||||
{{ t('logout') }}
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
</p-popover>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
@@ -0,0 +1,243 @@
|
||||
.topbar-logo {
|
||||
padding-left: 1.25rem;
|
||||
padding-right: 6rem;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.logo-text {
|
||||
font-size: 1.875rem;
|
||||
line-height: 2.25rem;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.topbar-content {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
gap: 1rem;
|
||||
|
||||
@media (max-width: 767px) {
|
||||
gap: 0.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
.topbar-search {
|
||||
flex-grow: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.topbar-desktop-items {
|
||||
display: none;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
margin-left: auto;
|
||||
padding-left: 1rem;
|
||||
|
||||
@media (min-width: 768px) {
|
||||
display: flex;
|
||||
}
|
||||
}
|
||||
|
||||
.topbar-action-group {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.topbar-icon {
|
||||
color: var(--p-surface-100);
|
||||
}
|
||||
|
||||
.topbar-item-relative {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.heart-button {
|
||||
overflow: visible;
|
||||
cursor: pointer;
|
||||
position: relative;
|
||||
|
||||
&:hover .heart-icon {
|
||||
animation: heartbeat 0.6s ease-in-out;
|
||||
filter: drop-shadow(0 0 8px rgba(236, 72, 153, 0.8));
|
||||
}
|
||||
|
||||
&:hover .heart-ripple {
|
||||
animation: ripple-burst 1.2s ease-out infinite;
|
||||
}
|
||||
|
||||
&:hover .heart-ripple-delayed {
|
||||
animation-delay: 0.4s;
|
||||
}
|
||||
}
|
||||
|
||||
.heart-ripple {
|
||||
position: absolute;
|
||||
z-index: -1;
|
||||
inset: 0;
|
||||
border-radius: 50%;
|
||||
border: 1.5px solid #ec4899;
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.heart-orbit {
|
||||
position: absolute;
|
||||
z-index: 11;
|
||||
width: 4px;
|
||||
height: 4px;
|
||||
border-radius: 50%;
|
||||
pointer-events: none;
|
||||
top: calc(50% - 2px);
|
||||
left: calc(50% - 2px);
|
||||
}
|
||||
|
||||
.heart-orbit-1 {
|
||||
background: #f472b6;
|
||||
box-shadow: 0 0 10px #f472b6, 0 0 4px #f472b6;
|
||||
animation: orbit-1 2.5s linear infinite;
|
||||
}
|
||||
|
||||
.heart-orbit-2 {
|
||||
background: #a78bfa;
|
||||
box-shadow: 0 0 10px #a78bfa, 0 0 4px #a78bfa;
|
||||
animation: orbit-2 3.2s linear infinite reverse;
|
||||
}
|
||||
|
||||
.heart-orbit-3 {
|
||||
background: #38bdf8;
|
||||
box-shadow: 0 0 10px #38bdf8, 0 0 4px #38bdf8;
|
||||
animation: orbit-3 4s linear infinite;
|
||||
}
|
||||
|
||||
.heart-icon {
|
||||
z-index: 10;
|
||||
color: #e8366d !important;
|
||||
font-size: 1.05rem;
|
||||
animation: heart-float 2.5s ease-in-out infinite;
|
||||
filter: drop-shadow(0 0 6px rgba(232, 54, 109, 0.8));
|
||||
transition: filter 0.3s;
|
||||
}
|
||||
|
||||
.heart-button-static {
|
||||
.heart-icon {
|
||||
animation: none;
|
||||
filter: none;
|
||||
}
|
||||
|
||||
&:hover .heart-icon {
|
||||
animation: none;
|
||||
filter: none;
|
||||
}
|
||||
}
|
||||
|
||||
.mobile-trigger {
|
||||
display: none;
|
||||
position: relative;
|
||||
margin-left: auto;
|
||||
|
||||
@media (max-width: 767px) {
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
|
||||
.mobile-menu-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.25rem;
|
||||
width: 12rem;
|
||||
}
|
||||
|
||||
.mobile-menu-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
width: 100%;
|
||||
text-align: left;
|
||||
padding: 0.5rem;
|
||||
border-radius: 0.25rem;
|
||||
background: none;
|
||||
border: none;
|
||||
color: inherit;
|
||||
font: inherit;
|
||||
cursor: pointer;
|
||||
text-decoration: none;
|
||||
|
||||
&:hover {
|
||||
background: var(--p-surface-700);
|
||||
}
|
||||
}
|
||||
|
||||
.highlight {
|
||||
color: red !important;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
0% { transform: rotate(0deg); }
|
||||
100% { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
.spin {
|
||||
animation: spin 1.5s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes orbit-1 {
|
||||
0% { transform: rotate(0deg) translateX(16px) rotate(0deg); }
|
||||
100% { transform: rotate(360deg) translateX(16px) rotate(-360deg); }
|
||||
}
|
||||
|
||||
@keyframes orbit-2 {
|
||||
0% { transform: rotate(120deg) translateX(14px) rotate(-120deg); }
|
||||
100% { transform: rotate(480deg) translateX(14px) rotate(-480deg); }
|
||||
}
|
||||
|
||||
@keyframes orbit-3 {
|
||||
0% { transform: rotate(240deg) translateX(18px) rotate(-240deg); }
|
||||
100% { transform: rotate(600deg) translateX(18px) rotate(-600deg); }
|
||||
}
|
||||
|
||||
@keyframes ripple-burst {
|
||||
0% { transform: scale(0.8); opacity: 0.6; }
|
||||
100% { transform: scale(2.2); opacity: 0; }
|
||||
}
|
||||
|
||||
@keyframes heart-float {
|
||||
0%, 100% { transform: translateY(1px); }
|
||||
50% { transform: translateY(-1px); }
|
||||
}
|
||||
|
||||
@keyframes heartbeat {
|
||||
0% { transform: scale(1); }
|
||||
25% { transform: scale(1.35); }
|
||||
40% { transform: scale(0.95); }
|
||||
55% { transform: scale(1.2); }
|
||||
100% { transform: scale(1); }
|
||||
}
|
||||
|
||||
@keyframes pulsate {
|
||||
0% { transform: scale(1); opacity: 1; }
|
||||
50% { transform: scale(1.25); opacity: 0.8; }
|
||||
100% { transform: scale(1); opacity: 1; }
|
||||
}
|
||||
|
||||
.pulsating {
|
||||
animation: pulsate 1.5s infinite ease-in-out;
|
||||
}
|
||||
|
||||
.notification-badge {
|
||||
position: absolute;
|
||||
top: -0.4rem;
|
||||
right: -0.4rem;
|
||||
background-color: red;
|
||||
color: white;
|
||||
border-radius: 50%;
|
||||
width: 1.2rem;
|
||||
height: 1.2rem;
|
||||
font-size: 0.75rem;
|
||||
font-weight: 600;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
pointer-events: none;
|
||||
user-select: none;
|
||||
}
|
||||
@@ -0,0 +1,328 @@
|
||||
import {Component, computed, effect, ElementRef, inject, OnDestroy, ViewChild} from '@angular/core';
|
||||
import {MenuItem} from 'primeng/api';
|
||||
import {LayoutService} from '../layout-main/service/app.layout.service';
|
||||
import {Router, RouterLink} from '@angular/router';
|
||||
import {DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {TooltipModule} from 'primeng/tooltip';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {InputTextModule} from 'primeng/inputtext';
|
||||
import {BookSearcherComponent} from '../../../../features/book/components/book-searcher/book-searcher.component';
|
||||
import {NgClass, NgStyle} from '@angular/common';
|
||||
import {NotificationEventService} from '../../../websocket/notification-event.service';
|
||||
import {Button} from 'primeng/button';
|
||||
import {StyleClass} from 'primeng/styleclass';
|
||||
import {Divider} from 'primeng/divider';
|
||||
import {ThemeConfiguratorComponent} from '../theme-configurator/theme-configurator.component';
|
||||
import {AuthService} from '../../../service/auth.service';
|
||||
import {UserService} from '../../../../features/settings/user-management/user.service';
|
||||
import {Popover} from 'primeng/popover';
|
||||
import {MetadataProgressService} from '../../../service/metadata-progress.service';
|
||||
import {takeUntil} from 'rxjs/operators';
|
||||
import {Subject} from 'rxjs';
|
||||
import {MetadataBatchProgressNotification} from '../../../model/metadata-batch-progress.model';
|
||||
import {BookdropFileService} from '../../../../features/bookdrop/service/bookdrop-file.service';
|
||||
import {DialogLauncherService} from '../../../services/dialog-launcher.service';
|
||||
import {UnifiedNotificationBoxComponent} from '../../../components/unified-notification-popover/unified-notification-popover-component';
|
||||
import {Severity, LogNotification} from '../../../websocket/model/log-notification.model';
|
||||
import {Menu} from 'primeng/menu';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
import {AVAILABLE_LANGS, LANG_LABELS} from '../../../../core/config/transloco-loader';
|
||||
import {LANG_STORAGE_KEY} from '../../../../core/config/language-initializer';
|
||||
|
||||
@Component({
|
||||
selector: 'app-topbar',
|
||||
templateUrl: './app.topbar.component.html',
|
||||
styleUrls: ['./app.topbar.component.scss'],
|
||||
standalone: true,
|
||||
imports: [
|
||||
RouterLink,
|
||||
TooltipModule,
|
||||
FormsModule,
|
||||
InputTextModule,
|
||||
BookSearcherComponent,
|
||||
Button,
|
||||
ThemeConfiguratorComponent,
|
||||
StyleClass,
|
||||
NgClass,
|
||||
Divider,
|
||||
Popover,
|
||||
UnifiedNotificationBoxComponent,
|
||||
NgStyle,
|
||||
Menu,
|
||||
TranslocoDirective,
|
||||
],
|
||||
})
|
||||
export class AppTopBarComponent implements OnDestroy {
|
||||
protected readonly userService = inject(UserService);
|
||||
protected readonly user = this.userService.currentUser;
|
||||
items!: MenuItem[];
|
||||
ref?: DynamicDialogRef;
|
||||
statsMenuItems: MenuItem[] = [];
|
||||
|
||||
@ViewChild('menubutton') menuButton!: ElementRef;
|
||||
@ViewChild('topbarmenubutton') topbarMenuButton!: ElementRef;
|
||||
@ViewChild('topbarmenu') menu!: ElementRef;
|
||||
@ViewChild('statsMenu') statsMenu: Menu | undefined;
|
||||
|
||||
isMenuVisible = true;
|
||||
progressHighlight = false;
|
||||
completedTaskCount = 0;
|
||||
hasActiveOrCompletedTasks = false;
|
||||
showPulse = false;
|
||||
hasAnyTasks = false;
|
||||
hasPendingBookdropFiles = false;
|
||||
|
||||
private eventTimer: number | undefined;
|
||||
private destroy$ = new Subject<void>();
|
||||
|
||||
private latestTasks: Record<string, MetadataBatchProgressNotification> = {};
|
||||
private latestHasPendingFiles = false;
|
||||
private latestNotificationSeverity?: Severity;
|
||||
|
||||
activeLang = '';
|
||||
langMenuItems: MenuItem[] = [];
|
||||
|
||||
private translocoService: TranslocoService;
|
||||
|
||||
constructor(
|
||||
public layoutService: LayoutService,
|
||||
private notificationService: NotificationEventService,
|
||||
private router: Router,
|
||||
private authService: AuthService,
|
||||
private metadataProgressService: MetadataProgressService,
|
||||
private bookdropFileService: BookdropFileService,
|
||||
private dialogLauncher: DialogLauncherService,
|
||||
translocoService: TranslocoService
|
||||
) {
|
||||
this.translocoService = translocoService;
|
||||
this.activeLang = translocoService.getActiveLang();
|
||||
this.langMenuItems = AVAILABLE_LANGS.map(lang => ({
|
||||
label: LANG_LABELS[lang] || lang,
|
||||
icon: lang === this.activeLang ? 'pi pi-check' : undefined,
|
||||
command: () => this.switchLanguage(lang),
|
||||
}));
|
||||
|
||||
this.subscribeToMetadataProgress();
|
||||
this.subscribeToNotifications();
|
||||
|
||||
this.metadataProgressService.activeTasks$
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
.subscribe((tasks) => {
|
||||
this.latestTasks = tasks;
|
||||
this.hasAnyTasks = Object.keys(tasks).length > 0;
|
||||
this.updateCompletedTaskCount();
|
||||
this.updateTaskVisibility(tasks);
|
||||
});
|
||||
|
||||
this.bookdropFileService.hasPendingFiles$
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
.subscribe((hasPending) => {
|
||||
this.latestHasPendingFiles = hasPending;
|
||||
this.hasPendingBookdropFiles = hasPending;
|
||||
this.updateCompletedTaskCount();
|
||||
this.updateTaskVisibilityWithBookdrop();
|
||||
});
|
||||
|
||||
effect(() => {
|
||||
this.user();
|
||||
this.initializeStatsMenu();
|
||||
});
|
||||
|
||||
this.translocoService.langChanges$
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
.subscribe(() => {
|
||||
this.initializeStatsMenu();
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
if (this.ref) this.ref.close();
|
||||
clearTimeout(this.eventTimer);
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
}
|
||||
|
||||
toggleMenu() {
|
||||
this.isMenuVisible = !this.isMenuVisible;
|
||||
this.layoutService.onMenuToggle();
|
||||
}
|
||||
|
||||
openLibraryCreatorDialog(): void {
|
||||
this.dialogLauncher.openLibraryCreateDialog();
|
||||
}
|
||||
|
||||
openFileUploadDialog(): void {
|
||||
this.dialogLauncher.openFileUploadDialog();
|
||||
}
|
||||
|
||||
openUserProfileDialog(): void {
|
||||
this.dialogLauncher.openUserProfileDialog();
|
||||
}
|
||||
|
||||
navigateToSettings() {
|
||||
this.router.navigate(['/settings']);
|
||||
}
|
||||
|
||||
navigateToBookdrop() {
|
||||
this.router.navigate(['/bookdrop']);
|
||||
}
|
||||
|
||||
navigateToMetadataManager() {
|
||||
this.router.navigate(['/metadata-manager']);
|
||||
}
|
||||
|
||||
navigateToStats() {
|
||||
this.router.navigate(['/library-stats']);
|
||||
}
|
||||
|
||||
navigateToUserStats() {
|
||||
this.router.navigate(['/reading-stats']);
|
||||
}
|
||||
|
||||
switchLanguage(lang: string) {
|
||||
if (lang === this.activeLang) return;
|
||||
this.translocoService.load(lang).subscribe(() => {
|
||||
this.translocoService.setActiveLang(lang);
|
||||
localStorage.setItem(LANG_STORAGE_KEY, lang);
|
||||
this.activeLang = lang;
|
||||
this.langMenuItems = AVAILABLE_LANGS.map(l => ({
|
||||
label: LANG_LABELS[l] || l,
|
||||
icon: l === lang ? 'pi pi-check' : undefined,
|
||||
command: () => this.switchLanguage(l),
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
logout() {
|
||||
this.authService.logout();
|
||||
}
|
||||
|
||||
handleStatsButtonClick(event: Event) {
|
||||
if (this.statsMenuItems.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.statsMenuItems.length === 1) {
|
||||
this.statsMenuItems[0].command?.({originalEvent: event, item: this.statsMenuItems[0]});
|
||||
}
|
||||
}
|
||||
|
||||
private subscribeToMetadataProgress() {
|
||||
this.metadataProgressService.progressUpdates$
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
.subscribe((progress) => {
|
||||
this.progressHighlight = progress.status === 'IN_PROGRESS';
|
||||
});
|
||||
}
|
||||
|
||||
private subscribeToNotifications() {
|
||||
this.notificationService.latestNotification$
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
.subscribe((notification: LogNotification) => {
|
||||
this.latestNotificationSeverity = notification.severity;
|
||||
this.triggerPulseEffect();
|
||||
});
|
||||
}
|
||||
|
||||
private triggerPulseEffect() {
|
||||
this.showPulse = true;
|
||||
clearTimeout(this.eventTimer);
|
||||
this.eventTimer = setTimeout(() => {
|
||||
this.showPulse = false;
|
||||
}, 4000) as unknown as number;
|
||||
}
|
||||
|
||||
private updateCompletedTaskCount() {
|
||||
const completedMetadataTasks = Object.values(this.latestTasks).length;
|
||||
const bookdropFileTaskCount = this.latestHasPendingFiles ? 1 : 0;
|
||||
this.completedTaskCount = completedMetadataTasks + bookdropFileTaskCount;
|
||||
}
|
||||
|
||||
private updateTaskVisibility(tasks: Record<string, MetadataBatchProgressNotification>) {
|
||||
this.hasActiveOrCompletedTasks =
|
||||
this.progressHighlight || this.completedTaskCount > 0 || Object.keys(tasks).length > 0;
|
||||
this.updateTaskVisibilityWithBookdrop();
|
||||
}
|
||||
|
||||
private updateTaskVisibilityWithBookdrop() {
|
||||
this.hasActiveOrCompletedTasks = this.hasActiveOrCompletedTasks || this.hasPendingBookdropFiles;
|
||||
}
|
||||
|
||||
private initializeStatsMenu() {
|
||||
const user = this.user();
|
||||
|
||||
this.statsMenuItems = [];
|
||||
|
||||
if (user?.permissions?.canAccessLibraryStats || user?.permissions?.admin) {
|
||||
this.statsMenuItems.push({
|
||||
label: this.translocoService.translate('layout.topbar.libraryStats'),
|
||||
icon: 'pi pi-chart-line',
|
||||
command: () => this.navigateToStats()
|
||||
});
|
||||
}
|
||||
|
||||
if (user?.permissions?.canAccessUserStats || user?.permissions?.admin) {
|
||||
this.statsMenuItems.push({
|
||||
label: this.translocoService.translate('layout.topbar.readingStats'),
|
||||
icon: 'pi pi-users',
|
||||
command: () => this.navigateToUserStats()
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
get hasStatsAccess(): boolean {
|
||||
return this.statsMenuItems.length > 0;
|
||||
}
|
||||
|
||||
get shouldShowStatsMenu(): boolean {
|
||||
return this.statsMenuItems.length > 1;
|
||||
}
|
||||
|
||||
get statsTooltip(): string {
|
||||
if (this.statsMenuItems.length === 0) {
|
||||
return this.translocoService.translate('layout.topbar.stats');
|
||||
}
|
||||
if (this.statsMenuItems.length === 1) {
|
||||
return this.statsMenuItems[0].label || this.translocoService.translate('layout.topbar.stats');
|
||||
}
|
||||
return this.translocoService.translate('layout.topbar.stats');
|
||||
}
|
||||
|
||||
get iconClass(): string {
|
||||
if (this.progressHighlight) return 'pi-spinner spin';
|
||||
if (this.iconPulsating) return 'pi-wave-pulse';
|
||||
if (this.completedTaskCount > 0 || this.hasPendingBookdropFiles) return 'pi-bell';
|
||||
return 'pi-wave-pulse';
|
||||
}
|
||||
|
||||
get iconColor(): string {
|
||||
if (this.progressHighlight) return 'gold';
|
||||
if (this.showPulse) {
|
||||
switch (this.latestNotificationSeverity) {
|
||||
case Severity.ERROR:
|
||||
return 'crimson';
|
||||
case Severity.INFO:
|
||||
return 'aqua';
|
||||
case Severity.WARN:
|
||||
return 'orange';
|
||||
default:
|
||||
return 'orange';
|
||||
}
|
||||
}
|
||||
if (this.completedTaskCount > 0 || this.hasPendingBookdropFiles)
|
||||
return 'limegreen';
|
||||
return 'inherit';
|
||||
}
|
||||
|
||||
get iconPulsating(): boolean {
|
||||
return !this.progressHighlight && (this.showPulse);
|
||||
}
|
||||
|
||||
get shouldShowNotificationBadge(): boolean {
|
||||
return (
|
||||
(this.completedTaskCount > 0 || this.hasPendingBookdropFiles) &&
|
||||
!this.progressHighlight &&
|
||||
!this.showPulse
|
||||
);
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
import {Injectable, inject} from '@angular/core';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {Observable, map, tap} from 'rxjs';
|
||||
import {API_CONFIG} from '../../../../core/config/api-config';
|
||||
|
||||
@Injectable({providedIn: 'root'})
|
||||
export class BackgroundUploadService {
|
||||
private readonly baseUrl = `${API_CONFIG.BASE_URL}/api/v1/background`;
|
||||
private readonly http = inject(HttpClient);
|
||||
|
||||
uploadFile(file: File): Observable<string> {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
return this.http.post<{ url: string }>(`${this.baseUrl}/upload`, formData).pipe(
|
||||
tap(response => console.log('File upload response:', response)),
|
||||
map(resp => resp?.url)
|
||||
);
|
||||
}
|
||||
|
||||
uploadUrl(url: string): Observable<string> {
|
||||
return this.http.post<{ url: string }>(`${this.baseUrl}/url`, {url}).pipe(
|
||||
tap(response => console.log('URL upload response:', response)),
|
||||
map(resp => resp?.url)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
|
||||
@Injectable({providedIn: 'root'})
|
||||
export class FaviconService {
|
||||
private svgTemplate = (color: string) => `
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 126 126" fill="currentColor">
|
||||
<path d="M59 4.79297C71.5051 11.5557 80 24.7854 80 40C80 40.5959 79.987 41.1888 79.9609 41.7783C79.8609 44.0406 81.7355 46 84 46C106.091 46 124 63.9086 124 86C124 108.091 106.091 126 84 126H10C4.47715 126 0 121.523 0 116V39.0068L0.0126953 38.9941C0.357624 25.0252 7.86506 12.8347 19 5.95215V63.832C19 64.8345 20.0676 65.4391 20.9121 64.9902L21.0771 64.8867L38.2227 52.3428C38.6819 52.0068 39.3064 52.0068 39.7656 52.3428L56.9229 64.8945L57.0879 64.998C57.9324 65.447 59 64.8423 59 63.8398V4.79297Z" fill="${color}"/>
|
||||
<path d="M40 0C43.8745 0 47.6199 0.552381 51.1631 1.58008V50.9697L44.3926 46.0176L44.0879 45.8037C40.9061 43.6679 36.7098 43.7393 33.5957 46.0176L26.8369 50.9619V2.21875C30.9593 0.782634 35.3881 0 40 0Z" fill="white"/>
|
||||
</svg>
|
||||
`;
|
||||
|
||||
updateFavicon(color: string) {
|
||||
const svg = this.svgTemplate(color);
|
||||
const blob = new Blob([svg], {type: 'image/svg+xml'});
|
||||
const url = URL.createObjectURL(blob);
|
||||
|
||||
let favicon = document.querySelector("link[rel*='icon']") as HTMLLinkElement;
|
||||
if (!favicon) {
|
||||
favicon = document.createElement('link');
|
||||
favicon.rel = 'icon';
|
||||
document.head.appendChild(favicon);
|
||||
}
|
||||
|
||||
favicon.type = 'image/svg+xml';
|
||||
favicon.href = url;
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
<ng-container *transloco="let t; prefix: 'layout.theme'">
|
||||
<div class="config-panel-content">
|
||||
|
||||
<div class="config-panel-colors">
|
||||
<span class="config-panel-label">{{ t('primary') }}</span>
|
||||
<div>
|
||||
@for (primaryColor of primaryColors(); track primaryColor.name) {
|
||||
<button
|
||||
type="button"
|
||||
[title]="primaryColor.name"
|
||||
(click)="updateColors($event, 'primary', primaryColor)"
|
||||
[ngClass]="{ 'active-color': primaryColor.name === selectedPrimaryColor() }"
|
||||
[style]="{ 'background-color': primaryColor.name === 'noir' ? 'var(--text-color)' : primaryColor.palette['500'] || 'transparent' }"
|
||||
></button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="config-panel-colors">
|
||||
<span class="config-panel-label">{{ t('surface') }}</span>
|
||||
<div>
|
||||
@for (surface of surfaces; track surface.name) {
|
||||
<button
|
||||
type="button"
|
||||
[title]="surface.name"
|
||||
(click)="updateColors($event, 'surface', surface)"
|
||||
[ngClass]="{ 'active-color': selectedSurfaceColor() ? selectedSurfaceColor() === surface.name : surface.name === 'zinc' }"
|
||||
[style]="{'background-color': surface.name === 'noir' ? 'var(--text-color)' : surface.palette['500'] }">
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</ng-container>
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {ChangeDetectionStrategy, Component, computed, effect, inject} from '@angular/core';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {ButtonModule} from 'primeng/button';
|
||||
import {RadioButtonModule} from 'primeng/radiobutton';
|
||||
import {ToggleSwitchModule} from 'primeng/toggleswitch';
|
||||
|
||||
import Aura from '../theme-palette-extend';
|
||||
|
||||
import {AppConfigService} from '../../../service/app-config.service';
|
||||
import {TranslocoDirective} from '@jsverse/transloco';
|
||||
import {FaviconService} from './favicon-service';
|
||||
|
||||
type ColorPalette = Record<string, string>;
|
||||
|
||||
interface Palette {
|
||||
name: string;
|
||||
palette: ColorPalette;
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-theme-configurator',
|
||||
standalone: true,
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
templateUrl: './theme-configurator.component.html',
|
||||
host: {
|
||||
class: 'config-panel hidden'
|
||||
},
|
||||
imports: [
|
||||
CommonModule,
|
||||
FormsModule,
|
||||
ButtonModule,
|
||||
RadioButtonModule,
|
||||
ToggleSwitchModule,
|
||||
TranslocoDirective
|
||||
]
|
||||
})
|
||||
export class ThemeConfiguratorComponent {
|
||||
readonly configService = inject(AppConfigService);
|
||||
readonly faviconService = inject(FaviconService);
|
||||
|
||||
readonly surfaces = this.configService.surfaces;
|
||||
|
||||
readonly selectedPrimaryColor = computed(() => this.configService.appState().primary);
|
||||
readonly selectedSurfaceColor = computed(() => this.configService.appState().surface);
|
||||
|
||||
readonly faviconColor = computed(() => {
|
||||
const name = this.selectedPrimaryColor() ?? 'green';
|
||||
const presetPalette = (Aura.primitive ?? {}) as Record<string, ColorPalette>;
|
||||
const colorPalette = presetPalette[name];
|
||||
return colorPalette?.[500] ?? name;
|
||||
});
|
||||
|
||||
private readonly _faviconSyncEffect = effect(() => {
|
||||
this.faviconService.updateFavicon(this.faviconColor());
|
||||
});
|
||||
|
||||
readonly primaryColors = computed<Palette[]>(() => {
|
||||
const presetPalette = (Aura.primitive ?? {}) as Record<string, ColorPalette>;
|
||||
const colors = [
|
||||
'emerald', 'green', 'lime', 'orange', 'amber', 'yellow',
|
||||
'teal', 'cyan', 'sky', 'blue', 'indigo', 'violet',
|
||||
'purple', 'fuchsia', 'pink', 'rose', 'red',
|
||||
'coralSunset', 'roseBlush', 'melonBlush', 'cottonCandy',
|
||||
'apricotSunrise', 'antiqueBronze', 'butteryYellow', 'vanillaCream',
|
||||
'citrusMint', 'freshMint', 'sagePearl', 'skyBlue','periwinkleCream',
|
||||
'pastelRoyalBlue', 'lavenderDream', 'dustyNeutral'
|
||||
];
|
||||
return [{name: 'noir', palette: {}}].concat(
|
||||
colors.map(name => ({
|
||||
name,
|
||||
palette: presetPalette[name] ?? {}
|
||||
}))
|
||||
);
|
||||
});
|
||||
|
||||
updateColors(event: Event, type: 'primary' | 'surface', color: { name: string; palette?: ColorPalette }) {
|
||||
this.configService.appState.update((state) => ({
|
||||
...state,
|
||||
[type]: color.name
|
||||
}));
|
||||
event.stopPropagation();
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
<ng-container *transloco="let t; prefix: 'layout.uploadDialog'">
|
||||
<div class="upload-dialog-content">
|
||||
<div class="upload-section">
|
||||
<div class="file-selector">
|
||||
<label class="file-label">{{ t('chooseFile') }}</label>
|
||||
<p-button
|
||||
[label]="t('selectImage')"
|
||||
icon="pi pi-upload"
|
||||
(click)="fileInput.click()"
|
||||
outlined
|
||||
severity="info">
|
||||
</p-button>
|
||||
</div>
|
||||
<input
|
||||
#fileInput
|
||||
type="file"
|
||||
accept=".jpg,.jpeg,.png,image/jpeg,image/png"
|
||||
(change)="onFileSelected($event)"
|
||||
style="display: none;">
|
||||
<small class="file-note">{{ t('fileNote') }}</small>
|
||||
@if (uploadFile) {
|
||||
<small class="selected-file">{{ uploadFile.name }}</small>
|
||||
}
|
||||
</div>
|
||||
|
||||
<p-divider align="center" type="solid">
|
||||
<span class="or-text">{{ t('or') }}</span>
|
||||
</p-divider>
|
||||
|
||||
<div class="url-section">
|
||||
<label for="urlInput" class="url-label">{{ t('imageUrl') }}</label>
|
||||
<input
|
||||
id="urlInput"
|
||||
type="text"
|
||||
[(ngModel)]="uploadImageUrl"
|
||||
[placeholder]="t('urlPlaceholder')"
|
||||
class="url-input"
|
||||
pInputText>
|
||||
<small class="url-note">{{ t('urlNote') }}</small>
|
||||
</div>
|
||||
|
||||
@if (uploadError) {
|
||||
<p-message severity="error">{{uploadError}}</p-message>
|
||||
}
|
||||
|
||||
<div class="dialog-footer">
|
||||
<p-button
|
||||
[label]="'common.cancel' | transloco"
|
||||
icon="pi pi-times"
|
||||
(click)="cancel()"
|
||||
severity="secondary"
|
||||
outlined>
|
||||
</p-button>
|
||||
<p-button
|
||||
[label]="'common.submit' | transloco"
|
||||
icon="pi pi-check"
|
||||
(click)="submit()">
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
.upload-dialog-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1.5rem;
|
||||
padding: 1rem 0;
|
||||
|
||||
.upload-section {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
margin-bottom: 1rem;
|
||||
|
||||
.file-selector {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.file-label {
|
||||
font-weight: 500;
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
.file-input {
|
||||
padding: 0.75rem;
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: var(--p-border-radius);
|
||||
background: var(--ground-background);
|
||||
}
|
||||
|
||||
.file-note {
|
||||
color: var(--text-secondary-color);
|
||||
font-size: 0.875rem;
|
||||
margin-top: 0.25rem;
|
||||
}
|
||||
|
||||
.selected-file {
|
||||
color: var(--text-secondary-color);
|
||||
font-style: italic;
|
||||
}
|
||||
}
|
||||
|
||||
.url-section {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.25rem;
|
||||
|
||||
.url-label {
|
||||
font-weight: 500;
|
||||
color: var(--text-color);
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.url-input {
|
||||
width: 100%;
|
||||
padding: 0.75rem;
|
||||
}
|
||||
|
||||
.url-note {
|
||||
color: var(--text-secondary-color);
|
||||
font-size: 0.875rem;
|
||||
margin-top: 0.25rem;
|
||||
}
|
||||
}
|
||||
|
||||
.or-text {
|
||||
font-size: 0.9rem;
|
||||
color: var(--text-color);
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
p-message {
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
.dialog-footer {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
justify-content: flex-end;
|
||||
margin-top: 1rem;
|
||||
}
|
||||
}
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
import {Component, inject} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {ButtonModule} from 'primeng/button';
|
||||
import {InputTextModule} from 'primeng/inputtext';
|
||||
import {DividerModule} from 'primeng/divider';
|
||||
import {MessageModule} from 'primeng/message';
|
||||
import {BackgroundUploadService} from '../background-upload.service';
|
||||
import {take} from 'rxjs';
|
||||
import {TranslocoDirective, TranslocoPipe, TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
@Component({
|
||||
selector: 'app-upload-dialog',
|
||||
standalone: true,
|
||||
templateUrl: './upload-dialog.component.html',
|
||||
styleUrls: ['./upload-dialog.component.scss'],
|
||||
imports: [
|
||||
CommonModule,
|
||||
FormsModule,
|
||||
ButtonModule,
|
||||
InputTextModule,
|
||||
DividerModule,
|
||||
MessageModule,
|
||||
TranslocoDirective,
|
||||
TranslocoPipe
|
||||
]
|
||||
})
|
||||
export class UploadDialogComponent {
|
||||
private readonly dialogRef = inject(DynamicDialogRef);
|
||||
private readonly backgroundUploadService = inject(BackgroundUploadService);
|
||||
private readonly t = inject(TranslocoService);
|
||||
|
||||
uploadImageUrl = '';
|
||||
uploadFile: File | null = null;
|
||||
uploadError = '';
|
||||
|
||||
onFileSelected(event: Event) {
|
||||
const input = event.target as HTMLInputElement;
|
||||
if (input.files && input.files.length > 0) {
|
||||
this.uploadFile = input.files[0];
|
||||
this.uploadImageUrl = '';
|
||||
}
|
||||
}
|
||||
|
||||
submit() {
|
||||
this.uploadError = '';
|
||||
let upload$;
|
||||
if (this.uploadFile) {
|
||||
upload$ = this.backgroundUploadService.uploadFile(this.uploadFile);
|
||||
} else if (this.uploadImageUrl.trim()) {
|
||||
upload$ = this.backgroundUploadService.uploadUrl(this.uploadImageUrl.trim());
|
||||
} else {
|
||||
this.uploadError = this.t.translate('layout.uploadDialog.errorNoInput');
|
||||
return;
|
||||
}
|
||||
|
||||
upload$.pipe(take(1)).subscribe({
|
||||
next: (imageUrl) => {
|
||||
if (imageUrl) {
|
||||
this.dialogRef.close({ imageUrl });
|
||||
} else {
|
||||
this.uploadError = 'Failed to upload image.';
|
||||
}
|
||||
},
|
||||
error: (err) => {
|
||||
console.error('Upload failed:', err);
|
||||
this.uploadError = 'Upload failed. Please try again.';
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
cancel() {
|
||||
this.dialogRef.close();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,222 @@
|
||||
import Aura from '@primeuix/themes/aura';
|
||||
|
||||
type ColorPalette = Record<string, string>;
|
||||
|
||||
const customPalettes: Record<string, ColorPalette> = {
|
||||
coralSunset: {
|
||||
50: '#fef7f0',
|
||||
100: '#feede1',
|
||||
200: '#fcd9c2',
|
||||
300: '#f9be9e',
|
||||
400: '#f59673',
|
||||
500: '#ef7550',
|
||||
600: '#de5a3a',
|
||||
700: '#b94730',
|
||||
800: '#943a2e',
|
||||
900: '#78322a',
|
||||
950: '#401814'
|
||||
},
|
||||
roseBlush: {
|
||||
50: '#fef7f7',
|
||||
100: '#feebeb',
|
||||
200: '#fddcdc',
|
||||
300: '#fbbfbf',
|
||||
400: '#f69393',
|
||||
500: '#ed6767',
|
||||
600: '#d93f3f',
|
||||
700: '#b73030',
|
||||
800: '#982d2d',
|
||||
900: '#7f2d2d',
|
||||
950: '#451313'
|
||||
},
|
||||
melonBlush: {
|
||||
50: '#fffafb',
|
||||
100: '#fff2f4',
|
||||
200: '#ffdfe7',
|
||||
300: '#ffcbd4',
|
||||
400: '#ffaebb',
|
||||
500: '#ff90a2',
|
||||
600: '#ff6f88',
|
||||
700: '#e8506b',
|
||||
800: '#b7384d',
|
||||
900: '#7f2231',
|
||||
950: '#3f1118'
|
||||
},
|
||||
cottonCandy: {
|
||||
50: '#fff9fb',
|
||||
100: '#fff0f6',
|
||||
200: '#ffdfee',
|
||||
300: '#ffc0e0',
|
||||
400: '#ffa3cf',
|
||||
500: '#ff86bf',
|
||||
600: '#ff69ad',
|
||||
700: '#e14f93',
|
||||
800: '#b93a72',
|
||||
900: '#86284f',
|
||||
950: '#42142a'
|
||||
},
|
||||
apricotSunrise: {
|
||||
50: '#fffaf7',
|
||||
100: '#fff1e8',
|
||||
200: '#ffe2c9',
|
||||
300: '#ffd2a8',
|
||||
400: '#ffbf88',
|
||||
500: '#ffad68',
|
||||
600: '#ff974f',
|
||||
700: '#e67a3b',
|
||||
800: '#b6572b',
|
||||
900: '#7f351b',
|
||||
950: '#3f190f'
|
||||
},
|
||||
antiqueBronze: {
|
||||
50: '#faf7f2',
|
||||
100: '#f4ede0',
|
||||
200: '#e8d9c0',
|
||||
300: '#d9c199',
|
||||
400: '#c8a56f',
|
||||
500: '#b8904f',
|
||||
600: '#a67c44',
|
||||
700: '#8a6439',
|
||||
800: '#715233',
|
||||
900: '#5c442c',
|
||||
950: '#302316'
|
||||
},
|
||||
butteryYellow: {
|
||||
50: '#fffef7',
|
||||
100: '#fffceb',
|
||||
200: '#fff7d1',
|
||||
300: '#ffeea7',
|
||||
400: '#ffe072',
|
||||
500: '#ffcf45',
|
||||
600: '#ffb61f',
|
||||
700: '#ff9b0a',
|
||||
800: '#cc7606',
|
||||
900: '#a35f0c',
|
||||
950: '#633204'
|
||||
},
|
||||
vanillaCream: {
|
||||
50: '#fefdfb',
|
||||
100: '#fefbf6',
|
||||
200: '#fdf5ea',
|
||||
300: '#fbecd5',
|
||||
400: '#f7dbb5',
|
||||
500: '#f1c589',
|
||||
600: '#e8a95c',
|
||||
700: '#d88d3e',
|
||||
800: '#b47134',
|
||||
900: '#915c2e',
|
||||
950: '#4e2f17'
|
||||
},
|
||||
citrusMint: {
|
||||
50: '#fbfff9',
|
||||
100: '#f4fff2',
|
||||
200: '#e8ffd9',
|
||||
300: '#d1ffbc',
|
||||
400: '#b7ffa0',
|
||||
500: '#96ff84',
|
||||
600: '#76e96e',
|
||||
700: '#4fb84c',
|
||||
800: '#2f7f32',
|
||||
900: '#1a4f20',
|
||||
950: '#0a2410'
|
||||
},
|
||||
freshMint: {
|
||||
50: '#f8fff9',
|
||||
100: '#f0fff3',
|
||||
200: '#dcffea',
|
||||
300: '#bfffd6',
|
||||
400: '#99ffc2',
|
||||
500: '#7fffae',
|
||||
600: '#5fe592',
|
||||
700: '#3fbf75',
|
||||
800: '#2d8f55',
|
||||
900: '#1e5f39',
|
||||
950: '#0f2f1d'
|
||||
},
|
||||
sagePearl: {
|
||||
50: '#fbfdfb',
|
||||
100: '#f4f8f4',
|
||||
200: '#e6efe6',
|
||||
300: '#d1e6d1',
|
||||
400: '#bcdcbf',
|
||||
500: '#9fcfa8',
|
||||
600: '#84b792',
|
||||
700: '#5f8f6e',
|
||||
800: '#3f6648',
|
||||
900: '#25442e',
|
||||
950: '#0f2118'
|
||||
},
|
||||
skyBlue: {
|
||||
50: '#f7fbff',
|
||||
100: '#eef6ff',
|
||||
200: '#dceefd',
|
||||
300: '#c1e8ff',
|
||||
400: '#99dfff',
|
||||
500: '#6fc8ff',
|
||||
600: '#48afff',
|
||||
700: '#2e88e6',
|
||||
800: '#2360b3',
|
||||
900: '#153d80',
|
||||
950: '#071d40'
|
||||
},
|
||||
periwinkleCream: {
|
||||
50: '#fbfbff',
|
||||
100: '#f2f3ff',
|
||||
200: '#e7eaff',
|
||||
300: '#d2dcff',
|
||||
400: '#b9c9ff',
|
||||
500: '#9fb2ff',
|
||||
600: '#7f97ff',
|
||||
700: '#5f78e6',
|
||||
800: '#4559b3',
|
||||
900: '#2b387f',
|
||||
950: '#151c40'
|
||||
},
|
||||
pastelRoyalBlue: {
|
||||
50: '#f6fbff',
|
||||
100: '#eef6ff',
|
||||
200: '#dbeeff',
|
||||
300: '#b9ddff',
|
||||
400: '#92c7ff',
|
||||
500: '#63aaff',
|
||||
600: '#3b88ff',
|
||||
700: '#2e66cc',
|
||||
800: '#235099',
|
||||
900: '#183366',
|
||||
950: '#0d1a33'
|
||||
},
|
||||
lavenderDream: {
|
||||
50: '#fbf7ff',
|
||||
100: '#f6eeff',
|
||||
200: '#ebdcff',
|
||||
300: '#dcc0ff',
|
||||
400: '#caa1ff',
|
||||
500: '#b47fff',
|
||||
600: '#9366e6',
|
||||
700: '#6f45b3',
|
||||
800: '#4c2f80',
|
||||
900: '#2d1b4f',
|
||||
950: '#15082a'
|
||||
},
|
||||
dustyNeutral: {
|
||||
50: '#faf9f7',
|
||||
100: '#f3f1ed',
|
||||
200: '#e8e3db',
|
||||
300: '#d8cfc2',
|
||||
400: '#c4b5a3',
|
||||
500: '#b39c85',
|
||||
600: '#a28a70',
|
||||
700: '#87725d',
|
||||
800: '#6f5e4e',
|
||||
900: '#5a4e42',
|
||||
950: '#2f2821'
|
||||
}
|
||||
};
|
||||
|
||||
if (!Aura.primitive) {
|
||||
Aura.primitive = {};
|
||||
}
|
||||
|
||||
Object.assign(Aura.primitive, customPalettes);
|
||||
|
||||
export default Aura;
|
||||
Reference in New Issue
Block a user