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

87 lines
2.2 KiB
TypeScript
Raw Normal View History

import {Component} from "@angular/core";
import {ActivatedRoute} from "@angular/router";
import {WarService} from "../../services/logs/war.service";
2017-09-13 11:49:34 +02:00
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";
2017-07-08 21:56:11 +02:00
@Component({
selector: 'war-detail',
templateUrl: './war-detail.component.html',
2017-10-07 09:38:02 +02:00
styleUrls: ['./war-detail.component.css', '../../style/list-entry.css', '../../style/hide-scrollbar.css']
2017-07-08 21:56:11 +02:00
})
export class WarDetailComponent {
2017-11-08 14:37:13 +01:00
readonly fraction = Fraction;
2017-11-12 19:27:26 +01:00
war: War;
2017-10-29 17:36:55 +01:00
logData;
2017-07-09 17:08:32 +02:00
2017-11-13 15:45:12 +01:00
singlePlayerView: number;
playerDetailName: string;
tab: number;
2017-09-13 11:49:34 +02:00
fractionStatsInitialized: boolean;
fractionFilterSelected: string;
2017-07-09 17:08:32 +02:00
playerChart: any[] = [];
2017-09-13 11:49:34 +02:00
colorScheme = {
domain: [Fraction.COLOR_OPFOR, Fraction.COLOR_BLUFOR]
2017-09-13 11:49:34 +02:00
};
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
.map(params => params['id'])
.filter(id => id != undefined)
.flatMap(id => this.warService.getWar(id))
.subscribe(war => {
this.war = war;
2017-11-13 15:45:12 +01:00
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]);
})
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;
});
}
window.scrollTo({left: 0, top: 0, behavior: 'smooth'});
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
}