fuse-angular/src/app/app.component.ts

114 lines
3.7 KiB
TypeScript
Raw Normal View History

2018-05-29 11:58:48 +00:00
import { Component, OnDestroy, OnInit } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
2018-05-29 11:58:48 +00:00
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
2018-05-29 11:58:48 +00:00
import { FuseConfigService } from '@fuse/services/config.service';
import { FuseNavigationService } from '@fuse/components/navigation/navigation.service';
import { FuseSidebarService } from '@fuse/components/sidebar/sidebar.service';
import { FuseSplashScreenService } from '@fuse/services/splash-screen.service';
import { FuseTranslationLoaderService } from '@fuse/services/translation-loader.service';
2018-05-20 07:12:31 +00:00
import { navigation } from 'app/navigation/navigation';
import { locale as navigationEnglish } from 'app/navigation/i18n/en';
import { locale as navigationTurkish } from 'app/navigation/i18n/tr';
@Component({
selector : 'app',
templateUrl: './app.component.html',
2017-07-12 12:35:07 +00:00
styleUrls : ['./app.component.scss']
})
2018-05-29 11:58:48 +00:00
export class AppComponent implements OnInit, OnDestroy
{
2018-05-20 07:12:31 +00:00
navigation: any;
2018-05-29 11:58:48 +00:00
fuseConfig: any;
// Private
private _unsubscribeAll: Subject<any>;
2018-05-20 07:12:31 +00:00
/**
* Constructor
*
2018-05-29 11:58:48 +00:00
* @param {FuseConfigService} _fuseConfigService
2018-05-20 07:12:31 +00:00
* @param {FuseNavigationService} _fuseNavigationService
* @param {FuseSidebarService} _fuseSidebarService
2018-05-20 07:12:31 +00:00
* @param {FuseSplashScreenService} _fuseSplashScreenService
* @param {FuseTranslationLoaderService} _fuseTranslationLoaderService
* @param {TranslateService} _translateService
*/
constructor(
2018-05-29 11:58:48 +00:00
private _fuseConfigService: FuseConfigService,
2018-05-20 07:12:31 +00:00
private _fuseNavigationService: FuseNavigationService,
private _fuseSidebarService: FuseSidebarService,
2018-05-20 07:12:31 +00:00
private _fuseSplashScreenService: FuseSplashScreenService,
private _fuseTranslationLoaderService: FuseTranslationLoaderService,
private _translateService: TranslateService
)
2017-07-12 12:35:07 +00:00
{
2018-05-29 11:58:48 +00:00
// Get default navigation
2018-05-20 07:12:31 +00:00
this.navigation = navigation;
2018-05-29 11:58:48 +00:00
// Register the navigation to the service
this._fuseNavigationService.register('main', this.navigation);
// Set the main navigation as our current navigation
this._fuseNavigationService.setCurrentNavigation('main');
// Add languages
2018-05-20 07:12:31 +00:00
this._translateService.addLangs(['en', 'tr']);
// Set the default language
2018-05-20 07:12:31 +00:00
this._translateService.setDefaultLang('en');
// Set the navigation translations
2018-05-20 07:12:31 +00:00
this._fuseTranslationLoaderService.loadTranslations(navigationEnglish, navigationTurkish);
// Use a language
2018-05-20 07:12:31 +00:00
this._translateService.use('en');
2018-05-29 11:58:48 +00:00
// Set the private defaults
this._unsubscribeAll = new Subject();
}
// -----------------------------------------------------------------------------------------------------
// @ Lifecycle hooks
// -----------------------------------------------------------------------------------------------------
/**
* On init
*/
ngOnInit(): void
{
// Subscribe to config changes
this._fuseConfigService.config
.pipe(takeUntil(this._unsubscribeAll))
.subscribe((config) => {
this.fuseConfig = config;
});
}
/**
* On destroy
*/
ngOnDestroy(): void
{
// Unsubscribe from all subscriptions
this._unsubscribeAll.next();
this._unsubscribeAll.complete();
2017-07-12 12:35:07 +00:00
}
// -----------------------------------------------------------------------------------------------------
2018-06-15 14:45:27 +00:00
// @ Public methods
// -----------------------------------------------------------------------------------------------------
/**
* Toggle sidebar open
*
* @param key
*/
2018-06-15 14:45:27 +00:00
private toggleSidebarOpen(key): void
{
this._fuseSidebarService.getSidebar(key).toggleOpen();
}
}