2018-03-29 17:01:49 +02:00
|
|
|
import {Component, HostListener, Inject, OnInit} from '@angular/core';
|
2017-09-09 06:00:25 +02:00
|
|
|
import {NavigationEnd, NavigationStart, Router} from '@angular/router';
|
2017-10-22 18:06:37 +02:00
|
|
|
import {LoginService} from './services/app-user-service/login-service';
|
2018-03-07 11:56:50 +01:00
|
|
|
import {PromotionService} from './services/army-management/promotion.service';
|
|
|
|
import {AwardingService} from './services/army-management/awarding.service';
|
|
|
|
import {RouteConfig} from './app.config';
|
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';
|
|
|
|
import {MatIconRegistry} from '@angular/material';
|
2018-07-17 10:07:12 +02:00
|
|
|
import {SpinnerService} from './services/user-interface/spinner/spinner.service';
|
2018-10-02 10:57:45 +02:00
|
|
|
import {TranslateService} from '@ngx-translate/core';
|
2018-10-05 09:55:39 +02:00
|
|
|
import {SettingsService} from './services/settings.service';
|
2017-05-10 11:04:06 +02:00
|
|
|
|
2017-10-14 18:43:00 +02:00
|
|
|
declare function require(url: string);
|
|
|
|
|
2017-05-10 11:04:06 +02:00
|
|
|
@Component({
|
|
|
|
selector: 'app-root',
|
|
|
|
templateUrl: 'app.component.html',
|
2017-09-09 06:00:25 +02:00
|
|
|
styleUrls: ['app.component.css', 'style/load-indicator.css']
|
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
|
|
|
|
2017-08-01 23:52:10 +02:00
|
|
|
config = RouteConfig;
|
|
|
|
|
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;
|
|
|
|
|
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 = {
|
|
|
|
'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',
|
|
|
|
'stats-chart': 'stats/statsChart',
|
2018-08-19 22:35:40 +02:00
|
|
|
// --SCOREBOARD--
|
|
|
|
'death': 'stats/scoreboard/death',
|
|
|
|
'flagTouch': 'stats/scoreboard/flagTouch',
|
|
|
|
'friendlyFire': 'stats/scoreboard/friendlyFire',
|
|
|
|
'kill': 'stats/scoreboard/kill',
|
|
|
|
'respawn': 'stats/scoreboard/respawn',
|
|
|
|
'revive': 'stats/scoreboard/revive',
|
|
|
|
'stats-detail': 'stats/scoreboard/round-assessment-24px',
|
|
|
|
'vehicleAir': 'stats/scoreboard/vehicleAir',
|
|
|
|
'vehicleHeavy': 'stats/scoreboard/vehicleHeavy',
|
|
|
|
'vehicleLight': 'stats/scoreboard/vehicleLight',
|
2018-07-17 08:32:01 +02:00
|
|
|
};
|
|
|
|
|
2018-03-29 17:13:55 +02:00
|
|
|
version = 'v'.concat(require('./../../../package.json').version);
|
2017-10-14 18:43:00 +02:00
|
|
|
|
2017-10-15 12:56:16 +02:00
|
|
|
constructor(public loginService: LoginService,
|
2017-07-23 10:57:46 +02:00
|
|
|
private promotionService: PromotionService,
|
|
|
|
private awardingService: AwardingService,
|
2018-03-29 17:01:24 +02:00
|
|
|
private router: Router,
|
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,
|
2018-10-02 10:57:45 +02:00
|
|
|
private translate: TranslateService,
|
2018-10-05 09:55:39 +02:00
|
|
|
private settingsService: SettingsService,
|
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();
|
2017-09-09 06:00:25 +02:00
|
|
|
}
|
|
|
|
if (event instanceof NavigationEnd) {
|
2018-07-17 11:34:32 +02:00
|
|
|
this.spinnerService.deactivate();
|
2018-07-17 09:09:56 +02:00
|
|
|
const currentUrl = this.router.url;
|
|
|
|
|
2018-03-29 17:01:24 +02:00
|
|
|
// scroll to top on route from army overview to user detail and back
|
2018-08-08 21:42:57 +02:00
|
|
|
if (currentUrl.includes('/overview') || 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() {
|
2018-10-05 09:55:39 +02:00
|
|
|
this.settingsService.getLanguage().subscribe((language) => this.translate.setDefaultLang(language));
|
2018-10-02 10:57:45 +02:00
|
|
|
if (this.loginService.hasPermission(2)) {
|
|
|
|
const fraction = this.loginService.getCurrentUser().squad.fraction;
|
|
|
|
this.promotionService.checkUnconfirmedPromotions(fraction);
|
|
|
|
this.awardingService.checkUnprocessedAwards(fraction);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-07-17 11:34:32 +02:00
|
|
|
const fileUri = '../assets/icon/'.concat(this.svgIcons[key])
|
2018-08-19 22:35:40 +02:00
|
|
|
.concat('.svg');
|
2018-07-17 08:32:01 +02:00
|
|
|
this.iconRegistry.addSvgIcon(key, this.sanitizer.bypassSecurityTrustResourceUrl(fileUri));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-03-29 17:14:45 +02:00
|
|
|
@HostListener('window:scroll', [])
|
2018-03-29 17:01:24 +02:00
|
|
|
onWindowScroll() {
|
|
|
|
this.scrollTopVisible = document.body.scrollTop > this.scrollBtnVisibleVal
|
|
|
|
|| document.documentElement.scrollTop > this.scrollBtnVisibleVal;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
2018-10-02 10:57:45 +02:00
|
|
|
|
2018-10-05 10:21:50 +02:00
|
|
|
setLanguage(language: string) {
|
2018-10-05 09:55:39 +02:00
|
|
|
if (language) {
|
|
|
|
this.settingsService.setLanguage(language);
|
|
|
|
}
|
|
|
|
}
|
2017-05-10 11:04:06 +02:00
|
|
|
}
|
|
|
|
|