89 lines
2.3 KiB
TypeScript
89 lines
2.3 KiB
TypeScript
import {Injectable} from "@angular/core";
|
|
import {BehaviorSubject, Observable} from "rxjs";
|
|
import {ActivationStart, Router} from "@angular/router";
|
|
|
|
@Injectable({
|
|
providedIn: 'root'
|
|
})
|
|
export class LayoutService {
|
|
|
|
/**
|
|
* Set this to true when sidebar items are ready.
|
|
*/
|
|
private openSubject: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
|
|
|
|
/**
|
|
* Add hasSidebar: false on data of route config, if sidebar is not needed.
|
|
*/
|
|
private hasSidebarSubject: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
|
|
|
|
/**
|
|
* Add hasHeader: false on data of route config, if header is not needed.
|
|
*/
|
|
private hasHeaderSubject: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
|
|
|
|
/**
|
|
* Add hasAdminMenu: true on data of route config, if global sidebar should be used.
|
|
*/
|
|
private _hasAdminMenuSubject: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
|
|
|
|
constructor(private router: Router) {
|
|
this.router.events.subscribe(event => {
|
|
if (event instanceof ActivationStart) {
|
|
let data = event.snapshot.data;
|
|
if (data['hasSidebar'] !== undefined &&
|
|
data['hasSidebar'] === false) {
|
|
this.setHasSidebar(false);
|
|
} else {
|
|
this.setHasSidebar(true);
|
|
}
|
|
if (data['hasHeader'] !== undefined &&
|
|
data['hasHeader'] === false) {
|
|
this.setHasHeader(false);
|
|
} else {
|
|
this.setHasHeader(true);
|
|
}
|
|
if (data['hasAdminMenu'] !== undefined &&
|
|
data['hasAdminMenu'] === true) {
|
|
this.setHasAdminMenu(true);
|
|
} else {
|
|
this.setHasAdminMenu(false);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
get open(): boolean {
|
|
return this.openSubject.getValue();
|
|
}
|
|
|
|
setOpen(value: boolean) {
|
|
this.openSubject.next(value);
|
|
}
|
|
|
|
get hasSidebar(): Observable<boolean> {
|
|
return this.hasSidebarSubject.asObservable();
|
|
}
|
|
|
|
setHasSidebar(value: boolean) {
|
|
this.hasSidebarSubject.next(value);
|
|
}
|
|
|
|
get hasHeader(): Observable<boolean> {
|
|
return this.hasHeaderSubject.asObservable();
|
|
}
|
|
|
|
setHasHeader(value: boolean) {
|
|
this.hasHeaderSubject.next(value);
|
|
}
|
|
|
|
|
|
get hasAdminMenu(): Observable<boolean> {
|
|
return this._hasAdminMenuSubject.asObservable();
|
|
}
|
|
|
|
setHasAdminMenu(value: boolean) {
|
|
this._hasAdminMenuSubject.next(value);
|
|
}
|
|
}
|