opt-cc/static/src/app/army/army-member/army-member.component.ts

66 lines
2.2 KiB
TypeScript
Raw Normal View History

2018-03-08 09:44:35 +01:00
import {Component, Inject, OnDestroy, OnInit} from '@angular/core';
2018-07-08 13:28:21 +02:00
import {Award, User} from '../../models/model-interfaces';
2018-03-07 11:56:50 +01:00
import {ActivatedRoute, Router} from '@angular/router';
2018-07-08 13:28:21 +02:00
import {UserService} from '../../services/army-management/user.service';
2018-03-07 11:56:50 +01:00
import {Subscription} from 'rxjs/Subscription';
2018-07-08 13:28:21 +02:00
import {RouteConfig} from '../../app.config';
import {AwardingService} from '../../services/army-management/awarding.service';
import {Fraction} from '../../utils/fraction.enum';
import {DOCUMENT, Location} from '@angular/common';
2018-07-08 13:28:21 +02:00
import {CSSHelpers} from '../../utils/global.helpers';
@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 {
subscription: Subscription;
user: User = {};
awards: Award[] = [];
signatureUrl;
isCopied = false;
2017-11-08 14:54:04 +01:00
readonly fraction = Fraction;
constructor(private router: Router,
private route: ActivatedRoute,
private userService: UserService,
private awardingService: AwardingService,
private location: Location,
@Inject(DOCUMENT) private document) {
}
ngOnInit() {
// set background image css
2018-01-21 11:38:54 +01:00
this.document.getElementById('right').setAttribute('style', CSSHelpers.getBackgroundCSS('../assets/bg.jpg'));
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;
}));
});
};
ngOnDestroy() {
2018-01-21 11:38:54 +01:00
if (this.router.url !== '/' + RouteConfig.overviewPath) {
this.document.getElementById('right').setAttribute('style', '');
}
}
backToOverview() {
this.location.back();
}
}