test
This commit is contained in:
@@ -4,8 +4,11 @@ import { DataTable, TableColumn } from '@shared/components/data-table/data-table
|
||||
import { ZardButtonComponent } from '@shared/components/button/button.component';
|
||||
import { ZardPaginationModule } from '@shared/components/pagination/pagination.module';
|
||||
import { ListParams, PagedResult } from '@shared/paging/paging';
|
||||
import { ResultatApiResponse } from 'src/app/core/interfaces/resultat';
|
||||
import { ResultatApiResponse, ResultatStatut } from 'src/app/core/interfaces/resultat';
|
||||
import { ResultatService } from 'src/app/core/services/resultat';
|
||||
import { Depouillement, ResultatCourse } from 'src/app/core/services/depouillement';
|
||||
import { Course } from 'src/app/core/interfaces/course';
|
||||
import { toast } from 'ngx-sonner';
|
||||
|
||||
@Component({
|
||||
standalone: true,
|
||||
@@ -17,6 +20,7 @@ import { ResultatService } from 'src/app/core/services/resultat';
|
||||
export class Rapport {
|
||||
rows = signal<ResultatApiResponse[]>([]);
|
||||
loading = signal(false);
|
||||
sending = signal<Map<string, boolean>>(new Map());
|
||||
// Pagination state
|
||||
page = signal<number>(1);
|
||||
perPage = signal<number>(10);
|
||||
@@ -34,7 +38,7 @@ export class Rapport {
|
||||
{ key: 'dateValidation', label: 'Date validation' },
|
||||
];
|
||||
|
||||
constructor(private api: ResultatService) {
|
||||
constructor(private api: ResultatService, private depouillement: Depouillement) {
|
||||
// initial load
|
||||
this.fetch();
|
||||
}
|
||||
@@ -85,10 +89,90 @@ export class Rapport {
|
||||
openReport(row: ResultatApiResponse) {
|
||||
try {
|
||||
// Open a per-result report URL in a new tab. Adjust path if your server uses another route.
|
||||
const url = `/rapport/${row.id}`;
|
||||
const url = `/resultat/${row.id}`;
|
||||
window.open(url, '_blank');
|
||||
} catch (err) {
|
||||
console.error('Failed to open report for', row, err);
|
||||
}
|
||||
}
|
||||
|
||||
isSending(id: string | number) {
|
||||
return !!this.sending().get(String(id));
|
||||
}
|
||||
|
||||
private setSending(id: string | number, v: boolean) {
|
||||
const map = new Map(this.sending());
|
||||
map.set(String(id), v);
|
||||
this.sending.set(map);
|
||||
}
|
||||
|
||||
sendToDepouillement(row: ResultatApiResponse) {
|
||||
if (!row || !row.id) return;
|
||||
const id = String(row.id);
|
||||
if (this.isSending(id)) return; // already sending
|
||||
|
||||
this.setSending(id, true);
|
||||
|
||||
// Build a minimal ResultatCourse payload using available fields.
|
||||
const course: Course = {
|
||||
id: String((row as any).courseId ?? ''),
|
||||
hippodrome: undefined,
|
||||
reunionNumero: Number((row as any).reunionNumero ?? 0),
|
||||
reunionDate: '',
|
||||
nom: row.courseNom ?? '',
|
||||
numero: Number(row.courseNumero ?? 0),
|
||||
heureDepartPrevue: '',
|
||||
discipline: '',
|
||||
distanceMetres: 0,
|
||||
categorie: '',
|
||||
nombrePartants: 0,
|
||||
statut: '',
|
||||
annulee: false,
|
||||
reporteeMemeJour: false,
|
||||
reporteeAutreJour: false,
|
||||
incidentTechnique: false,
|
||||
nonPartants: [],
|
||||
typesParisOuverts: [],
|
||||
};
|
||||
|
||||
const payload: ResultatCourse = {
|
||||
id: Number(row.id as any),
|
||||
course,
|
||||
statut: (row.statut as any) ?? (0 as any),
|
||||
ordreArrivee: String(row.ordreArrivee ?? ''),
|
||||
datePublication: row.datePublication ?? row.createdAt,
|
||||
dateValidation: row.dateValidation,
|
||||
dateAnnulation: row.dateAnnulation,
|
||||
notes: '',
|
||||
createdAt: row.createdAt,
|
||||
updatedAt: row.updatedAt,
|
||||
};
|
||||
|
||||
this.depouillement.sendResultat(payload).subscribe({
|
||||
next: (res) => {
|
||||
console.debug('Depouillement sent:', res);
|
||||
// After successful depouillement, update the resultat statut to PROVISOIRE
|
||||
const updateId = String((res && (res as any).id) ?? row.id);
|
||||
this.api.update(updateId, { statut: ResultatStatut.PROVISOIRE }).subscribe({
|
||||
next: (updated) => {
|
||||
// Update the local rows to reflect the new statut
|
||||
this.rows.set(
|
||||
this.rows().map((r) => (String(r.id) === String(updateId) ? { ...r, statut: ResultatStatut.PROVISOIRE } : r))
|
||||
);
|
||||
toast.success('Résultat envoyé au dépouillement et statut mis à jour.');
|
||||
this.setSending(id, false);
|
||||
},
|
||||
error: (err) => {
|
||||
console.error('Error updating resultat statut after depouillement:', err);
|
||||
toast.error('Échec de la mise à jour du statut du résultat.');
|
||||
this.setSending(id, false);
|
||||
},
|
||||
});
|
||||
},
|
||||
error: (err) => {
|
||||
console.error('Error sending to depouillement:', err);
|
||||
this.setSending(id, false);
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user