Compare commits
No commits in common. "b425617a7d46ee814065980563fbd5449b309b29" and "c9fce51ef60603f3e8b6f0b025364a0aa19ae40c" have entirely different histories.
b425617a7d
...
c9fce51ef6
|
@ -63,21 +63,6 @@ campaigns.route('/')
|
|||
routerHandling.httpMethodNotAllowed
|
||||
);
|
||||
|
||||
campaigns.route('/with/war/:id')
|
||||
.get((req, res, next) => {
|
||||
WarModel.findById(req.params.id, (err, item) => {
|
||||
if (err) {
|
||||
err.status = codes.servererror;
|
||||
return next(err);
|
||||
}
|
||||
return genericGetById({params: {id: item.campaign}}, res, next, CampaignModel);
|
||||
});
|
||||
})
|
||||
|
||||
.all(
|
||||
routerHandling.httpMethodNotAllowed
|
||||
);
|
||||
|
||||
campaigns.route('/:id')
|
||||
.get(idValidator, (req, res, next) => {
|
||||
return genericGetById(req, res, next, CampaignModel);
|
||||
|
|
|
@ -23,6 +23,7 @@ const resourceLocation = require('../middleware/resource-location').resourceLoca
|
|||
const parseWarLog = require('../tools/log-parse-tool');
|
||||
|
||||
// Mongoose Model using mongoDB
|
||||
const CampaignModel = require('../models/campaign');
|
||||
const WarModel = require('../models/war');
|
||||
const PlayerModel = require('../models/player');
|
||||
const LogKillModel = require('../models/logs/kill');
|
||||
|
@ -42,18 +43,36 @@ const wars = new express.Router();
|
|||
// routes **********************
|
||||
wars.route('/')
|
||||
.get((req, res, next) => {
|
||||
const filter = {};
|
||||
if (req.query.campaignId) {
|
||||
filter.campaign = req.query.campaignId;
|
||||
}
|
||||
WarModel.find(filter, {}, {sort: {date: 'desc'}}, (err, wars) => {
|
||||
let result = [];
|
||||
CampaignModel.find({}, {}, {sort: {timestamp: 'desc'}}, (err, campaigns) => {
|
||||
if (err) {
|
||||
err.status = codes.servererror;
|
||||
return next(err);
|
||||
}
|
||||
res.locals.items = wars;
|
||||
res.locals.processed = true;
|
||||
next();
|
||||
if (campaigns) {
|
||||
WarModel.find({}, {}, {sort: {date: 'desc'}}, (err, wars) => {
|
||||
if (err) {
|
||||
err.status = codes.servererror;
|
||||
return next(err);
|
||||
}
|
||||
if (wars) {
|
||||
campaigns.forEach((campaign) => {
|
||||
let entry = {_id: campaign._id, title: campaign.title, wars: []};
|
||||
wars.forEach((war) => {
|
||||
if (String(campaign._id) === String(war.campaign)) {
|
||||
entry.wars.push(war);
|
||||
}
|
||||
});
|
||||
result.push(entry);
|
||||
});
|
||||
res.locals.items = result;
|
||||
}
|
||||
res.locals.processed = true;
|
||||
next();
|
||||
}
|
||||
)
|
||||
;
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import {Observable} from 'rxjs';
|
||||
|
||||
export interface AppUser {
|
||||
_id?: string;
|
||||
username?: string;
|
||||
|
@ -45,7 +43,7 @@ export interface CampaignPlayer {
|
|||
export interface Campaign {
|
||||
_id?: string;
|
||||
title?: string;
|
||||
wars$?: Observable<War[]>;
|
||||
wars?: War[];
|
||||
}
|
||||
|
||||
export interface War {
|
||||
|
|
|
@ -20,18 +20,17 @@ export class CampaignService {
|
|||
|
||||
getAllCampaigns() {
|
||||
return this.http.get(this.config.apiCampaignPath)
|
||||
.map(res => res.json())
|
||||
.do((ranks) => this.campaignStore.dispatch({type: LOAD, data: ranks}));
|
||||
}
|
||||
|
||||
getCampaign(id: string) {
|
||||
return this.http.get(`${this.config.apiCampaignPath}/${id}`)
|
||||
.map(res => res.json());
|
||||
}
|
||||
|
||||
getCampaignByWarId(warId) {
|
||||
return this.http.get(`${this.config.apiCampaignPath}/with/war/${warId}`)
|
||||
.map((res) => res.json());
|
||||
getAllCampaignsWithWars() {
|
||||
this.http.get(this.config.apiWarPath)
|
||||
.map(res => res.json())
|
||||
.do((ranks) => {
|
||||
this.campaignStore.dispatch({type: LOAD, data: ranks});
|
||||
}).subscribe(_ => {
|
||||
});
|
||||
return this.campaigns$;
|
||||
}
|
||||
|
||||
submitCampaign(campaign: Campaign) {
|
||||
|
@ -64,6 +63,13 @@ export class CampaignService {
|
|||
|
||||
deleteCampaign(campaign: Campaign) {
|
||||
return this.http.delete(this.config.apiCampaignPath + '/' + campaign._id)
|
||||
.do(res => this.campaignStore.dispatch({type: REMOVE, data: campaign}));
|
||||
.do(res => {
|
||||
this.campaignStore.dispatch({type: REMOVE, data: campaign});
|
||||
});
|
||||
}
|
||||
|
||||
getCampaign(id: string) {
|
||||
return this.http.get(this.config.apiCampaignPath + '/' + id)
|
||||
.map(res => res.json());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,29 +2,12 @@ import {Injectable} from '@angular/core';
|
|||
import {War} from '../../models/model-interfaces';
|
||||
import {AppConfig} from '../../app.config';
|
||||
import {HttpClient} from '../http-client';
|
||||
import {ADD, EDIT, LOAD, REMOVE, Store} from '../stores/generic-store';
|
||||
import {Observable} from 'rxjs';
|
||||
|
||||
@Injectable()
|
||||
export class WarService {
|
||||
|
||||
wars$: Observable<War[]>;
|
||||
|
||||
warStore = new Store<War>();
|
||||
|
||||
constructor(private http: HttpClient,
|
||||
private config: AppConfig) {
|
||||
this.wars$ = this.warStore.items$;
|
||||
}
|
||||
|
||||
getAllWars(campaignId?: string) {
|
||||
let targetUrl = this.config.apiWarPath;
|
||||
if (campaignId) {
|
||||
targetUrl += `?campaignId=${campaignId}`
|
||||
}
|
||||
return this.http.get(targetUrl)
|
||||
.map(res => res.json())
|
||||
.do((wars) => this.warStore.dispatch({type: LOAD, data: wars}));
|
||||
}
|
||||
|
||||
getWar(warId: string) {
|
||||
|
@ -32,6 +15,7 @@ export class WarService {
|
|||
.map(res => res.json());
|
||||
}
|
||||
|
||||
|
||||
submitWar(war: War, logFile?) {
|
||||
let body;
|
||||
|
||||
|
@ -46,19 +30,17 @@ export class WarService {
|
|||
}
|
||||
|
||||
return this.http.post(this.config.apiWarPath, body)
|
||||
.map(res => res.json())
|
||||
.do((newWar) => this.warStore.dispatch({type: ADD, data: newWar}));
|
||||
.map(res => res.json());
|
||||
}
|
||||
|
||||
deleteWar(id: string) {
|
||||
return this.http.delete(this.config.apiWarPath + '/' + id)
|
||||
.map(res => res.json());
|
||||
}
|
||||
|
||||
updateWar(war: War) {
|
||||
return this.http.patch(this.config.apiWarPath + '/' + war._id, war)
|
||||
.map(res => res.json())
|
||||
.do((updatedWar) => this.warStore.dispatch({type: EDIT, data: updatedWar}));
|
||||
}
|
||||
|
||||
deleteWar(war: War) {
|
||||
return this.http.delete(this.config.apiWarPath + '/' + war._id)
|
||||
.do((emptyRes) => this.warStore.dispatch({type: REMOVE, data: war}));
|
||||
.map(res => res.json());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
</mat-button-toggle-group>
|
||||
</div>
|
||||
|
||||
<div class="fade-in" *ngIf="initialized">
|
||||
<div class="fade-in">
|
||||
<div class="slide-chart-container">
|
||||
<ngx-charts-line-chart
|
||||
[scheme]="colorScheme"
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
import {Component, OnInit} from '@angular/core';
|
||||
import {Component, Input, OnInit} from '@angular/core';
|
||||
import {ActivatedRoute} from '@angular/router';
|
||||
import {CampaignService} from '../../../services/logs/campaign.service';
|
||||
import {ChartUtils} from '../../../utils/chart-utils';
|
||||
import {Fraction} from '../../../utils/fraction.enum';
|
||||
import {WarService} from '../../../services/logs/war.service';
|
||||
|
||||
|
||||
@Component({
|
||||
|
@ -13,9 +12,10 @@ import {WarService} from '../../../services/logs/war.service';
|
|||
})
|
||||
export class StatisticOverviewComponent implements OnInit {
|
||||
|
||||
id: string;
|
||||
@Input() campaigns;
|
||||
|
||||
initialized = false;
|
||||
id = '';
|
||||
title = '';
|
||||
|
||||
pointData: any[] = [];
|
||||
pointSumData: any[] = [];
|
||||
|
@ -38,8 +38,7 @@ export class StatisticOverviewComponent implements OnInit {
|
|||
timeline = false;
|
||||
|
||||
constructor(private route: ActivatedRoute,
|
||||
private campaignService: CampaignService,
|
||||
private warService: WarService) {
|
||||
private campaignService: CampaignService) {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
|
@ -47,21 +46,26 @@ export class StatisticOverviewComponent implements OnInit {
|
|||
.map(params => params['id'])
|
||||
.subscribe((id) => {
|
||||
this.id = id;
|
||||
this.initWars();
|
||||
this.campaignService.getAllCampaignsWithWars().subscribe(campaigns => {
|
||||
this.initWars(campaigns);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
initWars() {
|
||||
if (this.id === 'all') {
|
||||
this.warService.getAllWars().subscribe((wars) => {
|
||||
initWars(campaigns) {
|
||||
let wars = [];
|
||||
let itemsProcessed = 0;
|
||||
campaigns = campaigns.filter(campaign => this.id === 'all' || campaign._id === this.id);
|
||||
campaigns.forEach(campaign => {
|
||||
wars = wars.concat(campaign.wars);
|
||||
itemsProcessed++;
|
||||
if (itemsProcessed === campaigns.length) {
|
||||
if (this.id === 'all') {
|
||||
this.timeline = true;
|
||||
}
|
||||
this.initChart(wars);
|
||||
});
|
||||
this.timeline = true;
|
||||
} else {
|
||||
this.warService.wars$.subscribe((wars) => {
|
||||
this.initChart(wars);
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
goToSlide(index) {
|
||||
|
@ -133,9 +137,5 @@ export class StatisticOverviewComponent implements OnInit {
|
|||
this.goToSlide(1);
|
||||
}
|
||||
Object.assign(this, this.currentData);
|
||||
|
||||
setTimeout(() => {
|
||||
this.initialized = true;
|
||||
}, 250);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import {CampaignService} from '../services/logs/campaign.service';
|
|||
import {ActivatedRoute, Router} from '@angular/router';
|
||||
import {TranslateService} from '@ngx-translate/core';
|
||||
import {SettingsService} from '../services/settings.service';
|
||||
import {WarService} from '../services/logs/war.service';
|
||||
|
||||
@Component({
|
||||
selector: 'cc-stats',
|
||||
|
@ -13,14 +12,13 @@ import {WarService} from '../services/logs/war.service';
|
|||
})
|
||||
export class StatisticComponent implements OnInit {
|
||||
|
||||
selectedCampaign: Campaign = {};
|
||||
selectedCampaign: Campaign;
|
||||
|
||||
campaigns: Campaign[] = [];
|
||||
|
||||
collapsed = false;
|
||||
|
||||
constructor(private campaignService: CampaignService,
|
||||
private warService: WarService,
|
||||
private router: Router,
|
||||
private route: ActivatedRoute,
|
||||
private translate: TranslateService,
|
||||
|
@ -29,15 +27,18 @@ export class StatisticComponent implements OnInit {
|
|||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.campaignService.getAllCampaigns()
|
||||
.filter(campaigns => campaigns.length !== 0)
|
||||
.subscribe((campaigns) => {
|
||||
this.campaigns = campaigns;
|
||||
this.resolveCampaignFromUrl();
|
||||
});
|
||||
this.campaignService.getAllCampaignsWithWars().subscribe((campaigns) => {
|
||||
this.campaigns = campaigns;
|
||||
this.selectedCampaign = this.resolveCampaignFromUrl();
|
||||
this.switchCampaign(this.selectedCampaign);
|
||||
});
|
||||
}
|
||||
|
||||
resolveCampaignFromUrl() {
|
||||
if (this.campaigns.length === 0) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const url = this.router.url;
|
||||
|
||||
const idFetchPattern = /right:.*\/(.*)\)$/;
|
||||
|
@ -45,33 +46,25 @@ export class StatisticComponent implements OnInit {
|
|||
if (url.includes('right:overview') || url.includes('right:highscore')) {
|
||||
const id = idFetchPattern.exec(url)[1];
|
||||
if (id === 'all') {
|
||||
this.switchCampaign({_id: id});
|
||||
return {_id: id}
|
||||
}
|
||||
const filteredCampaigns = this.campaigns.filter(c => c._id === id);
|
||||
if (filteredCampaigns.length === 1) {
|
||||
this.switchCampaign(filteredCampaigns[0]);
|
||||
return filteredCampaigns[0];
|
||||
}
|
||||
} else if (url.includes('right:war')) {
|
||||
const id = idFetchPattern.exec(url)[1];
|
||||
console.log(id)
|
||||
this.campaignService.getCampaignByWarId(id).subscribe((campaign) => {
|
||||
this.switchCampaign(campaign);
|
||||
});
|
||||
} else {
|
||||
this.switchCampaign(this.campaigns[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) {
|
||||
if (campaign._id !== 'all') {
|
||||
campaign.wars$ = this.warService.wars$;
|
||||
this.warService.getAllWars(campaign._id).subscribe((wars) => {
|
||||
this.selectedCampaign = campaign;
|
||||
});
|
||||
} else {
|
||||
this.selectedCampaign = campaign;
|
||||
}
|
||||
|
||||
this.selectedCampaign = campaign;
|
||||
if (campaign._id === 'all' || this.router.url.includes('/overview/all')) {
|
||||
setTimeout(_ => {
|
||||
window.dispatchEvent(new Event('resize'));
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
</div>
|
||||
|
||||
<div class="battle-list">
|
||||
<div *ngFor="let war of campaign.wars$ | async">
|
||||
<div *ngFor="let war of campaign.wars">
|
||||
<cc-war-item
|
||||
[war]="war"
|
||||
(warEdit)="editWar($event)"
|
||||
|
|
|
@ -107,11 +107,12 @@ export class WarListComponent implements OnChanges {
|
|||
this.translate.get('stats.sidebar.battle.manage.delete.confirm', {title: war.title})
|
||||
.subscribe((confirmQuestion: string) => {
|
||||
if (confirm(confirmQuestion)) {
|
||||
this.warService.deleteWar(war)
|
||||
this.warService.deleteWar(war._id)
|
||||
.subscribe((res) => {
|
||||
if (this.selectedWarId === war._id) {
|
||||
this.selectOverview('all');
|
||||
}
|
||||
this.campaign.wars.splice(this.campaign.wars.indexOf(war), 1);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -88,7 +88,7 @@
|
|||
<button id="save"
|
||||
type="submit"
|
||||
*ngIf="!loading"
|
||||
(click)="submitWar()"
|
||||
(click)="war._id ? editWar() : saveWar()"
|
||||
class="btn btn-default"
|
||||
[disabled]="!form.valid">
|
||||
{{'stats.war.submit.button.submit' | translate}}
|
||||
|
|
|
@ -61,39 +61,29 @@ export class WarSubmitComponent {
|
|||
}
|
||||
}
|
||||
|
||||
submitWar() {
|
||||
if (this.war._id) {
|
||||
this.warService.updateWar(this.war).subscribe((updatedWar) => {
|
||||
this.router.navigate(['../../war/' + updatedWar._id], {relativeTo: this.route});
|
||||
},
|
||||
(error) => {
|
||||
const errorMsg = JSON.parse(error._body).error.message;
|
||||
this.snackBarService.showError('Error: '.concat(errorMsg), 15000);
|
||||
}
|
||||
);
|
||||
} else {
|
||||
if (!this.fileList) {
|
||||
this.translate.get('stats.war.submit.logfile').subscribe((fieldNameLogfile) => {
|
||||
this.translate.get('public.error.message.required',
|
||||
{fieldName: fieldNameLogfile}).subscribe((message) => {
|
||||
this.snackBarService.showError(message, 4000);
|
||||
})
|
||||
saveWar() {
|
||||
if (!this.fileList) {
|
||||
this.translate.get('stats.war.submit.logfile').subscribe((fieldNameLogfile) => {
|
||||
this.translate.get('public.error.message.required',
|
||||
{fieldName: fieldNameLogfile}).subscribe((message) => {
|
||||
this.snackBarService.showError(message, 4000);
|
||||
})
|
||||
}
|
||||
const file: File = this.fileList[0];
|
||||
this.loading = true;
|
||||
this.spinnerService.activate();
|
||||
this.warService.submitWar(this.war, file)
|
||||
.subscribe(war => {
|
||||
this.router.navigate(['../war/' + war._id], {relativeTo: this.route});
|
||||
},
|
||||
error => {
|
||||
this.spinnerService.deactivate();
|
||||
this.loading = false;
|
||||
const errorMsg = JSON.parse(error._body).error.message;
|
||||
this.snackBarService.showError('Error: '.concat(errorMsg), 15000);
|
||||
});
|
||||
})
|
||||
}
|
||||
const file: File = this.fileList[0];
|
||||
this.loading = true;
|
||||
this.spinnerService.activate();
|
||||
|
||||
this.warService.submitWar(this.war, file)
|
||||
.subscribe(war => {
|
||||
this.router.navigate(['../war/' + war._id], {relativeTo: this.route});
|
||||
},
|
||||
error => {
|
||||
this.spinnerService.deactivate();
|
||||
this.loading = false;
|
||||
const errorMsg = JSON.parse(error._body).error.message;
|
||||
this.snackBarService.showError('Error: '.concat(errorMsg), 15000);
|
||||
});
|
||||
}
|
||||
|
||||
cancel() {
|
||||
|
|
Loading…
Reference in New Issue