2022-10-16 00:13:03 +02:00
|
|
|
import { Component, OnInit } from '@angular/core';
|
2022-10-18 18:04:53 +02:00
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
|
|
|
import { PrimeNGConfig } from 'primeng/api';
|
2022-10-16 00:13:03 +02:00
|
|
|
import { AuthService } from './services/auth/auth.service';
|
2022-10-16 01:55:20 +02:00
|
|
|
import { SocketService } from './services/socket/socket.service';
|
2022-10-16 00:13:03 +02:00
|
|
|
import { ThemeService } from './services/theme/theme.service';
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-root',
|
|
|
|
templateUrl: './app.component.html',
|
|
|
|
styleUrls: ['./app.component.scss']
|
|
|
|
})
|
|
|
|
export class AppComponent implements OnInit {
|
|
|
|
|
2022-10-16 12:57:27 +02:00
|
|
|
themeName!: string;
|
|
|
|
sidebarWidth!: string;
|
|
|
|
|
|
|
|
isLoggedIn: boolean = false;
|
|
|
|
|
2022-10-16 00:13:03 +02:00
|
|
|
constructor(
|
2022-10-16 16:01:37 +02:00
|
|
|
private authService: AuthService,
|
2022-10-16 12:57:27 +02:00
|
|
|
private themeService: ThemeService,
|
2022-10-18 18:04:53 +02:00
|
|
|
private socket: SocketService,
|
|
|
|
private translateService: TranslateService,
|
|
|
|
private config: PrimeNGConfig
|
|
|
|
) {
|
2022-10-16 12:57:27 +02:00
|
|
|
this.themeService.sidebarWidth$.subscribe(value => {
|
|
|
|
this.sidebarWidth = value;
|
|
|
|
});
|
|
|
|
this.themeService.themeName$.subscribe(value => {
|
|
|
|
this.themeName = value;
|
|
|
|
});
|
2022-10-16 16:01:37 +02:00
|
|
|
this.authService.isLoggedIn$.subscribe(value => {
|
|
|
|
this.isLoggedIn = value;
|
|
|
|
});
|
2022-10-18 18:04:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
this.translateService.setDefaultLang('en');
|
2022-10-16 12:57:27 +02:00
|
|
|
|
2022-10-16 00:13:03 +02:00
|
|
|
this.themeService.loadTheme();
|
2022-10-16 16:01:37 +02:00
|
|
|
this.socket.startSocket();
|
2022-10-16 00:13:03 +02:00
|
|
|
}
|
2022-10-16 12:57:27 +02:00
|
|
|
|
2022-10-18 18:04:53 +02:00
|
|
|
loadLang(): void {
|
|
|
|
let lang = localStorage.getItem(`default_lang`);
|
|
|
|
if (!lang) {
|
|
|
|
lang = 'en';
|
|
|
|
this.setLang(lang);
|
|
|
|
}
|
|
|
|
this.translate(lang);
|
|
|
|
}
|
|
|
|
|
|
|
|
setLang(lang: string): void {
|
|
|
|
localStorage.setItem(`default_lang`, lang);
|
|
|
|
}
|
|
|
|
|
|
|
|
translate(lang: string) {
|
|
|
|
this.translateService.use(lang);
|
|
|
|
this.translateService.get('primeng').subscribe(res => this.config.setTranslation(res));
|
|
|
|
}
|
|
|
|
|
2022-10-16 12:57:27 +02:00
|
|
|
|
|
|
|
setSideWidth($event: any): void {
|
|
|
|
this.themeService.setSideWidth($event);
|
|
|
|
}
|
2022-10-16 00:13:03 +02:00
|
|
|
}
|