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

51 lines
1.4 KiB
TypeScript

import {Component} from '@angular/core';
import {Award} from '../../models/model-interfaces';
import {AwardingService} from '../../services/army-management/awarding.service';
import {LoginService} from '../../services/app-user-service/login-service';
@Component({
templateUrl: './confirm-award.component.html',
styleUrls: ['./confirm-award.component.css', '../../style/overview.css'],
})
export class ConfirmAwardComponent {
awards: Award[];
showSuccessLabel = false;
constructor(private awardingService: AwardingService,
private loginService: LoginService) {
}
ngOnInit() {
let currentUser = this.loginService.getCurrentUser();
this.awardingService.getUnconfirmedAwards(currentUser.squad.fraction).subscribe(awards => {
this.awards = awards;
});
}
confirm(award: Award, decision: boolean) {
const updateObject = {
_id: award._id,
confirmed: decision ? 1 : 2
};
this.awardingService.updateAward(updateObject).subscribe(res => {
let currentUser = this.loginService.getCurrentUser();
this.awardingService.getUnconfirmedAwards(currentUser.squad.fraction).subscribe(awards => {
this.awards = awards;
if (awards.length < 1) {
this.awardingService.hasUnprocessedAwards = false;
}
this.showSuccessLabel = true;
setTimeout(() => {
this.showSuccessLabel = false;
}, 2000);
});
});
}
}