2018-07-29 20:59:09 +02:00
|
|
|
import {Component, Input, OnChanges, OnInit, SimpleChanges} from '@angular/core';
|
2018-03-07 11:56:50 +01:00
|
|
|
import {ActivatedRoute, Router} from '@angular/router';
|
2018-04-29 10:07:20 +02:00
|
|
|
import {Campaign, War} from '../../../models/model-interfaces';
|
|
|
|
import {WarService} from '../../../services/logs/war.service';
|
|
|
|
import {LoginService} from '../../../services/app-user-service/login-service';
|
|
|
|
import {CampaignService} from '../../../services/logs/campaign.service';
|
|
|
|
import {RouteConfig} from '../../../app.config';
|
2017-08-06 10:42:37 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'war-list',
|
|
|
|
templateUrl: './war-list.component.html',
|
2018-07-29 20:59:09 +02:00
|
|
|
styleUrls: ['./war-list.component.css']
|
2017-08-06 10:42:37 +02:00
|
|
|
})
|
2018-07-29 20:59:09 +02:00
|
|
|
export class WarListComponent implements OnInit, OnChanges {
|
|
|
|
|
|
|
|
@Input() campaign: Campaign;
|
2017-08-06 10:42:37 +02:00
|
|
|
|
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
|
|
|
|
2017-12-23 10:41:36 +01:00
|
|
|
public readonly highscore = 'HIGHSCORE';
|
|
|
|
|
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) {
|
|
|
|
}
|
|
|
|
|
2018-07-29 20:59:09 +02:00
|
|
|
ngOnChanges(changes: SimpleChanges) {
|
|
|
|
this.selectedWarId = this.campaign._id;
|
|
|
|
}
|
|
|
|
|
2017-08-06 10:42:37 +02:00
|
|
|
ngOnInit() {
|
2018-07-28 16:04:38 +02:00
|
|
|
this.campaignService.getAllCampaignsWithWars().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)) {
|
2018-07-29 20:59:09 +02:00
|
|
|
this.selectOverview(this.campaign._id);
|
2017-10-06 21:41:59 +02:00
|
|
|
} else if (url.indexOf(subPathWar) !== -1) {
|
2018-03-07 11:56:50 +01:00
|
|
|
this.selectedWarId = url.substring(url.lastIndexOf(subPathWar) + subPathWar.length, url.lastIndexOf(')'));
|
2017-10-06 21:41:59 +02:00
|
|
|
} else if (url.indexOf(subPathOverview) !== -1) {
|
2018-03-07 11:56:50 +01:00
|
|
|
this.selectedWarId = url.substring(url.lastIndexOf(subPathOverview) + subPathOverview.length, url.lastIndexOf(')'));
|
2017-10-06 21:41:59 +02:00
|
|
|
}
|
2017-08-06 10:42:37 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-09-14 11:47:41 +02:00
|
|
|
selectNewCampaign() {
|
|
|
|
this.selectedWarId = null;
|
2018-04-28 10:44:52 +02:00
|
|
|
this.router.navigate([{outlets: {'right': ['campaign']}}], {relativeTo: this.route});
|
2017-09-14 11:47:41 +02:00
|
|
|
}
|
|
|
|
|
2017-08-12 22:27:23 +02:00
|
|
|
selectWar(warId) {
|
2018-03-07 11:56:50 +01:00
|
|
|
if (this.selectedWarId !== warId) {
|
2017-08-12 22:27:23 +02:00
|
|
|
this.selectedWarId = warId;
|
|
|
|
this.router.navigate([{outlets: {'right': ['war', warId]}}], {relativeTo: this.route});
|
|
|
|
}
|
2017-08-06 10:42:37 +02:00
|
|
|
}
|
|
|
|
|
2017-12-23 10:41:36 +01:00
|
|
|
selectOverview(campaignId) {
|
2018-03-07 11:56:50 +01:00
|
|
|
if (this.selectedWarId !== campaignId) {
|
2017-12-23 10:41:36 +01:00
|
|
|
this.selectedWarId = campaignId;
|
2018-07-29 20:59:09 +02:00
|
|
|
setTimeout(_ => {
|
|
|
|
window.dispatchEvent(new Event('resize'));
|
|
|
|
});
|
2017-12-23 10:41:36 +01:00
|
|
|
this.router.navigate([{outlets: {'right': ['overview', campaignId]}}], {relativeTo: this.route});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
selectHighscore(campaignId) {
|
2018-03-07 11:56:50 +01:00
|
|
|
if (this.selectedWarId !== campaignId + this.highscore) {
|
2017-12-23 10:41:36 +01:00
|
|
|
this.selectedWarId = campaignId + this.highscore;
|
2017-12-23 10:59:27 +01:00
|
|
|
this.router.navigate([{outlets: {'right': ['highscore', campaignId]}}], {relativeTo: this.route});
|
2017-08-12 22:27:23 +02:00
|
|
|
}
|
2017-08-06 10:42:37 +02:00
|
|
|
}
|
|
|
|
|
2018-04-29 11:12:09 +02:00
|
|
|
selectNewWar() {
|
|
|
|
this.selectedWarId = null;
|
|
|
|
this.router.navigate([{outlets: {'right': ['submit-war']}}], {relativeTo: this.route});
|
|
|
|
}
|
|
|
|
|
|
|
|
editWar(warId) {
|
|
|
|
this.selectedWarId = warId;
|
|
|
|
this.router.navigate([{outlets: {'right': ['submit-war', warId]}}], {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)
|
2018-02-26 09:04:27 +01:00
|
|
|
.subscribe((res) => {
|
|
|
|
if (this.selectedWarId === war._id) {
|
|
|
|
this.selectOverview('all');
|
|
|
|
}
|
2018-04-29 11:12:09 +02:00
|
|
|
this.campaigns.forEach(campaign => {
|
2018-04-29 11:30:40 +02:00
|
|
|
campaign.wars.splice(campaign.wars.indexOf(war), 1);
|
|
|
|
});
|
2018-03-07 11:56:50 +01:00
|
|
|
});
|
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)
|
2018-02-26 09:04:27 +01:00
|
|
|
.subscribe((res) => {
|
|
|
|
if (this.selectedWarId === campaign._id) {
|
|
|
|
this.selectOverview('all');
|
|
|
|
}
|
|
|
|
this.campaigns.splice(this.campaigns.indexOf(campaign), 1);
|
2018-03-07 11:56:50 +01:00
|
|
|
});
|
2017-09-12 15:02:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-27 15:19:23 +02:00
|
|
|
editCampaign(selectCampaign) {
|
2018-04-28 10:44:52 +02:00
|
|
|
this.router.navigate([{outlets: {'right': ['campaign', selectCampaign._id]}}], {relativeTo: this.route});
|
2018-04-27 15:19:23 +02:00
|
|
|
}
|
2017-08-06 10:42:37 +02:00
|
|
|
}
|