Compare commits
22 Commits
edaffc82e4
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 87d9291bfb | |||
| c646ae15ee | |||
|
|
8128ba4744 | ||
|
|
19e4372006 | ||
|
|
7fd84005f9 | ||
|
|
a56317fecd | ||
|
|
ecbb16776c | ||
|
|
3008f45dfa | ||
|
|
5baf1228f7 | ||
|
|
aacf06e203 | ||
| 368aa53b9d | |||
| 335577fa4d | |||
| 1f55acecd0 | |||
| c1fedd728b | |||
| 0e9e8d1e0f | |||
|
|
0e1e1932a1 | ||
| fb36ee1a05 | |||
| 9cb3568770 | |||
| d387452044 | |||
| 2cdccc4dd8 | |||
| 8083e7fc5f | |||
| 0fd693aa42 |
10
package-lock.json
generated
10
package-lock.json
generated
@@ -25,6 +25,7 @@
|
||||
"@popperjs/core": "^2.11.8",
|
||||
"bootstrap": "^5.3.7",
|
||||
"express": "^4.21.2",
|
||||
"jwt-decode": "^4.0.0",
|
||||
"moment": "2.30.1",
|
||||
"ngx-cookie-service-ssr": "^20.1.0",
|
||||
"ngx-mask": "^20.0.3",
|
||||
@@ -6835,6 +6836,15 @@
|
||||
],
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/jwt-decode": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/jwt-decode/-/jwt-decode-4.0.0.tgz",
|
||||
"integrity": "sha512-+KJGIyHgkGuIq3IEBNftfhW/LfWhXUIY6OmyVWjliu5KH1y0fw7VQ8YndE2O4qZdMSd9SqbnC8GOcZEy0Om7sA==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/karma": {
|
||||
"version": "6.4.4",
|
||||
"resolved": "https://registry.npmjs.org/karma/-/karma-6.4.4.tgz",
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
"@popperjs/core": "^2.11.8",
|
||||
"bootstrap": "^5.3.7",
|
||||
"express": "^4.21.2",
|
||||
"jwt-decode": "^4.0.0",
|
||||
"moment": "2.30.1",
|
||||
"ngx-cookie-service-ssr": "^20.1.0",
|
||||
"ngx-mask": "^20.0.3",
|
||||
|
||||
@@ -17,10 +17,10 @@
|
||||
<mat-icon>group</mat-icon>
|
||||
Spelers
|
||||
</a>
|
||||
@if (this.userService.isLoggedIn()) {
|
||||
@if (this.authService.isLoggedIn()) {
|
||||
<button mat-flat-button [matMenuTriggerFor]="accountMenu">
|
||||
<mat-icon>person</mat-icon>
|
||||
{{ user }}
|
||||
{{ this.authService.getUsername() }}
|
||||
</button>
|
||||
<mat-menu #accountMenu="matMenu">
|
||||
<button mat-menu-item (click)="logOut()">
|
||||
|
||||
@@ -6,9 +6,10 @@ import {MatIcon} from "@angular/material/icon";
|
||||
import {MatToolbar} from "@angular/material/toolbar";
|
||||
import {filter, map, Subscription} from "rxjs";
|
||||
import {MatMenu, MatMenuItem, MatMenuTrigger} from "@angular/material/menu";
|
||||
import {UserService} from "./authentication/user.service";
|
||||
// import {UserService} from "./authentication/user.service";
|
||||
import {TournamentService} from "./service/tournament.service";
|
||||
import {HeaderService} from "./service/header.service";
|
||||
import {AuthService} from "./auth/auth.service";
|
||||
|
||||
@Component({
|
||||
selector: 'app-root',
|
||||
@@ -19,11 +20,11 @@ import {HeaderService} from "./service/header.service";
|
||||
export class AppComponent implements OnInit {
|
||||
|
||||
header: string;
|
||||
user: string;
|
||||
userSubscription: Subscription;
|
||||
// user: string;
|
||||
// userSubscription: Subscription;
|
||||
|
||||
constructor(
|
||||
protected userService: UserService,
|
||||
protected authService: AuthService,
|
||||
private router: Router,
|
||||
protected activatedRoute: ActivatedRoute,
|
||||
private tournamentService: TournamentService,
|
||||
@@ -32,7 +33,7 @@ export class AppComponent implements OnInit {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.userSubscription = this.userService.currentUser.subscribe(newUser => this.user = newUser);
|
||||
// this.userSubscription = this.userService.currentUser.subscribe(newUser => this.user = newUser);
|
||||
|
||||
this.router.events.pipe(
|
||||
filter(event => event instanceof NavigationEnd),
|
||||
@@ -55,8 +56,8 @@ export class AppComponent implements OnInit {
|
||||
}
|
||||
|
||||
logOut() {
|
||||
this.userService.removeUser();
|
||||
this.router.navigate(['/auth/login']);
|
||||
this.authService.logout();
|
||||
this.router.navigate(['/login']);
|
||||
}
|
||||
|
||||
addTestData() {
|
||||
|
||||
@@ -7,19 +7,12 @@ import {HTTP_INTERCEPTORS, provideHttpClient, withFetch, withInterceptorsFromDi}
|
||||
import {provideAnimationsAsync} from '@angular/platform-browser/animations/async';
|
||||
import {provideMomentDateAdapter} from "@angular/material-moment-adapter";
|
||||
import {MAT_SNACK_BAR_DEFAULT_OPTIONS} from "@angular/material/snack-bar";
|
||||
import {AuthGuard} from "./authentication/authguard";
|
||||
import {TokenInterceptor} from "./authentication/tokenInterceptor";
|
||||
import {ErrorInterceptor} from "./authentication/errorInterceptor";
|
||||
import {provideNgxMask} from "ngx-mask";
|
||||
import {UserService} from './authentication/user.service';
|
||||
import {provideAnimations} from "@angular/platform-browser/animations";
|
||||
import {AuthInterceptor} from "./auth/auth.interceptor";
|
||||
|
||||
export const appConfig: ApplicationConfig = {
|
||||
providers: [
|
||||
provideAppInitializer(() => {
|
||||
const userService = inject(UserService);
|
||||
userService.initializeUser();
|
||||
}),
|
||||
provideZoneChangeDetection({eventCoalescing: true}),
|
||||
provideRouter(routes),
|
||||
provideClientHydration(),
|
||||
@@ -27,9 +20,7 @@ export const appConfig: ApplicationConfig = {
|
||||
provideAnimations(),
|
||||
provideMomentDateAdapter(undefined, {useUtc: false}),
|
||||
{ provide: MAT_SNACK_BAR_DEFAULT_OPTIONS, useValue: { duration: 2500}},
|
||||
AuthGuard,
|
||||
{ provide: HTTP_INTERCEPTORS, useClass: TokenInterceptor, multi: true },
|
||||
{ provide: HTTP_INTERCEPTORS, useClass: ErrorInterceptor, multi: true },
|
||||
{ provide: HTTP_INTERCEPTORS, useClass: AuthInterceptor, multi: true },
|
||||
provideNgxMask(),
|
||||
]
|
||||
};
|
||||
|
||||
@@ -8,24 +8,24 @@ import {TournamentDrawComponent} from "./components/tournament-draw/tournament-d
|
||||
import {TournamentManageComponent} from "./components/tournament-manage/tournament-manage.component";
|
||||
import {MatchSheetsComponent} from "./components/match-sheets/match-sheets.component";
|
||||
import {RoundOverviewComponent} from "./components/round-overview/round-overview.component";
|
||||
import {AuthGuard} from "./authentication/authguard";
|
||||
import {LoginComponent} from "./components/login/login.component";
|
||||
import {TournamentPlayersComponent} from "./components/tournament-players/tournament-players.component";
|
||||
import {AuthGuard} from "./auth/auth-guard.service";
|
||||
|
||||
export const routes: Routes = [
|
||||
{ path: '', component: TournamentListComponent, canActivate: [AuthGuard], data: { header: 'Toernooien' }},
|
||||
{ path: 'tournaments', component: TournamentListComponent, canActivate: [AuthGuard], data: { header: 'Toernooien' }},
|
||||
{ path: 'tournaments/add', component: TournamentEditComponent, canActivate: [AuthGuard], data: { header: 'Nieuw Toernooi' }},
|
||||
{ path: 'tournaments/:id/edit', component: TournamentEditComponent, canActivate: [AuthGuard], data: { header: 'Bewerk Toernooi' }},
|
||||
{ path: 'tournaments/:id/registrations', component: TournamentPlayersComponent, canActivate: [AuthGuard], data: { header: 'Inschrijvingen' }},
|
||||
{ path: 'tournaments/:id/draw', component: TournamentDrawComponent, canActivate: [AuthGuard], data: { header: 'Toernooi loten' }},
|
||||
{ path: 'tournaments/:id/manage', component: TournamentManageComponent, canActivate: [AuthGuard]},
|
||||
{ path: 'tournaments/:id/manage/:tab', component: TournamentManageComponent, canActivate: [AuthGuard], data: { header: 'Toernooien' }},
|
||||
{ path: 'players', component: PlayerListComponent, canActivate: [AuthGuard], data: { header: 'Spelers' }},
|
||||
{ path: 'players/add', component: PlayerEditComponent, canActivate: [AuthGuard], data: { header: 'Nieuwe Speler' }},
|
||||
{ path: 'players/:id/edit', component: PlayerEditComponent, canActivate: [AuthGuard], data: { header: 'Bewerk Speler' }},
|
||||
{ path: 'players/:id/registrations', component: PlayerRegistrationsComponent, canActivate: [AuthGuard]},
|
||||
{ path: 'tournaments/:id/rounds/:roundId/matchsheets', component: MatchSheetsComponent, canActivate: [AuthGuard]},
|
||||
{ path: 'tournaments/:id/rounds/:roundId/overview', component: RoundOverviewComponent, canActivate: [AuthGuard], data: { header: 'Rondeoverzicht' }},
|
||||
{ path: 'auth/login', component: LoginComponent, data: { header: 'Inloggen'}}
|
||||
{ path: '', component: TournamentListComponent, canActivate: [AuthGuard], data: { role: 'ROLE_USER', header: 'Toernooien' }},
|
||||
{ path: 'tournaments', component: TournamentListComponent, canActivate: [AuthGuard], data: { role: 'ROLE_USER', header: 'Toernooien' }},
|
||||
{ path: 'tournaments/add', component: TournamentEditComponent, canActivate: [AuthGuard], data: { role: 'ROLE_USER', header: 'Nieuw Toernooi' }},
|
||||
{ path: 'tournaments/:id/edit', component: TournamentEditComponent, canActivate: [AuthGuard], data: { role: 'ROLE_USER', header: 'Bewerk Toernooi' }},
|
||||
{ path: 'tournaments/:id/registrations', component: TournamentPlayersComponent, canActivate: [AuthGuard], data: { role: 'ROLE_USER', header: 'Inschrijvingen' }},
|
||||
{ path: 'tournaments/:id/draw', component: TournamentDrawComponent, canActivate: [AuthGuard], data: { role: 'ROLE_USER', header: 'Toernooi loten' }},
|
||||
{ path: 'tournaments/:id/manage', component: TournamentManageComponent, canActivate: [AuthGuard], data: { role: 'ROLE_USER' }},
|
||||
{ path: 'tournaments/:id/manage/:tab', component: TournamentManageComponent, canActivate: [AuthGuard], data: { role: 'ROLE_USER', header: 'Toernooien' }},
|
||||
{ path: 'players', component: PlayerListComponent, canActivate: [AuthGuard], data: { role: 'ROLE_USER', header: 'Spelers' }},
|
||||
{ path: 'players/add', component: PlayerEditComponent, canActivate: [AuthGuard], data: { role: 'ROLE_USER', header: 'Nieuwe Speler' }},
|
||||
{ path: 'players/:id/edit', component: PlayerEditComponent, canActivate: [AuthGuard], data: { role: 'ROLE_USER', header: 'Bewerk Speler' }},
|
||||
{ path: 'players/:id/registrations', component: PlayerRegistrationsComponent, canActivate: [AuthGuard], data: { role: 'ROLE_USER' }},
|
||||
{ path: 'tournaments/:id/rounds/:roundId/matchsheets', component: MatchSheetsComponent, canActivate: [AuthGuard], data: { role: 'ROLE_USER' }},
|
||||
{ path: 'tournaments/:id/rounds/:roundId/overview', component: RoundOverviewComponent, canActivate: [AuthGuard], data: { role: 'ROLE_USER', header: 'Rondeoverzicht' }},
|
||||
{ path: 'login', component: LoginComponent, data: { header: 'Inloggen'}}
|
||||
];
|
||||
|
||||
22
src/app/auth/auth-guard.service.ts
Normal file
22
src/app/auth/auth-guard.service.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot} from '@angular/router';
|
||||
import {AuthService} from './auth.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class AuthGuard implements CanActivate {
|
||||
|
||||
constructor(private authService: AuthService, private router: Router) {
|
||||
}
|
||||
|
||||
public canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
|
||||
if (this.authService.isLoggedIn() && this.authService.isUserInRole(next.routeConfig?.data?.['role'])) {
|
||||
return true;
|
||||
} else {
|
||||
// this.router.navigateByUrl("/login");
|
||||
this.router.navigate(['/login'], { queryParams: { returnUrl: state.url } });
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
35
src/app/auth/auth.interceptor.ts
Normal file
35
src/app/auth/auth.interceptor.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {HttpErrorResponse, HttpEvent, HttpHandler, HttpInterceptor, HttpRequest} from '@angular/common/http';
|
||||
import {catchError, Observable, throwError} from 'rxjs';
|
||||
import {Router} from '@angular/router';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class AuthInterceptor implements HttpInterceptor {
|
||||
|
||||
constructor(private router: Router) {
|
||||
}
|
||||
|
||||
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
|
||||
let token = localStorage.getItem("app.token");
|
||||
if (token) {
|
||||
request = request.clone({
|
||||
setHeaders: {
|
||||
Authorization: `Bearer ${token}`
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return next.handle(request).pipe(
|
||||
catchError((error: HttpErrorResponse) => this.handleErrorRes(error))
|
||||
);
|
||||
}
|
||||
|
||||
private handleErrorRes(error: HttpErrorResponse): Observable<never> {
|
||||
if (error.status === 401) {
|
||||
this.router.navigateByUrl("/login", {replaceUrl: true});
|
||||
}
|
||||
return throwError(() => error);
|
||||
}
|
||||
}
|
||||
85
src/app/auth/auth.service.ts
Normal file
85
src/app/auth/auth.service.ts
Normal file
@@ -0,0 +1,85 @@
|
||||
import {Inject, Injectable, PLATFORM_ID} from '@angular/core';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {Observable} from 'rxjs';
|
||||
import {environment} from "../../environments/environment";
|
||||
import {isPlatformBrowser} from "@angular/common";
|
||||
import {jwtDecode, JwtPayload} from "jwt-decode";
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class AuthService {
|
||||
|
||||
private readonly authUrl: string
|
||||
|
||||
constructor(private http: HttpClient,
|
||||
@Inject(PLATFORM_ID) private platformId: Object) {
|
||||
this.authUrl = `${environment.backendUrl}/api/auth`;
|
||||
}
|
||||
|
||||
private get isBrowser(): boolean {
|
||||
return isPlatformBrowser(this.platformId);
|
||||
}
|
||||
|
||||
isLoggedIn(): boolean {
|
||||
if (!this.isBrowser) return false;
|
||||
return localStorage.getItem("app.token") != null;
|
||||
}
|
||||
|
||||
login(username: string, password: string): Observable<string> {
|
||||
if (!this.isBrowser) {
|
||||
throw new Error('Login can only be performed in browser');
|
||||
}
|
||||
|
||||
const credentials = btoa(`${username}:${password}`);
|
||||
|
||||
const httpOptions = {
|
||||
headers: {
|
||||
'Authorization': `Basic ${credentials}`,
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
responseType: 'text' as 'text',
|
||||
};
|
||||
return this.http.post(this.authUrl, null, httpOptions);
|
||||
}
|
||||
|
||||
logout() {
|
||||
if (!this.isBrowser) return;
|
||||
localStorage.removeItem("app.token");
|
||||
localStorage.removeItem("app.roles");
|
||||
}
|
||||
|
||||
isUserInRole(roleFromRoute: string) {
|
||||
if (!this.isBrowser) return false;
|
||||
|
||||
const roles = localStorage.getItem("app.roles");
|
||||
|
||||
if (roles!.includes(",")) {
|
||||
if (roles === roleFromRoute) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
const roleArray = roles!.split(",");
|
||||
for (let role of roleArray) {
|
||||
if (role === roleFromRoute) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
getUsername(): string | null {
|
||||
if (!this.isBrowser) return null;
|
||||
|
||||
const token = localStorage.getItem("app.token");
|
||||
if (!token) return null;
|
||||
|
||||
try {
|
||||
const decodedToken = jwtDecode<JwtPayload>(token);
|
||||
return decodedToken.sub || null; // 'sub' is the standard JWT claim for subject/username
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import {environment} from "../../environments/environment";
|
||||
import {LoginCredentials} from "./loginCredentials";
|
||||
import {TokenModel} from "./tokenModel";
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class AuthenticationService {
|
||||
|
||||
private readonly authUrl: string
|
||||
|
||||
constructor(private http: HttpClient) {
|
||||
this.authUrl = `${environment.backendUrl}`
|
||||
}
|
||||
|
||||
public login(loginCredentials: LoginCredentials) {
|
||||
return this.http.post<any>(`${this.authUrl}/authenticate`, loginCredentials);
|
||||
}
|
||||
|
||||
public logout(tokenModel: TokenModel) {
|
||||
return this.http.post<string>(
|
||||
`${this.authUrl}/logout`,
|
||||
tokenModel
|
||||
);
|
||||
}
|
||||
|
||||
public logoutEverywhere() {
|
||||
return this.http.post<string>(
|
||||
`${this.authUrl}/logout-everywhere`,
|
||||
undefined
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
import {Injectable} from "@angular/core";
|
||||
import {ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot} from "@angular/router";
|
||||
import {UserService} from "./user.service";
|
||||
import {delay, map, Observable, of} from "rxjs";
|
||||
|
||||
@Injectable()
|
||||
export class AuthGuard implements CanActivate {
|
||||
|
||||
constructor(
|
||||
private router: Router,
|
||||
private userService: UserService
|
||||
) {}
|
||||
|
||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
|
||||
if (this.userService.getUser()) {
|
||||
return true;
|
||||
}
|
||||
this.router.navigate(['/auth/login'], { queryParams: { returnUrl: state.url } });
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
import {Injectable} from "@angular/core";
|
||||
import {HttpEvent, HttpHandler, HttpInterceptor, HttpRequest} from "@angular/common/http";
|
||||
import {catchError, Observable, throwError} from "rxjs";
|
||||
import {UserService} from "./user.service";
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ErrorInterceptor implements HttpInterceptor {
|
||||
|
||||
constructor(private userService: UserService) { }
|
||||
|
||||
intercept(
|
||||
request: HttpRequest<any>,
|
||||
next: HttpHandler
|
||||
): Observable<HttpEvent<any>> {
|
||||
|
||||
return next.handle(request).pipe(catchError(error=>{
|
||||
if((error.status == 401 || error.status == 403) && !this.isLoginPage(request)){
|
||||
this.userService.removeUser();
|
||||
}
|
||||
// const errMsg = error.error.message || error.statusText;
|
||||
return throwError(() => error);
|
||||
// return throwError(()=> errMsg);
|
||||
}));
|
||||
}
|
||||
|
||||
private isLoginPage(request: HttpRequest<any>){
|
||||
return request.url.includes("/authenticate")
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class IpService {
|
||||
|
||||
constructor(private http: HttpClient) { }
|
||||
|
||||
public getIPAddress() {
|
||||
return this.http.get("http://api.ipify.org/?format=json");
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
export class LoginCredentials {
|
||||
username: string;
|
||||
password: string;
|
||||
// ipAddress: string;
|
||||
// recaptcha: string;
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
import {Injectable} from "@angular/core";
|
||||
import {HttpEvent, HttpHandler, HttpInterceptor, HttpRequest} from "@angular/common/http";
|
||||
import {Observable} from "rxjs";
|
||||
import {UserService} from "./user.service";
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class TokenInterceptor implements HttpInterceptor {
|
||||
|
||||
constructor(private userService: UserService) { }
|
||||
|
||||
intercept(
|
||||
request: HttpRequest<any>,
|
||||
next: HttpHandler
|
||||
): Observable<HttpEvent<any>> {
|
||||
if (this.userService.isLoggedIn()) {
|
||||
let newRequest = request.clone({
|
||||
setHeaders: {
|
||||
Authorization: `Bearer ${this.userService.getUser()?.accessToken}`,
|
||||
},
|
||||
});
|
||||
return next.handle(newRequest);
|
||||
}
|
||||
return next.handle(request);
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
export class TokenModel {
|
||||
constructor(token: string, refreshToken: string, ipAddress: string) {
|
||||
this.token = token;
|
||||
this.refreshToken = refreshToken;
|
||||
this.ipAddress = ipAddress;
|
||||
}
|
||||
|
||||
token: string;
|
||||
refreshToken: string;
|
||||
ipAddress: string;
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
import { Injectable } from "@angular/core";
|
||||
import { SsrCookieService } from "ngx-cookie-service-ssr";
|
||||
import { Router } from "@angular/router";
|
||||
import { User } from "./user";
|
||||
import { BehaviorSubject } from "rxjs";
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class UserService {
|
||||
private user?: User;
|
||||
private userEmitter = new BehaviorSubject<string>('');
|
||||
private initialized = false;
|
||||
|
||||
currentUser = this.userEmitter.asObservable();
|
||||
|
||||
constructor(
|
||||
private cookieService: SsrCookieService,
|
||||
private router: Router,
|
||||
) {}
|
||||
|
||||
initializeUser() {
|
||||
if (this.initialized) return;
|
||||
|
||||
try {
|
||||
const userCookie = this.cookieService.get('swissuser');
|
||||
if (userCookie && userCookie.trim() !== '') {
|
||||
this.user = JSON.parse(userCookie);
|
||||
if (this.user?.username) {
|
||||
this.userEmitter.next(this.user.username);
|
||||
} else {
|
||||
this.userEmitter.next('');
|
||||
}
|
||||
} else {
|
||||
this.user = undefined;
|
||||
this.userEmitter.next('');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error parsing user cookie:', error);
|
||||
this.user = undefined;
|
||||
this.userEmitter.next('');
|
||||
}
|
||||
|
||||
this.initialized = true;
|
||||
}
|
||||
|
||||
public getUser(): User | undefined {
|
||||
this.initializeUser();
|
||||
return this.user;
|
||||
}
|
||||
|
||||
public isLoggedIn(): boolean {
|
||||
this.initializeUser();
|
||||
return !!this.user;
|
||||
}
|
||||
|
||||
public setUser(user: User) {
|
||||
this.cookieService.set('swissuser', JSON.stringify(user));
|
||||
this.user = user;
|
||||
this.userEmitter.next(this.user.username);
|
||||
}
|
||||
|
||||
public removeUser() {
|
||||
this.cookieService.delete('swissuser');
|
||||
this.user = undefined;
|
||||
this.router.navigate(['/tournaments']);
|
||||
this.userEmitter.next('');
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
export class User {
|
||||
accessToken: string;
|
||||
username: string;
|
||||
// passwordHash: string;
|
||||
// email: string;
|
||||
// token: string;
|
||||
// refreshToken: string;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<mat-dialog-content>
|
||||
<h3>Kies een teller:</h3>
|
||||
<div class="col-md-6">
|
||||
<mat-form-field appearance="fill">
|
||||
<mat-label>Teller</mat-label>
|
||||
<mat-select [(ngModel)]="counter">
|
||||
<mat-option>Geen</mat-option>
|
||||
@for (player of data.availableCounters; track player.playerId) {
|
||||
<mat-option [value]="player">
|
||||
{{ player.name }}
|
||||
</mat-option>
|
||||
}
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
</mat-dialog-content>
|
||||
<mat-dialog-actions>
|
||||
@if (counter) {
|
||||
<button mat-button [mat-dialog-close]="{counter: counter}">Opslaan</button>
|
||||
}
|
||||
<button mat-button (click)="onAnnulerenClick()">Annuleren</button>
|
||||
</mat-dialog-actions>
|
||||
@@ -0,0 +1,4 @@
|
||||
button:disabled {
|
||||
cursor: not-allowed;
|
||||
pointer-events: all !important;
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
import {Component, inject, Inject} from '@angular/core';
|
||||
import {
|
||||
MAT_DIALOG_DATA,
|
||||
MatDialogActions,
|
||||
MatDialogClose,
|
||||
MatDialogContent,
|
||||
MatDialogRef
|
||||
} from "@angular/material/dialog";
|
||||
import {Match} from "../../model/match";
|
||||
import {MatButton} from "@angular/material/button";
|
||||
import {TournamentPlayer} from "../../model/tournamentPlayer";
|
||||
import {MatFormField, MatLabel} from "@angular/material/form-field";
|
||||
import {MatOption, MatSelect} from "@angular/material/select";
|
||||
import {FormsModule} from "@angular/forms";
|
||||
|
||||
@Component({
|
||||
selector: 'app-counter-selection',
|
||||
imports: [
|
||||
MatDialogContent,
|
||||
MatButton,
|
||||
MatDialogClose,
|
||||
MatDialogActions,
|
||||
MatFormField,
|
||||
MatLabel,
|
||||
MatOption,
|
||||
MatSelect,
|
||||
FormsModule,
|
||||
|
||||
],
|
||||
templateUrl: './counter-selection.component.html',
|
||||
standalone: true,
|
||||
styleUrl: './counter-selection.component.scss'
|
||||
})
|
||||
export class CounterSelectionComponent {
|
||||
|
||||
counter: TournamentPlayer;
|
||||
|
||||
readonly dialogRef = inject(MatDialogRef<CounterSelectionComponent>);
|
||||
|
||||
constructor(@Inject(MAT_DIALOG_DATA) public data: {
|
||||
match: Match,
|
||||
availableCounters: TournamentPlayer[]
|
||||
}) {}
|
||||
|
||||
onAnnulerenClick() {
|
||||
this.dialogRef.close();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,22 +1,23 @@
|
||||
<mat-card>
|
||||
<mat-card-content>
|
||||
<form class="form-horizontal" [formGroup]="form">
|
||||
<form class="form-horizontal" (ngSubmit)="login()">
|
||||
<div class="row">
|
||||
<mat-form-field appearance="outline">
|
||||
<mat-label>Gebruikersnaam</mat-label>
|
||||
<input matInput placeholder="Gebruikersnaam" formControlName="username" required>
|
||||
<input matInput name="username" placeholder="Gebruikersnaam" required [(ngModel)]="username">
|
||||
</mat-form-field>
|
||||
</div>
|
||||
<div class="row">
|
||||
<mat-form-field appearance="outline">
|
||||
<mat-label>Wachtwoord</mat-label>
|
||||
<input matInput placeholder="Wachtwoord" type="password" formControlName="password" required>
|
||||
<input matInput name="password" placeholder="Wachtwoord" type="password" required [(ngModel)]="password">
|
||||
</mat-form-field>
|
||||
</div>
|
||||
<button class="w-100 mt-2" mat-button mat-flat-button color="primary"
|
||||
(click)="login()" [disabled]="form.invalid">
|
||||
(click)="login()">
|
||||
Inloggen
|
||||
</button>
|
||||
</form>
|
||||
<p>{{message}}</p>
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
import {FormBuilder, FormGroup, ReactiveFormsModule, Validators} from '@angular/forms';
|
||||
import {FormGroup, FormsModule, ReactiveFormsModule} from '@angular/forms';
|
||||
import {Component, OnInit} from '@angular/core';
|
||||
import {ActivatedRoute, Router, RouterLink} from '@angular/router';
|
||||
import {MatCard, MatCardContent, MatCardHeader, MatCardTitle} from "@angular/material/card";
|
||||
import {MatError, MatFormField, MatLabel} from "@angular/material/form-field";
|
||||
import {ActivatedRoute, Router} from '@angular/router';
|
||||
import {MatCard, MatCardContent} from "@angular/material/card";
|
||||
import {MatFormField, MatLabel} from "@angular/material/form-field";
|
||||
import {MatButton} from "@angular/material/button";
|
||||
import {MatInput} from "@angular/material/input";
|
||||
import {NgIf} from "@angular/common";
|
||||
import {AuthenticationService} from "../../authentication/authentication.service";
|
||||
import {UserService} from "../../authentication/user.service";
|
||||
import {LoginCredentials} from "../../authentication/loginCredentials";
|
||||
import {User} from "../../authentication/user";
|
||||
import {jwtDecode, JwtPayload} from "jwt-decode";
|
||||
import {AuthService} from "../../auth/auth.service";
|
||||
import {MatSnackBar} from "@angular/material/snack-bar";
|
||||
|
||||
|
||||
@Component({
|
||||
@@ -23,6 +21,7 @@ import {User} from "../../authentication/user";
|
||||
MatInput,
|
||||
MatLabel,
|
||||
MatCard,
|
||||
FormsModule,
|
||||
],
|
||||
standalone: true,
|
||||
styleUrls: ['./login.component.scss']
|
||||
@@ -32,48 +31,42 @@ export class LoginComponent implements OnInit {
|
||||
private returnUrl: string;
|
||||
private ipAddress: string;
|
||||
|
||||
constructor(
|
||||
username: string = "";
|
||||
password: string = "";
|
||||
message: string = "";
|
||||
|
||||
constructor(private authService: AuthService,
|
||||
private route: ActivatedRoute,
|
||||
private fb: FormBuilder,
|
||||
private authenticationService: AuthenticationService,
|
||||
private router: Router,
|
||||
private userPersistenceService: UserService,
|
||||
) {
|
||||
this.initializeForm();
|
||||
private snackBar: MatSnackBar) {
|
||||
}
|
||||
|
||||
private initializeForm() {
|
||||
this.form = this.fb.group({
|
||||
username: ['', [Validators.required]],
|
||||
password: ['', [Validators.required]],
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.returnUrl = this.route.snapshot.queryParams['returnUrl'] || '/';
|
||||
}
|
||||
|
||||
login() {
|
||||
if (this.form.invalid) {
|
||||
return;
|
||||
}
|
||||
public login(): void {
|
||||
localStorage.removeItem("app.token");
|
||||
|
||||
let loginCredentials = new LoginCredentials();
|
||||
loginCredentials = {
|
||||
...loginCredentials,
|
||||
...this.form.value,
|
||||
};
|
||||
this.authService.login(this.username, this.password)
|
||||
.subscribe({
|
||||
next: (token) => {
|
||||
localStorage.setItem("app.token", token);
|
||||
|
||||
this.authenticationService
|
||||
.login(loginCredentials)
|
||||
.subscribe(
|
||||
{
|
||||
next: (user: User) => {
|
||||
this.userPersistenceService.setUser(user);
|
||||
this.router.navigate([this.returnUrl]);
|
||||
const decodedToken = jwtDecode<JwtPayload>(token);
|
||||
// @ts-ignore
|
||||
localStorage.setItem("app.roles", decodedToken.scope);
|
||||
|
||||
// this.router.navigateByUrl("/persons");
|
||||
|
||||
// this.router.navigate([this.returnUrl]);
|
||||
this.router.navigate([this.route.snapshot.queryParams['returnUrl'] || '/']);
|
||||
},
|
||||
error: (error) => {
|
||||
this.snackBar.open(`Login failed: ${error.status}`, "OK")
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,76 +7,76 @@
|
||||
<b>{{ data.group.name }} {{ data.round.name }}</b>
|
||||
</div>
|
||||
</mat-grid-tile>
|
||||
<mat-grid-tile>
|
||||
<button type="button" class="btn btn-primary btn-lg" (click)="set21(1, 1)">21</button>
|
||||
</mat-grid-tile>
|
||||
<mat-grid-tile>
|
||||
<button type="button" class="btn btn-primary btn-lg" (click)="set21(1, 2)">21</button>
|
||||
</mat-grid-tile>
|
||||
<mat-grid-tile>
|
||||
<button type="button" class="btn btn-primary btn-lg" (click)="set21(1, 3)">21</button>
|
||||
</mat-grid-tile>
|
||||
|
||||
@for (gameNum of [1, 2, 3]; track gameNum) {
|
||||
<mat-grid-tile>
|
||||
<button type="button" class="btn btn-primary btn-lg" (click)="set21(1, gameNum)">21</button>
|
||||
</mat-grid-tile>
|
||||
}
|
||||
<mat-grid-tile colspan="2">
|
||||
<div class="w-100" [ngClass]="{'winner': validateResult() == 1}">
|
||||
{{ data.match.team1 | teamText }}
|
||||
<div class="w-100" [ngClass]="{'winner': isValidResult == 1}">
|
||||
<app-team-display
|
||||
[team]="data.match.team1"
|
||||
[event]="data.event"
|
||||
[tournament]="data.tournament"
|
||||
[inline]="false">
|
||||
</app-team-display>
|
||||
</div>
|
||||
</mat-grid-tile>
|
||||
|
||||
@for (game of result.games; track $index; let i = $index) {
|
||||
<mat-grid-tile>
|
||||
<mat-form-field appearance="outline" (change)="validateResult()">
|
||||
<input matInput type="number" min="0" max="30" [(ngModel)]="result.games[0].score1">
|
||||
</mat-form-field>
|
||||
</mat-grid-tile>
|
||||
<mat-grid-tile>
|
||||
<mat-form-field appearance="outline" (change)="validateResult()">
|
||||
<input matInput type="number" min="0" max="30" [(ngModel)]="result.games[1].score1">
|
||||
</mat-form-field>
|
||||
</mat-grid-tile>
|
||||
<mat-grid-tile>
|
||||
<mat-form-field appearance="outline" (change)="validateResult()">
|
||||
<input matInput type="number" min="0" max="30" [(ngModel)]="result.games[2].score1">
|
||||
<mat-form-field appearance="outline">
|
||||
<input matInput
|
||||
type="number"
|
||||
min="0"
|
||||
max="30"
|
||||
[(ngModel)]="game.score1"
|
||||
(blur)="complementScores()"
|
||||
(ngModelChange)="validateResult()"
|
||||
[tabindex]="i * 2 + 1">
|
||||
</mat-form-field>
|
||||
</mat-grid-tile>
|
||||
}
|
||||
|
||||
<mat-grid-tile colspan="2">
|
||||
<div class="w-100" [ngClass]="{'winner': validateResult() == -1}">
|
||||
{{ data.match.team2 | teamText }}
|
||||
<div class="w-100" [ngClass]="{'winner': isValidResult == -1}">
|
||||
<app-team-display
|
||||
[team]="data.match.team2"
|
||||
[event]="data.event"
|
||||
[tournament]="data.tournament"
|
||||
[inline]="false">
|
||||
</app-team-display>
|
||||
</div>
|
||||
</mat-grid-tile>
|
||||
<mat-grid-tile>
|
||||
<mat-form-field appearance="outline" (change)="validateResult()">
|
||||
<input matInput type="number" min="0" max="30" [(ngModel)]="result.games[0].score2">
|
||||
</mat-form-field>
|
||||
</mat-grid-tile>
|
||||
<mat-grid-tile>
|
||||
<mat-form-field appearance="outline" (change)="validateResult()">
|
||||
<input matInput type="number" min="0" max="30" [(ngModel)]="result.games[1].score2">
|
||||
</mat-form-field>
|
||||
</mat-grid-tile>
|
||||
<mat-grid-tile>
|
||||
<mat-form-field appearance="outline" (change)="validateResult()">
|
||||
<input matInput type="number" min="0" max="30" [(ngModel)]="result.games[2].score2">
|
||||
</mat-form-field>
|
||||
</mat-grid-tile>
|
||||
|
||||
@for (game of result.games; track $index; let i = $index) {
|
||||
<mat-grid-tile>
|
||||
<mat-form-field appearance="outline">
|
||||
<input matInput
|
||||
type="number"
|
||||
min="0"
|
||||
max="30"
|
||||
[(ngModel)]="game.score2"
|
||||
(blur)="complementScores()"
|
||||
(ngModelChange)="validateResult()"
|
||||
[tabindex]="i * 2 + 2">
|
||||
</mat-form-field>
|
||||
</mat-grid-tile>
|
||||
}
|
||||
<mat-grid-tile></mat-grid-tile>
|
||||
<mat-grid-tile></mat-grid-tile>
|
||||
|
||||
</mat-grid-tile>
|
||||
@for (gameNum of [1, 2, 3]; track gameNum) {
|
||||
<mat-grid-tile>
|
||||
<button type="button" class="btn btn-primary btn-lg" (click)="set21(2, gameNum)">21</button>
|
||||
</mat-grid-tile>
|
||||
<mat-grid-tile>
|
||||
<button type="button" class="btn btn-primary btn-lg" (click)="set21(2, 1)">21</button>
|
||||
</mat-grid-tile>
|
||||
<mat-grid-tile>
|
||||
<button type="button" class="btn btn-primary btn-lg" (click)="set21(2, 2)">21</button>
|
||||
</mat-grid-tile>
|
||||
<mat-grid-tile>
|
||||
<button type="button" class="btn btn-primary btn-lg" (click)="set21(2, 3)">21</button>
|
||||
</mat-grid-tile>
|
||||
}
|
||||
|
||||
</mat-grid-list>
|
||||
</mat-dialog-content>
|
||||
|
||||
<mat-dialog-actions>
|
||||
<button mat-button (click)="onAnnulerenClick()">Annuleren</button>
|
||||
<button mat-button [disabled]="validateResult() == 0" [mat-dialog-close]="result">Opslaan</button>
|
||||
<button mat-button [disabled]="isValidResult == 0" [mat-dialog-close]="result">Opslaan</button>
|
||||
</mat-dialog-actions>
|
||||
|
||||
@@ -19,6 +19,9 @@ import {MatGridList, MatGridTile} from "@angular/material/grid-list";
|
||||
import {Round} from "../../model/round";
|
||||
import {Group} from "../../model/group";
|
||||
import {Game} from "../../model/game";
|
||||
import {TeamDisplayComponent} from "../team-display/team-display.component";
|
||||
import {Event} from "../../model/event";
|
||||
import {Tournament} from "../../model/tournament";
|
||||
|
||||
@Component({
|
||||
selector: 'app-match-result',
|
||||
@@ -28,14 +31,14 @@ import {Game} from "../../model/game";
|
||||
MatButton,
|
||||
MatDialogClose,
|
||||
MatDialogTitle,
|
||||
TeamPipe,
|
||||
MatInput,
|
||||
ReactiveFormsModule,
|
||||
FormsModule,
|
||||
MatFormField,
|
||||
MatGridList,
|
||||
MatGridTile,
|
||||
NgClass
|
||||
NgClass,
|
||||
TeamDisplayComponent
|
||||
],
|
||||
providers: [
|
||||
FullNamePipe,
|
||||
@@ -48,8 +51,9 @@ import {Game} from "../../model/game";
|
||||
export class MatchResultComponent {
|
||||
|
||||
result: Result = new Result();
|
||||
isValidResult: number = 0;
|
||||
|
||||
constructor(@Inject(MAT_DIALOG_DATA) public data: {match: Match, group: Group, round: Round}) {
|
||||
constructor(@Inject(MAT_DIALOG_DATA) public data: {match: Match, tournament: Tournament, event: Event, group: Group, round: Round}) {
|
||||
this.result.matchId = this.data.match.id;
|
||||
|
||||
if (data.match.games.length == 0) {
|
||||
@@ -64,6 +68,8 @@ export class MatchResultComponent {
|
||||
this.result.games.push(new Game());
|
||||
}
|
||||
}
|
||||
|
||||
this.validateResult();
|
||||
}
|
||||
|
||||
readonly dialogRef = inject(MatDialogRef<MatchResultComponent>);
|
||||
@@ -76,13 +82,18 @@ export class MatchResultComponent {
|
||||
this.result.games[game - 1].score2 = 21;
|
||||
}
|
||||
|
||||
this.validateResult();
|
||||
}
|
||||
|
||||
onAnnulerenClick() {
|
||||
this.dialogRef.close();
|
||||
}
|
||||
|
||||
validateResult(): number {
|
||||
complementScores() {
|
||||
// console.log("in complementScores");
|
||||
}
|
||||
|
||||
validateResult(): void {
|
||||
let valid : boolean = true;
|
||||
valid &&= this.gameValid(this.result.games[0].score1, this.result.games[0].score2);
|
||||
valid &&= this.gameValid(this.result.games[1].score1, this.result.games[1].score2);
|
||||
@@ -91,7 +102,7 @@ export class MatchResultComponent {
|
||||
valid &&= this.gameValid(this.result.games[2].score1, this.result.games[2].score2);
|
||||
}
|
||||
|
||||
return valid ? this.matchResult(this.result) : 0;
|
||||
this.isValidResult = valid ? this.matchResult(this.result) : 0;
|
||||
}
|
||||
|
||||
gameValid(score1: number, score2: number): boolean {
|
||||
@@ -114,29 +125,31 @@ export class MatchResultComponent {
|
||||
}
|
||||
|
||||
matchResult(result: Result): number {
|
||||
let gameBalance = 0;
|
||||
if (result.games[0].score1 < result.games[0].score2) {
|
||||
gameBalance--;
|
||||
} else {
|
||||
gameBalance++;
|
||||
let team1Wins = 0;
|
||||
let team2Wins = 0;
|
||||
|
||||
// Count wins for games 1 and 2
|
||||
if (result.games[0].score1 > result.games[0].score2) team1Wins++;
|
||||
else team2Wins++;
|
||||
|
||||
if (result.games[1].score1 > result.games[1].score2) team1Wins++;
|
||||
else team2Wins++;
|
||||
|
||||
// If match is already decided (2-0), game 3 shouldn't have scores
|
||||
if (Math.max(team1Wins, team2Wins) == 2) {
|
||||
if (result.games[2].score1 != undefined || result.games[2].score2 != undefined) {
|
||||
return 0; // Invalid
|
||||
}
|
||||
if (result.games[1].score1 < result.games[1].score2) {
|
||||
gameBalance--;
|
||||
} else {
|
||||
gameBalance++;
|
||||
}
|
||||
|
||||
if (Math.abs(gameBalance) == 2 && (result.games[2].score1 != undefined || result.games[2].score2 != undefined)) {
|
||||
return 0;
|
||||
return team1Wins > team2Wins ? 1 : -1;
|
||||
}
|
||||
|
||||
// Match is 1-1, check game 3
|
||||
if (result.games[2].score1 != undefined && result.games[2].score2 != undefined) {
|
||||
if (result.games[2].score1 < result.games[2].score2) {
|
||||
gameBalance--;
|
||||
} else {
|
||||
gameBalance++;
|
||||
}
|
||||
}
|
||||
return Math.sign(gameBalance);
|
||||
if (result.games[2].score1 > result.games[2].score2) team1Wins++;
|
||||
else team2Wins++;
|
||||
return team1Wins > team2Wins ? 1 : -1;
|
||||
}
|
||||
|
||||
return 0; // Incomplete
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,12 +3,26 @@
|
||||
<div class="nobreak">
|
||||
<mat-card appearance="outlined">
|
||||
<mat-card-content>
|
||||
<h6>{{ tournament.name }}</h6>
|
||||
<br>
|
||||
<br>
|
||||
<div class="row">
|
||||
<div class="col-6">
|
||||
<b>{{ match.team1 | teamText }}</b>
|
||||
<h5>{{ tournament.name }}</h5>
|
||||
</div>
|
||||
<div class="col-6 text-end">
|
||||
{{ group.name }} {{ round.name }}
|
||||
</div>
|
||||
</div>
|
||||
<br>
|
||||
<br>
|
||||
<div class="row align-middle">
|
||||
<div class="col-6">
|
||||
<b>
|
||||
<app-team-display
|
||||
[team]="match.team1"
|
||||
[event]="this.event"
|
||||
[tournament]="this.tournament"
|
||||
[inline]="true">
|
||||
</app-team-display>
|
||||
</b>
|
||||
</div>
|
||||
<div class="col-2">
|
||||
<mat-form-field appearance="outline">
|
||||
@@ -28,7 +42,14 @@
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-6">
|
||||
<b>{{ match.team2 | teamText }}</b>
|
||||
<b>
|
||||
<app-team-display
|
||||
[team]="match.team2"
|
||||
[event]="this.event"
|
||||
[tournament]="this.tournament"
|
||||
[inline]="true">
|
||||
</app-team-display>
|
||||
</b>
|
||||
</div>
|
||||
<div class="col-2">
|
||||
<mat-form-field appearance="outline">
|
||||
@@ -50,9 +71,6 @@
|
||||
<div class="col-6">
|
||||
<u>Graag de winnaar omcirkelen</u>
|
||||
</div>
|
||||
<div class="col-6 text-end">
|
||||
{{ group.name }} {{ round.name }}
|
||||
</div>
|
||||
</div>
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
|
||||
@@ -11,16 +11,18 @@ import {MatFormField} from "@angular/material/form-field";
|
||||
import {MatInput} from "@angular/material/input";
|
||||
import {ReactiveFormsModule} from "@angular/forms";
|
||||
import {HeaderService} from "../../service/header.service";
|
||||
import {TeamDisplayComponent} from "../team-display/team-display.component";
|
||||
import {Event} from "../../model/event";
|
||||
|
||||
@Component({
|
||||
selector: 'app-match-sheets',
|
||||
imports: [
|
||||
MatCard,
|
||||
MatCardContent,
|
||||
TeamPipe,
|
||||
MatFormField,
|
||||
MatInput,
|
||||
ReactiveFormsModule
|
||||
ReactiveFormsModule,
|
||||
TeamDisplayComponent
|
||||
],
|
||||
providers: [
|
||||
TeamPipe,
|
||||
@@ -33,6 +35,7 @@ import {HeaderService} from "../../service/header.service";
|
||||
export class MatchSheetsComponent implements OnInit, OnDestroy {
|
||||
|
||||
tournament: Tournament;
|
||||
event: Event;
|
||||
group: Group;
|
||||
round: Round;
|
||||
|
||||
@@ -54,6 +57,7 @@ export class MatchSheetsComponent implements OnInit, OnDestroy {
|
||||
for (let group of event.groups) {
|
||||
for (let round of group.rounds) {
|
||||
if (round.id == roundId) {
|
||||
this.event = event;
|
||||
this.group = group;
|
||||
this.round = round;
|
||||
this.headerService.setTitle(`Wedstrijdbriefjes ${this.group.name} ${this.round.name}`);
|
||||
|
||||
@@ -12,17 +12,24 @@ import {MatTooltip} from '@angular/material/tooltip';
|
||||
styleUrls: ['./player-display.component.scss'],
|
||||
template: `
|
||||
@let substitute = getSubstituteForEvent(player, event);
|
||||
@if (exlicitSubstitute) {
|
||||
@if (substitute) {
|
||||
{{ substitute }} (valt in voor {{ player | fullName }})
|
||||
} @else {
|
||||
{{ player | fullName }}
|
||||
}
|
||||
} @else {
|
||||
<span [class.has-substitute]="substitute"
|
||||
[matTooltip]="substitute ? 'Valt in voor ' + (player | fullName) : ''"
|
||||
matTooltipPosition="below">
|
||||
{{ substitute || (player | fullName) }}
|
||||
</span>
|
||||
matTooltipPosition="below">{{ substitute || (player | fullName) }}</span>
|
||||
}
|
||||
`
|
||||
})
|
||||
export class PlayerDisplayComponent {
|
||||
@Input({ required: true }) player!: Player;
|
||||
@Input({ required: true }) event!: Event;
|
||||
@Input({ required: true }) tournament!: Tournament;
|
||||
@Input({ required: false }) exlicitSubstitute: boolean = false;
|
||||
|
||||
getSubstituteForEvent(player: Player, event: Event): string | undefined {
|
||||
const tournamentPlayer = this.tournament.tournamentPlayers.find(
|
||||
|
||||
@@ -45,7 +45,6 @@ export class PlayerEditComponent implements OnInit {
|
||||
player: Player;
|
||||
isEditMode: boolean = false;
|
||||
|
||||
|
||||
constructor(
|
||||
private playerService: PlayerService,
|
||||
private route: ActivatedRoute,
|
||||
|
||||
@@ -39,7 +39,8 @@
|
||||
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
|
||||
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
|
||||
</table>
|
||||
<mat-paginator [pageSizeOptions]="[10, 20, 50]"
|
||||
<mat-paginator [pageSizeOptions]="[10, 25, 100]"
|
||||
[pageSize]="100"
|
||||
showFirstLastButtons
|
||||
aria-label="Select page of periodic elements">
|
||||
</mat-paginator>
|
||||
|
||||
@@ -5,3 +5,7 @@ a {
|
||||
td, th {
|
||||
background-color: transparent !important;
|
||||
}
|
||||
|
||||
.mat-mdc-row:hover {
|
||||
background-color: rgba(0, 0, 0, 0.075);
|
||||
}
|
||||
|
||||
@@ -18,14 +18,23 @@
|
||||
@if (eventRegistration.doublesEvent) {
|
||||
<mat-form-field appearance="fill">
|
||||
<mat-label>Partner</mat-label>
|
||||
<mat-select [value]="eventRegistration.partner" [disabled]="!tournamentRegistration.editable || !eventRegistration.registered" [(ngModel)]="eventRegistration.partner">
|
||||
<mat-option>Geen</mat-option>
|
||||
@for (player of getRelevantPlayers(eventRegistration.type); track player.id) {
|
||||
<input type="text"
|
||||
matInput
|
||||
[matAutocomplete]="auto"
|
||||
[disabled]="!tournamentRegistration.editable || !eventRegistration.registered"
|
||||
[(ngModel)]="eventRegistration.partner"
|
||||
(input)="onPartnerSearch($any($event.target).value, eventRegistration)"
|
||||
[name]="'partner-' + eventRegistration.id">
|
||||
<mat-autocomplete #auto="matAutocomplete"
|
||||
[displayWith]="displayPartnerName.bind(this)"
|
||||
(optionSelected)="onPartnerSelected($event, eventRegistration)">
|
||||
<mat-option [value]="null">Geen</mat-option>
|
||||
@for (player of getFilteredPlayers(eventRegistration); track player.id) {
|
||||
<mat-option [value]="player.id">
|
||||
{{ player | fullName }}
|
||||
</mat-option>
|
||||
}
|
||||
</mat-select>
|
||||
</mat-autocomplete>
|
||||
</mat-form-field>
|
||||
}
|
||||
</div>
|
||||
|
||||
@@ -9,12 +9,13 @@ import {RegistrationService} from "../../service/registration.service";
|
||||
import {MatCheckbox, MatCheckboxChange} from "@angular/material/checkbox";
|
||||
import {EventRegistration, TournamentRegistration} from "../../model/tournamentRegistration";
|
||||
import {MatOption} from "@angular/material/core";
|
||||
import {MatSelect} from "@angular/material/select";
|
||||
import {MatIcon} from "@angular/material/icon";
|
||||
import {MatAnchor, MatButton} from "@angular/material/button";
|
||||
import {MatSnackBar} from "@angular/material/snack-bar";
|
||||
import {FullNamePipe} from "../../pipes/fullname-pipe";
|
||||
import {HeaderService} from "../../service/header.service";
|
||||
import {MatAutocomplete, MatAutocompleteTrigger} from "@angular/material/autocomplete";
|
||||
import {MatInput} from "@angular/material/input";
|
||||
|
||||
@Component({
|
||||
selector: 'app-player-registrations',
|
||||
@@ -30,11 +31,14 @@ import {HeaderService} from "../../service/header.service";
|
||||
MatCardActions,
|
||||
RouterLink,
|
||||
MatOption,
|
||||
MatSelect,
|
||||
// MatSelect,
|
||||
MatIcon,
|
||||
MatButton,
|
||||
MatAnchor,
|
||||
FullNamePipe
|
||||
FullNamePipe,
|
||||
MatAutocomplete,
|
||||
MatAutocompleteTrigger,
|
||||
MatInput,
|
||||
],
|
||||
providers: [
|
||||
FullNamePipe
|
||||
@@ -52,6 +56,8 @@ export class PlayerRegistrationsComponent implements OnInit {
|
||||
|
||||
waitingForBackend: boolean = false;
|
||||
|
||||
private partnerSearchTerms: Map<number, string> = new Map();
|
||||
|
||||
constructor(
|
||||
private _snackBar: MatSnackBar,
|
||||
private playerService: PlayerService,
|
||||
@@ -76,6 +82,40 @@ export class PlayerRegistrationsComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
onPartnerSearch(searchTerm: any, eventRegistration: EventRegistration) {
|
||||
// Only treat as search if it's a string (typed input)
|
||||
if (typeof searchTerm === 'string') {
|
||||
this.partnerSearchTerms.set(eventRegistration.id, searchTerm?.toLowerCase() || '');
|
||||
}
|
||||
}
|
||||
|
||||
getFilteredPlayers(eventRegistration: EventRegistration): Player[] {
|
||||
const allRelevant = this.getRelevantPlayers(eventRegistration.type);
|
||||
const searchTerm = this.partnerSearchTerms.get(eventRegistration.id);
|
||||
|
||||
if (!searchTerm) {
|
||||
return allRelevant;
|
||||
}
|
||||
|
||||
return allRelevant.filter(player => {
|
||||
const fullName = this.fullNamePipe.transform(player).toLowerCase();
|
||||
return fullName.includes(searchTerm);
|
||||
});
|
||||
}
|
||||
|
||||
displayPartnerName(playerId: number | null): string {
|
||||
if (!playerId || !this.allPlayers) return '';
|
||||
const player = this.allPlayers.find(p => p.id === playerId);
|
||||
return player ? this.fullNamePipe.transform(player) : '';
|
||||
}
|
||||
|
||||
onPartnerSelected(event: any, eventRegistration: EventRegistration) {
|
||||
eventRegistration.partner = event.option.value;
|
||||
// Clear the search term when a partner is selected
|
||||
this.partnerSearchTerms.delete(eventRegistration.id);
|
||||
}
|
||||
|
||||
|
||||
saveRegistration(tournamentRegistration: TournamentRegistration, event: MouseEvent) {
|
||||
this.waitingForBackend = true;
|
||||
this.registrationService.saveTournamentRegistrations(tournamentRegistration, this.player.id).subscribe(data => {
|
||||
|
||||
@@ -5,9 +5,23 @@
|
||||
<tbody>
|
||||
@for (match of round.matches; track match.id) {
|
||||
<tr>
|
||||
<td class="align-middle" style="width: 45%;">{{ match.team1 | teamText }}</td>
|
||||
<td class="align-middle" style="width: 45%;">
|
||||
<app-team-display
|
||||
[team]="match.team1"
|
||||
[event]="this.event"
|
||||
[tournament]="this.tournament"
|
||||
[inline]="true">
|
||||
</app-team-display>
|
||||
</td>
|
||||
<td class="align-middle w-sep">-</td>
|
||||
<td class="align-middle" style="width: 45%;">{{ match.team2 | teamText }}</td>
|
||||
<td class="align-middle" style="width: 45%;">
|
||||
<app-team-display
|
||||
[team]="match.team2"
|
||||
[event]="this.event"
|
||||
[tournament]="this.tournament"
|
||||
[inline]="true">
|
||||
</app-team-display>
|
||||
</td>
|
||||
<td class="align-middle w-sep"></td>
|
||||
</tr>
|
||||
}
|
||||
@@ -24,18 +38,20 @@
|
||||
@for (match of round.matches; track match.id) {
|
||||
<tr>
|
||||
<td class="align-middle" style="width: 30%;">
|
||||
@if (event.doublesEvent) {
|
||||
{{ match.team1.player1 | fullName }} /<br>{{ match.team1.player2 | fullName }}
|
||||
} @else {
|
||||
{{ match.team1.player1 | fullName }}
|
||||
}
|
||||
<app-team-display
|
||||
[team]="match.team1"
|
||||
[event]="this.event"
|
||||
[tournament]="this.tournament"
|
||||
[inline]="true">
|
||||
</app-team-display>
|
||||
<td class="align-middle w-sep">-</td>
|
||||
<td class="align-middle" style="width: 30%;">
|
||||
@if (event.doublesEvent) {
|
||||
{{ match.team2.player1 | fullName }} /<br>{{ match.team2.player2 | fullName }}
|
||||
} @else {
|
||||
{{ match.team2.player1 | fullName }}
|
||||
}
|
||||
<app-team-display
|
||||
[team]="match.team2"
|
||||
[event]="this.event"
|
||||
[tournament]="this.tournament"
|
||||
[inline]="true">
|
||||
</app-team-display>
|
||||
</td>
|
||||
<td class="align-middle" style="width: 35%;">
|
||||
<div class="row result align-items-center">
|
||||
@@ -87,7 +103,15 @@
|
||||
@for (entry of round.standings.entries; track entry.position) {
|
||||
<tr>
|
||||
<td class="align-middle">{{ entry.position }}</td>
|
||||
<td class="align-middle">{{ entry.team | teamText }}</td>
|
||||
<td class="align-middle">
|
||||
<app-team-display
|
||||
[team]="entry.team"
|
||||
[event]="this.event"
|
||||
[tournament]="this.tournament"
|
||||
[inline]="true"
|
||||
[explicitSubstitute]="true">
|
||||
</app-team-display>
|
||||
</td>
|
||||
<td class="align-middle">{{ entry.played }}</td>
|
||||
<td class="align-middle">{{ entry.points / entry.played | number: '1.0-2' }}</td>
|
||||
<td class="align-middle">{{ (entry.gamesWon - entry.gamesLost) / entry.played | number: '1.0-2' }}</td>
|
||||
|
||||
@@ -8,13 +8,14 @@ import {ActivatedRoute, Router} from "@angular/router";
|
||||
import {DecimalPipe} from "@angular/common";
|
||||
import {TeamPipe} from "../../pipes/team-pipe";
|
||||
import {FullNamePipe} from "../../pipes/fullname-pipe";
|
||||
import {TeamDisplayComponent} from "../team-display/team-display.component";
|
||||
|
||||
@Component({
|
||||
selector: 'app-round-overview',
|
||||
imports: [
|
||||
TeamPipe,
|
||||
DecimalPipe,
|
||||
FullNamePipe
|
||||
TeamDisplayComponent
|
||||
],
|
||||
providers: [
|
||||
TeamPipe,
|
||||
|
||||
@@ -12,11 +12,16 @@ import {Team} from "../../model/team";
|
||||
<app-player-display
|
||||
[player]="team.player1"
|
||||
[event]="event"
|
||||
[tournament]="tournament">
|
||||
[tournament]="tournament"
|
||||
[exlicitSubstitute]="explicitSubstitute">
|
||||
</app-player-display>
|
||||
|
||||
@if (event.doublesEvent && team.player2) {
|
||||
@if (this.inline) {
|
||||
/
|
||||
} @else {
|
||||
<br />
|
||||
}
|
||||
<app-player-display
|
||||
[player]="team.player2"
|
||||
[event]="event"
|
||||
@@ -29,4 +34,6 @@ export class TeamDisplayComponent {
|
||||
@Input({ required: true }) team!: Team;
|
||||
@Input({ required: true }) event!: Event;
|
||||
@Input({ required: true }) tournament!: Tournament;
|
||||
@Input({ required: false }) inline: boolean = true;
|
||||
@Input({ required: false }) explicitSubstitute: boolean = false;
|
||||
}
|
||||
|
||||
@@ -122,42 +122,49 @@
|
||||
<span class="badge text-bg-success">{{ this.activeMatches().length }}</span>
|
||||
}
|
||||
</ng-template>
|
||||
|
||||
<div class="tab-content-wrapper">
|
||||
@if (this.activeMatches().length > 0) {
|
||||
<h6 class="mt-3"></h6>
|
||||
|
||||
@for (activeMatch of this.activeMatches(); track activeMatch.match.id) {
|
||||
<mat-expansion-panel>
|
||||
<mat-expansion-panel-header>
|
||||
<div class="col-md-2">Baan {{ activeMatch.match.court }}</div>
|
||||
<div class="col-md-2 d-flex align-items-center">Baan {{ activeMatch.match.court }}</div>
|
||||
<div class="col-md-3">
|
||||
<app-team-display
|
||||
[team]="activeMatch.match.team1"
|
||||
[event]="activeMatch.event"
|
||||
[tournament]="this.tournament">
|
||||
[tournament]="this.tournament"
|
||||
[inline]="false">
|
||||
</app-team-display>
|
||||
</div>
|
||||
<div class="col-md-1">-</div>
|
||||
<div class="col-md-1 d-flex align-items-center">-</div>
|
||||
<div class="col-md-3">
|
||||
<app-team-display
|
||||
[team]="activeMatch.match.team2"
|
||||
[event]="activeMatch.event"
|
||||
[tournament]="this.tournament">
|
||||
[tournament]="this.tournament"
|
||||
[inline]="false">
|
||||
</app-team-display>
|
||||
</div>
|
||||
<div class="col-md-3">{{ activeMatch.group.name }} {{ activeMatch.round.name }}</div>
|
||||
<div class="col-md-3 d-flex align-items-center">{{ activeMatch.group.name }} {{ activeMatch.round.name }}</div>
|
||||
</mat-expansion-panel-header>
|
||||
<div class="row">
|
||||
<hr/>
|
||||
<div class="col-md-3">Teller: {{ activeMatch.match.counter | fullName }}</div>
|
||||
<div class="col-md-5"></div>
|
||||
<div class="col-md-2">Starttijd: {{ activeMatch.match.startTime | date: 'HH:mm' }}</div>
|
||||
<div class="col-md-2">Duur: {{ getDuration(activeMatch.match.startTime) | date: 'mm:ss' }}</div>
|
||||
</div>
|
||||
<mat-action-row>
|
||||
<button class="align-baseline" mat-button (click)="editResult(activeMatch.match, activeMatch.group, activeMatch.round)">
|
||||
<mat-icon>edit</mat-icon>
|
||||
<button class="align-baseline" mat-button (click)="editResult(activeMatch.match, activeMatch.event, activeMatch.group, activeMatch.round)">
|
||||
<mat-icon>leaderboard</mat-icon>
|
||||
Uitslag invoeren
|
||||
</button>
|
||||
<button mat-button (click)="changeCounter(activeMatch.match)">
|
||||
<mat-icon>person</mat-icon>
|
||||
Teller wijzigen
|
||||
</button>
|
||||
<button mat-button (click)="stopMatch(activeMatch.match)">
|
||||
<mat-icon>stop</mat-icon>
|
||||
Wedstrijd stoppen
|
||||
@@ -169,6 +176,7 @@
|
||||
} @else {
|
||||
<h6 class="mt-3">Geen actieve wedstrijden</h6>
|
||||
}
|
||||
</div>
|
||||
</mat-tab>
|
||||
}
|
||||
@if (tournament.status == 'ONGOING' || tournament.status == 'DRAWN') {
|
||||
@@ -293,7 +301,6 @@
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
<!-- }-->
|
||||
} @else if (round.status == 'IN_PROGRESS') {
|
||||
<table class="table table-hover m-4 wide w-95">
|
||||
<tbody>
|
||||
@@ -316,18 +323,31 @@
|
||||
</td>
|
||||
<td class="align-middle w-fill">
|
||||
@if (match.status == 'NOT_STARTED') {
|
||||
@if (match.canStart) {
|
||||
<button mat-button (click)="startMatch(match)">
|
||||
<mat-icon>play_arrow</mat-icon>
|
||||
Wedstrijd starten
|
||||
</button>
|
||||
} @else {
|
||||
<span [matTooltip]="match.cantStartReason" style="cursor: not-allowed;">
|
||||
<button mat-button disabled>
|
||||
<mat-icon>play_arrow</mat-icon>
|
||||
Wedstrijd starten
|
||||
</button>
|
||||
</span>
|
||||
}
|
||||
} @else if (match.status == 'IN_PROGRESS') {
|
||||
<button mat-button (click)="editResult(match, group, round)">
|
||||
<mat-icon>edit</mat-icon>
|
||||
Uitslag invoeren
|
||||
<button mat-button (click)="editResult(match, event, group, round)">
|
||||
<mat-icon>leaderboard</mat-icon>
|
||||
Uitslag
|
||||
</button>
|
||||
<button mat-button (click)="changeCounter(match)">
|
||||
<mat-icon>person</mat-icon>
|
||||
Teller
|
||||
</button>
|
||||
<button mat-button (click)="stopMatch(match)">
|
||||
<mat-icon>stop</mat-icon>
|
||||
Wedstrijd stoppen
|
||||
Stoppen
|
||||
</button>
|
||||
} @else if (match.status == 'FINISHED') {
|
||||
<div class="row result align-items-center">
|
||||
@@ -342,8 +362,8 @@
|
||||
<mat-icon>more_vert</mat-icon>
|
||||
</button>
|
||||
<mat-menu #finishedMatchMenu="matMenu">
|
||||
<button mat-menu-item (click)="editResult(match, group, round)">
|
||||
<mat-icon>edit</mat-icon>
|
||||
<button mat-menu-item (click)="editResult(match, event, group, round)">
|
||||
<mat-icon>leaderboard</mat-icon>
|
||||
Uitslag bewerken
|
||||
</button>
|
||||
</mat-menu>
|
||||
@@ -425,7 +445,14 @@
|
||||
@for (entry of getStandingsForRound(round, group).entries; track entry.position) {
|
||||
<tr>
|
||||
<td class="align-middle">{{ entry.position }}</td>
|
||||
<td class="align-middle">{{ entry.team | teamText }}</td>
|
||||
<td class="align-middle">
|
||||
<app-team-display
|
||||
[team]="entry.team"
|
||||
[event]="event"
|
||||
[tournament]="this.tournament"
|
||||
[inline]="true">
|
||||
</app-team-display>
|
||||
</td>
|
||||
<td class="align-middle">{{ entry.played }}</td>
|
||||
<td class="align-middle">
|
||||
@if (entry.played > 0 ) {
|
||||
|
||||
@@ -39,3 +39,6 @@ td.w-fill {
|
||||
z-index: 1000 !important;
|
||||
}
|
||||
|
||||
.tab-content-wrapper {
|
||||
margin: 0 4px 0 4px;
|
||||
}
|
||||
|
||||
@@ -33,8 +33,10 @@ import {Standings} from "../../model/standings";
|
||||
import {HeaderService} from "../../service/header.service";
|
||||
import {TournamentPlayersComponent} from "../tournament-players/tournament-players.component";
|
||||
import {TournamentPlayer} from "../../model/tournamentPlayer";
|
||||
import {MatTooltip} from "@angular/material/tooltip";
|
||||
import {TeamDisplayComponent} from "../team-display/team-display.component";
|
||||
import {CounterSelectionComponent} from "../counter-selection/counter-selection.component";
|
||||
import {Observable, Subscription, tap} from "rxjs";
|
||||
import {MatTooltip} from '@angular/material/tooltip';
|
||||
|
||||
@Component({
|
||||
selector: 'app-tournament-manage',
|
||||
@@ -65,6 +67,7 @@ import {TeamDisplayComponent} from "../team-display/team-display.component";
|
||||
TournamentPlayersComponent,
|
||||
MatExpansionPanelActionRow,
|
||||
TeamDisplayComponent,
|
||||
MatTooltip,
|
||||
],
|
||||
providers: [
|
||||
FullNamePipe,
|
||||
@@ -97,10 +100,10 @@ export class TournamentManageComponent implements OnInit, OnDestroy {
|
||||
this.activeRoundTab = params['tab'];
|
||||
}
|
||||
})
|
||||
this.tournamentService.getById(Number(id)).subscribe(data => {
|
||||
this.tournament = data;
|
||||
this.headerService.setTitle(this.tournament.name);
|
||||
});
|
||||
this.loadTournament(
|
||||
this.tournamentService.getById(Number(id)),
|
||||
(tournament) => this.headerService.setTitle(tournament.name)
|
||||
);
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
@@ -151,56 +154,42 @@ export class TournamentManageComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
startRound(round: Round) {
|
||||
this.tournamentService.startRound(this.tournament.id, round.id).subscribe(data => {
|
||||
this.tournament = data;
|
||||
});
|
||||
this.loadTournament(this.tournamentService.startRound(this.tournament.id, round.id));
|
||||
}
|
||||
|
||||
finishRound(round: Round) {
|
||||
this.tournamentService.finishRound(this.tournament.id, round.id).subscribe(data => {
|
||||
this.tournament = data;
|
||||
});
|
||||
this.loadTournament(this.tournamentService.finishRound(this.tournament.id, round.id));
|
||||
}
|
||||
|
||||
finishGroup(group: Group) {
|
||||
this.tournamentService.finishGroup(this.tournament.id, group.id).subscribe(data => {
|
||||
this.tournament = data;
|
||||
});
|
||||
this.loadTournament(this.tournamentService.finishGroup(this.tournament.id, group.id));
|
||||
}
|
||||
|
||||
reopenGroup(group: Group) {
|
||||
this.tournamentService.reopenGroup(this.tournament.id, group.id).subscribe(data => {
|
||||
this.tournament = data;
|
||||
});
|
||||
this.loadTournament(this.tournamentService.reopenGroup(this.tournament.id, group.id));
|
||||
}
|
||||
|
||||
divideTournament() {
|
||||
this.tournamentService.divide(this.tournament.id).subscribe(data => {
|
||||
this.tournament = data;
|
||||
});
|
||||
this.loadTournament(this.tournamentService.divide(this.tournament.id));
|
||||
}
|
||||
|
||||
clearDivision() {
|
||||
this.tournamentService.clearDivision(this.tournament.id).subscribe(data => {
|
||||
this.tournament = data;
|
||||
});
|
||||
this.loadTournament(this.tournamentService.clearDivision(this.tournament.id));
|
||||
}
|
||||
|
||||
drawTournament() {
|
||||
this.tournamentService.draw(this.tournament.id).subscribe(data => {
|
||||
this.tournament = data;
|
||||
});
|
||||
this.loadTournament(this.tournamentService.draw(this.tournament.id));
|
||||
}
|
||||
|
||||
startMatch(match: Match) {
|
||||
const availableCourts = this.getAvailableCourts();
|
||||
|
||||
if (availableCourts.length == 0) {
|
||||
alert('Geen banen beschikbaar!');
|
||||
this._snackBar.open('Geen banen beschikbaar.')
|
||||
} else if (this.matchContainsPlayersThatArePlaying(match)) {
|
||||
alert('Deze wedstrijd bevat spelers die al aan het spelen zijn!');
|
||||
this._snackBar.open('Deze wedstrijd bevat spelers die al aan het spelen zijn.')
|
||||
} else if (this.matchContainsPlayersThatAreCounting(match)) {
|
||||
alert('Deze wedstrijd bevat spelers die aan het tellen zijn!');
|
||||
this._snackBar.open('Deze wedstrijd bevat spelers die aan het tellen zijn.')
|
||||
} else {
|
||||
this.courtSelectionDialog.open(CourtSelectionComponent, {
|
||||
data: {
|
||||
@@ -213,10 +202,7 @@ export class TournamentManageComponent implements OnInit, OnDestroy {
|
||||
minHeight: '250px'
|
||||
}).afterClosed().subscribe(result => {
|
||||
if (result != undefined) {
|
||||
console.log('Start match on court ' + result.court + ' with counter ' + result.counter.name);
|
||||
this.tournamentService.startMatch(this.tournament.id, match.id, result.court, result.counter.playerId).subscribe(data => {
|
||||
this.tournament = data;
|
||||
});
|
||||
this.loadTournament(this.tournamentService.startMatch(this.tournament.id, match.id, result.court, result.counter.playerId));
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -224,26 +210,48 @@ export class TournamentManageComponent implements OnInit, OnDestroy {
|
||||
|
||||
matchContainsPlayersThatArePlaying(match: Match): boolean {
|
||||
let matchPlayers: number[] = [];
|
||||
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);
|
||||
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);
|
||||
|
||||
let matchPlayersThatArePlaying = this.tournament.playersPlaying.filter(Set.prototype.has, new Set(matchPlayers));
|
||||
return matchPlayersThatArePlaying.length > 0;
|
||||
}
|
||||
|
||||
matchPlayersThatArePlaying(match: Match): number[] {
|
||||
let 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);
|
||||
|
||||
return this.tournament.playersPlaying.filter(Set.prototype.has, new Set(matchPlayers));
|
||||
}
|
||||
|
||||
matchContainsPlayersThatAreCounting(match: Match): boolean {
|
||||
let matchPlayers: number[] = [];
|
||||
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);
|
||||
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);
|
||||
|
||||
let matchPlayersThatAreCounting = this.tournament.playersCounting.filter(Set.prototype.has, new Set(matchPlayers));
|
||||
return matchPlayersThatAreCounting.length > 0;
|
||||
}
|
||||
|
||||
matchPlayersThatAreCounting(match: Match): number[] {
|
||||
let 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);
|
||||
|
||||
return this.tournament.playersCounting.filter(Set.prototype.has, new Set(matchPlayers));
|
||||
}
|
||||
|
||||
getTournamentPlayerFromPlayer(player: Player): TournamentPlayer {
|
||||
for (let tournamentPlayer of this.tournament.tournamentPlayers) {
|
||||
if (tournamentPlayer.playerId == player.id) {
|
||||
@@ -303,15 +311,11 @@ export class TournamentManageComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
stopMatch(match: Match) {
|
||||
this.tournamentService.stopMatch(this.tournament.id, match.id).subscribe(data => {
|
||||
this.tournament = data;
|
||||
})
|
||||
this.loadTournament(this.tournamentService.stopMatch(this.tournament.id, match.id));
|
||||
}
|
||||
|
||||
newRound(group: Group) {
|
||||
this.tournamentService.newRound(this.tournament.id, group.id).subscribe(data => {
|
||||
this.tournament = data;
|
||||
})
|
||||
this.loadTournament(this.tournamentService.newRound(this.tournament.id, group.id));
|
||||
}
|
||||
|
||||
getStrength(strength: string | undefined) {
|
||||
@@ -368,16 +372,15 @@ export class TournamentManageComponent implements OnInit, OnDestroy {
|
||||
|
||||
matchResultDialog = inject(MatDialog);
|
||||
courtSelectionDialog = inject(MatDialog);
|
||||
counterSelectionDialog = inject(MatDialog);
|
||||
|
||||
editResult(match: Match, group: Group, round: Round) {
|
||||
editResult(match: Match, event: Event, group: Group, round: Round) {
|
||||
this.matchResultDialog.open(MatchResultComponent, {
|
||||
data: {match: match, group: group, round: round},
|
||||
data: {match: match, tournament: this.tournament, event: event, group: group, round: round},
|
||||
minWidth: '800px'
|
||||
}).afterClosed().subscribe(result => {
|
||||
if (result != undefined) {
|
||||
this.tournamentService.saveResult(this.tournament.id, result.matchId, result).subscribe(data => {
|
||||
this.tournament = data;
|
||||
})
|
||||
this.loadTournament(this.tournamentService.saveResult(this.tournament.id, result.matchId, result));
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -428,6 +431,84 @@ export class TournamentManageComponent implements OnInit, OnDestroy {
|
||||
return count;
|
||||
}
|
||||
|
||||
changeCounter(match: Match) {
|
||||
this.counterSelectionDialog.open(CounterSelectionComponent, {
|
||||
data: {
|
||||
match: match,
|
||||
availableCounters: this.getAvailableCounters(match)
|
||||
},
|
||||
minWidth: '800px',
|
||||
minHeight: '250px'
|
||||
}).afterClosed().subscribe(result => {
|
||||
if (result != undefined) {
|
||||
this.loadTournament(this.tournamentService.updateCounter(this.tournament.id, match.id, result.counter.playerId));
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private loadTournament(
|
||||
observable: Observable<Tournament>,
|
||||
afterLoad?: (tournament: Tournament) => void
|
||||
): Subscription {
|
||||
return observable.subscribe(data => {
|
||||
this.tournament = data;
|
||||
this.updateMatchAvailability();
|
||||
afterLoad?.(data); // Optional chaining
|
||||
});
|
||||
}
|
||||
|
||||
private updateMatchAvailability() {
|
||||
for (const event of this.tournament.events) {
|
||||
for (const group of event.groups) {
|
||||
for (const round of group.rounds) {
|
||||
for (const match of round.matches) {
|
||||
let canStart = true;
|
||||
let matchPlayersThatArePlaying = this.matchPlayersThatArePlaying(match);
|
||||
let matchPlayersThatAreCounting = this.matchPlayersThatAreCounting(match);
|
||||
|
||||
let cantStartReason = "";
|
||||
|
||||
if (matchPlayersThatArePlaying.length > 0) {
|
||||
canStart = false;
|
||||
cantStartReason = this.joinWithEn(matchPlayersThatArePlaying.map(m => this.getTournamentPlayerFromId(m).name));
|
||||
if (matchPlayersThatArePlaying.length == 1) {
|
||||
cantStartReason += " is al aan het spelen";
|
||||
} else {
|
||||
cantStartReason += " zijn al aan het spelen";
|
||||
}
|
||||
}
|
||||
|
||||
if (matchPlayersThatAreCounting.length > 0) {
|
||||
canStart = false;
|
||||
if (cantStartReason.length > 0) {
|
||||
cantStartReason += " en ";
|
||||
}
|
||||
cantStartReason += this.joinWithEn(matchPlayersThatAreCounting.map(m => this.getTournamentPlayerFromId(m).name));
|
||||
if (matchPlayersThatAreCounting.length == 1) {
|
||||
cantStartReason += " is aan het tellen";
|
||||
} else {
|
||||
cantStartReason += " zijn aan het tellen";
|
||||
}
|
||||
}
|
||||
|
||||
match.canStart = canStart;
|
||||
match.cantStartReason = cantStartReason;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
joinWithEn(items: string[], separator = ", "): string {
|
||||
const len = items.length;
|
||||
|
||||
if (len === 0) return "";
|
||||
if (len === 1) return items[0];
|
||||
if (len === 2) return items.join(" en ");
|
||||
|
||||
return items.slice(0, -1).join(separator) + `${separator}and ${items[len - 1]}`;
|
||||
}
|
||||
}
|
||||
|
||||
class ActiveMatch {
|
||||
|
||||
@@ -2,14 +2,13 @@ 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 {ActivatedRoute} 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";
|
||||
@@ -34,15 +33,27 @@ import {MatTab, MatTabGroup, MatTabLabel} from "@angular/material/tabs";
|
||||
standalone: true,
|
||||
styleUrl: './tournament-players.component.scss'
|
||||
})
|
||||
export class TournamentPlayersComponent {
|
||||
export class TournamentPlayersComponent implements OnInit {
|
||||
|
||||
@Input() tournament: Tournament;
|
||||
|
||||
constructor(
|
||||
private tournamentService: TournamentService,
|
||||
private route: ActivatedRoute,
|
||||
private _snackBar: MatSnackBar,
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
if (!this.tournament) {
|
||||
const id = Number(this.route.snapshot.paramMap.get('id'));
|
||||
if (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.');
|
||||
@@ -67,13 +78,8 @@ export class TournamentPlayersComponent {
|
||||
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);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -13,4 +13,6 @@ export class Match {
|
||||
games: Game[];
|
||||
court: number;
|
||||
counter: Player;
|
||||
canStart?: boolean;
|
||||
cantStartReason?: string;
|
||||
}
|
||||
|
||||
@@ -97,6 +97,10 @@ export class TournamentService {
|
||||
return this.http.post<Tournament>(`${this.tournamentsUrl}/${tournamentId}/players/${playerId}/substitutions`, substitutions)
|
||||
}
|
||||
|
||||
public updateCounter(tournamentId: number, matchId: number, counter: number): Observable<Tournament> {
|
||||
return this.http.patch<Tournament>(`${this.tournamentsUrl}/${tournamentId}/matches/${matchId}/update?counter=${counter}`, null);
|
||||
}
|
||||
|
||||
public addTestData(): Observable<void> {
|
||||
return this.http.get<void>(`${environment.backendUrl}/testdata`);
|
||||
}
|
||||
|
||||
@@ -7,3 +7,6 @@ body { margin: 0; font-family: Roboto, "Helvetica Neue", sans-serif; }
|
||||
z-index: 2000 !important;
|
||||
}
|
||||
*/
|
||||
.mat-tooltip {
|
||||
white-space: pre-line !important;
|
||||
}
|
||||
|
||||
@@ -3114,6 +3114,11 @@ jsonparse@^1.3.1:
|
||||
resolved "https://registry.npmjs.org/jsonparse/-/jsonparse-1.3.1.tgz"
|
||||
integrity sha512-POQXvpdL69+CluYsillJ7SUhKvytYjW9vG/GKpnf+xP8UWgYEM/RaMzHHofbALDiKbbP1W8UEYmgGl39WkPZsg==
|
||||
|
||||
jwt-decode@^4.0.0:
|
||||
version "4.0.0"
|
||||
resolved "https://registry.npmjs.org/jwt-decode/-/jwt-decode-4.0.0.tgz"
|
||||
integrity sha512-+KJGIyHgkGuIq3IEBNftfhW/LfWhXUIY6OmyVWjliu5KH1y0fw7VQ8YndE2O4qZdMSd9SqbnC8GOcZEy0Om7sA==
|
||||
|
||||
karma-chrome-launcher@~3.2.0:
|
||||
version "3.2.0"
|
||||
resolved "https://registry.npmjs.org/karma-chrome-launcher/-/karma-chrome-launcher-3.2.0.tgz"
|
||||
|
||||
Reference in New Issue
Block a user