107 lines
3.1 KiB
TypeScript
107 lines
3.1 KiB
TypeScript
|
import {Component, ElementRef, EventEmitter, Input, OnChanges, Output, SimpleChanges} from '@angular/core';
|
||
|
import {War} from '../../../models/model-interfaces';
|
||
|
import {Fraction} from '../../../utils/fraction.enum';
|
||
|
import {PlayerUtils} from '../../../utils/player-utils';
|
||
|
import {saveAs} from 'file-saver/FileSaver';
|
||
|
|
||
|
@Component({
|
||
|
selector: 'cc-scoreboard',
|
||
|
templateUrl: './scoreboard.component.html',
|
||
|
styleUrls: ['./scoreboard.component.css', '../../../style/list-entry.css', '../../../style/hide-scrollbar.css']
|
||
|
})
|
||
|
export class ScoreboardComponent implements OnChanges {
|
||
|
|
||
|
readonly fraction = Fraction;
|
||
|
|
||
|
@Input() war: War;
|
||
|
|
||
|
@Input() fractionFilterSelected: string;
|
||
|
|
||
|
@Output() playerTabSwitch = new EventEmitter();
|
||
|
|
||
|
tableHead = [
|
||
|
{prop: 'name', head: 'Spieler'}, {prop: 'fraction', head: 'Fraktion'}, {prop: 'kill', head: 'Kills'},
|
||
|
{prop: 'friendlyFire', head: 'FriendlyFire'}, {prop: 'vehicleLight', head: 'Fahrzeug (leicht)'},
|
||
|
{prop: 'vehicleHeavy', head: 'Fahrzeug (schwer)'}, {prop: 'vehicleAir', head: 'Fahrzeug (Luft)'},
|
||
|
{prop: 'revive', head: 'Revive'}, {prop: 'flagTouch', head: 'Flagge'}, {prop: 'death', head: 'Tod'},
|
||
|
{prop: 'respawn', head: 'Respawn'}
|
||
|
];
|
||
|
|
||
|
isSteamUUID = PlayerUtils.isSteamUUID;
|
||
|
|
||
|
cellHeight = 40;
|
||
|
|
||
|
columnWidth = 65;
|
||
|
|
||
|
rows = [];
|
||
|
|
||
|
reorderable = false;
|
||
|
|
||
|
customClasses = {
|
||
|
sortAscending: 'glyphicon glyphicon-triangle-top',
|
||
|
sortDescending: 'glyphicon glyphicon-triangle-bottom',
|
||
|
};
|
||
|
|
||
|
constructor(private elRef: ElementRef) {
|
||
|
}
|
||
|
|
||
|
selectPlayerDetail(view: number, player) {
|
||
|
this.playerTabSwitch.emit({
|
||
|
view: view,
|
||
|
player: player
|
||
|
});
|
||
|
}
|
||
|
|
||
|
ngOnChanges(changes: SimpleChanges) {
|
||
|
if (changes.war) {
|
||
|
this.rows = changes.war.currentValue.players;
|
||
|
this.elRef.nativeElement
|
||
|
.querySelector('.datatable-body')
|
||
|
.scrollTo(0, 0);
|
||
|
}
|
||
|
if (changes.fractionFilterSelected) {
|
||
|
this.filterPlayersByFraction(this.fractionFilterSelected);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
filterPlayersByFraction(fraction?: string) {
|
||
|
if (fraction) {
|
||
|
this.rows = this.war.players.filter((player) => {
|
||
|
return player.fraction === fraction;
|
||
|
});
|
||
|
} else {
|
||
|
this.rows = this.war.players;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
exportCSV() {
|
||
|
let csvOut = '';
|
||
|
for (let i = 0; i < this.tableHead.length; i++) {
|
||
|
csvOut += this.tableHead[i];
|
||
|
if (i !== this.tableHead.length - 1) {
|
||
|
csvOut += ',';
|
||
|
}
|
||
|
}
|
||
|
|
||
|
for (let j = 0; j < this.war.players.length; j++) {
|
||
|
const player = this.war.players[j];
|
||
|
csvOut += '\r\n';
|
||
|
csvOut += '"' + player.name + '",';
|
||
|
csvOut += player.fraction + ',';
|
||
|
csvOut += player.kill + ',';
|
||
|
csvOut += player.friendlyFire + ',';
|
||
|
csvOut += player.vehicleLight + ',';
|
||
|
csvOut += player.vehicleHeavy + ',';
|
||
|
csvOut += player.vehicleAir + ',';
|
||
|
csvOut += player.revive + ',';
|
||
|
csvOut += player.flagTouch + ',';
|
||
|
csvOut += player.death + ',';
|
||
|
csvOut += player.respawn;
|
||
|
}
|
||
|
|
||
|
const blob = new Blob([csvOut], {type: 'text/plain'});
|
||
|
saveAs(blob, this.war.title.toLowerCase().replace(' ', '_').concat('.csv'));
|
||
|
}
|
||
|
|
||
|
}
|