2020-05-01 19:10:17 +02:00
|
|
|
import { Component, OnDestroy, OnInit } from '@angular/core';
|
2020-04-22 12:56:18 +02:00
|
|
|
import { Title } from '@angular/platform-browser';
|
2020-05-01 19:10:17 +02:00
|
|
|
import { Subscription } from 'rxjs';
|
2020-04-22 12:56:18 +02:00
|
|
|
|
2020-04-14 11:28:33 +02:00
|
|
|
import { environment } from '../environments/environment';
|
2020-04-22 12:56:18 +02:00
|
|
|
import { Theme } from './core/enums/theme.enum';
|
2020-05-01 19:10:17 +02:00
|
|
|
import { UserRole } from './core/enums/user-role.enum';
|
2020-05-05 18:17:12 +02:00
|
|
|
import { User } from './core/models/user.model';
|
|
|
|
import { LanguageService } from './core/services/language.service';
|
2020-05-01 19:10:17 +02:00
|
|
|
import { MockingService } from './core/services/mocking.service';
|
2020-04-22 12:56:18 +02:00
|
|
|
import { ThemeService } from './core/services/theme.service';
|
2019-08-09 13:38:51 +02:00
|
|
|
|
|
|
|
@Component({
|
2020-04-21 10:50:26 +02:00
|
|
|
selector: 'app-root',
|
|
|
|
templateUrl: './app.component.html',
|
|
|
|
styleUrls: ['./app.component.scss'],
|
2019-08-09 13:38:51 +02:00
|
|
|
})
|
2020-04-22 12:56:18 +02:00
|
|
|
export class AppComponent implements OnInit, OnDestroy {
|
|
|
|
public appTitle: string = environment.appTitle;
|
|
|
|
public themeClass: string;
|
2020-05-01 19:10:17 +02:00
|
|
|
public isSidebarOpened = false;
|
2020-04-22 12:56:18 +02:00
|
|
|
private themeSubscription: Subscription;
|
|
|
|
|
2020-04-21 10:50:26 +02:00
|
|
|
constructor(
|
2020-04-22 12:56:18 +02:00
|
|
|
private titleService: Title,
|
|
|
|
private themeService: ThemeService,
|
2020-05-05 18:17:12 +02:00
|
|
|
private languageService: LanguageService,
|
2020-05-01 19:10:17 +02:00
|
|
|
private mockingService: MockingService
|
2020-04-22 12:56:18 +02:00
|
|
|
) {}
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
if (!environment.production) {
|
2020-05-01 19:10:17 +02:00
|
|
|
this.appTitle += ' [DEV]';
|
2020-05-05 18:17:12 +02:00
|
|
|
// TODO: to be removed
|
2020-05-12 19:16:23 +02:00
|
|
|
this.mockingService.loadUser(new User('TOTO', 'toto@gafam.com', UserRole.REGISTERED));
|
2020-04-22 12:56:18 +02:00
|
|
|
}
|
|
|
|
this.titleService.setTitle(this.appTitle);
|
2020-05-05 18:17:12 +02:00
|
|
|
this.languageService.configureAndInitTranslations();
|
2020-04-22 12:56:18 +02:00
|
|
|
this.themeSubscription = this.themeService.theme.subscribe((theme: Theme) => {
|
|
|
|
switch (theme) {
|
|
|
|
case Theme.DARK:
|
|
|
|
this.themeClass = 'theme-dark-crystal';
|
|
|
|
break;
|
|
|
|
case Theme.RED:
|
|
|
|
this.themeClass = 'theme-hot-covid';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
this.themeClass = 'theme-light-watermelon';
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2020-01-16 11:02:57 +01:00
|
|
|
|
2020-04-22 12:56:18 +02:00
|
|
|
ngOnDestroy(): void {
|
|
|
|
if (this.themeSubscription) {
|
|
|
|
this.themeSubscription.unsubscribe();
|
|
|
|
}
|
2020-04-21 10:50:26 +02:00
|
|
|
}
|
2020-01-16 11:02:57 +01:00
|
|
|
|
2020-05-01 19:10:17 +02:00
|
|
|
public toggleSidebar(status: boolean): void {
|
|
|
|
this.isSidebarOpened = status === true;
|
2020-04-22 12:56:18 +02:00
|
|
|
}
|
2019-08-09 13:38:51 +02:00
|
|
|
}
|