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

72 lines
1.8 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;
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.tab = 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;
});
}
}
filterPlayersByFraction(fraction?: string) {
this.fractionFilterSelected = fraction;
}
}