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

54 lines
1.7 KiB
TypeScript
Raw Normal View History

2018-03-08 09:44:35 +01:00
import {Component, OnInit} from '@angular/core';
2018-03-07 11:56:50 +01:00
import {Award} from '../../models/model-interfaces';
import {AwardingService} from '../../services/army-management/awarding.service';
import {LoginService} from '../../services/app-user-service/login-service';
import {SnackBarService} from '../../services/user-interface/snack-bar/snack-bar.service';
2017-06-10 22:07:32 +02:00
@Component({
templateUrl: './confirm-award.component.html',
styleUrls: ['./confirm-award.component.scss'],
2017-06-10 22:07:32 +02:00
})
2018-03-08 09:44:35 +01:00
export class ConfirmAwardComponent implements OnInit {
2017-06-10 22:07:32 +02:00
awards: Award[];
2017-09-23 11:53:10 +02:00
constructor(private awardingService: AwardingService,
private loginService: LoginService,
private snackBarService: SnackBarService) {
2017-06-10 22:07:32 +02:00
}
ngOnInit() {
2018-03-08 09:44:35 +01:00
const currentUser = this.loginService.getCurrentUser();
2017-06-10 22:07:32 +02:00
this.awardingService.getUnconfirmedAwards(currentUser.squad.fraction).subscribe(awards => {
this.awards = awards;
});
}
confirm(award: Award, decision: boolean, reason: string, rejectReason: string) {
2017-06-10 22:07:32 +02:00
const updateObject = {
_id: award._id,
confirmed: decision ? 1 : 2
};
if (rejectReason) {
updateObject['rejectReason'] = rejectReason;
}
if (reason && reason !== award.reason) {
updateObject['reason'] = reason;
}
2017-06-10 22:07:32 +02:00
this.awardingService.updateAward(updateObject).subscribe(res => {
2018-03-08 09:44:35 +01:00
const currentUser = this.loginService.getCurrentUser();
2017-06-10 22:07:32 +02:00
this.awardingService.getUnconfirmedAwards(currentUser.squad.fraction).subscribe(awards => {
this.awards = awards;
if (awards.length < 1) {
this.awardingService.hasUnprocessedAwards = false;
}
2018-10-05 15:51:46 +02:00
this.snackBarService.showSuccess('generic.save.success');
2017-06-10 22:07:32 +02:00
});
});
}
}