Add feature statistic overview #2

Merged
hardi merged 1 commits from feature/statistic-charts into master 2017-07-30 10:58:46 +02:00
4 changed files with 33 additions and 14 deletions

View File

@ -28,13 +28,13 @@ const WarSchema = new Schema({
type: Number,
get: v => Math.round(v),
set: v => Math.round(v),
required: true
default: 0
},
playersOpfor: {
type: Number,
get: v => Math.round(v),
set: v => Math.round(v),
required: true
default: 0
},
bestPlayerId: {
type: mongoose.Schema.Types.ObjectId,

View File

@ -51,11 +51,11 @@ wars.route('/')
const war = new WarModel(body);
if (req.file) {
war.save((err, item) => {
war.save((err, war) => {
if (err) {
return next(err);
}
const folderName = __dirname + '/../resource/logs/' + item._id;
const folderName = __dirname + '/../resource/logs/' + war._id;
mkdirp(folderName, function (err) {
if (err) {
return next(err);
@ -65,7 +65,7 @@ wars.route('/')
return next(err);
}
//TODO: combine run and clean in one script, so log file gets touched only once
exec(__dirname + '/../war-parser/run.sh ' + folderName + ' ' + item._id, (error, stdout) => {
exec(__dirname + '/../war-parser/run.sh ' + folderName + ' ' + war._id, (error, stdout) => {
if (error) {
return next(error);
}
@ -74,14 +74,33 @@ wars.route('/')
return next(error);
}
let obj = JSON.parse(`${stdout}`);
for (let i = 0; i < obj.length; i++) {
if (obj[i].fraction === 'BLUFOR') {
war.playersBlufor++;
} else {
war.playersOpfor++;
}
}
WarModel.findByIdAndUpdate(war._id, war, {new: true}, (err, item) => {
if (err) {
err.status = codes.wrongrequest;
}
else if (!item) {
err = new Error("item not found");
err.status = codes.notfound;
}
else {
PlayerModel.create(obj, function (err) {
if (err) {
return next(err);
}
res.status(codes.created);
res.locals.items = item;
res.locals.items = war;
return next();
});
}
})
});
});
});

View File

@ -24,7 +24,7 @@
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true"
aria-expanded="false">
Schlacht Statistik
Statistik
<span class="caret"></span>
</a>
<ul class="dropdown-menu scrollable-menu">

View File

@ -55,7 +55,7 @@ export class WarSubmitComponent {
this.router.navigate([war._id], {relativeTo: this.route});
},
error => {
this.error = error._body;
this.error = error._body.error.message;
this.showErrorLabel = true;
this.loading = false;
});