All checks were successful
Gitea/swiss-client/pipeline/head This commit looks good
68 lines
2.1 KiB
TypeScript
68 lines
2.1 KiB
TypeScript
import {Component, OnDestroy, OnInit} from '@angular/core';
|
|
import {ActivatedRoute, NavigationEnd, Router, RouterLink, RouterOutlet} from '@angular/router';
|
|
import {CommonModule, NgOptimizedImage} from "@angular/common";
|
|
import {MatAnchor, MatButton} from "@angular/material/button";
|
|
import {MatIcon} from "@angular/material/icon";
|
|
import {MatToolbar} from "@angular/material/toolbar";
|
|
import {filter, map, Subscription} from "rxjs";
|
|
import {MatMenu, MatMenuItem, MatMenuTrigger} from "@angular/material/menu";
|
|
import {UserService} from "./authentication/user.service";
|
|
import {TournamentService} from "./service/tournament.service";
|
|
import {HeaderService} from "./service/header.service";
|
|
|
|
@Component({
|
|
selector: 'app-root',
|
|
imports: [RouterOutlet, CommonModule, RouterLink, MatAnchor, MatIcon, MatButton, MatToolbar, NgOptimizedImage, MatMenuTrigger, MatMenu, MatMenuItem],
|
|
templateUrl: './app.component.html',
|
|
styleUrl: './app.component.scss'
|
|
})
|
|
export class AppComponent implements OnInit {
|
|
|
|
header: string;
|
|
user: string;
|
|
userSubscription: Subscription;
|
|
|
|
constructor(
|
|
protected userService: UserService,
|
|
private router: Router,
|
|
protected activatedRoute: ActivatedRoute,
|
|
private tournamentService: TournamentService,
|
|
private headerService: HeaderService
|
|
) {
|
|
}
|
|
|
|
ngOnInit() {
|
|
this.userSubscription = this.userService.currentUser.subscribe(newUser => this.user = newUser);
|
|
|
|
this.router.events.pipe(
|
|
filter(event => event instanceof NavigationEnd),
|
|
map(() => {
|
|
let currentRoute = this.activatedRoute;
|
|
while (currentRoute.firstChild) {
|
|
currentRoute = currentRoute.firstChild;
|
|
}
|
|
return currentRoute.snapshot.data['header'] || '';
|
|
})
|
|
).subscribe(header => {
|
|
this.header = header;
|
|
});
|
|
|
|
this.headerService.header$.subscribe(override => {
|
|
if (override) {
|
|
this.header = override;
|
|
}
|
|
});
|
|
}
|
|
|
|
logOut() {
|
|
this.userService.removeUser();
|
|
this.router.navigate(['/auth/login']);
|
|
}
|
|
|
|
addTestData() {
|
|
this.tournamentService.addTestData().subscribe(data => {
|
|
this.router.navigate(['/tournaments']);
|
|
})
|
|
}
|
|
}
|