2018-07-12 06:24:54 +00:00
|
|
|
import { Component, Inject, OnDestroy, OnInit } from '@angular/core';
|
|
|
|
import { DOCUMENT } from '@angular/common';
|
|
|
|
import { Platform } from '@angular/cdk/platform';
|
2017-10-24 12:41:44 +00:00
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
2018-05-29 11:58:48 +00:00
|
|
|
import { Subject } from 'rxjs';
|
|
|
|
import { takeUntil } from 'rxjs/operators';
|
2017-12-06 11:10:48 +00:00
|
|
|
|
2018-05-29 11:58:48 +00:00
|
|
|
import { FuseConfigService } from '@fuse/services/config.service';
|
|
|
|
import { FuseNavigationService } from '@fuse/components/navigation/navigation.service';
|
2018-05-30 09:23:09 +00:00
|
|
|
import { FuseSidebarService } from '@fuse/components/sidebar/sidebar.service';
|
2018-02-17 14:21:38 +00:00
|
|
|
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';
|
2017-06-27 08:08:19 +00:00
|
|
|
|
|
|
|
@Component({
|
2018-05-23 09:35:08 +00:00
|
|
|
selector : 'app',
|
2017-07-08 16:12:52 +00:00
|
|
|
templateUrl: './app.component.html',
|
2017-07-12 12:35:07 +00:00
|
|
|
styleUrls : ['./app.component.scss']
|
2017-06-27 08:08:19 +00:00
|
|
|
})
|
2018-05-29 11:58:48 +00:00
|
|
|
export class AppComponent implements OnInit, OnDestroy
|
2017-07-08 16:12:52 +00:00
|
|
|
{
|
2018-05-29 11:58:48 +00:00
|
|
|
fuseConfig: any;
|
2018-07-13 09:54:02 +00:00
|
|
|
navigation: any;
|
2018-05-29 11:58:48 +00:00
|
|
|
|
|
|
|
// Private
|
|
|
|
private _unsubscribeAll: Subject<any>;
|
2018-05-20 07:12:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
2018-07-12 06:24:54 +00:00
|
|
|
* @param {DOCUMENT} document
|
2018-05-29 11:58:48 +00:00
|
|
|
* @param {FuseConfigService} _fuseConfigService
|
2018-05-20 07:12:31 +00:00
|
|
|
* @param {FuseNavigationService} _fuseNavigationService
|
2018-05-30 09:23:09 +00:00
|
|
|
* @param {FuseSidebarService} _fuseSidebarService
|
2018-05-20 07:12:31 +00:00
|
|
|
* @param {FuseSplashScreenService} _fuseSplashScreenService
|
|
|
|
* @param {FuseTranslationLoaderService} _fuseTranslationLoaderService
|
2018-07-12 06:24:54 +00:00
|
|
|
* @param {Platform} _platform
|
2018-05-20 07:12:31 +00:00
|
|
|
* @param {TranslateService} _translateService
|
|
|
|
*/
|
2017-10-24 12:41:44 +00:00
|
|
|
constructor(
|
2018-07-12 06:24:54 +00:00
|
|
|
@Inject(DOCUMENT) private document: any,
|
2018-05-29 11:58:48 +00:00
|
|
|
private _fuseConfigService: FuseConfigService,
|
2018-05-20 07:12:31 +00:00
|
|
|
private _fuseNavigationService: FuseNavigationService,
|
2018-05-30 09:23:09 +00:00
|
|
|
private _fuseSidebarService: FuseSidebarService,
|
2018-05-20 07:12:31 +00:00
|
|
|
private _fuseSplashScreenService: FuseSplashScreenService,
|
|
|
|
private _fuseTranslationLoaderService: FuseTranslationLoaderService,
|
2018-07-12 06:24:54 +00:00
|
|
|
private _translateService: TranslateService,
|
|
|
|
private _platform: Platform
|
2017-10-24 12:41:44 +00:00
|
|
|
)
|
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');
|
|
|
|
|
2017-10-24 12:41:44 +00:00
|
|
|
// Add languages
|
2018-05-20 07:12:31 +00:00
|
|
|
this._translateService.addLangs(['en', 'tr']);
|
2017-10-24 12:41:44 +00:00
|
|
|
|
|
|
|
// Set the default language
|
2018-05-20 07:12:31 +00:00
|
|
|
this._translateService.setDefaultLang('en');
|
2017-10-24 12:41:44 +00:00
|
|
|
|
2018-03-08 09:25:27 +00:00
|
|
|
// Set the navigation translations
|
2018-05-20 07:12:31 +00:00
|
|
|
this._fuseTranslationLoaderService.loadTranslations(navigationEnglish, navigationTurkish);
|
2018-03-08 09:25:27 +00:00
|
|
|
|
2017-10-24 12:41:44 +00:00
|
|
|
// Use a language
|
2018-05-20 07:12:31 +00:00
|
|
|
this._translateService.use('en');
|
2018-05-29 11:58:48 +00:00
|
|
|
|
2018-08-11 06:02:05 +00:00
|
|
|
/**
|
2018-08-17 10:07:01 +00:00
|
|
|
* ------------------------------------------------------------------
|
|
|
|
* ngxTranslate Fix Start
|
|
|
|
* ------------------------------------------------------------------
|
|
|
|
* If you are using a language other than the default one, i.e. Turkish in this case,
|
|
|
|
* you may encounter an issue where some of the components are not actually being
|
|
|
|
* translated when your app first initialized.
|
|
|
|
*
|
|
|
|
* This is related to ngxTranslate module and below there is a temporary fix while we
|
|
|
|
* are moving the multi language implementation over to the Angular's core language
|
|
|
|
* service.
|
2018-08-11 06:02:05 +00:00
|
|
|
**/
|
|
|
|
|
2018-08-17 10:07:01 +00:00
|
|
|
// Set the default language to 'en' and then back to 'tr'.
|
|
|
|
// '.use' cannot be used here as ngxTranslate won't switch to a language that's already
|
|
|
|
// been selected and there is no way to force it, so we overcome the issue by switching
|
|
|
|
// the default language back and forth.
|
2018-08-11 06:02:05 +00:00
|
|
|
/**
|
|
|
|
setTimeout(() => {
|
|
|
|
this._translateService.setDefaultLang('en');
|
|
|
|
this._translateService.setDefaultLang('tr');
|
|
|
|
});
|
|
|
|
*/
|
|
|
|
|
2018-08-17 10:07:01 +00:00
|
|
|
/**
|
|
|
|
* ------------------------------------------------------------------
|
|
|
|
* ngxTranslate Fix End
|
|
|
|
* ------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2018-07-12 06:24:54 +00:00
|
|
|
// Add is-mobile class to the body if the platform is mobile
|
|
|
|
if ( this._platform.ANDROID || this._platform.IOS )
|
|
|
|
{
|
2018-07-13 15:55:45 +00:00
|
|
|
this.document.body.classList.add('is-mobile');
|
2018-07-12 06:24:54 +00:00
|
|
|
}
|
|
|
|
|
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) => {
|
2018-08-26 15:30:00 +00:00
|
|
|
|
2018-05-29 11:58:48 +00:00
|
|
|
this.fuseConfig = config;
|
2018-07-13 15:55:45 +00:00
|
|
|
|
2018-08-26 15:30:00 +00:00
|
|
|
// Boxed
|
2018-07-13 15:55:45 +00:00
|
|
|
if ( this.fuseConfig.layout.width === 'boxed' )
|
|
|
|
{
|
|
|
|
this.document.body.classList.add('boxed');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.document.body.classList.remove('boxed');
|
|
|
|
}
|
2018-08-26 15:30:00 +00:00
|
|
|
|
|
|
|
// Color theme
|
|
|
|
this.document.body.classList.forEach(className => {
|
|
|
|
if ( className.startsWith('theme-') )
|
|
|
|
{
|
|
|
|
this.document.body.classList.remove(className);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
this.document.body.classList.add(this.fuseConfig.colorTheme);
|
2018-05-29 11:58:48 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* On destroy
|
|
|
|
*/
|
|
|
|
ngOnDestroy(): void
|
|
|
|
{
|
|
|
|
// Unsubscribe from all subscriptions
|
|
|
|
this._unsubscribeAll.next();
|
|
|
|
this._unsubscribeAll.complete();
|
2017-07-12 12:35:07 +00:00
|
|
|
}
|
2018-05-30 09:23:09 +00:00
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------------------------------
|
2018-06-15 14:45:27 +00:00
|
|
|
// @ Public methods
|
2018-05-30 09:23:09 +00:00
|
|
|
// -----------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Toggle sidebar open
|
|
|
|
*
|
|
|
|
* @param key
|
|
|
|
*/
|
2018-06-15 14:46:41 +00:00
|
|
|
toggleSidebarOpen(key): void
|
2018-05-30 09:23:09 +00:00
|
|
|
{
|
|
|
|
this._fuseSidebarService.getSidebar(key).toggleOpen();
|
|
|
|
}
|
2017-06-27 08:08:19 +00:00
|
|
|
}
|