@ -1,5 +1,5 @@
import { Component , Inject , PLATFORM_ID } from '@angular/core' ;
import { Component , Inject , PLATFORM_ID } from '@angular/core' ;
import { Router Outlet } from '@angular/router' ;
import { Router , Router Outlet } from '@angular/router' ;
import { TranslateService } from '@ngx-translate/core' ;
import { TranslateService } from '@ngx-translate/core' ;
import { StorageService } from './shared/services/storage.service' ;
import { StorageService } from './shared/services/storage.service' ;
import { isPlatformBrowser } from '@angular/common' ;
import { isPlatformBrowser } from '@angular/common' ;
@ -15,31 +15,49 @@ import { NotificationsComponent } from './shared/components/notifications/notifi
} )
} )
export class AppComponent {
export class AppComponent {
direction : any ;
direction : any ;
title = ' ACONNECT-UX ';
title = ' aConnect ';
constructor ( private translateService : TranslateService , private storageService : StorageService ,
constructor (
private translateService : TranslateService ,
private storageService : StorageService ,
private router : Router ,
@Inject ( PLATFORM_ID ) private platformId : object
@Inject ( PLATFORM_ID ) private platformId : object
) { }
) { }
ngOnInit() {
ngOnInit() {
if ( this . storageService . getItem ( 'language' ) ) {
if ( ! isPlatformBrowser ( this . platformId ) ) return ;
const currentLanguage = this . storageService . getItem ( 'language' ) ! ;
if ( isPlatformBrowser ( this . platformId ) ) {
const currentLanguage = this . storageService . getItem ( 'language' ) || supportedLanguages . ENGLISH ;
this . storageService . setItem ( 'language' , currentLanguage ) ;
this . translateService . setDefaultLang ( currentLanguage ) ;
this . translateService . setDefaultLang ( currentLanguage ) ;
this . translateService . use ( currentLanguage ) ;
this . translateService . use ( currentLanguage ) ;
}
this . direction = this . storageService . getItem ( 'direction' ) ;
this . direction = this . storageService . getItem ( 'direction' ) || directions . LTR ;
this . storageService . setItem ( 'direction' , this . direction ) ;
const userStr = this . storageService . getItem ( 'user' ) ;
if ( userStr ) {
try {
const data = JSON . parse ( userStr ) ;
if ( data ? . token ) {
if ( this . router . url === '/' || this . router . url === '/login' ) {
this . router . navigate ( [ '/home/dashboard' ] ) ;
}
}
else {
} else {
if ( isPlatformBrowser ( this . platformId ) ) {
if ( this . router . url === '/' ) {
this . translateService . setDefaultLang ( 'English' ) ;
this . router . navigate ( [ '/login' ] ) ;
this . translateService . use ( 'English' ) ;
}
}
} catch {
this . storageService . removeItem ( 'user' ) ;
if ( this . router . url === '/' ) {
this . router . navigate ( [ '/login' ] ) ;
}
}
} else {
if ( this . router . url === '/' ) {
this . router . navigate ( [ '/login' ] ) ;
}
}
this . storageService . setItem ( 'language' , supportedLanguages . ENGLISH ) ;
this . direction = directions . LTR ;
this . storageService . setItem ( 'direction' , this . direction ) ;
}
}
}
}
}
}