admin-layout.component.ts
2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import { Component, ElementRef, NgZone, OnInit, OnDestroy, ViewChild, HostListener } from '@angular/core';
import { Router, NavigationEnd } from '@angular/router';
import { Subscription } from 'rxjs/Subscription';
import 'rxjs/add/operator/filter';
import { TranslateService } from '@ngx-translate/core';
import { PerfectScrollbarConfigInterface, PerfectScrollbarDirective } from 'ngx-perfect-scrollbar';
const SMALL_WIDTH_BREAKPOINT = 960;
@Component({
selector: 'app-layout',
templateUrl: './admin-layout.component.html'
})
export class AdminLayoutComponent implements OnInit, OnDestroy {
private _router: Subscription;
mediaMatcher: MediaQueryList = matchMedia(`(max-width: ${SMALL_WIDTH_BREAKPOINT}px)`);
url: string;
sidePanelOpened;
options = {
collapsed: false,
compact: false,
boxed: false,
dark: false,
dir: 'ltr'
};
@ViewChild('sidemenu') sidemenu;
@ViewChild(PerfectScrollbarDirective) directiveScroll: PerfectScrollbarDirective;
public config: PerfectScrollbarConfigInterface = {};
constructor(
private _element: ElementRef,
private router: Router,
zone: NgZone) {
this.mediaMatcher.addListener(mql => zone.run(() => {
this.mediaMatcher = mql;
}));
}
ngOnInit(): void {
this.url = this.router.url;
this._router = this.router.events.filter(event => event instanceof NavigationEnd).subscribe((event: NavigationEnd) => {
document.querySelector('.app-inner > .mat-drawer-content > div').scrollTop = 0;
this.url = event.url;
this.runOnRouteChange();
});
}
ngOnDestroy(): void {
this._router.unsubscribe();
}
runOnRouteChange(): void {
if (this.isOver()) {
this.sidemenu.close();
}
this.updatePS();
}
receiveOptions($event): void {
this.options = $event;
}
isOver(): boolean {
if (this.url === '/apps/messages' ||
this.url === '/apps/calendar' ||
this.url === '/apps/media' ||
this.url === '/maps/leaflet' ||
this.url === '/taskboard') {
return true;
} else {
return this.mediaMatcher.matches;
}
}
menuMouseOver(): void {
if (this.mediaMatcher.matches && this.options.collapsed) {
this.sidemenu.mode = 'over';
}
}
menuMouseOut(): void {
if (this.mediaMatcher.matches && this.options.collapsed) {
this.sidemenu.mode = 'side';
}
}
updatePS(): void {
if (!this.mediaMatcher.matches && !this.options.compact) {
setTimeout(() => {
this.directiveScroll.update();
}, 350);
}
}
}