Add new filter parameter to get users after award owning and use for trace pages
							parent
							
								
									78cc61232b
								
							
						
					
					
						commit
						88346db70e
					
				| 
						 | 
					@ -5,14 +5,17 @@ Get single army member information
 | 
				
			||||||
+ Parameters
 | 
					+ Parameters
 | 
				
			||||||
    + q: `hardi` (string, optional) - filter string which filters for partial username
 | 
					    + q: `hardi` (string, optional) - filter string which filters for partial username
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    + fractFilter: `BLUFOR` (enum[string], optional)
 | 
					    + fractFilter: `BLUFOR` (enum[string], optional) - Field to filter by fraction
 | 
				
			||||||
        Field to filter by fraction
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        + Members
 | 
					        + Members
 | 
				
			||||||
            + `BLUFOR`
 | 
					            + `BLUFOR`
 | 
				
			||||||
            + `OPFOR`
 | 
					            + `OPFOR`
 | 
				
			||||||
            + `GLOBAL`
 | 
					            + `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)
 | 
					    + limit: 20 (number, optional)
 | 
				
			||||||
        Maximum number of users to return
 | 
					        Maximum number of users to return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -29,29 +29,7 @@ users.get('/', offsetlimitMiddleware);
 | 
				
			||||||
// routes **********************
 | 
					// routes **********************
 | 
				
			||||||
users.route('/')
 | 
					users.route('/')
 | 
				
			||||||
     .get((req, res, next) => {
 | 
					     .get((req, res, next) => {
 | 
				
			||||||
       const userQuery = () => {
 | 
					       const finishFiltersAndExecute = () => {
 | 
				
			||||||
         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};
 | 
					 | 
				
			||||||
         // squad / fraction filter setup
 | 
					         // squad / fraction filter setup
 | 
				
			||||||
         if (req.query.fractFilter && req.query.fractFilter !== 'UNASSIGNED' && !req.query.squadId) {
 | 
					         if (req.query.fractFilter && req.query.fractFilter !== 'UNASSIGNED' && !req.query.squadId) {
 | 
				
			||||||
           SquadModel.find({'fraction': req.query.fractFilter}, {_id: 1}, (err, squads) => {
 | 
					           SquadModel.find({'fraction': req.query.fractFilter}, {_id: 1}, (err, squads) => {
 | 
				
			||||||
| 
						 | 
					@ -64,6 +42,47 @@ users.route('/')
 | 
				
			||||||
           }
 | 
					           }
 | 
				
			||||||
           userQuery();
 | 
					           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) => {
 | 
					     .post(apiAuthenticationMiddleware, checkHl, (req, res, next) => {
 | 
				
			||||||
| 
						 | 
					@ -196,7 +215,6 @@ users.route('/:id')
 | 
				
			||||||
       routerHandling.httpMethodNotAllowed
 | 
					       routerHandling.httpMethodNotAllowed
 | 
				
			||||||
     );
 | 
					     );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
// this middleware function can be used, if you like or remove it
 | 
					// 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
 | 
					// 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);
 | 
					users.use(routerHandling.emptyResponse);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -51,7 +51,6 @@ export class ArmyMemberComponent implements OnInit, OnDestroy {
 | 
				
			||||||
                                this.awards = awards;
 | 
					                                this.awards = awards;
 | 
				
			||||||
                              }));
 | 
					                              }));
 | 
				
			||||||
                            });
 | 
					                            });
 | 
				
			||||||
 | 
					 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  ngOnDestroy() {
 | 
					  ngOnDestroy() {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,7 +4,7 @@
 | 
				
			||||||
  min-width: 800px;
 | 
					  min-width: 800px;
 | 
				
			||||||
  position: relative;
 | 
					  position: relative;
 | 
				
			||||||
  margin: auto auto 25px;
 | 
					  margin: auto auto 25px;
 | 
				
			||||||
  height: calc(100vh - 95px);
 | 
					  min-height: calc(100vh - 95px);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.show-panel {
 | 
					.show-panel {
 | 
				
			||||||
| 
						 | 
					@ -12,6 +12,10 @@
 | 
				
			||||||
  margin: inherit;
 | 
					  margin: inherit;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					:host /deep/ .show-panel mat-card {
 | 
				
			||||||
 | 
					  cursor: default;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.decoration-show-panel {
 | 
					.decoration-show-panel {
 | 
				
			||||||
  height: 250px;
 | 
					  height: 250px;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -23,7 +23,7 @@
 | 
				
			||||||
      <ng-container matColumnDef="fraction">
 | 
					      <ng-container matColumnDef="fraction">
 | 
				
			||||||
        <th mat-header-cell *matHeaderCellDef>Fraktion</th>
 | 
					        <th mat-header-cell *matHeaderCellDef>Fraktion</th>
 | 
				
			||||||
        <td mat-cell *matCellDef="let element"
 | 
					        <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}}
 | 
					          {{element.squadId.fraction === 'BLUFOR' ? fraction.BLUFOR : fraction.OPFOR}}
 | 
				
			||||||
        </td>
 | 
					        </td>
 | 
				
			||||||
      </ng-container>
 | 
					      </ng-container>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -44,18 +44,19 @@ export class TraceOverviewComponent implements OnInit, OnDestroy {
 | 
				
			||||||
      if (this.router.url.includes('find/award/')) {
 | 
					      if (this.router.url.includes('find/award/')) {
 | 
				
			||||||
        // Award
 | 
					        // Award
 | 
				
			||||||
        this.isRank = false;
 | 
					        this.isRank = false;
 | 
				
			||||||
        console.log(itemId);
 | 
					 | 
				
			||||||
        this.decorationService.getDecoration(itemId).subscribe(decoration => {
 | 
					        this.decorationService.getDecoration(itemId).subscribe(decoration => {
 | 
				
			||||||
          this.traceItem = 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/')) {
 | 
					      } else if (this.router.url.includes('find/rank/')) {
 | 
				
			||||||
        // Rank
 | 
					        // Rank
 | 
				
			||||||
        this.isRank = true;
 | 
					        this.isRank = true;
 | 
				
			||||||
        this.rankService.getRank(itemId).subscribe(rank => {
 | 
					        this.rankService.getRank(itemId).subscribe(rank => {
 | 
				
			||||||
          this.traceItem = rank;
 | 
					          this.traceItem = rank;
 | 
				
			||||||
          this.userService.findUsers('', rank.fraction).subscribe(users => {
 | 
					          this.userService.findUsers({fraction: rank.fraction}).subscribe(users => {
 | 
				
			||||||
            this.users = users.filter(user => user.rankLvl === rank.level);
 | 
					            this.users = users.filter(user => user.squadId != null && user.rankLvl === rank.level);
 | 
				
			||||||
          });
 | 
					          });
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -45,7 +45,7 @@ export class RequestAwardComponent implements OnInit {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  ngOnInit() {
 | 
					  ngOnInit() {
 | 
				
			||||||
    const currentUser = this.loginService.getCurrentUser();
 | 
					    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.users = users;
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
    this.decorationService.findDecorations('', currentUser.squad.fraction).subscribe(decorations => {
 | 
					    this.decorationService.findDecorations('', currentUser.squad.fraction).subscribe(decorations => {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -44,7 +44,7 @@ export class RequestPromotionComponent implements OnInit {
 | 
				
			||||||
  ngOnInit() {
 | 
					  ngOnInit() {
 | 
				
			||||||
    const currentUser = this.loginService.getCurrentUser();
 | 
					    const currentUser = this.loginService.getCurrentUser();
 | 
				
			||||||
    // show only current users squad members
 | 
					    // 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.users = users;
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
    this.rankService.findRanks('', currentUser.squad.fraction).subscribe(ranks => {
 | 
					    this.rankService.findRanks('', currentUser.squad.fraction).subscribe(ranks => {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -19,15 +19,23 @@ export class UserService {
 | 
				
			||||||
    this.users$ = userStore.items$;
 | 
					    this.users$ = userStore.items$;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  findUsers(query = '', fractionFilter?, squadFilter?, limit?, offset?, action = LOAD) {
 | 
					  findUsers(filter, limit?, offset?, action = LOAD) {
 | 
				
			||||||
    const searchParams = new URLSearchParams();
 | 
					    const searchParams = new URLSearchParams();
 | 
				
			||||||
    searchParams.append('q', query);
 | 
					
 | 
				
			||||||
    if (fractionFilter) {
 | 
					    searchParams.append('q', (filter && filter.query) ? filter.query : '');
 | 
				
			||||||
      searchParams.append('fractFilter', fractionFilter);
 | 
					
 | 
				
			||||||
 | 
					    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('limit', limit);
 | 
				
			||||||
    searchParams.append('offset', offset);
 | 
					    searchParams.append('offset', offset);
 | 
				
			||||||
    this.http.get(this.config.apiUserPath, searchParams)
 | 
					    this.http.get(this.config.apiUserPath, searchParams)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,4 @@
 | 
				
			||||||
import {Component, OnInit} from '@angular/core';
 | 
					import {Component, OnInit} from '@angular/core';
 | 
				
			||||||
import {Location} from '@angular/common';
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
import {FormControl} from '@angular/forms';
 | 
					import {FormControl} from '@angular/forms';
 | 
				
			||||||
import {ActivatedRoute, Router} from '@angular/router';
 | 
					import {ActivatedRoute, Router} from '@angular/router';
 | 
				
			||||||
| 
						 | 
					@ -81,8 +80,10 @@ export class UserListComponent implements OnInit {
 | 
				
			||||||
      this.limit = 20;
 | 
					      this.limit = 20;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    this.radioModel = UIHelpers.toggleReleaseButton(this.radioModel, group);
 | 
					    this.radioModel = UIHelpers.toggleReleaseButton(this.radioModel, group);
 | 
				
			||||||
    return this.users$ = this.userService.findUsers(this.searchTerm.value, this.radioModel,
 | 
					    return this.users$ = this.userService.findUsers({
 | 
				
			||||||
      null, this.limit, this.offset, action);
 | 
					      query: this.searchTerm.value,
 | 
				
			||||||
 | 
					      fraction: this.radioModel
 | 
				
			||||||
 | 
					    }, this.limit, this.offset, action);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  onScrollDown() {
 | 
					  onScrollDown() {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue