dev #107
@ -1,5 +1,6 @@
|
||||
package fr.titionfire.ffsaf.domain.entity;
|
||||
|
||||
import fr.titionfire.ffsaf.data.model.CatPresetModel;
|
||||
import fr.titionfire.ffsaf.data.model.CompetitionGuestModel;
|
||||
import fr.titionfire.ffsaf.data.model.MembreModel;
|
||||
import fr.titionfire.ffsaf.data.model.RegisterModel;
|
||||
@ -28,6 +29,7 @@ public class CombEntity {
|
||||
int overCategory;
|
||||
Integer weight;
|
||||
List<CombEntity> teamMembers;
|
||||
List<Long> categoriesInscrites;
|
||||
|
||||
public static CombEntity fromModel(MembreModel model) {
|
||||
if (model == null)
|
||||
@ -36,7 +38,7 @@ public class CombEntity {
|
||||
return new CombEntity(model.getId(), model.getLname(), model.getFname(), model.getCategorie(),
|
||||
model.getClub() == null ? null : model.getClub().getClubId(),
|
||||
model.getClub() == null ? "Sans club" : model.getClub().getName(), model.getGenre(), model.getCountry(),
|
||||
0, null, new ArrayList<>());
|
||||
0, null, new ArrayList<>(), new ArrayList<>());
|
||||
}
|
||||
|
||||
|
||||
@ -47,7 +49,15 @@ public class CombEntity {
|
||||
return new CombEntity(model.getId() * -1, model.getLname(), model.getFname(), model.getCategorie(), null,
|
||||
model.getClub(), model.getGenre(), model.getCountry(), 0, model.getWeight(),
|
||||
Stream.concat(model.getComb().stream().map(CombEntity::fromModel),
|
||||
model.getGuest().stream().map(CombEntity::fromModel)).toList());
|
||||
model.getGuest().stream().map(CombEntity::fromModel)).toList(),
|
||||
new ArrayList<>());
|
||||
}
|
||||
|
||||
public CombEntity addCategoriesInscrites(List<CatPresetModel> categoriesInscrites) {
|
||||
if (categoriesInscrites == null)
|
||||
return this;
|
||||
this.categoriesInscrites = categoriesInscrites.stream().map(CatPresetModel::getId).toList();
|
||||
return this;
|
||||
}
|
||||
|
||||
public static CombEntity fromModel(RegisterModel registerModel) {
|
||||
@ -58,6 +68,7 @@ public class CombEntity {
|
||||
return new CombEntity(model.getId(), model.getLname(), model.getFname(), registerModel.getCategorie(),
|
||||
registerModel.getClub2() == null ? null : registerModel.getClub2().getClubId(),
|
||||
registerModel.getClub2() == null ? "Sans club" : registerModel.getClub2().getName(), model.getGenre(),
|
||||
model.getCountry(), registerModel.getOverCategory(), registerModel.getWeight(), new ArrayList<>());
|
||||
model.getCountry(), registerModel.getOverCategory(), registerModel.getWeight(), new ArrayList<>(),
|
||||
new ArrayList<>());
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,10 +4,12 @@ import fr.titionfire.ffsaf.data.model.CatPresetModel;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@RegisterForReflection
|
||||
public class PresetData {
|
||||
|
||||
@ -250,6 +250,12 @@ public class RCategorie {
|
||||
.replaceWithVoid();
|
||||
}
|
||||
|
||||
@WSReceiver(code = "listPreset", permission = PermLevel.VIEW)
|
||||
public Uni<List<PresetData>> listPreset(WebSocketConnection connection, Object o) {
|
||||
return catPresetRepository.list("competition.uuid", connection.pathParam("uuid"))
|
||||
.map(presets -> presets.stream().map(PresetData::fromModel).toList());
|
||||
}
|
||||
|
||||
@WSReceiver(code = "createClassementMatchs", permission = PermLevel.TABLE)
|
||||
public Uni<Void> createClassementMatchs(WebSocketConnection connection, Long categoryId) {
|
||||
return getById(categoryId, connection)
|
||||
|
||||
@ -6,6 +6,7 @@ import fr.titionfire.ffsaf.ws.PermLevel;
|
||||
import io.quarkus.hibernate.reactive.panache.common.WithSession;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
import io.quarkus.websockets.next.WebSocketConnection;
|
||||
import io.smallrye.mutiny.Multi;
|
||||
import io.smallrye.mutiny.Uni;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
@ -24,14 +25,20 @@ public class RRegister {
|
||||
|
||||
@WSReceiver(code = "getRegister", permission = PermLevel.TABLE)
|
||||
public Uni<List<CombEntity>> getRegister(WebSocketConnection connection, Object o) {
|
||||
ArrayList<CombEntity> combEntities = new ArrayList<>();
|
||||
return competitionRepository.find("uuid", connection.pathParam("uuid")).firstResult()
|
||||
.call(cm -> Mutiny.fetch(cm.getInsc()))
|
||||
.call(cm -> Mutiny.fetch(cm.getGuests()))
|
||||
.map(cm -> {
|
||||
ArrayList<CombEntity> combEntities = new ArrayList<>();
|
||||
combEntities.addAll(cm.getInsc().stream().map(CombEntity::fromModel).toList());
|
||||
combEntities.addAll(cm.getGuests().stream().map(CombEntity::fromModel).toList());
|
||||
return combEntities;
|
||||
});
|
||||
.call(cm -> Mutiny.fetch(cm.getInsc())
|
||||
.onItem().transformToMulti(Multi.createFrom()::iterable)
|
||||
.call(r -> Mutiny.fetch(r.getCategoriesInscrites()))
|
||||
.map(r -> CombEntity.fromModel(r).addCategoriesInscrites(r.getCategoriesInscrites()))
|
||||
.collect().asList()
|
||||
.invoke(combEntities::addAll))
|
||||
.call(cm -> Mutiny.fetch(cm.getGuests())
|
||||
.onItem().transformToMulti(Multi.createFrom()::iterable)
|
||||
.call(r -> Mutiny.fetch(r.getCategoriesInscrites()))
|
||||
.map(r -> CombEntity.fromModel(r).addCategoriesInscrites(r.getCategoriesInscrites()))
|
||||
.collect().asList()
|
||||
.invoke(combEntities::addAll))
|
||||
.replaceWith(combEntities);
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,6 +14,7 @@ import io.quarkus.websockets.next.UserData;
|
||||
import io.smallrye.mutiny.Uni;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import org.hibernate.reactive.mutiny.Mutiny;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
@ -30,18 +31,20 @@ public class SRegister {
|
||||
CardService cardService;
|
||||
|
||||
public Uni<Void> sendRegister(String uuid, RegisterModel registerModel) {
|
||||
return send(uuid, "sendRegister", CombEntity.fromModel(registerModel))
|
||||
.call(__ -> cardService.addTeamCartToNewComb(registerModel.getMembre().getId(),
|
||||
registerModel.getClub2().getClubId(), registerModel.getClub2().getName(),
|
||||
registerModel.getCompetition())
|
||||
.chain(cardModels -> send(uuid, "sendCards", cardModels)));
|
||||
return Mutiny.fetch(registerModel.getCategoriesInscrites()).chain(o ->
|
||||
send(uuid, "sendRegister", CombEntity.fromModel(registerModel).addCategoriesInscrites(o))
|
||||
.call(__ -> cardService.addTeamCartToNewComb(registerModel.getMembre().getId(),
|
||||
registerModel.getClub2().getClubId(), registerModel.getClub2().getName(),
|
||||
registerModel.getCompetition())
|
||||
.chain(cardModels -> send(uuid, "sendCards", cardModels))));
|
||||
}
|
||||
|
||||
public Uni<Void> sendRegister(String uuid, CompetitionGuestModel model) {
|
||||
return send(uuid, "sendRegister", CombEntity.fromModel(model))
|
||||
.call(__ -> cardService.addTeamCartToNewComb(model.getId() * -1,
|
||||
null, model.getClub(), model.getCompetition())
|
||||
.chain(cardModels -> send(uuid, "sendCards", cardModels)));
|
||||
return Mutiny.fetch(model.getCategoriesInscrites()).chain(o ->
|
||||
send(uuid, "sendRegister", CombEntity.fromModel(model).addCategoriesInscrites(o))
|
||||
.call(__ -> cardService.addTeamCartToNewComb(model.getId() * -1,
|
||||
null, model.getClub(), model.getCompetition())
|
||||
.chain(cardModels -> send(uuid, "sendCards", cardModels))));
|
||||
}
|
||||
|
||||
public Uni<Void> sendRegisterRemove(String uuid, Long combId) {
|
||||
|
||||
37
src/main/webapp/src/components/cm/ListPresetSelect.jsx
Normal file
37
src/main/webapp/src/components/cm/ListPresetSelect.jsx
Normal file
@ -0,0 +1,37 @@
|
||||
import {useRequestWS} from "../../hooks/useWS.jsx";
|
||||
import {AxiosError} from "../AxiosError.jsx";
|
||||
import {useTranslation} from "react-i18next";
|
||||
import React, {useId} from "react";
|
||||
|
||||
export function ListPresetSelect({disabled, value, onChange}) {
|
||||
const id = useId()
|
||||
const {data, error} = useRequestWS("listPreset", {}, null);
|
||||
const {t} = useTranslation();
|
||||
return <>
|
||||
{data
|
||||
? <div className="mb-3">
|
||||
<label className="form-label" htmlFor={id}>{t('catégorie')}</label>
|
||||
<select className="form-select" id={id} disabled={disabled}
|
||||
value={value} onChange={e => onChange(Number(e.target.value))}>
|
||||
<option value={-1}>{t('sélectionner...')}</option>
|
||||
{data.sort((a, b) => a.name.localeCompare(b.name)).map(club => (<option key={club.id} value={club.id}>{club.name}</option>))}
|
||||
</select>
|
||||
</div>
|
||||
: error
|
||||
? <AxiosError error={error}/>
|
||||
: <Def/>
|
||||
}
|
||||
</>
|
||||
}
|
||||
|
||||
function Def() {
|
||||
const {t} = useTranslation();
|
||||
|
||||
return <div className="input-group mb-3">
|
||||
<label className="input-group-text" id="inputGroupSelect02">{t('catégorie')}</label>
|
||||
<select className="form-select" id="inputGroupSelect02"
|
||||
defaultValue={t('chargement...')}>
|
||||
<option>{t('chargement...')}</option>
|
||||
</select>
|
||||
</div>;
|
||||
}
|
||||
@ -19,6 +19,7 @@ import {copyStyles} from "../../../utils/copyStyles.js";
|
||||
import {StateWindow} from "./StateWindow.jsx";
|
||||
import {CombName, useCombs} from "../../../hooks/useComb.jsx";
|
||||
import {useCards, useCardsDispatch} from "../../../hooks/useCard.jsx";
|
||||
import {ListPresetSelect} from "../../../components/cm/ListPresetSelect.jsx";
|
||||
|
||||
const vite_url = import.meta.env.VITE_URL;
|
||||
|
||||
@ -610,6 +611,7 @@ function ModalContent({state, setCatId, setConfirm, confirmRef}) {
|
||||
const [fullClassement, setFullClassement] = useState(false)
|
||||
const [size, setSize] = useState(4)
|
||||
const [loserMatch, setLoserMatch] = useState(1)
|
||||
const [preset, setPreset] = useState(-1)
|
||||
const {t} = useTranslation("cm");
|
||||
|
||||
const {sendRequest} = useWS();
|
||||
@ -621,6 +623,7 @@ function ModalContent({state, setCatId, setConfirm, confirmRef}) {
|
||||
setTournoi((state.type & 2) !== 0);
|
||||
setClassement(state.treeAreClassement !== undefined && state.treeAreClassement !== false);
|
||||
setFullClassement(state.fullClassement !== undefined && state.fullClassement !== false);
|
||||
setPreset(state.preset?.id || -1);
|
||||
|
||||
let trees_ = []
|
||||
for (let i = 0; i < state?.raw_trees?.length; i++) {
|
||||
@ -674,7 +677,8 @@ function ModalContent({state, setCatId, setConfirm, confirmRef}) {
|
||||
liceName: lice.trim(),
|
||||
type: nType,
|
||||
treeAreClassement: classement,
|
||||
fullClassement: fullClassement
|
||||
fullClassement: fullClassement,
|
||||
preset: {id: preset !== -1 ? preset : null}
|
||||
}
|
||||
|
||||
let nbMatch = -1;
|
||||
@ -745,7 +749,10 @@ function ModalContent({state, setCatId, setConfirm, confirmRef}) {
|
||||
toast.promise(sendRequest('createCategory', {
|
||||
name: name.trim(),
|
||||
liceName: lice.trim(),
|
||||
type: nType
|
||||
type: nType,
|
||||
treeAreClassement: classement,
|
||||
fullClassement: fullClassement,
|
||||
preset: {id: preset !== -1 ? preset : null}
|
||||
}), getToastMessage("toast.createCategory", "cm")
|
||||
).then(id => {
|
||||
if (tournoi) {
|
||||
@ -774,6 +781,8 @@ function ModalContent({state, setCatId, setConfirm, confirmRef}) {
|
||||
onChange={e => setName(e.target.value)}/>
|
||||
</div>
|
||||
|
||||
<ListPresetSelect value={preset} onChange={setPreset}/>
|
||||
|
||||
<div className="mb-3">
|
||||
<label htmlFor="liceInput1" className="form-label"><Trans i18nKey="nomDesZonesDeCombat" ns="cm">t <small>(séparée par des ';')</small></Trans></label>
|
||||
<input type="text" className="form-control" id="liceInput1" placeholder="1;2" name="zone de combat" value={lice}
|
||||
|
||||
@ -169,7 +169,7 @@ export function CategoryContent({cat, catId, setCat, menuActions}) {
|
||||
|
||||
return <>
|
||||
<div className="col-md-3">
|
||||
<AddComb groups={groups} setGroups={setGroups} removeGroup={removeGroup} menuActions={menuActions}/>
|
||||
<AddComb groups={groups} setGroups={setGroups} removeGroup={removeGroup} menuActions={menuActions} cat={cat}/>
|
||||
</div>
|
||||
<div className="col-md-9">
|
||||
{cat && <ListMatch cat={cat} matches={matches} groups={groups} reducer={reducer}/>}
|
||||
@ -177,7 +177,7 @@ export function CategoryContent({cat, catId, setCat, menuActions}) {
|
||||
</>
|
||||
}
|
||||
|
||||
function AddComb({groups, setGroups, removeGroup, menuActions}) {
|
||||
function AddComb({groups, setGroups, removeGroup, menuActions, cat}) {
|
||||
const {data, setData} = useRequestWS("getRegister", null)
|
||||
const combDispatch = useCombsDispatch()
|
||||
const {dispatch} = useWS()
|
||||
@ -243,7 +243,8 @@ function AddComb({groups, setGroups, removeGroup, menuActions}) {
|
||||
<div className="modal fade" id="selectCombModal" tabIndex="-1" aria-labelledby="selectCombModalLabel" aria-hidden="true">
|
||||
<div className="modal-dialog modal-dialog-scrollable modal-lg modal-fullscreen-lg-down">
|
||||
<div className="modal-content">
|
||||
<SelectCombModalContent data={data} setGroups={setGroups} teamMode={modalMode} groups={groups}/>
|
||||
<SelectCombModalContent data={data} setGroups={setGroups} teamMode={modalMode} groups={groups}
|
||||
defaultPreset={cat?.preset?.id || -1}/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
import {useCountries} from "../../../hooks/useCountries.jsx";
|
||||
import {useEffect, useReducer, useRef, useState} from "react";
|
||||
import React, {useEffect, useReducer, useRef, useState} from "react";
|
||||
import {CatList, getCatName, getToastMessage} from "../../../utils/Tools.js";
|
||||
import {CombName} from "../../../hooks/useComb.jsx";
|
||||
import {useWS} from "../../../hooks/useWS.jsx";
|
||||
import {useTranslation} from "react-i18next";
|
||||
import {toast} from "react-toastify";
|
||||
import {ListPresetSelect} from "../../../components/cm/ListPresetSelect.jsx";
|
||||
|
||||
function SelectReducer(state, action) {
|
||||
switch (action.type) {
|
||||
@ -59,7 +60,7 @@ function SelectReducer(state, action) {
|
||||
}
|
||||
}
|
||||
|
||||
export function SelectCombModalContent({data, groups, setGroups, teamMode = false}) {
|
||||
export function SelectCombModalContent({data, groups, setGroups, teamMode = false, defaultPreset = -1}) {
|
||||
const country = useCountries('fr')
|
||||
const {t} = useTranslation("cm");
|
||||
const {sendRequest, dispatch} = useWS()
|
||||
@ -77,6 +78,11 @@ export function SelectCombModalContent({data, groups, setGroups, teamMode = fals
|
||||
const [weightMax, setWeightMax] = useState(0)
|
||||
const [team, setTeam] = useState(false)
|
||||
const [teamName, setTeamName] = useState("");
|
||||
const [preset, setPreset] = useState(-1)
|
||||
|
||||
useEffect(() => {
|
||||
setPreset(defaultPreset)
|
||||
}, [defaultPreset])
|
||||
|
||||
const handleSubmit = (e) => {
|
||||
e.preventDefault();
|
||||
@ -149,7 +155,8 @@ export function SelectCombModalContent({data, groups, setGroups, teamMode = fals
|
||||
&& (weightMin === 0 || comb.weight !== null && comb.weight >= weightMin)
|
||||
&& (weightMax === 0 || comb.weight !== null && comb.weight <= weightMax)
|
||||
&& (teamMode && (comb.teamMembers == null || comb.teamMembers.length === 0) || !teamMode
|
||||
&& ((comb.teamMembers == null || comb.teamMembers.length === 0) !== team))) {
|
||||
&& ((comb.teamMembers == null || comb.teamMembers.length === 0) !== team))
|
||||
&& (preset === -1 || comb.categoriesInscrites.includes(preset))) {
|
||||
dataOut[id] = dataIn[id];
|
||||
}
|
||||
}
|
||||
@ -215,6 +222,8 @@ export function SelectCombModalContent({data, groups, setGroups, teamMode = fals
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<ListPresetSelect value={preset} onChange={setPreset}/>
|
||||
|
||||
<div>
|
||||
<label htmlFor="inputState1" className="form-label">{t('club')}</label>
|
||||
<select id="inputState1" className="form-select" value={club} onChange={(e) => setClub(e.target.value)}>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user