feat: exel export register data
All checks were successful
Deploy Production Server / if_merged (pull_request) Successful in 10m16s

This commit is contained in:
Thibaut Valentin 2025-08-21 11:37:03 +02:00
parent 0fc871bd46
commit 587173c79f
3 changed files with 42 additions and 4 deletions

View File

@ -2,8 +2,8 @@ package fr.titionfire.ffsaf.rest.data;
import fr.titionfire.ffsaf.data.model.LicenceModel;
import fr.titionfire.ffsaf.data.model.MembreModel;
import fr.titionfire.ffsaf.net2.data.SimpleClubModel;
import fr.titionfire.ffsaf.data.model.RegisterModel;
import fr.titionfire.ffsaf.net2.data.SimpleClubModel;
import fr.titionfire.ffsaf.utils.Utils;
import io.quarkus.runtime.annotations.RegisterForReflection;
import lombok.AllArgsConstructor;
@ -18,6 +18,7 @@ public class SimpleRegisterComb {
private long id;
private String fname;
private String lname;
private String genre;
private String categorie;
private SimpleClubModel club;
private Integer licence;
@ -29,6 +30,7 @@ public class SimpleRegisterComb {
public static SimpleRegisterComb fromModel(RegisterModel register, List<LicenceModel> licences) {
MembreModel membreModel = register.getMembre();
return new SimpleRegisterComb(membreModel.getId(), membreModel.getFname(), membreModel.getLname(),
membreModel.getGenre().name(),
(register.getCategorie() == null) ? "Catégorie inconnue" : register.getCategorie().getName(),
SimpleClubModel.fromModel(register.getClub()), membreModel.getLicence(), register.getWeight(),
register.getOverCategory(),

View File

@ -200,7 +200,6 @@ function FileOutput() {
<small>À utiliser comme template pour mettre à jour les informations</small>
</div>
);
}

View File

@ -4,12 +4,14 @@ import {useFetch} from "../../hooks/useFetch.js";
import {AxiosError} from "../../components/AxiosError.jsx";
import {ThreeDots} from "react-loader-spinner";
import {useEffect, useReducer, useRef, useState} from "react";
import {apiAxios} from "../../utils/Tools.js";
import {apiAxios, errFormater} from "../../utils/Tools.js";
import {toast} from "react-toastify";
import {SimpleReducer} from "../../utils/SimpleReducer.jsx";
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
import {faAdd, faGavel, faTrashCan} from "@fortawesome/free-solid-svg-icons";
import "./CompetitionRegisterAdmin.css"
import * as XLSX from "xlsx-js-style";
import * as Tools from "../../utils/Tools.js";
export function CompetitionRegisterAdmin({source}) {
const {id} = useParams()
@ -81,6 +83,7 @@ export function CompetitionRegisterAdmin({source}) {
setCatFilter={setCatFilter} source={source}/>
</div>
</div>
{source === "admin" && <FileOutput data={data}/>}
</div>
</div>
@ -427,7 +430,7 @@ function MakeCentralPanel({data, dispatch, id, setModalState, source}) {
<div className="row">
<span className="col-auto">{req.data.licence ? String(req.data.licence).padStart(5, '0') : "-------"}</span>
<div className="ms-2 col-auto">
<div className="fw-bold">{req.data.fname} {req.data.lname}</div>
<div><strong>{req.data.fname} {req.data.lname}</strong> <small>{req.data.genre}</small></div>
<small>{req.data.club?.name || "Sans club"}</small>
</div>
</div>
@ -495,6 +498,40 @@ function MakeCentralPanel({data, dispatch, id, setModalState, source}) {
</>
}
function FileOutput({data}) {
const handleFileDownload = () => {
const dataOut = []
for (const e of data) {
const tmp = {
licence: e.licence,
nom: e.lname,
prenom: e.fname,
genre: e.genre,
weight: e.weight,
categorie: e.categorie,
overCategory: e.overCategory,
club: e.club ? e.club.name : '',
}
dataOut.push(tmp)
}
const wb = XLSX.utils.book_new();
const ws = XLSX.utils.json_to_sheet(dataOut);
XLSX.utils.sheet_add_aoa(ws, [["Licence", "Nom", "Prénom", "Genre", "Poids", "Catégorie normalizer", "Surclassement", "Club"]], {origin: 'A1'});
ws["!cols"] = [{wch: 7}, {wch: 16}, {wch: 16}, {wch: 6}, {wch: 6}, {wch: 10}, {wch: 10}, {wch: 60}]
XLSX.utils.book_append_sheet(wb, ws, "Feuille 1");
XLSX.writeFile(wb, "output.xlsx");
};
return (
<div>
<button className="btn btn-primary" onClick={handleFileDownload}>Exporter les inscription</button>
</div>
);
}
function Def() {
return <div className="list-group">
<li className="list-group-item"><ThreeDots/></li>