Redirect to campaign/war/highscore by url

pull/38/head
HardiReady 2018-08-08 21:42:57 +02:00
parent d8544edb5e
commit 8e70ca831f
5 changed files with 55 additions and 26 deletions

View File

@ -73,7 +73,7 @@ export class AppComponent implements OnInit {
const currentUrl = this.router.url;
// 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();
}
}

View File

@ -10,7 +10,7 @@ import {PlayerUtils} from '../../../utils/player-utils';
@Component({
selector: 'stats-highscore',
selector: 'cc-stats-highscore',
templateUrl: './highscore.component.html',
styleUrls: ['./highscore.component.css', '../../../style/list-entry.css', '../../../style/overview.css']
})
@ -20,8 +20,6 @@ export class StatisticHighScoreComponent implements OnInit {
id = '';
title = '';
searchTerm = new FormControl();
players: Player = {};
@ -60,9 +58,6 @@ export class StatisticHighScoreComponent implements OnInit {
}
initData() {
this.title = this.campaignService.campaigns
.filter(camp => camp._id === this.id).pop().title;
this.playerService.getCampaignHighscore(this.id).subscribe(players => {
this.players = players;
this.playersStored = players;

View File

@ -24,11 +24,38 @@ export class StatisticComponent implements OnInit {
ngOnInit() {
this.campaignService.getAllCampaignsWithWars().subscribe((campaigns) => {
this.campaigns = campaigns;
// TODO next line has to die!
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) {
this.selectedCampaign = campaign;
if (campaign._id === 'all' || this.router.url.includes('/overview/all')) {
@ -36,7 +63,6 @@ export class StatisticComponent implements OnInit {
window.dispatchEvent(new Event('resize'));
});
}
this.router.navigate([{outlets: {'right': ['overview', campaign._id]}}], {relativeTo: this.route});
}
toggleCollapse() {

View File

@ -7,7 +7,6 @@
</button>
</div>
<div class="list-header"
[ngClass]="{selected : selectedWarId == campaign._id}" (click)="selectOverview(campaign._id)">
<div class="select-indicator-container">

View File

@ -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 {Campaign, War} from '../../../models/model-interfaces';
import {WarService} from '../../../services/logs/war.service';
@ -11,7 +11,7 @@ import {RouteConfig} from '../../../app.config';
templateUrl: './war-list.component.html',
styleUrls: ['./war-list.component.css']
})
export class WarListComponent implements OnInit, OnChanges {
export class WarListComponent implements OnChanges, AfterViewInit {
@Input() campaign: Campaign;
@ -19,6 +19,8 @@ export class WarListComponent implements OnInit, OnChanges {
selectedWarId: string | number;
initialized = false;
public readonly highscore = 'HIGHSCORE';
constructor(private warService: WarService,
@ -28,23 +30,30 @@ export class WarListComponent implements OnInit, OnChanges {
private route: ActivatedRoute) {
}
ngOnChanges(changes: SimpleChanges) {
if (changes.campaign) {
this.selectedWarId = this.campaign._id;
}
ngAfterViewInit() {
this.initialized = true;
}
ngOnInit() {
const url = this.router.url;
const subPathWar = 'war/';
const subPathOverview = 'overview/';
ngOnChanges(changes: SimpleChanges) {
if (this.initialized && changes.campaign) {
const url = this.router.url;
const subPathWar = 'war/';
const subPathHighscore = 'highscore/';
const subPathOverview = 'overview/';
if (url.endsWith(RouteConfig.statsPath)) {
this.selectOverview(this.campaign._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(')'));
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]);
}
}
}
}
}