Merge pull request 'dev' (#34) from dev into master

Reviewed-on: #34
This commit is contained in:
Thibaut Valentin 2025-02-14 16:07:14 +01:00
commit df58e93886
27 changed files with 683 additions and 68 deletions

View File

@ -24,6 +24,7 @@ public class AffiliationRequestModel {
long siret;
String RNA;
String address;
String contact;
String m1_lname;
String m1_fname;

View File

@ -1,6 +1,7 @@
package fr.titionfire.ffsaf.data.model;
import fr.titionfire.ffsaf.utils.CompetitionSystem;
import fr.titionfire.ffsaf.utils.RegisterEmbeddable;
import io.quarkus.runtime.annotations.RegisterForReflection;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
@ -37,12 +38,9 @@ public class CompetitionModel {
Date date;
@ManyToMany
@JoinTable(name = "register",
uniqueConstraints = @UniqueConstraint(columnNames = {"id_competition", "id_membre"}),
joinColumns = @JoinColumn(name = "id_competition"),
inverseJoinColumns = @JoinColumn(name = "id_membre"))
List<MembreModel> insc;
@ElementCollection(fetch = FetchType.LAZY)
@CollectionTable(name = "register", joinColumns = @JoinColumn(name = "id_competition"))
List<RegisterEmbeddable> insc;
String owner;
}

View File

@ -25,6 +25,7 @@ public class MembreModel {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Access(AccessType.PROPERTY)
@Schema(description = "L'identifiant du membre.", example = "1")
Long id;

View File

@ -118,6 +118,7 @@ public class AffiliationService {
origine.setName(model.getName());
origine.setRNA(model.getRNA());
origine.setAddress(model.getAddress());
origine.setContact(model.getContact());
origine.setM1_lname(model.getM1_lname());
origine.setM1_fname(model.getM1_fname());
origine.setM1_lincence(model.getM1_lincence());
@ -159,6 +160,7 @@ public class AffiliationService {
model.setSiret(form.getSiret());
model.setRNA(form.getRna());
model.setAddress(form.getAddress());
model.setContact(form.getContact());
if (form.getM1_mode() == 2) {
model.setM1_lname(form.getM1_lname());
@ -285,6 +287,7 @@ public class AffiliationService {
club.setSIRET(form.getSiret());
club.setRNA(form.getRna());
club.setAddress(form.getAddress());
club.setContact_intern(form.getContact());
club.setAffiliations(new ArrayList<>());
return Panache.withTransaction(() -> clubRepository.persist(club)
.chain(c -> sequenceRepository.getNextValueInTransaction(SequenceType.Affiliation)
@ -321,6 +324,7 @@ public class AffiliationService {
club.setSIRET(form.getSiret());
club.setRNA(form.getRna());
club.setAddress(form.getAddress());
club.setContact_intern(form.getContact());
return Panache.withTransaction(() -> clubRepository.persist(club)
.chain(() -> repository.persist(new AffiliationModel(null, club, model.getSaison())))
.chain(() -> repositoryRequest.delete(model)));

View File

@ -1,26 +1,32 @@
package fr.titionfire.ffsaf.domain.service;
import fr.titionfire.ffsaf.data.model.CompetitionModel;
import fr.titionfire.ffsaf.data.repository.ClubRepository;
import fr.titionfire.ffsaf.data.repository.CompetitionRepository;
import fr.titionfire.ffsaf.data.repository.MatchRepository;
import fr.titionfire.ffsaf.data.repository.PouleRepository;
import fr.titionfire.ffsaf.data.model.MembreModel;
import fr.titionfire.ffsaf.data.repository.*;
import fr.titionfire.ffsaf.net2.ServerCustom;
import fr.titionfire.ffsaf.net2.data.SimpleCompet;
import fr.titionfire.ffsaf.net2.request.SReqCompet;
import fr.titionfire.ffsaf.net2.request.SReqRegister;
import fr.titionfire.ffsaf.rest.data.CompetitionData;
import fr.titionfire.ffsaf.rest.data.RegisterRequestData;
import fr.titionfire.ffsaf.rest.data.SimpleCompetData;
import fr.titionfire.ffsaf.rest.data.SimpleRegisterComb;
import fr.titionfire.ffsaf.rest.exception.DBadRequestException;
import fr.titionfire.ffsaf.rest.exception.DForbiddenException;
import fr.titionfire.ffsaf.utils.CompetitionSystem;
import fr.titionfire.ffsaf.utils.RegisterEmbeddable;
import fr.titionfire.ffsaf.utils.SecurityCtx;
import io.quarkus.cache.Cache;
import io.quarkus.cache.CacheName;
import io.quarkus.hibernate.reactive.panache.Panache;
import io.quarkus.hibernate.reactive.panache.common.WithSession;
import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.Uni;
import io.smallrye.mutiny.unchecked.Unchecked;
import io.vertx.mutiny.core.Vertx;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import org.hibernate.reactive.mutiny.Mutiny;
import org.keycloak.representations.idm.UserRepresentation;
import java.util.*;
@ -42,6 +48,9 @@ public class CompetitionService {
@Inject
KeycloakService keycloakService;
@Inject
CombRepository combRepository;
@Inject
ServerCustom serverCustom;
@ -51,14 +60,23 @@ public class CompetitionService {
@Inject
Vertx vertx;
@Inject
@CacheName("safca-config")
Cache cache;
@Inject
@CacheName("safca-have-access")
Cache cacheAccess;
public Uni<CompetitionData> getById(SecurityCtx securityCtx, Long id) {
if (id == 0) {
return Uni.createFrom()
.item(new CompetitionData(null, "", "", new Date(), CompetitionSystem.SAFCA,
null, "", ""));
null, "", "", null));
}
return permService.hasViewPerm(securityCtx, id)
.map(CompetitionData::fromModel)
.chain(competitionModel -> Mutiny.fetch(competitionModel.getInsc())
.map(insc -> CompetitionData.fromModel(competitionModel).addInsc(insc)))
.chain(data ->
vertx.getOrCreateContext().executeBlocking(() -> {
keycloakService.getUser(UUID.fromString(data.getOwner()))
@ -138,7 +156,7 @@ public class CompetitionService {
return Panache.withTransaction(() -> repository.persist(model));
}).map(CompetitionData::fromModel)
.call(__ -> permService.cacheAccess.invalidate(securityCtx.getSubject()));
.call(__ -> cacheAccess.invalidate(securityCtx.getSubject()));
} else {
return permService.hasEditPerm(securityCtx, data.getId())
.chain(model -> {
@ -160,10 +178,82 @@ public class CompetitionService {
}))
.chain(__ -> Panache.withTransaction(() -> repository.persist(model)));
}).map(CompetitionData::fromModel)
.call(__ -> permService.cacheAccess.invalidate(securityCtx.getSubject()));
.call(__ -> cacheAccess.invalidate(securityCtx.getSubject()));
}
}
public Uni<List<SimpleRegisterComb>> getRegister(SecurityCtx securityCtx, Long id) {
return permService.hasEditPerm(securityCtx, id)
.chain(c -> Mutiny.fetch(c.getInsc()))
.onItem().transformToMulti(Multi.createFrom()::iterable)
.onItem().call(combModel -> Mutiny.fetch(combModel.getMembre().getLicences()))
.map(combModel -> SimpleRegisterComb.fromModel(combModel, combModel.getMembre().getLicences()))
.collect().asList();
}
public Uni<SimpleRegisterComb> addRegisterComb(SecurityCtx securityCtx, Long id, RegisterRequestData data) {
return permService.hasEditPerm(securityCtx, id)
.chain(c -> findComb(data.getLicence(), data.getFname(), data.getLname())
.chain(combModel -> Mutiny.fetch(c.getInsc())
.chain(Unchecked.function(insc -> {
Optional<RegisterEmbeddable> opt = insc.stream()
.filter(m -> m.getMembre().equals(combModel)).findAny();
RegisterEmbeddable r;
if (opt.isPresent()) {
r = opt.get();
r.setWeight(data.getWeight());
r.setOverCategory(data.getOverCategory());
} else {
r = new RegisterEmbeddable(combModel, data.getWeight(), data.getOverCategory());
insc.add(r);
}
if (c.getSystem() == CompetitionSystem.SAFCA) {
SReqRegister.sendIfNeed(serverCustom.clients,
new CompetitionData.SimpleRegister(r.getMembre().getId(),
r.getOverCategory(), r.getWeight()), c.getId());
}
return Panache.withTransaction(() -> repository.persist(c)).map(__ -> r);
}))))
.chain(r -> Mutiny.fetch(r.getMembre().getLicences())
.map(licences -> SimpleRegisterComb.fromModel(r, licences)));
}
private Uni<MembreModel> findComb(Long licence, String fname, String lname) {
if (licence != null && licence != 0) {
return combRepository.find("licence = ?1", licence).firstResult()
.invoke(Unchecked.consumer(combModel -> {
if (combModel == null)
throw new DForbiddenException("Licence " + licence + " non trouvé");
}));
} else {
if (fname == null || lname == null)
return Uni.createFrom().failure(new DBadRequestException("Nom et prénom requis"));
return combRepository.find("LOWER(lname) LIKE LOWER(?1) OR LOWER(fname) LIKE LOWER(?2)", lname,
fname).firstResult()
.invoke(Unchecked.consumer(combModel -> {
if (combModel == null)
throw new DForbiddenException("Combattant " + fname + " " + lname + " non trouvé");
}));
}
}
public Uni<Void> removeRegisterComb(SecurityCtx securityCtx, Long id, Long combId) {
return permService.hasEditPerm(securityCtx, id)
.chain(c -> Mutiny.fetch(c.getInsc())
.chain(Unchecked.function(insc -> {
if (insc.removeIf(m -> m.getMembre().getId().equals(combId))) {
if (c.getSystem() == CompetitionSystem.SAFCA) {
SReqRegister.sendRmIfNeed(serverCustom.clients, combId, id);
}
return Panache.withTransaction(() -> repository.persist(c)).map(__ -> null);
}
throw new DBadRequestException("Combattant non inscrit");
})));
}
public Uni<?> delete(SecurityCtx securityCtx, Long id) {
return repository.findById(id).invoke(Unchecked.consumer(c -> {
if (!securityCtx.getSubject().equals(c.getOwner()) || securityCtx.roleHas("federation_admin"))
@ -180,7 +270,7 @@ public class CompetitionService {
() -> pouleRepository.delete("compet = ?1", competitionModel)))
.chain(model -> Panache.withTransaction(() -> repository.delete("id", model.getId())))
.invoke(o -> SReqCompet.rmCompet(serverCustom.clients, id))
.call(__ -> permService.cache.invalidate(id));
.call(__ -> cache.invalidate(id));
}
public Uni<SimpleCompetData> getSafcaData(SecurityCtx securityCtx, Long id) {
@ -234,15 +324,20 @@ public class CompetitionService {
}))
.invoke(simpleCompet -> SReqCompet.sendUpdate(serverCustom.clients, simpleCompet))
.call(simpleCompet -> permService.getSafcaConfig(data.getId())
.call(c -> Uni.join().all(Stream.concat(
Stream.concat(
c.admin().stream().filter(uuid -> !simpleCompet.admin().contains(uuid)),
simpleCompet.admin().stream().filter(uuid -> !c.admin().contains(uuid))),
Stream.concat(
c.table().stream().filter(uuid -> !simpleCompet.table().contains(uuid)),
simpleCompet.table().stream().filter(uuid -> !c.table().contains(uuid))))
.map(uuid -> permService.cacheAccess.invalidate(uuid.toString())).toList())
.andCollectFailures()))
.call(__ -> permService.cache.invalidate(data.getId()));
.call(c -> {
List<Uni<Void>> list = Stream.concat(
Stream.concat(
c.admin().stream().filter(uuid -> !simpleCompet.admin().contains(uuid)),
simpleCompet.admin().stream().filter(uuid -> !c.admin().contains(uuid))),
Stream.concat(
c.table().stream().filter(uuid -> !simpleCompet.table().contains(uuid)),
simpleCompet.table().stream().filter(uuid -> !c.table().contains(uuid)))
).map(uuid -> cacheAccess.invalidate(uuid.toString())).toList();
if (list.isEmpty())
return Uni.createFrom().nullItem();
return Uni.join().all(list).andCollectFailures();
}))
.call(__ -> cache.invalidate(data.getId()));
}
}

View File

@ -11,16 +11,6 @@ import java.util.HashMap;
public class RComb {
private static final Logger LOGGER = Logger.getLogger(RComb.class);
final IAction findComb = (client_Thread, message) -> {
try {
SimpleCombModel combModel = ServerCustom.getInstance().membreService.find(message.data().get("licence").asInt(), message.data().get("np").asText());
client_Thread.sendRepTo(combModel, message);
} catch (Throwable e) {
LOGGER.error(e.getMessage(), e);
client_Thread.sendErrTo(e.getMessage(), message);
}
};
final CIA<Long> findByIdOptionalComb = new CIA<>(Long.class, (client_Thread, message) -> {
try {
SimpleCombModel combModel = ServerCustom.getInstance().membreService.findByIdOptionalComb(message.data());
@ -34,7 +24,6 @@ public class RComb {
public static void register(HashMap<String, IAction> iMap) {
RComb rComb = new RComb();
iMap.put("findComb", rComb.findComb);
iMap.put("findByIdOptionalComb", rComb.findByIdOptionalComb);
}
}

View File

@ -0,0 +1,29 @@
package fr.titionfire.ffsaf.net2.request;
import fr.titionfire.ffsaf.net2.Client_Thread;
import fr.titionfire.ffsaf.rest.data.CompetitionData;
import java.util.ArrayList;
import java.util.HashMap;
public class SReqRegister {
public static void sendIfNeed(ArrayList<Client_Thread> client_Thread, CompetitionData.SimpleRegister simpleRegister, Long competitionId) {
HashMap<String, Object> map = new HashMap<>();
map.put("simpleRegister", simpleRegister);
map.put("competitionId", competitionId);
for (Client_Thread client : client_Thread) {
client.sendNotify(map, "sendRegister");
}
}
public static void sendRmIfNeed(ArrayList<Client_Thread> clients, Long combId, Long id) {
HashMap<String, Object> map = new HashMap<>();
map.put("combId", combId);
map.put("competitionId", id);
for (Client_Thread client : clients) {
client.sendNotify(map, "sendRmRegister");
}
}
}

View File

@ -2,7 +2,9 @@ package fr.titionfire.ffsaf.rest;
import fr.titionfire.ffsaf.domain.service.CompetitionService;
import fr.titionfire.ffsaf.rest.data.CompetitionData;
import fr.titionfire.ffsaf.rest.data.RegisterRequestData;
import fr.titionfire.ffsaf.rest.data.SimpleCompetData;
import fr.titionfire.ffsaf.rest.data.SimpleRegisterComb;
import fr.titionfire.ffsaf.utils.CompetitionSystem;
import fr.titionfire.ffsaf.utils.SecurityCtx;
import io.quarkus.security.Authenticated;
@ -10,6 +12,7 @@ import io.smallrye.mutiny.Uni;
import jakarta.inject.Inject;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.MediaType;
import org.eclipse.microprofile.openapi.annotations.Operation;
import java.util.List;
@ -30,6 +33,32 @@ public class CompetitionEndpoints {
return service.getById(securityCtx, id);
}
@GET
@Path("{id}/register")
@Authenticated
@Produces(MediaType.APPLICATION_JSON)
public Uni<List<SimpleRegisterComb>> getRegister(@PathParam("id") Long id) {
return service.getRegister(securityCtx, id);
}
@POST
@Path("{id}/register")
@Authenticated
@Produces(MediaType.APPLICATION_JSON)
@Operation(hidden = true)
public Uni<SimpleRegisterComb> addRegisterComb(@PathParam("id") Long id, RegisterRequestData data) {
return service.addRegisterComb(securityCtx, id, data);
}
@DELETE
@Path("{id}/register/{comb_id}")
@Authenticated
@Produces(MediaType.APPLICATION_JSON)
@Operation(hidden = true)
public Uni<Void> removeRegisterComb(@PathParam("id") Long id, @PathParam("comb_id") Long combId) {
return service.removeRegisterComb(securityCtx, id, combId);
}
@GET
@Path("{id}/safcaData")
@Authenticated

View File

@ -2,11 +2,13 @@ package fr.titionfire.ffsaf.rest.data;
import fr.titionfire.ffsaf.data.model.CompetitionModel;
import fr.titionfire.ffsaf.utils.CompetitionSystem;
import fr.titionfire.ffsaf.utils.RegisterEmbeddable;
import io.quarkus.runtime.annotations.RegisterForReflection;
import lombok.AllArgsConstructor;
import lombok.Data;
import java.util.Date;
import java.util.List;
@Data
@AllArgsConstructor
@ -20,12 +22,28 @@ public class CompetitionData {
private Long club;
private String clubName;
private String owner;
private List<SimpleRegister> registers;
public static CompetitionData fromModel(CompetitionModel model) {
if (model == null)
return null;
return new CompetitionData(model.getId(), model.getName(), model.getUuid(), model.getDate(), model.getSystem(),
model.getClub().getId(), model.getClub().getName(), model.getOwner());
model.getClub().getId(), model.getClub().getName(), model.getOwner(), null);
}
public CompetitionData addInsc(List<RegisterEmbeddable> insc) {
this.registers = insc.stream()
.map(i -> new SimpleRegister(i.getMembre().getId(), i.getOverCategory(), i.getWeight())).toList();
return this;
}
@Data
@AllArgsConstructor
@RegisterForReflection
public static class SimpleRegister {
long id;
int overCategory;
Integer weight;
}
}

View File

@ -0,0 +1,15 @@
package fr.titionfire.ffsaf.rest.data;
import io.quarkus.runtime.annotations.RegisterForReflection;
import lombok.Data;
@Data
@RegisterForReflection
public class RegisterRequestData {
private Long licence;
private String fname;
private String lname;
private Integer weight;
private int overCategory;
}

View File

@ -0,0 +1,36 @@
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.utils.RegisterEmbeddable;
import fr.titionfire.ffsaf.utils.Utils;
import io.quarkus.runtime.annotations.RegisterForReflection;
import lombok.AllArgsConstructor;
import lombok.Data;
import java.util.List;
@Data
@AllArgsConstructor
@RegisterForReflection
public class SimpleRegisterComb {
private long id;
private String fname;
private String lname;
private String categorie;
private SimpleClubModel club;
private Integer licence;
private Integer weight;
private int overCategory;
private boolean hasLicenceActive;
public static SimpleRegisterComb fromModel(RegisterEmbeddable register, List<LicenceModel> licences) {
MembreModel membreModel = register.getMembre();
return new SimpleRegisterComb(membreModel.getId(), membreModel.getFname(), membreModel.getLname(),
(membreModel.getCategorie() == null) ? "Catégorie inconnue" : membreModel.getCategorie().getName(),
SimpleClubModel.fromModel(membreModel.getClub()), membreModel.getLicence(), register.getWeight(),
register.getOverCategory(),
licences.stream().anyMatch(l -> l.isValidate() && l.getSaison() == Utils.getSaison()));
}
}

View File

@ -31,6 +31,8 @@ public class SimpleReqAffiliation {
String RNA;
@Schema(description = "Adresse de l'association", example = "1 rue de l'exemple, 75000 Paris")
String address;
@Schema(description = "Email de contact de l'association", example = "test@test.fr")
String contact;
@Schema(description = "Liste des membres pour la demande d'affiliation")
List<AffiliationMember> members;
@Schema(description = "Saison de l'affiliation", example = "2025")
@ -47,6 +49,7 @@ public class SimpleReqAffiliation {
.RNA(model.getRNA())
.address(model.getAddress())
.saison(model.getSaison())
.contact(model.getContact())
.members(List.of(
new AffiliationMember(model.getM1_lname(), model.getM1_fname(), model.getM1_email(),
model.getM1_lincence(), model.getM1_role()),

View File

@ -33,6 +33,10 @@ public class AffiliationRequestForm {
@FormParam("adresse")
private String adresse = null;
@Schema(description = "Email de contact de l'association", example = "test@test.fr")
@FormParam("contact")
private String contact = null;
@Schema(description = "La saison de l'affiliation.", example = "2025", required = true)
@FormParam("saison")
private int saison = -1;
@ -114,6 +118,7 @@ public class AffiliationRequestForm {
model.setRNA(this.getRna());
model.setAddress(this.getAdresse());
model.setSaison(this.getSaison());
model.setContact(this.getContact());
model.setM1_lname(this.getM1_lname());
model.setM1_fname(this.getM1_fname());

View File

@ -31,6 +31,10 @@ public class AffiliationRequestSaveForm {
@FormParam("address")
private String address = null;
@Schema(description = "Email de contact de l'association", example = "test@test.fr")
@FormParam("contact")
private String contact = null;
@Schema(description = "Le statut de l'association.")
@FormParam("status")
@PartType(MediaType.APPLICATION_OCTET_STREAM)

View File

@ -2,7 +2,6 @@ package fr.titionfire.ffsaf.utils;
import io.quarkus.runtime.annotations.RegisterForReflection;
import javax.naming.ldap.HasControls;
import java.util.HashMap;
@RegisterForReflection
@ -11,7 +10,8 @@ public enum Contact {
TELEPHONE("Téléphone"),
SITE("Site web"),
FACEBOOK("Facebook"),
INSTAGRAM("Instagram");
INSTAGRAM("Instagram"),
AUTRE("Autre");
public String name;

View File

@ -0,0 +1,28 @@
package fr.titionfire.ffsaf.utils;
import fr.titionfire.ffsaf.data.model.MembreModel;
import io.quarkus.runtime.annotations.RegisterForReflection;
import jakarta.persistence.Embeddable;
import jakarta.persistence.FetchType;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@RegisterForReflection
@Embeddable
public class RegisterEmbeddable {
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "id_membre")
MembreModel membre;
Integer weight;
int overCategory = 0;
}

View File

@ -1,4 +1,5 @@
const api_url = "https://intra.ffsaf.fr";
//const api_url = "https://intra.ffsaf.fr";
const api_url = "http://localhost:8080";
let map = L.map('map').setView([46.631196, 2.456000], 6);
@ -94,13 +95,45 @@ async function getData() {
div_info.appendChild(document.createElement("br"));
} else {
for (const [key, value] of Object.entries(d.contact)) {
div_info.appendChild(document.createTextNode(`${key.charAt(0).toUpperCase() + key.slice(1).toLowerCase()}: ${value}`));
let str
if (key === "SITE") {
str = document.createElement('a');
str.appendChild(document.createTextNode(value))
str.title = value
str.href = (value.startsWith("http") ? "" : "https://") + value
str.target = '_blank'
} else if (key === "COURRIEL") {
str = document.createElement('a');
str.appendChild(document.createTextNode(value))
str.title = value
str.href = `mailto:${value}`
str.target = '_blank'
} else if (key === "INSTAGRAM") {
let r = value.match(/^https?:\/\/www\.instagram\.com\/([a-zA-Z0-9_.\-]+)\/?$/)
str = document.createElement('a');
str.appendChild(document.createTextNode(r == null ? value : r[1]))
str.title = value
str.href = (value.startsWith("http") ? "" : "https://www.instagram.com/") + value
str.target = '_blank'
} else if (key === "FACEBOOK") {
let r = value.match(/^https?:\/\/www\.facebook\.com\/([a-zA-Z0-9_.\-]+)\/?$/)
str = document.createElement('a');
str.appendChild(document.createTextNode(r == null ? value : r[1]))
str.title = value
str.href = (value.startsWith("http") ? "" : "https://www.facebook.com/") + value
str.target = '_blank'
} else {
str = document.createTextNode(value)
}
div_info.appendChild(document.createTextNode(`${key.charAt(0).toUpperCase() + key.slice(1).toLowerCase()}: `));
div_info.appendChild(str);
div_info.appendChild(document.createElement("br"));
}
}
marker.bindPopup(div_info.innerHTML);
if (icon !== null){
if (icon !== null) {
marker.valueOf()._icon.style.backgroundColor = '#FFFFFF';
marker.valueOf()._icon.style.borderRadius = '10px';
}

View File

@ -8,16 +8,18 @@ export function ContactEditor({data}) {
const [out_data, setOutData] = useState({})
useEffect(() => {
let i = 0;
for (const key in data.contact) {
dispatch({type: 'UPDATE_OR_ADD', payload: {id: key, data: data.contact[key]}})
dispatch({type: 'UPDATE_OR_ADD', payload: {id: i, data: {type: key, value: data.contact[key]}}})
i = i + 1
}
}, [data.contact]);
useEffect(() => {
let out_data2 = {}
state.forEach(d => {
if (d.data !== undefined)
out_data2[d.id] = d.data
if (d.data !== undefined && d.data.value !== undefined)
out_data2[d.data.type] = d.data.value
})
setOutData(out_data2)
}, [state]);
@ -27,26 +29,25 @@ export function ContactEditor({data}) {
<span className="input-group-text">Contacts</span>
<ul className="list-group form-control">
{state.map((d, index) => {
if (d.data === undefined)
if (d.data === undefined || d.data.value === undefined)
return;
return <div key={index} className="input-group">
<select className="form-select" aria-label="type" defaultValue={d.id}
<select className="form-select" aria-label="type" value={d.data.type}
onChange={(e) => {
dispatch({type: 'UPDATE_OR_ADD', payload: {id: d.id, data: undefined}})
dispatch({type: 'UPDATE_OR_ADD', payload: {id: e.target.value, data: d.data}})
dispatch({type: 'UPDATE_OR_ADD', payload: {id: d.id, data: {type: e.target.value, value: d.data.value}}})
}}>
{Object.keys(data.contactMap).map((key, _) => {
let b = false;
for (let s of state) {
if (s.id === key && s.data !== undefined) b = true;
if (s.data.type === key && s.data.value !== undefined) b = true;
}
return (<option key={key} value={key} disabled={b}>{data.contactMap[key]}</option>)
})}
</select>
<input type="text" className="form-control" defaultValue={d.data} required
<input type="text" className="form-control" value={d.data.value} required
onChange={(e) => {
dispatch({type: 'UPDATE_OR_ADD', payload: {id: d.id, data: e.target.value}})
dispatch({type: 'UPDATE_OR_ADD', payload: {id: d.id, data: {type: d.data.type, value: e.target.value}}})
}}/>
<button className="btn btn-danger" type="button"
onClick={() => dispatch({type: 'REMOVE', payload: d.id})}><FontAwesomeIcon
@ -61,15 +62,21 @@ export function ContactEditor({data}) {
for (let key in data.contactMap) {
let b = false;
for (let s of state) {
if (s.id === key && s.data !== undefined) b = true;
if (s.data.type === key && s.data.value !== undefined) b = true;
}
if (!b) {
id = key
break
}
}
if (id !== null)
dispatch({type: 'UPDATE_OR_ADD', payload: {id: id, data: ''}})
if (id !== null) {
let maxId = 0;
state.forEach((d) => {
if (d.id > maxId)
maxId = d.id;
})
dispatch({type: 'UPDATE_OR_ADD', payload: {id: maxId + 1, data: {type: id, value: ''}}})
}
}}>
<FontAwesomeIcon icon={faAdd}/>
</button>

View File

@ -208,6 +208,7 @@ function AssoInfo({initData, needFile}) {
const [rnaEnable, setRnaEnable] = useState(false)
const [adresse, setAdresse] = useState(initData.address ? initData.address : "")
const [saison, setSaison] = useState(initData.saison ? initData.saison : getSaison())
const [contact, setContact] = useState(initData.contact ? initData.contact : "")
const fetchSiret = () => {
if (siret.length < 14) {
@ -298,6 +299,15 @@ function AssoInfo({initData, needFile}) {
</div>
</div>
<div className="mb-3">
<div className="input-group">
<span className="input-group-text" id="basic-addon1">Contact administratif*</span>
<input type="email" className="form-control" placeholder="Contact administratif" aria-label="Contact administratif"
aria-describedby="basic-addon1"
required value={contact} name="contact" onChange={e => setContact(e.target.value)}/>
</div>
</div>
<div className="mb-3">
<div className="input-group">
<label className="input-group-text" htmlFor="logo">Blason{needFile && "*"}</label>

View File

@ -118,9 +118,6 @@ function CatGraph({raw_data}) {
const textAnchor = cos >= 0 ? 'start' : 'end';
return <g>
<text x={cx} y={cy} dy={8} textAnchor="middle" fill={fill}>
{payload.name}
</text>
<Sector
cx={cx}
cy={cy}

View File

@ -180,6 +180,7 @@ function Content({data, refresh}) {
<TextField type="number" name="siret" text="SIRET" value={data.siret} disabled={true}/>
<TextField name="rna" text="RNA" value={data.rna} required={false}/>
<TextField name="address" text="Adresse" value={data.address}/>
<TextField name="contact" text="Contact administratif" value={data.contact}/>
<img
src={`${vite_url}/api/affiliation/request/${data.id}/logo`}
@ -198,7 +199,7 @@ function Content({data, refresh}) {
<label className="input-group-text" htmlFor="status">Status</label>
<a href={`${vite_url}/api/affiliation/request/${data.id}/status`} target='_blank'>
<button className="btn btn-outline-secondary" type="button" id="button-addon1"
onClick={e => null}><FontAwesomeIcon icon={faFilePdf}></FontAwesomeIcon>
onClick={_ => null}><FontAwesomeIcon icon={faFilePdf}></FontAwesomeIcon>
</button>
</a>
<input type="file" className="form-control" id="status" name="status" accept=".pdf,.txt"/>

View File

@ -102,10 +102,10 @@ function InformationForm({data}) {
<form onSubmit={handleSubmit}>
<div className="card mb-4">
<input name="id" value={data.id} readOnly hidden/>
<input name="clubId" value={data.clubId} readOnly hidden/>
<div className="card-header">Affiliation n°{data.no_affiliation}</div>
<div className="card-body text-center">
<TextField name="clubId" text="ClubID" value={data.clubId} disabled={true}/>
<TextField name="name" text="Nom" value={data.name}/>
<CountryList name="country" text="Pays" value={data.country}/>

View File

@ -96,11 +96,12 @@ function PhotoCard({data}) {
}
function SelectCard() {
return <div className="card mb-4 mb-md-0">
return <></>
/*return <div className="card mb-4 mb-md-0">
<div className="card-header">Sélection en équipe de France</div>
<div className="card-body">
<p className="mb-1">Web Design</p>
</div>
</div>;
</div>;*/
}

View File

@ -75,7 +75,7 @@ export function MemberPage() {
function PhotoCard({data}) {
return <div className="card mb-4">
<div className="card-header">{data.licence ? "Licence n°"+data.licence : "Pas de licence"}</div>
<div className="card-header">{data.licence ? "Licence n°" + data.licence : "Pas de licence"}</div>
<div className="card-body text-center">
<div className="input-group mb-3">
<img
@ -94,11 +94,12 @@ function PhotoCard({data}) {
}
function SelectCard() {
return <div className="card mb-4 mb-md-0">
return <></>
/*return <div className="card mb-4 mb-md-0">
<div className="card-header">Sélection en équipe de France</div>
<div className="card-body">
<p className="mb-1">Soon</p>
</div>
</div>;
</div>;*/
}

View File

@ -43,8 +43,12 @@ export function CompetitionEdit() {
<div>
{data
? <div className="">
<Content data={data} refresh={refresh}/>
{data.id !== null && <button style={{marginBottom: "1.5em", width: "100%"}} className="btn btn-primary"
onClick={_ => navigate(`/competition/${data.id}/register`)}>Voir/Modifier les participants</button>}
{data.id !== null && <ContentSAFCA data2={data}/>}
{data.id !== null && <>
@ -74,14 +78,14 @@ function ContentSAFCA({data2}) {
useEffect(() => {
if (data === null)
return
if (data.admin !== null){
if (data.admin !== null) {
let index = 0
for (const d of data.admin) {
dispatch({type: 'UPDATE_OR_ADD', payload: {id: index, data: d}})
index++
}
}
if (data.table !== null){
if (data.table !== null) {
let index = 0
for (const d of data.table) {
dispatch2({type: 'UPDATE_OR_ADD', payload: {id: index, data: d}})
@ -232,7 +236,8 @@ function Content({data}) {
},
}
).then(data => {
navigate("/competition/" + data.id)
if (data.id !== undefined)
navigate("/competition/" + data.id)
})
}

View File

@ -0,0 +1,300 @@
import {useNavigate, useParams} from "react-router-dom";
import {useLoadingSwitcher} from "../../hooks/useLoading.jsx";
import {useFetch} from "../../hooks/useFetch.js";
import {AxiosError} from "../../components/AxiosError.jsx";
import {ThreeDots} from "react-loader-spinner";
import {useEffect, useReducer, useState} from "react";
import {apiAxios} from "../../utils/Tools.js";
import {toast} from "react-toastify";
import {SimpleReducer} from "../../utils/SimpleReducer.jsx";
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
import {faTrashCan} from "@fortawesome/free-solid-svg-icons";
export function CompetitionRegisterAdmin() {
const {id} = useParams()
const navigate = useNavigate()
const [state, dispatch] = useReducer(SimpleReducer, [])
const [clubFilter, setClubFilter] = useState("")
const [catFilter, setCatFilter] = useState("")
const [modalState, setModalState] = useState({})
const setLoading = useLoadingSwitcher()
const {data, error} = useFetch(`/competition/${id}/register`, setLoading, 1)
const sortName = (a, b) => {
if (a.data.fname === b.data.fname)
return a.data.lname.localeCompare(b.data.lname);
return a.data.fname.localeCompare(b.data.fname);
}
useEffect(() => {
if (!data)
return;
data.forEach((d, index) => {
dispatch({type: 'UPDATE_OR_ADD', payload: {id: index, data: d}})
})
dispatch({type: 'SORT', payload: sortName})
}, [data, clubFilter, catFilter]);
const sendRegister = (event, new_state) => {
event.preventDefault();
console.log(new_state)
toast.promise(apiAxios.post(`/competition/${id}/register`, new_state), {
pending: "Recherche en cours",
success: "Combattant trouvé et ajouté/mis à jour",
error: {
render({data}) {
return data.response.data || "Combattant non trouvé"
}
}
}).then((response) => {
if (response.data.error) {
return
}
let maxId = 0;
if (new_state.id) {
maxId = new_state.id - 1
} else {
state.forEach((d) => {
if (d.id > maxId)
maxId = d.id;
})
}
dispatch({type: 'UPDATE_OR_ADD', payload: {id: maxId + 1, data: response.data}})
dispatch({type: 'SORT', payload: sortName})
document.getElementById("closeModal").click();
})
}
return <div>
<h2>Combattants inscrits</h2>
<button type="button" className="btn btn-link" onClick={() => navigate("/competition/" + id)}>
&laquo; retour
</button>
<div className="row">
<div className="col-lg-9">
{data
? <div className="">
<MakeCentralPanel
data={state.filter(s => (clubFilter.length === 0 || s.data.club.name === clubFilter) && (catFilter.length === 0 || s.data.categorie === catFilter))}
dispatch={dispatch} id={id} setModalState={setModalState}/>
</div>
: error
? <AxiosError error={error}/>
: <Def/>
}
</div>
<div className="col-lg-3">
<div className="mb-4">
<button type="button" className="btn btn-primary" data-bs-toggle="modal" data-bs-target="#registerModal"
onClick={() => setModalState({})}>Ajouter un combattant
</button>
</div>
<div className="card mb-4">
<div className="card-header">Filtre</div>
<div className="card-body">
<FiltreBar data={data} clubFilter={clubFilter} setClubFilter={setClubFilter} catFilter={catFilter}
setCatFilter={setCatFilter}/>
</div>
</div>
</div>
</div>
<Modal sendRegister={sendRegister} modalState={modalState} setModalState={setModalState}/>
</div>
}
function Modal({sendRegister, modalState, setModalState}) {
const [licence, setLicence] = useState("")
const [fname, setFname] = useState("")
const [lname, setLname] = useState("")
const [weight, setWeight] = useState("")
const [cat, setCat] = useState(0)
const [editMode, setEditMode] = useState(false)
useEffect(() => {
if (!modalState) {
setLicence("")
setFname("")
setLname("")
setWeight("")
setCat(0)
setEditMode(false)
} else {
setLicence(modalState.licence ? modalState.licence : "")
setFname(modalState.fname ? modalState.fname : "")
setLname(modalState.lname ? modalState.lname : "")
setWeight(modalState.weight ? modalState.weight : "")
setCat(modalState.overCategory ? modalState.overCategory : 0)
setEditMode(modalState.licence || (modalState.fname && modalState.lname))
}
}, [modalState]);
return <div className="modal fade" id="registerModal" tabIndex="-1" aria-labelledby="registerLabel"
aria-hidden="true">
<div className="modal-dialog">
<div className="modal-content">
<form onSubmit={e => {
const new_state = {
licence: licence,
fname: fname,
lname: lname,
weight: weight,
overCategory: cat,
id: modalState.id
}
setModalState(new_state)
sendRegister(e, new_state)
}}>
<div className="modal-header">
<h1 className="modal-title fs-5" id="registerLabel">Ajouter un combattant</h1>
<button type="button" className="btn-close" data-bs-dismiss="modal"
aria-label="Close"></button>
</div>
<div className="modal-body">
<div className="card" style={{marginBottom: "1em"}}>
<div className="card-header">Recherche*</div>
<div className="card-body">
<div className="row">
<div className="col">
<input type="number" min={0} step={1} className="form-control" placeholder="N° de licence" name="licence"
value={licence} onChange={e => setLicence(e.target.value)} disabled={editMode}/>
</div>
</div>
<h5 style={{textAlign: "center", marginTop: "0.25em"}}>Ou</h5>
<div className="row">
<div className="col">
<input type="text" className="form-control" placeholder="Prénom" name="fname" disabled={editMode}
value={fname} onChange={e => setFname(e.target.value)}/>
</div>
<div className="col">
<input type="text" className="form-control" placeholder="Nom" name="lname" disabled={editMode}
value={lname} onChange={e => setLname(e.target.value)}/>
</div>
</div>
</div>
</div>
<div className="input-group mb-3">
<span className="input-group-text" id="weight">Poids (en kg)</span>
<input type="number" min={1} step={1} className="form-control" placeholder="42" aria-label="weight"
name="weight" aria-describedby="weight" value={weight} onChange={e => setWeight(e.target.value)}/>
</div>
<div className="input-group mb-3">
<span className="input-group-text" id="categorie">Surclassement</span>
<select className="form-select" aria-label="categorie" name="categorie" value={cat}
onChange={e => setCat(Number(e.target.value))}>
<option value={0}>Aucun</option>
<option value={1}>+1 catégorie</option>
<option value={2}>+2 catégorie</option>
</select>
</div>
</div>
<div className="modal-footer">
<button type="submit" className="btn btn-primary">{editMode? "Modifier" : "Ajouter"}</button>
<button type="reset" className="btn btn-secondary" data-bs-dismiss="modal" id="closeModal">Annuler</button>
</div>
</form>
</div>
</div>
</div>
}
let allClub = []
let allCat = []
function FiltreBar({data, clubFilter, setClubFilter, catFilter, setCatFilter}) {
useEffect(() => {
if (!data)
return;
allClub.push(...data.map((e) => e.club?.name))
allClub = allClub.filter((value, index, self) => self.indexOf(value) === index).filter(value => value != null).sort()
allCat.push(...data.map((e) => e.categorie))
allCat = allCat.filter((value, index, self) => self.indexOf(value) === index).filter(value => value != null).sort()
}, [data]);
return <div>
<div className="mb-3">
<select className="form-select" value={clubFilter} onChange={event => setClubFilter(event.target.value)}>
<option value="">--- tout les clubs ---</option>
{allClub && allClub.map((value, index) => {
return <option key={index} value={value}>{value}</option>
})
}
</select>
</div>
<div className="mb-3">
<select className="form-select" value={catFilter} onChange={event => setCatFilter(event.target.value)}>
<option value="">--- toute les catégories ---</option>
{allCat && allCat.map((value, index) => {
return <option key={index} value={value}>{value}</option>
})
}
</select>
</div>
</div>
}
function MakeCentralPanel({data, dispatch, id, setModalState}) {
return <>
<div className="mb-4">
<div className="list-group">
{data.map((req, index) => (
<div key={index} className="list-group-item d-flex justify-content-between align-items-start list-group-item-action"
data-bs-toggle="modal" data-bs-target="#registerModal" onClick={() => setModalState({...req.data, id: req.id})}>
<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>
<small>{req.data.club?.name || "Sans club"}</small>
</div>
</div>
<div className="row">
<div className="col-auto" style={{textAlign: "right"}}>
<small>{req.data.categorie + (req.data.overCategory === 0 ? "" : (" avec " + req.data.overCategory + " de surclassement"))}<br/>
{req.data.weight ? req.data.weight : "---"} kg
</small>
</div>
<div className="col-auto">
<button className="btn btn-danger" type="button"
onClick={e => {
e.preventDefault()
toast.promise(apiAxios.delete(`/competition/${id}/register/${req.data.id}`), {
pending: "Désinscription en cours",
success: "Combattant désinscrit",
error: {
render({data}) {
return data.response.data || "Erreur"
}
}
}).finally(() => {
dispatch({type: 'REMOVE', payload: req.id})
setTimeout(() => document.getElementById("closeModal").click(), 500);
})
}
}>
<FontAwesomeIcon icon={faTrashCan}/>
</button>
</div>
</div>
</div>
))}
</div>
</div>
</>
}
function Def() {
return <div className="list-group">
<li className="list-group-item"><ThreeDots/></li>
<li className="list-group-item"><ThreeDots/></li>
<li className="list-group-item"><ThreeDots/></li>
<li className="list-group-item"><ThreeDots/></li>
<li className="list-group-item"><ThreeDots/></li>
</div>
}

View File

@ -2,6 +2,7 @@ import {LoadingProvider} from "../../hooks/useLoading.jsx";
import {Outlet} from "react-router-dom";
import {CompetitionList} from "./CompetitionList.jsx";
import {CompetitionEdit} from "./CompetitionEdit.jsx";
import {CompetitionRegisterAdmin} from "./CompetitionRegisterAdmin.jsx";
export function CompetitionRoot() {
return <>
@ -21,6 +22,10 @@ export function getCompetitionChildren() {
{
path: ':id',
element: <CompetitionEdit/>
},
{
path: ':id/register',
element: <CompetitionRegisterAdmin/>
}
]
}