55 lines
2.1 KiB
TypeScript
55 lines
2.1 KiB
TypeScript
|
import {Component, Inject, OnInit} from '@angular/core';
|
||
|
import {MAT_BOTTOM_SHEET_DATA, MatBottomSheetRef} from '@angular/material';
|
||
|
import {RankOverviewComponent} from '../rank-overview/rank-overview.component';
|
||
|
import {ActivatedRoute, Router} from '@angular/router';
|
||
|
import {RankService} from '../../services/army-management/rank.service';
|
||
|
import {DecorationService} from '../../services/army-management/decoration.service';
|
||
|
import {UserService} from '../../services/army-management/user.service';
|
||
|
import {User} from '../../models/model-interfaces';
|
||
|
import {Fraction} from '../../utils/fraction.enum';
|
||
|
|
||
|
@Component({
|
||
|
selector: 'cc-user-list-sheet',
|
||
|
templateUrl: 'user-list-sheet.component.html',
|
||
|
})
|
||
|
export class UserListSheetComponent implements OnInit {
|
||
|
|
||
|
users: User[];
|
||
|
|
||
|
readonly fraction = Fraction;
|
||
|
|
||
|
constructor(private router: Router,
|
||
|
private route: ActivatedRoute,
|
||
|
private userService: UserService,
|
||
|
private rankService: RankService,
|
||
|
private decorationService: DecorationService,
|
||
|
private bottomSheetRef: MatBottomSheetRef<RankOverviewComponent>,
|
||
|
@Inject(MAT_BOTTOM_SHEET_DATA) public data: any) {
|
||
|
}
|
||
|
|
||
|
ngOnInit() {
|
||
|
if (this.data.decoration) {
|
||
|
const itemId = this.data.decoration._id;
|
||
|
this.decorationService.getDecoration(itemId).subscribe(decoration => {
|
||
|
this.userService.findUsers({decorationId: decoration._id}).subscribe(users => {
|
||
|
this.users = users.filter(user => user.squadId != null);
|
||
|
});
|
||
|
});
|
||
|
} else if (this.data.rank) {
|
||
|
// Rank
|
||
|
const itemId = this.data.rank._id;
|
||
|
this.rankService.getRank(itemId).subscribe(rank => {
|
||
|
this.userService.findUsers({fraction: rank.fraction}).subscribe(users => {
|
||
|
this.users = users.filter(user => user.squadId != null && user.rankLvl === rank.level);
|
||
|
});
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
|
||
|
selectUser(user) {
|
||
|
this.bottomSheetRef.dismiss();
|
||
|
event.preventDefault();
|
||
|
this.router.navigate(['overview', {outlets: {'right': ['member', user._id]}}]);
|
||
|
}
|
||
|
}
|