Moved Dashboad webapp on Angular 5 !
[src/xds/xds-agent.git] / webapp / src / app / app.component.ts
1 import { Component, OnInit, OnDestroy } from '@angular/core';
2 import { TranslateService } from '@ngx-translate/core';
3 import { ConfigService, IConfig } from './services/config.service';
4
5 @Component({
6     selector: 'app-root',
7     templateUrl: 'app.component.html',
8     styleUrls: ['app.component.css']
9 })
10
11 export class AppComponent implements OnInit, OnDestroy {
12     private defaultLanguage = 'en';
13     public isCollapsed = true;
14
15     constructor(private translate: TranslateService, private configSvr: ConfigService) {
16     }
17
18     ngOnInit() {
19         this.translate.addLangs(['en', 'fr']);
20         this.translate.setDefaultLang(this.defaultLanguage);
21
22         const browserLang = this.translate.getBrowserLang();
23         this.translate.use(browserLang.match(/en|fr/) ? browserLang : this.defaultLanguage);
24
25         this.configSvr.Conf$.subscribe((cfg: IConfig) => {
26             let lang: string;
27             switch (cfg.language) {
28                 case 'ENG':
29                     lang = 'en';
30                     break;
31                 case 'FRA':
32                     lang = 'fr';
33                     break;
34                 default:
35                     lang = this.defaultLanguage;
36             }
37             this.translate.use(lang);
38         });
39     }
40
41     ngOnDestroy(): void {
42         // this.aglIdentityService.loginResponse.unsubscribe();
43         // this.aglIdentityService.logoutResponse.unsubscribe();
44     }
45 }