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

179 lines
4.9 KiB
TypeScript

import {Component, ElementRef, ViewChild} from "@angular/core";
import {ActivatedRoute, Router} from "@angular/router";
import {WarService} from "../../services/logs/war.service";
import {War} from "../../models/model-interfaces";
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 {
war: War = {players: []};
fractionRadioSelect: string;
playerChart: any[] = [];
@ViewChild('overview') private overviewContainer: ElementRef;
cellHeight = 40;
rows = [];
reorderable: boolean = false;
customClasses = {
sortAscending: 'glyphicon glyphicon-triangle-top',
sortDescending: 'glyphicon glyphicon-triangle-bottom',
};
pointData: any[] = [];
budgetData: any[] = [];
colorScheme = {
domain: ['#0000FF', '#B22222']
};
yAxisLabelPoints = 'Punkte';
yAxisLabelBudget = 'Budget';
gradient = false;
yAxis = true;
xAxis = true;
legend = false;
legendTitle = false;
showXAxisLabel = false;
showYAxisLabel = true;
autoscale = true;
timeline = false;
roundDomains = true;
fractionInitialized: boolean = false;
constructor(private route: ActivatedRoute,
private router: Router,
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.rows = war.players;
this.playerChart = [
{
"name": "CSAT",
"value": war.playersOpfor
},
{
"name": "NATO",
"value": war.playersBlufor
}
];
Object.assign(this, [this.playerChart, this.pointData, this.budgetData]);
this.scrollOverviewTop();
});
}
filterPlayersByFraction(fraction?: string) {
if (fraction) {
this.rows = this.war.players.filter((player) => {
return player.fraction === fraction;
})
} else {
this.rows = this.war.players;
}
}
selectPlayerDetail(player) {
if (player && player.selected && player.selected.length > 0) {
this.router.navigate(['../../campaign-player/' + this.war.campaign + '/' + player.selected[0].name],
{relativeTo: this.route});
}
}
scrollOverviewTop() {
try {
this.overviewContainer.nativeElement.scrollTop = 0;
} catch (err) {
}
}
loadFractionData() {
if (!this.fractionInitialized) {
const tmpPointData = [
{
"name": "NATO",
"series": []
},
{
"name": "CSAT",
"series": []
}
];
const tmpBudgetData = JSON.parse(JSON.stringify(tmpPointData));
const tmpKillData = JSON.parse(JSON.stringify(tmpPointData));
const tmpFrienlyFireData = JSON.parse(JSON.stringify(tmpPointData));
const tmpTransportData = JSON.parse(JSON.stringify(tmpPointData));
const tmpReviveData = JSON.parse(JSON.stringify(tmpPointData));
const tmpStabilizeData = JSON.parse(JSON.stringify(tmpPointData));
const tmpFlagCaptureData = JSON.parse(JSON.stringify(tmpPointData));
// POINTS
this.logsService.getPointsLogs(this.war._id).subscribe((data) => {
data.forEach(pointEntry => {
const dateObj = new Date(this.war.date);
const time = pointEntry.time.split(':');
dateObj.setHours(time[0]);
dateObj.setMinutes(time[1]);
tmpPointData[0].series.push({
"name": dateObj,
"value": pointEntry.ptBlufor
});
tmpPointData[1].series.push({
"name": dateObj,
"value": pointEntry.ptOpfor
});
});
this.pointData = tmpPointData;
});
// BUDGET
this.logsService.getBudgetLogs(this.war._id).subscribe((data) => {
const dateObj = new Date(this.war.date);
dateObj.setHours(0);
dateObj.setMinutes(0);
tmpBudgetData[0].series.push({
"name": dateObj,
"value": this.war.budgetBlufor
});
tmpBudgetData[1].series.push({
"name": dateObj,
"value": this.war.budgetOpfor
});
data.forEach(budgetEntry => {
const time = budgetEntry.time.split(':');
const dateObj = new Date(this.war.date);
dateObj.setHours(time[0]);
dateObj.setMinutes(time[1]);
tmpBudgetData[budgetEntry.fraction === 'BLUFOR' ? 0 : 1].series.push({
"name": dateObj,
"value": budgetEntry.newBudget
});
});
this.budgetData = tmpBudgetData;
});
this.fractionInitialized = true;
}
}
}