first step for plr game platform

This commit is contained in:
OnlyPapy98
2025-12-29 13:56:18 +01:00
parent 169b5ca412
commit ed79cae77d
40 changed files with 620 additions and 373 deletions

View File

@@ -18,7 +18,7 @@ import { Course as CourseType } from 'src/app/core/interfaces/course';
import { SortDir } from '@shared/paging/paging';
import { CourseApiResponse, CourseService } from 'src/app/core/services/course';
import { ResultatService } from 'src/app/core/services/resultat';
import { Resultat } from 'src/app/core/interfaces/resultat';
import { Resultat, ResultatStatut } from 'src/app/core/interfaces/resultat';
import { A11yModule } from '@angular/cdk/a11y';
import { CourseForm } from '@shared/forms/course-form/course-form';
import { NonPartantForm } from '@shared/forms/nonpartant-form/nonpartant-form';
@@ -57,10 +57,10 @@ export class Course {
totalClosed = signal(0);
totalByType = signal<Record<string, number>>({});
page = signal(1);
page = signal(0);
perPage = signal(10);
search = signal('');
sort = signal<SortState>({ key: 'numero', dir: 'asc' });
sort = signal<SortState>({ key: 'id', dir: 'asc' });
pageSize = [10, 20, 50];
modalOpen = signal(false);
@@ -102,40 +102,42 @@ export class Course {
return '<span class="text-gray-500 dark:text-gray-400">—</span>';
}
// Group horses that are at the same place (ex-aequo/dead heat).
// Backend/Resultat model store ordreArrivee as cheval numbers (1,2,3,...) and
// chevauxDeadHeat as the subset that are ex-aequo.
const deadHeatSet = new Set(resultat.chevauxDeadHeat || []);
return `<span class="text-gray-500 dark:text-gray-400">${resultat.ordreArrivee}</span>`
const groups: number[][] = [];
let currentGroup: number[] = [];
// // Group horses that are at the same place (ex-aequo/dead heat).
// // Backend/Resultat model store ordreArrivee as cheval numbers (1,2,3,...) and
// // chevauxDeadHeat as the subset that are ex-aequo.
// const deadHeatSet = new Set(resultat.chevauxDeadHeat || []);
resultat.ordreArrivee.forEach((num, index) => {
const isInDeadHeat = deadHeatSet.has(num);
const prevNum = index > 0 ? resultat.ordreArrivee[index - 1] : null;
const prevIsInDeadHeat = prevNum !== null && deadHeatSet.has(prevNum);
// const groups: number[][] = [];
// let currentGroup: number[] = [];
if (isInDeadHeat && prevIsInDeadHeat && currentGroup.length > 0) {
// Continue the current dead heat group
currentGroup.push(num);
} else {
// Start a new group
if (currentGroup.length > 0) {
groups.push(currentGroup);
}
currentGroup = [num];
}
});
// resultat.ordreArrivee.forEach((num, index) => {
// const isInDeadHeat = deadHeatSet.has(num);
// const prevNum = index > 0 ? resultat.ordreArrivee[index - 1] : null;
// const prevIsInDeadHeat = prevNum !== null && deadHeatSet.has(prevNum);
// Don't forget the last group
if (currentGroup.length > 0) {
groups.push(currentGroup);
}
// if (isInDeadHeat && prevIsInDeadHeat && currentGroup.length > 0) {
// // Continue the current dead heat group
// currentGroup.push(num);
// } else {
// // Start a new group
// if (currentGroup.length > 0) {
// groups.push(currentGroup);
// }
// currentGroup = [num];
// }
// });
const s = groups.map((nums) => nums.join('=')).join(' - ');
// // Don't forget the last group
// if (currentGroup.length > 0) {
// groups.push(currentGroup);
// }
// For now, we'll show the resultat. In the future, we might add a statut field to Resultat
return `<span class="mr-2">${s}</span>`;
// const s = groups.map((nums) => nums.join('=')).join(' - ');
// // For now, we'll show the resultat. In the future, we might add a statut field to Resultat
// return ;
},
},
{
@@ -187,7 +189,7 @@ export class Course {
effect(() => {
const params = {
page: this.page(),
perPage: this.perPage(),
size: this.perPage(),
search: this.search(),
sortKey: this.sort().key,
sortDir: this.sort().dir as SortDir,
@@ -198,7 +200,7 @@ export class Course {
private fetch(params: {
page: number;
perPage: number;
size: number;
search: string;
sortKey: string;
sortDir: SortDir;
@@ -256,7 +258,7 @@ export class Course {
// === UI Actions ===
onSearch(q: string) {
this.search.set(q);
this.page.set(1);
this.page.set(0);
}
openCreate() {
@@ -283,21 +285,15 @@ export class Course {
this.formComp?.onSubmit();
}
onFormSave(payload: Partial<CourseType>) {
const current = this.editingItem();
const req$ = current?.id
? this.api.update(current.id, payload)
: this.api.create(payload as Omit<CourseApiResponse, 'id'>);
req$.subscribe(() => {
this.closeModal();
this.fetch({
page: this.page(),
perPage: this.perPage(),
search: this.search(),
sortKey: this.sort().key,
sortDir: this.sort().dir,
});
onFormSave(_: CourseType) {
// The form now persists create/update itself. Just close and refresh.
this.closeModal();
this.fetch({
page: this.page(),
size: this.perPage(),
search: this.search(),
sortKey: this.sort().key,
sortDir: this.sort().dir,
});
}
@@ -307,7 +303,7 @@ export class Course {
this.api.delete(row.id).subscribe(() =>
this.fetch({
page: this.page(),
perPage: this.perPage(),
size: this.perPage(),
search: this.search(),
sortKey: this.sort().key,
sortDir: this.sort().dir,
@@ -360,7 +356,7 @@ export class Course {
this.closeNonPartantModal();
this.fetch({
page: this.page(),
perPage: this.perPage(),
size: this.perPage(),
search: this.search(),
sortKey: this.sort().key,
sortDir: this.sort().dir,
@@ -381,20 +377,22 @@ export class Course {
this.selectedCourseForResultat.set(null);
}
onResultatSave(places: number[][]) {
onResultatSave(places: number[][], typesParisOuverts: string[]) {
const c = this.selectedCourseForResultat();
if (!c) return;
// Determine required number of horses based on course type
const getRequiredHorses = (type: string): number => {
const typeStr = String(type).toUpperCase();
if (typeStr.includes('TIERCE') || typeStr === 'PLAT') return 3;
if (typeStr.includes('QUARTE')) return 4;
const getRequiredHorses = (types: string[]): number => {
const typeStr = types;
if (typeStr.includes('PLACE') || typeStr.includes('GAGNANT')) return 3;
if(typeStr.includes('JUMELE_GAGNANT') || typeStr.includes('JUMELE_PLACE') || typeStr.includes('JUMELE_ORDRE')) return 2;
if(typeStr.includes('TRIO') || typeStr.includes('TRIO_ORDRE') || typeStr.includes('TRIPLET')) return 3
if (typeStr.includes('QUATRO')) return 4;
if (typeStr.includes('QUINTE')) return 5;
return 3; // Default
};
const requiredHorses = 3;
const requiredHorses = getRequiredHorses(typesParisOuverts);
// Collect all selected horses (flatten the places array)
const allHorses: number[] = places
@@ -409,46 +407,28 @@ export class Course {
// Convert to ordreArrivee format
// If all are ex-aequo, they all go in ordreArrivee as they are (first place)
// Otherwise, distribute them across places
const ordreArrivee: Array<string> = [];
const chevauxDeadHeat: number[] = [];
if (isAllExAequo) {
// All horses are in first place (ex-aequo)
allHorses.forEach((numero) => {
ordreArrivee.push(numero.toString());
chevauxDeadHeat.push(numero);
});
} else {
// Horses are distributed across places
places.forEach((placeGroup, placeIndex) => {
const validHorses = placeGroup.filter((n) => typeof n === 'number' && n > 0);
if (validHorses.length === 0) return;
const isDeadHeat = validHorses.length > 1;
validHorses.forEach((numero) => {
ordreArrivee.push(numero.toString());
if (isDeadHeat) {
chevauxDeadHeat.push(numero);
}
});
});
}
let ordreArrivee: string = '';
places.forEach((place)=>{
if(Array.isArray(place) && place.length>1){
place.forEach((p, index)=>{
if(index == 0){
ordreArrivee = ordreArrivee ==''? String(p) : ordreArrivee+","+String(p)
}else{
ordreArrivee = ordreArrivee ==''? String(p) : ordreArrivee+"="+String(p)
}
})
}else{
ordreArrivee = ordreArrivee ==''? String(place[0]): ordreArrivee+","+String(place[0])
}
})
// Check if resultat already exists
const existingResultat = this.resultatsMap().get(c.id);
const payload = {
course: { id: c.id },
courseId: Number(c.id) ,
ordreArrivee,
chevauxDeadHeat: chevauxDeadHeat.map((n) => String(n)),
totalMises: 0,
masseAPartager: 0,
prelevementsLegaux: 0,
montantRembourse: 0,
montantCagnotte: 0,
adeadHeat: chevauxDeadHeat.length > 0,
statut: ResultatStatut.EN_ATTENTE,
};
const request$ = existingResultat
@@ -460,7 +440,7 @@ export class Course {
this.closeResultatModal();
this.fetch({
page: this.page(),
perPage: this.perPage(),
size: this.perPage(),
search: this.search(),
sortKey: this.sort().key,
sortDir: this.sort().dir,
@@ -490,7 +470,7 @@ export class Course {
this.closeResultatModal();
this.fetch({
page: this.page(),
perPage: this.perPage(),
size: this.perPage(),
search: this.search(),
sortKey: this.sort().key,
sortDir: this.sort().dir,
@@ -520,7 +500,7 @@ export class Course {
this.closeResultatModal();
this.fetch({
page: this.page(),
perPage: this.perPage(),
size: this.perPage(),
search: this.search(),
sortKey: this.sort().key,
sortDir: this.sort().dir,