Add login guard for statistic pages; Add basic edit war page

pull/34/head
HardiReady 2018-04-29 10:32:14 +02:00
parent 1ac78b7550
commit 266ce9a48a
9 changed files with 153 additions and 25 deletions

View File

@ -1,7 +1,7 @@
import {RouterModule, Routes} from '@angular/router'; import {RouterModule, Routes} from '@angular/router';
import {LoginComponent} from './login/index'; import {LoginComponent, LoginGuardMT} from './login';
import {NotFoundComponent} from './common/not-found/not-found.component'; import {NotFoundComponent} from './common/not-found';
import {LoginGuardAdmin, LoginGuardHL} from './login/login.guard'; import {LoginGuardAdmin, LoginGuardHL} from './login';
import {armyRoutes, armyRoutingComponents} from './army/army.routing'; import {armyRoutes, armyRoutingComponents} from './army/army.routing';
import {SignupComponent} from './login/signup.component'; import {SignupComponent} from './login/signup.component';
import {RouteConfig} from './app.config'; import {RouteConfig} from './app.config';
@ -72,4 +72,4 @@ export const appRouting = RouterModule.forRoot(appRoutes);
export const routingComponents = [...armyRoutingComponents, LoginComponent, SignupComponent, NotFoundComponent]; export const routingComponents = [...armyRoutingComponents, LoginComponent, SignupComponent, NotFoundComponent];
export const routingProviders = [LoginGuardHL, LoginGuardAdmin]; export const routingProviders = [LoginGuardHL, LoginGuardMT, LoginGuardAdmin];

View File

@ -38,5 +38,9 @@ export class WarService {
.map(res => res.json()); .map(res => res.json());
} }
updateWar(war: War) {
return this.http.put(this.config.apiWarPath, war)
.map(res => res.json());
}
} }

View File

@ -26,7 +26,6 @@ export class CampaignSubmitComponent {
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 this.subscription = this.route.params
.map(params => params['id']) .map(params => params['id'])
.filter(id => id !== undefined) .filter(id => id !== undefined)
@ -55,5 +54,4 @@ export class CampaignSubmitComponent {
this.router.navigate(['..'], {relativeTo: this.route}); this.router.navigate(['..'], {relativeTo: this.route});
return false; return false;
} }
} }

View File

@ -11,6 +11,8 @@ import {WarSubmitComponent} from './war/war-submit/war-submit.component';
import {FractionStatsComponent} from './war/fraction-stats/fraction-stats.component'; import {FractionStatsComponent} from './war/fraction-stats/fraction-stats.component';
import {StatisticHighScoreComponent} from './campaign/highscore/highscore.component'; import {StatisticHighScoreComponent} from './campaign/highscore/highscore.component';
import {WarHeaderComponent} from "./war/war-header/war-header.component"; import {WarHeaderComponent} from "./war/war-header/war-header.component";
import {WarEditComponent} from "./war/war-edit/war-edit.component";
import {LoginGuardMT} from "../login";
export const statsRoutes: Routes = [{ export const statsRoutes: Routes = [{
@ -32,21 +34,6 @@ export const statsRoutes: Routes = [{
component: StatisticHighScoreComponent, component: StatisticHighScoreComponent,
outlet: 'right' outlet: 'right'
}, },
{
path: 'campaign',
component: CampaignSubmitComponent,
outlet: 'right'
},
{
path: 'campaign/:id',
component: CampaignSubmitComponent,
outlet: 'right'
},
{
path: 'new',
component: WarSubmitComponent,
outlet: 'right'
},
{ {
path: 'war/:id', path: 'war/:id',
component: WarHeaderComponent, component: WarHeaderComponent,
@ -56,11 +43,35 @@ export const statsRoutes: Routes = [{
path: 'campaign-player/:id/:playerName', path: 'campaign-player/:id/:playerName',
component: CampaignPlayerDetailComponent, component: CampaignPlayerDetailComponent,
outlet: 'right' outlet: 'right'
},
{
path: 'campaign',
component: CampaignSubmitComponent,
outlet: 'right',
canActivate: [LoginGuardMT]
},
{
path: 'campaign/:id',
component: CampaignSubmitComponent,
outlet: 'right',
canActivate: [LoginGuardMT]
},
{
path: 'submit-war',
component: WarSubmitComponent,
outlet: 'right',
canActivate: [LoginGuardMT]
},
{
path: 'submit-war/:id',
component: WarEditComponent,
outlet: 'right',
canActivate: [LoginGuardMT]
}]; }];
export const statsRouterModule: ModuleWithProviders = RouterModule.forChild(statsRoutes); export const statsRouterModule: ModuleWithProviders = RouterModule.forChild(statsRoutes);
export const statsRoutingComponents = [StatisticComponent, StatisticOverviewComponent, StatisticHighScoreComponent, export const statsRoutingComponents = [StatisticComponent, StatisticOverviewComponent, StatisticHighScoreComponent,
CampaignSubmitComponent, WarListComponent, WarSubmitComponent, WarHeaderComponent, ScoreboardComponent, CampaignSubmitComponent, WarListComponent, WarSubmitComponent, WarEditComponent, WarHeaderComponent,
FractionStatsComponent, CampaignPlayerDetailComponent, WarItemComponent]; ScoreboardComponent, FractionStatsComponent, CampaignPlayerDetailComponent, WarItemComponent];

View File

@ -0,0 +1,58 @@
<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 displayName="Name" controlPath="title"></show-error>
</div>
<div class="form-group">
<label for="campaign">Kampagne</label>
<select class="form-control"
name="campaign"
id="campaign"
[(ngModel)]="war.campaign"
required>
<option *ngFor="let campaign of campaignService.campaigns" [ngValue]="campaign._id">
{{campaign.title}}
</option>
</select>
</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="showFileError">
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)="updateWar()"
class="btn btn-default"
[disabled]="!form.valid">
Bestätigen
</button>
<span *ngIf="loading" class="load-indicator 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>

View File

@ -0,0 +1,58 @@
import {Component, ViewChild} from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router';
import {NgForm} from '@angular/forms';
import {WarService} from '../../../services/logs/war.service';
import {War} from '../../../models/model-interfaces';
import {CampaignService} from "../../../services/logs/campaign.service";
import {Subscription} from 'rxjs/Subscription';
@Component({
selector: 'war-edit',
templateUrl: './war-edit.component.html',
styleUrls: ['./war-edit.component.css', '../../../style/load-indicator.css',
'../../../style/entry-form.css', '../../../style/overview.css']
})
export class WarEditComponent {
war: War = {players: []};
subscription: Subscription;
showFileError = false;
showErrorLabel = false;
error;
@ViewChild(NgForm) form: NgForm;
constructor(private route: ActivatedRoute,
private router: Router,
private warService: WarService,
private campaignService: CampaignService) {
this.subscription = this.route.params
.map(params => params['id'])
.filter(id => id !== undefined)
.flatMap(id => this.warService.getWar(id))
.subscribe(war => {
this.war = war;
});
}
updateWar() {
this.warService.updateWar(this.war)
.subscribe(war => {
this.router.navigate(['../war/' + war._id], {relativeTo: this.route});
},
error => {
this.error = error._body.error.message;
this.showErrorLabel = true;
});
}
cancel() {
this.router.navigate(['..'], {relativeTo: this.route});
return false;
}
}

View File

@ -51,7 +51,7 @@ export class WarListComponent implements OnInit {
selectNewWar() { selectNewWar() {
this.selectedWarId = null; this.selectedWarId = null;
this.router.navigate([{outlets: {'right': ['new']}}], {relativeTo: this.route}); this.router.navigate([{outlets: {'right': ['submit-war']}}], {relativeTo: this.route});
} }
selectWar(warId) { selectWar(warId) {

View File

@ -70,5 +70,4 @@ export class WarSubmitComponent {
this.router.navigate(['..'], {relativeTo: this.route}); this.router.navigate(['..'], {relativeTo: this.route});
return false; return false;
} }
} }