Add list matchs

This commit is contained in:
ExostFlash 2025-06-02 14:06:26 +02:00
parent e05f356bee
commit f61416c4d0
6 changed files with 152 additions and 0 deletions

View file

@ -6,12 +6,14 @@ import { authGuard } from '@guards/auth.guard';
import { LoginComponent } from './components/essentials/login/login.component'; import { LoginComponent } from './components/essentials/login/login.component';
import { LogoutComponent } from './components/essentials/logout/logout.component'; import { LogoutComponent } from './components/essentials/logout/logout.component';
import { HomeComponent } from './components/home/home.component'; import { HomeComponent } from './components/home/home.component';
import { MatchesComponent } from './components/matches/matches.component';
const routes: Routes = [ const routes: Routes = [
{ path: 'login', component: LoginComponent }, { path: 'login', component: LoginComponent },
{ path: 'logout', component: LogoutComponent }, { path: 'logout', component: LogoutComponent },
{ path: '', component: HomeComponent }, { path: '', component: HomeComponent },
{ path: 'home', component: HomeComponent }, { path: 'home', component: HomeComponent },
{ path: 'matches', component: MatchesComponent },
]; ];
@NgModule({ @NgModule({

View file

@ -9,6 +9,7 @@ import { FooterComponent } from './components/essentials/footer/footer.component
import { HomeComponent } from './components/home/home.component'; import { HomeComponent } from './components/home/home.component';
import { LoginComponent } from './components/essentials/login/login.component'; import { LoginComponent } from './components/essentials/login/login.component';
import { LogoutComponent } from './components/essentials/logout/logout.component'; import { LogoutComponent } from './components/essentials/logout/logout.component';
import { MatchesComponent } from './components/matches/matches.component';
@NgModule({ @NgModule({
declarations: [ declarations: [
@ -18,6 +19,7 @@ import { LogoutComponent } from './components/essentials/logout/logout.component
HomeComponent, HomeComponent,
LoginComponent, LoginComponent,
LogoutComponent, LogoutComponent,
MatchesComponent,
], ],
imports: [BrowserModule, AppRoutingModule, FormsModule], imports: [BrowserModule, AppRoutingModule, FormsModule],
providers: [], providers: [],

View file

@ -0,0 +1,8 @@
.border-start-5 {
border-left: 5px solid #ccc;
}
.card:hover {
transform: translateY(-2px);
transition: 0.2s ease-in-out;
}

View file

@ -0,0 +1,51 @@
<div class="container my-4">
<h2 class="mb-4 text-center">Liste des Matchs</h2>
<div class="row g-4">
<div class="col-md-6" *ngFor="let match of matches">
<div
class="card shadow-sm border-start-5"
[ngClass]="getMatchBorderColor(match.state)"
>
<div class="card-body">
<div class="d-flex justify-content-between align-items-center mb-2">
<h5 class="mb-0">
{{ match.city }} —
<small class="text-muted">{{
match.date | date : "longDate"
}}</small>
</h5>
<span class="badge bg-light text-dark">{{ match.weapon }}</span>
</div>
<div class="d-flex justify-content-between align-items-center">
<div class="text-start">
<strong>{{ getPlayerName(match.player1ID) }}</strong>
<span class="badge bg-primary ms-2">{{ match.score1 }}</span>
</div>
<div class="text-center text-muted">vs</div>
<div class="text-end">
<strong>{{ getPlayerName(match.player2ID) }}</strong>
<span class="badge bg-primary ms-2">{{ match.score2 }}</span>
</div>
</div>
<div class="mt-3">
<span
class="badge"
[ngClass]="{
'bg-secondary': match.state === MatchState.NOT_STARTED,
'bg-warning text-dark': match.state === MatchState.ONGOING,
'bg-success': match.state === MatchState.OVER
}"
>
{{ getMatchStatusLabel(match.state) }}
</span>
</div>
</div>
</div>
</div>
</div>
</div>

View file

@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { MatchesComponent } from './matches.component';
describe('MatchesComponent', () => {
let component: MatchesComponent;
let fixture: ComponentFixture<MatchesComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [MatchesComponent]
})
.compileComponents();
fixture = TestBed.createComponent(MatchesComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View file

@ -0,0 +1,66 @@
import { Component } from '@angular/core';
import { MatchesService } from '@services/matches.service';
import { Matches, MatchState } from '@interfaces/matches';
import { PlayerService } from '@services/player.service';
import { Player } from '@interfaces/player';
@Component({
selector: 'app-matches',
standalone: false,
templateUrl: './matches.component.html',
styleUrl: './matches.component.css',
})
export class MatchesComponent {
matches: Matches[] = [];
playersMap: Map<number, Player> = new Map();
MatchState = MatchState;
constructor(
private matchesService: MatchesService,
private playerService: PlayerService
) {}
ngOnInit(): void {
this.playerService.getPlayers().subscribe((players) => {
// construire la map ID -> joueur
players.forEach((player) => this.playersMap.set(player.id, player));
});
this.matchesService.getMatches().subscribe((data) => {
this.matches = data;
});
}
getPlayerName(id: number): string {
const player = this.playersMap.get(id);
return player ? `${player.firstName} ${player.name}` : 'Joueur inconnu';
}
getMatchBorderColor(state: MatchState): string {
switch (state) {
case MatchState.NOT_STARTED:
return 'border-secondary';
case MatchState.ONGOING:
return 'border-warning';
case MatchState.OVER:
return 'border-success';
default:
return 'border-light';
}
}
getMatchStatusLabel(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';
}
}
}