mirror of
https://github.com/richard-loafle/fuse-angular.git
synced 2025-04-15 12:55:14 +00:00
(layouts) Common components of layouts now requests their data directly from their service rather than getting it from route data (core) New navigation service to request and store the navigation data
114 lines
3.6 KiB
TypeScript
114 lines
3.6 KiB
TypeScript
import { Component, OnDestroy, OnInit, ViewEncapsulation } from '@angular/core';
|
|
import { ActivatedRoute, Router } from '@angular/router';
|
|
import { Subject } from 'rxjs';
|
|
import { takeUntil } from 'rxjs/operators';
|
|
import { FuseMediaWatcherService } from '@fuse/services/media-watcher';
|
|
import { FuseNavigationService, FuseVerticalNavigationComponent } from '@fuse/components/navigation';
|
|
import { Navigation } from 'app/core/navigation/navigation.types';
|
|
import { NavigationService } from 'app/core/navigation/navigation.service';
|
|
import { User } from 'app/core/user/user.types';
|
|
import { UserService } from 'app/core/user/user.service';
|
|
|
|
@Component({
|
|
selector : 'futuristic-layout',
|
|
templateUrl : './futuristic.component.html',
|
|
encapsulation: ViewEncapsulation.None
|
|
})
|
|
export class FuturisticLayoutComponent implements OnInit, OnDestroy
|
|
{
|
|
isScreenSmall: boolean;
|
|
navigation: Navigation;
|
|
user: User;
|
|
private _unsubscribeAll: Subject<any> = new Subject<any>();
|
|
|
|
/**
|
|
* Constructor
|
|
*/
|
|
constructor(
|
|
private _activatedRoute: ActivatedRoute,
|
|
private _router: Router,
|
|
private _navigationService: NavigationService,
|
|
private _userService: UserService,
|
|
private _fuseMediaWatcherService: FuseMediaWatcherService,
|
|
private _fuseNavigationService: FuseNavigationService
|
|
)
|
|
{
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------------------------------
|
|
// @ Accessors
|
|
// -----------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
* Getter for current year
|
|
*/
|
|
get currentYear(): number
|
|
{
|
|
return new Date().getFullYear();
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------------------------------
|
|
// @ Lifecycle hooks
|
|
// -----------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
* On init
|
|
*/
|
|
ngOnInit(): void
|
|
{
|
|
// Subscribe to navigation data
|
|
this._navigationService.navigation$
|
|
.pipe(takeUntil(this._unsubscribeAll))
|
|
.subscribe((navigation: Navigation) => {
|
|
this.navigation = navigation;
|
|
});
|
|
|
|
// Subscribe to the user service
|
|
this._userService.user$
|
|
.pipe((takeUntil(this._unsubscribeAll)))
|
|
.subscribe((user: User) => {
|
|
this.user = user;
|
|
});
|
|
|
|
// Subscribe to media changes
|
|
this._fuseMediaWatcherService.onMediaChange$
|
|
.pipe(takeUntil(this._unsubscribeAll))
|
|
.subscribe(({matchingAliases}) => {
|
|
|
|
// Check if the screen is small
|
|
this.isScreenSmall = !matchingAliases.includes('md');
|
|
});
|
|
}
|
|
|
|
/**
|
|
* On destroy
|
|
*/
|
|
ngOnDestroy(): void
|
|
{
|
|
// Unsubscribe from all subscriptions
|
|
this._unsubscribeAll.next();
|
|
this._unsubscribeAll.complete();
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------------------------------
|
|
// @ Public methods
|
|
// -----------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
* Toggle navigation
|
|
*
|
|
* @param name
|
|
*/
|
|
toggleNavigation(name: string): void
|
|
{
|
|
// Get the navigation
|
|
const navigation = this._fuseNavigationService.getComponent<FuseVerticalNavigationComponent>(name);
|
|
|
|
if ( navigation )
|
|
{
|
|
// Toggle the opened status
|
|
navigation.toggle();
|
|
}
|
|
}
|
|
}
|