2019-11-01 19:30:11 +01:00
|
|
|
import {Injectable} from "@angular/core";
|
|
|
|
import {BehaviorSubject, Observable} from "rxjs";
|
2019-11-14 13:42:41 +01:00
|
|
|
import {ActivationStart, Router} from "@angular/router";
|
2019-11-01 19:30:11 +01:00
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
providedIn: 'root'
|
|
|
|
})
|
|
|
|
export class SideBarService {
|
|
|
|
|
2019-11-12 16:55:37 +01:00
|
|
|
/**
|
|
|
|
* Set this to true when sidebar items are ready.
|
|
|
|
*/
|
|
|
|
private openSubject: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
|
|
|
|
|
|
|
|
/**
|
2019-11-14 16:20:51 +01:00
|
|
|
* Add hasSidebar: false on data of route config, if sidebar is not needed.
|
2019-11-12 16:55:37 +01:00
|
|
|
*/
|
|
|
|
private hasSidebarSubject: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(true);
|
2019-11-01 19:30:11 +01:00
|
|
|
|
2019-11-14 13:42:41 +01:00
|
|
|
constructor(private router: Router) {
|
|
|
|
this.router.events.subscribe(event => {
|
|
|
|
if (event instanceof ActivationStart) {
|
|
|
|
let data = event.snapshot.data;
|
|
|
|
if (this.hasSidebarSubject.value === true &&
|
|
|
|
data['hasSidebar'] !== undefined &&
|
|
|
|
data['hasSidebar'] === false) {
|
|
|
|
this.setHasSidebar(false);
|
|
|
|
} else if (this.hasSidebarSubject.value === false) {
|
|
|
|
this.setHasSidebar(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2019-11-01 19:30:11 +01:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|