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

73 lines
1.8 KiB
TypeScript

import {Component, ElementRef, SimpleChanges, ViewChild} from "@angular/core";
import {ActivatedRoute, Router} from "@angular/router";
import {War} from "../../../models/model-interfaces";
import {Fraction} from "../../../utils/fraction.enum";
@Component({
selector: 'scoreboard',
templateUrl: './scoreboard.component.html',
inputs: ['war', 'fractionFilterSelected'],
styleUrls: ['./scoreboard.component.css', '../../../style/list-entry.css', '../../../style/hide-scrollbar.css']
})
export class ScoreboardComponent {
readonly fraction = Fraction;
@ViewChild('overview') private overviewContainer: ElementRef;
war: War;
fractionFilterSelected: string;
cellHeight = 40;
rows = [];
reorderable: boolean = false;
customClasses = {
sortAscending: 'glyphicon glyphicon-triangle-top',
sortDescending: 'glyphicon glyphicon-triangle-bottom',
};
constructor(private route: ActivatedRoute,
private router: Router) {
}
ngOnInit() {
}
selectPlayerDetail(playerName: string) {
this.router.navigate(['../../campaign-player/' + this.war.campaign + '/' + playerName],
{relativeTo: this.route});
}
ngOnChanges(changes: SimpleChanges) {
if (changes.war) {
this.rows = changes.war.currentValue.players;
}
if (changes.fractionFilterSelected) {
this.filterPlayersByFraction(this.fractionFilterSelected)
}
this.scrollOverviewTop();
}
scrollOverviewTop() {
try {
this.overviewContainer.nativeElement.scrollTop = 0;
} catch (err) {
}
}
filterPlayersByFraction(fraction?: string) {
if (fraction) {
this.rows = this.war.players.filter((player) => {
return player.fraction === fraction;
})
} else {
this.rows = this.war.players;
}
}
}