Add delete war option

pull/1/head
Florian Hartwich 2017-07-14 23:50:58 +02:00
parent 6bf7992f0f
commit 07df5bd4c8
5 changed files with 28 additions and 6 deletions

View File

@ -129,10 +129,12 @@ wars.route('/:id')
WarModel.findByIdAndRemove(req.params.id, (err, item) => {
if (err) {
err.status = codes.wrongrequest;
return next(err);
}
else if (!item) {
err = new Error("item not found");
err.status = codes.notfound;
return next(err);
}
//TODO: add removal of resource files
@ -142,7 +144,7 @@ wars.route('/:id')
// we don't set res.locals.items and thus it will send a 204 (no content) at the end. see last handler user.use(..)
res.locals.processed = true;
next(err); // this works because err is in normal case undefined and that is the same as no parameter
next();
})
})

View File

@ -1,6 +1,6 @@
<h1>Übersicht über alle Spieler, Squads und Armeen</h1>
<div style="width: 1900px; margin-left: 25%">
<div style="width: 1200px; margin-left: 25%">
<div class="div-table" style="width: 490px; float:left">
<h3 class="text-blufor army-head">NATO</h3>

View File

@ -38,5 +38,10 @@ export class WarService {
.map(res => res.json())
}
deleteWar(id: string) {
return this.http.delete(this.config.apiUrl + this.config.apiWarPath + '/' + id)
.map(res => res.json())
}
}

View File

@ -10,8 +10,11 @@
</h3>
<div style="margin-left: 500px; margin-top:1%">
<a class="btn btn-default btn-" style="margin: 20px" target="_blank" href="resource/logs/{{war._id}}/clean.log">Logfile
<a class="btn btn-default" style="margin: 20px" target="_blank" href="resource/logs/{{war._id}}/clean.log">Logfile
anzeigen</a>
<button *ngIf="loginService.hasPermission(3)" class="btn btn-warning" style="margin: 20px" (click)="delete()">
Schlacht löschen
</button>
<form class="form-group">
<label class="radio-inline">
<input type="radio" name="fractSelect"

View File

@ -1,7 +1,8 @@
import {Component} from "@angular/core";
import {Player, War} from "../models/model-interfaces";
import {WarService} from "../services/war-service/war.service";
import {ActivatedRoute} from "@angular/router";
import {ActivatedRoute, Router} from "@angular/router";
import {LoginService} from "../services/login-service/login-service";
@Component({
@ -21,8 +22,10 @@ export class WarDetailComponent {
sortOrder = "desc";
constructor(private route: ActivatedRoute,
private warService: WarService) {
constructor(private router: Router,
private route: ActivatedRoute,
private warService: WarService,
private loginService: LoginService) {
}
ngOnInit() {
@ -46,4 +49,13 @@ export class WarDetailComponent {
}
}
delete() {
if (confirm('Soll die Schlacht "' + this.war.title + '" wirklich gelöscht werden?')) {
this.warService.deleteWar(this.war._id)
.subscribe((res) => {
this.router.navigate(['../..'], {relativeTo: this.route});
})
}
}
}