Add war submit form
parent
4a79cb8c22
commit
6bf7992f0f
|
@ -69,16 +69,14 @@ wars.route('/')
|
|||
if (error) {
|
||||
return next(error);
|
||||
}
|
||||
let obj = JSON.parse(`${stdout}`);
|
||||
console.log(obj);
|
||||
PlayerModel.create(obj, function (err) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
exec(__dirname + '/../war-parser/clean.sh /../' + folderName + ' | tee ' + folderName + '/clean.log', (error) => {
|
||||
if (error) {
|
||||
return next(error);
|
||||
}
|
||||
|
||||
exec(__dirname + '/../war-parser/clean.sh /../' + folderName + ' | tee ' + folderName + '/clean.log', (error) => {
|
||||
if (error) {
|
||||
return next(error);
|
||||
let obj = JSON.parse(`${stdout}`);
|
||||
PlayerModel.create(obj, function (err) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
res.status(codes.created);
|
||||
res.locals.items = item;
|
||||
|
|
|
@ -28,8 +28,13 @@
|
|||
<span class="caret"></span>
|
||||
</a>
|
||||
<ul class="dropdown-menu scrollable-menu">
|
||||
<li *ngIf="loginService.hasPermission(3)">
|
||||
<a routerLink='/cc-wars' class="link">Hinzufügen...</a>
|
||||
</li>
|
||||
<li *ngFor="let war of wars">
|
||||
<a [routerLink]="['/cc-wars/' + war._id]">{{war.title}} <small>{{war.date | date: 'dd.MM.yy'}}</small></a>
|
||||
<a [routerLink]="['/cc-wars/' + war._id]">{{war.title}}
|
||||
<small>{{war.date | date: 'dd.MM.yy'}}</small>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
|
@ -45,7 +50,8 @@
|
|||
<li *ngIf="loginService.hasPermission(2)" routerLinkActive="active">
|
||||
<a routerLink='/cc-ranks' class="link">Ränge</a>
|
||||
</li>
|
||||
<li *ngIf="loginService.hasPermission(1) && !loginService.hasPermission(2) && loginService.hasSquad()" class="dropdown">
|
||||
<li *ngIf="loginService.hasPermission(1) && !loginService.hasPermission(2) && loginService.hasSquad()"
|
||||
class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true"
|
||||
aria-expanded="false">
|
||||
Beantragen
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import {RouterModule, Routes} from "@angular/router";
|
||||
import {LoginComponent} from "./login/index";
|
||||
import {NotFoundComponent} from "./not-found/not-found.component";
|
||||
import {LoginGuardAdmin, LoginGuardHL, LoginGuardSQL} from "./login/login.guard";
|
||||
import {LoginGuardAdmin, LoginGuardHL, LoginGuardMT, LoginGuardSQL} from "./login/login.guard";
|
||||
import {usersRoutes, usersRoutingComponents} from "./users/users.routing";
|
||||
import {squadsRoutes, squadsRoutingComponents} from "./squads/squads.routing";
|
||||
import {decorationsRoutes, decorationsRoutingComponents} from "./decorations/decoration.routing";
|
||||
|
@ -13,7 +13,7 @@ import {RequestAwardComponent} from "./request/award/req-award.component";
|
|||
import {RequestPromotionComponent} from "./request/promotion/req-promotion.component";
|
||||
import {ConfirmPromotionComponent} from "./request/confirm-promotion/confirm-promotion.component";
|
||||
import {ConfirmAwardComponent} from "./request/confirm-award/confirm-award.component";
|
||||
import {WarDetailComponent} from "./wars/war-detail.component";
|
||||
import {warRoutes, warsRoutingComponents} from "./wars/wars.routing";
|
||||
|
||||
|
||||
export const appRoutes: Routes = [
|
||||
|
@ -21,7 +21,7 @@ export const appRoutes: Routes = [
|
|||
{path: 'cc-overview', children: armyRoutes},
|
||||
{path: '', redirectTo: '/cc-overview', pathMatch: 'full'},
|
||||
|
||||
{path: 'cc-wars/:id', component: WarDetailComponent},
|
||||
{path: 'cc-wars', children: warRoutes},
|
||||
|
||||
{path: 'login', component: LoginComponent},
|
||||
{path: 'signup', component: SignupComponent},
|
||||
|
@ -47,6 +47,6 @@ export const appRouting = RouterModule.forRoot(appRoutes);
|
|||
|
||||
export const routingComponents = [LoginComponent, SignupComponent, RequestAwardComponent, RequestPromotionComponent, ConfirmAwardComponent,
|
||||
ConfirmPromotionComponent, AdminComponent, ...armyRoutingComponents, NotFoundComponent, ...usersRoutingComponents,
|
||||
...squadsRoutingComponents, ...decorationsRoutingComponents, ...ranksRoutingComponents, WarDetailComponent];
|
||||
...squadsRoutingComponents, ...decorationsRoutingComponents, ...ranksRoutingComponents, ...warsRoutingComponents];
|
||||
|
||||
export const routingProviders = [LoginGuardHL];
|
||||
export const routingProviders = [LoginGuardSQL, LoginGuardHL, LoginGuardMT, LoginGuardAdmin];
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
<span *ngIf="showErrorLabel"
|
||||
class="center-block label label-danger" style="font-size: medium; padding: 2px; margin-top: 2px">
|
||||
{{error}}
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import { Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
|
||||
import {Injectable} from '@angular/core';
|
||||
import {Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot} from '@angular/router';
|
||||
|
||||
@Injectable()
|
||||
export class LoginGuardSQL implements CanActivate {
|
||||
|
||||
constructor(private router: Router) { }
|
||||
constructor(private router: Router) {
|
||||
}
|
||||
|
||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
|
||||
if (localStorage.getItem('currentUser')) {
|
||||
|
@ -16,7 +17,7 @@ export class LoginGuardSQL implements CanActivate {
|
|||
}
|
||||
|
||||
// not logged in so redirect to login page with the return url
|
||||
this.router.navigate(['/login'], { queryParams: { returnUrl: state.url }});
|
||||
this.router.navigate(['/login'], {queryParams: {returnUrl: state.url}});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +25,8 @@ export class LoginGuardSQL implements CanActivate {
|
|||
@Injectable()
|
||||
export class LoginGuardHL implements CanActivate {
|
||||
|
||||
constructor(private router: Router) { }
|
||||
constructor(private router: Router) {
|
||||
}
|
||||
|
||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
|
||||
if (localStorage.getItem('currentUser')) {
|
||||
|
@ -36,7 +38,28 @@ export class LoginGuardHL implements CanActivate {
|
|||
}
|
||||
|
||||
// not logged in so redirect to login page with the return url
|
||||
this.router.navigate(['/login'], { queryParams: { returnUrl: state.url }});
|
||||
this.router.navigate(['/login'], {queryParams: {returnUrl: state.url}});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class LoginGuardMT implements CanActivate {
|
||||
|
||||
constructor(private router: Router) {
|
||||
}
|
||||
|
||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
|
||||
if (localStorage.getItem('currentUser')) {
|
||||
let currentUser = JSON.parse(localStorage.getItem('currentUser'));
|
||||
if (currentUser.permission >= 3) {
|
||||
// logged and correct permission so return true
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// not logged in so redirect to login page with the return url
|
||||
this.router.navigate(['/login'], {queryParams: {returnUrl: state.url}});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -44,7 +67,8 @@ export class LoginGuardHL implements CanActivate {
|
|||
@Injectable()
|
||||
export class LoginGuardAdmin implements CanActivate {
|
||||
|
||||
constructor(private router: Router) { }
|
||||
constructor(private router: Router) {
|
||||
}
|
||||
|
||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
|
||||
if (localStorage.getItem('currentUser')) {
|
||||
|
@ -56,7 +80,7 @@ export class LoginGuardAdmin implements CanActivate {
|
|||
}
|
||||
|
||||
// not logged in so redirect to login page with the return url
|
||||
this.router.navigate(['/login'], { queryParams: { returnUrl: state.url }});
|
||||
this.router.navigate(['/login'], {queryParams: {returnUrl: state.url}});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ export interface Player {
|
|||
export interface War {
|
||||
_id?: string;
|
||||
title?: string;
|
||||
date?: Date;
|
||||
date?: string;
|
||||
ptBlufor?: number;
|
||||
ptOpfor?: number;
|
||||
bestPlayerId?: Player;
|
||||
|
|
|
@ -21,7 +21,7 @@ export class WarService {
|
|||
}
|
||||
|
||||
|
||||
submitDecoration(war: War, logFile?) {
|
||||
submitWar(war: War, logFile?) {
|
||||
let body;
|
||||
|
||||
if (logFile) {
|
||||
|
@ -34,11 +34,8 @@ export class WarService {
|
|||
body.append('log', logFile, logFile.name);
|
||||
}
|
||||
|
||||
return this.http.post(this.config.apiUrl + this.config.apiDecorationPath, body)
|
||||
return this.http.post(this.config.apiUrl + this.config.apiWarPath, body)
|
||||
.map(res => res.json())
|
||||
.do(savedDecoration => {
|
||||
console.log('saved successfully')
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -39,7 +39,6 @@ export class WarDetailComponent {
|
|||
filterPlayersByFraction(fraction: string) {
|
||||
if (fraction) {
|
||||
this.players = this.war.players.filter((player) => {
|
||||
console.log(player.fraction + " .... " + fraction);
|
||||
return player.fraction === fraction;
|
||||
})
|
||||
} else {
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
.overview {
|
||||
position: fixed;
|
||||
width: 25%;
|
||||
padding-left: 50px;
|
||||
padding-top: 70px;
|
||||
margin-left: 10px;
|
||||
}
|
||||
|
||||
.load-arrow {
|
||||
background: url(../../assets/loading.png) no-repeat;
|
||||
display: block;
|
||||
width: 120px;
|
||||
height: 120px;
|
||||
}
|
||||
|
||||
/* Loading Animation */
|
||||
.glyphicon-refresh-animate {
|
||||
animation: spin 1.5s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
0% {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
100% {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
<form #form="ngForm" class="overview">
|
||||
<h3>Schlacht hinzufügen</h3>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="title">Titel</label>
|
||||
<input type="text" class="form-control"
|
||||
[(ngModel)]="war.title"
|
||||
name="title"
|
||||
id="title"
|
||||
required maxlength="50"/>
|
||||
|
||||
<show-error text="Name" path="title"></show-error>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="date">Datum</label>
|
||||
<input type="date" class="form-control"
|
||||
[(ngModel)]="war.date"
|
||||
name="date"
|
||||
id="date"
|
||||
required/>
|
||||
<show-error text="Datum" path="date"></show-error>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="ptblu">Punkte NATO</label>
|
||||
<input type="number" class="form-control" step="1"
|
||||
[(ngModel)]="war.ptBlufor"
|
||||
name="ptblu"
|
||||
id="ptblu"
|
||||
required/>
|
||||
<show-error text="Punkte NATO" path="ptnblu"></show-error>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="ptopf">Punkte CSAT</label>
|
||||
<input type="number" class="form-control" step="1"
|
||||
[(ngModel)]="war.ptOpfor"
|
||||
name="ptopf"
|
||||
id="ptopf"
|
||||
required/>
|
||||
<show-error text="Punkte CSAT" path="ptopf"></show-error>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<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">
|
||||
Logfile muss im Format RPT, LOG oder TXT vorliegen
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<button id="cancel"
|
||||
*ngIf="!loading"
|
||||
(click)="cancel()"
|
||||
class="btn btn-default">
|
||||
Abbrechen
|
||||
</button>
|
||||
|
||||
<button id="save"
|
||||
*ngIf="!loading"
|
||||
(click)="saveWar()"
|
||||
class="btn btn-default"
|
||||
[disabled]="!form.valid">
|
||||
Bestätigen
|
||||
</button>
|
||||
|
||||
<span *ngIf="loading" class="load-arrow glyphicon-refresh-animate"></span>
|
||||
<span *ngIf="showErrorLabel"
|
||||
class="center-block label label-danger" style="font-size: medium; padding: 2px; margin-top: 2px">
|
||||
{{error}}
|
||||
</span>
|
||||
|
||||
</form>
|
|
@ -0,0 +1,72 @@
|
|||
import {Component, ViewChild} from "@angular/core";
|
||||
import {Player, War} from "../models/model-interfaces";
|
||||
import {WarService} from "../services/war-service/war.service";
|
||||
import {ActivatedRoute, Router} from "@angular/router";
|
||||
import {NgForm} from "@angular/forms";
|
||||
|
||||
|
||||
@Component({
|
||||
selector: 'war-submit',
|
||||
templateUrl: './war-submit.component.html',
|
||||
styleUrls: ['./war-submit.component.css']
|
||||
})
|
||||
export class WarSubmitComponent {
|
||||
|
||||
war: War = {date: new Date().toISOString().slice(0, 10), players: []};
|
||||
|
||||
fileList: FileList;
|
||||
|
||||
showImageError = false;
|
||||
|
||||
showErrorLabel = false;
|
||||
|
||||
loading = false;
|
||||
|
||||
error;
|
||||
|
||||
@ViewChild(NgForm) form: NgForm;
|
||||
|
||||
constructor(private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private warService: WarService) {
|
||||
}
|
||||
|
||||
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;
|
||||
this.fileList = event.target.files;
|
||||
}
|
||||
}
|
||||
|
||||
saveWar() {
|
||||
let file: File;
|
||||
console.log(this.war.date)
|
||||
if (this.fileList) {
|
||||
file = this.fileList[0];
|
||||
this.loading = true;
|
||||
|
||||
this.warService.submitWar(this.war, file)
|
||||
.subscribe(war => {
|
||||
this.router.navigate([war._id], {relativeTo: this.route});
|
||||
},
|
||||
error => {
|
||||
this.error = error._body;
|
||||
this.showErrorLabel = true;
|
||||
this.loading = false;
|
||||
});
|
||||
} else {
|
||||
return window.alert(`Logfile ist ein Pflichtfeld`);
|
||||
}
|
||||
}
|
||||
|
||||
cancel() {
|
||||
this.router.navigate(['..'], {relativeTo: this.route});
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
import {Routes} from "@angular/router";
|
||||
import {WarSubmitComponent} from "./war-submit.component";
|
||||
import {WarDetailComponent} from "./war-detail.component";
|
||||
import {LoginGuardMT} from "../login/login.guard";
|
||||
|
||||
|
||||
export const warRoutes: Routes = [
|
||||
{
|
||||
path: '',
|
||||
component: WarSubmitComponent,
|
||||
canActivate: [LoginGuardMT]
|
||||
},
|
||||
{
|
||||
path: ':id',
|
||||
component: WarDetailComponent,
|
||||
}];
|
||||
|
||||
export const warsRoutingComponents = [WarSubmitComponent, WarDetailComponent];
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 7.8 KiB |
Loading…
Reference in New Issue