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

106 lines
3.6 KiB
TypeScript
Raw Normal View History

2018-03-07 11:56:50 +01:00
import {Component, OnInit} from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router';
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';
@Component({
selector: 'war-list',
templateUrl: './war-list.component.html',
styleUrls: ['./war-list.component.css', '../../../style/list-entry.css', '../../../style/select-list.css']
})
export class WarListComponent implements OnInit {
2017-08-13 16:35:42 +02:00
selectedWarId: string | number;
2017-08-12 21:37:31 +02:00
campaigns: Campaign[] = [];
2017-12-23 10:41:36 +01:00
public readonly highscore = 'HIGHSCORE';
constructor(private warService: WarService,
2017-09-12 15:02:35 +02:00
private campaignService: CampaignService,
public loginService: LoginService,
private router: Router,
private route: ActivatedRoute) {
}
ngOnInit() {
2017-09-12 15:02:35 +02:00
this.campaignService.getAllCampaigns().subscribe((items) => {
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;
const url = this.router.url;
if (url.endsWith(RouteConfig.statsPath)) {
this.selectOverview(this.campaigns[0]._id);
} 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(')'));
} 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-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
}
selectNewWar() {
this.selectedWarId = null;
this.router.navigate([{outlets: {'right': ['submit-war']}}], {relativeTo: this.route});
}
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-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;
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
}
}
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');
}
this.campaigns.splice(this.campaigns.indexOf(war), 1);
2018-03-07 11:56:50 +01: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
}
}