2021-11-16 16:16:30 +01:00
|
|
|
import { AfterViewInit, Component, Inject, OnDestroy, OnInit } from '@angular/core';
|
2020-10-17 11:12:53 +02:00
|
|
|
import { Title } from '@angular/platform-browser';
|
|
|
|
import { Subscription } from 'rxjs';
|
2020-04-22 12:56:18 +02:00
|
|
|
|
2020-10-17 11:12:53 +02:00
|
|
|
import { environment } from '../environments/environment';
|
|
|
|
import { Theme } from './core/enums/theme.enum';
|
|
|
|
import { LanguageService } from './core/services/language.service';
|
|
|
|
import { ThemeService } from './core/services/theme.service';
|
2022-02-03 12:26:04 +01:00
|
|
|
import { NavigationEnd, Route, Router } from '@angular/router';
|
2021-05-18 11:21:40 +02:00
|
|
|
import { slideInAnimation } from './shared/animations/main';
|
2021-05-18 13:34:28 +02:00
|
|
|
import { FramaKeyboardShortcuts } from './shared/shortcuts/main';
|
2021-05-18 15:19:11 +02:00
|
|
|
import { ShortcutEventOutput, ShortcutInput } from 'ng-keyboard-shortcuts';
|
2021-09-09 09:59:02 +02:00
|
|
|
import { PollService } from './core/services/poll.service';
|
2021-11-08 10:26:16 +01:00
|
|
|
import { PrimeNGConfig } from 'primeng/api';
|
2021-11-16 16:16:30 +01:00
|
|
|
import { ApiService } from './core/services/api.service';
|
|
|
|
import { DOCUMENT } from '@angular/common';
|
2022-02-14 10:37:38 +01:00
|
|
|
import { Poll } from './core/models/poll.model';
|
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
|
|
|
import { ToastService } from './core/services/toast.service';
|
|
|
|
import { StorageService } from './core/services/storage.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'],
|
2021-05-18 11:21:40 +02:00
|
|
|
animations: [slideInAnimation],
|
2019-08-09 13:38:51 +02:00
|
|
|
})
|
2021-05-18 13:34:28 +02:00
|
|
|
export class AppComponent implements OnInit, OnDestroy, AfterViewInit {
|
|
|
|
shortcuts: ShortcutInput[] = FramaKeyboardShortcuts;
|
|
|
|
|
2020-04-22 12:56:18 +02:00
|
|
|
public appTitle: string = environment.appTitle;
|
2020-08-12 16:00:20 +02:00
|
|
|
public appLogo: string = environment.appLogo;
|
2020-04-22 12:56:18 +02:00
|
|
|
public themeClass: string;
|
2020-05-01 19:10:17 +02:00
|
|
|
public isSidebarOpened = false;
|
2020-10-21 17:02:01 +02:00
|
|
|
public devModeEnabled = !environment.production;
|
2021-05-01 23:10:00 +02:00
|
|
|
public environment = environment;
|
2022-02-14 10:37:38 +01:00
|
|
|
|
2021-11-18 14:57:07 +01:00
|
|
|
public onHomePage = false;
|
2021-12-21 16:45:19 +01:00
|
|
|
private themeSubscription: Subscription;
|
2021-05-01 23:10:00 +02:00
|
|
|
|
2020-04-21 10:50:26 +02:00
|
|
|
constructor(
|
2021-04-25 11:58:58 +02:00
|
|
|
private router: Router,
|
2020-04-22 12:56:18 +02:00
|
|
|
private titleService: Title,
|
2022-02-14 10:37:38 +01:00
|
|
|
private translate: TranslateService,
|
2020-04-22 12:56:18 +02:00
|
|
|
private themeService: ThemeService,
|
2021-09-09 09:59:02 +02:00
|
|
|
private pollService: PollService,
|
2022-02-14 10:37:38 +01:00
|
|
|
private storageService: StorageService,
|
2021-11-16 16:16:30 +01:00
|
|
|
private apiService: ApiService,
|
2022-02-14 10:37:38 +01:00
|
|
|
private toastService: ToastService,
|
2021-11-08 10:26:16 +01:00
|
|
|
private config: PrimeNGConfig,
|
2021-11-16 16:16:30 +01:00
|
|
|
@Inject(DOCUMENT) private document: any,
|
2020-10-21 17:02:01 +02:00
|
|
|
private languageService: LanguageService // private mockingService: MockingService
|
|
|
|
) {}
|
2020-04-22 12:56:18 +02:00
|
|
|
|
2021-06-10 10:52:32 +02:00
|
|
|
printpath(parent: string, config: Route[]) {
|
|
|
|
for (let i = 0; i < config.length; i++) {
|
|
|
|
const route = config[i];
|
|
|
|
if (route.children) {
|
|
|
|
const currentPath = route.path ? parent + '/' + route.path : parent;
|
|
|
|
this.printpath(currentPath, route.children);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-22 12:56:18 +02:00
|
|
|
ngOnInit(): void {
|
2021-11-08 10:26:16 +01:00
|
|
|
this.languageService.getPrimeNgStrings().subscribe((resp) => {
|
|
|
|
this.config.setTranslation(resp);
|
2022-02-14 10:37:38 +01:00
|
|
|
this.pollService.updateTitle();
|
2021-11-08 10:26:16 +01:00
|
|
|
});
|
|
|
|
|
2021-06-10 10:52:32 +02:00
|
|
|
this.printpath('', this.router.config);
|
2021-04-25 11:58:58 +02:00
|
|
|
this.router.events.subscribe((evt) => {
|
|
|
|
if (!(evt instanceof NavigationEnd)) {
|
|
|
|
return;
|
|
|
|
}
|
2021-11-18 14:57:07 +01:00
|
|
|
|
|
|
|
this.onHomePage = evt.url === '/';
|
2022-02-14 10:37:38 +01:00
|
|
|
this.pollService.updateTitle();
|
2021-12-21 16:45:19 +01:00
|
|
|
setTimeout(() => {
|
|
|
|
window.scrollTo(0, 0);
|
|
|
|
}, 10);
|
2021-04-25 11:58:58 +02:00
|
|
|
});
|
|
|
|
|
2020-04-22 12:56:18 +02:00
|
|
|
if (!environment.production) {
|
2020-05-01 19:10:17 +02:00
|
|
|
this.appTitle += ' [DEV]';
|
2020-04-22 12:56:18 +02:00
|
|
|
}
|
2021-09-09 09:59:02 +02:00
|
|
|
|
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;
|
2020-06-25 22:42:26 +02:00
|
|
|
case Theme.CONTRAST:
|
2020-04-22 12:56:18 +02:00
|
|
|
this.themeClass = 'theme-hot-covid';
|
|
|
|
break;
|
2020-09-14 16:07:09 +02:00
|
|
|
case Theme.RED:
|
|
|
|
this.themeClass = 'theme-hot-covid';
|
|
|
|
break;
|
2020-04-22 12:56:18 +02:00
|
|
|
default:
|
|
|
|
this.themeClass = 'theme-light-watermelon';
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2021-11-07 15:21:27 +01:00
|
|
|
|
2021-05-18 15:19:11 +02:00
|
|
|
ngAfterViewInit(): void {
|
2022-02-14 10:37:38 +01:00
|
|
|
this.setupShortcuts();
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy(): void {
|
|
|
|
if (this.themeSubscription) {
|
|
|
|
this.themeSubscription.unsubscribe();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
prepareRoute(outlet: any) {
|
|
|
|
return outlet && outlet.activatedRouteData && outlet.activatedRouteData.animation;
|
|
|
|
}
|
|
|
|
|
|
|
|
private setupShortcuts() {
|
2021-05-18 15:19:11 +02:00
|
|
|
this.shortcuts.push(
|
|
|
|
{
|
|
|
|
key: '?',
|
|
|
|
label: 'Help',
|
|
|
|
description: 'Question mark',
|
|
|
|
command: (e) => console.log('question mark clicked', { e }),
|
|
|
|
preventDefault: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: ['up up down down left right left right b a enter'],
|
|
|
|
label: 'Sequences',
|
|
|
|
description: 'Konami code!',
|
|
|
|
command: (output: ShortcutEventOutput) => console.log('Konami code!!!', output),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: ['cmd + b'],
|
|
|
|
label: 'Help',
|
|
|
|
description: 'Cmd + b',
|
|
|
|
command: (e) => console.log(e),
|
|
|
|
preventDefault: true,
|
|
|
|
}
|
|
|
|
);
|
2021-05-18 13:34:28 +02:00
|
|
|
}
|
2019-08-09 13:38:51 +02:00
|
|
|
}
|