62 lines
1.5 KiB
TypeScript
62 lines
1.5 KiB
TypeScript
import {Component, ElementRef, EventEmitter, SimpleChanges} from "@angular/core";
|
|
import {War} from "../../../models/model-interfaces";
|
|
import {Fraction} from "../../../utils/fraction.enum";
|
|
|
|
@Component({
|
|
selector: 'scoreboard',
|
|
templateUrl: './scoreboard.component.html',
|
|
inputs: ['war', 'fractionFilterSelected'],
|
|
outputs: ['playerTabSwitch'],
|
|
styleUrls: ['./scoreboard.component.css', '../../../style/list-entry.css', '../../../style/hide-scrollbar.css']
|
|
})
|
|
export class ScoreboardComponent {
|
|
|
|
readonly fraction = Fraction;
|
|
|
|
playerTabSwitch = new EventEmitter();
|
|
|
|
war: War;
|
|
|
|
fractionFilterSelected: string;
|
|
|
|
cellHeight = 40;
|
|
|
|
rows = [];
|
|
|
|
reorderable: boolean = false;
|
|
|
|
customClasses = {
|
|
sortAscending: 'glyphicon glyphicon-triangle-top',
|
|
sortDescending: 'glyphicon glyphicon-triangle-bottom',
|
|
};
|
|
|
|
constructor(private elRef: ElementRef) {
|
|
}
|
|
|
|
selectPlayerDetail(view: number, playerName: string) {
|
|
this.playerTabSwitch.emit({view: view, player: playerName})
|
|
}
|
|
|
|
ngOnChanges(changes: SimpleChanges) {
|
|
this.elRef.nativeElement.querySelector('.datatable-body').scrollTo(0, 0);
|
|
|
|
if (changes.war) {
|
|
this.rows = changes.war.currentValue.players;
|
|
}
|
|
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;
|
|
}
|
|
}
|
|
|
|
}
|