opt-cc/static/src/app/request/confirm-promotion/confirm-promotion.component.ts

59 lines
1.8 KiB
TypeScript

import {Component} from '@angular/core';
import {Promotion, Rank} from '../../models/model-interfaces';
import {RankService} from '../../services/army-management/rank.service';
import {PromotionService} from '../../services/army-management/promotion.service';
import {LoginService} from '../../services/app-user-service/login-service';
@Component({
templateUrl: './confirm-promotion.component.html',
styleUrls: ['./confirm-promotion.component.css', '../../style/overview.css'],
})
export class ConfirmPromotionComponent {
showSuccessLabel = false;
ranks: Rank[];
promotions: Promotion[];
constructor(private rankService: RankService,
private promotionService: PromotionService,
private loginService: LoginService) {
}
ngOnInit() {
let currentUser = this.loginService.getCurrentUser();
// show only current users fraction promotions
this.rankService.findRanks('', currentUser.squad.fraction).subscribe(ranks => {
this.ranks = ranks;
});
this.promotionService.getUnconfirmedPromotions(currentUser.squad.fraction).subscribe(promotions => {
this.promotions = promotions;
})
}
confirm(promotion: Promotion, decision: boolean) {
const updateObject = {
_id: promotion._id,
confirmed: decision ? 1 : 2
};
this.promotionService.updatePromotion(updateObject).subscribe(res => {
let currentUser = this.loginService.getCurrentUser();
this.promotionService.getUnconfirmedPromotions(currentUser.squad.fraction).subscribe(promotions => {
this.promotions = promotions;
if (promotions.length < 1) {
this.promotionService.hasUnprocessedPromotion = false;
}
this.showSuccessLabel = true;
setTimeout(() => {
this.showSuccessLabel = false;
}, 2000);
});
});
}
}