From 929fd6b5814805c8a4fb13265f580d99bcfe6589 Mon Sep 17 00:00:00 2001 From: Michel ten Voorde Date: Wed, 10 Sep 2025 10:35:15 +0200 Subject: [PATCH] WIP: substitutions --- .../substitute-selection.component.html | 23 ++++++++++ .../substitute-selection.component.scss | 0 .../substitute-selection.component.ts | 46 +++++++++++++++++++ .../tournament-players.component.html | 17 +++++++ .../tournament-players.component.ts | 37 ++++++++++++++- src/app/service/tournament.service.ts | 4 ++ 6 files changed, 125 insertions(+), 2 deletions(-) create mode 100644 src/app/components/substitute-selection/substitute-selection.component.html create mode 100644 src/app/components/substitute-selection/substitute-selection.component.scss create mode 100644 src/app/components/substitute-selection/substitute-selection.component.ts diff --git a/src/app/components/substitute-selection/substitute-selection.component.html b/src/app/components/substitute-selection/substitute-selection.component.html new file mode 100644 index 0000000..c103a6d --- /dev/null +++ b/src/app/components/substitute-selection/substitute-selection.component.html @@ -0,0 +1,23 @@ + +

Kies een invaller voor {{ data.player.name }}:

+ +
+ + Invaller + + Geen + @for (player of data.availablePlayers; track player.playerId) { + + {{ player.name }} + + } + + +
+
+ + @if (substitute) { + + } + + diff --git a/src/app/components/substitute-selection/substitute-selection.component.scss b/src/app/components/substitute-selection/substitute-selection.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/src/app/components/substitute-selection/substitute-selection.component.ts b/src/app/components/substitute-selection/substitute-selection.component.ts new file mode 100644 index 0000000..47a2f7b --- /dev/null +++ b/src/app/components/substitute-selection/substitute-selection.component.ts @@ -0,0 +1,46 @@ +import {Component, inject, Inject} from '@angular/core'; +import {MatButton} from "@angular/material/button"; +import { + MAT_DIALOG_DATA, + MatDialogActions, + MatDialogClose, + MatDialogContent, + MatDialogRef +} from "@angular/material/dialog"; +import {MatFormField} from "@angular/material/form-field"; +import {MatLabel} from "@angular/material/form-field"; +import {MatOption, MatSelect} from "@angular/material/select"; +import {TournamentPlayer} from "../../model/tournamentPlayer"; +import {FormsModule} from "@angular/forms"; + +@Component({ + selector: 'app-substitute-selection', + imports: [ + MatButton, + MatDialogActions, + MatDialogContent, + MatFormField, + MatLabel, + MatOption, + MatSelect, + FormsModule, + MatDialogClose + ], + templateUrl: './substitute-selection.component.html', + styleUrl: './substitute-selection.component.scss' +}) +export class SubstituteSelectionComponent { + + substitute: TournamentPlayer; + + readonly dialogRef = inject(MatDialogRef); + + constructor(@Inject(MAT_DIALOG_DATA) public data: { + player: TournamentPlayer, + availablePlayers: TournamentPlayer[] + }) {} + + onAnnulerenClick() { + this.dialogRef.close(); + } +} diff --git a/src/app/components/tournament-players/tournament-players.component.html b/src/app/components/tournament-players/tournament-players.component.html index c38aed2..78b2c47 100644 --- a/src/app/components/tournament-players/tournament-players.component.html +++ b/src/app/components/tournament-players/tournament-players.component.html @@ -11,6 +11,7 @@ Betaald @if (tournament.status == 'ONGOING') { Aanwezig + } @@ -48,6 +49,22 @@ } + + + + + + + + } } diff --git a/src/app/components/tournament-players/tournament-players.component.ts b/src/app/components/tournament-players/tournament-players.component.ts index 2360c9f..200af39 100644 --- a/src/app/components/tournament-players/tournament-players.component.ts +++ b/src/app/components/tournament-players/tournament-players.component.ts @@ -1,4 +1,4 @@ -import {Component, Input, OnInit} from '@angular/core'; +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"; @@ -6,13 +6,25 @@ 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"; @Component({ selector: 'app-tournament-players', imports: [ CurrencyPipe, MatSlideToggle, - FormsModule + FormsModule, + MatIcon, + MatIconButton, + MatMenu, + MatMenuItem, + MatMenuTrigger ], templateUrl: './tournament-players.component.html', standalone: true, @@ -49,4 +61,25 @@ export class TournamentPlayersComponent implements OnInit { }); } + 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('Substitute selected for ' + player.name + ', namely: ' + result.substitute.name); + this.tournamentService.startMatch(this.tournament.id, match.id, result.court, result.counter.playerId).subscribe(data => { + this.tournament = data; + }); + } + }); + + } + } diff --git a/src/app/service/tournament.service.ts b/src/app/service/tournament.service.ts index 71e1cce..9c538b1 100644 --- a/src/app/service/tournament.service.ts +++ b/src/app/service/tournament.service.ts @@ -92,6 +92,10 @@ export class TournamentService { return this.http.patch(`${this.tournamentsUrl}/${tournamentId}/players/${playerId}/present/${paid}`, null); } + public playerSubstitute(tournamentId: number, playerId: number, substituteId: number): Observable { + return this.http.post(`${this.tournamentsUrl}/${tournamentId}/players/${playerId}/substitute/${substituteId}`, null) + } + public addTestData(): Observable { return this.http.get(`${environment.backendUrl}/testdata`); }