import { Component, OnInit } from "@angular/core"; import { Router } from "@angular/router"; import { TranslateService } from "@ngx-translate/core"; import { User } from "../models/user"; import { CacheApiKey } from "../models/cache-api-key.enum"; import { AuthenticationService } from "../services/authentication.service"; import { ServiceComm } from "../services/service-comm.service"; import { ConfigurationHelper } from "../services/configuration-helper"; import { ServiceCacheApi } from "../services/service-cache-api.service"; @Component({ selector: "app-root", templateUrl: "./app.component.html", styleUrls: ["./app.component.css"], standalone: false }) export class AppComponent implements OnInit { public title = "app"; public currentUser: User; public version: string; public selectedLanguageFlag: string; constructor(private router: Router, private authenticationService: AuthenticationService, private serviceComm: ServiceComm, private serviceCacheApi : ServiceCacheApi, private translateService: TranslateService) { this.authenticationService.currentUser.subscribe(user => { if (user) { this.currentUser = user; this.translateService.addLangs(['en', 'fr']); this.translateService.use(user.language); this.selectedLanguageFlag = user.language; } }); ConfigurationHelper.settings.subscribe(settings => { if (settings != null) { this.version = settings.version; } }); } ngOnInit() { this.serviceComm.componentTitle.subscribe(title => (this.title = title)); } public show() { return this.authenticationService.currentUserValue != undefined; } public logout() { this.serviceCacheApi.delete(CacheApiKey.Dropzone); this.authenticationService.logout(); this.router.navigate(["/login"], { skipLocationChange: true }); } public switchLang(event: any) { this.translateService.use(event.value); this.currentUser.language = event.value; this.authenticationService.currentUserValue = this.currentUser; this.selectedLanguageFlag = event.value; this.serviceComm.forceTranslate(); } }