Compare commits
No commits in common. "da29c39b88711a56809714441050f9de84aaf124" and "6381c1ca86d026f4c0baab720538b33353e1254f" have entirely different histories.
da29c39b88
...
6381c1ca86
|
@ -1,3 +1,2 @@
|
||||||
{"_id":{"$oid":"5abd55ea9e30a76bfef747d6"},"title":"Ein Kessel Buntes","timestamp":{"$date":"2018-03-29T21:08:58.123Z"},"updatedAt":{"$date":"2018-03-29T21:08:58.123Z"},"__v":0}
|
{"_id":{"$oid":"5abd55ea9e30a76bfef747d6"},"title":"Ein Kessel Buntes","timestamp":{"$date":"2018-03-29T21:08:58.123Z"},"updatedAt":{"$date":"2018-03-29T21:08:58.123Z"},"__v":0}
|
||||||
{"_id":{"$oid":"5abd58989e30a76bfef747e6"},"title":"This Is The End","timestamp":{"$date":"2018-03-29T21:20:24.558Z"},"updatedAt":{"$date":"2018-03-29T21:20:24.558Z"},"__v":0}
|
{"_id":{"$oid":"5abd58989e30a76bfef747e6"},"title":"This Is The End","timestamp":{"$date":"2018-03-29T21:20:24.558Z"},"updatedAt":{"$date":"2018-03-29T21:20:24.558Z"},"__v":0}
|
||||||
{"_id":{"$oid":"5abd55ea9e32a76afef777d6"},"title":"Placeholder","timestamp":{"$date":"2018-03-30T21:08:58.123Z"},"updatedAt":{"$date":"2018-03-30T21:08:58.123Z"},"__v":0}
|
|
||||||
|
|
|
@ -24,25 +24,6 @@ Create a new campaign
|
||||||
|
|
||||||
+ Attributes (Campaign, fixed-type)
|
+ Attributes (Campaign, fixed-type)
|
||||||
|
|
||||||
### Update Campaign [PATCH /campaigns/{id}]
|
|
||||||
|
|
||||||
Update a campaign, identified by its id
|
|
||||||
|
|
||||||
**Permission: 3**
|
|
||||||
|
|
||||||
+ Parameters
|
|
||||||
+ id: `5abd55ea9e32a76afef777d6` (string, required) - unique id of campaign
|
|
||||||
|
|
||||||
+ Request (application/json)
|
|
||||||
|
|
||||||
+ Attributes
|
|
||||||
+ _id: `5abd55ea9e32a76afef777d6` (string, required) - unique id of campaign
|
|
||||||
+ title: `Operation Pandora` (string, optional) - display name of the campaign
|
|
||||||
|
|
||||||
+ Response 200 (application/json; charset=utf-8)
|
|
||||||
|
|
||||||
+ Attributes (Campaign, fixed-type)
|
|
||||||
|
|
||||||
### Delete Campaign [DELETE /campaigns/{id}]
|
### Delete Campaign [DELETE /campaigns/{id}]
|
||||||
|
|
||||||
Delete a campaign
|
Delete a campaign
|
||||||
|
|
|
@ -16,10 +16,12 @@ const idValidator = require('../middleware/validators').idValidator;
|
||||||
const CampaignModel = require('../models/campaign');
|
const CampaignModel = require('../models/campaign');
|
||||||
const WarModel = require('../models/war');
|
const WarModel = require('../models/war');
|
||||||
|
|
||||||
|
|
||||||
const campaigns = new express.Router();
|
const campaigns = new express.Router();
|
||||||
|
|
||||||
// routes **********************
|
// routes **********************
|
||||||
campaigns.route('/')
|
campaigns.route('/')
|
||||||
|
|
||||||
.post(apiAuthenticationMiddleware, checkMT, (req, res, next) => {
|
.post(apiAuthenticationMiddleware, checkMT, (req, res, next) => {
|
||||||
const campaign = new CampaignModel(req.body);
|
const campaign = new CampaignModel(req.body);
|
||||||
// timestamp and default are set automatically by Mongoose Schema Validation
|
// timestamp and default are set automatically by Mongoose Schema Validation
|
||||||
|
@ -55,37 +57,6 @@ campaigns.route('/:id')
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
.patch(apiAuthenticationMiddleware, checkMT, (req, res, next) => {
|
|
||||||
if (!req.body || (req.body._id && req.body._id !== req.params.id)) {
|
|
||||||
// little bit different as in PUT. :id does not need to be in data, but if the _id and url id must match
|
|
||||||
const err = new Error('id of PATCH resource and send JSON body are not equal ' + req.params.id + ' ' +
|
|
||||||
req.body._id);
|
|
||||||
err.status = codes.notfound;
|
|
||||||
next(err);
|
|
||||||
return; // prevent node to process this function further after next() has finished.
|
|
||||||
}
|
|
||||||
|
|
||||||
req.body.updatedAt = new Date();
|
|
||||||
req.body.$inc = { __v: 1 };
|
|
||||||
if (req.body.hasOwnProperty('__v')) {
|
|
||||||
delete req.body.__v;
|
|
||||||
}
|
|
||||||
|
|
||||||
// PATCH is easier with mongoose than PUT. You simply update by all data that comes from outside. no need to
|
|
||||||
// reset attributes that are missing.
|
|
||||||
CampaignModel.findByIdAndUpdate(req.params.id, req.body, { new: true }, (err, item) => {
|
|
||||||
if (err) {
|
|
||||||
err.status = codes.wrongrequest;
|
|
||||||
} else if (!item) {
|
|
||||||
err = new Error('item not found');
|
|
||||||
err.status = codes.notfound;
|
|
||||||
} else {
|
|
||||||
res.locals.items = item;
|
|
||||||
}
|
|
||||||
next(err);
|
|
||||||
});
|
|
||||||
})
|
|
||||||
|
|
||||||
.delete((req, res, next) => {
|
.delete((req, res, next) => {
|
||||||
CampaignModel.findByIdAndRemove(req.params.id, (err, item) => {
|
CampaignModel.findByIdAndRemove(req.params.id, (err, item) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
@ -96,7 +67,7 @@ campaigns.route('/:id')
|
||||||
err.status = codes.notfound;
|
err.status = codes.notfound;
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
WarModel.find({ campaign: req.params.id }).remove().exec();
|
WarModel.find({campaign: req.params.id}).remove().exec();
|
||||||
// TODO: remove all the war logs from fs here!!!
|
// TODO: remove all the war logs from fs here!!!
|
||||||
res.locals.processed = true;
|
res.locals.processed = true;
|
||||||
next();
|
next();
|
||||||
|
|
|
@ -18,23 +18,14 @@ export class CampaignService {
|
||||||
}
|
}
|
||||||
|
|
||||||
submitCampaign(campaign: Campaign) {
|
submitCampaign(campaign: Campaign) {
|
||||||
if (campaign._id) {
|
|
||||||
return this.http.patch(this.config.apiCampaignPath + '/' + campaign._id, campaign)
|
|
||||||
.map(res => res.json());
|
|
||||||
} else {
|
|
||||||
return this.http.post(this.config.apiCampaignPath, campaign)
|
return this.http.post(this.config.apiCampaignPath, campaign)
|
||||||
.map(res => res.json());
|
.map(res => res.json());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
deleteCampaign(id: string) {
|
deleteCampaign(id: string) {
|
||||||
return this.http.delete(this.config.apiCampaignPath + '/' + id)
|
return this.http.delete(this.config.apiCampaignPath + '/' + id)
|
||||||
.map(res => res.json());
|
.map(res => res.json());
|
||||||
}
|
}
|
||||||
|
|
||||||
getCampaign(id: string) {
|
|
||||||
return this.http.get(this.config.apiCampaignPath + '/' + id)
|
|
||||||
.map(res => res.json());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
<form #form="ngForm" class="overview">
|
<form #form="ngForm" class="overview">
|
||||||
<h3 *ngIf="campaign._id">Kampagne editieren</h3>
|
<h3>Kampagne hinzufügen</h3>
|
||||||
<h3 *ngIf="!campaign._id">Neue Kampagne hinzufügen</h3>
|
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="title">Titel</label>
|
<label for="title">Titel</label>
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import {Component, ViewChild} from '@angular/core';
|
import {Component, ViewChild} from '@angular/core';
|
||||||
import {ActivatedRoute, Router} from '@angular/router';
|
import {ActivatedRoute, Router} from '@angular/router';
|
||||||
import {NgForm} from '@angular/forms';
|
import {NgForm} from '@angular/forms';
|
||||||
import {Subscription} from 'rxjs/Subscription';
|
|
||||||
import {Campaign} from '../../models/model-interfaces';
|
import {Campaign} from '../../models/model-interfaces';
|
||||||
import {CampaignService} from '../../services/logs/campaign.service';
|
import {CampaignService} from '../../services/logs/campaign.service';
|
||||||
|
|
||||||
|
@ -19,31 +18,17 @@ export class CampaignSubmitComponent {
|
||||||
|
|
||||||
error;
|
error;
|
||||||
|
|
||||||
subscription: Subscription;
|
|
||||||
|
|
||||||
@ViewChild(NgForm) form: NgForm;
|
@ViewChild(NgForm) form: NgForm;
|
||||||
|
|
||||||
constructor(private route: ActivatedRoute,
|
constructor(private route: ActivatedRoute,
|
||||||
private router: Router,
|
private router: Router,
|
||||||
private campaignService: CampaignService) {
|
private campaignService: CampaignService) {
|
||||||
|
|
||||||
this.subscription = this.route.params
|
|
||||||
.map(params => params['id'])
|
|
||||||
.filter(id => id !== undefined)
|
|
||||||
.flatMap(id => this.campaignService.getCampaign(id))
|
|
||||||
.subscribe(campaign => {
|
|
||||||
this.campaign = campaign;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
saveCampaign() {
|
saveCampaign() {
|
||||||
this.campaignService.submitCampaign(this.campaign)
|
this.campaignService.submitCampaign(this.campaign)
|
||||||
.subscribe(campaign => {
|
.subscribe(campaign => {
|
||||||
let redirectSuccessUrl = '../overview/';
|
this.router.navigate(['../overview/' + campaign._id], {relativeTo: this.route});
|
||||||
if (this.campaign._id) {
|
|
||||||
redirectSuccessUrl = '../' + redirectSuccessUrl
|
|
||||||
}
|
|
||||||
this.router.navigate([redirectSuccessUrl + campaign._id], {relativeTo: this.route});
|
|
||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
this.error = error._body.error.message;
|
this.error = error._body.error.message;
|
||||||
|
|
|
@ -33,12 +33,7 @@ export const statsRoutes: Routes = [{
|
||||||
outlet: 'right'
|
outlet: 'right'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'campaign',
|
path: 'new-campaign',
|
||||||
component: CampaignSubmitComponent,
|
|
||||||
outlet: 'right'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: 'campaign/:id',
|
|
||||||
component: CampaignSubmitComponent,
|
component: CampaignSubmitComponent,
|
||||||
outlet: 'right'
|
outlet: 'right'
|
||||||
},
|
},
|
||||||
|
|
|
@ -46,7 +46,7 @@ export class WarListComponent implements OnInit {
|
||||||
|
|
||||||
selectNewCampaign() {
|
selectNewCampaign() {
|
||||||
this.selectedWarId = null;
|
this.selectedWarId = null;
|
||||||
this.router.navigate([{outlets: {'right': ['campaign']}}], {relativeTo: this.route});
|
this.router.navigate([{outlets: {'right': ['new-campaign']}}], {relativeTo: this.route});
|
||||||
}
|
}
|
||||||
|
|
||||||
selectNewWar() {
|
selectNewWar() {
|
||||||
|
@ -100,6 +100,6 @@ export class WarListComponent implements OnInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
editCampaign(selectCampaign) {
|
editCampaign(selectCampaign) {
|
||||||
this.router.navigate([{outlets: {'right': ['campaign', selectCampaign._id]}}], {relativeTo: this.route});
|
this.router.navigate([{outlets: {'right': ['overview', selectCampaign._id]}}], {relativeTo: this.route});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
<label for="log">Logfile</label>
|
<label for="log">Logfile</label>
|
||||||
<input id="log" name="log" class="ui-button form-control" type="file"
|
<input id="log" name="log" class="ui-button form-control" type="file"
|
||||||
(change)="fileChange($event)">
|
(change)="fileChange($event)">
|
||||||
<span class="label label-bg label-danger center-block" style="font-size:small" *ngIf="showFileError">
|
<span class="label label-bg label-danger center-block" style="font-size:small" *ngIf="showImageError">
|
||||||
Logfile muss im Format RPT, LOG oder TXT vorliegen
|
Logfile muss im Format RPT, LOG oder TXT vorliegen
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -18,9 +18,7 @@ export class WarSubmitComponent {
|
||||||
|
|
||||||
fileList: FileList;
|
fileList: FileList;
|
||||||
|
|
||||||
readonly validExtensions = ['.rpt', '.log', '.txt'];
|
showImageError = false;
|
||||||
|
|
||||||
showFileError = false;
|
|
||||||
|
|
||||||
showErrorLabel = false;
|
showErrorLabel = false;
|
||||||
|
|
||||||
|
@ -37,13 +35,14 @@ export class WarSubmitComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
fileChange(event) {
|
fileChange(event) {
|
||||||
if (this.validExtensions.filter(ext => event.target.files[0] &&
|
if (!event.target.files[0].name.endsWith('.rpt')
|
||||||
event.target.files[0].name.endsWith(ext)).length == 1) {
|
&& !event.target.files[0].name.endsWith('.log')
|
||||||
this.showFileError = false;
|
&& !event.target.files[0].name.endsWith('.txt')) {
|
||||||
this.fileList = event.target.files;
|
this.showImageError = true;
|
||||||
} else {
|
|
||||||
this.showFileError = true;
|
|
||||||
this.fileList = undefined;
|
this.fileList = undefined;
|
||||||
|
} else {
|
||||||
|
this.showImageError = false;
|
||||||
|
this.fileList = event.target.files;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue