58 lines
1.7 KiB
TypeScript
58 lines
1.7 KiB
TypeScript
|
import {Component, OnInit} from "@angular/core";
|
||
|
import {ActivatedRoute, Router} from "@angular/router";
|
||
|
import {War} from "../../models/model-interfaces";
|
||
|
import {WarService} from "../../services/war-service/war.service";
|
||
|
import {LoginService} from "../../services/login-service/login-service";
|
||
|
|
||
|
@Component({
|
||
|
selector: 'war-list',
|
||
|
templateUrl: './war-list.component.html',
|
||
|
styleUrls: ['./war-list.component.css', '../../style/list-entry.css']
|
||
|
})
|
||
|
export class WarListComponent implements OnInit {
|
||
|
|
||
|
selectedWarId: string | number = '0';
|
||
|
|
||
|
wars: War[] = [];
|
||
|
|
||
|
constructor(private warService: WarService,
|
||
|
private loginService: LoginService,
|
||
|
private router: Router,
|
||
|
private route: ActivatedRoute) {
|
||
|
}
|
||
|
|
||
|
ngOnInit() {
|
||
|
this.warService.getAllWars().subscribe((items) => {
|
||
|
this.wars = items;
|
||
|
this.router.navigate([{outlets: {'right': ['overview']}}], {relativeTo: this.route});
|
||
|
});
|
||
|
}
|
||
|
|
||
|
selectNewWar() {
|
||
|
this.selectedWarId = null;
|
||
|
this.router.navigate([{outlets: {'right': ['new']}}], {relativeTo: this.route});
|
||
|
}
|
||
|
|
||
|
selectWar(warId: string | number) {
|
||
|
this.selectedWarId = warId;
|
||
|
this.router.navigate([{outlets: {'right': ['war', warId]}}], {relativeTo: this.route});
|
||
|
}
|
||
|
|
||
|
selectOverview() {
|
||
|
this.selectedWarId = '0';
|
||
|
this.router.navigate([{outlets: {'right': ['overview']}}], {relativeTo: this.route});
|
||
|
}
|
||
|
|
||
|
deleteWar(war: War) {
|
||
|
if (confirm('Soll die Schlacht ' + war.title + ' wirklich gelöscht werden?')) {
|
||
|
this.warService.deleteWar(war._id)
|
||
|
.subscribe((res) => {
|
||
|
if (this.selectedWarId === war._id) {
|
||
|
this.selectOverview();
|
||
|
}
|
||
|
this.wars.splice(this.wars.indexOf(war), 1);
|
||
|
})
|
||
|
}
|
||
|
}
|
||
|
}
|