2019-02-25 14:32:29 +01:00
|
|
|
import {Component, Inject, OnInit} from '@angular/core';
|
2017-09-09 06:00:25 +02:00
|
|
|
import {NavigationEnd, NavigationStart, Router} from '@angular/router';
|
2018-03-29 17:14:45 +02:00
|
|
|
import {DOCUMENT} from '@angular/common';
|
2018-07-06 23:45:03 +02:00
|
|
|
import {DomSanitizer} from '@angular/platform-browser';
|
2018-10-18 20:07:50 +02:00
|
|
|
import {MatIconRegistry} from '@angular/material';
|
2018-07-17 10:07:12 +02:00
|
|
|
import {SpinnerService} from './services/user-interface/spinner/spinner.service';
|
2019-02-10 08:53:39 +01:00
|
|
|
import {SnackBarService} from './services/user-interface/snack-bar/snack-bar.service';
|
2019-02-25 14:32:29 +01:00
|
|
|
import {Observable} from 'rxjs';
|
|
|
|
import {LoginService} from './services/app-user-service/login-service';
|
|
|
|
import {RouteConfig} from './app.config';
|
2017-05-10 11:04:06 +02:00
|
|
|
|
2017-10-14 18:43:00 +02:00
|
|
|
|
2017-05-10 11:04:06 +02:00
|
|
|
@Component({
|
|
|
|
selector: 'app-root',
|
|
|
|
templateUrl: 'app.component.html',
|
2019-02-17 19:46:24 +01:00
|
|
|
styleUrls: ['app.component.scss']
|
2017-05-10 11:04:06 +02:00
|
|
|
})
|
2018-03-08 09:44:35 +01:00
|
|
|
export class AppComponent implements OnInit {
|
2017-05-10 11:04:06 +02:00
|
|
|
|
2018-03-08 09:44:35 +01:00
|
|
|
loading = false;
|
2017-09-09 06:00:25 +02:00
|
|
|
|
2018-03-29 17:01:24 +02:00
|
|
|
scrollTopVisible = false;
|
|
|
|
|
|
|
|
scrollBtnVisibleVal = 100;
|
|
|
|
|
2019-02-25 14:32:29 +01:00
|
|
|
currentUrl = '';
|
|
|
|
|
2018-07-17 11:34:32 +02:00
|
|
|
// a map of svgIcon names and associated svg file names
|
|
|
|
// to load from assets/icon folder
|
2018-07-17 08:32:01 +02:00
|
|
|
svgIcons = {
|
2019-02-04 13:48:34 +01:00
|
|
|
'opt-logo': 'general/opt-logo',
|
2019-02-17 19:46:24 +01:00
|
|
|
'opt-logo-core': 'general/opt-logo-core',
|
2019-02-25 14:32:29 +01:00
|
|
|
'menu': 'baseline-menu-24px',
|
2018-07-17 08:32:01 +02:00
|
|
|
'add': 'outline-add_box-24px',
|
|
|
|
'add-user': 'twotone-person_add-24px',
|
2018-08-21 09:11:02 +02:00
|
|
|
'award': 'award',
|
2018-08-19 22:35:40 +02:00
|
|
|
'arrow-up': 'baseline-arrow_upward-24px',
|
2018-07-17 08:32:01 +02:00
|
|
|
'chevron-left': 'baseline-chevron_left-24px',
|
2018-07-20 22:18:50 +02:00
|
|
|
'chevron-right': 'baseline-chevron_right-24px',
|
2018-08-19 22:35:40 +02:00
|
|
|
'delete': 'baseline-delete-24px',
|
|
|
|
'edit': 'baseline-edit-24px',
|
2018-08-06 20:50:04 +02:00
|
|
|
'more-vert': 'baseline-more_vert-24px',
|
2018-07-29 20:59:09 +02:00
|
|
|
// --------STATISTICS---------
|
|
|
|
'battle': 'stats/battle',
|
|
|
|
'highscore': 'stats/highscore',
|
2019-02-04 12:41:59 +01:00
|
|
|
'stats-chart': 'stats/stats-chart',
|
2019-02-04 12:36:18 +01:00
|
|
|
'stats-fraction': 'stats/fraction-btn',
|
|
|
|
'stats-player': 'stats/player-stats-btn',
|
|
|
|
'stats-scoreboard': 'stats/scoreboard-btn',
|
2019-02-07 21:05:58 +01:00
|
|
|
'stats-performance': 'stats/performance-stats-btn',
|
2018-08-19 22:35:40 +02:00
|
|
|
// --SCOREBOARD--
|
|
|
|
'death': 'stats/scoreboard/death',
|
2019-02-04 12:41:59 +01:00
|
|
|
'flagTouch': 'stats/scoreboard/flag-touch',
|
|
|
|
'friendlyFire': 'stats/scoreboard/friendly-fire',
|
2018-08-19 22:35:40 +02:00
|
|
|
'kill': 'stats/scoreboard/kill',
|
|
|
|
'respawn': 'stats/scoreboard/respawn',
|
|
|
|
'revive': 'stats/scoreboard/revive',
|
|
|
|
'stats-detail': 'stats/scoreboard/round-assessment-24px',
|
2019-02-04 12:41:59 +01:00
|
|
|
'vehicleAir': 'stats/scoreboard/vehicle-air',
|
|
|
|
'vehicleHeavy': 'stats/scoreboard/vehicle-heavy',
|
|
|
|
'vehicleLight': 'stats/scoreboard/vehicle-light',
|
2019-02-10 18:22:47 +01:00
|
|
|
'travelDistance': 'stats/scoreboard/travel-distance',
|
|
|
|
'driverDistance': 'stats/scoreboard/driver-distance',
|
2019-02-11 22:57:31 +01:00
|
|
|
'warCount': 'stats/scoreboard/war-count',
|
2018-10-05 13:01:51 +02:00
|
|
|
// --------LOCALE---------
|
|
|
|
'flag-de': 'locale/de',
|
2018-10-20 16:16:11 +02:00
|
|
|
'flag-en': 'locale/en',
|
2018-07-17 08:32:01 +02:00
|
|
|
};
|
|
|
|
|
2019-02-25 14:32:29 +01:00
|
|
|
constructor(private router: Router,
|
|
|
|
private loginService: LoginService,
|
2018-07-06 17:01:59 +02:00
|
|
|
private iconRegistry: MatIconRegistry,
|
|
|
|
private sanitizer: DomSanitizer,
|
2018-07-17 10:07:12 +02:00
|
|
|
private spinnerService: SpinnerService,
|
2019-02-10 08:53:39 +01:00
|
|
|
private snackBarService: SnackBarService,
|
2018-03-29 17:01:24 +02:00
|
|
|
@Inject(DOCUMENT) private document) {
|
2018-07-17 08:32:01 +02:00
|
|
|
this.initMaterialSvgIcons();
|
2018-07-06 17:01:59 +02:00
|
|
|
|
2018-07-17 10:07:12 +02:00
|
|
|
this.spinnerService.spinnerActive.subscribe(active => this.toggleSpinner(active));
|
|
|
|
|
2017-09-09 06:00:25 +02:00
|
|
|
router.events.subscribe(event => {
|
|
|
|
if (event instanceof NavigationStart) {
|
2018-07-17 10:07:12 +02:00
|
|
|
this.spinnerService.activate();
|
2019-02-10 08:53:39 +01:00
|
|
|
this.snackBarService.dismiss();
|
2017-09-09 06:00:25 +02:00
|
|
|
}
|
|
|
|
if (event instanceof NavigationEnd) {
|
2018-07-17 11:34:32 +02:00
|
|
|
this.spinnerService.deactivate();
|
2019-02-25 14:32:29 +01:00
|
|
|
this.currentUrl = this.router.url;
|
2018-07-17 09:09:56 +02:00
|
|
|
|
2018-03-29 17:01:24 +02:00
|
|
|
// scroll to top on route from army overview to user detail and back
|
2019-02-25 14:32:29 +01:00
|
|
|
if (this.currentUrl.includes('/overview') || this.currentUrl.includes('/public')) {
|
2018-03-29 17:14:45 +02:00
|
|
|
this.scrollToTop();
|
2018-03-29 17:01:24 +02:00
|
|
|
}
|
2017-09-09 06:00:25 +02:00
|
|
|
}
|
|
|
|
});
|
2017-05-10 11:04:06 +02:00
|
|
|
}
|
|
|
|
|
2018-10-02 10:57:45 +02:00
|
|
|
ngOnInit() {
|
2019-02-25 14:32:29 +01:00
|
|
|
Observable.fromEvent(this.document, 'scroll').subscribe(e => {
|
|
|
|
this.scrollTopVisible = document.body.scrollTop > this.scrollBtnVisibleVal
|
|
|
|
|| document.documentElement.scrollTop > this.scrollBtnVisibleVal;
|
2018-10-05 13:01:51 +02:00
|
|
|
});
|
2018-10-02 10:57:45 +02:00
|
|
|
}
|
|
|
|
|
2018-07-17 11:34:32 +02:00
|
|
|
toggleSpinner(active) {
|
2018-07-17 10:07:12 +02:00
|
|
|
this.loading = active;
|
|
|
|
}
|
|
|
|
|
2018-07-17 08:32:01 +02:00
|
|
|
initMaterialSvgIcons() {
|
|
|
|
Object.keys(this.svgIcons).forEach(key => {
|
2018-10-05 13:01:51 +02:00
|
|
|
const fileUri = '../assets/icon/'.concat(this.svgIcons[key]).concat('.svg');
|
2018-07-17 08:32:01 +02:00
|
|
|
this.iconRegistry.addSvgIcon(key, this.sanitizer.bypassSecurityTrustResourceUrl(fileUri));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-05-10 11:04:06 +02:00
|
|
|
logout() {
|
|
|
|
this.loginService.logout();
|
2018-07-17 10:07:12 +02:00
|
|
|
setTimeout(() => {
|
|
|
|
this.router.navigate([RouteConfig.overviewPath]);
|
|
|
|
}, 500);
|
2017-05-10 11:04:06 +02:00
|
|
|
}
|
|
|
|
|
2019-02-25 14:32:29 +01:00
|
|
|
|
2018-03-29 17:01:24 +02:00
|
|
|
scrollToTop() {
|
|
|
|
this.document.body.scrollTop = 0; // For Safari
|
|
|
|
this.document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera
|
|
|
|
}
|
2017-05-10 11:04:06 +02:00
|
|
|
}
|
|
|
|
|