2022-07-22 13:13:50 +03:00
|
|
|
import { Component, OnDestroy, Renderer2, ViewChild } from '@angular/core';
|
2024-12-30 12:00:11 +03:00
|
|
|
import {NavigationEnd, Router, RouterModule} from '@angular/router';
|
2022-07-22 13:13:50 +03:00
|
|
|
import { filter, Subscription } from 'rxjs';
|
|
|
|
|
import { LayoutService } from "./service/app.layout.service";
|
|
|
|
|
import { AppSidebarComponent } from "./app.sidebar.component";
|
|
|
|
|
import { AppTopBarComponent } from './app.topbar.component';
|
2024-12-30 12:00:11 +03:00
|
|
|
import {AppConfigComponent} from './config/app.config.component';
|
|
|
|
|
import {AppFooterComponent} from './app.footer.component';
|
|
|
|
|
import {CommonModule} from '@angular/common';
|
2022-07-22 13:13:50 +03:00
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-layout',
|
2024-12-30 12:00:11 +03:00
|
|
|
standalone: true,
|
|
|
|
|
imports: [CommonModule, RouterModule, AppTopBarComponent, AppSidebarComponent, AppConfigComponent, AppFooterComponent],
|
2022-07-22 13:13:50 +03:00
|
|
|
templateUrl: './app.layout.component.html'
|
|
|
|
|
})
|
|
|
|
|
export class AppLayoutComponent implements OnDestroy {
|
|
|
|
|
|
|
|
|
|
overlayMenuOpenSubscription: Subscription;
|
|
|
|
|
|
|
|
|
|
menuOutsideClickListener: any;
|
|
|
|
|
|
2022-08-23 11:48:14 +03:00
|
|
|
profileMenuOutsideClickListener: any;
|
|
|
|
|
|
2022-07-22 13:13:50 +03:00
|
|
|
@ViewChild(AppSidebarComponent) appSidebar!: AppSidebarComponent;
|
|
|
|
|
|
2022-08-23 11:48:14 +03:00
|
|
|
@ViewChild(AppTopBarComponent) appTopbar!: AppTopBarComponent;
|
|
|
|
|
|
2022-08-24 01:01:38 +03:00
|
|
|
constructor(public layoutService: LayoutService, public renderer: Renderer2, public router: Router) {
|
2022-07-22 13:13:50 +03:00
|
|
|
this.overlayMenuOpenSubscription = this.layoutService.overlayOpen$.subscribe(() => {
|
|
|
|
|
if (!this.menuOutsideClickListener) {
|
|
|
|
|
this.menuOutsideClickListener = this.renderer.listen('document', 'click', event => {
|
2024-12-30 12:00:11 +03:00
|
|
|
const isOutsideClicked = !(this.appSidebar.el.nativeElement.isSameNode(event.target) || this.appSidebar.el.nativeElement.contains(event.target)
|
2022-08-24 00:52:27 +03:00
|
|
|
|| this.appTopbar.menuButton.nativeElement.isSameNode(event.target) || this.appTopbar.menuButton.nativeElement.contains(event.target));
|
2024-12-30 12:00:11 +03:00
|
|
|
|
2022-07-22 13:13:50 +03:00
|
|
|
if (isOutsideClicked) {
|
2022-08-23 12:36:54 +03:00
|
|
|
this.hideMenu();
|
2022-07-22 13:13:50 +03:00
|
|
|
}
|
|
|
|
|
});
|
2022-08-23 11:48:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!this.profileMenuOutsideClickListener) {
|
|
|
|
|
this.profileMenuOutsideClickListener = this.renderer.listen('document', 'click', event => {
|
2022-08-23 12:36:54 +03:00
|
|
|
const isOutsideClicked = !(this.appTopbar.menu.nativeElement.isSameNode(event.target) || this.appTopbar.menu.nativeElement.contains(event.target)
|
2022-08-24 00:52:27 +03:00
|
|
|
|| this.appTopbar.topbarMenuButton.nativeElement.isSameNode(event.target) || this.appTopbar.topbarMenuButton.nativeElement.contains(event.target));
|
2022-08-23 11:48:14 +03:00
|
|
|
|
2022-08-23 12:36:54 +03:00
|
|
|
if (isOutsideClicked) {
|
|
|
|
|
this.hideProfileMenu();
|
|
|
|
|
}
|
2022-08-23 11:48:14 +03:00
|
|
|
});
|
2022-07-22 13:13:50 +03:00
|
|
|
}
|
2022-08-23 12:36:54 +03:00
|
|
|
|
|
|
|
|
if (this.layoutService.state.staticMenuMobileActive) {
|
|
|
|
|
this.blockBodyScroll();
|
|
|
|
|
}
|
2022-07-22 13:13:50 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.router.events.pipe(filter(event => event instanceof NavigationEnd))
|
|
|
|
|
.subscribe(() => {
|
2022-08-23 12:36:54 +03:00
|
|
|
this.hideMenu();
|
|
|
|
|
this.hideProfileMenu();
|
2022-07-22 13:13:50 +03:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-23 12:36:54 +03:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-22 13:13:50 +03:00
|
|
|
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 {
|
2023-12-22 10:16:50 +03:00
|
|
|
'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',
|
2022-07-22 13:13:50 +03:00
|
|
|
'layout-overlay-active': this.layoutService.state.overlayMenuActive,
|
|
|
|
|
'layout-mobile-active': this.layoutService.state.staticMenuMobileActive,
|
2023-12-22 10:16:50 +03:00
|
|
|
'p-input-filled': this.layoutService.config().inputStyle === 'filled',
|
|
|
|
|
'p-ripple-disabled': !this.layoutService.config().ripple
|
2022-07-22 13:13:50 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnDestroy() {
|
|
|
|
|
if (this.overlayMenuOpenSubscription) {
|
|
|
|
|
this.overlayMenuOpenSubscription.unsubscribe();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this.menuOutsideClickListener) {
|
|
|
|
|
this.menuOutsideClickListener();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|