opt-cc/static/src/app/statistic/war/war-header/war-header.component.ts

119 lines
3.3 KiB
TypeScript
Raw Normal View History

2018-04-02 13:22:04 +02:00
import {Component, OnInit, ViewChild} from '@angular/core';
2018-03-07 11:56:50 +01:00
import {ActivatedRoute} from '@angular/router';
import {WarService} from '../../../services/logs/war.service';
import {War} from '../../../models/model-interfaces';
import {ChartUtils} from '../../../utils/chart-utils';
import {Fraction} from '../../../utils/fraction.enum';
import {LogsService} from '../../../services/logs/logs.service';
import {ScoreboardComponent} from '../scoreboard/scoreboard.component';
2019-02-27 23:13:23 +01:00
import {BaseConfig} from '../../../app.config';
import {Observable} from 'rxjs';
2019-10-11 20:25:07 +02:00
import {FractionHelpers} from '../../../utils/global.helpers';
2017-07-08 21:56:11 +02:00
@Component({
selector: 'war-detail',
templateUrl: './war-header.component.html',
styleUrls: ['./war-header.component.scss']
2017-07-08 21:56:11 +02:00
})
export class WarHeaderComponent implements OnInit {
2017-07-08 21:56:11 +02:00
2017-11-08 14:37:13 +01:00
readonly fraction = Fraction;
2019-10-11 20:25:07 +02:00
readonly fractionHelpers = FractionHelpers;
2017-11-12 19:27:26 +01:00
war: War;
2017-10-29 17:36:55 +01:00
2018-04-02 13:20:44 +02:00
@ViewChild('scoreboard') scoreBoardComponent: ScoreboardComponent;
logData;
2017-07-09 17:08:32 +02:00
fractionStatsInitialized: boolean;
performanceData;
performanceStatsInitialized: boolean;
2017-11-13 15:45:12 +01:00
singlePlayerView: number;
playerDetailName: string;
tab: number;
2017-09-13 11:49:34 +02:00
fractionFilterSelected: string;
2017-07-09 17:08:32 +02:00
2019-02-27 23:13:23 +01:00
isSmallLayout = false;
playerChart: any[] = [];
2017-09-13 11:49:34 +02:00
2019-10-11 20:25:07 +02:00
colorScheme;
2017-07-30 16:25:11 +02:00
constructor(private route: ActivatedRoute,
private warService: WarService,
private logsService: LogsService) {
2017-07-08 21:56:11 +02:00
}
ngOnInit() {
this.route.params
2018-02-26 09:04:27 +01:00
.map(params => params['id'])
2018-03-07 11:56:50 +01:00
.filter(id => id !== undefined)
2018-02-26 09:04:27 +01:00
.flatMap(id => this.warService.getWar(id))
.subscribe(war => {
this.war = war;
this.switchTab(0);
this.fractionStatsInitialized = false;
this.fractionFilterSelected = undefined;
2019-10-11 20:25:07 +02:00
this.colorScheme = {
domain: [
FractionHelpers.getFractionColor('OPFOR', war),
FractionHelpers.getFractionColor('BLUFOR', war)
]
};
this.playerChart =
2019-10-11 20:25:07 +02:00
ChartUtils.getSingleDataArray(
FractionHelpers.getFractionName(war, 'OPFOR'), war.playersOpfor,
FractionHelpers.getFractionName(war, 'BLUFOR'), war.playersBlufor
);
2018-02-26 09:04:27 +01:00
Object.assign(this, [this.playerChart]);
2018-03-07 11:56:50 +01:00
});
2019-02-27 23:13:23 +01:00
this.isSmallLayout = window.innerWidth <= BaseConfig.responsive.breakpointPx;
Observable.fromEvent(window, 'resize').subscribe(event => {
this.isSmallLayout = event.target['innerWidth'] <= BaseConfig.responsive.breakpointPx;
});
2017-11-03 12:51:58 +01:00
}
switchTab(index: number) {
this.tab = index;
if (index === 1 && !this.fractionStatsInitialized) {
this.logsService.getFullLog(this.war._id).subscribe(log => {
this.logData = log;
this.fractionStatsInitialized = true;
});
}
if (index === 3 && !this.performanceStatsInitialized) {
this.logsService.getPerformanceLogs(this.war._id).subscribe(log => {
this.performanceData = log;
this.performanceStatsInitialized = true;
});
}
2017-11-13 15:45:12 +01:00
}
/**
* called by EventEmitter,
* @param event with fields: 'view' (0 = war-detail, 1 = campaign-detail); 'player' = player name
*/
switchToPlayerTab(event) {
this.singlePlayerView = event.view;
this.playerDetailName = event.player;
this.switchTab(2);
2017-11-04 15:58:48 +01:00
}
2017-11-12 19:27:26 +01:00
filterPlayersByFraction(fraction?: string) {
this.fractionFilterSelected = fraction;
}
2017-07-08 21:56:11 +02:00
}