Add campaign overview id

pull/6/head
Florian Hartwich 2017-08-12 21:37:31 +02:00
parent 8319b79e1f
commit 7890ef76fb
6 changed files with 58 additions and 19 deletions

View File

@ -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;

View File

@ -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())
}

View File

@ -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,12 +20,38 @@ 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);
}
})
}

View File

@ -17,7 +17,7 @@ export const statsRoutes: Routes = [{
]
},
{
path: 'overview',
path: 'overview/:id',
component: StatisticOverviewComponent,
outlet: 'right'
},

View File

@ -16,12 +16,13 @@
</div>
</div>
<accordion [closeOthers]="oneAtATime">
<accordion-group #group>
<accordion [closeOthers]="oneAtATime" *ngFor="let campaign of campaigns">
<accordion-group>
<div accordion-heading>
Return to Hell in a Bowl
{{campaign.title}}
<span class="pull-right"></span>
</div>
<div *ngFor="let war of wars">
<div *ngFor="let war of campaign.wars">
<pjm-war-item
[war]="war"
(warDelete)="deleteWar(war)"

View File

@ -1,6 +1,6 @@
import {Component, OnInit} from "@angular/core";
import {ActivatedRoute, Router} from "@angular/router";
import {War} from "../../models/model-interfaces";
import {Campaign, War} from "../../models/model-interfaces";
import {WarService} from "../../services/war-service/war.service";
import {LoginService} from "../../services/login-service/login-service";
@ -13,7 +13,7 @@ export class WarListComponent implements OnInit {
selectedWarId: string | number = '0';
wars: War[] = [];
campaigns: Campaign[] = [];
public oneAtATime: boolean = true;
@ -24,9 +24,10 @@ export class WarListComponent implements OnInit {
}
ngOnInit() {
this.warService.getAllWars().subscribe((items) => {
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);
})
}
}