Add possibility to remove ranks, catch error use-cases in signature creation and army-overview

pull/1/head
Florian Hartwich 2017-05-15 13:44:37 +02:00
parent 630668e032
commit 4c6f3dab78
10 changed files with 73 additions and 31 deletions

View File

@ -48,12 +48,16 @@ overview.route('/')
}, {sort: {rankLvl: 'desc', name: 'asc'}}, (err, users) => { }, {sort: {rankLvl: 'desc', name: 'asc'}}, (err, users) => {
const squadMembers = []; const squadMembers = [];
async.eachSeries(users, (user, callback) => { async.eachSeries(users, (user, callback) => {
const usr = user.toObject();
RankModel.findOne({level: user.rankLvl, fraction: squad.fraction}, (err, rank) => { RankModel.findOne({level: user.rankLvl, fraction: squad.fraction}, (err, rank) => {
if (err) { if (err) {
return next(err); return next(err);
} }
const usr = user.toObject();
usr.rank = rank.name; // not defined if rank was deleted / rankLvl not available for fraction
if (rank) {
usr.rank = rank.name;
}
delete usr.rankLvl; delete usr.rankLvl;
squadMembers.push(usr) squadMembers.push(usr)

View File

@ -71,28 +71,34 @@ let createSignature = (userId, res, next) => {
return next(err) return next(err)
} }
if (user.squadId.fraction === 'BLUFOR') { if (result) {
rankW = 25; if (user.squadId.fraction === 'BLUFOR') {
rankH = 60; rankW = 25;
rankX = 36; rankH = 60;
rankY = 34; rankX = 36;
} else { rankY = 34;
rankW = 37; } else {
rankH = 58; rankW = 37;
rankX = 30; rankH = 58;
rankY = 34; rankX = 30;
} rankY = 34;
}
jimp.read(resourceDir + 'rank/' + result._id + fileExt) jimp.read(resourceDir + 'rank/' + result._id + fileExt)
.then((rankImage) => { .then((rankImage) => {
rankImage.resize(rankW, rankH); rankImage.resize(rankW, rankH);
loadedImage loadedImage
.print(font, 128, 55, result.name) .print(font, 128, 55, result.name)
.composite(rankImage, rankX, rankY) .composite(rankImage, rankX, rankY)
}) })
.then(() => { .then(() => {
addDecorationsAndSave(userId, loadedImage, res, next); addDecorationsAndSave(userId, loadedImage, res, next);
}) })
} else {
// user has not any assignable rank in his fraction at this point,
// e.g. assigned rank has been deleted or switched fraction so rankLvl is not defined
addDecorationsAndSave(userId, loadedImage, res, next);
}
}) })
}) })
.catch((err) => { .catch((err) => {

View File

@ -7,6 +7,12 @@ div.rank-list-entry, a.rank-list-entry {
margin-bottom: -1px; margin-bottom: -1px;
} }
.rank-list-preview {
height: 54px;
float: left;
margin-right: 12px;
}
.marked { .marked {
background: lightgrey; background: lightgrey;
} }
@ -25,9 +31,9 @@ small {
} }
.trash { .trash {
float:right;
padding-top: 18px; padding-top: 18px;
font-size: 17px; font-size: 17px;
margin-left: -10px;
} }
.selected { .selected {

View File

@ -1,7 +1,7 @@
<div class="fade-in rank-list-entry" [ngClass]="{selected : selected}" (click)="select()"> <div class="fade-in rank-list-entry" [ngClass]="{selected : selected}" (click)="select()">
<div class="row"> <div class="row">
<div class="col-xs-11"> <div class="col-xs-9">
<span> <span>
<a>{{rank.name}}</a> <a>{{rank.name}}</a>
</span> </span>
@ -10,5 +10,12 @@
<small *ngIf="rank.fraction == 'BLUFOR'">NATO</small> <small *ngIf="rank.fraction == 'BLUFOR'">NATO</small>
<small> - Stufe {{rank.level}}</small> <small> - Stufe {{rank.level}}</small>
</div> </div>
<div class="col-xs-3">
<img src="resource/rank/{{rank._id}}.png" class="rank-list-preview">
<span (click)="delete(); $event.stopPropagation()" title="Löschen" class="glyphicon glyphicon-trash trash"></span>
</div>
</div> </div>
</div> </div>

View File

@ -27,7 +27,7 @@ export class RankItemComponent {
} }
delete() { delete() {
this.rankSelected.emit(this.rank); this.rankDelete.emit(this.rank);
} }
ngAfterViewChecked() { ngAfterViewChecked() {

View File

@ -21,6 +21,9 @@
(change)="filterRanksByFraction(query.value, fractRadioOpfor.value)">CSAT (change)="filterRanksByFraction(query.value, fractRadioOpfor.value)">CSAT
</label> </label>
</form> </form>
<a class="pull-right btn btn-success" (click)="openNewRankForm()">
Neuen Rang hinzufügen
</a>
</div> </div>
<div class="input-group search-bar" style="padding-top: 0;"> <div class="input-group search-bar" style="padding-top: 0;">

View File

@ -60,6 +60,15 @@ export class RankListComponent implements OnInit {
this.ranks$ = this.rankService.findRanks(query, fractionFilter); this.ranks$ = this.rankService.findRanks(query, fractionFilter);
} }
deleteRank(rank) {
const fraction = rank.fraction === 'OPFOR' ? 'CSAT' : 'NATO';
if (confirm('Soll der Rang ' + rank.name + ' (' + fraction + ') wirklich gelöscht werden?')) {
this.rankService.deleteRank(rank)
.subscribe((res) => {
})
}
}
adjustBrowserUrl(queryString = '') { adjustBrowserUrl(queryString = '') {
const absoluteUrl = this.location.path().split('?')[0]; const absoluteUrl = this.location.path().split('?')[0];
const queryPart = queryString !== '' ? `query=${queryString}` : ''; const queryPart = queryString !== '' ? `query=${queryString}` : '';

View File

@ -3,7 +3,7 @@ import {Decoration, Rank} from "../../models/model-interfaces";
import {RequestMethod, RequestOptions, URLSearchParams} from "@angular/http"; import {RequestMethod, RequestOptions, URLSearchParams} from "@angular/http";
import {Observable} from "rxjs/Observable"; import {Observable} from "rxjs/Observable";
import {LOAD} from "../stores/decoration.store"; import {LOAD} from "../stores/decoration.store";
import {EDIT, RankStore} from "../stores/rank.store"; import {EDIT, RankStore, REMOVE} from "../stores/rank.store";
import {AppConfig} from "../../app.config"; import {AppConfig} from "../../app.config";
import {HttpClient} from "../http-client"; import {HttpClient} from "../http-client";
@ -84,6 +84,13 @@ export class RankService {
}); });
} }
deleteRank(rank: Rank) {
return this.http.delete(this.config.apiUrl + this.config.apiRankPath + rank._id)
.do(res => {
this.rankStore.dispatch({type: REMOVE, data: rank});
});
}
} }

View File

@ -66,11 +66,11 @@
<table class="table table-hover"> <table class="table table-hover">
<thead> <thead>
<tr> <tr>
<th class="col-sm-1" style="width: 60px;">Bild</th> <th class="col-sm-1">Bild</th>
<th class="col-sm-2">Bezeichnung</th> <th class="col-sm-2">Bezeichnung</th>
<th class="col-sm-2">Begründung</th> <th class="col-sm-2">Begründung</th>
<th class="col-sm-1 text-right" style="width: 65px;">Datum</th> <th class="col-sm-1 text-right">Datum</th>
<th class="col-sm-1 text-center" style="width: 45px;"></th> <th class="col-sm-1 text-center"></th>
</tr> </tr>
</thead> </thead>
<tbody *ngFor="let award of awards"> <tbody *ngFor="let award of awards">

View File

@ -12,7 +12,7 @@
</div> </div>
<div class="col-xs-3"> <div class="col-xs-3">
<span (click)="select()" title="Bearbeiten" class="glyphicon glyphicon-pencil pull-left edit"></span> <span (click)="select()" title="Name, Squad, Rang" class="glyphicon glyphicon-pencil pull-left edit"></span>
<span (click)="award()" title="Auszeichnungen" class="icon-award pull-left"></span> <span (click)="award()" title="Auszeichnungen" class="icon-award pull-left"></span>
<span (click)="delete(); $event.stopPropagation()" title="Löschen" class="glyphicon glyphicon-trash trash"></span> <span (click)="delete(); $event.stopPropagation()" title="Löschen" class="glyphicon glyphicon-trash trash"></span>
</div> </div>