2018-03-08 09:44:35 +01:00
|
|
|
import {Component, Inject, OnDestroy, OnInit} from '@angular/core';
|
2018-03-07 11:56:50 +01:00
|
|
|
import {Award, User} from '../models/model-interfaces';
|
|
|
|
import {ActivatedRoute, Router} from '@angular/router';
|
|
|
|
import {UserService} from '../services/army-management/user.service';
|
|
|
|
import {Subscription} from 'rxjs/Subscription';
|
|
|
|
import {RouteConfig} from '../app.config';
|
|
|
|
import {AwardingService} from '../services/army-management/awarding.service';
|
|
|
|
import {Fraction} from '../utils/fraction.enum';
|
|
|
|
import {DOCUMENT} from '@angular/common';
|
|
|
|
import {CSSHelpers} from '../global.helpers';
|
2017-05-18 14:32:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'army-member',
|
|
|
|
templateUrl: './army-member.component.html',
|
|
|
|
styleUrls: ['./army-member.component.css']
|
|
|
|
})
|
2018-03-08 09:44:35 +01:00
|
|
|
export class ArmyMemberComponent implements OnInit, OnDestroy {
|
2017-05-18 14:32:51 +02:00
|
|
|
|
|
|
|
subscription: Subscription;
|
|
|
|
|
|
|
|
user: User = {};
|
|
|
|
|
2017-10-14 19:58:34 +02:00
|
|
|
awards: Award[] = [];
|
|
|
|
|
2017-05-19 00:45:43 +02:00
|
|
|
signatureUrl;
|
|
|
|
|
|
|
|
isCopied = false;
|
|
|
|
|
2017-11-08 14:54:04 +01:00
|
|
|
readonly fraction = Fraction;
|
|
|
|
|
2017-05-18 14:32:51 +02:00
|
|
|
constructor(private router: Router,
|
|
|
|
private route: ActivatedRoute,
|
2017-10-14 19:58:34 +02:00
|
|
|
private userService: UserService,
|
2018-01-16 19:46:28 +01:00
|
|
|
private awardingService: AwardingService,
|
|
|
|
@Inject(DOCUMENT) private document) {
|
2017-05-18 14:32:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
2018-01-16 19:46:28 +01:00
|
|
|
// set background image css
|
2018-01-21 11:38:54 +01:00
|
|
|
this.document.getElementById('right').setAttribute('style', CSSHelpers.getBackgroundCSS('../assets/bg.jpg'));
|
2018-01-16 19:46:28 +01:00
|
|
|
|
2017-05-18 14:32:51 +02:00
|
|
|
this.subscription = this.route.params
|
2018-02-26 09:04:27 +01:00
|
|
|
.map(params => params['id'])
|
2018-03-08 09:44:35 +01:00
|
|
|
.filter(id => id !== undefined)
|
2018-02-26 09:04:27 +01:00
|
|
|
.flatMap(id => this.userService.getUser(id))
|
|
|
|
.subscribe(user => {
|
|
|
|
this.user = user;
|
|
|
|
this.signatureUrl = window.location.origin + '/resource/signature/' + user._id + '.png';
|
|
|
|
this.awardingService.getUserAwardings(user._id).subscribe((awards => {
|
|
|
|
this.awards = awards;
|
|
|
|
}));
|
|
|
|
});
|
2017-05-18 14:32:51 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2018-01-16 19:46:28 +01:00
|
|
|
ngOnDestroy() {
|
2018-01-21 11:38:54 +01:00
|
|
|
if (this.router.url !== '/' + RouteConfig.overviewPath) {
|
|
|
|
this.document.getElementById('right').setAttribute('style', '');
|
|
|
|
}
|
2018-01-16 19:46:28 +01:00
|
|
|
}
|
|
|
|
|
2017-05-18 14:32:51 +02:00
|
|
|
backToOverview() {
|
2017-08-01 23:52:10 +02:00
|
|
|
this.router.navigate([RouteConfig.overviewPath]);
|
2017-05-18 14:32:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|