2020-04-14 11:28:33 +02:00
|
|
|
import { Component, Inject } from '@angular/core';
|
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
|
|
|
import { NavigationStart, Router } from '@angular/router';
|
|
|
|
import { DOCUMENT } from '@angular/common';
|
|
|
|
import { filter } from 'rxjs/operators';
|
|
|
|
import { ConfigService } from './services/config.service';
|
|
|
|
import { environment } from '../environments/environment';
|
2019-08-09 13:38:51 +02:00
|
|
|
|
|
|
|
@Component({
|
2019-09-27 16:10:03 +02:00
|
|
|
selector: 'app-root',
|
|
|
|
templateUrl: './app.component.html',
|
2020-04-14 11:28:33 +02:00
|
|
|
styleUrls: ['./app.component.scss'],
|
2019-08-09 13:38:51 +02:00
|
|
|
})
|
|
|
|
export class AppComponent {
|
2020-01-21 12:04:14 +01:00
|
|
|
step: string;
|
2020-04-14 11:28:33 +02:00
|
|
|
isDevelopmentEnv = false;
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
private translate: TranslateService,
|
|
|
|
public config: ConfigService,
|
|
|
|
@Inject(DOCUMENT) private document,
|
|
|
|
private route: Router
|
|
|
|
) {
|
2020-01-16 11:02:57 +01:00
|
|
|
this.detectCurrentTabOnRouteChange();
|
|
|
|
|
2020-04-14 11:28:33 +02:00
|
|
|
this.isDevelopmentEnv = !environment.production;
|
2020-01-16 11:02:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
detectCurrentTabOnRouteChange() {
|
2020-04-14 11:28:33 +02:00
|
|
|
this.route.events.subscribe((event: any) => {});
|
|
|
|
this.route.events
|
|
|
|
.pipe(filter((event) => event instanceof NavigationStart))
|
|
|
|
.subscribe((event: NavigationStart) => {
|
|
|
|
this.scrollGoToTop();
|
|
|
|
this.updateCurrentTab(event);
|
|
|
|
// only if there is a poll ID
|
|
|
|
this.config.fetchPollFromRoute(event);
|
|
|
|
});
|
2019-10-01 15:43:37 +02:00
|
|
|
}
|
|
|
|
|
2020-01-20 15:15:06 +01:00
|
|
|
scrollGoToTop() {
|
|
|
|
this.document.documentElement.scrollTop = 0;
|
|
|
|
}
|
2020-01-23 14:23:07 +01:00
|
|
|
|
2020-04-02 16:36:09 +02:00
|
|
|
updateCurrentTab(event) {
|
2020-01-23 14:23:07 +01:00
|
|
|
if (event.url) {
|
|
|
|
const tab = event.url.split('/');
|
|
|
|
if (tab && tab[2]) {
|
|
|
|
this.step = tab[2];
|
|
|
|
} else {
|
|
|
|
this.step = 'home';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-08-09 13:38:51 +02:00
|
|
|
}
|