Redirect to campaign/war/highscore by url
parent
d8544edb5e
commit
8e70ca831f
|
@ -73,7 +73,7 @@ export class AppComponent implements OnInit {
|
||||||
const currentUrl = this.router.url;
|
const currentUrl = this.router.url;
|
||||||
|
|
||||||
// scroll to top on route from army overview to user detail and back
|
// scroll to top on route from army overview to user detail and back
|
||||||
if (currentUrl.includes('/overview')) {
|
if (currentUrl.includes('/overview') || currentUrl.includes('/public')) {
|
||||||
this.scrollToTop();
|
this.scrollToTop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ import {PlayerUtils} from '../../../utils/player-utils';
|
||||||
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'stats-highscore',
|
selector: 'cc-stats-highscore',
|
||||||
templateUrl: './highscore.component.html',
|
templateUrl: './highscore.component.html',
|
||||||
styleUrls: ['./highscore.component.css', '../../../style/list-entry.css', '../../../style/overview.css']
|
styleUrls: ['./highscore.component.css', '../../../style/list-entry.css', '../../../style/overview.css']
|
||||||
})
|
})
|
||||||
|
@ -20,8 +20,6 @@ export class StatisticHighScoreComponent implements OnInit {
|
||||||
|
|
||||||
id = '';
|
id = '';
|
||||||
|
|
||||||
title = '';
|
|
||||||
|
|
||||||
searchTerm = new FormControl();
|
searchTerm = new FormControl();
|
||||||
|
|
||||||
players: Player = {};
|
players: Player = {};
|
||||||
|
@ -60,9 +58,6 @@ export class StatisticHighScoreComponent implements OnInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
initData() {
|
initData() {
|
||||||
this.title = this.campaignService.campaigns
|
|
||||||
.filter(camp => camp._id === this.id).pop().title;
|
|
||||||
|
|
||||||
this.playerService.getCampaignHighscore(this.id).subscribe(players => {
|
this.playerService.getCampaignHighscore(this.id).subscribe(players => {
|
||||||
this.players = players;
|
this.players = players;
|
||||||
this.playersStored = players;
|
this.playersStored = players;
|
||||||
|
|
|
@ -24,11 +24,38 @@ export class StatisticComponent implements OnInit {
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.campaignService.getAllCampaignsWithWars().subscribe((campaigns) => {
|
this.campaignService.getAllCampaignsWithWars().subscribe((campaigns) => {
|
||||||
this.campaigns = campaigns;
|
this.campaigns = campaigns;
|
||||||
|
// TODO next line has to die!
|
||||||
this.campaignService.campaigns = campaigns;
|
this.campaignService.campaigns = campaigns;
|
||||||
this.switchCampaign(campaigns[0])
|
this.selectedCampaign = this.resolveCampaignFromUrl();
|
||||||
|
this.switchCampaign(this.selectedCampaign);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resolveCampaignFromUrl() {
|
||||||
|
const url = this.router.url;
|
||||||
|
|
||||||
|
const idFetchPattern = /right:.*\/(.*)\)$/;
|
||||||
|
|
||||||
|
if (url.includes('right:overview') || url.includes('right:highscore')) {
|
||||||
|
const id = idFetchPattern.exec(url)[1];
|
||||||
|
if (id === 'all') {
|
||||||
|
return {_id: id}
|
||||||
|
}
|
||||||
|
const filteredCampaigns = this.campaigns.filter(c => c._id === id);
|
||||||
|
if (filteredCampaigns.length === 1) {
|
||||||
|
return filteredCampaigns[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (url.includes('right:war')) {
|
||||||
|
const id = idFetchPattern.exec(url)[1];
|
||||||
|
const filteredCampaigns = this.campaigns.filter(c => c.wars.filter(war => war._id === id).length > 0);
|
||||||
|
if (filteredCampaigns.length === 1) {
|
||||||
|
return filteredCampaigns[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this.campaigns[0]
|
||||||
|
}
|
||||||
|
|
||||||
switchCampaign(campaign) {
|
switchCampaign(campaign) {
|
||||||
this.selectedCampaign = campaign;
|
this.selectedCampaign = campaign;
|
||||||
if (campaign._id === 'all' || this.router.url.includes('/overview/all')) {
|
if (campaign._id === 'all' || this.router.url.includes('/overview/all')) {
|
||||||
|
@ -36,7 +63,6 @@ export class StatisticComponent implements OnInit {
|
||||||
window.dispatchEvent(new Event('resize'));
|
window.dispatchEvent(new Event('resize'));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
this.router.navigate([{outlets: {'right': ['overview', campaign._id]}}], {relativeTo: this.route});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleCollapse() {
|
toggleCollapse() {
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div class="list-header"
|
<div class="list-header"
|
||||||
[ngClass]="{selected : selectedWarId == campaign._id}" (click)="selectOverview(campaign._id)">
|
[ngClass]="{selected : selectedWarId == campaign._id}" (click)="selectOverview(campaign._id)">
|
||||||
<div class="select-indicator-container">
|
<div class="select-indicator-container">
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import {Component, Input, OnChanges, OnInit, SimpleChanges} from '@angular/core';
|
import {AfterViewInit, Component, Input, OnChanges, SimpleChanges} from '@angular/core';
|
||||||
import {ActivatedRoute, Router} from '@angular/router';
|
import {ActivatedRoute, Router} from '@angular/router';
|
||||||
import {Campaign, War} from '../../../models/model-interfaces';
|
import {Campaign, War} from '../../../models/model-interfaces';
|
||||||
import {WarService} from '../../../services/logs/war.service';
|
import {WarService} from '../../../services/logs/war.service';
|
||||||
|
@ -11,7 +11,7 @@ import {RouteConfig} from '../../../app.config';
|
||||||
templateUrl: './war-list.component.html',
|
templateUrl: './war-list.component.html',
|
||||||
styleUrls: ['./war-list.component.css']
|
styleUrls: ['./war-list.component.css']
|
||||||
})
|
})
|
||||||
export class WarListComponent implements OnInit, OnChanges {
|
export class WarListComponent implements OnChanges, AfterViewInit {
|
||||||
|
|
||||||
@Input() campaign: Campaign;
|
@Input() campaign: Campaign;
|
||||||
|
|
||||||
|
@ -19,6 +19,8 @@ export class WarListComponent implements OnInit, OnChanges {
|
||||||
|
|
||||||
selectedWarId: string | number;
|
selectedWarId: string | number;
|
||||||
|
|
||||||
|
initialized = false;
|
||||||
|
|
||||||
public readonly highscore = 'HIGHSCORE';
|
public readonly highscore = 'HIGHSCORE';
|
||||||
|
|
||||||
constructor(private warService: WarService,
|
constructor(private warService: WarService,
|
||||||
|
@ -28,23 +30,30 @@ export class WarListComponent implements OnInit, OnChanges {
|
||||||
private route: ActivatedRoute) {
|
private route: ActivatedRoute) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnChanges(changes: SimpleChanges) {
|
ngAfterViewInit() {
|
||||||
if (changes.campaign) {
|
this.initialized = true;
|
||||||
this.selectedWarId = this.campaign._id;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnChanges(changes: SimpleChanges) {
|
||||||
|
if (this.initialized && changes.campaign) {
|
||||||
const url = this.router.url;
|
const url = this.router.url;
|
||||||
const subPathWar = 'war/';
|
const subPathWar = 'war/';
|
||||||
|
const subPathHighscore = 'highscore/';
|
||||||
const subPathOverview = 'overview/';
|
const subPathOverview = 'overview/';
|
||||||
|
|
||||||
if (url.endsWith(RouteConfig.statsPath)) {
|
if (url.endsWith(RouteConfig.statsPath) || url.includes(subPathOverview)) {
|
||||||
this.selectOverview(this.campaign._id);
|
this.selectOverview(this.campaign._id);
|
||||||
} else if (url.indexOf(subPathWar) !== -1) {
|
} else {
|
||||||
this.selectedWarId = url.substring(url.lastIndexOf(subPathWar) + subPathWar.length, url.lastIndexOf(')'));
|
const idFetchPattern = /right:.*\/(.*)\)$/;
|
||||||
} else if (url.indexOf(subPathOverview) !== -1) {
|
const id = idFetchPattern.exec(url);
|
||||||
this.selectedWarId = url.substring(url.lastIndexOf(subPathOverview) + subPathOverview.length, url.lastIndexOf(')'));
|
if (id.length === 2) {
|
||||||
|
if (url.includes(subPathWar)) {
|
||||||
|
this.selectWar(id[1]);
|
||||||
|
} else if (url.includes(subPathHighscore)) {
|
||||||
|
this.selectHighscore(id[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue