simplify armyoverview data structure
parent
193b136b0a
commit
0e571136bb
|
@ -17,16 +17,12 @@ const overview = new express.Router();
|
|||
// routes **********************
|
||||
overview.route('/')
|
||||
.get((req, res, next) => {
|
||||
let countOpfor = 0;
|
||||
let countBlufor = 0;
|
||||
const armyOverview = {
|
||||
BLUFOR: {
|
||||
squads: [],
|
||||
},
|
||||
OPFOR: {
|
||||
squads: [],
|
||||
},
|
||||
};
|
||||
const fractions = ['BLUFOR', 'OPFOR'];
|
||||
const fractionMemberCount = [0, 0];
|
||||
const armyOverview = [
|
||||
{squads: []},
|
||||
{squads: []},
|
||||
];
|
||||
|
||||
SquadModel.find({}, {'sortingNumber': 0, 'updatedAt': 0, 'timestamp': 0, '__v': 0}, {
|
||||
sort: {
|
||||
|
@ -71,15 +67,14 @@ overview.route('/')
|
|||
const s = squad.toObject();
|
||||
s.members = squadMembers;
|
||||
s.memberCount = squadMembers.length;
|
||||
if (s.fraction === 'BLUFOR') {
|
||||
delete s.fraction;
|
||||
armyOverview.BLUFOR.squads.push(s);
|
||||
countBlufor += s.members.length;
|
||||
}
|
||||
if (s.fraction === 'OPFOR') {
|
||||
delete s.fraction;
|
||||
armyOverview.OPFOR.squads.push(s);
|
||||
countOpfor += s.members.length;
|
||||
|
||||
for (let i = 0; i < fractions.length; i++) {
|
||||
if (s.fraction === fractions[i]) {
|
||||
delete s.fraction;
|
||||
armyOverview[i].squads.push(s);
|
||||
fractionMemberCount[i] += s.members.length;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -90,8 +85,11 @@ overview.route('/')
|
|||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
armyOverview.BLUFOR.memberCount = countBlufor;
|
||||
armyOverview.OPFOR.memberCount = countOpfor;
|
||||
|
||||
for (let i = 0; i < fractions.length; i++) {
|
||||
armyOverview[i].memberCount = fractionMemberCount[i];
|
||||
}
|
||||
|
||||
res.locals.items = armyOverview;
|
||||
res.locals.processed = true;
|
||||
next();
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
<div class="pull-left" style="width: 45%;">
|
||||
<h3 class="army-head" [style.color]="fraction.COLOR_BLUFOR">{{fraction.BLUFOR}}</h3>
|
||||
<div class="squad-layout" *ngFor="let squad of army.BLUFOR.squads">
|
||||
<div class="squad-layout" *ngFor="let squad of army[0].squads">
|
||||
<div class="row colored-row title-row">
|
||||
<div class="squad-cell pull-left"><img
|
||||
src="resource/squad/{{squad._id}}.png"></div>
|
||||
|
@ -27,12 +27,12 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="member-count">Armeemitglieder: {{army.BLUFOR.memberCount}}</div>
|
||||
<div class="member-count">Armeemitglieder: {{army[0].memberCount}}</div>
|
||||
</div>
|
||||
|
||||
<div class="pull-right" style="width: 45%;">
|
||||
<h3 class="army-head" [style.color]="fraction.COLOR_OPFOR">{{fraction.OPFOR}}</h3>
|
||||
<div class="squad-layout" *ngFor="let squad of army.OPFOR.squads">
|
||||
<div class="squad-layout" *ngFor="let squad of army[1].squads">
|
||||
<div class="row colored-row title-row">
|
||||
<div class="squad-cell pull-left"><img
|
||||
src="resource/squad/{{squad._id}}.png"></div>
|
||||
|
@ -56,7 +56,7 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="member-count">Armeemitglieder: {{army.OPFOR.memberCount}}</div>
|
||||
<div class="member-count">Armeemitglieder: {{army[1].memberCount}}</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
|
|
@ -15,7 +15,7 @@ import {CSSHelpers} from '../global.helpers';
|
|||
})
|
||||
export class ArmyComponent implements OnInit, OnDestroy {
|
||||
|
||||
army: Army = {BLUFOR: {squads: [], memberCount: 0}, OPFOR: {squads: [], memberCount: 0}};
|
||||
army: Army[];
|
||||
|
||||
readonly fraction = Fraction;
|
||||
|
||||
|
|
|
@ -104,7 +104,6 @@ export interface Decoration {
|
|||
}
|
||||
|
||||
export interface Army {
|
||||
BLUFOR: {
|
||||
squads: {
|
||||
_id,
|
||||
name,
|
||||
|
@ -115,20 +114,6 @@ export interface Army {
|
|||
rank
|
||||
}[],
|
||||
}[],
|
||||
memberCount
|
||||
};
|
||||
OPFOR: {
|
||||
squads: {
|
||||
_id,
|
||||
name,
|
||||
memberCount,
|
||||
members: {
|
||||
_id,
|
||||
username,
|
||||
rank
|
||||
}[],
|
||||
}[],
|
||||
memberCount
|
||||
};
|
||||
memberCount: number
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue