mirror of
https://github.com/richard-loafle/fuse-angular.git
synced 2025-04-27 10:33:12 +00:00
96 lines
2.7 KiB
TypeScript
96 lines
2.7 KiB
TypeScript
import { Component, Input, OnDestroy, OnInit, ViewChild, ViewEncapsulation } from '@angular/core';
|
|
import { NavigationEnd, Router } from '@angular/router';
|
|
|
|
import { Subscription } from 'rxjs';
|
|
|
|
import { FusePerfectScrollbarDirective } from '@fuse/directives/fuse-perfect-scrollbar/fuse-perfect-scrollbar.directive';
|
|
import { FuseSidebarService } from '@fuse/components/sidebar/sidebar.service';
|
|
|
|
import { navigation } from 'app/navigation/navigation';
|
|
import { FuseNavigationService } from '@fuse/components/navigation/navigation.service';
|
|
import { FuseSidebarComponent } from '@fuse/components/sidebar/sidebar.component';
|
|
|
|
@Component({
|
|
selector : 'fuse-navbar',
|
|
templateUrl : './navbar.component.html',
|
|
styleUrls : ['./navbar.component.scss'],
|
|
encapsulation: ViewEncapsulation.None
|
|
})
|
|
export class FuseNavbarComponent implements OnInit, OnDestroy
|
|
{
|
|
private fusePerfectScrollbar: FusePerfectScrollbarDirective;
|
|
|
|
@ViewChild(FusePerfectScrollbarDirective) set directive(theDirective: FusePerfectScrollbarDirective)
|
|
{
|
|
if ( !theDirective )
|
|
{
|
|
return;
|
|
}
|
|
|
|
this.fusePerfectScrollbar = theDirective;
|
|
|
|
this.navigationServiceWatcher =
|
|
this.navigationService.onItemCollapseToggled.subscribe(() => {
|
|
this.fusePerfectScrollbarUpdateTimeout = setTimeout(() => {
|
|
this.fusePerfectScrollbar.update();
|
|
}, 310);
|
|
});
|
|
}
|
|
|
|
@Input() layout;
|
|
navigation: any;
|
|
navigationServiceWatcher: Subscription;
|
|
fusePerfectScrollbarUpdateTimeout;
|
|
|
|
constructor(
|
|
private sidebarService: FuseSidebarService,
|
|
private navigationService: FuseNavigationService,
|
|
private router: Router
|
|
)
|
|
{
|
|
// Navigation data
|
|
this.navigation = navigation;
|
|
|
|
// Default layout
|
|
this.layout = 'vertical';
|
|
}
|
|
|
|
ngOnInit()
|
|
{
|
|
this.router.events.subscribe(
|
|
(event) => {
|
|
if ( event instanceof NavigationEnd )
|
|
{
|
|
if ( this.sidebarService.getSidebar('navbar') )
|
|
{
|
|
this.sidebarService.getSidebar('navbar').close();
|
|
}
|
|
}
|
|
}
|
|
);
|
|
}
|
|
|
|
ngOnDestroy()
|
|
{
|
|
if ( this.fusePerfectScrollbarUpdateTimeout )
|
|
{
|
|
clearTimeout(this.fusePerfectScrollbarUpdateTimeout);
|
|
}
|
|
|
|
if ( this.navigationServiceWatcher )
|
|
{
|
|
this.navigationServiceWatcher.unsubscribe();
|
|
}
|
|
}
|
|
|
|
toggleSidebarOpened()
|
|
{
|
|
this.sidebarService.getSidebar('navbar').toggleOpen();
|
|
}
|
|
|
|
toggleSidebarFolded()
|
|
{
|
|
this.sidebarService.getSidebar('navbar').toggleFold();
|
|
}
|
|
}
|