2017-08-06 10:42:37 +02:00
|
|
|
import {Component, OnInit} from "@angular/core";
|
|
|
|
import {ActivatedRoute, Router} from "@angular/router";
|
2017-08-12 21:37:31 +02:00
|
|
|
import {Campaign, War} from "../../models/model-interfaces";
|
2017-10-22 18:06:37 +02:00
|
|
|
import {WarService} from "../../services/logs/war.service";
|
|
|
|
import {LoginService} from "../../services/app-user-service/login-service";
|
|
|
|
import {CampaignService} from "../../services/logs/campaign.service";
|
2017-10-06 21:41:59 +02:00
|
|
|
import {RouteConfig} from "../../app.config";
|
2017-08-06 10:42:37 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'war-list',
|
|
|
|
templateUrl: './war-list.component.html',
|
2017-10-06 20:11:18 +02:00
|
|
|
styleUrls: ['./war-list.component.css', '../../style/list-entry.css', '../../style/select-list.css']
|
2017-08-06 10:42:37 +02:00
|
|
|
})
|
|
|
|
export class WarListComponent implements OnInit {
|
|
|
|
|
2017-08-13 16:35:42 +02:00
|
|
|
selectedWarId: string | number;
|
2017-08-06 10:42:37 +02:00
|
|
|
|
2017-08-12 21:37:31 +02:00
|
|
|
campaigns: Campaign[] = [];
|
2017-08-06 10:42:37 +02:00
|
|
|
|
|
|
|
constructor(private warService: WarService,
|
2017-09-12 15:02:35 +02:00
|
|
|
private campaignService: CampaignService,
|
2017-10-08 12:17:21 +02:00
|
|
|
public loginService: LoginService,
|
2017-08-06 10:42:37 +02:00
|
|
|
private router: Router,
|
|
|
|
private route: ActivatedRoute) {
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
2017-09-12 15:02:35 +02:00
|
|
|
this.campaignService.getAllCampaigns().subscribe((items) => {
|
2017-10-06 21:41:59 +02:00
|
|
|
const subPathWar = 'war/';
|
|
|
|
const subPathOverview = 'overview/';
|
2017-09-12 15:02:35 +02:00
|
|
|
this.campaignService.campaigns = items;
|
2017-08-12 21:37:31 +02:00
|
|
|
this.campaigns = items;
|
2017-10-06 21:41:59 +02:00
|
|
|
|
|
|
|
const url = this.router.url;
|
|
|
|
if (url.endsWith(RouteConfig.statsPath)) {
|
|
|
|
this.selectOverview(this.campaigns[0]._id);
|
|
|
|
} else if (url.indexOf(subPathWar) !== -1) {
|
|
|
|
this.selectedWarId = url.substring(url.lastIndexOf(subPathWar) + subPathWar.length, url.lastIndexOf(")"));
|
|
|
|
} else if (url.indexOf(subPathOverview) !== -1) {
|
|
|
|
this.selectedWarId = url.substring(url.lastIndexOf(subPathOverview) + subPathOverview.length, url.lastIndexOf(")"));
|
|
|
|
}
|
2017-08-06 10:42:37 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-09-14 11:47:41 +02:00
|
|
|
selectNewCampaign() {
|
|
|
|
this.selectedWarId = null;
|
|
|
|
this.router.navigate([{outlets: {'right': ['new-campaign']}}], {relativeTo: this.route});
|
|
|
|
}
|
|
|
|
|
2017-08-06 10:42:37 +02:00
|
|
|
selectNewWar() {
|
|
|
|
this.selectedWarId = null;
|
|
|
|
this.router.navigate([{outlets: {'right': ['new']}}], {relativeTo: this.route});
|
|
|
|
}
|
|
|
|
|
2017-08-12 22:27:23 +02:00
|
|
|
selectWar(warId) {
|
|
|
|
if (this.selectedWarId != warId) {
|
|
|
|
this.selectedWarId = warId;
|
|
|
|
this.router.navigate([{outlets: {'right': ['war', warId]}}], {relativeTo: this.route});
|
|
|
|
}
|
2017-08-06 10:42:37 +02:00
|
|
|
}
|
|
|
|
|
2017-08-12 22:27:23 +02:00
|
|
|
selectOverview(overviewId) {
|
|
|
|
if (this.selectedWarId != overviewId) {
|
|
|
|
this.selectedWarId = overviewId;
|
|
|
|
this.router.navigate([{outlets: {'right': ['overview', overviewId]}}], {relativeTo: this.route});
|
|
|
|
}
|
2017-08-06 10:42:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2017-08-12 22:27:23 +02:00
|
|
|
this.selectOverview('all');
|
2017-08-06 10:42:37 +02:00
|
|
|
}
|
2017-08-12 21:37:31 +02:00
|
|
|
this.campaigns.splice(this.campaigns.indexOf(war), 1);
|
2017-08-06 10:42:37 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2017-08-12 15:28:37 +02:00
|
|
|
|
2017-09-12 15:02:35 +02:00
|
|
|
deleteCampaign(campaign) {
|
|
|
|
if (confirm('Soll die Kampagne ' + campaign.title + ' wirklich gelöscht werden?')) {
|
|
|
|
this.campaignService.deleteCampaign(campaign._id)
|
|
|
|
.subscribe((res) => {
|
|
|
|
console.log(res)
|
|
|
|
if (this.selectedWarId === campaign._id) {
|
|
|
|
this.selectOverview('all');
|
|
|
|
}
|
|
|
|
this.campaigns.splice(this.campaigns.indexOf(campaign), 1);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-06 10:42:37 +02:00
|
|
|
}
|