import {Component} from "@angular/core"; import {Promotion, Rank} from "../../models/model-interfaces"; import {RankService} from "../../services/rank-service/rank.service"; import {PromotionService} from "../../services/promotion-service/promotion.service"; import {LoginService} from "../../services/login-service/login-service"; @Component({ templateUrl: './confirm-promotion.component.html', styleUrls: ['./confirm-promotion.component.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); }); }); } }