Files
swiss-client/src/app/components/tournament-players/tournament-players.component.ts
2025-09-23 20:47:11 +02:00

97 lines
3.4 KiB
TypeScript

import {Component, inject, Input, OnInit} from '@angular/core';
import {CurrencyPipe} from "@angular/common";
import {MatSlideToggle, MatSlideToggleChange} from "@angular/material/slide-toggle";
import {TournamentService} from "../../service/tournament.service";
import {ActivatedRoute, Router} from "@angular/router";
import {Tournament} from "../../model/tournament";
import {FormsModule} from "@angular/forms";
import {MatSnackBar} from "@angular/material/snack-bar";
import {MatIcon} from "@angular/material/icon";
import {MatIconButton} from "@angular/material/button";
import {MatMenu, MatMenuItem, MatMenuTrigger} from "@angular/material/menu";
import {CourtSelectionComponent} from "../court-selection/court-selection.component";
import {MatDialog} from "@angular/material/dialog";
import {SubstituteSelectionComponent} from "../substitute-selection/substitute-selection.component";
import {TournamentPlayer} from "../../model/tournamentPlayer";
import {MatTab, MatTabGroup, MatTabLabel} from "@angular/material/tabs";
@Component({
selector: 'app-tournament-players',
imports: [
CurrencyPipe,
MatSlideToggle,
FormsModule,
MatIcon,
MatIconButton,
MatMenu,
MatMenuItem,
MatMenuTrigger,
MatTab,
MatTabGroup,
MatTabLabel
],
templateUrl: './tournament-players.component.html',
standalone: true,
styleUrl: './tournament-players.component.scss'
})
export class TournamentPlayersComponent implements OnInit {
@Input() tournament: Tournament;
constructor(
private tournamentService: TournamentService,
private _snackBar: MatSnackBar,
private route: ActivatedRoute,
private router: Router,
) {}
ngOnInit() {
console.log('Tournament received from parent:', this.tournament);
// const id = this.route.snapshot.paramMap.get('id');
// this.tournamentService.getById(Number(id)).subscribe(data => {
// this.tournament = data;
// });
}
playerPaid($event: MatSlideToggleChange, playerId: number) {
this.tournamentService.playerPaid(this.tournament.id, playerId, $event.checked).subscribe(() => {
this._snackBar.open('Opgeslagen.');
});
}
playerPresent($event: MatSlideToggleChange, playerId: number) {
this.tournamentService.playerPresent(this.tournament.id, playerId, $event.checked).subscribe(() => {
this._snackBar.open('Opgeslagen.');
});
}
substituteSelectionDialog = inject(MatDialog);
findSubstitute(player: TournamentPlayer) {
this.substituteSelectionDialog.open(SubstituteSelectionComponent, {
data: {
player: player,
availablePlayers: this.tournament.tournamentPlayers
},
minWidth: '800px',
minHeight: '250px'
}).afterClosed().subscribe(result => {
if (result != undefined) {
console.log('Substitutes selected for ' + player.name + ': ');
console.log(result.substitutions);
console.log(result.substitutions[0].event + ': ' + result.substitutions[0].substitute);
console.log(result.substitutions[1].event + ': ' + result.substitutions[1].substitute);
this.tournamentService.playerSubstitute(this.tournament.id, player.playerId, result.substitutions).subscribe(data => {
this.tournament = data;
console.log(this.tournament);
});
}
});
}
hasSubstitutes(tournamentPlayer: TournamentPlayer) {
return tournamentPlayer.substitutions.filter(s => s.substitute != null && s.substitute >= 0).length > 0;
}
}