Compare commits

..

No commits in common. "da29c39b88711a56809714441050f9de84aaf124" and "6381c1ca86d026f4c0baab720538b33353e1254f" have entirely different histories.

10 changed files with 19 additions and 99 deletions

View File

@ -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":"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}

View File

@ -24,25 +24,6 @@ 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

View File

@ -16,10 +16,12 @@ 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
@ -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) => {
CampaignModel.findByIdAndRemove(req.params.id, (err, item) => {
if (err) {

View File

@ -18,23 +18,14 @@ 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());
}
}

View File

@ -1,6 +1,5 @@
<form #form="ngForm" class="overview">
<h3 *ngIf="campaign._id">Kampagne editieren</h3>
<h3 *ngIf="!campaign._id">Neue Kampagne hinzufügen</h3>
<h3>Kampagne hinzufügen</h3>
<div class="form-group">
<label for="title">Titel</label>

View File

@ -1,7 +1,6 @@
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';
@ -19,31 +18,17 @@ 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 => {
let redirectSuccessUrl = '../overview/';
if (this.campaign._id) {
redirectSuccessUrl = '../' + redirectSuccessUrl
}
this.router.navigate([redirectSuccessUrl + campaign._id], {relativeTo: this.route});
this.router.navigate(['../overview/' + campaign._id], {relativeTo: this.route});
},
error => {
this.error = error._body.error.message;

View File

@ -33,12 +33,7 @@ export const statsRoutes: Routes = [{
outlet: 'right'
},
{
path: 'campaign',
component: CampaignSubmitComponent,
outlet: 'right'
},
{
path: 'campaign/:id',
path: 'new-campaign',
component: CampaignSubmitComponent,
outlet: 'right'
},

View File

@ -46,7 +46,7 @@ export class WarListComponent implements OnInit {
selectNewCampaign() {
this.selectedWarId = null;
this.router.navigate([{outlets: {'right': ['campaign']}}], {relativeTo: this.route});
this.router.navigate([{outlets: {'right': ['new-campaign']}}], {relativeTo: this.route});
}
selectNewWar() {
@ -100,6 +100,6 @@ export class WarListComponent implements OnInit {
}
editCampaign(selectCampaign) {
this.router.navigate([{outlets: {'right': ['campaign', selectCampaign._id]}}], {relativeTo: this.route});
this.router.navigate([{outlets: {'right': ['overview', selectCampaign._id]}}], {relativeTo: this.route});
}
}

View File

@ -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="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
</span>
</div>

View File

@ -18,9 +18,7 @@ export class WarSubmitComponent {
fileList: FileList;
readonly validExtensions = ['.rpt', '.log', '.txt'];
showFileError = false;
showImageError = false;
showErrorLabel = false;
@ -37,13 +35,14 @@ export class WarSubmitComponent {
}
fileChange(event) {
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;
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;
this.fileList = event.target.files;
}
}