Compare commits
No commits in common. "c9fce51ef60603f3e8b6f0b025364a0aa19ae40c" and "8e46b6c6f1e4b7838dc172b88e37e09e43277bed" have entirely different histories.
c9fce51ef6
...
8e46b6c6f1
|
@ -2,20 +2,14 @@ import {Injectable} from '@angular/core';
|
||||||
import {Campaign} from '../../models/model-interfaces';
|
import {Campaign} from '../../models/model-interfaces';
|
||||||
import {AppConfig} from '../../app.config';
|
import {AppConfig} from '../../app.config';
|
||||||
import {HttpClient} from '../http-client';
|
import {HttpClient} from '../http-client';
|
||||||
import {ADD, EDIT, LOAD, REMOVE, Store} from '../stores/generic-store';
|
|
||||||
import {Observable} from 'rxjs';
|
|
||||||
import {RequestMethod, RequestOptions} from '@angular/http';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class CampaignService {
|
export class CampaignService {
|
||||||
|
|
||||||
campaigns$: Observable<Campaign[]>;
|
campaigns: Campaign[];
|
||||||
|
|
||||||
campaignStore = new Store<Campaign>();
|
|
||||||
|
|
||||||
constructor(private http: HttpClient,
|
constructor(private http: HttpClient,
|
||||||
private config: AppConfig) {
|
private config: AppConfig) {
|
||||||
this.campaigns$ = this.campaignStore.items$;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getAllCampaigns() {
|
getAllCampaigns() {
|
||||||
|
@ -24,48 +18,23 @@ export class CampaignService {
|
||||||
}
|
}
|
||||||
|
|
||||||
getAllCampaignsWithWars() {
|
getAllCampaignsWithWars() {
|
||||||
this.http.get(this.config.apiWarPath)
|
return this.http.get(this.config.apiWarPath)
|
||||||
.map(res => res.json())
|
.map(res => res.json());
|
||||||
.do((ranks) => {
|
|
||||||
this.campaignStore.dispatch({type: LOAD, data: ranks});
|
|
||||||
}).subscribe(_ => {
|
|
||||||
});
|
|
||||||
return this.campaigns$;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
submitCampaign(campaign: Campaign) {
|
submitCampaign(campaign: Campaign) {
|
||||||
let requestUrl: string;
|
|
||||||
let requestMethod: RequestMethod
|
|
||||||
let accessType;
|
|
||||||
|
|
||||||
if (campaign._id) {
|
if (campaign._id) {
|
||||||
requestUrl = this.config.apiCampaignPath + '/' + campaign._id;
|
return this.http.patch(this.config.apiCampaignPath + '/' + campaign._id, campaign)
|
||||||
requestMethod = RequestMethod.Patch;
|
.map(res => res.json());
|
||||||
accessType = EDIT;
|
|
||||||
} else {
|
} else {
|
||||||
requestUrl = this.config.apiCampaignPath;
|
return this.http.post(this.config.apiCampaignPath, campaign)
|
||||||
requestMethod = RequestMethod.Post;
|
.map(res => res.json());
|
||||||
accessType = ADD;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const options = new RequestOptions({
|
|
||||||
body: campaign,
|
|
||||||
method: requestMethod
|
|
||||||
});
|
|
||||||
|
|
||||||
return this.http.request(requestUrl, options)
|
|
||||||
.map(res => res.json())
|
|
||||||
.do(savedCampaign => {
|
|
||||||
const action = {type: accessType, data: savedCampaign};
|
|
||||||
this.campaignStore.dispatch(action);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteCampaign(campaign: Campaign) {
|
deleteCampaign(id: string) {
|
||||||
return this.http.delete(this.config.apiCampaignPath + '/' + campaign._id)
|
return this.http.delete(this.config.apiCampaignPath + '/' + id)
|
||||||
.do(res => {
|
.map(res => res.json());
|
||||||
this.campaignStore.dispatch({type: REMOVE, data: campaign});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getCampaign(id: string) {
|
getCampaign(id: string) {
|
||||||
|
|
|
@ -1,4 +1,14 @@
|
||||||
import {Component, ElementRef, EventEmitter, Input, OnChanges, Output, SimpleChanges, ViewChild} from '@angular/core';
|
import {
|
||||||
|
AfterViewInit,
|
||||||
|
Component,
|
||||||
|
ElementRef,
|
||||||
|
EventEmitter,
|
||||||
|
Input,
|
||||||
|
OnChanges,
|
||||||
|
Output,
|
||||||
|
SimpleChanges,
|
||||||
|
ViewChild
|
||||||
|
} from '@angular/core';
|
||||||
import {Campaign} from '../../../models/model-interfaces';
|
import {Campaign} from '../../../models/model-interfaces';
|
||||||
import {LoginService} from '../../../services/app-user-service/login-service';
|
import {LoginService} from '../../../services/app-user-service/login-service';
|
||||||
|
|
||||||
|
@ -37,10 +47,8 @@ export class CampaignNavigationComponent implements OnChanges {
|
||||||
}
|
}
|
||||||
|
|
||||||
select(campaign) {
|
select(campaign) {
|
||||||
if (campaign && campaign._id) {
|
this.selectedCampaignId = campaign._id;
|
||||||
this.selectedCampaignId = campaign._id;
|
this.campaignSelect.emit(campaign);
|
||||||
this.campaignSelect.emit(campaign);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
edit(campaign) {
|
edit(campaign) {
|
||||||
|
|
|
@ -16,6 +16,8 @@ import {PlayerUtils} from '../../../utils/player-utils';
|
||||||
})
|
})
|
||||||
export class StatisticHighScoreComponent implements OnInit {
|
export class StatisticHighScoreComponent implements OnInit {
|
||||||
|
|
||||||
|
@Input() campaigns;
|
||||||
|
|
||||||
id = '';
|
id = '';
|
||||||
|
|
||||||
searchTerm = new FormControl();
|
searchTerm = new FormControl();
|
||||||
|
@ -29,7 +31,8 @@ export class StatisticHighScoreComponent implements OnInit {
|
||||||
readonly fraction = Fraction;
|
readonly fraction = Fraction;
|
||||||
|
|
||||||
constructor(private route: ActivatedRoute,
|
constructor(private route: ActivatedRoute,
|
||||||
private playerService: PlayerService) {
|
private playerService: PlayerService,
|
||||||
|
private campaignService: CampaignService) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
|
@ -37,7 +40,14 @@ export class StatisticHighScoreComponent implements OnInit {
|
||||||
.map(params => params['id'])
|
.map(params => params['id'])
|
||||||
.subscribe((id) => {
|
.subscribe((id) => {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.initData();
|
if (this.campaignService.campaigns) {
|
||||||
|
this.initData();
|
||||||
|
} else {
|
||||||
|
this.campaignService.getAllCampaignsWithWars().subscribe(campaigns => {
|
||||||
|
this.campaignService.campaigns = campaigns;
|
||||||
|
this.initData();
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const searchTermStream = this.searchTerm.valueChanges.debounceTime(400);
|
const searchTermStream = this.searchTerm.valueChanges.debounceTime(400);
|
||||||
|
|
|
@ -46,9 +46,13 @@ export class StatisticOverviewComponent implements OnInit {
|
||||||
.map(params => params['id'])
|
.map(params => params['id'])
|
||||||
.subscribe((id) => {
|
.subscribe((id) => {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.campaignService.getAllCampaignsWithWars().subscribe(campaigns => {
|
if (this.campaignService.campaigns) {
|
||||||
this.initWars(campaigns);
|
this.initWars(this.campaignService.campaigns);
|
||||||
});
|
} else {
|
||||||
|
this.campaignService.getAllCampaignsWithWars().subscribe(campaigns => {
|
||||||
|
this.initWars(campaigns);
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,40 +95,36 @@ export class StatisticOverviewComponent implements OnInit {
|
||||||
const playersObj = ChartUtils.getMultiDataArray(Fraction.BLUFOR, Fraction.OPFOR);
|
const playersObj = ChartUtils.getMultiDataArray(Fraction.BLUFOR, Fraction.OPFOR);
|
||||||
|
|
||||||
for (let i = wars.length - 1; i >= 0; i--) {
|
for (let i = wars.length - 1; i >= 0; i--) {
|
||||||
const war = wars[i];
|
|
||||||
if (!war) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const j = wars.length - i - 1;
|
const j = wars.length - i - 1;
|
||||||
const warDate = (this.id === 'all') ? new Date(war.date) : ChartUtils.getShortDateString(war.date);
|
const warDate = (this.id === 'all') ? new Date(wars[i].date) : ChartUtils.getShortDateString(wars[i].date);
|
||||||
|
|
||||||
pointsObj[0].series.push({
|
pointsObj[0].series.push({
|
||||||
name: warDate,
|
name: warDate,
|
||||||
value: war.ptBlufor
|
value: wars[i].ptBlufor
|
||||||
});
|
});
|
||||||
pointsObj[1].series.push({
|
pointsObj[1].series.push({
|
||||||
name: warDate,
|
name: warDate,
|
||||||
value: war.ptOpfor
|
value: wars[i].ptOpfor
|
||||||
});
|
});
|
||||||
pointsSumObj[0].series.push({
|
pointsSumObj[0].series.push({
|
||||||
name: warDate,
|
name: warDate,
|
||||||
value: pointsSumObj[0].series[j - 1] ?
|
value: pointsSumObj[0].series[j - 1] ?
|
||||||
pointsSumObj[0].series[j - 1].value + war.ptBlufor :
|
pointsSumObj[0].series[j - 1].value + wars[i].ptBlufor :
|
||||||
war.ptBlufor
|
wars[i].ptBlufor
|
||||||
});
|
});
|
||||||
pointsSumObj[1].series.push({
|
pointsSumObj[1].series.push({
|
||||||
name: warDate,
|
name: warDate,
|
||||||
value: pointsSumObj[1].series[j - 1]
|
value: pointsSumObj[1].series[j - 1]
|
||||||
? pointsSumObj[1].series[j - 1].value + war.ptOpfor :
|
? pointsSumObj[1].series[j - 1].value + wars[i].ptOpfor :
|
||||||
war.ptOpfor
|
wars[i].ptOpfor
|
||||||
});
|
});
|
||||||
playersObj[0].series.push({
|
playersObj[0].series.push({
|
||||||
name: warDate,
|
name: warDate,
|
||||||
value: war.playersBlufor
|
value: wars[i].playersBlufor
|
||||||
});
|
});
|
||||||
playersObj[1].series.push({
|
playersObj[1].series.push({
|
||||||
name: warDate,
|
name: warDate,
|
||||||
value: war.playersOpfor
|
value: wars[i].playersOpfor
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ import {SettingsService} from '../services/settings.service';
|
||||||
})
|
})
|
||||||
export class StatisticComponent implements OnInit {
|
export class StatisticComponent implements OnInit {
|
||||||
|
|
||||||
selectedCampaign: Campaign;
|
selectedCampaign: Campaign = {};
|
||||||
|
|
||||||
campaigns: Campaign[] = [];
|
campaigns: Campaign[] = [];
|
||||||
|
|
||||||
|
@ -29,16 +29,14 @@ 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.selectedCampaign = this.resolveCampaignFromUrl();
|
this.selectedCampaign = this.resolveCampaignFromUrl();
|
||||||
this.switchCampaign(this.selectedCampaign);
|
this.switchCampaign(this.selectedCampaign);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
resolveCampaignFromUrl() {
|
resolveCampaignFromUrl() {
|
||||||
if (this.campaigns.length === 0) {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
const url = this.router.url;
|
const url = this.router.url;
|
||||||
|
|
||||||
const idFetchPattern = /right:.*\/(.*)\)$/;
|
const idFetchPattern = /right:.*\/(.*)\)$/;
|
||||||
|
@ -82,8 +80,9 @@ export class StatisticComponent implements OnInit {
|
||||||
deleteCampaign(campaign) {
|
deleteCampaign(campaign) {
|
||||||
this.translate.get('stats.campaign.manage.delete.confirm', {title: campaign.title}).subscribe((confirmQuestion: string) => {
|
this.translate.get('stats.campaign.manage.delete.confirm', {title: campaign.title}).subscribe((confirmQuestion: string) => {
|
||||||
if (confirm(confirmQuestion)) {
|
if (confirm(confirmQuestion)) {
|
||||||
this.campaignService.deleteCampaign(campaign)
|
this.campaignService.deleteCampaign(campaign._id)
|
||||||
.subscribe((res) => {
|
.subscribe((res) => {
|
||||||
|
this.campaigns.splice(this.campaigns.indexOf(campaign), 1);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
id="campaign"
|
id="campaign"
|
||||||
[(ngModel)]="war.campaign"
|
[(ngModel)]="war.campaign"
|
||||||
required>
|
required>
|
||||||
<option *ngFor="let campaign of campaignService.campaigns$ | async" [ngValue]="campaign._id">
|
<option *ngFor="let campaign of campaignService.campaigns" [ngValue]="campaign._id">
|
||||||
{{campaign.title}}
|
{{campaign.title}}
|
||||||
</option>
|
</option>
|
||||||
</select>
|
</select>
|
||||||
|
|
Loading…
Reference in New Issue