From 83c6b6e504b5e8d2402636c29b150c23a3701b8c Mon Sep 17 00:00:00 2001 From: ExostFlash Date: Mon, 2 Jun 2025 15:04:33 +0200 Subject: [PATCH] modif match --- .../src/app/app-routing.module.ts | 2 + FencerJudgeFront/src/app/app.module.ts | 2 + .../matches-id/matches-id.component.css | 3 + .../matches-id/matches-id.component.html | 94 ++++++++++++ .../matches-id/matches-id.component.spec.ts | 23 +++ .../matches-id/matches-id.component.ts | 141 ++++++++++++++++++ .../components/matches/matches.component.html | 2 + .../components/matches/matches.component.ts | 8 +- .../src/app/services/matches.service.ts | 10 ++ 9 files changed, 284 insertions(+), 1 deletion(-) create mode 100644 FencerJudgeFront/src/app/components/matches-id/matches-id.component.css create mode 100644 FencerJudgeFront/src/app/components/matches-id/matches-id.component.html create mode 100644 FencerJudgeFront/src/app/components/matches-id/matches-id.component.spec.ts create mode 100644 FencerJudgeFront/src/app/components/matches-id/matches-id.component.ts diff --git a/FencerJudgeFront/src/app/app-routing.module.ts b/FencerJudgeFront/src/app/app-routing.module.ts index 5bf8bf7..fcdc89f 100644 --- a/FencerJudgeFront/src/app/app-routing.module.ts +++ b/FencerJudgeFront/src/app/app-routing.module.ts @@ -7,6 +7,7 @@ import { LoginComponent } from './components/essentials/login/login.component'; import { LogoutComponent } from './components/essentials/logout/logout.component'; import { HomeComponent } from './components/home/home.component'; import { MatchesComponent } from './components/matches/matches.component'; +import { MatchesIdComponent } from './components/matches-id/matches-id.component'; const routes: Routes = [ { path: 'login', component: LoginComponent }, @@ -14,6 +15,7 @@ const routes: Routes = [ { path: '', component: HomeComponent }, { path: 'home', component: HomeComponent }, { path: 'matches', component: MatchesComponent }, + { path: 'matches/:id', component: MatchesIdComponent }, ]; @NgModule({ diff --git a/FencerJudgeFront/src/app/app.module.ts b/FencerJudgeFront/src/app/app.module.ts index a3dd923..0c33646 100644 --- a/FencerJudgeFront/src/app/app.module.ts +++ b/FencerJudgeFront/src/app/app.module.ts @@ -10,6 +10,7 @@ import { HomeComponent } from './components/home/home.component'; import { LoginComponent } from './components/essentials/login/login.component'; import { LogoutComponent } from './components/essentials/logout/logout.component'; import { MatchesComponent } from './components/matches/matches.component'; +import { MatchesIdComponent } from './components/matches-id/matches-id.component'; @NgModule({ declarations: [ @@ -20,6 +21,7 @@ import { MatchesComponent } from './components/matches/matches.component'; LoginComponent, LogoutComponent, MatchesComponent, + MatchesIdComponent, ], imports: [BrowserModule, AppRoutingModule, FormsModule], providers: [], diff --git a/FencerJudgeFront/src/app/components/matches-id/matches-id.component.css b/FencerJudgeFront/src/app/components/matches-id/matches-id.component.css new file mode 100644 index 0000000..f517d5c --- /dev/null +++ b/FencerJudgeFront/src/app/components/matches-id/matches-id.component.css @@ -0,0 +1,3 @@ +.card { + border-left-width: 0.5rem !important; +} diff --git a/FencerJudgeFront/src/app/components/matches-id/matches-id.component.html b/FencerJudgeFront/src/app/components/matches-id/matches-id.component.html new file mode 100644 index 0000000..38721f0 --- /dev/null +++ b/FencerJudgeFront/src/app/components/matches-id/matches-id.component.html @@ -0,0 +1,94 @@ +
+

Détail du Match

+ +
+
+
+
+ {{ match.city }}, {{ match.country }} +
+ {{ match.date | date : "fullDate" }} - + {{ match.date | date : "shortTime" }} +
+ {{ match.weapon }} +
+ +
+
+ {{ player1?.firstName }} {{ player1?.name }}
+ {{ player1?.club }} +
+ +
+ + + {{ match.score1 }} + + vs + + {{ match.score2 }} + + + + + {{ match.score1 }} + vs + {{ match.score2 }} + +
+ +
+ {{ player2?.firstName }} {{ player2?.name }}
+ {{ player2?.club }} +
+
+ +
+ + {{ getMatchStateLabel(match.state) }} + +
+ +
+
Arbitre
+
+

+ {{ referee.firstName }} {{ referee.name }} +

+

+ Niveau : {{ getRefereeLevelLabel(referee.level) }} +

+
+
+

Arbitre non trouvé.

+
+
+
+
+
+ + +
+

Match non trouvé.

+
diff --git a/FencerJudgeFront/src/app/components/matches-id/matches-id.component.spec.ts b/FencerJudgeFront/src/app/components/matches-id/matches-id.component.spec.ts new file mode 100644 index 0000000..b09ff2d --- /dev/null +++ b/FencerJudgeFront/src/app/components/matches-id/matches-id.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { MatchesIdComponent } from './matches-id.component'; + +describe('MatchesIdComponent', () => { + let component: MatchesIdComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [MatchesIdComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(MatchesIdComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/FencerJudgeFront/src/app/components/matches-id/matches-id.component.ts b/FencerJudgeFront/src/app/components/matches-id/matches-id.component.ts new file mode 100644 index 0000000..2e0be56 --- /dev/null +++ b/FencerJudgeFront/src/app/components/matches-id/matches-id.component.ts @@ -0,0 +1,141 @@ +import { Component, OnInit } from '@angular/core'; +import { ActivatedRoute } from '@angular/router'; +import { AuthService } from '@services/auth.service'; + +import { MatchesService } from '@services/matches.service'; +import { MatchState, Matches } from '@interfaces/matches'; +import { PlayerService } from '@services/player.service'; +import { Player } from '@interfaces/player'; +import { RefereeService } from '@services/referee.service'; +import { Referee, RefereeLevel } from '@interfaces/referee'; + +@Component({ + selector: 'app-matches-id', + standalone: false, + templateUrl: './matches-id.component.html', + styleUrl: './matches-id.component.css', +}) +export class MatchesIdComponent implements OnInit { + match: Matches | undefined; + player1: Player | undefined; + player2: Player | undefined; + referee: Referee | undefined; + + constructor( + private route: ActivatedRoute, + private matchService: MatchesService, + private playerService: PlayerService, + private refereeService: RefereeService, + public authService: AuthService + ) {} + + ngOnInit(): void { + const id = Number(this.route.snapshot.paramMap.get('id')); + this.matchService.getMatchById(id).subscribe((match) => { + if (match) { + this.match = match; + + this.playerService + .getPlayerById(match.player1ID) + .subscribe((p1) => (this.player1 = p1!)); + this.playerService + .getPlayerById(match.player2ID) + .subscribe((p2) => (this.player2 = p2!)); + + this.refereeService + .getRefereeById(match.refereeID) + .subscribe((ref) => (this.referee = ref!)); + } + }); + } + + saveScores(): void { + if (this.match) { + this.matchService.updateMatch(this.match.id, { + score1: this.match.score1, + score2: this.match.score2, + }); + } + } + + getMatchStateLabel(state: MatchState): string { + switch (state) { + case MatchState.NOT_STARTED: + return 'À venir'; + case MatchState.ONGOING: + return 'En cours'; + case MatchState.OVER: + return 'Terminé'; + default: + return 'Inconnu'; + } + } + + getMatchStateColor(state: MatchState): string { + switch (state) { + case MatchState.NOT_STARTED: + return 'secondary'; + case MatchState.ONGOING: + return 'warning'; + case MatchState.OVER: + return 'success'; + default: + return 'light'; + } + } + + getRefereeLevelLabel(level: RefereeLevel): string { + switch (level) { + case RefereeLevel.NATIONAL: + return 'National'; + case RefereeLevel.REGIONAL: + return 'Régional'; + case RefereeLevel.DEPARTMENTAL: + return 'Départemental'; + default: + return 'Inconnu'; + } + } + + updateScores(): void { + if (this.match) { + this.matchService.updateMatch(this.match.id, { + score1: this.match.score1, + score2: this.match.score2, + }); + } + } + + incrementScore(player: 1 | 2): void { + if (!this.match) return; + + // Incrémente le score du joueur + if (player === 1) { + this.match.score1 += 1; + } else { + this.match.score2 += 1; + } + + // Change l'état en fonction des scores + if ( + this.match.score1 === 1 && + this.match.score2 === 0 && + this.match.state === MatchState.NOT_STARTED + ) { + this.match.state = MatchState.ONGOING; // passage à l'état 1 (en cours) + } else if ( + this.match.score2 === 1 && + this.match.score1 === 0 && + this.match.state === MatchState.NOT_STARTED + ) { + this.match.state = MatchState.ONGOING; + } + + // Si l'un des scores arrive à 15, on considère le match terminé + if (this.match.score1 >= 15 || this.match.score2 >= 15) { + this.match.state = MatchState.OVER; // passage à l'état 2 (terminé) + } + + this.updateScores(); + } +} diff --git a/FencerJudgeFront/src/app/components/matches/matches.component.html b/FencerJudgeFront/src/app/components/matches/matches.component.html index a5561bb..e7036ad 100644 --- a/FencerJudgeFront/src/app/components/matches/matches.component.html +++ b/FencerJudgeFront/src/app/components/matches/matches.component.html @@ -6,6 +6,8 @@
diff --git a/FencerJudgeFront/src/app/components/matches/matches.component.ts b/FencerJudgeFront/src/app/components/matches/matches.component.ts index 935e3d1..623f011 100644 --- a/FencerJudgeFront/src/app/components/matches/matches.component.ts +++ b/FencerJudgeFront/src/app/components/matches/matches.component.ts @@ -1,4 +1,5 @@ import { Component } from '@angular/core'; +import { Router } from '@angular/router'; import { MatchesService } from '@services/matches.service'; import { Matches, MatchState } from '@interfaces/matches'; @@ -19,7 +20,8 @@ export class MatchesComponent { constructor( private matchesService: MatchesService, - private playerService: PlayerService + private playerService: PlayerService, + private router: Router ) {} ngOnInit(): void { @@ -63,4 +65,8 @@ export class MatchesComponent { return 'Inconnu'; } } + + goToMatchDetail(matchId: number): void { + this.router.navigate(['/matches', matchId]); + } } diff --git a/FencerJudgeFront/src/app/services/matches.service.ts b/FencerJudgeFront/src/app/services/matches.service.ts index 12a6201..fef45dd 100644 --- a/FencerJudgeFront/src/app/services/matches.service.ts +++ b/FencerJudgeFront/src/app/services/matches.service.ts @@ -68,4 +68,14 @@ export class MatchesService { ); // ici tu pourrais plus tard faire : this.socket = new WebSocket('ws://...') etc. } + + updateMatch(id: number, updatedData: Partial): void { + const match = this.matches.find((m) => m.id === id); + if (match) { + Object.assign(match, updatedData); + console.log(`[MatchesService] Match ${id} mis à jour :`, match); + } else { + console.warn(`[MatchesService] Match ${id} introuvable`); + } + } }