From 43960fa3af86b74cb3597cc10e793db535f63a28 Mon Sep 17 00:00:00 2001 From: Florian Hartwich Date: Sat, 14 Oct 2017 17:47:55 +0200 Subject: [PATCH] Fix request pages --- .../promotion/req-promotion.component.html | 4 ++-- .../promotion/req-promotion.component.ts | 19 +++++++++++-------- .../app/services/user-service/user.service.ts | 10 ++++------ .../users/user-list/user-list.component.ts | 3 +-- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/static/src/app/request/promotion/req-promotion.component.html b/static/src/app/request/promotion/req-promotion.component.html index 0a43f6d..9e7307f 100644 --- a/static/src/app/request/promotion/req-promotion.component.html +++ b/static/src/app/request/promotion/req-promotion.component.html @@ -22,7 +22,7 @@
@@ -53,7 +53,7 @@ *ngIf="showForm" (click)="addPromotion()" class="btn btn-default" - [disabled]="newLevel === user.rank.level"> + [disabled]="newLevel === user.rankLvl"> Bestätigen diff --git a/static/src/app/request/promotion/req-promotion.component.ts b/static/src/app/request/promotion/req-promotion.component.ts index f542516..4d6451e 100644 --- a/static/src/app/request/promotion/req-promotion.component.ts +++ b/static/src/app/request/promotion/req-promotion.component.ts @@ -30,6 +30,8 @@ export class RequestPromotionComponent { uncheckedPromotions = []; + selectedUserRank; + constructor(private router: Router, private route: ActivatedRoute, private userService: UserService, @@ -56,7 +58,8 @@ export class RequestPromotionComponent { toggleUser() { if (this.user._id != '0') { this.showForm = true; - this.newLevel = this.user.rank.level; + this.newLevel = this.user.rankLvl; + this.selectedUserRank = this.ranks.filter(rank => rank.level === this.user.rankLvl).map(rank => rank.name); } else { this.showForm = false; } @@ -66,20 +69,20 @@ export class RequestPromotionComponent { addPromotion() { const promotion = { "userId": this.user._id, - "oldRankLvl": this.user.rank.level, + "oldRankLvl": this.user.rankLvl, "newRankLvl": this.newLevel }; this.promotionService.requestPromotion(promotion).subscribe(() => { - this.showSuccessLabel = true; - setTimeout(() => { - this.showSuccessLabel = false; - }, 2000); - this.showForm = false; - this.user = {}; let currentUser = this.loginService.getCurrentUser(); this.promotionService.getSquadPromotions(currentUser.squad._id).subscribe(promotions => { this.uncheckedPromotions = promotions; + this.showForm = false; + this.user = {_id: '0'}; + this.showSuccessLabel = true; + setTimeout(() => { + this.showSuccessLabel = false; + }, 2000); }) }); } diff --git a/static/src/app/services/user-service/user.service.ts b/static/src/app/services/user-service/user.service.ts index 7a91bb9..a1996d2 100644 --- a/static/src/app/services/user-service/user.service.ts +++ b/static/src/app/services/user-service/user.service.ts @@ -19,7 +19,7 @@ export class UserService { this.users$ = userStore.items$; } - findUsers(query = '', fractionFilter?, squadFilter?, limit?, offset?, action?) { + findUsers(query = '', fractionFilter?, squadFilter?, limit?, offset?, action = LOAD) { const searchParams = new URLSearchParams(); searchParams.append('q', query); if (fractionFilter) { @@ -33,14 +33,12 @@ export class UserService { this.http.get(this.config.apiUserPath, searchParams) .do((res) => { let headerCount = parseInt(res.headers.get('x-total-count')); - console.log(headerCount) if (headerCount) { this.totalCount = headerCount; } - let users = res.json(); - this.userStore.dispatch({type: action, data: users}); - }).subscribe(_ => { - }); + }).map(res => res.json()).do((users) => { + this.userStore.dispatch({type: action, data: users}); + }).subscribe(_ => {}); return this.users$; } diff --git a/static/src/app/users/user-list/user-list.component.ts b/static/src/app/users/user-list/user-list.component.ts index 6a9e41e..b334813 100644 --- a/static/src/app/users/user-list/user-list.component.ts +++ b/static/src/app/users/user-list/user-list.component.ts @@ -79,8 +79,7 @@ export class UserListComponent implements OnInit { } filterUsers(action?) { - if (!action || (action && action === LOAD)) { - action = LOAD; + if (!action || action === LOAD) { this.offset = 0; this.limit = 20; }