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

86 lines
2.2 KiB
TypeScript

import {Component} from '@angular/core';
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';
@Component({
selector: 'war-detail',
templateUrl: './war-detail.component.html',
styleUrls: ['./war-detail.component.css', '../../style/list-entry.css', '../../style/hide-scrollbar.css']
})
export class WarDetailComponent {
readonly fraction = Fraction;
war: War;
logData;
singlePlayerView: number;
playerDetailName: string;
tab: number;
fractionStatsInitialized: boolean;
fractionFilterSelected: string;
playerChart: any[] = [];
colorScheme = {
domain: [Fraction.COLOR_OPFOR, Fraction.COLOR_BLUFOR]
};
constructor(private route: ActivatedRoute,
private warService: WarService,
private logsService: LogsService) {
}
ngOnInit() {
this.route.params
.map(params => params['id'])
.filter(id => id !== undefined)
.flatMap(id => this.warService.getWar(id))
.subscribe(war => {
this.war = war;
this.switchTab(0);
this.fractionStatsInitialized = false;
this.fractionFilterSelected = undefined;
this.playerChart = ChartUtils.getSingleDataArray(Fraction.OPFOR, war.playersOpfor, Fraction.BLUFOR, war.playersBlufor);
Object.assign(this, [this.playerChart]);
});
}
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;
});
}
}
/**
* 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);
}
filterPlayersByFraction(fraction?: string) {
this.fractionFilterSelected = fraction;
}
}