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

59 lines
1.8 KiB
TypeScript
Raw Normal View History

import {Component} from "@angular/core";
import {Promotion, Rank} from "../../models/model-interfaces";
2017-10-22 18:06:37 +02:00
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";
2017-06-10 22:07:32 +02:00
@Component({
templateUrl: './confirm-promotion.component.html',
styleUrls: ['./confirm-promotion.component.css', '../../style/overview.css'],
2017-06-10 22:07:32 +02:00
})
export class ConfirmPromotionComponent {
showSuccessLabel = false;
ranks: Rank[];
promotions: Promotion[];
2017-06-10 22:07:32 +02:00
constructor(private rankService: RankService,
2017-09-23 11:53:10 +02:00
private promotionService: PromotionService,
private loginService: LoginService) {
2017-06-10 22:07:32 +02:00
}
ngOnInit() {
2017-09-23 11:53:10 +02:00
let currentUser = this.loginService.getCurrentUser();
// show only current users fraction promotions
2017-06-10 22:07:32 +02:00
this.rankService.findRanks('', currentUser.squad.fraction).subscribe(ranks => {
this.ranks = ranks;
});
this.promotionService.getUnconfirmedPromotions(currentUser.squad.fraction).subscribe(promotions => {
this.promotions = promotions;
2017-06-10 22:07:32 +02:00
})
}
confirm(promotion: Promotion, decision: boolean) {
const updateObject = {
_id: promotion._id,
confirmed: decision ? 1 : 2
2017-06-10 22:07:32 +02:00
};
this.promotionService.updatePromotion(updateObject).subscribe(res => {
2017-09-23 11:53:10 +02:00
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);
});
});
2017-06-10 22:07:32 +02:00
}
}