From 7890ef76fbd45b5d78a1f2fe54c8fa0f24cabc85 Mon Sep 17 00:00:00 2001 From: Florian Hartwich Date: Sat, 12 Aug 2017 21:37:31 +0200 Subject: [PATCH] Add campaign overview id --- static/src/app/models/model-interfaces.ts | 7 +++- .../app/services/war-service/war.service.ts | 6 ++- .../overview/stats-overview.component.ts | 40 ++++++++++++++++--- static/src/app/statistic/stats.routing.ts | 2 +- .../war-list/war-list.component.html | 9 +++-- .../statistic/war-list/war-list.component.ts | 13 +++--- 6 files changed, 58 insertions(+), 19 deletions(-) diff --git a/static/src/app/models/model-interfaces.ts b/static/src/app/models/model-interfaces.ts index 4f564af..5881dc0 100644 --- a/static/src/app/models/model-interfaces.ts +++ b/static/src/app/models/model-interfaces.ts @@ -11,7 +11,7 @@ export interface User { _id?: string; boardUserId?: number; username?: string; - squad?: any; //Squad or string + squad?: any; //Squad or id-string rank?: Rank; awards?: Award[]; } @@ -28,6 +28,11 @@ export interface Player { respawn?: number; flagTouch?: number; } +export interface Campaign { + _id?: string; + title?: string; + wars?: War[]; +} export interface War { _id?: string; title?: string; diff --git a/static/src/app/services/war-service/war.service.ts b/static/src/app/services/war-service/war.service.ts index ac6de1a..de761c8 100644 --- a/static/src/app/services/war-service/war.service.ts +++ b/static/src/app/services/war-service/war.service.ts @@ -1,16 +1,18 @@ import {Injectable} from "@angular/core"; -import {War} from "../../models/model-interfaces"; +import {Campaign, War} from "../../models/model-interfaces"; import {AppConfig} from "../../app.config"; import {HttpClient} from "../http-client"; @Injectable() export class WarService { + campaigns :Campaign[]; + constructor(private http: HttpClient, private config: AppConfig) { } - getAllWars() { + getAllCampaigns() { return this.http.get(this.config.apiWarPath) .map(res => res.json()) } diff --git a/static/src/app/statistic/overview/stats-overview.component.ts b/static/src/app/statistic/overview/stats-overview.component.ts index a762ee0..9187fa5 100644 --- a/static/src/app/statistic/overview/stats-overview.component.ts +++ b/static/src/app/statistic/overview/stats-overview.component.ts @@ -1,11 +1,15 @@ import {Component} from "@angular/core"; import {WarService} from "../../services/war-service/war.service"; +import {Campaign, War} from "../../models/model-interfaces"; +import {WarListComponent} from "../war-list/war-list.component"; +import {ActivatedRoute} from "@angular/router"; @Component({ selector: 'stats-overview', templateUrl: './stats-overview.component.html', - styleUrls: ['./stats-overview.component.css'] + styleUrls: ['./stats-overview.component.css'], + inputs: ['campaigns'] }) export class StatisticOverviewComponent { @@ -16,13 +20,39 @@ export class StatisticOverviewComponent { domain: ['#0000FF', '#B22222'] }; - constructor(private warService: WarService) { + constructor(private route: ActivatedRoute, + private warService: WarService) { } ngOnInit() { - this.warService.getAllWars().subscribe(items => { - this.initChart(items); - }) + this.route.params + .map(params => params['id']) + .subscribe((id) => { + console.log(id); + + if (this.warService.campaigns) { + this.initWars(this.warService.campaigns, id); + } else { + this.warService.getAllCampaigns().subscribe(campaigns => { + this.initWars(campaigns, id); + }) + } + }); + } + + initWars(campaigns, id) { + let wars = []; + let itemsProcessed = 0; + + campaigns + .filter(campaign => id === 'all' || campaign._id === id) + .forEach(campaign => { + wars = wars.concat(campaign.wars); + itemsProcessed++; + if (itemsProcessed === campaigns.length) { + this.initChart(wars); + } + }) } initChart(wars: any[]) { diff --git a/static/src/app/statistic/stats.routing.ts b/static/src/app/statistic/stats.routing.ts index 53d09dc..b34c8d1 100644 --- a/static/src/app/statistic/stats.routing.ts +++ b/static/src/app/statistic/stats.routing.ts @@ -17,7 +17,7 @@ export const statsRoutes: Routes = [{ ] }, { - path: 'overview', + path: 'overview/:id', component: StatisticOverviewComponent, outlet: 'right' }, diff --git a/static/src/app/statistic/war-list/war-list.component.html b/static/src/app/statistic/war-list/war-list.component.html index 58ecb9b..be9b7e2 100644 --- a/static/src/app/statistic/war-list/war-list.component.html +++ b/static/src/app/statistic/war-list/war-list.component.html @@ -16,12 +16,13 @@ - - + +
- Return to Hell in a Bowl + {{campaign.title}} +
-
+
{ - this.wars = items; - this.router.navigate([{outlets: {'right': ['overview']}}], {relativeTo: this.route}); + this.warService.getAllCampaigns().subscribe((items) => { + this.warService.campaigns = items; + this.campaigns = items; + this.router.navigate([{outlets: {'right': ['overview', 'all']}}], {relativeTo: this.route}); }); } @@ -52,7 +53,7 @@ export class WarListComponent implements OnInit { if (this.selectedWarId === war._id) { this.selectOverview(); } - this.wars.splice(this.wars.indexOf(war), 1); + this.campaigns.splice(this.campaigns.indexOf(war), 1); }) } }