Prevent match containing active players from being started

This commit is contained in:
Michel ten Voorde
2024-12-10 21:58:49 +01:00
parent 2fdc2e9f56
commit 76b9cfbc91

View File

@@ -2,7 +2,6 @@ import {Component, inject, Input, OnInit} from '@angular/core';
import {
MatAccordion,
MatExpansionPanel,
MatExpansionPanelDescription,
MatExpansionPanelHeader,
MatExpansionPanelTitle
} from "@angular/material/expansion";
@@ -13,14 +12,10 @@ import {TournamentService} from "../../service/tournament.service";
import {ActivatedRoute, Router} from "@angular/router";
import {Tournament} from "../../model/tournament";
import {FullNamePipe} from "../../pipes/fullname-pipe";
import {MatList, MatListItem} from "@angular/material/list";
import {MatDivider} from "@angular/material/divider";
import {MatAnchor, MatButton, MatIconAnchor, MatIconButton, MatMiniFabAnchor} from "@angular/material/button";
import {MatButton, MatIconButton} from "@angular/material/button";
import {MatIcon} from "@angular/material/icon";
import {Group} from "../../model/group";
import {Round} from "../../model/round";
import {MatTable} from "@angular/material/table";
import {StatusPipe} from "../../pipes/status-pipe";
import {MatMenu, MatMenuContent, MatMenuItem, MatMenuTrigger} from "@angular/material/menu";
import {Match} from "../../model/match";
import {FormsModule} from "@angular/forms";
@@ -48,19 +43,12 @@ import {TitleService} from "../../service/title.service";
MatCardContent,
MatCardHeader,
MatExpansionPanel,
MatExpansionPanelDescription,
MatExpansionPanelHeader,
MatExpansionPanelTitle,
NgForOf,
NgIf,
TeamPipe,
MatListItem,
MatDivider,
MatList,
MatAnchor,
MatIcon,
MatTable,
StatusPipe,
NgClass,
MatMenu,
MatMenuItem,
@@ -71,9 +59,6 @@ import {TitleService} from "../../service/title.service";
MatTab,
MatTabLabel,
MatButton,
MatchResultPipe,
MatIconAnchor,
MatMiniFabAnchor,
MatIconButton,
DecimalPipe,
TournamentValidateComponent,
@@ -195,8 +180,11 @@ export class TournamentManageComponent implements OnInit {
startMatch(match: Match) {
const availableCourts = this.getAvailableCourts();
if (availableCourts.length == 0) {
alert('Geen banen beschikbaar!');
} else if (this.matchContainsPlayersThatArePlaying(match)) {
alert('Deze wedstrijd bevat spelers die al aan het spelen zijn!');
} else {
this.courtSelectionDialog.open(CourtSelectionComponent, {
data: {
@@ -216,6 +204,23 @@ export class TournamentManageComponent implements OnInit {
}
}
matchContainsPlayersThatArePlaying(match: Match): boolean {
let activePlayers: number[] = [];
for (let activeMatch of this.activeMatches()) {
activePlayers.push(activeMatch.match.team1.player1.id);
if (activeMatch.match.team1.player2) activePlayers.push(activeMatch.match.team1.player2.id);
activePlayers.push(activeMatch.match.team2.player1.id);
if (activeMatch.match.team2.player2) activePlayers.push(activeMatch.match.team2.player2.id);
}
let matchPlayers: number[] = [];
matchPlayers.push(match.team1.player1.id);
if (match.team1.player2) matchPlayers.push(match.team1.player2.id);
matchPlayers.push(match.team2.player1.id);
if (match.team2.player2) matchPlayers.push(match.team2.player2.id);
let playersThatArePlaying = activePlayers.filter(Set.prototype.has, new Set(matchPlayers));
return playersThatArePlaying.length > 0;
}
getAvailableCourts(): number[] {
const maxCourts = this.tournament.courts;
const activeCourts = this.activeMatches().map(activeMatch => activeMatch.match.court);