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

62 lines
1.5 KiB
TypeScript
Raw Normal View History

2017-07-08 21:56:11 +02:00
import {Component} from "@angular/core";
import {Player, War} from "../models/model-interfaces";
import {WarService} from "../services/war-service/war.service";
2017-07-14 23:50:58 +02:00
import {ActivatedRoute, Router} from "@angular/router";
import {LoginService} from "../services/login-service/login-service";
2017-07-08 21:56:11 +02:00
@Component({
selector: 'war-detail',
templateUrl: './war-detail.component.html',
styleUrls: ['./war-detail.component.css']
})
export class WarDetailComponent {
war: War = {players: []};
players: Player[] = [];
fractionRadioSelect: string;
2017-07-09 17:08:32 +02:00
sortBy = "kill";
sortOrder = "desc";
2017-07-14 23:50:58 +02:00
constructor(private router: Router,
private route: ActivatedRoute,
private warService: WarService,
private loginService: LoginService) {
2017-07-08 21:56:11 +02:00
}
ngOnInit() {
this.route.params
.map(params => params['id'])
.filter(id => id != undefined)
.flatMap(id => this.warService.getWar(id))
.subscribe(war => {
this.war = war;
this.players = war.players;
});
}
filterPlayersByFraction(fraction: string) {
if (fraction) {
this.players = this.war.players.filter((player) => {
return player.fraction === fraction;
})
} else {
this.players = this.war.players;
}
}
2017-07-14 23:50:58 +02:00
delete() {
if (confirm('Soll die Schlacht "' + this.war.title + '" wirklich gelöscht werden?')) {
this.warService.deleteWar(this.war._id)
.subscribe((res) => {
this.router.navigate(['../..'], {relativeTo: this.route});
})
}
}
2017-07-08 21:56:11 +02:00
}