2019-12-23 13:52:26 +01:00
|
|
|
import {Injectable} from "@angular/core";
|
2020-11-13 17:34:39 +01:00
|
|
|
import {BehaviorSubject, Observable, Subscriber} from "rxjs";
|
2019-12-23 13:52:26 +01:00
|
|
|
import {ActivationStart, Router} from "@angular/router";
|
2023-02-15 10:53:25 +01:00
|
|
|
import {Icon} from "../../../sharedComponents/menu";
|
2019-12-23 13:52:26 +01:00
|
|
|
|
2022-12-07 10:33:16 +01:00
|
|
|
declare var ResizeObserver;
|
|
|
|
|
2023-02-15 10:53:25 +01:00
|
|
|
export interface SidebarItem {
|
|
|
|
icon?: Icon,
|
|
|
|
name: string,
|
|
|
|
subItem?: SidebarItem
|
|
|
|
}
|
|
|
|
|
2019-12-23 13:52:26 +01:00
|
|
|
@Injectable({
|
|
|
|
providedIn: 'root'
|
|
|
|
})
|
|
|
|
export class LayoutService {
|
2023-02-15 10:53:25 +01:00
|
|
|
|
2022-07-02 20:32:10 +02:00
|
|
|
public static HEADER_HEIGHT = '65px';
|
2022-12-07 10:33:16 +01:00
|
|
|
private deviceBreakpoint: number;
|
2023-02-15 10:53:25 +01:00
|
|
|
|
2019-12-23 13:52:26 +01:00
|
|
|
/**
|
|
|
|
* Set this to true when sidebar items are ready.
|
|
|
|
*/
|
|
|
|
private openSubject: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
|
2023-02-15 10:53:25 +01:00
|
|
|
|
2023-01-25 07:00:35 +01:00
|
|
|
/**
|
|
|
|
* Set this to true when sidebar is hovered, otherwise false.
|
|
|
|
*/
|
|
|
|
private hoverSubject: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
|
2023-02-15 10:53:25 +01:00
|
|
|
|
2019-12-23 13:52:26 +01:00
|
|
|
/**
|
|
|
|
* Add hasSidebar: false on data of route config, if sidebar is not needed.
|
|
|
|
*/
|
|
|
|
private hasSidebarSubject: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
|
2023-02-15 10:53:25 +01:00
|
|
|
|
2019-12-23 13:52:26 +01:00
|
|
|
/**
|
|
|
|
* Add hasHeader: false on data of route config, if header is not needed.
|
|
|
|
*/
|
|
|
|
private hasHeaderSubject: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
|
2023-02-15 10:53:25 +01:00
|
|
|
|
2019-12-23 13:52:26 +01:00
|
|
|
/**
|
2019-12-24 10:37:00 +01:00
|
|
|
* Add hasAdminMenu: true on data of route config, if global sidebar should be used.
|
2019-12-23 13:52:26 +01:00
|
|
|
*/
|
2020-12-11 19:33:54 +01:00
|
|
|
private hasAdminMenuSubject: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
|
2022-11-04 15:35:10 +01:00
|
|
|
/**
|
|
|
|
* Add hasInternalSidebar: true on data of route config, if internal sidebar should be used.
|
|
|
|
*/
|
|
|
|
private hasInternalSidebarSubject: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
|
2020-07-03 16:20:51 +02:00
|
|
|
/**
|
|
|
|
* Add isFrontPage: true on data of route config, if current route is for front page.
|
|
|
|
*/
|
2020-12-11 19:33:54 +01:00
|
|
|
private isFrontPageSubject: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
|
|
|
|
/**
|
|
|
|
* Add isSmallScreen: true on data of route config, if screen is small.
|
2023-02-09 11:09:49 +01:00
|
|
|
* @deprecated
|
2020-12-11 19:33:54 +01:00
|
|
|
*/
|
|
|
|
private isSmallScreenSubject: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
|
2022-10-12 14:30:39 +02:00
|
|
|
/**
|
|
|
|
* Add hasQuickContact: false on data of route config, if the quick-contact fixed button is not needed.
|
|
|
|
*/
|
2023-05-08 16:50:39 +02:00
|
|
|
private hasQuickContactSubject: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
|
2022-03-28 10:40:21 +02:00
|
|
|
/**
|
|
|
|
* Add activeMenuItem: string on data of route config, if page should activate a specific MenuItem and route url does not match.
|
|
|
|
*/
|
2022-10-12 14:30:39 +02:00
|
|
|
|
2022-03-28 10:40:21 +02:00
|
|
|
private activeMenuItemSubject: BehaviorSubject<string> = new BehaviorSubject<string>("");
|
2023-02-15 10:53:25 +01:00
|
|
|
|
2022-08-04 14:29:08 +02:00
|
|
|
/**
|
|
|
|
* Change to true will replace your Nav Header with the replaceHeader of your object.
|
|
|
|
* Be sure that replaceHeader exists.
|
|
|
|
*/
|
|
|
|
private replaceHeaderSubject: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
|
2022-12-07 10:33:16 +01:00
|
|
|
/** Check if the current device is mobile or tablet */
|
|
|
|
private isMobileSubject: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
|
2023-02-15 10:53:25 +01:00
|
|
|
/** Active sidebar Item*/
|
|
|
|
private activeSidebarItemSubject: BehaviorSubject<SidebarItem> = new BehaviorSubject<SidebarItem>(null);
|
2023-05-11 16:17:16 +02:00
|
|
|
/**
|
|
|
|
* Add hasMenuSearchBar: false/ nothing on data of route config, if the search bar in the menu should not appear, otherwise true.
|
|
|
|
*/
|
|
|
|
private hasMenuSearchBarSubject: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
|
2023-08-30 10:11:23 +02:00
|
|
|
/**
|
|
|
|
* Add hasStickyHeaderOnMobile: true in order to activate uk-sticky in header of mobile/tablet devices.
|
|
|
|
* */
|
|
|
|
private hasStickyHeaderOnMobileSubject: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
|
2023-11-24 09:51:22 +01:00
|
|
|
/**
|
|
|
|
* Add a class in root element of the html. (For different theme apply)
|
|
|
|
* Handle it manually in the component, it doesn't use data
|
|
|
|
* */
|
|
|
|
private rootClassSubject: BehaviorSubject<string> = new BehaviorSubject<string>(null);
|
2024-03-08 11:50:55 +01:00
|
|
|
/**
|
|
|
|
* Display help pop-up on non-admin pages. (default true for the rest of the pages)
|
|
|
|
* */
|
|
|
|
private hasHelpPopUpSubject: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(true);
|
2022-12-07 10:33:16 +01:00
|
|
|
private subscriptions: any[] = [];
|
2023-02-15 10:53:25 +01:00
|
|
|
|
2020-11-13 17:34:39 +01:00
|
|
|
ngOnDestroy() {
|
|
|
|
this.clearSubscriptions();
|
|
|
|
}
|
2023-02-15 10:53:25 +01:00
|
|
|
|
2020-12-11 19:33:54 +01:00
|
|
|
clearSubscriptions() {
|
2022-12-07 10:33:16 +01:00
|
|
|
this.subscriptions.forEach(subscription => {
|
|
|
|
if (subscription instanceof Subscriber) {
|
|
|
|
subscription.unsubscribe();
|
2023-03-28 07:57:18 +02:00
|
|
|
} else if (typeof ResizeObserver !== "undefined" && subscription instanceof ResizeObserver) {
|
2022-12-07 10:33:16 +01:00
|
|
|
subscription.disconnect();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2023-02-15 10:53:25 +01:00
|
|
|
|
2022-12-07 10:33:16 +01:00
|
|
|
setObserver() {
|
2023-02-15 10:53:25 +01:00
|
|
|
if (typeof ResizeObserver !== "undefined" && typeof document !== "undefined") {
|
2022-12-07 10:33:16 +01:00
|
|
|
this.deviceBreakpoint = Number.parseInt(getComputedStyle(document.documentElement).getPropertyValue('--uk-breakpoint-m').replace('px', '')) + 1;
|
|
|
|
let resizeObs = new ResizeObserver(entries => {
|
|
|
|
entries.forEach(entry => {
|
|
|
|
this.isMobileSubject.next(entry.target.clientWidth < this.deviceBreakpoint);
|
2023-02-15 10:53:25 +01:00
|
|
|
});
|
2022-12-07 10:33:16 +01:00
|
|
|
});
|
|
|
|
this.subscriptions.push(resizeObs);
|
|
|
|
resizeObs.observe(document.documentElement);
|
2020-11-13 17:34:39 +01:00
|
|
|
}
|
|
|
|
}
|
2023-02-15 10:53:25 +01:00
|
|
|
|
2019-12-23 13:52:26 +01:00
|
|
|
constructor(private router: Router) {
|
2023-02-15 10:53:25 +01:00
|
|
|
if (typeof window !== 'undefined') {
|
2022-12-07 10:33:16 +01:00
|
|
|
this.isMobileSubject.next(window.innerWidth < this.deviceBreakpoint);
|
|
|
|
}
|
|
|
|
this.subscriptions.push(this.router.events.subscribe(event => {
|
2019-12-23 13:52:26 +01:00
|
|
|
if (event instanceof ActivationStart) {
|
2022-08-04 14:29:08 +02:00
|
|
|
this.setReplaceHeader(false);
|
2019-12-23 13:52:26 +01:00
|
|
|
let data = event.snapshot.data;
|
2019-12-24 10:37:00 +01:00
|
|
|
if (data['hasSidebar'] !== undefined &&
|
2019-12-23 13:52:26 +01:00
|
|
|
data['hasSidebar'] === false) {
|
|
|
|
this.setHasSidebar(false);
|
2019-12-24 10:37:00 +01:00
|
|
|
} else {
|
2019-12-23 13:52:26 +01:00
|
|
|
this.setHasSidebar(true);
|
|
|
|
}
|
2019-12-24 10:37:00 +01:00
|
|
|
if (data['hasHeader'] !== undefined &&
|
2019-12-23 13:52:26 +01:00
|
|
|
data['hasHeader'] === false) {
|
|
|
|
this.setHasHeader(false);
|
2023-02-15 10:53:25 +01:00
|
|
|
if (typeof document !== "undefined") {
|
2023-11-03 15:52:52 +01:00
|
|
|
document.documentElement.style.setProperty('--header-height', '0px');
|
2022-08-02 22:13:12 +02:00
|
|
|
}
|
2019-12-24 10:37:00 +01:00
|
|
|
} else {
|
2019-12-23 13:52:26 +01:00
|
|
|
this.setHasHeader(true);
|
2023-02-15 10:53:25 +01:00
|
|
|
if (typeof document !== "undefined") {
|
2022-08-02 22:13:12 +02:00
|
|
|
document.documentElement.style.setProperty('--header-height', LayoutService.HEADER_HEIGHT);
|
|
|
|
}
|
2019-12-23 13:52:26 +01:00
|
|
|
}
|
2019-12-24 10:37:00 +01:00
|
|
|
if (data['hasAdminMenu'] !== undefined &&
|
|
|
|
data['hasAdminMenu'] === true) {
|
2019-12-23 13:52:26 +01:00
|
|
|
this.setHasAdminMenu(true);
|
2019-12-24 10:37:00 +01:00
|
|
|
} else {
|
|
|
|
this.setHasAdminMenu(false);
|
2019-12-23 13:52:26 +01:00
|
|
|
}
|
2022-11-04 15:35:10 +01:00
|
|
|
if (data['hasInternalSidebar'] !== undefined &&
|
|
|
|
data['hasInternalSidebar'] === true) {
|
|
|
|
this.setHasInternalSidebar(true);
|
|
|
|
} else {
|
|
|
|
this.setHasInternalSidebar(false);
|
|
|
|
}
|
2020-06-04 13:21:32 +02:00
|
|
|
if (data['isFrontPage'] !== undefined &&
|
|
|
|
data['isFrontPage'] === true) {
|
|
|
|
this.setFrontPage(true);
|
|
|
|
} else {
|
|
|
|
this.setFrontPage(false);
|
|
|
|
}
|
2020-10-12 14:39:42 +02:00
|
|
|
if (data['isSmallScreen'] !== undefined &&
|
|
|
|
data['isSmallScreen'] === true) {
|
|
|
|
this.setSmallScreen(true);
|
|
|
|
} else {
|
|
|
|
this.setSmallScreen(false);
|
2022-10-12 14:30:39 +02:00
|
|
|
}
|
2023-02-15 10:53:25 +01:00
|
|
|
if (data['hasQuickContact'] !== undefined &&
|
2022-10-12 14:30:39 +02:00
|
|
|
data['hasQuickContact'] === false) {
|
|
|
|
this.setHasQuickContact(false);
|
|
|
|
} else {
|
|
|
|
this.setHasQuickContact(true);
|
2020-10-12 14:39:42 +02:00
|
|
|
}
|
2022-03-28 10:40:21 +02:00
|
|
|
if (data['activeMenuItem'] !== undefined &&
|
|
|
|
data['activeMenuItem'] !== null) {
|
|
|
|
this.setActiveMenuItem(data['activeMenuItem']);
|
|
|
|
} else {
|
|
|
|
this.setActiveMenuItem('');
|
|
|
|
}
|
2023-05-11 16:17:16 +02:00
|
|
|
if (data['hasMenuSearchBar'] !== undefined &&
|
|
|
|
data['hasMenuSearchBar'] === true) {
|
|
|
|
this.setHasMenuSearchBar(true);
|
|
|
|
} else {
|
|
|
|
this.setHasMenuSearchBar(false);
|
|
|
|
}
|
2023-08-30 10:11:23 +02:00
|
|
|
if (data['hasStickyHeaderOnMobile'] !== undefined &&
|
|
|
|
data['hasStickyHeaderOnMobile'] === true) {
|
|
|
|
this.setHasStickyHeaderOnMobile(true);
|
|
|
|
} else {
|
|
|
|
this.setHasStickyHeaderOnMobile(false);
|
|
|
|
}
|
2019-12-23 13:52:26 +01:00
|
|
|
}
|
2022-12-07 10:33:16 +01:00
|
|
|
}));
|
|
|
|
this.setObserver();
|
2019-12-23 13:52:26 +01:00
|
|
|
}
|
2023-01-25 13:41:53 +01:00
|
|
|
|
|
|
|
get isOpen(): Observable<boolean> {
|
|
|
|
return this.openSubject.asObservable();
|
|
|
|
}
|
|
|
|
|
2019-12-23 13:52:26 +01:00
|
|
|
get open(): boolean {
|
|
|
|
return this.openSubject.getValue();
|
|
|
|
}
|
2023-02-15 10:53:25 +01:00
|
|
|
|
2019-12-23 13:52:26 +01:00
|
|
|
setOpen(value: boolean) {
|
|
|
|
this.openSubject.next(value);
|
|
|
|
}
|
2023-02-15 10:53:25 +01:00
|
|
|
|
2023-01-25 07:00:35 +01:00
|
|
|
get hover(): boolean {
|
|
|
|
return this.hoverSubject.getValue();
|
|
|
|
}
|
2023-02-15 10:53:25 +01:00
|
|
|
|
2023-01-25 07:00:35 +01:00
|
|
|
setHover(value: boolean) {
|
|
|
|
this.hoverSubject.next(value);
|
|
|
|
}
|
2023-02-15 10:53:25 +01:00
|
|
|
|
|
|
|
get hasAnySidebar(): boolean {
|
|
|
|
return this.hasSidebarSubject.getValue() || this.hasInternalSidebarSubject.getValue() || this.hasAdminMenuSubject.getValue();
|
|
|
|
}
|
|
|
|
|
2019-12-23 13:52:26 +01:00
|
|
|
get hasSidebar(): Observable<boolean> {
|
|
|
|
return this.hasSidebarSubject.asObservable();
|
|
|
|
}
|
2023-02-15 10:53:25 +01:00
|
|
|
|
2019-12-23 13:52:26 +01:00
|
|
|
setHasSidebar(value: boolean) {
|
|
|
|
this.hasSidebarSubject.next(value);
|
|
|
|
}
|
2023-02-15 10:53:25 +01:00
|
|
|
|
2019-12-23 13:52:26 +01:00
|
|
|
get hasHeader(): Observable<boolean> {
|
|
|
|
return this.hasHeaderSubject.asObservable();
|
|
|
|
}
|
2023-02-15 10:53:25 +01:00
|
|
|
|
2019-12-23 13:52:26 +01:00
|
|
|
setHasHeader(value: boolean) {
|
|
|
|
this.hasHeaderSubject.next(value);
|
|
|
|
}
|
2023-02-15 10:53:25 +01:00
|
|
|
|
2020-02-14 16:08:54 +01:00
|
|
|
get hasAdminMenu(): Observable<boolean> {
|
2020-12-11 19:33:54 +01:00
|
|
|
return this.hasAdminMenuSubject.asObservable();
|
2019-12-23 13:52:26 +01:00
|
|
|
}
|
2023-02-15 10:53:25 +01:00
|
|
|
|
2019-12-23 13:52:26 +01:00
|
|
|
setHasAdminMenu(value: boolean) {
|
2020-12-11 19:33:54 +01:00
|
|
|
this.hasAdminMenuSubject.next(value);
|
2019-12-23 13:52:26 +01:00
|
|
|
}
|
2023-02-15 10:53:25 +01:00
|
|
|
|
2022-11-04 15:35:10 +01:00
|
|
|
get hasInternalSidebar(): Observable<boolean> {
|
|
|
|
return this.hasInternalSidebarSubject.asObservable();
|
|
|
|
}
|
2023-02-15 10:53:25 +01:00
|
|
|
|
2022-11-04 15:35:10 +01:00
|
|
|
setHasInternalSidebar(value: boolean) {
|
|
|
|
this.hasInternalSidebarSubject.next(value);
|
|
|
|
}
|
2023-02-15 10:53:25 +01:00
|
|
|
|
2020-06-04 13:21:32 +02:00
|
|
|
get isFrontPage(): Observable<boolean> {
|
2020-12-11 19:33:54 +01:00
|
|
|
return this.isFrontPageSubject.asObservable();
|
2020-06-04 13:21:32 +02:00
|
|
|
}
|
2023-02-15 10:53:25 +01:00
|
|
|
|
2020-06-04 13:21:32 +02:00
|
|
|
setFrontPage(value: boolean) {
|
2020-12-11 19:33:54 +01:00
|
|
|
this.isFrontPageSubject.next(value);
|
2020-06-04 13:21:32 +02:00
|
|
|
}
|
2023-02-15 10:53:25 +01:00
|
|
|
|
2022-08-04 14:29:08 +02:00
|
|
|
get replaceHeader(): Observable<boolean> {
|
|
|
|
return this.replaceHeaderSubject.asObservable();
|
|
|
|
}
|
2023-02-15 10:53:25 +01:00
|
|
|
|
2022-12-12 15:16:47 +01:00
|
|
|
get replaceHeaderValue(): boolean {
|
|
|
|
return this.replaceHeaderSubject.getValue();
|
|
|
|
}
|
2023-02-15 10:53:25 +01:00
|
|
|
|
2022-08-04 14:29:08 +02:00
|
|
|
setReplaceHeader(value: boolean) {
|
|
|
|
this.replaceHeaderSubject.next(value);
|
|
|
|
}
|
2023-02-15 10:53:25 +01:00
|
|
|
|
2023-02-09 11:09:49 +01:00
|
|
|
/**
|
|
|
|
* @deprecated
|
|
|
|
* */
|
2020-12-11 19:33:54 +01:00
|
|
|
get isSmallScreen(): boolean {
|
|
|
|
return this.isSmallScreenSubject.getValue();
|
|
|
|
}
|
2023-02-15 10:53:25 +01:00
|
|
|
|
2023-02-09 11:09:49 +01:00
|
|
|
/**
|
|
|
|
* @deprecated
|
|
|
|
* */
|
2020-10-12 14:39:42 +02:00
|
|
|
setSmallScreen(value: boolean) {
|
2020-12-11 19:33:54 +01:00
|
|
|
this.isSmallScreenSubject.next(value);
|
2020-10-12 14:39:42 +02:00
|
|
|
}
|
2022-03-28 10:40:21 +02:00
|
|
|
|
2023-02-15 10:53:25 +01:00
|
|
|
get hasQuickContact(): Observable<boolean> {
|
|
|
|
return this.hasQuickContactSubject.asObservable();
|
|
|
|
}
|
2022-10-12 14:30:39 +02:00
|
|
|
|
2023-02-15 10:53:25 +01:00
|
|
|
setHasQuickContact(value: boolean) {
|
|
|
|
this.hasQuickContactSubject.next(value);
|
|
|
|
}
|
2022-10-12 14:30:39 +02:00
|
|
|
|
2022-03-28 10:40:21 +02:00
|
|
|
get activeMenuItem(): string {
|
|
|
|
return this.activeMenuItemSubject.getValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
setActiveMenuItem(value: string) {
|
|
|
|
this.activeMenuItemSubject.next(value);
|
|
|
|
}
|
2023-02-15 10:53:25 +01:00
|
|
|
|
2022-12-07 10:33:16 +01:00
|
|
|
get isMobile(): Observable<boolean> {
|
|
|
|
return this.isMobileSubject.asObservable();
|
|
|
|
}
|
2023-02-15 10:53:25 +01:00
|
|
|
|
2022-12-09 17:17:06 +01:00
|
|
|
get isMobileValue(): boolean {
|
|
|
|
return this.isMobileSubject.getValue();
|
|
|
|
}
|
2023-02-15 10:53:25 +01:00
|
|
|
|
|
|
|
get activeSidebarItem(): Observable<SidebarItem> {
|
|
|
|
return this.activeSidebarItemSubject.asObservable();
|
|
|
|
}
|
|
|
|
|
|
|
|
setActiveSidebarItem(value: SidebarItem) {
|
|
|
|
this.activeSidebarItemSubject.next(value);
|
|
|
|
}
|
2023-05-11 16:17:16 +02:00
|
|
|
|
|
|
|
get hasMenuSearchBar(): Observable<boolean> {
|
|
|
|
return this.hasMenuSearchBarSubject.asObservable();
|
|
|
|
}
|
|
|
|
|
|
|
|
setHasMenuSearchBar(value: boolean) {
|
|
|
|
this.hasMenuSearchBarSubject.next(value);
|
|
|
|
}
|
2023-08-30 10:11:23 +02:00
|
|
|
|
|
|
|
get hasStickyHeaderOnMobile(): Observable<boolean> {
|
|
|
|
return this.hasStickyHeaderOnMobileSubject.asObservable();
|
|
|
|
}
|
|
|
|
|
|
|
|
setHasStickyHeaderOnMobile(value: boolean) {
|
|
|
|
this.hasStickyHeaderOnMobileSubject.next(value);
|
|
|
|
}
|
2023-11-24 09:51:22 +01:00
|
|
|
|
|
|
|
get rootClass(): Observable<string> {
|
|
|
|
return this.rootClassSubject.asObservable();
|
|
|
|
}
|
|
|
|
|
|
|
|
setRootClass(value: string = null): void {
|
2024-01-12 08:15:04 +01:00
|
|
|
if(this.rootClassSubject.value != value) {
|
|
|
|
this.rootClassSubject.next(value);
|
|
|
|
}
|
2023-11-24 09:51:22 +01:00
|
|
|
}
|
2024-03-08 11:50:55 +01:00
|
|
|
|
|
|
|
get hasHelpPopUp(): Observable<boolean> {
|
|
|
|
return this.hasHelpPopUpSubject.asObservable();
|
|
|
|
}
|
|
|
|
|
|
|
|
setHasHelpPopUp(value: boolean) {
|
|
|
|
this.hasHelpPopUpSubject.next(value);
|
|
|
|
}
|
2019-12-23 13:52:26 +01:00
|
|
|
}
|