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

67 lines
1.6 KiB
TypeScript

import {Component, ElementRef, EventEmitter, Input, Output, SimpleChanges} from '@angular/core';
import {War} from '../../../models/model-interfaces';
import {Fraction} from '../../../utils/fraction.enum';
import {PlayerUtils} from '../../../utils/player-utils';
@Component({
selector: 'scoreboard',
templateUrl: './scoreboard.component.html',
styleUrls: ['./scoreboard.component.css', '../../../style/list-entry.css', '../../../style/hide-scrollbar.css']
})
export class ScoreboardComponent {
readonly fraction = Fraction;
@Input() war: War;
@Input() fractionFilterSelected: string;
@Output() playerTabSwitch = new EventEmitter();
isSteamUUID = PlayerUtils.isSteamUUID;
cellHeight = 40;
rows = [];
reorderable: boolean = 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;
}
}
}