WIP: Arrange UI files for better structuring
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 layout-sidebar-custom">
|
||||
<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,130 @@
|
||||
import { Component, OnDestroy, 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 "./app.sidebar.component";
|
||||
import { AppTopBarComponent } from './app.topbar.component';
|
||||
import {NgClass} from '@angular/common';
|
||||
import {ToastModule} from 'primeng/toast';
|
||||
|
||||
@Component({
|
||||
selector: 'app-layout',
|
||||
imports: [
|
||||
RouterOutlet,
|
||||
AppSidebarComponent,
|
||||
AppTopBarComponent,
|
||||
NgClass,
|
||||
ToastModule
|
||||
],
|
||||
templateUrl: './app.layout.component.html'
|
||||
})
|
||||
export class AppLayoutComponent implements OnDestroy {
|
||||
|
||||
overlayMenuOpenSubscription: Subscription;
|
||||
|
||||
menuOutsideClickListener: any;
|
||||
|
||||
profileMenuOutsideClickListener: any;
|
||||
|
||||
@ViewChild(AppSidebarComponent) appSidebar!: AppSidebarComponent;
|
||||
|
||||
@ViewChild(AppTopBarComponent) appTopbar!: AppTopBarComponent;
|
||||
|
||||
constructor(public layoutService: LayoutService, public renderer: Renderer2, public router: Router) {
|
||||
this.overlayMenuOpenSubscription = this.layoutService.overlayOpen$.subscribe(() => {
|
||||
if (!this.menuOutsideClickListener) {
|
||||
this.menuOutsideClickListener = this.renderer.listen('document', 'click', event => {
|
||||
const isOutsideClicked = !(this.appSidebar.el.nativeElement.isSameNode(event.target) || this.appSidebar.el.nativeElement.contains(event.target)
|
||||
|| this.appTopbar.menuButton.nativeElement.isSameNode(event.target) || this.appTopbar.menuButton.nativeElement.contains(event.target));
|
||||
|
||||
if (isOutsideClicked) {
|
||||
this.hideMenu();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (!this.profileMenuOutsideClickListener) {
|
||||
this.profileMenuOutsideClickListener = this.renderer.listen('document', 'click', event => {
|
||||
const isOutsideClicked = !(this.appTopbar.menu.nativeElement.isSameNode(event.target) || this.appTopbar.menu.nativeElement.contains(event.target)
|
||||
|| this.appTopbar.topbarMenuButton.nativeElement.isSameNode(event.target) || this.appTopbar.topbarMenuButton.nativeElement.contains(event.target));
|
||||
|
||||
if (isOutsideClicked) {
|
||||
this.hideProfileMenu();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (this.layoutService.state.staticMenuMobileActive) {
|
||||
this.blockBodyScroll();
|
||||
}
|
||||
});
|
||||
|
||||
this.router.events.pipe(filter(event => event instanceof NavigationEnd))
|
||||
.subscribe(() => {
|
||||
this.hideMenu();
|
||||
this.hideProfileMenu();
|
||||
});
|
||||
}
|
||||
|
||||
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-theme-light': this.layoutService.config().colorScheme === 'light',
|
||||
'layout-theme-dark': this.layoutService.config().colorScheme === 'dark',
|
||||
'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,
|
||||
'p-input-filled': this.layoutService.config().inputStyle === 'filled',
|
||||
'p-ripple-disabled': !this.layoutService.config().ripple
|
||||
}
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
if (this.overlayMenuOpenSubscription) {
|
||||
this.overlayMenuOpenSubscription.unsubscribe();
|
||||
}
|
||||
|
||||
if (this.menuOutsideClickListener) {
|
||||
this.menuOutsideClickListener();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { BrowserModule } from '@angular/platform-browser';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { HttpClientModule } from '@angular/common/http';
|
||||
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
||||
import { InputTextModule } from 'primeng/inputtext';
|
||||
import { SidebarModule } from 'primeng/sidebar';
|
||||
import { BadgeModule } from 'primeng/badge';
|
||||
import { RadioButtonModule } from 'primeng/radiobutton';
|
||||
import { InputSwitchModule } from 'primeng/inputswitch';
|
||||
import { RippleModule } from 'primeng/ripple';
|
||||
import { AppMenuComponent } from './app.menu.component';
|
||||
import { AppMenuitemComponent } from './app.menuitem.component';
|
||||
import { RouterModule } from '@angular/router';
|
||||
import { AppTopBarComponent } from './app.topbar.component';
|
||||
import { AppSidebarComponent } from "./app.sidebar.component";
|
||||
|
||||
@NgModule({
|
||||
declarations: [
|
||||
|
||||
],
|
||||
imports: [
|
||||
BrowserModule,
|
||||
FormsModule,
|
||||
HttpClientModule,
|
||||
BrowserAnimationsModule,
|
||||
InputTextModule,
|
||||
SidebarModule,
|
||||
BadgeModule,
|
||||
RadioButtonModule,
|
||||
InputSwitchModule,
|
||||
RippleModule,
|
||||
RouterModule,
|
||||
AppMenuitemComponent,
|
||||
AppTopBarComponent,
|
||||
AppMenuComponent,
|
||||
AppSidebarComponent,
|
||||
]
|
||||
})
|
||||
export class AppLayoutModule { }
|
||||
@@ -0,0 +1,26 @@
|
||||
<ul class="layout-menu">
|
||||
<ng-container *ngIf="homeMenu$ | async as homeMenu">
|
||||
<ng-container *ngFor="let item of homeMenu; let i = index;">
|
||||
<li app-menuitem *ngIf="!item.separator" [item]="item" [index]="i" [root]="true"></li>
|
||||
<li *ngIf="item.separator" class="menu-separator"></li>
|
||||
</ng-container>
|
||||
</ng-container>
|
||||
</ul>
|
||||
|
||||
<ul class="layout-menu">
|
||||
<ng-container *ngIf="libraryMenu$ | async as libraryMenu">
|
||||
<ng-container *ngFor="let item of libraryMenu; let i = index;">
|
||||
<li app-menuitem *ngIf="!item.separator" [item]="item" [index]="i" [root]="true"></li>
|
||||
<li *ngIf="item.separator" class="menu-separator"></li>
|
||||
</ng-container>
|
||||
</ng-container>
|
||||
</ul>
|
||||
|
||||
<ul class="layout-menu">
|
||||
<ng-container *ngIf="shelfMenu$ | async as shelfMenu">
|
||||
<ng-container *ngFor="let item of shelfMenu; let i = index;">
|
||||
<li app-menuitem *ngIf="!item.separator" [item]="item" [index]="i" [root]="true"></li>
|
||||
<li *ngIf="item.separator" class="menu-separator"></li>
|
||||
</ng-container>
|
||||
</ng-container>
|
||||
</ul>
|
||||
@@ -0,0 +1,80 @@
|
||||
import {Component, OnInit} from '@angular/core';
|
||||
import {AppMenuitemComponent} from './app.menuitem.component';
|
||||
import {AsyncPipe, NgForOf, NgIf} from '@angular/common';
|
||||
import {MenuModule} from 'primeng/menu';
|
||||
import {LibraryService} from '../book/service/library.service';
|
||||
import {Observable, of} from 'rxjs';
|
||||
import {map} from 'rxjs/operators';
|
||||
import {ShelfService} from '../book/service/shelf.service';
|
||||
import {BookService} from '../book/service/book.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-menu',
|
||||
imports: [AppMenuitemComponent, NgIf, NgForOf, MenuModule, AsyncPipe],
|
||||
templateUrl: './app.menu.component.html',
|
||||
})
|
||||
export class AppMenuComponent implements OnInit {
|
||||
libraryMenu$: Observable<any> | undefined;
|
||||
shelfMenu$: Observable<any> | undefined;
|
||||
homeMenu$: Observable<any> | undefined;
|
||||
|
||||
constructor(private libraryService: LibraryService, private shelfService: ShelfService, private bookService: BookService) {
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.libraryMenu$ = this.libraryService.libraryState$.pipe(
|
||||
map((state) => [
|
||||
{
|
||||
label: 'Library',
|
||||
separator: false,
|
||||
items: state.libraries?.map((library) => ({
|
||||
label: library.name,
|
||||
icon: 'pi pi-' + library.icon,
|
||||
routerLink: [`/library/${library.id}/books`],
|
||||
bookCount$: this.libraryService.getBookCount(library.id ?? 0),
|
||||
})) || [],
|
||||
},
|
||||
])
|
||||
);
|
||||
|
||||
this.shelfMenu$ = this.shelfService.shelfState$.pipe(
|
||||
map((state) => [
|
||||
{
|
||||
label: 'Shelves',
|
||||
separator: false,
|
||||
items: state.shelves?.map((shelf) => ({
|
||||
label: shelf.name,
|
||||
icon: 'pi pi-' + shelf.icon,
|
||||
routerLink: [`/shelf/${shelf.id}/books`],
|
||||
bookCount$: this.shelfService.getBookCount(shelf.id ?? 0),
|
||||
})) || [],
|
||||
},
|
||||
])
|
||||
);
|
||||
|
||||
this.homeMenu$ = this.bookService.bookState$.pipe(
|
||||
map((bookState) => {
|
||||
return [
|
||||
{
|
||||
label: 'Home',
|
||||
separator: false,
|
||||
items: [
|
||||
{
|
||||
label: 'Dashboard',
|
||||
icon: 'pi pi-fw pi-home',
|
||||
routerLink: ['/'],
|
||||
},
|
||||
{
|
||||
label: 'All Books',
|
||||
icon: 'pi pi-fw pi-book',
|
||||
routerLink: ['/all-books'],
|
||||
bookCount$: of(bookState.books ? bookState.books.length : 0),
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
import {ChangeDetectorRef, Component, Host, HostBinding, Input, OnDestroy, OnInit} from '@angular/core';
|
||||
import {NavigationEnd, Router, RouterLink, RouterLinkActive} from '@angular/router';
|
||||
import {animate, state, style, transition, trigger} from '@angular/animations';
|
||||
import {Subscription} from 'rxjs';
|
||||
import {filter} from 'rxjs/operators';
|
||||
import {MenuService} from './app.menu.service';
|
||||
import {LayoutService} from './service/app.layout.service';
|
||||
import {AsyncPipe, NgClass, NgForOf, NgIf} from '@angular/common';
|
||||
import {Ripple} from 'primeng/ripple';
|
||||
|
||||
@Component({
|
||||
selector: '[app-menuitem]',
|
||||
template: `
|
||||
<ng-container>
|
||||
|
||||
<div *ngIf="root && item.visible !== false" class="layout-menuitem-root-text">{{ item.label }}</div>
|
||||
|
||||
<a *ngIf="(!item.routerLink || item.items) && item.visible !== false" [attr.href]="item.url"
|
||||
(click)="itemClick($event)"
|
||||
[ngClass]="item.class" [attr.target]="item.target" tabindex="0" pRipple>
|
||||
<i [ngClass]="item.icon" class="layout-menuitem-icon"></i>
|
||||
<span class="layout-menuitem-text">
|
||||
{{ item.label }}
|
||||
</span>
|
||||
<i class="pi pi-fw pi-angle-down layout-submenu-toggler" *ngIf="item.items"></i>
|
||||
</a>
|
||||
|
||||
<a *ngIf="(item.routerLink && !item.items) && item.visible !== false" (click)="itemClick($event)"
|
||||
[ngClass]="item.class"
|
||||
[routerLink]="item.routerLink" routerLinkActive="active-route"
|
||||
[routerLinkActiveOptions]="item.routerLinkActiveOptions||{ paths: 'exact', queryParams: 'ignored', matrixParams: 'ignored', fragment: 'ignored' }"
|
||||
[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>
|
||||
<i [ngClass]="item.icon" class="layout-menuitem-icon"></i>
|
||||
<span class="layout-menuitem-text w-full">
|
||||
{{ item.label }}
|
||||
<span *ngIf="item.bookCount$ | async as bookCount">
|
||||
{{ bookCount }}
|
||||
</span>
|
||||
</span>
|
||||
<i class="pi pi-fw pi-angle-down layout-submenu-toggler" *ngIf="item.items"></i>
|
||||
</a>
|
||||
|
||||
<ul *ngIf="item.items && item.visible !== false" [@children]="submenuAnimation">
|
||||
<ng-template ngFor let-child let-i="index" [ngForOf]="item.items">
|
||||
<li app-menuitem [item]="child" [index]="i" [parentKey]="key" [class]="child.badgeClass"></li>
|
||||
</ng-template>
|
||||
</ul>
|
||||
</ng-container>
|
||||
`,
|
||||
imports: [
|
||||
RouterLink,
|
||||
RouterLinkActive,
|
||||
NgClass,
|
||||
NgForOf,
|
||||
Ripple,
|
||||
NgIf,
|
||||
AsyncPipe
|
||||
],
|
||||
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;
|
||||
|
||||
active = false;
|
||||
menuSourceSubscription: Subscription;
|
||||
menuResetSubscription: Subscription;
|
||||
key: string = "";
|
||||
|
||||
constructor(public router: Router, private menuService: MenuService) {
|
||||
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.router.events.pipe(filter(event => event instanceof NavigationEnd))
|
||||
.subscribe(params => {
|
||||
if (this.item.routerLink) {
|
||||
this.updateActiveStateFromRoute();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.key = this.parentKey ? this.parentKey + '-' + this.index : String(this.index);
|
||||
if (this.item.routerLink) {
|
||||
this.updateActiveStateFromRoute();
|
||||
}
|
||||
}
|
||||
|
||||
updateActiveStateFromRoute() {
|
||||
let 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;
|
||||
}
|
||||
this.menuService.onMenuStateChange({key: this.key});
|
||||
}
|
||||
|
||||
get submenuAnimation() {
|
||||
return this.root ? 'expanded' : (this.active ? 'expanded' : 'collapsed');
|
||||
}
|
||||
|
||||
@HostBinding('class.active-menuitem')
|
||||
get activeClass() {
|
||||
return this.active && !this.root;
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
if (this.menuSourceSubscription) {
|
||||
this.menuSourceSubscription.unsubscribe();
|
||||
}
|
||||
if (this.menuResetSubscription) {
|
||||
this.menuResetSubscription.unsubscribe();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<app-menu></app-menu>
|
||||
@@ -0,0 +1,3 @@
|
||||
.layout-sidebar-custom {
|
||||
width: 250px !important;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { Component, ElementRef } from '@angular/core';
|
||||
import { LayoutService } from "./service/app.layout.service";
|
||||
import {AppMenuComponent} from './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,58 @@
|
||||
<div class="layout-topbar">
|
||||
|
||||
<a class="layout-topbar-logo" routerLink="">
|
||||
<span class="flex">
|
||||
<p>Book</p>
|
||||
<p class="half-title text-3xl">lore</p>
|
||||
</span>
|
||||
</a>
|
||||
|
||||
<p-button
|
||||
#menubutton
|
||||
icon="pi pi-arrow-left"
|
||||
[rounded]="true"
|
||||
[outlined]="true"
|
||||
(click)="toggleMenu()"
|
||||
[ngClass]="{ 'rotate-right': !isMenuVisible, 'rotate-left': isMenuVisible }"
|
||||
>
|
||||
</p-button>
|
||||
|
||||
<div class="topbar-right-items">
|
||||
<app-book-searcher></app-book-searcher>
|
||||
<ul class="topbar-items">
|
||||
<p-divider layout="vertical" />
|
||||
<li>
|
||||
<i class="pi pi-wave-pulse" style="font-size: 1.5rem"
|
||||
(click)="toggleEventDisplay()"
|
||||
(mouseenter)="onMouseEnter()"
|
||||
(mouseleave)="onMouseLeave()"
|
||||
[class.pulsating]="eventHighlight"
|
||||
[class.highlight]="eventHighlight"></i>
|
||||
<div *ngIf="showEvents" class="live-event-container" (mouseleave)="onMouseLeave()">
|
||||
<p *ngIf="latestEvent.timestamp">{{ latestEvent.timestamp }}</p>
|
||||
<p>{{ latestEvent.message }}</p>
|
||||
</div>
|
||||
</li>
|
||||
<p-divider layout="vertical" />
|
||||
<li>
|
||||
<a class="topbar-item">
|
||||
<i class="pi pi-plus-circle text-surface-700 dark:text-surface-100" (click)="openLibraryCreatorDialog()"
|
||||
pTooltip="Create New Library" tooltipPosition="top"></i>
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="topbar-item">
|
||||
<i class="pi pi-upload text-surface-700 dark:text-surface-100" (click)="openFileUploadDialog()"
|
||||
pTooltip="Upload book" tooltipPosition="top"></i>
|
||||
</a>
|
||||
</li>
|
||||
<li class="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-configurator></app-configurator>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
@@ -0,0 +1,38 @@
|
||||
.live-event-container {
|
||||
position: absolute;
|
||||
top: 43px;
|
||||
right: -180px;
|
||||
width: 500px;
|
||||
background: var(--card-background);
|
||||
border: 0.5px solid var(--primary-color);
|
||||
border-radius: 4px;
|
||||
padding: 12px;
|
||||
overflow-x: hidden;
|
||||
/*z-index: 1000;*/
|
||||
word-wrap: break-word;
|
||||
white-space: normal;
|
||||
}
|
||||
|
||||
.highlight {
|
||||
color: red !important;
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
import {Component, ElementRef, OnDestroy, ViewChild} from '@angular/core';
|
||||
import {MenuItem} from 'primeng/api';
|
||||
import {LayoutService} from './service/app.layout.service';
|
||||
import {RouterLink} from '@angular/router';
|
||||
import {DialogService as PrimeDialogService, DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {LibraryCreatorComponent} from '../book/library-creator/library-creator.component';
|
||||
import {TooltipModule} from 'primeng/tooltip';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {InputTextModule} from 'primeng/inputtext';
|
||||
import {BookSearcherComponent} from '../book/book-searcher/book-searcher.component';
|
||||
import {FileUploadComponent} from '../utilities/file-upload/file-upload.component';
|
||||
import {NgClass, NgIf} from '@angular/common';
|
||||
import {EventService} from '../book/service/event.service';
|
||||
import {LogNotification} from '../book/model/log-notification.model';
|
||||
import {Button} from 'primeng/button';
|
||||
import {AppConfiguratorComponent} from '../core/configurator/configurator.component';
|
||||
import {StyleClass} from 'primeng/styleclass';
|
||||
import {Divider} from 'primeng/divider';
|
||||
|
||||
@Component({
|
||||
selector: 'app-topbar',
|
||||
templateUrl: './app.topbar.component.html',
|
||||
styleUrls: ['./app.topbar.component.scss'],
|
||||
imports: [
|
||||
RouterLink,
|
||||
TooltipModule,
|
||||
FormsModule,
|
||||
InputTextModule,
|
||||
BookSearcherComponent,
|
||||
NgIf,
|
||||
Button,
|
||||
AppConfiguratorComponent,
|
||||
StyleClass,
|
||||
NgClass,
|
||||
Divider
|
||||
],
|
||||
})
|
||||
export class AppTopBarComponent implements OnDestroy {
|
||||
items!: MenuItem[];
|
||||
ref: DynamicDialogRef | undefined;
|
||||
|
||||
latestEvent: LogNotification = {message: 'No recent notifications...'};
|
||||
eventHighlight: boolean = false;
|
||||
showEvents: boolean = false;
|
||||
eventTimeout: any;
|
||||
|
||||
@ViewChild('menubutton') menuButton!: ElementRef;
|
||||
@ViewChild('topbarmenubutton') topbarMenuButton!: ElementRef;
|
||||
@ViewChild('topbarmenu') menu!: ElementRef;
|
||||
|
||||
constructor(public layoutService: LayoutService, public dialogService: PrimeDialogService, private eventService: EventService) {
|
||||
this.eventService.latestEvent$.subscribe(event => {
|
||||
this.latestEvent = event;
|
||||
});
|
||||
this.eventService.eventHighlight$.subscribe(highlight => {
|
||||
this.eventHighlight = highlight;
|
||||
});
|
||||
}
|
||||
|
||||
isMenuVisible: boolean = true;
|
||||
|
||||
toggleMenu() {
|
||||
this.isMenuVisible = !this.isMenuVisible;
|
||||
this.layoutService.onMenuToggle();
|
||||
}
|
||||
|
||||
onMouseEnter() {
|
||||
this.showEvents = true;
|
||||
}
|
||||
|
||||
onMouseLeave() {
|
||||
this.showEvents = false;
|
||||
}
|
||||
|
||||
toggleEventDisplay(): void {
|
||||
this.showEvents = !this.showEvents;
|
||||
}
|
||||
|
||||
openLibraryCreatorDialog(): void {
|
||||
this.ref = this.dialogService.open(LibraryCreatorComponent, {
|
||||
header: 'Create New Library',
|
||||
modal: true,
|
||||
closable: true,
|
||||
width: '675px',
|
||||
height: '480px',
|
||||
style: {
|
||||
position: 'absolute',
|
||||
top: '15%',
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
openFileUploadDialog() {
|
||||
this.ref = this.dialogService.open(FileUploadComponent, {
|
||||
header: 'Upload Book',
|
||||
modal: true,
|
||||
closable: true,
|
||||
width: '600px',
|
||||
height: '330px',
|
||||
style: {
|
||||
position: 'absolute',
|
||||
top: '15%',
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
if (this.ref) {
|
||||
this.ref.close();
|
||||
}
|
||||
clearTimeout(this.eventTimeout);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
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<any>();
|
||||
|
||||
configUpdate$ = this.configUpdate.asObservable();
|
||||
|
||||
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 = <HTMLLinkElement>document.getElementById('theme-css');
|
||||
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';
|
||||
let themeLink = <HTMLLinkElement>document.getElementById(id);
|
||||
const cloneLinkElement = <HTMLLinkElement>themeLink.cloneNode(true);
|
||||
|
||||
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`;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user