import {Component} from "@angular/core"; import {Award} from "../../models/model-interfaces"; import {AwardingService} from "../../services/awarding-service/awarding.service"; import {LoginService} from "../../services/login-service/login-service"; @Component({ templateUrl: './confirm-award.component.html', styleUrls: ['./confirm-award.component.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); }); }); } }