Use Player Links & match count

This commit is contained in:
2024-11-14 00:00:33 +01:00
parent b48623f77e
commit 5a4e7f89e1
7 changed files with 114 additions and 4 deletions

View File

@@ -0,0 +1,21 @@
@if (this.message_parts[0]) {
{{ this.message_parts[0] }}
} @else { }
@if (this.player1_id) {
<a routerLink="/players/{{ this.player1_id}}/registrations">{{ this.player1_name }}</a>
}
@if (this.message_parts[1]) {
{{ this.message_parts[1] }}
}
@if (this.player2_id) {
<a routerLink="/players/{{ this.player2_id}}/registrations">{{ this.player2_name }}</a>
}
@if (this.message_parts[2]) {
{{ this.message_parts[2] }}
}
@if (this.player3_id) {
<a routerLink="/players/{{ this.player3_id}}/registrations">{{ this.player3_name }}</a>
}
@if (this.message_parts[3]) {
{{ this.message_parts[3] }}
}

View File

@@ -0,0 +1,53 @@
import {Component, Input, OnInit} from '@angular/core';
import {MatAnchor} from "@angular/material/button";
import {RouterLink} from "@angular/router";
@Component({
selector: 'player-link',
standalone: true,
imports: [
MatAnchor,
RouterLink
],
templateUrl: './player-link.component.html',
styleUrl: './player-link.component.scss'
})
export class PlayerLinkComponent implements OnInit {
player1_id: string;
player1_name: string;
player2_id: string;
player2_name: string;
player3_id: string;
player3_name: string;
message_parts: string[];
constructor() {}
@Input() validationMessage: string;
ngOnInit(): void {
this.parse(this.validationMessage);
}
parse(message: string) {
this.message_parts = message.split(/\[.*?]/g);
const matches = message.match(/\[(\d+)\|.*?]/g);
if (matches) {
if (matches[0]) {
this.player1_id = matches[0].substring(1, matches[0].indexOf("|"));
this.player1_name = matches[0].substring(matches[0].indexOf("|") + 1, matches[0].indexOf("]"));
}
if (matches[1]) {
this.player2_id = matches[1].substring(1, matches[1].indexOf("|"));
this.player2_name = matches[1].substring(matches[1].indexOf("|") + 1, matches[1].indexOf("]"));
}
if (matches[2]) {
this.player3_id = matches[2].substring(1, matches[2].indexOf("|"));
this.player3_name = matches[2].substring(matches[2].indexOf("|") + 1, matches[2].indexOf("]"));
}
}
}
}

View File

@@ -46,11 +46,16 @@
</button>
</mat-menu>
</ng-template>
<mat-card appearance="outlined" class="m-3">
<mat-card-header>
<h6>Totaal: {{ getTournamentMatchCount(tournament)}} wedstrijden</h6>
</mat-card-header>
</mat-card>
@for (event of tournament.events; track event) {
@if (event.groups.length > 0) {
<mat-card appearance="outlined" class="m-3">
<mat-card-header>
<h6>Indeling {{ TournamentEvent.getType(event.type) }}</h6>
<h6>Indeling {{ TournamentEvent.getType(event.type) }} ({{ getEventMatchCount(event)}} wedstrijden)</h6>
</mat-card-header>
<mat-card-content>
<mat-accordion multi="true">

View File

@@ -345,6 +345,24 @@ export class TournamentManageComponent implements OnInit {
protected readonly TournamentEvent = Event;
getEventMatchCount(event: Event) {
let count = 0;
for (let group of event.groups) {
let numTeams = group.teams.length;
let rounds = Math.trunc(Math.log2(numTeams));
let matchesPerRound = Math.trunc(numTeams / 2);
count += (rounds * matchesPerRound);
}
return count;
}
getTournamentMatchCount(tournament: Tournament) {
let count = 0;
for (let event of tournament.events) {
count += this.getEventMatchCount(event);
}
return count;
}
}
class ActiveMatch {

View File

@@ -59,7 +59,12 @@
<ul>
<li *ngFor="let validation of getEventValidation(event.id)?.validations">
<mat-icon class="text-{{ getColorForSeverity(validation.severity) }}">{{ getIconForSeverity(validation.severity) }}</mat-icon>
{{ validation.message }}
<player-link [validationMessage]="validation.message"></player-link>
<!--
<div *ngIf="validation.message">
<app-player-link [validationMessage]="'validation.message'"></app-player-link>
</div>
-->
</li>
</ul>
</mat-expansion-panel>

View File

@@ -15,6 +15,8 @@ import {Player} from "../../model/player";
import {EventValidation, TournamentValidation, Validation} from "../../model/tournamentValidation";
import {MatIcon} from "@angular/material/icon";
import {FullNamePipe} from "../../pipes/fullname-pipe";
import {PlayerService} from "../../service/player.service";
import {PlayerLinkComponent} from "../player-link/player-link.component";
@Component({
selector: 'app-tournament-validate',
@@ -31,7 +33,8 @@ import {FullNamePipe} from "../../pipes/fullname-pipe";
MatAccordion,
AsyncPipe,
MatIcon,
FullNamePipe
FullNamePipe,
PlayerLinkComponent
],
templateUrl: './tournament-validate.component.html',
styleUrl: './tournament-validate.component.scss'
@@ -39,6 +42,7 @@ import {FullNamePipe} from "../../pipes/fullname-pipe";
export class TournamentValidateComponent implements OnInit {
tournament: Tournament;
tournamentValidation: TournamentValidation;
players: Player[];
protected readonly TournamentEvent = Event;
protected readonly Player = Player;
@@ -46,8 +50,9 @@ export class TournamentValidateComponent implements OnInit {
constructor(
private tournamentService: TournamentService,
private playerService: PlayerService,
private route: ActivatedRoute,
private router: Router
private router: Router,
) {}
ngOnInit() {
@@ -58,6 +63,9 @@ export class TournamentValidateComponent implements OnInit {
this.tournamentService.getValidation(Number(id)).subscribe(data => {
this.tournamentValidation = data;
});
this.playerService.getAll().subscribe(data => {
this.players = data;
});
}
getEventValidation(id: number): EventValidation | null {