Compare commits
4 Commits
a1b5ca2694
...
dev-comp
| Author | SHA1 | Date | |
|---|---|---|---|
| 73f026210c | |||
| 4b969e6d69 | |||
| 4706af27f8 | |||
| 3e8c19534b |
@@ -66,15 +66,19 @@ public class MatchModel {
|
|||||||
List<CardboardModel> cardboard = new ArrayList<>();
|
List<CardboardModel> cardboard = new ArrayList<>();
|
||||||
|
|
||||||
public String getC1Name() {
|
public String getC1Name() {
|
||||||
if (c1_id == null)
|
if (c1_id != null)
|
||||||
|
return c1_id.fname + " " + c1_id.lname;
|
||||||
|
if (c1_guest != null)
|
||||||
return c1_guest.fname + " " + c1_guest.lname;
|
return c1_guest.fname + " " + c1_guest.lname;
|
||||||
return c1_id.fname + " " + c1_id.lname;
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getC2Name() {
|
public String getC2Name() {
|
||||||
if (c2_id == null)
|
if (c2_id != null)
|
||||||
|
return c2_id.fname + " " + c2_id.lname;
|
||||||
|
if (c2_guest != null)
|
||||||
return c2_guest.fname + " " + c2_guest.lname;
|
return c2_guest.fname + " " + c2_guest.lname;
|
||||||
return c2_id.fname + " " + c2_id.lname;
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public int win() {
|
public int win() {
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package fr.titionfire.ffsaf.data.repository;
|
||||||
|
|
||||||
|
import fr.titionfire.ffsaf.data.model.CardboardModel;
|
||||||
|
import io.quarkus.hibernate.reactive.panache.PanacheRepositoryBase;
|
||||||
|
import jakarta.enterprise.context.ApplicationScoped;
|
||||||
|
|
||||||
|
@ApplicationScoped
|
||||||
|
public class CardboardRepository implements PanacheRepositoryBase<CardboardModel, Long> {
|
||||||
|
}
|
||||||
@@ -17,7 +17,10 @@ public class CardboardEntity {
|
|||||||
int yellow;
|
int yellow;
|
||||||
|
|
||||||
public static CardboardEntity fromModel(CardboardModel model) {
|
public static CardboardEntity fromModel(CardboardModel model) {
|
||||||
return new CardboardEntity(model.getComb().getId(), model.getMatch().getId(), model.getCompet().getId(),
|
return new CardboardEntity(
|
||||||
|
model.getComb() != null ? model.getComb().getId() : model.getGuestComb().getId() * -1,
|
||||||
|
model.getMatch().getId(),
|
||||||
|
model.getCompet().getId(),
|
||||||
model.getRed(), model.getYellow());
|
model.getRed(), model.getYellow());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ public class CompetPermService {
|
|||||||
CompletableFuture<SimpleCompet> f = new CompletableFuture<>();
|
CompletableFuture<SimpleCompet> f = new CompletableFuture<>();
|
||||||
SReqCompet.getConfig(serverCustom.clients, id, f);
|
SReqCompet.getConfig(serverCustom.clients, id, f);
|
||||||
try {
|
try {
|
||||||
return f.get(1500, TimeUnit.MILLISECONDS);
|
return f.get(500, TimeUnit.MILLISECONDS);
|
||||||
} catch (InterruptedException | ExecutionException | TimeoutException e) {
|
} catch (InterruptedException | ExecutionException | TimeoutException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@@ -71,7 +71,8 @@ public class CompetPermService {
|
|||||||
.chain(competitionModels -> {
|
.chain(competitionModels -> {
|
||||||
CompletableFuture<HashMap<String, String>> f = new CompletableFuture<>();
|
CompletableFuture<HashMap<String, String>> f = new CompletableFuture<>();
|
||||||
SReqCompet.getAllHaveAccess(serverCustom.clients, securityCtx.getSubject(), f);
|
SReqCompet.getAllHaveAccess(serverCustom.clients, securityCtx.getSubject(), f);
|
||||||
return Uni.createFrom().future(f, Duration.ofMillis(1500))
|
return Uni.createFrom().future(f, Duration.ofMillis(500))
|
||||||
|
.onFailure().recoverWithItem(new HashMap<>())
|
||||||
.map(map_ -> {
|
.map(map_ -> {
|
||||||
HashMap<Long, String> map = new HashMap<>();
|
HashMap<Long, String> map = new HashMap<>();
|
||||||
map_.forEach((key, value) -> map.put(Long.parseLong(key), value));
|
map_.forEach((key, value) -> map.put(Long.parseLong(key), value));
|
||||||
|
|||||||
@@ -162,6 +162,14 @@ public class CompetitionService {
|
|||||||
.map(pouleModels -> pouleModels.stream().map(CompetitionData::fromModel).toList());
|
.map(pouleModels -> pouleModels.stream().map(CompetitionData::fromModel).toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Uni<List<CompetitionData>> getAllSystemTable(SecurityCtx securityCtx,
|
||||||
|
CompetitionSystem system) {
|
||||||
|
return repository.list("system = ?1", system)
|
||||||
|
.chain(l -> Uni.join().all(l.stream().map(cm -> permService.hasTablePerm(securityCtx, cm)).toList())
|
||||||
|
.andCollectFailures())
|
||||||
|
.map(l -> l.stream().filter(Objects::nonNull).map(CompetitionData::fromModel).toList());
|
||||||
|
}
|
||||||
|
|
||||||
public Uni<CompetitionData> addOrUpdate(SecurityCtx securityCtx, CompetitionData data) {
|
public Uni<CompetitionData> addOrUpdate(SecurityCtx securityCtx, CompetitionData data) {
|
||||||
if (data.getId() == null) {
|
if (data.getId() == null) {
|
||||||
return combRepository.find("userId = ?1", securityCtx.getSubject()).firstResult()
|
return combRepository.find("userId = ?1", securityCtx.getSubject()).firstResult()
|
||||||
@@ -496,6 +504,10 @@ public class CompetitionService {
|
|||||||
.andCollectFailures()))
|
.andCollectFailures()))
|
||||||
.call(competitionModel -> Panache.withTransaction(
|
.call(competitionModel -> Panache.withTransaction(
|
||||||
() -> categoryRepository.delete("compet = ?1", competitionModel)))
|
() -> categoryRepository.delete("compet = ?1", competitionModel)))
|
||||||
|
.call(competitionModel -> Panache.withTransaction(
|
||||||
|
() -> registerRepository.delete("competition = ?1", competitionModel)))
|
||||||
|
.call(competitionModel -> Panache.withTransaction(
|
||||||
|
() -> competitionGuestRepository.delete("competition = ?1", competitionModel)))
|
||||||
.chain(model -> Panache.withTransaction(() -> repository.delete("id", model.getId())))
|
.chain(model -> Panache.withTransaction(() -> repository.delete("id", model.getId())))
|
||||||
.invoke(o -> SReqCompet.rmCompet(serverCustom.clients, id))
|
.invoke(o -> SReqCompet.rmCompet(serverCustom.clients, id))
|
||||||
.call(__ -> cache.invalidate(id));
|
.call(__ -> cache.invalidate(id));
|
||||||
|
|||||||
@@ -47,4 +47,12 @@ public class CompetitionAdminEndpoints {
|
|||||||
public Uni<List<CompetitionData>> getAllSystemAdmin(@PathParam("system") CompetitionSystem system) {
|
public Uni<List<CompetitionData>> getAllSystemAdmin(@PathParam("system") CompetitionSystem system) {
|
||||||
return service.getAllSystemAdmin(securityCtx, system);
|
return service.getAllSystemAdmin(securityCtx, system);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("all/{system}/table")
|
||||||
|
@Authenticated
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
public Uni<List<CompetitionData>> getAllSystemTable(@PathParam("system") CompetitionSystem system) {
|
||||||
|
return service.getAllSystemTable(securityCtx, system);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,10 +6,7 @@ import fr.titionfire.ffsaf.domain.service.CompetPermService;
|
|||||||
import fr.titionfire.ffsaf.net2.MessageType;
|
import fr.titionfire.ffsaf.net2.MessageType;
|
||||||
import fr.titionfire.ffsaf.utils.SecurityCtx;
|
import fr.titionfire.ffsaf.utils.SecurityCtx;
|
||||||
import fr.titionfire.ffsaf.ws.data.WelcomeInfo;
|
import fr.titionfire.ffsaf.ws.data.WelcomeInfo;
|
||||||
import fr.titionfire.ffsaf.ws.recv.RCategorie;
|
import fr.titionfire.ffsaf.ws.recv.*;
|
||||||
import fr.titionfire.ffsaf.ws.recv.RMatch;
|
|
||||||
import fr.titionfire.ffsaf.ws.recv.RRegister;
|
|
||||||
import fr.titionfire.ffsaf.ws.recv.WSReceiver;
|
|
||||||
import fr.titionfire.ffsaf.ws.send.JsonUni;
|
import fr.titionfire.ffsaf.ws.send.JsonUni;
|
||||||
import io.quarkus.hibernate.reactive.panache.common.WithSession;
|
import io.quarkus.hibernate.reactive.panache.common.WithSession;
|
||||||
import io.quarkus.security.Authenticated;
|
import io.quarkus.security.Authenticated;
|
||||||
@@ -44,6 +41,9 @@ public class CompetitionWS {
|
|||||||
@Inject
|
@Inject
|
||||||
RRegister rRegister;
|
RRegister rRegister;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
RCardboard rCardboard;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
SecurityCtx securityCtx;
|
SecurityCtx securityCtx;
|
||||||
|
|
||||||
@@ -77,6 +77,7 @@ public class CompetitionWS {
|
|||||||
getWSReceiverMethods(RMatch.class, rMatch);
|
getWSReceiverMethods(RMatch.class, rMatch);
|
||||||
getWSReceiverMethods(RCategorie.class, rCategorie);
|
getWSReceiverMethods(RCategorie.class, rCategorie);
|
||||||
getWSReceiverMethods(RRegister.class, rRegister);
|
getWSReceiverMethods(RRegister.class, rRegister);
|
||||||
|
getWSReceiverMethods(RCardboard.class, rCardboard);
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnOpen
|
@OnOpen
|
||||||
|
|||||||
128
src/main/java/fr/titionfire/ffsaf/ws/recv/RCardboard.java
Normal file
128
src/main/java/fr/titionfire/ffsaf/ws/recv/RCardboard.java
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
package fr.titionfire.ffsaf.ws.recv;
|
||||||
|
|
||||||
|
import fr.titionfire.ffsaf.data.model.CardboardModel;
|
||||||
|
import fr.titionfire.ffsaf.data.model.MatchModel;
|
||||||
|
import fr.titionfire.ffsaf.data.repository.CardboardRepository;
|
||||||
|
import fr.titionfire.ffsaf.data.repository.MatchRepository;
|
||||||
|
import fr.titionfire.ffsaf.domain.entity.CardboardEntity;
|
||||||
|
import fr.titionfire.ffsaf.rest.exception.DForbiddenException;
|
||||||
|
import fr.titionfire.ffsaf.rest.exception.DNotFoundException;
|
||||||
|
import fr.titionfire.ffsaf.ws.PermLevel;
|
||||||
|
import fr.titionfire.ffsaf.ws.send.SSCardboard;
|
||||||
|
import io.quarkus.hibernate.reactive.panache.Panache;
|
||||||
|
import io.quarkus.hibernate.reactive.panache.common.WithSession;
|
||||||
|
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||||
|
import io.quarkus.websockets.next.WebSocketConnection;
|
||||||
|
import io.smallrye.mutiny.Uni;
|
||||||
|
import io.smallrye.mutiny.unchecked.Unchecked;
|
||||||
|
import jakarta.enterprise.context.ApplicationScoped;
|
||||||
|
import jakarta.inject.Inject;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
@WithSession
|
||||||
|
@ApplicationScoped
|
||||||
|
@RegisterForReflection
|
||||||
|
public class RCardboard {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
MatchRepository matchRepository;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
CardboardRepository cardboardRepository;
|
||||||
|
|
||||||
|
private Uni<MatchModel> getById(long id, WebSocketConnection connection) {
|
||||||
|
return matchRepository.findById(id)
|
||||||
|
.invoke(Unchecked.consumer(o -> {
|
||||||
|
if (o == null)
|
||||||
|
throw new DNotFoundException("Matche non trouver");
|
||||||
|
if (!o.getCategory().getCompet().getUuid().equals(connection.pathParam("uuid")))
|
||||||
|
throw new DForbiddenException("Permission denied");
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
@WSReceiver(code = "sendCardboardChange", permission = PermLevel.TABLE)
|
||||||
|
public Uni<Void> sendCardboardChange(WebSocketConnection connection, SendCardboard card) {
|
||||||
|
return getById(card.matchId, connection)
|
||||||
|
.chain(matchModel -> cardboardRepository.find("(comb.id = ?1 OR guestComb.id = ?2) AND match.id = ?3",
|
||||||
|
card.combId, card.combId * -1, card.matchId).firstResult()
|
||||||
|
.chain(model -> {
|
||||||
|
if (model != null) {
|
||||||
|
model.setRed(model.getRed() + card.red);
|
||||||
|
model.setYellow(model.getYellow() + card.yellow);
|
||||||
|
return Panache.withTransaction(() -> cardboardRepository.persist(model));
|
||||||
|
}
|
||||||
|
CardboardModel cardboardModel = new CardboardModel();
|
||||||
|
|
||||||
|
cardboardModel.setCompet(matchModel.getCategory().getCompet());
|
||||||
|
cardboardModel.setMatch(matchModel);
|
||||||
|
cardboardModel.setRed(card.red);
|
||||||
|
cardboardModel.setYellow(card.yellow);
|
||||||
|
cardboardModel.setComb(null);
|
||||||
|
cardboardModel.setGuestComb(null);
|
||||||
|
|
||||||
|
if (card.combId >= 0) {
|
||||||
|
if (matchModel.getC1_id() != null && matchModel.getC1_id().getId() == card.combId)
|
||||||
|
cardboardModel.setComb(matchModel.getC1_id());
|
||||||
|
if (matchModel.getC2_id() != null && matchModel.getC2_id().getId() == card.combId)
|
||||||
|
cardboardModel.setComb(matchModel.getC2_id());
|
||||||
|
} else {
|
||||||
|
if (matchModel.getC1_guest() != null && matchModel.getC1_guest()
|
||||||
|
.getId() == card.combId * -1)
|
||||||
|
cardboardModel.setGuestComb(matchModel.getC1_guest());
|
||||||
|
if (matchModel.getC2_guest() != null && matchModel.getC2_guest()
|
||||||
|
.getId() == card.combId * -1)
|
||||||
|
cardboardModel.setGuestComb(matchModel.getC2_guest());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cardboardModel.getComb() == null && cardboardModel.getGuestComb() == null)
|
||||||
|
return Uni.createFrom().nullItem();
|
||||||
|
return Panache.withTransaction(() -> cardboardRepository.persist(cardboardModel));
|
||||||
|
}))
|
||||||
|
.call(model -> SSCardboard.sendCardboard(connection, CardboardEntity.fromModel(model)))
|
||||||
|
.replaceWithVoid();
|
||||||
|
}
|
||||||
|
|
||||||
|
@WSReceiver(code = "getCardboardWithoutThis", permission = PermLevel.VIEW)
|
||||||
|
public Uni<CardboardAllMatch> getCardboardWithoutThis(WebSocketConnection connection, Long matchId) {
|
||||||
|
return getById(matchId, connection)
|
||||||
|
.chain(matchModel -> cardboardRepository.list("compet = ?1 AND match != ?2", matchModel.getCategory().getCompet(), matchModel)
|
||||||
|
.map(models -> {
|
||||||
|
CardboardAllMatch out = new CardboardAllMatch();
|
||||||
|
|
||||||
|
models.stream().filter(c -> (matchModel.getC1_id() != null
|
||||||
|
&& Objects.equals(c.getComb(), matchModel.getC1_id()))
|
||||||
|
|| (matchModel.getC1_guest() != null
|
||||||
|
&& Objects.equals(c.getGuestComb(), matchModel.getC1_guest())))
|
||||||
|
.forEach(c -> {
|
||||||
|
out.c1_yellow += c.getYellow();
|
||||||
|
out.c1_red += c.getRed();
|
||||||
|
});
|
||||||
|
|
||||||
|
models.stream().filter(c -> (matchModel.getC2_id() != null
|
||||||
|
&& Objects.equals(c.getComb(), matchModel.getC2_id()))
|
||||||
|
|| (matchModel.getC2_guest() != null
|
||||||
|
&& Objects.equals(c.getGuestComb(), matchModel.getC2_guest())))
|
||||||
|
.forEach(c -> {
|
||||||
|
out.c2_yellow += c.getYellow();
|
||||||
|
out.c2_red += c.getRed();
|
||||||
|
});
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
@RegisterForReflection
|
||||||
|
public record SendCardboard(long matchId, long combId, int yellow, int red) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@RegisterForReflection
|
||||||
|
public static class CardboardAllMatch {
|
||||||
|
int c1_yellow = 0;
|
||||||
|
int c1_red = 0;
|
||||||
|
int c2_yellow = 0;
|
||||||
|
int c2_red = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
13
src/main/java/fr/titionfire/ffsaf/ws/send/SSCardboard.java
Normal file
13
src/main/java/fr/titionfire/ffsaf/ws/send/SSCardboard.java
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package fr.titionfire.ffsaf.ws.send;
|
||||||
|
|
||||||
|
import fr.titionfire.ffsaf.domain.entity.CardboardEntity;
|
||||||
|
import fr.titionfire.ffsaf.ws.CompetitionWS;
|
||||||
|
import io.quarkus.websockets.next.WebSocketConnection;
|
||||||
|
import io.smallrye.mutiny.Uni;
|
||||||
|
|
||||||
|
public class SSCardboard {
|
||||||
|
|
||||||
|
public static Uni<Void> sendCardboard(WebSocketConnection connection, CardboardEntity cardboardEntity) {
|
||||||
|
return CompetitionWS.sendNotifyToOtherEditor(connection, "sendCardboard", cardboardEntity);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -43,9 +43,9 @@ function AffiliationMenu() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function CompMenu() {
|
function CompMenu() {
|
||||||
const {is_authenticated} = useAuth()
|
const {is_authenticated, userinfo} = useAuth()
|
||||||
|
|
||||||
if (!is_authenticated)
|
if (!is_authenticated || !userinfo?.roles?.includes("federation_admin"))
|
||||||
return <></>
|
return <></>
|
||||||
|
|
||||||
return <li className="nav-item dropdown">
|
return <li className="nav-item dropdown">
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import {createContext, useContext, useReducer} from "react";
|
import {createContext, useContext, useReducer} from "react";
|
||||||
|
|
||||||
const PubAffContext = createContext({next: [], c1: undefined, c2: undefined, showScore: true, timeCb: undefined});
|
const PubAffContext = createContext({next: [], c1: undefined, c2: undefined, showScore: true, timeCb: undefined, scoreRouge: 0, scoreBleu: 0});
|
||||||
const PubAffDispatchContext = createContext(() => {
|
const PubAffDispatchContext = createContext(() => {
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,10 @@ export function CompetitionEdit() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
refresh(`/competition/${id}?light=false`)
|
||||||
|
}, [id]);
|
||||||
|
|
||||||
return <>
|
return <>
|
||||||
<button type="button" className="btn btn-link" onClick={() => navigate("/competition")}>
|
<button type="button" className="btn btn-link" onClick={() => navigate("/competition")}>
|
||||||
« retour
|
« retour
|
||||||
@@ -284,17 +288,18 @@ function Content({data}) {
|
|||||||
toast.promise(
|
toast.promise(
|
||||||
apiAxios.post(`/competition`, out),
|
apiAxios.post(`/competition`, out),
|
||||||
{
|
{
|
||||||
pending: "Enregistrement du club en cours",
|
pending: "Enregistrement de la competition en cours",
|
||||||
success: "Club enregistrée avec succès 🎉",
|
success: "Competition enregistrée avec succès 🎉",
|
||||||
error: {
|
error: {
|
||||||
render({data}) {
|
render({data}) {
|
||||||
return errFormater(data, "Échec de l'enregistrement du club")
|
return errFormater(data, "Échec de l'enregistrement de la competition")
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
).then(data => {
|
).then(data => {
|
||||||
if (data.id !== undefined)
|
console.log(data.data)
|
||||||
navigate("/competition/" + data.id)
|
if (data.data.id !== undefined)
|
||||||
|
navigate("/competition/" + data.data.id)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -315,7 +320,7 @@ function Content({data}) {
|
|||||||
<div id="collapseOne" className="accordion-collapse collapse" data-bs-parent="#accordionExample">
|
<div id="collapseOne" className="accordion-collapse collapse" data-bs-parent="#accordionExample">
|
||||||
<div className="accordion-body">
|
<div className="accordion-body">
|
||||||
<TextField name="uuid" text="UUID" value={data.uuid} disabled={true}/>
|
<TextField name="uuid" text="UUID" value={data.uuid} disabled={true}/>
|
||||||
<OptionField name="system" text="System" value={data.system} values={{SAFCA: 'SAFCA', NONE: "intranet"}}
|
<OptionField name="system" text="System" value={data.system} values={{SAFCA: 'SAFCA', INTERNAL: "Intranet"}}
|
||||||
disabled={data.id !== null}/>
|
disabled={data.id !== null}/>
|
||||||
{data.id !== null &&
|
{data.id !== null &&
|
||||||
<div className="row">
|
<div className="row">
|
||||||
@@ -383,11 +388,11 @@ function Content({data}) {
|
|||||||
<span className="input-group-text" id="startRegister">Du</span>
|
<span className="input-group-text" id="startRegister">Du</span>
|
||||||
<input type="datetime-local" className="form-control" placeholder="jj/mm/aaaa" aria-label="date"
|
<input type="datetime-local" className="form-control" placeholder="jj/mm/aaaa" aria-label="date"
|
||||||
name="startRegister" aria-describedby="startRegister"
|
name="startRegister" aria-describedby="startRegister"
|
||||||
defaultValue={data.startRegister ? data.startRegister.split('+')[0] : ''}/>
|
defaultValue={data.startRegister ? data.startRegister.substring(0, 16) : ''}/>
|
||||||
<span className="input-group-text" id="endRegister">Au</span>
|
<span className="input-group-text" id="endRegister">Au</span>
|
||||||
<input type="datetime-local" className="form-control" placeholder="jj/mm/aaaa" aria-label="endRegister"
|
<input type="datetime-local" className="form-control" placeholder="jj/mm/aaaa" aria-label="endRegister"
|
||||||
name="endRegister" aria-describedby="endRegister"
|
name="endRegister" aria-describedby="endRegister"
|
||||||
defaultValue={data.endRegister ? data.endRegister.split('+')[0] : ''}/>
|
defaultValue={data.endRegister ? data.endRegister.substring(0, 16) : ''}/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div style={{display: registerMode === "HELLOASSO" ? "initial" : "none"}}>
|
<div style={{display: registerMode === "HELLOASSO" ? "initial" : "none"}}>
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
.btn-xs {
|
||||||
|
--bs-btn-padding-y: .05rem;
|
||||||
|
--bs-btn-padding-x: .6rem;
|
||||||
|
--bs-btn-font-size: .75rem;
|
||||||
|
}
|
||||||
@@ -10,6 +10,7 @@ import {scorePrint, win} from "../../../utils/Tools.js";
|
|||||||
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
|
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
|
||||||
import {faCircleQuestion} from "@fortawesome/free-regular-svg-icons";
|
import {faCircleQuestion} from "@fortawesome/free-regular-svg-icons";
|
||||||
import {toast} from "react-toastify";
|
import {toast} from "react-toastify";
|
||||||
|
import "./CMTMatchPanel.css"
|
||||||
|
|
||||||
function CupImg() {
|
function CupImg() {
|
||||||
return <img decoding="async" loading="lazy" width={"16"} height={"16"} className="wp-image-1635"
|
return <img decoding="async" loading="lazy" width={"16"} height={"16"} className="wp-image-1635"
|
||||||
@@ -17,7 +18,7 @@ function CupImg() {
|
|||||||
alt=""/>
|
alt=""/>
|
||||||
}
|
}
|
||||||
|
|
||||||
export function CategorieSelect({catId, setCatId}) {
|
export function CategorieSelect({catId, setCatId, menuActions}) {
|
||||||
const setLoading = useLoadingSwitcher()
|
const setLoading = useLoadingSwitcher()
|
||||||
const {data: cats, setData: setCats} = useRequestWS('getAllCategory', {}, setLoading);
|
const {data: cats, setData: setCats} = useRequestWS('getAllCategory', {}, setLoading);
|
||||||
const {dispatch} = useWS();
|
const {dispatch} = useWS();
|
||||||
@@ -41,11 +42,11 @@ export function CategorieSelect({catId, setCatId}) {
|
|||||||
<option key={c.id} value={c.id}>{c.name}</option>))}
|
<option key={c.id} value={c.id}>{c.name}</option>))}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
{catId !== -1 && <CMTMatchPanel catId={catId} cat={cat}/>}
|
{catId !== -1 && <CMTMatchPanel catId={catId} cat={cat} menuActions={menuActions}/>}
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
|
|
||||||
function CMTMatchPanel({catId, cat}) {
|
function CMTMatchPanel({catId, cat, menuActions}) {
|
||||||
const setLoading = useLoadingSwitcher()
|
const setLoading = useLoadingSwitcher()
|
||||||
const {sendRequest, dispatch} = useWS();
|
const {sendRequest, dispatch} = useWS();
|
||||||
const [trees, setTrees] = useState([]);
|
const [trees, setTrees] = useState([]);
|
||||||
@@ -105,22 +106,28 @@ function CMTMatchPanel({catId, cat}) {
|
|||||||
reducer({type: 'REMOVE', payload: data})
|
reducer({type: 'REMOVE', payload: data})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const sendCardboard = ({data}) => {
|
||||||
|
reducer({type: 'UPDATE_CARDBOARD', payload: {...data}})
|
||||||
|
}
|
||||||
|
|
||||||
dispatch({type: 'addListener', payload: {callback: treeListener, code: 'sendTreeCategory'}})
|
dispatch({type: 'addListener', payload: {callback: treeListener, code: 'sendTreeCategory'}})
|
||||||
dispatch({type: 'addListener', payload: {callback: matchListener, code: 'sendMatch'}})
|
dispatch({type: 'addListener', payload: {callback: matchListener, code: 'sendMatch'}})
|
||||||
dispatch({type: 'addListener', payload: {callback: matchOrder, code: 'sendMatchOrder'}})
|
dispatch({type: 'addListener', payload: {callback: matchOrder, code: 'sendMatchOrder'}})
|
||||||
dispatch({type: 'addListener', payload: {callback: deleteMatch, code: 'sendDeleteMatch'}})
|
dispatch({type: 'addListener', payload: {callback: deleteMatch, code: 'sendDeleteMatch'}})
|
||||||
|
dispatch({type: 'addListener', payload: {callback: sendCardboard, code: 'sendCardboard'}})
|
||||||
return () => {
|
return () => {
|
||||||
dispatch({type: 'removeListener', payload: treeListener})
|
dispatch({type: 'removeListener', payload: treeListener})
|
||||||
dispatch({type: 'removeListener', payload: matchListener})
|
dispatch({type: 'removeListener', payload: matchListener})
|
||||||
dispatch({type: 'removeListener', payload: matchOrder})
|
dispatch({type: 'removeListener', payload: matchOrder})
|
||||||
dispatch({type: 'removeListener', payload: deleteMatch})
|
dispatch({type: 'removeListener', payload: deleteMatch})
|
||||||
|
dispatch({type: 'removeListener', payload: sendCardboard})
|
||||||
}
|
}
|
||||||
}, [catId]);
|
}, [catId]);
|
||||||
|
|
||||||
return <ListMatch cat={cat} matches={matches} trees={trees}/>
|
return <ListMatch cat={cat} matches={matches} trees={trees} menuActions={menuActions}/>
|
||||||
}
|
}
|
||||||
|
|
||||||
function ListMatch({cat, matches, trees}) {
|
function ListMatch({cat, matches, trees, menuActions}) {
|
||||||
const [type, setType] = useState(1);
|
const [type, setType] = useState(1);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -146,16 +153,16 @@ function ListMatch({cat, matches, trees}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{type === 1 && <>
|
{type === 1 && <>
|
||||||
<MatchList matches={matches} cat={cat}/>
|
<MatchList matches={matches} cat={cat} menuActions={menuActions}/>
|
||||||
</>}
|
</>}
|
||||||
|
|
||||||
{type === 2 && <>
|
{type === 2 && <>
|
||||||
<BuildTree treeData={trees} matches={matches}/>
|
<BuildTree treeData={trees} matches={matches} menuActions={menuActions}/>
|
||||||
</>}
|
</>}
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
function MatchList({matches, cat}) {
|
function MatchList({matches, cat, menuActions}) {
|
||||||
const [activeMatch, setActiveMatch] = useState(null)
|
const [activeMatch, setActiveMatch] = useState(null)
|
||||||
const [lice, setLice] = useState(localStorage.getItem("cm_lice") || "A")
|
const [lice, setLice] = useState(localStorage.getItem("cm_lice") || "A")
|
||||||
const publicAffDispatch = usePubAffDispatch();
|
const publicAffDispatch = usePubAffDispatch();
|
||||||
@@ -164,6 +171,7 @@ function MatchList({matches, cat}) {
|
|||||||
const marches2 = matches.filter(m => m.categorie_ord !== -42)
|
const marches2 = matches.filter(m => m.categorie_ord !== -42)
|
||||||
.sort((a, b) => a.categorie_ord - b.categorie_ord)
|
.sort((a, b) => a.categorie_ord - b.categorie_ord)
|
||||||
.map(m => ({...m, win: win(m.scores)}))
|
.map(m => ({...m, win: win(m.scores)}))
|
||||||
|
const firstIndex = marches2.findLastIndex(m => m.poule === '-') + 1;
|
||||||
|
|
||||||
const match = matches.find(m => m.id === activeMatch)
|
const match = matches.find(m => m.id === activeMatch)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -175,7 +183,10 @@ function MatchList({matches, cat}) {
|
|||||||
payload: {
|
payload: {
|
||||||
c1: match.c1,
|
c1: match.c1,
|
||||||
c2: match.c2,
|
c2: match.c2,
|
||||||
next: marches2.filter(m => !m.end && m.poule === lice && m.id !== activeMatch).map(m => ({c1: m.c1, c2: m.c2}))
|
next: marches2.filter((m, index) => !m.end && liceName[(index - firstIndex) % liceName.length] === lice && m.id !== activeMatch).map(m => ({
|
||||||
|
c1: m.c1,
|
||||||
|
c2: m.c2
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -187,7 +198,7 @@ function MatchList({matches, cat}) {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (match && match.poule !== lice)
|
if (match && match.poule !== lice)
|
||||||
setActiveMatch(marches2.find(m => !m.end && m.poule === lice)?.id)
|
setActiveMatch(marches2.find((m, index) => !m.end && liceName[(index - firstIndex) % liceName.length] === lice)?.id)
|
||||||
}, [lice]);
|
}, [lice]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -196,10 +207,8 @@ function MatchList({matches, cat}) {
|
|||||||
if (marches2.some(m => m.id === activeMatch))
|
if (marches2.some(m => m.id === activeMatch))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
setActiveMatch(marches2.find(m => !m.end && m.poule === lice)?.id);
|
setActiveMatch(marches2.find((m, index) => !m.end && liceName[(index - firstIndex) % liceName.length] === lice)?.id);
|
||||||
}, [matches])
|
}, [matches])
|
||||||
|
|
||||||
const firstIndex = marches2.findLastIndex(m => m.poule === '-') + 1;
|
|
||||||
return <>
|
return <>
|
||||||
{liceName.length > 1 &&
|
{liceName.length > 1 &&
|
||||||
<div className="input-group" style={{maxWidth: "10em", marginTop: "0.5em"}}>
|
<div className="input-group" style={{maxWidth: "10em", marginTop: "0.5em"}}>
|
||||||
@@ -230,7 +239,8 @@ function MatchList({matches, cat}) {
|
|||||||
</thead>
|
</thead>
|
||||||
<tbody className="table-group-divider">
|
<tbody className="table-group-divider">
|
||||||
{marches2.map((m, index) => (
|
{marches2.map((m, index) => (
|
||||||
<tr key={m.id} className={m.id === activeMatch ? "table-info" : (m.poule === lice ? "" : "table-warning")}
|
<tr key={m.id}
|
||||||
|
className={m.id === activeMatch ? "table-info" : (liceName[(index - firstIndex) % liceName.length] === lice ? "" : "table-warning")}
|
||||||
onClick={() => setActiveMatch(m.id)}>
|
onClick={() => setActiveMatch(m.id)}>
|
||||||
<td style={{textAlign: "center", paddingLeft: "0.2em", paddingRight: "0.2em"}}>
|
<td style={{textAlign: "center", paddingLeft: "0.2em", paddingRight: "0.2em"}}>
|
||||||
{liceName[(index - firstIndex) % liceName.length]}</td>
|
{liceName[(index - firstIndex) % liceName.length]}</td>
|
||||||
@@ -249,11 +259,11 @@ function MatchList({matches, cat}) {
|
|||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{activeMatch && <LoadingProvider><ScorePanel matchId={activeMatch} match={match}/></LoadingProvider>}
|
{activeMatch && <LoadingProvider><ScorePanel matchId={activeMatch} match={match} menuActions={menuActions}/></LoadingProvider>}
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
|
|
||||||
function BuildTree({treeData, matches}) {
|
function BuildTree({treeData, matches, menuActions}) {
|
||||||
const scrollRef = useRef(null)
|
const scrollRef = useRef(null)
|
||||||
const [currentMatch, setCurrentMatch] = useState(null)
|
const [currentMatch, setCurrentMatch] = useState(null)
|
||||||
const {getComb} = useCombs()
|
const {getComb} = useCombs()
|
||||||
@@ -320,11 +330,22 @@ function BuildTree({treeData, matches}) {
|
|||||||
matchSelect={currentMatch?.matchSelect} matchNext={currentMatch?.matchNext} size={23}/>
|
matchSelect={currentMatch?.matchSelect} matchNext={currentMatch?.matchNext} size={23}/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{currentMatch?.matchSelect && <LoadingProvider><ScorePanel matchId={currentMatch?.matchSelect} match={match}/></LoadingProvider>}
|
{currentMatch?.matchSelect &&
|
||||||
|
<LoadingProvider><ScorePanel matchId={currentMatch?.matchSelect} match={match} menuActions={menuActions}/></LoadingProvider>}
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
function ScorePanel({matchId, match}) {
|
function ScorePanel({matchId, match, menuActions}) {
|
||||||
|
const onClickVoid = useRef(() => {
|
||||||
|
});
|
||||||
|
|
||||||
|
return <div className="row" onClick={onClickVoid.current}>
|
||||||
|
<ScorePanel_ matchId={matchId} match={match} menuActions={menuActions} onClickVoid_={onClickVoid}/>
|
||||||
|
<CardPanel matchId={matchId} match={match}/>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
function ScorePanel_({matchId, match, menuActions, onClickVoid_}) {
|
||||||
const {sendRequest} = useWS()
|
const {sendRequest} = useWS()
|
||||||
const setLoading = useLoadingSwitcher()
|
const setLoading = useLoadingSwitcher()
|
||||||
|
|
||||||
@@ -335,6 +356,21 @@ function ScorePanel({matchId, match}) {
|
|||||||
const scoreRef = useRef([])
|
const scoreRef = useRef([])
|
||||||
const lastScoreClick = useRef(null)
|
const lastScoreClick = useRef(null)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
menuActions.current.saveScore = (scoreRed, scoreBlue) => {
|
||||||
|
const maxRound = (Math.max(...match.scores.map(s => s.n_round), -1) + 1) || 0;
|
||||||
|
const newScore = {n_round: maxRound, s1: scoreRed, s2: scoreBlue};
|
||||||
|
toast.promise(sendRequest('updateMatchScore', {matchId: matchId, ...newScore}),
|
||||||
|
{
|
||||||
|
pending: 'Sauvegarde du score...',
|
||||||
|
success: 'Score sauvegardé !',
|
||||||
|
error: 'Erreur lors de la sauvegarde du score'
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return () => menuActions.current.saveScore = undefined;
|
||||||
|
}, [matchId])
|
||||||
|
|
||||||
const handleScoreClick = (e, round, comb) => {
|
const handleScoreClick = (e, round, comb) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
const tableRect = tableRef.current.getBoundingClientRect();
|
const tableRect = tableRef.current.getBoundingClientRect();
|
||||||
@@ -402,6 +438,7 @@ function ScorePanel({matchId, match}) {
|
|||||||
sel.style.display = "none";
|
sel.style.display = "none";
|
||||||
lastScoreClick.current = null;
|
lastScoreClick.current = null;
|
||||||
}
|
}
|
||||||
|
onClickVoid_.current = onClickVoid;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!match || match?.end === end)
|
if (!match || match?.end === end)
|
||||||
@@ -447,64 +484,143 @@ function ScorePanel({matchId, match}) {
|
|||||||
"-999 : forfait"
|
"-999 : forfait"
|
||||||
|
|
||||||
const maxRound = (match?.scores) ? (Math.max(...match.scores.map(s => s.n_round), -1) + 1) : 0;
|
const maxRound = (match?.scores) ? (Math.max(...match.scores.map(s => s.n_round), -1) + 1) : 0;
|
||||||
return <div className="row" onClick={onClickVoid}>
|
return <div ref={tableRef} className="col" style={{position: "relative"}}>
|
||||||
<div ref={tableRef} className="col" style={{position: "relative"}}>
|
<h6>Scores <FontAwesomeIcon icon={faCircleQuestion} role="button" data-bs-toggle="tooltip" data-bs-placement="right" data-bs-title={tt}
|
||||||
<h6>Scores <FontAwesomeIcon icon={faCircleQuestion} role="button" data-bs-toggle="tooltip" data-bs-placement="right" data-bs-title={tt}
|
data-bs-html="true"/></h6>
|
||||||
data-bs-html="true"/></h6>
|
<table className="table table-striped">
|
||||||
<table className="table table-striped">
|
<thead>
|
||||||
<thead>
|
<tr>
|
||||||
<tr>
|
<th style={{textAlign: "center"}} scope="col">Manche</th>
|
||||||
<th style={{textAlign: "center"}} scope="col">Manche</th>
|
<th style={{textAlign: "center", minWidth: "4em"}} scope="col">Rouge</th>
|
||||||
<th style={{textAlign: "center", minWidth: "4em"}} scope="col">Rouge</th>
|
<th style={{textAlign: "center", minWidth: "4em"}} scope="col">Bleu</th>
|
||||||
<th style={{textAlign: "center", minWidth: "4em"}} scope="col">Bleu</th>
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody className="table-group-divider">
|
||||||
|
{match?.scores && match.scores.sort((a, b) => a.n_round - b.n_round).map(score => (
|
||||||
|
<tr key={score.n_round}>
|
||||||
|
<th style={{textAlign: "center"}}>{score.n_round + 1}</th>
|
||||||
|
<td style={{textAlign: "center"}} ref={e => scoreRef.current[score.n_round * 2] = e}
|
||||||
|
onClick={e => handleScoreClick(e, score.n_round, 1)}>{scorePrint(score.s1)}</td>
|
||||||
|
<td style={{textAlign: "center"}} ref={e => scoreRef.current[score.n_round * 2 + 1] = e}
|
||||||
|
onClick={e => handleScoreClick(e, score.n_round, 2)}>{scorePrint(score.s2)}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
))}
|
||||||
<tbody className="table-group-divider">
|
<tr>
|
||||||
{match?.scores && match.scores.sort((a, b) => a.n_round - b.n_round).map(score => (
|
<th style={{textAlign: "center"}}></th>
|
||||||
<tr key={score.n_round}>
|
<td style={{textAlign: "center"}} ref={e => scoreRef.current[maxRound * 2] = e} onClick={e => handleScoreClick(e, -1, 1)}>-</td>
|
||||||
<th style={{textAlign: "center"}}>{score.n_round + 1}</th>
|
<td style={{textAlign: "center"}} ref={e => scoreRef.current[maxRound * 2 + 1] = e} onClick={e => handleScoreClick(e, -1, 2)}>-
|
||||||
<td style={{textAlign: "center"}} ref={e => scoreRef.current[score.n_round * 2] = e}
|
</td>
|
||||||
onClick={e => handleScoreClick(e, score.n_round, 1)}>{scorePrint(score.s1)}</td>
|
</tr>
|
||||||
<td style={{textAlign: "center"}} ref={e => scoreRef.current[score.n_round * 2 + 1] = e}
|
</tbody>
|
||||||
onClick={e => handleScoreClick(e, score.n_round, 2)}>{scorePrint(score.s2)}</td>
|
</table>
|
||||||
</tr>
|
<div style={{textAlign: "right"}}>
|
||||||
))}
|
<div className="form-check" style={{display: "inline-block"}}>
|
||||||
<tr>
|
<input className="form-check-input" type="checkbox" id="checkboxEnd" name="checkboxEnd" checked={end}
|
||||||
<th style={{textAlign: "center"}}></th>
|
onChange={e => setEnd(e.target.checked)}/>
|
||||||
<td style={{textAlign: "center"}} ref={e => scoreRef.current[maxRound * 2] = e} onClick={e => handleScoreClick(e, -1, 1)}>-</td>
|
<label className="form-check-label" htmlFor="checkboxEnd">Terminé</label>
|
||||||
<td style={{textAlign: "center"}} ref={e => scoreRef.current[maxRound * 2 + 1] = e} onClick={e => handleScoreClick(e, -1, 2)}>-
|
</div>
|
||||||
</td>
|
</div>
|
||||||
</tr>
|
<input ref={inputRef} type="number" className="form-control" style={{position: "absolute", top: 0, left: 0, display: "none"}} min="-999"
|
||||||
</tbody>
|
max="999"
|
||||||
</table>
|
value={scoreIn} onChange={e => setScoreIn(e.target.value)}
|
||||||
<div style={{textAlign: "right"}}>
|
onClick={e => e.stopPropagation()}
|
||||||
<div className="form-check" style={{display: "inline-block"}}>
|
onKeyDown={e => {
|
||||||
<input className="form-check-input" type="checkbox" id="checkboxEnd" name="checkboxEnd" checked={end}
|
if (e.key === "Tab") {
|
||||||
onChange={e => setEnd(e.target.checked)}/>
|
if (lastScoreClick.current !== null) {
|
||||||
<label className="form-check-label" htmlFor="checkboxEnd">Terminé</label>
|
const {round, comb} = lastScoreClick.current;
|
||||||
|
const nextIndex = (round * 2 + (comb - 1)) + (e.shiftKey ? -1 : 1);
|
||||||
|
if (nextIndex >= 0 && nextIndex < scoreRef.current.length) {
|
||||||
|
e.preventDefault();
|
||||||
|
scoreRef.current[nextIndex].click();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (e.key === "Enter") {
|
||||||
|
e.preventDefault();
|
||||||
|
onClickVoid();
|
||||||
|
}
|
||||||
|
}}/>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
function CardPanel({matchId, match}) {
|
||||||
|
const {sendRequest, dispatch} = useWS();
|
||||||
|
const setLoading = useLoadingSwitcher()
|
||||||
|
|
||||||
|
const {data, refresh} = useRequestWS('getCardboardWithoutThis', matchId, setLoading);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
refresh('getCardboardWithoutThis', matchId);
|
||||||
|
|
||||||
|
const sendCardboard = ({data}) => {
|
||||||
|
if (data.comb_id === match.c1 || data.comb_id === match.c2) {
|
||||||
|
refresh('getCardboardWithoutThis', matchId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dispatch({type: 'addListener', payload: {callback: sendCardboard, code: 'sendCardboard'}})
|
||||||
|
return () => dispatch({type: 'removeListener', payload: sendCardboard})
|
||||||
|
}, [matchId])
|
||||||
|
|
||||||
|
if (!match) {
|
||||||
|
return <div className="col"></div>
|
||||||
|
}
|
||||||
|
|
||||||
|
const c1Cards = match.cardboard?.find(c => c.comb_id === match.c1) || {red: 0, yellow: 0};
|
||||||
|
const c2Cards = match.cardboard?.find(c => c.comb_id === match.c2) || {red: 0, yellow: 0};
|
||||||
|
|
||||||
|
const handleCard = (combId, yellow, red) => {
|
||||||
|
if (combId === match.c1) {
|
||||||
|
if (c1Cards.red + red < 0 || c1Cards.yellow + yellow < 0)
|
||||||
|
return;
|
||||||
|
} else if (combId === match.c2) {
|
||||||
|
if (c2Cards.red + red < 0 || c2Cards.yellow + yellow < 0)
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setLoading(1)
|
||||||
|
sendRequest('sendCardboardChange', {matchId, combId, yellow, red})
|
||||||
|
.finally(() => {
|
||||||
|
setLoading(0)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return <div className="col">
|
||||||
|
<h6>Carton</h6>
|
||||||
|
<div className="bg-danger-subtle text-danger-emphasis" style={{padding: ".25em", borderRadius: "1em 1em 0 0"}}>
|
||||||
|
<div>Competition: <span className="badge text-bg-danger">{(data?.c1_red || 0) + c1Cards.red}</span> <span
|
||||||
|
className="badge text-bg-warning">{(data?.c1_yellow || 0) + c1Cards.yellow}</span></div>
|
||||||
|
<div className="d-flex justify-content-center align-items-center" style={{margin: ".25em"}}>
|
||||||
|
Match:
|
||||||
|
<div className="d-flex flex-column" style={{marginLeft: ".25em"}}>
|
||||||
|
<button className="col btn btn-xs btn-danger" onClick={__ => handleCard(match.c1, 0, +1)}>+</button>
|
||||||
|
<span className="badge text-bg-danger">{c1Cards.red}</span>
|
||||||
|
<button className="col btn btn-xs btn-danger" onClick={__ => handleCard(match.c1, 0, -1)}>-</button>
|
||||||
|
</div>
|
||||||
|
<div className="d-flex flex-column" style={{marginLeft: ".25em"}}>
|
||||||
|
<button className="col btn btn-xs btn-warning" onClick={__ => handleCard(match.c1, +1, 0)}>+</button>
|
||||||
|
<span className="badge text-bg-warning">{c1Cards.yellow}</span>
|
||||||
|
<button className="col btn btn-xs btn-warning" onClick={__ => handleCard(match.c1, -1, 0)}>-</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<input ref={inputRef} type="number" className="form-control" style={{position: "absolute", top: 0, left: 0, display: "none"}} min="-999"
|
|
||||||
max="999"
|
|
||||||
value={scoreIn} onChange={e => setScoreIn(e.target.value)}
|
|
||||||
onClick={e => e.stopPropagation()}
|
|
||||||
onKeyDown={e => {
|
|
||||||
if (e.key === "Tab") {
|
|
||||||
if (lastScoreClick.current !== null) {
|
|
||||||
const {round, comb} = lastScoreClick.current;
|
|
||||||
const nextIndex = (round * 2 + (comb - 1)) + (e.shiftKey ? -1 : 1);
|
|
||||||
if (nextIndex >= 0 && nextIndex < scoreRef.current.length) {
|
|
||||||
e.preventDefault();
|
|
||||||
scoreRef.current[nextIndex].click();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (e.key === "Enter") {
|
|
||||||
e.preventDefault();
|
|
||||||
onClickVoid();
|
|
||||||
}
|
|
||||||
}}/>
|
|
||||||
</div>
|
</div>
|
||||||
<div className="col">
|
<div className="bg-info-subtle text-info-emphasis" style={{padding: ".25em", borderRadius: "0 0 1em 1em"}}>
|
||||||
|
<div>Competition: <span className="badge text-bg-danger">{(data?.c2_red || 0) + c2Cards.red}</span> <span
|
||||||
|
className="badge text-bg-warning">{(data?.c2_yellow || 0) + c2Cards.yellow}</span></div>
|
||||||
|
<div className="d-flex justify-content-center align-items-center" style={{margin: ".25em"}}>
|
||||||
|
Match:
|
||||||
|
<div className="d-flex flex-column" style={{marginLeft: ".25em"}}>
|
||||||
|
<button className="col btn btn-xs btn-danger" onClick={__ => handleCard(match.c2, 0, +1)}>+</button>
|
||||||
|
<span className="badge text-bg-danger">{c2Cards.red}</span>
|
||||||
|
<button className="col btn btn-xs btn-danger" onClick={__ => handleCard(match.c2, 0, -1)}>-</button>
|
||||||
|
</div>
|
||||||
|
<div className="d-flex flex-column" style={{marginLeft: ".25em"}}>
|
||||||
|
<button className="col btn btn-xs btn-warning" onClick={__ => handleCard(match.c2, +1, 0)}>+</button>
|
||||||
|
<span className="badge text-bg-warning">{c2Cards.yellow}</span>
|
||||||
|
<button className="col btn btn-xs btn-warning" onClick={__ => handleCard(match.c2, -1, 0)}>-</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|||||||
51
src/main/webapp/src/pages/competition/editor/CMTPoint.jsx
Normal file
51
src/main/webapp/src/pages/competition/editor/CMTPoint.jsx
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
import {useEffect, useState} from "react";
|
||||||
|
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
|
||||||
|
import {faChevronDown, faChevronUp} from "@fortawesome/free-solid-svg-icons";
|
||||||
|
import {usePubAffDispatch} from "../../../hooks/useExternalWindow.jsx";
|
||||||
|
|
||||||
|
export function PointPanel({menuActions}) {
|
||||||
|
const [revers, setRevers] = useState(false)
|
||||||
|
const [scoreRouge, setScoreRouge] = useState(0)
|
||||||
|
const [scoreBleu, setScoreBleu] = useState(0)
|
||||||
|
const publicAffDispatch = usePubAffDispatch()
|
||||||
|
|
||||||
|
menuActions.current.switchSore = () => {
|
||||||
|
setRevers(!revers)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSave = () => {
|
||||||
|
menuActions.current.saveScore?.(scoreRouge, scoreBleu)
|
||||||
|
handleReset();
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleReset = () => {
|
||||||
|
setScoreRouge(0);
|
||||||
|
setScoreBleu(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
publicAffDispatch({type: 'SET_DATA', payload: {scoreRouge: scoreRouge, scoreBleu: scoreBleu}})
|
||||||
|
}, [scoreRouge, scoreBleu])
|
||||||
|
|
||||||
|
const red =
|
||||||
|
<div className="col-5 row align-items-center" style={{padding: "0 1em"}}>
|
||||||
|
<button className="btn btn-secondary" onClick={() => setScoreRouge(scoreRouge + 1)}><FontAwesomeIcon icon={faChevronUp}/></button>
|
||||||
|
<h1 style={{color: "red", fontSize: "min(15vw, 7em)", textAlign: "center"}}>{scoreRouge}</h1>
|
||||||
|
<button className="btn btn-secondary" onClick={() => setScoreRouge(scoreRouge - 1)}><FontAwesomeIcon icon={faChevronDown}/></button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
return <div className="row">
|
||||||
|
{!revers && red}
|
||||||
|
<div className="col-5 row align-items-center" style={{padding: "0 1em"}}>
|
||||||
|
<button className="btn btn-secondary" onClick={() => setScoreBleu(scoreBleu + 1)}><FontAwesomeIcon icon={faChevronUp}/></button>
|
||||||
|
<h1 style={{color: "blue", fontSize: "min(15vw, 7em)", textAlign: "center"}}>{scoreBleu}</h1>
|
||||||
|
<button className="btn btn-secondary" onClick={() => setScoreBleu(scoreBleu - 1)}><FontAwesomeIcon icon={faChevronDown}/></button>
|
||||||
|
</div>
|
||||||
|
{revers && red}
|
||||||
|
|
||||||
|
<div className="col row align-items-center">
|
||||||
|
<button className="btn btn-danger" onClick={handleReset}>Réinitialiser</button>
|
||||||
|
<button className="btn btn-success" onClick={handleSave}>Sauvegarder</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
@@ -5,15 +5,17 @@ import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
|
|||||||
import {createPortal} from "react-dom";
|
import {createPortal} from "react-dom";
|
||||||
import {copyStyles} from "../../../utils/copyStyles.js";
|
import {copyStyles} from "../../../utils/copyStyles.js";
|
||||||
import {PubAffProvider, usePubAffDispatch} from "../../../hooks/useExternalWindow.jsx";
|
import {PubAffProvider, usePubAffDispatch} from "../../../hooks/useExternalWindow.jsx";
|
||||||
import {faDisplay} from "@fortawesome/free-solid-svg-icons";
|
import {faArrowRightArrowLeft, faDisplay} from "@fortawesome/free-solid-svg-icons";
|
||||||
import {PubAffWindow} from "./PubAffWindow.jsx";
|
import {PubAffWindow} from "./PubAffWindow.jsx";
|
||||||
import {SimpleIconsScore} from "../../../assets/SimpleIconsScore.ts";
|
import {SimpleIconsScore} from "../../../assets/SimpleIconsScore.ts";
|
||||||
import {ChronoPanel} from "./CMTChronoPanel.jsx";
|
import {ChronoPanel} from "./CMTChronoPanel.jsx";
|
||||||
import {CategorieSelect} from "./CMTMatchPanel.jsx";
|
import {CategorieSelect} from "./CMTMatchPanel.jsx";
|
||||||
|
import {PointPanel} from "./CMTPoint.jsx";
|
||||||
|
|
||||||
export function CMTable() {
|
export function CMTable() {
|
||||||
const combDispatch = useCombsDispatch()
|
const combDispatch = useCombsDispatch()
|
||||||
const [catId, setCatId] = useState(-1);
|
const [catId, setCatId] = useState(-1);
|
||||||
|
const menuActions = useRef({});
|
||||||
const {data} = useRequestWS("getRegister", null)
|
const {data} = useRequestWS("getRegister", null)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -32,15 +34,19 @@ export function CMTable() {
|
|||||||
<ChronoPanel/>
|
<ChronoPanel/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div style={{backgroundColor: "#0099c7"}}>
|
|
||||||
B
|
<div className="card mb-3">
|
||||||
|
<div className="card-header">Score</div>
|
||||||
|
<div className="card-body">
|
||||||
|
<PointPanel menuActions={menuActions}/>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="col-md-12 col-xl-6 col-xxl-5">
|
<div className="col-md-12 col-xl-6 col-xxl-5">
|
||||||
<div className="card mb-3">
|
<div className="card mb-3">
|
||||||
<div className="card-header">Matches</div>
|
<div className="card-header">Matches</div>
|
||||||
<div className="card-body">
|
<div className="card-body">
|
||||||
<CategorieSelect catId={catId} setCatId={setCatId}/>
|
<CategorieSelect catId={catId} setCatId={setCatId} menuActions={menuActions}/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div style={{backgroundColor: "#c70000"}}>
|
<div style={{backgroundColor: "#c70000"}}>
|
||||||
@@ -48,14 +54,16 @@ export function CMTable() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<Menu/>
|
<Menu menuActions={menuActions}/>
|
||||||
</div>
|
</div>
|
||||||
</PubAffProvider>
|
</PubAffProvider>
|
||||||
}
|
}
|
||||||
|
|
||||||
const windowName = "FFSAFScorePublicWindow";
|
const windowName = "FFSAFScorePublicWindow";
|
||||||
|
|
||||||
function Menu() {
|
let tto = [];
|
||||||
|
|
||||||
|
function Menu({menuActions}) {
|
||||||
const e = document.getElementById("actionMenu")
|
const e = document.getElementById("actionMenu")
|
||||||
const publicAffDispatch = usePubAffDispatch()
|
const publicAffDispatch = usePubAffDispatch()
|
||||||
const [showPubAff, setShowPubAff] = useState(false)
|
const [showPubAff, setShowPubAff] = useState(false)
|
||||||
@@ -96,22 +104,37 @@ function Menu() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const x of tto)
|
||||||
|
x.dispose();
|
||||||
|
const tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip2"]')
|
||||||
|
tto = [...tooltipTriggerList].map(tooltipTriggerEl => new bootstrap.Tooltip(tooltipTriggerEl))
|
||||||
|
|
||||||
const handleScore = __ => {
|
const handleScore = __ => {
|
||||||
setShowScore(!showScore);
|
setShowScore(!showScore);
|
||||||
publicAffDispatch({type: 'SET_DATA', payload: {showScore: !showScore}});
|
publicAffDispatch({type: 'SET_DATA', payload: {showScore: !showScore}});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleSwitchScore = () => {
|
||||||
|
menuActions.current.switchSore?.();
|
||||||
|
}
|
||||||
|
|
||||||
if (!e)
|
if (!e)
|
||||||
return <></>;
|
return <></>;
|
||||||
return <>
|
return <>
|
||||||
{createPortal(
|
{createPortal(
|
||||||
<>
|
<>
|
||||||
<div className="vr" style={{margin: "0 0.5em", height: "100%"}}></div>
|
<div className="vr" style={{margin: "0 0.5em", height: "100%"}}></div>
|
||||||
|
<FontAwesomeIcon icon={faArrowRightArrowLeft} size="xl" style={{color: "#6c757d", cursor: "pointer"}} onClick={handleSwitchScore}
|
||||||
|
data-bs-toggle="tooltip2" data-bs-placement="top"
|
||||||
|
data-bs-title="Inverser la position des combattants sur cette écran"/>
|
||||||
|
<div className="vr" style={{margin: "0 0.5em", height: "100%"}}></div>
|
||||||
<FontAwesomeIcon icon={faDisplay} size="xl"
|
<FontAwesomeIcon icon={faDisplay} size="xl"
|
||||||
style={{color: showPubAff ? "#00c700" : "#6c757d", cursor: "pointer", marginRight: "0.25em"}}
|
style={{color: showPubAff ? "#00c700" : "#6c757d", cursor: "pointer", marginRight: "0.25em"}}
|
||||||
onClick={handlePubAff}/>
|
onClick={handlePubAff}
|
||||||
|
data-bs-toggle="tooltip2" data-bs-placement="top" data-bs-title="Ouvrir l'affichage public"/>
|
||||||
<FontAwesomeIcon icon={SimpleIconsScore} size="xl" style={{color: showScore ? "#00c700" : "#6c757d", cursor: "pointer"}}
|
<FontAwesomeIcon icon={SimpleIconsScore} size="xl" style={{color: showScore ? "#00c700" : "#6c757d", cursor: "pointer"}}
|
||||||
onClick={handleScore}/>
|
onClick={handleScore}
|
||||||
|
data-bs-toggle="tooltip2" data-bs-placement="top" data-bs-title="Afficher les scores sur l'affichage public"/>
|
||||||
</>, document.getElementById("actionMenu"))}
|
</>, document.getElementById("actionMenu"))}
|
||||||
{externalWindow.current && createPortal(<PubAffWindow document={externalWindow.current.document}/>, containerEl.current)}
|
{externalWindow.current && createPortal(<PubAffWindow document={externalWindow.current.document}/>, containerEl.current)}
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
import {Route, Routes, useNavigate, useParams} from "react-router-dom";
|
import {Route, Routes, useNavigate, useParams} from "react-router-dom";
|
||||||
import {LoadingProvider} from "../../../hooks/useLoading.jsx";
|
import {LoadingProvider, useLoadingSwitcher} from "../../../hooks/useLoading.jsx";
|
||||||
import {useEffect, useState} from "react";
|
import {useEffect, useState} from "react";
|
||||||
import {useWS, WSProvider} from "../../../hooks/useWS.jsx";
|
import {useWS, WSProvider} from "../../../hooks/useWS.jsx";
|
||||||
import {ColoredCircle} from "../../../components/ColoredCircle.jsx";
|
import {ColoredCircle} from "../../../components/ColoredCircle.jsx";
|
||||||
import {CMAdmin} from "./CMAdmin.jsx";
|
import {CMAdmin} from "./CMAdmin.jsx";
|
||||||
import {CombsProvider} from "../../../hooks/useComb.jsx";
|
import {CombsProvider} from "../../../hooks/useComb.jsx";
|
||||||
import {CMTable} from "./CMTable.jsx";
|
import {CMTable} from "./CMTable.jsx";
|
||||||
|
import {ThreeDots} from "react-loader-spinner";
|
||||||
|
import {AxiosError} from "../../../components/AxiosError.jsx";
|
||||||
|
import {useFetch} from "../../../hooks/useFetch.js";
|
||||||
|
|
||||||
const vite_url = import.meta.env.VITE_URL;
|
const vite_url = import.meta.env.VITE_URL;
|
||||||
|
|
||||||
@@ -22,13 +25,33 @@ export default function CompetitionManagerRoot() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function Home() {
|
function Home() {
|
||||||
const nav = useNavigate();
|
const navigate = useNavigate();
|
||||||
return <div>
|
const setLoading = useLoadingSwitcher()
|
||||||
<h2>Home</h2>
|
const {data, error} = useFetch(`/competition/admin/all/INTERNAL/table`, setLoading, 1)
|
||||||
<button onClick={() => nav("d3dc76a6-2058-423a-b34b-6d15d7ae5848")}>Go comp</button>
|
|
||||||
|
return <div className="row">
|
||||||
|
{data
|
||||||
|
? <MakeCentralPanel data={data} navigate={navigate}/>
|
||||||
|
: error
|
||||||
|
? <AxiosError error={error}/>
|
||||||
|
: <Def/>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function MakeCentralPanel({data, navigate}) {
|
||||||
|
return <>
|
||||||
|
<div className="mb-4">
|
||||||
|
<h4>Compétition:</h4>
|
||||||
|
<div className="list-group">
|
||||||
|
{data.sort((a, b) => new Date(b.date.split('T')[0]) - new Date(a.date.split('T')[0])).map((o) => (
|
||||||
|
<li className="list-group-item list-group-item-action" key={o.id}
|
||||||
|
onClick={__ => navigate(o.uuid)}>{o.name}</li>))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
|
||||||
function HomeComp() {
|
function HomeComp() {
|
||||||
let {compUuid} = useParams();
|
let {compUuid} = useParams();
|
||||||
const [perm, setPerm] = useState("")
|
const [perm, setPerm] = useState("")
|
||||||
@@ -98,11 +121,12 @@ function Home2({perm}) {
|
|||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
function Test2() {
|
function Def() {
|
||||||
let {compUuid} = useParams();
|
return <div className="list-group">
|
||||||
const nav = useNavigate();
|
<li className="list-group-item"><ThreeDots/></li>
|
||||||
return <div>
|
<li className="list-group-item"><ThreeDots/></li>
|
||||||
<h2>Product ID: {compUuid}</h2>
|
<li className="list-group-item"><ThreeDots/></li>
|
||||||
<button onClick={() => nav(-1)}>Go Back</button>
|
<li className="list-group-item"><ThreeDots/></li>
|
||||||
|
<li className="list-group-item"><ThreeDots/></li>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,12 +37,12 @@ export function PubAffWindow({document}) {
|
|||||||
{showScore &&
|
{showScore &&
|
||||||
<div className="row" style={noMP}>
|
<div className="row" style={noMP}>
|
||||||
<div className="col-4" style={noMP}>
|
<div className="col-4" style={noMP}>
|
||||||
<div style={{fontSize: "30vh", lineHeight: "30vh", color: "#ff1414"}}>0</div>
|
<div style={{fontSize: "30vh", lineHeight: "30vh", color: "#ff1414"}}>{state.scoreRouge}</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="col-4" style={noMP}>
|
<div className="col-4" style={noMP}>
|
||||||
</div>
|
</div>
|
||||||
<div className="col-4" style={noMP}>
|
<div className="col-4" style={noMP}>
|
||||||
<div style={{fontSize: "30vh", lineHeight: "30vh", color: "#14adff"}}>0</div>
|
<div style={{fontSize: "30vh", lineHeight: "30vh", color: "#14adff"}}>{state.scoreBleu}</div>
|
||||||
</div>
|
</div>
|
||||||
</div>}
|
</div>}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -36,6 +36,22 @@ export function MarchReducer(datas, action) {
|
|||||||
datas[index] = action.payload
|
datas[index] = action.payload
|
||||||
return [...datas]
|
return [...datas]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case 'UPDATE_CARDBOARD':
|
||||||
|
const idx = datas.findIndex(data => data.id === action.payload.match_id)
|
||||||
|
if (idx === -1)
|
||||||
|
return datas // Do nothing
|
||||||
|
const data = datas[idx]
|
||||||
|
const tmp = data.cardboard?.find(c => c.comb_id === action.payload.comb_id)
|
||||||
|
if (tmp) {
|
||||||
|
tmp.red = action.payload.red
|
||||||
|
tmp.yellow = action.payload.yellow
|
||||||
|
} else {
|
||||||
|
if (!data.cardboard)
|
||||||
|
data.cardboard = []
|
||||||
|
data.cardboard.push(action.payload)
|
||||||
|
}
|
||||||
|
return [...datas]
|
||||||
case 'SORT':
|
case 'SORT':
|
||||||
return datas.sort(action.payload)
|
return datas.sort(action.payload)
|
||||||
case 'REORDER':
|
case 'REORDER':
|
||||||
|
|||||||
Reference in New Issue
Block a user