88 lines
2.4 KiB
TypeScript
88 lines
2.4 KiB
TypeScript
|
import {Component, OnInit, ViewChild} 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';
|
||
|
import {ScoreboardComponent} from '../scoreboard/scoreboard.component';
|
||
|
|
||
|
|
||
|
@Component({
|
||
|
selector: 'war-detail',
|
||
|
templateUrl: './war-header.component.html',
|
||
|
styleUrls: ['./war-header.component.css', '../../../style/list-entry.css', '../../../style/hide-scrollbar.css']
|
||
|
})
|
||
|
export class WarHeaderComponent implements OnInit {
|
||
|
|
||
|
readonly fraction = Fraction;
|
||
|
|
||
|
war: War;
|
||
|
|
||
|
@ViewChild('scoreboard') scoreBoardComponent: ScoreboardComponent;
|
||
|
|
||
|
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;
|
||
|
}
|
||
|
}
|