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

50 lines
1.3 KiB
TypeScript
Raw Normal View History

2017-06-10 22:07:32 +02:00
import {Component} from "@angular/core";
import {ActivatedRoute, Router} from "@angular/router";
import {Award} from "../../models/model-interfaces";
import {AwardingService} from "../../services/awarding-service/awarding.service";
@Component({
templateUrl: './confirm-award.component.html',
styleUrls: ['./confirm-award.component.css'],
})
export class ConfirmAwardComponent {
2017-06-10 22:07:32 +02:00
awards: Award[];
showSuccessLabel = false;
2017-06-10 22:07:32 +02:00
constructor(private router: Router,
private route: ActivatedRoute,
private awardingService: AwardingService) {
}
ngOnInit() {
let currentUser = JSON.parse(localStorage.getItem('currentUser'));
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 = JSON.parse(localStorage.getItem('currentUser'));
this.awardingService.getUnconfirmedAwards(currentUser.squad.fraction).subscribe(awards => {
this.awards = awards;
this.showSuccessLabel = true;
setTimeout(() => {
this.showSuccessLabel = false;
}, 2000);
2017-06-10 22:07:32 +02:00
});
});
}
}