admin-layout.component.ts 2.6 KB

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