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

51 lines
1.5 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 {Rank} from '../../models/model-interfaces';
import {RankService} from '../../services/army-management/rank.service';
@Component({
selector: 'cc-rank-overview',
templateUrl: './rank-overview.component.html',
styleUrls: ['./rank-overview.component.css']
})
export class RankOverviewComponent implements OnInit, OnDestroy {
ranksOpfor: Rank[];
ranksBlufor: Rank[];
displayedColumns: string[] = ['picture', 'name'];
readonly fraction = Fraction;
constructor(private router: Router,
private route: ActivatedRoute,
private rankService: RankService,
@Inject(DOCUMENT) private document) {
}
ngOnInit() {
// set background image css
this.document.getElementById('right').setAttribute('style', CSSHelpers.getBackgroundCSS('../assets/bg.jpg'));
// init rank data
this.rankService.findRanks()
.subscribe(ranks => {
this.ranksBlufor = ranks.filter(r => r.fraction === 'BLUFOR');
this.ranksOpfor = ranks.filter(r => r.fraction === 'OPFOR');
});
};
ngOnDestroy() {
if (!this.router.url.includes(RouteConfig.overviewPath)) {
this.document.getElementById('right').setAttribute('style', '');
}
}
}