160 lines
5.4 KiB
TypeScript
160 lines
5.4 KiB
TypeScript
import {Component, HostListener, Inject, OnInit} from '@angular/core';
|
|
import {NavigationEnd, NavigationStart, Router} from '@angular/router';
|
|
import {LoginService} from './services/app-user-service/login-service';
|
|
import {PromotionService} from './services/army-management/promotion.service';
|
|
import {AwardingService} from './services/army-management/awarding.service';
|
|
import {RouteConfig} from './app.config';
|
|
import {DOCUMENT} from '@angular/common';
|
|
import {DomSanitizer} from '@angular/platform-browser';
|
|
import {MatIconRegistry} from '@angular/material';
|
|
import {SpinnerService} from './services/user-interface/spinner/spinner.service';
|
|
import {TranslateService} from '@ngx-translate/core';
|
|
import {SettingsService} from './services/settings.service';
|
|
import {environment} from '../environments/environment';
|
|
import {SnackBarService} from './services/user-interface/snack-bar/snack-bar.service';
|
|
|
|
declare function require(url: string);
|
|
|
|
@Component({
|
|
selector: 'app-root',
|
|
templateUrl: 'app.component.html',
|
|
styleUrls: ['app.component.css', 'style/load-indicator.css']
|
|
})
|
|
export class AppComponent implements OnInit {
|
|
|
|
readonly features = environment.features;
|
|
|
|
config = RouteConfig;
|
|
|
|
loading = false;
|
|
|
|
scrollTopVisible = false;
|
|
|
|
scrollBtnVisibleVal = 100;
|
|
|
|
// a map of svgIcon names and associated svg file names
|
|
// to load from assets/icon folder
|
|
svgIcons = {
|
|
'opt-logo': 'general/opt-logo',
|
|
'loading-arrows': 'general/loading-arrows',
|
|
'add': 'outline-add_box-24px',
|
|
'add-user': 'twotone-person_add-24px',
|
|
'award': 'award',
|
|
'arrow-up': 'baseline-arrow_upward-24px',
|
|
'chevron-left': 'baseline-chevron_left-24px',
|
|
'chevron-right': 'baseline-chevron_right-24px',
|
|
'delete': 'baseline-delete-24px',
|
|
'edit': 'baseline-edit-24px',
|
|
'more-vert': 'baseline-more_vert-24px',
|
|
// --------STATISTICS---------
|
|
'battle': 'stats/battle',
|
|
'highscore': 'stats/highscore',
|
|
'stats-chart': 'stats/stats-chart',
|
|
'stats-fraction': 'stats/fraction-btn',
|
|
'stats-player': 'stats/player-stats-btn',
|
|
'stats-scoreboard': 'stats/scoreboard-btn',
|
|
'stats-performance': 'stats/performance-stats-btn',
|
|
// --SCOREBOARD--
|
|
'death': 'stats/scoreboard/death',
|
|
'flagTouch': 'stats/scoreboard/flag-touch',
|
|
'friendlyFire': 'stats/scoreboard/friendly-fire',
|
|
'kill': 'stats/scoreboard/kill',
|
|
'respawn': 'stats/scoreboard/respawn',
|
|
'revive': 'stats/scoreboard/revive',
|
|
'stats-detail': 'stats/scoreboard/round-assessment-24px',
|
|
'vehicleAir': 'stats/scoreboard/vehicle-air',
|
|
'vehicleHeavy': 'stats/scoreboard/vehicle-heavy',
|
|
'vehicleLight': 'stats/scoreboard/vehicle-light',
|
|
// --------LOCALE---------
|
|
'flag-de': 'locale/de',
|
|
'flag-en': 'locale/en',
|
|
};
|
|
|
|
language;
|
|
|
|
languages = ['de', 'en'];
|
|
|
|
version = 'v'.concat(require('./../../../package.json').version);
|
|
|
|
constructor(public loginService: LoginService,
|
|
private promotionService: PromotionService,
|
|
private awardingService: AwardingService,
|
|
private router: Router,
|
|
private iconRegistry: MatIconRegistry,
|
|
private sanitizer: DomSanitizer,
|
|
private spinnerService: SpinnerService,
|
|
private translate: TranslateService,
|
|
private settingsService: SettingsService,
|
|
private snackBarService: SnackBarService,
|
|
@Inject(DOCUMENT) private document) {
|
|
this.initMaterialSvgIcons();
|
|
|
|
this.spinnerService.spinnerActive.subscribe(active => this.toggleSpinner(active));
|
|
|
|
router.events.subscribe(event => {
|
|
if (event instanceof NavigationStart) {
|
|
this.spinnerService.activate();
|
|
this.snackBarService.dismiss();
|
|
}
|
|
if (event instanceof NavigationEnd) {
|
|
this.spinnerService.deactivate();
|
|
const currentUrl = this.router.url;
|
|
|
|
// scroll to top on route from army overview to user detail and back
|
|
if (currentUrl.includes('/overview') || currentUrl.includes('/public')) {
|
|
this.scrollToTop();
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
ngOnInit() {
|
|
this.settingsService.getLanguage().subscribe((language) => {
|
|
this.language = language;
|
|
this.translate.setDefaultLang(language)
|
|
});
|
|
if (this.loginService.hasPermission(2)) {
|
|
const fraction = this.loginService.getCurrentUser().squad.fraction;
|
|
this.promotionService.checkUnconfirmedPromotions(fraction);
|
|
this.awardingService.checkUnprocessedAwards(fraction);
|
|
}
|
|
}
|
|
|
|
toggleSpinner(active) {
|
|
this.loading = active;
|
|
}
|
|
|
|
initMaterialSvgIcons() {
|
|
Object.keys(this.svgIcons).forEach(key => {
|
|
const fileUri = '../assets/icon/'.concat(this.svgIcons[key]).concat('.svg');
|
|
this.iconRegistry.addSvgIcon(key, this.sanitizer.bypassSecurityTrustResourceUrl(fileUri));
|
|
});
|
|
}
|
|
|
|
@HostListener('window:scroll', [])
|
|
onWindowScroll() {
|
|
this.scrollTopVisible = document.body.scrollTop > this.scrollBtnVisibleVal
|
|
|| document.documentElement.scrollTop > this.scrollBtnVisibleVal;
|
|
}
|
|
|
|
logout() {
|
|
this.loginService.logout();
|
|
setTimeout(() => {
|
|
this.router.navigate([RouteConfig.overviewPath]);
|
|
}, 500);
|
|
}
|
|
|
|
scrollToTop() {
|
|
this.document.body.scrollTop = 0; // For Safari
|
|
this.document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera
|
|
}
|
|
|
|
setLanguage(language: string) {
|
|
if (language) {
|
|
this.language = language;
|
|
this.settingsService.setLanguage(language);
|
|
}
|
|
}
|
|
}
|
|
|