Add new filter parameter to get users after award owning and use for trace pages

pull/43/head
HardiReady 2018-07-22 18:18:46 +02:00
parent 78cc61232b
commit 88346db70e
10 changed files with 80 additions and 46 deletions

View File

@ -5,14 +5,17 @@ Get single army member information
+ Parameters
+ q: `hardi` (string, optional) - filter string which filters for partial username
+ fractFilter: `BLUFOR` (enum[string], optional)
Field to filter by fraction
+ fractFilter: `BLUFOR` (enum[string], optional) - Field to filter by fraction
+ Members
+ `BLUFOR`
+ `OPFOR`
+ `GLOBAL`
+ squadId: `591470249e9fae286e008e31` (string, optional) - Field to filter by membership of certain squad
+ decorationId: `5abd3dff6e6a0334d95b8ba0` (string, optional) - Field to filter by ownership of certain decoration
+ limit: 20 (number, optional)
Maximum number of users to return

View File

@ -29,29 +29,7 @@ users.get('/', offsetlimitMiddleware);
// routes **********************
users.route('/')
.get((req, res, next) => {
const userQuery = () => {
UserModel.find(dbFilter, res.locals.filter, res.locals.limitskip)
.populate('squadId')
.collation({locale: 'en', strength: 2}) // case insensitive order
.sort('username').exec((err, users) => {
if (err) return next(err);
if (users.length === 0) {
res.locals.items = users;
res.locals.processed = true;
return next();
}
UserModel.count(dbFilter, (err, totalCount) => {
res.set('x-total-count', totalCount);
res.locals.items = users;
res.locals.processed = true;
return next();
});
});
};
if (!req.query.q) req.query.q = '';
const dbFilter = {username: {'$regex': req.query.q, '$options': 'i'}};
if (req.query.squadId) dbFilter['squadId'] = {'$eq': req.query.squadId};
const finishFiltersAndExecute = () => {
// squad / fraction filter setup
if (req.query.fractFilter && req.query.fractFilter !== 'UNASSIGNED' && !req.query.squadId) {
SquadModel.find({'fraction': req.query.fractFilter}, {_id: 1}, (err, squads) => {
@ -64,6 +42,47 @@ users.route('/')
}
userQuery();
}
};
const userQuery = () => {
UserModel.find(dbFilter, res.locals.filter, res.locals.limitskip)
.populate('squadId')
.collation({locale: 'en', strength: 2}) // case insensitive order
.sort('username')
.exec((err, users) => {
if (err) return next(err);
if (users.length === 0) {
res.locals.items = users;
res.locals.processed = true;
return next();
}
UserModel.count(dbFilter, (err, totalCount) => {
res.set('x-total-count', totalCount);
res.locals.items = users;
res.locals.processed = true;
return next();
});
});
};
const nameQuery = (!req.query.q) ? '' : req.query.q;
const dbFilter = {username: {'$regex': nameQuery, '$options': 'i'}};
if (req.query.squadId) dbFilter['squadId'] = {'$eq': req.query.squadId};
// decoration filter
const queryDecoId = req.query.decorationId;
if (queryDecoId) {
AwardingModel.find({decorationId: queryDecoId}, (err, awards) => {
const userIds = [...new Set(awards.map((award) => award.userId))];
dbFilter._id = {'$in': userIds};
finishFiltersAndExecute();
});
} else {
finishFiltersAndExecute();
}
})
.post(apiAuthenticationMiddleware, checkHl, (req, res, next) => {
@ -196,7 +215,6 @@ users.route('/:id')
routerHandling.httpMethodNotAllowed
);
// this middleware function can be used, if you like or remove it
// it looks for object(s) in res.locals.items and if they exist, they are send to the client as json
users.use(routerHandling.emptyResponse);

View File

@ -51,7 +51,6 @@ export class ArmyMemberComponent implements OnInit, OnDestroy {
this.awards = awards;
}));
});
};
ngOnDestroy() {

View File

@ -4,7 +4,7 @@
min-width: 800px;
position: relative;
margin: auto auto 25px;
height: calc(100vh - 95px);
min-height: calc(100vh - 95px);
}
.show-panel {
@ -12,6 +12,10 @@
margin: inherit;
}
:host /deep/ .show-panel mat-card {
cursor: default;
}
.decoration-show-panel {
height: 250px;
}

View File

@ -23,7 +23,7 @@
<ng-container matColumnDef="fraction">
<th mat-header-cell *matHeaderCellDef>Fraktion</th>
<td mat-cell *matCellDef="let element"
[style.color]="traceItem.fraction === 'BLUFOR' ? fraction.COLOR_BLUFOR :fraction.COLOR_OPFOR">
[style.color]="element.squadId.fraction === 'BLUFOR' ? fraction.COLOR_BLUFOR :fraction.COLOR_OPFOR">
{{element.squadId.fraction === 'BLUFOR' ? fraction.BLUFOR : fraction.OPFOR}}
</td>
</ng-container>

View File

@ -44,18 +44,19 @@ export class TraceOverviewComponent implements OnInit, OnDestroy {
if (this.router.url.includes('find/award/')) {
// Award
this.isRank = false;
console.log(itemId);
this.decorationService.getDecoration(itemId).subscribe(decoration => {
this.traceItem = decoration;
console.log(decoration)
this.userService.findUsers({decorationId: decoration._id}).subscribe(users => {
this.users = users.filter(user => user.squadId != null);
});
});
} else if (this.router.url.includes('find/rank/')) {
// Rank
this.isRank = true;
this.rankService.getRank(itemId).subscribe(rank => {
this.traceItem = rank;
this.userService.findUsers('', rank.fraction).subscribe(users => {
this.users = users.filter(user => user.rankLvl === rank.level);
this.userService.findUsers({fraction: rank.fraction}).subscribe(users => {
this.users = users.filter(user => user.squadId != null && user.rankLvl === rank.level);
});
});
}

View File

@ -45,7 +45,7 @@ export class RequestAwardComponent implements OnInit {
ngOnInit() {
const currentUser = this.loginService.getCurrentUser();
this.userService.findUsers('', undefined, currentUser.squad._id).subscribe(users => {
this.userService.findUsers({squadId: currentUser.squad._id}).subscribe(users => {
this.users = users;
});
this.decorationService.findDecorations('', currentUser.squad.fraction).subscribe(decorations => {

View File

@ -44,7 +44,7 @@ export class RequestPromotionComponent implements OnInit {
ngOnInit() {
const currentUser = this.loginService.getCurrentUser();
// show only current users squad members
this.userService.findUsers('', undefined, currentUser.squad._id).subscribe(users => {
this.userService.findUsers({squadId: currentUser.squad._id}).subscribe(users => {
this.users = users;
});
this.rankService.findRanks('', currentUser.squad.fraction).subscribe(ranks => {

View File

@ -19,15 +19,23 @@ export class UserService {
this.users$ = userStore.items$;
}
findUsers(query = '', fractionFilter?, squadFilter?, limit?, offset?, action = LOAD) {
findUsers(filter, limit?, offset?, action = LOAD) {
const searchParams = new URLSearchParams();
searchParams.append('q', query);
if (fractionFilter) {
searchParams.append('fractFilter', fractionFilter);
searchParams.append('q', (filter && filter.query) ? filter.query : '');
if (filter && filter.fraction) {
searchParams.append('fractFilter', filter.fraction);
}
if (squadFilter) {
searchParams.append('squadId', squadFilter);
if (filter && filter.squadId) {
searchParams.append('squadId', filter.squadId);
}
if (filter && filter.decorationId) {
searchParams.append('decorationId', filter.decorationId);
}
searchParams.append('limit', limit);
searchParams.append('offset', offset);
this.http.get(this.config.apiUserPath, searchParams)

View File

@ -1,5 +1,4 @@
import {Component, OnInit} from '@angular/core';
import {Location} from '@angular/common';
import {FormControl} from '@angular/forms';
import {ActivatedRoute, Router} from '@angular/router';
@ -81,8 +80,10 @@ export class UserListComponent implements OnInit {
this.limit = 20;
}
this.radioModel = UIHelpers.toggleReleaseButton(this.radioModel, group);
return this.users$ = this.userService.findUsers(this.searchTerm.value, this.radioModel,
null, this.limit, this.offset, action);
return this.users$ = this.userService.findUsers({
query: this.searchTerm.value,
fraction: this.radioModel
}, this.limit, this.offset, action);
}
onScrollDown() {