81 lines
2.7 KiB
TypeScript
81 lines
2.7 KiB
TypeScript
import {Component, Inject, OnDestroy, OnInit} from '@angular/core';
|
|
import {ActivatedRoute, Router} from '@angular/router';
|
|
import {DOCUMENT, Location} 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 location: Location,
|
|
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]}}]);
|
|
}
|
|
|
|
navigateBack() {
|
|
this.location.back();
|
|
}
|
|
|
|
ngOnDestroy() {
|
|
if (!this.router.url.includes(RouteConfig.overviewPath)) {
|
|
this.document.getElementById('right').setAttribute('style', '');
|
|
}
|
|
}
|
|
}
|