2018-08-19 22:35:40 +02:00
|
|
|
import {Component, Input, OnChanges, 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';
|
2018-10-02 14:31:26 +02:00
|
|
|
import {TranslateService} from '@ngx-translate/core';
|
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-08-18 17:38:21 +02:00
|
|
|
export class WarListComponent implements OnChanges {
|
2018-07-29 20:59:09 +02:00
|
|
|
|
|
|
|
@Input() campaign: Campaign;
|
2017-08-06 10:42:37 +02:00
|
|
|
|
2018-07-30 20:43:47 +02:00
|
|
|
@Input() collapsed: boolean;
|
|
|
|
|
2017-08-13 16:35:42 +02:00
|
|
|
selectedWarId: string | number;
|
2017-08-06 10:42:37 +02:00
|
|
|
|
2018-08-18 17:38:21 +02:00
|
|
|
changeCount = 0;
|
2018-08-08 21:42:57 +02:00
|
|
|
|
2018-10-02 14:31:26 +02:00
|
|
|
toolTipTranslation = {};
|
|
|
|
|
|
|
|
readonly highscore = 'HIGHSCORE';
|
2017-12-23 10:41:36 +01:00
|
|
|
|
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,
|
2018-10-02 14:31:26 +02:00
|
|
|
private route: ActivatedRoute,
|
|
|
|
private translate: TranslateService) {
|
|
|
|
['stats.sidebar.overview',
|
|
|
|
'stats.sidebar.highscore',
|
|
|
|
'stats.sidebar.battles'].forEach(i18n => {
|
|
|
|
this.translate.get(i18n).subscribe((translated) => {
|
|
|
|
this.toolTipTranslation[i18n] = translated;
|
|
|
|
})
|
|
|
|
});
|
2017-08-06 10:42:37 +02:00
|
|
|
}
|
|
|
|
|
2018-08-08 21:42:57 +02:00
|
|
|
ngOnChanges(changes: SimpleChanges) {
|
2018-08-18 17:38:21 +02:00
|
|
|
if (this.changeCount <= 1) {
|
|
|
|
this.changeCount++;
|
2018-08-08 21:42:57 +02:00
|
|
|
const url = this.router.url;
|
|
|
|
const subPathWar = 'war/';
|
|
|
|
const subPathHighscore = 'highscore/';
|
|
|
|
const subPathOverview = 'overview/';
|
2018-07-30 21:30:59 +02:00
|
|
|
|
2018-08-08 21:42:57 +02:00
|
|
|
if (url.endsWith(RouteConfig.statsPath) || url.includes(subPathOverview)) {
|
|
|
|
this.selectOverview(this.campaign._id);
|
|
|
|
} else {
|
|
|
|
const idFetchPattern = /right:.*\/(.*)\)$/;
|
|
|
|
const id = idFetchPattern.exec(url);
|
|
|
|
if (id.length === 2) {
|
|
|
|
if (url.includes(subPathWar)) {
|
|
|
|
this.selectWar(id[1]);
|
|
|
|
} else if (url.includes(subPathHighscore)) {
|
|
|
|
this.selectHighscore(id[1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-08-18 17:38:21 +02:00
|
|
|
} else if (changes.campaign) {
|
|
|
|
this.selectOverview(this.campaign._id);
|
2018-07-30 21:30: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;
|
|
|
|
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) {
|
2018-10-02 14:31:26 +02:00
|
|
|
this.translate.get('stats.sidebar.battle.manage.delete.confirm', {title: war.title})
|
|
|
|
.subscribe((confirmQuestion: string) => {
|
|
|
|
if (confirm(confirmQuestion)) {
|
|
|
|
this.warService.deleteWar(war._id)
|
|
|
|
.subscribe((res) => {
|
|
|
|
if (this.selectedWarId === war._id) {
|
|
|
|
this.selectOverview('all');
|
|
|
|
}
|
|
|
|
this.campaign.wars.splice(this.campaign.wars.indexOf(war), 1);
|
|
|
|
});
|
2018-08-18 17:38:21 +02:00
|
|
|
}
|
|
|
|
});
|
2017-09-12 15:02:35 +02:00
|
|
|
}
|
2017-08-06 10:42:37 +02:00
|
|
|
}
|