Moved logic to backend
All checks were successful
Gitea/swiss-client/pipeline/head This commit looks good
All checks were successful
Gitea/swiss-client/pipeline/head This commit looks good
This commit is contained in:
@@ -130,9 +130,21 @@
|
||||
<mat-expansion-panel>
|
||||
<mat-expansion-panel-header>
|
||||
<div class="col-md-2">Baan {{ activeMatch.match.court }}</div>
|
||||
<div class="col-md-3">{{ activeMatch.match.team1 | teamText }}</div>
|
||||
<div class="col-md-3">
|
||||
<app-team-display
|
||||
[team]="activeMatch.match.team1"
|
||||
[event]="activeMatch.event"
|
||||
[tournament]="this.tournament">
|
||||
</app-team-display>
|
||||
</div>
|
||||
<div class="col-md-1">-</div>
|
||||
<div class="col-md-3">{{ activeMatch.match.team2 | teamText }}</div>
|
||||
<div class="col-md-3">
|
||||
<app-team-display
|
||||
[team]="activeMatch.match.team2"
|
||||
[event]="activeMatch.event"
|
||||
[tournament]="this.tournament">
|
||||
</app-team-display>
|
||||
</div>
|
||||
<div class="col-md-3">{{ activeMatch.group.name }} {{ activeMatch.round.name }}</div>
|
||||
</mat-expansion-panel-header>
|
||||
<div class="row">
|
||||
|
||||
@@ -64,7 +64,6 @@ import {TeamDisplayComponent} from "../team-display/team-display.component";
|
||||
TournamentValidateComponent,
|
||||
TournamentPlayersComponent,
|
||||
MatExpansionPanelActionRow,
|
||||
MatTooltip,
|
||||
TeamDisplayComponent,
|
||||
],
|
||||
providers: [
|
||||
@@ -224,36 +223,43 @@ export class TournamentManageComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
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;
|
||||
matchPlayers.push(this.getTournamentPlayerFromPlayer(match.team1.player1).id);
|
||||
if (match.team1.player2) matchPlayers.push(this.getTournamentPlayerFromPlayer(match.team1.player2).id);
|
||||
matchPlayers.push(this.getTournamentPlayerFromPlayer(match.team2.player1).id);
|
||||
if (match.team2.player2) matchPlayers.push(this.getTournamentPlayerFromPlayer(match.team2.player2).id);
|
||||
|
||||
let matchPlayersThatArePlaying = this.tournament.playersPlaying.filter(Set.prototype.has, new Set(matchPlayers));
|
||||
return matchPlayersThatArePlaying.length > 0;
|
||||
}
|
||||
|
||||
matchContainsPlayersThatAreCounting(match: Match): boolean {
|
||||
let currentCounters: number[] = [];
|
||||
for (let activeMatch of this.activeMatches()) {
|
||||
currentCounters.push(activeMatch.match.counter.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);
|
||||
matchPlayers.push(this.getTournamentPlayerFromPlayer(match.team1.player1).id);
|
||||
if (match.team1.player2) matchPlayers.push(this.getTournamentPlayerFromPlayer(match.team1.player2).id);
|
||||
matchPlayers.push(this.getTournamentPlayerFromPlayer(match.team2.player1).id);
|
||||
if (match.team2.player2) matchPlayers.push(this.getTournamentPlayerFromPlayer(match.team2.player2).id);
|
||||
|
||||
let playersThatAreCounting = currentCounters.filter(Set.prototype.has, new Set(matchPlayers));
|
||||
return playersThatAreCounting.length > 0;
|
||||
let matchPlayersThatAreCounting = this.tournament.playersCounting.filter(Set.prototype.has, new Set(matchPlayers));
|
||||
return matchPlayersThatAreCounting.length > 0;
|
||||
}
|
||||
|
||||
getTournamentPlayerFromPlayer(player: Player): TournamentPlayer {
|
||||
for (let tournamentPlayer of this.tournament.tournamentPlayers) {
|
||||
if (tournamentPlayer.playerId == player.id) {
|
||||
return tournamentPlayer;
|
||||
}
|
||||
}
|
||||
return null!;
|
||||
}
|
||||
|
||||
getTournamentPlayerFromId(tournamentPlayerId: number): TournamentPlayer {
|
||||
for (let tournamentPlayer of this.tournament.tournamentPlayers) {
|
||||
if (tournamentPlayer.id == tournamentPlayerId) {
|
||||
return tournamentPlayer;
|
||||
}
|
||||
}
|
||||
return null!;
|
||||
}
|
||||
|
||||
getAvailableCourts(): number[] {
|
||||
@@ -267,28 +273,33 @@ export class TournamentManageComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
getAvailableCounters(match: Match): TournamentPlayer[] {
|
||||
const activePlayerIds = new Set(
|
||||
this.activeMatches().flatMap(activeMatch => [
|
||||
activeMatch.match.team1.player1.id,
|
||||
activeMatch.match.team1.player2?.id,
|
||||
activeMatch.match.team2.player1.id,
|
||||
activeMatch.match.team2.player2?.id
|
||||
].filter(id => id !== undefined))
|
||||
);
|
||||
const matchPlayers: number[] = [];
|
||||
matchPlayers.push(this.getPlayerOrSubstitute(match.team1.player1, match.type).id);
|
||||
if (match.team1.player2) matchPlayers.push(this.getPlayerOrSubstitute(match.team1.player2, match.type).id);
|
||||
matchPlayers.push(this.getPlayerOrSubstitute(match.team2.player1, match.type).id);
|
||||
if (match.team2.player2) matchPlayers.push(this.getPlayerOrSubstitute(match.team2.player2, match.type).id);
|
||||
|
||||
const playerIdsInMatchToBeStarted = new Set([
|
||||
match.team1.player1.id,
|
||||
match.team1.player2?.id,
|
||||
match.team2.player1.id,
|
||||
match.team2.player2?.id
|
||||
].filter(id => id !== undefined));
|
||||
const counterIds = this.tournament.playersAvailable.filter(player => !matchPlayers.includes(player));
|
||||
|
||||
return this.tournament.tournamentPlayers.filter(
|
||||
player =>
|
||||
!player.counting
|
||||
&& !activePlayerIds.has(player.playerId)
|
||||
&& !playerIdsInMatchToBeStarted.has(player.playerId)
|
||||
return counterIds.map(id => this.getTournamentPlayerFromId(id));
|
||||
}
|
||||
|
||||
getPlayerOrSubstitute(player: Player, type: String): TournamentPlayer {
|
||||
return this.getSubstituteForEvent(player, type) || this.getTournamentPlayerFromPlayer(player);
|
||||
}
|
||||
|
||||
getSubstituteForEvent(player: Player, type: String): TournamentPlayer | undefined {
|
||||
const tournamentPlayer = this.tournament.tournamentPlayers.find(
|
||||
tp => tp.playerId === player.id
|
||||
);
|
||||
if (!tournamentPlayer) return undefined;
|
||||
|
||||
const substitution = tournamentPlayer.substitutions.find(
|
||||
s => s.event === type
|
||||
);
|
||||
if (!substitution) return undefined;
|
||||
|
||||
return this.getTournamentPlayerFromId(substitution.substitute);
|
||||
}
|
||||
|
||||
stopMatch(match: Match) {
|
||||
@@ -326,7 +337,7 @@ export class TournamentManageComponent implements OnInit, OnDestroy {
|
||||
for (const round of group.rounds) {
|
||||
for (const match of round.matches) {
|
||||
if (match.status == 'IN_PROGRESS') {
|
||||
matches.push(new ActiveMatch(match, round, group));
|
||||
matches.push(new ActiveMatch(match, round, group, event));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -420,13 +431,15 @@ export class TournamentManageComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
class ActiveMatch {
|
||||
constructor(match: Match, round: Round, group: Group) {
|
||||
constructor(match: Match, round: Round, group: Group, event: Event) {
|
||||
this.match = match;
|
||||
this.round = round;
|
||||
this.group = group;
|
||||
this.event = event;
|
||||
}
|
||||
|
||||
match: Match;
|
||||
round: Round;
|
||||
group: Group;
|
||||
event: Event;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,9 @@ export class Tournament {
|
||||
costsPerEvent: number[] = [10, 20, 0];
|
||||
courts: number;
|
||||
active: boolean;
|
||||
playersPlaying: number[];
|
||||
playersCounting: number[];
|
||||
playersAvailable: number[];
|
||||
|
||||
static getStatus(tournament: Tournament): string {
|
||||
if (tournament.status == "CLOSED") return "Afgerond";
|
||||
|
||||
Reference in New Issue
Block a user