Compare commits
4 Commits
6381c1ca86
...
da29c39b88
Author | SHA1 | Date |
---|---|---|
Florian Hartwich | da29c39b88 | |
Florian Hartwich | 8600eb5f3c | |
Florian Hartwich | b40c664bce | |
Florian Hartwich | 3754974bfb |
|
@ -1,2 +1,3 @@
|
|||
{"_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":"5abd55ea9e32a76afef777d6"},"title":"Placeholder","timestamp":{"$date":"2018-03-30T21:08:58.123Z"},"updatedAt":{"$date":"2018-03-30T21:08:58.123Z"},"__v":0}
|
||||
|
|
|
@ -24,6 +24,25 @@ Create a new campaign
|
|||
|
||||
+ 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 a campaign
|
||||
|
|
|
@ -16,12 +16,10 @@ const idValidator = require('../middleware/validators').idValidator;
|
|||
const CampaignModel = require('../models/campaign');
|
||||
const WarModel = require('../models/war');
|
||||
|
||||
|
||||
const campaigns = new express.Router();
|
||||
|
||||
// routes **********************
|
||||
campaigns.route('/')
|
||||
|
||||
.post(apiAuthenticationMiddleware, checkMT, (req, res, next) => {
|
||||
const campaign = new CampaignModel(req.body);
|
||||
// timestamp and default are set automatically by Mongoose Schema Validation
|
||||
|
@ -57,6 +55,37 @@ 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) => {
|
||||
CampaignModel.findByIdAndRemove(req.params.id, (err, item) => {
|
||||
if (err) {
|
||||
|
@ -67,7 +96,7 @@ campaigns.route('/:id')
|
|||
err.status = codes.notfound;
|
||||
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!!!
|
||||
res.locals.processed = true;
|
||||
next();
|
||||
|
|
|
@ -18,14 +18,23 @@ export class CampaignService {
|
|||
}
|
||||
|
||||
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)
|
||||
.map(res => res.json());
|
||||
}
|
||||
}
|
||||
|
||||
deleteCampaign(id: string) {
|
||||
return this.http.delete(this.config.apiCampaignPath + '/' + id)
|
||||
.map(res => res.json());
|
||||
}
|
||||
|
||||
getCampaign(id: string) {
|
||||
return this.http.get(this.config.apiCampaignPath + '/' + id)
|
||||
.map(res => res.json());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<form #form="ngForm" class="overview">
|
||||
<h3>Kampagne hinzufügen</h3>
|
||||
<h3 *ngIf="campaign._id">Kampagne editieren</h3>
|
||||
<h3 *ngIf="!campaign._id">Neue Kampagne hinzufügen</h3>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="title">Titel</label>
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import {Component, ViewChild} from '@angular/core';
|
||||
import {ActivatedRoute, Router} from '@angular/router';
|
||||
import {NgForm} from '@angular/forms';
|
||||
import {Subscription} from 'rxjs/Subscription';
|
||||
import {Campaign} from '../../models/model-interfaces';
|
||||
import {CampaignService} from '../../services/logs/campaign.service';
|
||||
|
||||
|
@ -18,17 +19,31 @@ export class CampaignSubmitComponent {
|
|||
|
||||
error;
|
||||
|
||||
subscription: Subscription;
|
||||
|
||||
@ViewChild(NgForm) form: NgForm;
|
||||
|
||||
constructor(private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
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() {
|
||||
this.campaignService.submitCampaign(this.campaign)
|
||||
.subscribe(campaign => {
|
||||
this.router.navigate(['../overview/' + campaign._id], {relativeTo: this.route});
|
||||
let redirectSuccessUrl = '../overview/';
|
||||
if (this.campaign._id) {
|
||||
redirectSuccessUrl = '../' + redirectSuccessUrl
|
||||
}
|
||||
this.router.navigate([redirectSuccessUrl + campaign._id], {relativeTo: this.route});
|
||||
},
|
||||
error => {
|
||||
this.error = error._body.error.message;
|
||||
|
|
|
@ -33,7 +33,12 @@ export const statsRoutes: Routes = [{
|
|||
outlet: 'right'
|
||||
},
|
||||
{
|
||||
path: 'new-campaign',
|
||||
path: 'campaign',
|
||||
component: CampaignSubmitComponent,
|
||||
outlet: 'right'
|
||||
},
|
||||
{
|
||||
path: 'campaign/:id',
|
||||
component: CampaignSubmitComponent,
|
||||
outlet: 'right'
|
||||
},
|
||||
|
|
|
@ -46,7 +46,7 @@ export class WarListComponent implements OnInit {
|
|||
|
||||
selectNewCampaign() {
|
||||
this.selectedWarId = null;
|
||||
this.router.navigate([{outlets: {'right': ['new-campaign']}}], {relativeTo: this.route});
|
||||
this.router.navigate([{outlets: {'right': ['campaign']}}], {relativeTo: this.route});
|
||||
}
|
||||
|
||||
selectNewWar() {
|
||||
|
@ -100,6 +100,6 @@ export class WarListComponent implements OnInit {
|
|||
}
|
||||
|
||||
editCampaign(selectCampaign) {
|
||||
this.router.navigate([{outlets: {'right': ['overview', selectCampaign._id]}}], {relativeTo: this.route});
|
||||
this.router.navigate([{outlets: {'right': ['campaign', selectCampaign._id]}}], {relativeTo: this.route});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
<label for="log">Logfile</label>
|
||||
<input id="log" name="log" class="ui-button form-control" type="file"
|
||||
(change)="fileChange($event)">
|
||||
<span class="label label-bg label-danger center-block" style="font-size:small" *ngIf="showImageError">
|
||||
<span class="label label-bg label-danger center-block" style="font-size:small" *ngIf="showFileError">
|
||||
Logfile muss im Format RPT, LOG oder TXT vorliegen
|
||||
</span>
|
||||
</div>
|
||||
|
|
|
@ -18,7 +18,9 @@ export class WarSubmitComponent {
|
|||
|
||||
fileList: FileList;
|
||||
|
||||
showImageError = false;
|
||||
readonly validExtensions = ['.rpt', '.log', '.txt'];
|
||||
|
||||
showFileError = false;
|
||||
|
||||
showErrorLabel = false;
|
||||
|
||||
|
@ -35,14 +37,13 @@ export class WarSubmitComponent {
|
|||
}
|
||||
|
||||
fileChange(event) {
|
||||
if (!event.target.files[0].name.endsWith('.rpt')
|
||||
&& !event.target.files[0].name.endsWith('.log')
|
||||
&& !event.target.files[0].name.endsWith('.txt')) {
|
||||
this.showImageError = true;
|
||||
this.fileList = undefined;
|
||||
} else {
|
||||
this.showImageError = false;
|
||||
if (this.validExtensions.filter(ext => event.target.files[0] &&
|
||||
event.target.files[0].name.endsWith(ext)).length == 1) {
|
||||
this.showFileError = false;
|
||||
this.fileList = event.target.files;
|
||||
} else {
|
||||
this.showFileError = true;
|
||||
this.fileList = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue