opt-cc/static/src/app/pub/trace-overview/trace-overview.component.ts

76 lines
2.6 KiB
TypeScript

import {Component, Inject, OnDestroy, OnInit} from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router';
import {DOCUMENT} from '@angular/common';
import {Fraction} from '../../utils/fraction.enum';
import {CSSHelpers} from '../../utils/global.helpers';
import {RouteConfig} from '../../app.config';
import {Decoration, Rank, User} from '../../models/model-interfaces';
import {UserService} from '../../services/army-management/user.service';
import {RankService} from '../../services/army-management/rank.service';
import {DecorationService} from '../../services/army-management/decoration.service';
@Component({
selector: 'cc-trace-overview',
templateUrl: './trace-overview.component.html',
styleUrls: ['./trace-overview.component.css']
})
export class TraceOverviewComponent implements OnInit, OnDestroy {
traceItem: Rank | Decoration = {};
users: User[];
isRank = true;
displayedColumns: string[] = ['name', 'fraction', 'squadName'];
readonly fraction = Fraction;
constructor(private router: Router,
private route: ActivatedRoute,
private userService: UserService,
private rankService: RankService,
private decorationService: DecorationService,
@Inject(DOCUMENT) private document) {
}
ngOnInit() {
// set background image css
this.document.getElementById('right').setAttribute('style', CSSHelpers.getBackgroundCSS('../assets/bg.jpg'));
this.route.params.subscribe(params => {
const itemId = params.id;
if (this.router.url.includes('find/award/')) {
// Award
this.isRank = false;
this.decorationService.getDecoration(itemId).subscribe(decoration => {
this.traceItem = decoration;
this.userService.findUsers({decorationId: decoration._id}).subscribe(users => {
this.users = users.filter(user => user.squadId != null);
});
});
} else if (this.router.url.includes('find/rank/')) {
// Rank
this.isRank = true;
this.rankService.getRank(itemId).subscribe(rank => {
this.traceItem = rank;
this.userService.findUsers({fraction: rank.fraction}).subscribe(users => {
this.users = users.filter(user => user.squadId != null && user.rankLvl === rank.level);
});
});
}
});
};
selectUser(user) {
this.router.navigate(['overview', {outlets: {'right': ['member', user._id]}}]);
}
ngOnDestroy() {
if (!this.router.url.includes(RouteConfig.overviewPath)) {
this.document.getElementById('right').setAttribute('style', '');
}
}
}