feat: auto categories
This commit is contained in:
parent
8663aa61cf
commit
d43cdc1a4e
@ -47,7 +47,8 @@ public class CombEntity {
|
|||||||
return null;
|
return null;
|
||||||
|
|
||||||
return new CombEntity(model.getId() * -1, model.getLname(), model.getFname(), model.getCategorie(), null,
|
return new CombEntity(model.getId() * -1, model.getLname(), model.getFname(), model.getCategorie(), null,
|
||||||
model.getClub(), model.getGenre(), model.getCountry(), 0, model.getWeight(),
|
model.getClub(), model.getGenre(), model.getCountry(), 0,
|
||||||
|
model.getWeight2() != null ? model.getWeight2() : model.getWeight(),
|
||||||
Stream.concat(model.getComb().stream().map(CombEntity::fromModel),
|
Stream.concat(model.getComb().stream().map(CombEntity::fromModel),
|
||||||
model.getGuest().stream().map(CombEntity::fromModel)).toList(),
|
model.getGuest().stream().map(CombEntity::fromModel)).toList(),
|
||||||
new ArrayList<>());
|
new ArrayList<>());
|
||||||
@ -68,7 +69,8 @@ public class CombEntity {
|
|||||||
return new CombEntity(model.getId(), model.getLname(), model.getFname(), registerModel.getCategorie(),
|
return new CombEntity(model.getId(), model.getLname(), model.getFname(), registerModel.getCategorie(),
|
||||||
registerModel.getClub2() == null ? null : registerModel.getClub2().getClubId(),
|
registerModel.getClub2() == null ? null : registerModel.getClub2().getClubId(),
|
||||||
registerModel.getClub2() == null ? "Sans club" : registerModel.getClub2().getName(), model.getGenre(),
|
registerModel.getClub2() == null ? "Sans club" : registerModel.getClub2().getName(), model.getGenre(),
|
||||||
model.getCountry(), registerModel.getOverCategory(), registerModel.getWeight(), new ArrayList<>(),
|
model.getCountry(), registerModel.getOverCategory(),
|
||||||
new ArrayList<>());
|
registerModel.getWeight2() != null ? registerModel.getWeight2() : registerModel.getWeight(),
|
||||||
|
new ArrayList<>(), new ArrayList<>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -368,6 +368,9 @@ public class CompetitionService {
|
|||||||
return Panache.withTransaction(() -> repository.persist(c));
|
return Panache.withTransaction(() -> repository.persist(c));
|
||||||
})
|
})
|
||||||
.chain(combModel -> updateRegister(data, c, combModel, true, false)))
|
.chain(combModel -> updateRegister(data, c, combModel, true, false)))
|
||||||
|
.call(r -> r.getCompetition().getSystem() == CompetitionSystem.INTERNAL ?
|
||||||
|
sRegister.sendRegisterNoFetch(r.getCompetition().getUuid(), r) : Uni.createFrom()
|
||||||
|
.voidItem())
|
||||||
.map(r -> SimpleRegisterComb.fromModel(r, r.getMembre().getLicences())
|
.map(r -> SimpleRegisterComb.fromModel(r, r.getMembre().getLicences())
|
||||||
.setCategorieInscrite(r.getCategoriesInscrites()));
|
.setCategorieInscrite(r.getCategoriesInscrites()));
|
||||||
} else {
|
} else {
|
||||||
@ -406,8 +409,8 @@ public class CompetitionService {
|
|||||||
}))
|
}))
|
||||||
.chain(model -> Panache.withTransaction(() -> competitionGuestRepository.persist(model))
|
.chain(model -> Panache.withTransaction(() -> competitionGuestRepository.persist(model))
|
||||||
.call(r -> model.getCompetition().getSystem() == CompetitionSystem.INTERNAL ?
|
.call(r -> model.getCompetition().getSystem() == CompetitionSystem.INTERNAL ?
|
||||||
sRegister.sendRegister(model.getCompetition().getUuid(),
|
sRegister.sendRegisterNoFetch(model.getCompetition().getUuid(), r)
|
||||||
r) : Uni.createFrom().voidItem()))
|
: Uni.createFrom().voidItem()))
|
||||||
.map(g -> SimpleRegisterComb.fromModel(g).setCategorieInscrite(g.getCategoriesInscrites()));
|
.map(g -> SimpleRegisterComb.fromModel(g).setCategorieInscrite(g.getCategoriesInscrites()));
|
||||||
}
|
}
|
||||||
if ("club".equals(source))
|
if ("club".equals(source))
|
||||||
@ -428,6 +431,9 @@ public class CompetitionService {
|
|||||||
throw new DForbiddenException(trad.t("insc.err1"));
|
throw new DForbiddenException(trad.t("insc.err1"));
|
||||||
}))
|
}))
|
||||||
.chain(combModel -> updateRegister(data, c, combModel, false, false)))
|
.chain(combModel -> updateRegister(data, c, combModel, false, false)))
|
||||||
|
.call(r -> r.getCompetition().getSystem() == CompetitionSystem.INTERNAL ?
|
||||||
|
sRegister.sendRegisterNoFetch(r.getCompetition().getUuid(), r) : Uni.createFrom()
|
||||||
|
.voidItem())
|
||||||
.map(r -> SimpleRegisterComb.fromModel(r, r.getMembre().getLicences())
|
.map(r -> SimpleRegisterComb.fromModel(r, r.getMembre().getLicences())
|
||||||
.setCategorieInscrite(r.getCategoriesInscrites()));
|
.setCategorieInscrite(r.getCategoriesInscrites()));
|
||||||
|
|
||||||
@ -444,6 +450,8 @@ public class CompetitionService {
|
|||||||
throw new DForbiddenException(trad.t("insc.err2"));
|
throw new DForbiddenException(trad.t("insc.err2"));
|
||||||
}))
|
}))
|
||||||
.chain(combModel -> updateRegister(data, c, combModel, false, false)))
|
.chain(combModel -> updateRegister(data, c, combModel, false, false)))
|
||||||
|
.call(r -> r.getCompetition().getSystem() == CompetitionSystem.INTERNAL ?
|
||||||
|
sRegister.sendRegisterNoFetch(r.getCompetition().getUuid(), r) : Uni.createFrom().voidItem())
|
||||||
.map(r -> SimpleRegisterComb.fromModel(r, List.of()).setCategorieInscrite(r.getCategoriesInscrites()));
|
.map(r -> SimpleRegisterComb.fromModel(r, List.of()).setCategorieInscrite(r.getCategoriesInscrites()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -453,20 +461,21 @@ public class CompetitionService {
|
|||||||
if (!"admin".equals(source))
|
if (!"admin".equals(source))
|
||||||
return Uni.createFrom().failure(new DForbiddenException());
|
return Uni.createFrom().failure(new DForbiddenException());
|
||||||
|
|
||||||
return Multi.createFrom().iterable(datas).onItem().transformToUni(data ->
|
return permService.hasEditPerm(securityCtx, id)
|
||||||
makeImportUpdate(securityCtx, id, data).onFailure().recoverWithItem(t -> {
|
.chain(cm -> Multi.createFrom().iterable(datas).onItem().transformToUni(data ->
|
||||||
|
makeImportUpdate(cm, data).onFailure().recoverWithItem(t -> {
|
||||||
SimpleRegisterComb errorComb = new SimpleRegisterComb();
|
SimpleRegisterComb errorComb = new SimpleRegisterComb();
|
||||||
errorComb.setLicence(-42);
|
errorComb.setLicence(-42);
|
||||||
errorComb.setFname("ERROR");
|
errorComb.setFname("ERROR");
|
||||||
errorComb.setLname(t.getMessage());
|
errorComb.setLname(t.getMessage());
|
||||||
return errorComb;
|
return errorComb;
|
||||||
})).concatenate().collect().asList();
|
})).concatenate().collect().asList());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Uni<SimpleRegisterComb> makeImportUpdate(SecurityCtx securityCtx, Long id, RegisterRequestData data) {
|
@WithSession
|
||||||
|
public Uni<SimpleRegisterComb> makeImportUpdate(CompetitionModel c, RegisterRequestData data) {
|
||||||
if (data.getLicence() == null || data.getLicence() != -1) { // not a guest
|
if (data.getLicence() == null || data.getLicence() != -1) { // not a guest
|
||||||
return permService.hasEditPerm(securityCtx, id)
|
return findComb(data.getLicence(), data.getFname(), data.getLname())
|
||||||
.chain(c -> findComb(data.getLicence(), data.getFname(), data.getLname())
|
|
||||||
.call(combModel -> Mutiny.fetch(combModel.getLicences()))
|
.call(combModel -> Mutiny.fetch(combModel.getLicences()))
|
||||||
.call(combModel -> {
|
.call(combModel -> {
|
||||||
if (c.getBanMembre() == null)
|
if (c.getBanMembre() == null)
|
||||||
@ -474,12 +483,11 @@ public class CompetitionService {
|
|||||||
c.getBanMembre().remove(combModel.getId());
|
c.getBanMembre().remove(combModel.getId());
|
||||||
return Panache.withTransaction(() -> repository.persist(c));
|
return Panache.withTransaction(() -> repository.persist(c));
|
||||||
})
|
})
|
||||||
.chain(combModel -> updateRegister(data, c, combModel, true, true)))
|
.chain(combModel -> updateRegister(data, c, combModel, true, true))
|
||||||
.map(r -> SimpleRegisterComb.fromModel(r, r.getMembre().getLicences())
|
.map(r -> SimpleRegisterComb.fromModel(r, r.getMembre().getLicences())
|
||||||
.setCategorieInscrite(r.getCategoriesInscrites()));
|
.setCategorieInscrite(r.getCategoriesInscrites()));
|
||||||
} else {
|
} else {
|
||||||
return permService.hasEditPerm(securityCtx, id)
|
return findGuestOrInit(data.getFname(), data.getLname(), c)
|
||||||
.chain(c -> findGuestOrInit(data.getFname(), data.getLname(), c))
|
|
||||||
.invoke(Unchecked.consumer(model -> {
|
.invoke(Unchecked.consumer(model -> {
|
||||||
if (data.getCategorie() == null)
|
if (data.getCategorie() == null)
|
||||||
throw new DBadRequestException(trad.t("categorie.requise"));
|
throw new DBadRequestException(trad.t("categorie.requise"));
|
||||||
@ -503,13 +511,13 @@ public class CompetitionService {
|
|||||||
} else
|
} else
|
||||||
model.setCountry(data.getCountry());
|
model.setCountry(data.getCountry());
|
||||||
|
|
||||||
if (model.getCompetition().getRequiredWeight().contains(model.getCategorie())) {
|
if (c.getRequiredWeight().contains(model.getCategorie())) {
|
||||||
if (data.getCountry() != null)
|
if (data.getCountry() != null)
|
||||||
model.setWeight(data.getWeight());
|
model.setWeight(data.getWeight());
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
.call(g -> Mutiny.fetch(g.getCategoriesInscrites()))
|
.call(g -> Mutiny.fetch(g.getCategoriesInscrites()))
|
||||||
.call(g -> catPresetRepository.list("competition = ?1 AND id IN ?2", g.getCompetition(),
|
.call(g -> catPresetRepository.list("competition = ?1 AND id IN ?2", c,
|
||||||
data.getCategoriesInscrites())
|
data.getCategoriesInscrites())
|
||||||
.invoke(cats -> {
|
.invoke(cats -> {
|
||||||
g.getCategoriesInscrites().clear();
|
g.getCategoriesInscrites().clear();
|
||||||
@ -518,9 +526,8 @@ public class CompetitionService {
|
|||||||
.noneMatch(e -> e.getCategorie().equals(g.getCategorie())));
|
.noneMatch(e -> e.getCategorie().equals(g.getCategorie())));
|
||||||
}))
|
}))
|
||||||
.chain(model -> Panache.withTransaction(() -> competitionGuestRepository.persist(model))
|
.chain(model -> Panache.withTransaction(() -> competitionGuestRepository.persist(model))
|
||||||
.call(r -> model.getCompetition().getSystem() == CompetitionSystem.INTERNAL ?
|
.call(r -> c.getSystem() == CompetitionSystem.INTERNAL ?
|
||||||
sRegister.sendRegister(model.getCompetition().getUuid(),
|
sRegister.sendRegister(c.getUuid(), r) : Uni.createFrom().voidItem()))
|
||||||
r) : Uni.createFrom().voidItem()))
|
|
||||||
.map(g -> SimpleRegisterComb.fromModel(g).setCategorieInscrite(g.getCategoriesInscrites()));
|
.map(g -> SimpleRegisterComb.fromModel(g).setCategorieInscrite(g.getCategoriesInscrites()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -117,7 +117,13 @@ public class RCategorie {
|
|||||||
categoryModel.setTree(new ArrayList<>());
|
categoryModel.setTree(new ArrayList<>());
|
||||||
categoryModel.setType(categorie.type);
|
categoryModel.setType(categorie.type);
|
||||||
categoryModel.setLiceName(categorie.liceName);
|
categoryModel.setLiceName(categorie.liceName);
|
||||||
|
categoryModel.setTreeAreClassement(categorie.treeAreClassement);
|
||||||
|
categoryModel.setFullClassement(categorie.fullClassement);
|
||||||
|
|
||||||
|
if (categorie.preset() != null)
|
||||||
|
return catPresetRepository.findById(categorie.preset().getId())
|
||||||
|
.invoke(categoryModel::setPreset)
|
||||||
|
.chain(__ -> categoryRepository.create(categoryModel));
|
||||||
return categoryRepository.create(categoryModel);
|
return categoryRepository.create(categoryModel);
|
||||||
})
|
})
|
||||||
.invoke(cat -> SSCategorie.sendAddCategory(connection, cat))
|
.invoke(cat -> SSCategorie.sendAddCategory(connection, cat))
|
||||||
|
|||||||
@ -40,6 +40,16 @@ public class SRegister {
|
|||||||
.chain(cardModels -> send(uuid, "sendCards", cardModels))));
|
.chain(cardModels -> send(uuid, "sendCards", cardModels))));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Uni<Void> sendRegisterNoFetch(String uuid, RegisterModel registerModel) {
|
||||||
|
return send(uuid, "sendRegister",
|
||||||
|
CombEntity.fromModel(registerModel).addCategoriesInscrites(registerModel.getCategoriesInscrites()))
|
||||||
|
.call(__ -> registerModel.getClub2() == null ? Uni.createFrom().voidItem() :
|
||||||
|
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) {
|
public Uni<Void> sendRegister(String uuid, CompetitionGuestModel model) {
|
||||||
return Mutiny.fetch(model.getCategoriesInscrites()).chain(o ->
|
return Mutiny.fetch(model.getCategoriesInscrites()).chain(o ->
|
||||||
send(uuid, "sendRegister", CombEntity.fromModel(model).addCategoriesInscrites(o))
|
send(uuid, "sendRegister", CombEntity.fromModel(model).addCategoriesInscrites(o))
|
||||||
@ -48,6 +58,14 @@ public class SRegister {
|
|||||||
.chain(cardModels -> send(uuid, "sendCards", cardModels))));
|
.chain(cardModels -> send(uuid, "sendCards", cardModels))));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Uni<Void> sendRegisterNoFetch(String uuid, CompetitionGuestModel model) {
|
||||||
|
return send(uuid, "sendRegister",
|
||||||
|
CombEntity.fromModel(model).addCategoriesInscrites(model.getCategoriesInscrites()))
|
||||||
|
.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) {
|
public Uni<Void> sendRegisterRemove(String uuid, Long combId) {
|
||||||
return send(uuid, "sendRegisterRemove", combId)
|
return send(uuid, "sendRegisterRemove", combId)
|
||||||
.call(__ -> cardService.rmTeamCardFromComb(combId, uuid));
|
.call(__ -> cardService.rmTeamCardFromComb(combId, uuid));
|
||||||
|
|||||||
@ -23,7 +23,9 @@
|
|||||||
"cartonNoir": "Black card",
|
"cartonNoir": "Black card",
|
||||||
"cartonRouge": "Red card",
|
"cartonRouge": "Red card",
|
||||||
"catégorie": "Category",
|
"catégorie": "Category",
|
||||||
|
"catégoriesVontêtreCréées": "weight categories will be created",
|
||||||
"ceCartonEstIssuDunCartonDéquipe": "This card comes from a team card, do you really want to delete it?",
|
"ceCartonEstIssuDunCartonDéquipe": "This card comes from a team card, do you really want to delete it?",
|
||||||
|
"certainsCombattantsNontPasDePoidsRenseigné": "Some fighters do not have a weight listed; they will NOT be included in the categories.",
|
||||||
"chrono.+/-...S": "+/- ... s",
|
"chrono.+/-...S": "+/- ... s",
|
||||||
"chrono.+10S": "+10 s",
|
"chrono.+10S": "+10 s",
|
||||||
"chrono.+1S": "+1 s",
|
"chrono.+1S": "+1 s",
|
||||||
@ -58,11 +60,15 @@
|
|||||||
"conserverUniquementLesMatchsTerminés": "Keep only finished matches",
|
"conserverUniquementLesMatchsTerminés": "Keep only finished matches",
|
||||||
"contre": "vs",
|
"contre": "vs",
|
||||||
"couleur": "Color",
|
"couleur": "Color",
|
||||||
|
"créationDeLaLesCatégories": "Creating the category(ies)",
|
||||||
|
"créerLaPhaseFinaleSilYADesPoules": "Create the final phase if there are groups.",
|
||||||
"créerLesMatchesDeClassement": "Create the ranking matches",
|
"créerLesMatchesDeClassement": "Create the ranking matches",
|
||||||
"créerLesMatchesDeClassement.msg": "Ranking matches have already been set up/played; recreating these matches will delete them all (you will therefore lose any results). Please note down any information you wish to keep.",
|
"créerLesMatchesDeClassement.msg": "Ranking matches have already been set up/played; recreating these matches will delete them all (you will therefore lose any results). Please note down any information you wish to keep.",
|
||||||
"créerLesMatchs": "Create matches",
|
"créerLesMatchs": "Create matches",
|
||||||
|
"créerToutesLesCatégories": "Create all categories",
|
||||||
"date": "Date",
|
"date": "Date",
|
||||||
"demi-finalesEtFinales": "Semi-finals and finals",
|
"demi-finalesEtFinales": "Semi-finals and finals",
|
||||||
|
"depuisUneCatégoriePrédéfinie": "From a predefined category",
|
||||||
"duréePause": "Pause duration",
|
"duréePause": "Pause duration",
|
||||||
"duréeRound": "Round duration",
|
"duréeRound": "Round duration",
|
||||||
"editionDeLaCatégorie": "Edit category",
|
"editionDeLaCatégorie": "Edit category",
|
||||||
@ -88,11 +94,13 @@
|
|||||||
"inscrit": "Registered",
|
"inscrit": "Registered",
|
||||||
"leTournoiServiraDePhaseFinaleAuxPoules": "The tournament will serve as the final phase for the group stage.",
|
"leTournoiServiraDePhaseFinaleAuxPoules": "The tournament will serve as the final phase for the group stage.",
|
||||||
"lesCombattantsEnDehors": "Fighters not participating in the tournament will have a ranking match.",
|
"lesCombattantsEnDehors": "Fighters not participating in the tournament will have a ranking match.",
|
||||||
|
"lesCombattantsEnDehors2": "Fighters outside the ranking tournament will have a ranking match",
|
||||||
"listeDesCartons": "List of cards",
|
"listeDesCartons": "List of cards",
|
||||||
"manche": "Round",
|
"manche": "Round",
|
||||||
"matchPourLesPerdantsDuTournoi": "Match for tournament losers:",
|
"matchPourLesPerdantsDuTournoi": "Match for tournament losers:",
|
||||||
"matchTerminé": "Match over",
|
"matchTerminé": "Match over",
|
||||||
"matches": "Matches",
|
"matches": "Matches",
|
||||||
|
"modeDeCréation": "Creation method",
|
||||||
"modifier": "Edit",
|
"modifier": "Edit",
|
||||||
"msg1": "There are already matches in this pool; what do you want to do with them?",
|
"msg1": "There are already matches in this pool; what do you want to do with them?",
|
||||||
"neRienConserver": "Keep nothing",
|
"neRienConserver": "Keep nothing",
|
||||||
@ -105,6 +113,7 @@
|
|||||||
"nouvelle...": "New...",
|
"nouvelle...": "New...",
|
||||||
"obs.préfixDesSources": "Source prefix",
|
"obs.préfixDesSources": "Source prefix",
|
||||||
"pays": "Country",
|
"pays": "Country",
|
||||||
|
"personnaliser": "Personalize",
|
||||||
"poids": "Weight",
|
"poids": "Weight",
|
||||||
"poule": "Pool",
|
"poule": "Pool",
|
||||||
"poulePour": "Pool for: ",
|
"poulePour": "Pool for: ",
|
||||||
|
|||||||
@ -23,7 +23,9 @@
|
|||||||
"cartonNoir": "Carton noir",
|
"cartonNoir": "Carton noir",
|
||||||
"cartonRouge": "Carton rouge",
|
"cartonRouge": "Carton rouge",
|
||||||
"catégorie": "Catégorie",
|
"catégorie": "Catégorie",
|
||||||
|
"catégoriesVontêtreCréées": "catégories de poids vont être créées",
|
||||||
"ceCartonEstIssuDunCartonDéquipe": "Ce carton est issu d'un carton d'équipe, voulez-vous vraiment le supprimer ?",
|
"ceCartonEstIssuDunCartonDéquipe": "Ce carton est issu d'un carton d'équipe, voulez-vous vraiment le supprimer ?",
|
||||||
|
"certainsCombattantsNontPasDePoidsRenseigné": "Certains combattants n'ont pas de poids renseigné, ils ne seront PAS insert dans les catégories",
|
||||||
"chrono.+/-...S": "+/- ... s",
|
"chrono.+/-...S": "+/- ... s",
|
||||||
"chrono.+10S": "+10 s",
|
"chrono.+10S": "+10 s",
|
||||||
"chrono.+1S": "+1 s",
|
"chrono.+1S": "+1 s",
|
||||||
@ -38,7 +40,7 @@
|
|||||||
"chronomètre": "Chronomètre",
|
"chronomètre": "Chronomètre",
|
||||||
"classement": "Classement",
|
"classement": "Classement",
|
||||||
"club": "Club",
|
"club": "Club",
|
||||||
"combattantsCorrespondentAuxSélectionnés": "combattant(s) correspondent aux sélectionnés ci-dessus.",
|
"combattantsCorrespondentAuxSélectionnés": "combattant(s) correspondent aux sélections ci-dessus.",
|
||||||
"compétition": "Compétition",
|
"compétition": "Compétition",
|
||||||
"compétitionManager": "Compétition manager",
|
"compétitionManager": "Compétition manager",
|
||||||
"config.obs.dossierDesResources": "Dossier des resources",
|
"config.obs.dossierDesResources": "Dossier des resources",
|
||||||
@ -58,11 +60,15 @@
|
|||||||
"conserverUniquementLesMatchsTerminés": "Conserver uniquement les matchs terminés",
|
"conserverUniquementLesMatchsTerminés": "Conserver uniquement les matchs terminés",
|
||||||
"contre": "contre",
|
"contre": "contre",
|
||||||
"couleur": "Couleur",
|
"couleur": "Couleur",
|
||||||
|
"créationDeLaLesCatégories": "Création de la/les catégories",
|
||||||
|
"créerLaPhaseFinaleSilYADesPoules": "Créer la phase finale s'il y a des poules",
|
||||||
"créerLesMatchesDeClassement": "Créer les matches de classement",
|
"créerLesMatchesDeClassement": "Créer les matches de classement",
|
||||||
"créerLesMatchesDeClassement.msg": "Des matches de classement ont déjà été configurer/jouer, la recréation de ces matches vont tous les supprimer (vous perdre donc les résultats s'il y en a). Mercie de noter de votre côté les informations que vous voulez conserver.",
|
"créerLesMatchesDeClassement.msg": "Des matches de classement ont déjà été configurer/jouer, la recréation de ces matches vont tous les supprimer (vous perdre donc les résultats s'il y en a). Mercie de noter de votre côté les informations que vous voulez conserver.",
|
||||||
"créerLesMatchs": "Créer les matchs",
|
"créerLesMatchs": "Créer les matchs",
|
||||||
|
"créerToutesLesCatégories": "Créer toutes les catégories",
|
||||||
"date": "Date",
|
"date": "Date",
|
||||||
"demi-finalesEtFinales": "Demi-finales et finales",
|
"demi-finalesEtFinales": "Demi-finales et finales",
|
||||||
|
"depuisUneCatégoriePrédéfinie": "Depuis une catégorie prédéfinie",
|
||||||
"duréePause": "Durée pause",
|
"duréePause": "Durée pause",
|
||||||
"duréeRound": "Durée round",
|
"duréeRound": "Durée round",
|
||||||
"editionDeLaCatégorie": "Edition de la catégorie",
|
"editionDeLaCatégorie": "Edition de la catégorie",
|
||||||
@ -88,11 +94,13 @@
|
|||||||
"inscrit": "Inscrit",
|
"inscrit": "Inscrit",
|
||||||
"leTournoiServiraDePhaseFinaleAuxPoules": "Le tournoi servira de phase finale aux poules",
|
"leTournoiServiraDePhaseFinaleAuxPoules": "Le tournoi servira de phase finale aux poules",
|
||||||
"lesCombattantsEnDehors": "Les combattants en dehors du tournoi auront un match de classement",
|
"lesCombattantsEnDehors": "Les combattants en dehors du tournoi auront un match de classement",
|
||||||
|
"lesCombattantsEnDehors2": "Les combattants en dehors du tournoi de classement auront un match de classement",
|
||||||
"listeDesCartons": "Liste des cartons",
|
"listeDesCartons": "Liste des cartons",
|
||||||
"manche": "Manche",
|
"manche": "Manche",
|
||||||
"matchPourLesPerdantsDuTournoi": "Match pour les perdants du tournoi:",
|
"matchPourLesPerdantsDuTournoi": "Match pour les perdants du tournoi:",
|
||||||
"matchTerminé": "Match terminé",
|
"matchTerminé": "Match terminé",
|
||||||
"matches": "Matches",
|
"matches": "Matches",
|
||||||
|
"modeDeCréation": "Mode de création",
|
||||||
"modifier": "Modifier",
|
"modifier": "Modifier",
|
||||||
"msg1": "Il y a déjà des matchs dans cette poule, que voulez-vous faire avec ?",
|
"msg1": "Il y a déjà des matchs dans cette poule, que voulez-vous faire avec ?",
|
||||||
"neRienConserver": "Ne rien conserver",
|
"neRienConserver": "Ne rien conserver",
|
||||||
@ -105,6 +113,7 @@
|
|||||||
"nouvelle...": "Nouvelle...",
|
"nouvelle...": "Nouvelle...",
|
||||||
"obs.préfixDesSources": "Préfix des sources",
|
"obs.préfixDesSources": "Préfix des sources",
|
||||||
"pays": "Pays",
|
"pays": "Pays",
|
||||||
|
"personnaliser": "Personnaliser",
|
||||||
"poids": "Poids",
|
"poids": "Poids",
|
||||||
"poule": "Poule",
|
"poule": "Poule",
|
||||||
"poulePour": "Poule pour: ",
|
"poulePour": "Poule pour: ",
|
||||||
|
|||||||
@ -1,8 +1,13 @@
|
|||||||
import React, {useEffect, useState} from "react";
|
import React, {useEffect, useState} from "react";
|
||||||
import {useTranslation} from "react-i18next";
|
import {Trans, useTranslation} from "react-i18next";
|
||||||
import {useCountries} from "../../hooks/useCountries.jsx";
|
import {useCountries} from "../../hooks/useCountries.jsx";
|
||||||
import {ListPresetSelect} from "./ListPresetSelect.jsx";
|
import {ListPresetSelect} from "./ListPresetSelect.jsx";
|
||||||
import {CatList, getCatName} from "../../utils/Tools.js";
|
import {CatList, getCatName} from "../../utils/Tools.js";
|
||||||
|
import {useCombs} from "../../hooks/useComb.jsx";
|
||||||
|
import {toast} from "react-toastify";
|
||||||
|
import {build_tree} from "../../utils/TreeUtils.js";
|
||||||
|
import {createMatch} from "../../utils/CompetitionTools.js";
|
||||||
|
import {useWS} from "../../hooks/useWS.jsx";
|
||||||
|
|
||||||
export function AutoCatModalContent({data, groups, setGroups, defaultPreset = -1}) {
|
export function AutoCatModalContent({data, groups, setGroups, defaultPreset = -1}) {
|
||||||
const country = useCountries('fr')
|
const country = useCountries('fr')
|
||||||
@ -52,64 +57,6 @@ export function AutoCatModalContent({data, groups, setGroups, defaultPreset = -1
|
|||||||
if (data != null)
|
if (data != null)
|
||||||
applyFilter(data, dispoFiltered);
|
applyFilter(data, dispoFiltered);
|
||||||
|
|
||||||
const makePoule = (combIn, groups) => {
|
|
||||||
combIn = combIn.sort(() => Math.random() - 0.5);
|
|
||||||
const maxInPoule = Math.ceil(combIn.length / 2);
|
|
||||||
const out = []
|
|
||||||
|
|
||||||
const pa = [];
|
|
||||||
const pb = [];
|
|
||||||
|
|
||||||
let nameA;
|
|
||||||
let nameB;
|
|
||||||
groups.forEach(g => {
|
|
||||||
const existsInCombIn = combIn.some(c => c.id === g.id);
|
|
||||||
if (existsInCombIn) {
|
|
||||||
if ((pa.length === 0 || g.poule === nameA) && pa.length < maxInPoule) {
|
|
||||||
nameA = g.poule || "1";
|
|
||||||
pa.push(g.id);
|
|
||||||
} else if ((pb.length === 0 || g.poule === nameB) && pb.length < maxInPoule) {
|
|
||||||
if (!(nameA === (g.poule || (nameA === "1" ? "2" : "1")))) {
|
|
||||||
nameB = g.poule || (nameA === "1" ? "2" : "1");
|
|
||||||
pb.push(g.id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
nameA = nameA || (nameB === "1" ? "2" : "1");
|
|
||||||
nameB = nameB || (nameA === "1" ? "2" : "1");
|
|
||||||
|
|
||||||
if (combIn.length <= 5) {
|
|
||||||
combIn.forEach(c => {
|
|
||||||
if (!pa.includes(c.id))
|
|
||||||
pa.push(c.id)
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
for (const c of combIn) {
|
|
||||||
if (pa.includes(c.id) || pb.includes(c.id))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
const club = c.club_str || (c.teamMembers && c.teamMembers[0].club_str) || "";
|
|
||||||
|
|
||||||
const countInPa = pa.filter(p => (p.club_str || (p.teamMembers && p.teamMembers[0].club_str) || "") === club).length;
|
|
||||||
const countInPb = pb.filter(p => (p.club_str || (p.teamMembers && p.teamMembers[0].club_str) || "") === club).length;
|
|
||||||
|
|
||||||
if (pa.length < maxInPoule && (countInPa <= countInPb || pb.length >= maxInPoule)) {
|
|
||||||
pa.push(c.id);
|
|
||||||
} else if (pb.length < maxInPoule) {
|
|
||||||
pb.push(c.id);
|
|
||||||
} else {
|
|
||||||
pa.push(c.id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pa.forEach(id => out.push({id: id, poule: nameA}));
|
|
||||||
pb.forEach(id => out.push({id: id, poule: nameB}));
|
|
||||||
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleSubmit = (e) => {
|
const handleSubmit = (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
@ -230,3 +177,415 @@ export function AutoCatModalContent({data, groups, setGroups, defaultPreset = -1
|
|||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function makePoule(combIn, groups) {
|
||||||
|
combIn = combIn.sort(() => Math.random() - 0.5);
|
||||||
|
const maxInPoule = Math.ceil(combIn.length / 2);
|
||||||
|
const out = []
|
||||||
|
|
||||||
|
const pa = [];
|
||||||
|
const pb = [];
|
||||||
|
|
||||||
|
let nameA;
|
||||||
|
let nameB;
|
||||||
|
groups.forEach(g => {
|
||||||
|
const existsInCombIn = combIn.some(c => c.id === g.id);
|
||||||
|
if (existsInCombIn) {
|
||||||
|
if ((pa.length === 0 || g.poule === nameA) && pa.length < maxInPoule) {
|
||||||
|
nameA = g.poule || "1";
|
||||||
|
pa.push(g.id);
|
||||||
|
} else if ((pb.length === 0 || g.poule === nameB) && pb.length < maxInPoule) {
|
||||||
|
if (!(nameA === (g.poule || (nameA === "1" ? "2" : "1")))) {
|
||||||
|
nameB = g.poule || (nameA === "1" ? "2" : "1");
|
||||||
|
pb.push(g.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
nameA = nameA || (nameB === "1" ? "2" : "1");
|
||||||
|
nameB = nameB || (nameA === "1" ? "2" : "1");
|
||||||
|
|
||||||
|
if (combIn.length <= 5) {
|
||||||
|
combIn.forEach(c => {
|
||||||
|
if (!pa.includes(c.id))
|
||||||
|
pa.push(c.id)
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
for (const c of combIn) {
|
||||||
|
if (pa.includes(c.id) || pb.includes(c.id))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
const club = c.club_str || (c.teamMembers && c.teamMembers[0].club_str) || "";
|
||||||
|
|
||||||
|
const countInPa = pa.filter(p => (p.club_str || (p.teamMembers && p.teamMembers[0].club_str) || "") === club).length;
|
||||||
|
const countInPb = pb.filter(p => (p.club_str || (p.teamMembers && p.teamMembers[0].club_str) || "") === club).length;
|
||||||
|
|
||||||
|
if (pa.length < maxInPoule && (countInPa <= countInPb || pb.length >= maxInPoule)) {
|
||||||
|
pa.push(c.id);
|
||||||
|
} else if (pb.length < maxInPoule) {
|
||||||
|
pb.push(c.id);
|
||||||
|
} else {
|
||||||
|
pa.push(c.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pa.forEach(id => out.push({id: id, poule: nameA}));
|
||||||
|
pb.forEach(id => out.push({id: id, poule: nameB}));
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
function makeWeightCategories(combs) {
|
||||||
|
combs = combs.filter(c => c.weight != null).sort((a, b) => a.weight - b.weight); // Add random for same weight ?
|
||||||
|
const catCount = Math.ceil(combs.length / 10);
|
||||||
|
const catSize = combs.length / catCount;
|
||||||
|
const catMaxSize = Math.min(Math.ceil(catSize), 10);
|
||||||
|
const catMinSize = Math.max(Math.floor(catSize), 3); // Add marge ?
|
||||||
|
|
||||||
|
const categories = Array.from({length: catCount}, () => []);
|
||||||
|
for (let i = 0; i < combs.length; i++) {
|
||||||
|
categories[Math.floor(i / catSize)].push(combs[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
let change = false;
|
||||||
|
let maxIterations = 500;
|
||||||
|
do {
|
||||||
|
change = false;
|
||||||
|
|
||||||
|
// ------ move in upper direction if better and possible ------
|
||||||
|
|
||||||
|
let needFree = -1;
|
||||||
|
let dIfFree = 0;
|
||||||
|
for (let i = 0; i < catCount - 1; i++) {
|
||||||
|
const weightDiff = categories.at(i).at(-1).weight - categories.at(i).at(-2).weight;
|
||||||
|
const nextWeightDiff = categories.at(i + 1).at(0).weight - categories.at(i).at(-1).weight;
|
||||||
|
|
||||||
|
if (weightDiff > nextWeightDiff && categories.at(i).length > catMinSize) {
|
||||||
|
if (categories.at(i + 1).length < catMaxSize) {
|
||||||
|
const movedComb = categories.at(i).pop();
|
||||||
|
categories.at(i + 1).unshift(movedComb);
|
||||||
|
change = true;
|
||||||
|
} else if (weightDiff - nextWeightDiff > dIfFree) {
|
||||||
|
needFree = i;
|
||||||
|
dIfFree = weightDiff - nextWeightDiff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (needFree !== -1) {
|
||||||
|
let haveSpace = -1;
|
||||||
|
let maxDiff = 0;
|
||||||
|
for (let i = needFree + 1; i < catCount; i++) {
|
||||||
|
if (categories.at(i).length < catMaxSize) {
|
||||||
|
haveSpace = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (haveSpace !== -1) {
|
||||||
|
for (let i = needFree + 1; i < haveSpace; i++) {
|
||||||
|
const weightDiff = categories.at(i).at(-1).weight - categories.at(i).at(-2).weight;
|
||||||
|
const nextWeightDiff = categories.at(i + 1).at(0).weight - categories.at(i).at(-1).weight;
|
||||||
|
const diffIfFree = weightDiff - nextWeightDiff;
|
||||||
|
if (diffIfFree > maxDiff) {
|
||||||
|
maxDiff = diffIfFree;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (maxDiff < dIfFree) {
|
||||||
|
for (let i = needFree; i < haveSpace; i++) {
|
||||||
|
const movedComb = categories.at(i).pop();
|
||||||
|
categories.at(i + 1).unshift(movedComb);
|
||||||
|
change = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------ move in lower direction if better and possible ------
|
||||||
|
|
||||||
|
needFree = -1;
|
||||||
|
dIfFree = 0;
|
||||||
|
for (let i = 1; i < catCount; i++) {
|
||||||
|
const currentFirst = categories[i][0];
|
||||||
|
const currentSecondFirst = categories[i][1];
|
||||||
|
const prevLast = categories[i - 1][categories[i - 1].length - 1];
|
||||||
|
|
||||||
|
const weightDiff = currentSecondFirst.weight - currentFirst.weight;
|
||||||
|
const prevWeightDiff = currentFirst.weight - prevLast.weight;
|
||||||
|
|
||||||
|
if (weightDiff > prevWeightDiff && categories.at(i).length > catMinSize) {
|
||||||
|
if (categories.at(i - 1).length < catMaxSize) {
|
||||||
|
const movedComb = categories.at(i).shift();
|
||||||
|
categories.at(i - 1).push(movedComb);
|
||||||
|
change = true;
|
||||||
|
} else if (weightDiff - prevWeightDiff > dIfFree) {
|
||||||
|
needFree = i;
|
||||||
|
dIfFree = weightDiff - prevWeightDiff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (needFree !== -1) {
|
||||||
|
let haveSpace = -1;
|
||||||
|
let maxDiff = 0;
|
||||||
|
for (let i = needFree - 1; i >= 0; i--) {
|
||||||
|
if (categories.at(i).length < catMaxSize) {
|
||||||
|
haveSpace = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (haveSpace !== -1) {
|
||||||
|
for (let i = needFree - 1; i > haveSpace; i--) {
|
||||||
|
const currentFirst = categories[i][0];
|
||||||
|
const currentSecondFirst = categories[i][1];
|
||||||
|
const prevLast = categories[i - 1][categories[i - 1].length - 1];
|
||||||
|
|
||||||
|
const weightDiff = currentSecondFirst.weight - currentFirst.weight;
|
||||||
|
const prevWeightDiff = currentFirst.weight - prevLast.weight;
|
||||||
|
|
||||||
|
const diffIfFree = weightDiff - prevWeightDiff;
|
||||||
|
if (diffIfFree > maxDiff) {
|
||||||
|
maxDiff = diffIfFree;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (maxDiff < dIfFree) {
|
||||||
|
for (let i = needFree; i > haveSpace; i--) {
|
||||||
|
const movedComb = categories.at(i).shift();
|
||||||
|
categories.at(i - 1).push(movedComb);
|
||||||
|
change = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (change && maxIterations-- > 0);
|
||||||
|
|
||||||
|
return categories;
|
||||||
|
}
|
||||||
|
|
||||||
|
const getCatNameList = (count) => {
|
||||||
|
const catNameList = [];
|
||||||
|
if (count >= 10) catNameList.push("Paille");
|
||||||
|
if (count >= 9) catNameList.push("Mouche");
|
||||||
|
if (count >= 8) catNameList.push("Coq");
|
||||||
|
if (count >= 7) catNameList.push("Plume");
|
||||||
|
if (count >= 3) catNameList.push("Léger");
|
||||||
|
if (count >= 5) catNameList.push("Mi-moyen");
|
||||||
|
if (count >= 1) catNameList.push("Moyen");
|
||||||
|
if (count >= 6) catNameList.push("Mi-lourd");
|
||||||
|
if (count >= 2) catNameList.push("Lourd");
|
||||||
|
if (count >= 4) catNameList.push("Super-lourd");
|
||||||
|
|
||||||
|
return catNameList;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function AutoNewCatModalContent() {
|
||||||
|
const {t} = useTranslation("cm");
|
||||||
|
const {combs} = useCombs();
|
||||||
|
const {sendRequest} = useWS();
|
||||||
|
const toastId = React.useRef(null);
|
||||||
|
|
||||||
|
const [gender, setGender] = useState({H: false, F: false, NA: false})
|
||||||
|
const [cat, setCat] = useState([])
|
||||||
|
const [preset, setPreset] = useState(undefined)
|
||||||
|
const [lice, setLice] = useState("1")
|
||||||
|
const [classement, setClassement] = useState(true)
|
||||||
|
const [fullClassement, setFullClassement] = useState(false)
|
||||||
|
|
||||||
|
const setCat_ = (e, index) => {
|
||||||
|
if (e.target.checked) {
|
||||||
|
if (!cat.includes(index)) {
|
||||||
|
setCat([...cat, index])
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setCat(cat.filter(c => c !== index))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function applyFilter(dataIn, dataOut) {
|
||||||
|
dataIn.forEach(comb => {
|
||||||
|
if (comb == null)
|
||||||
|
return;
|
||||||
|
if ((gender.H && comb.genre === 'H' || gender.F && comb.genre === 'F' || gender.NA && comb.genre === 'NA')
|
||||||
|
&& (cat.includes(Math.min(CatList.length, CatList.indexOf(comb.categorie) + comb.overCategory)))
|
||||||
|
&& (preset === undefined || comb.categoriesInscrites.includes(preset.id))) {
|
||||||
|
dataOut.push(comb)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const dispoFiltered = [];
|
||||||
|
if (combs != null)
|
||||||
|
applyFilter(Object.values(combs), dispoFiltered);
|
||||||
|
|
||||||
|
const handleSubmit = (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
let catList
|
||||||
|
if (dispoFiltered.length > 10) {
|
||||||
|
catList = makeWeightCategories(dispoFiltered);
|
||||||
|
} else {
|
||||||
|
catList = [[...dispoFiltered]];
|
||||||
|
}
|
||||||
|
console.log(catList.map(c => c.map(c => ({id: c.id, weight: c.weight, fname: c.fname, lname: c.lname}))))
|
||||||
|
|
||||||
|
toastId.current = toast(t('créationDeLaLesCatégories'), {progress: 0});
|
||||||
|
|
||||||
|
new Promise(async (resolve) => {
|
||||||
|
for (let i = 0; i < catList.length; i++) {
|
||||||
|
const progress = (i + 1) / catList.length;
|
||||||
|
toast.update(toastId.current, {progress});
|
||||||
|
|
||||||
|
const g = []
|
||||||
|
if (gender.H) g.push('H');
|
||||||
|
if (gender.F) g.push('F');
|
||||||
|
|
||||||
|
const type = catList[i].length > 5 && classement ? 3 : 1;
|
||||||
|
const newCat = {
|
||||||
|
name: preset.name + " - " + cat.map(pos => getCatName(CatList[pos])).join(", ") +
|
||||||
|
(gender.H && gender.F ? "" : " - " + g.join("/")) + (catList.length === 1 ? "" : " - " + getCatNameList(catList.length)[i]),
|
||||||
|
liceName: lice,
|
||||||
|
type: type,
|
||||||
|
treeAreClassement: classement,
|
||||||
|
fullClassement: fullClassement,
|
||||||
|
preset: {id: preset.id}
|
||||||
|
}
|
||||||
|
console.log(newCat)
|
||||||
|
|
||||||
|
await sendRequest('createCategory', newCat).then(id => {
|
||||||
|
newCat["id"] = id;
|
||||||
|
const groups = makePoule(catList[i], []);
|
||||||
|
const {newMatch, matchOrderToUpdate, matchPouleToUpdate} = createMatch(newCat, [], groups);
|
||||||
|
|
||||||
|
const p = [];
|
||||||
|
p.push(sendRequest("recalculateMatch", {
|
||||||
|
categorie: newCat.id,
|
||||||
|
newMatch,
|
||||||
|
matchOrderToUpdate: Object.fromEntries(matchOrderToUpdate),
|
||||||
|
matchPouleToUpdate: Object.fromEntries(matchPouleToUpdate),
|
||||||
|
matchesToRemove: []
|
||||||
|
}).then(() => {
|
||||||
|
console.log("Finished creating matches for category", newCat.name);
|
||||||
|
}).catch(err => {
|
||||||
|
console.error("Error creating matches for category", newCat.name, err);
|
||||||
|
}))
|
||||||
|
|
||||||
|
if (type === 3) {
|
||||||
|
const trees = build_tree(4, 1)
|
||||||
|
console.log("Creating trees for new category:", trees);
|
||||||
|
|
||||||
|
p.push(sendRequest('updateTrees', {
|
||||||
|
categoryId: id,
|
||||||
|
trees: trees
|
||||||
|
}).then(() => {
|
||||||
|
console.log("Finished creating trees for category", newCat.name);
|
||||||
|
}).catch(err => {
|
||||||
|
console.error("Error creating trees for category", newCat.name, err);
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
return Promise.allSettled(p)
|
||||||
|
}).catch(err => {
|
||||||
|
console.error("Error creating category", newCat.name, err);
|
||||||
|
})
|
||||||
|
console.log("Finished category", i + 1, "/", catList.length);
|
||||||
|
}
|
||||||
|
resolve();
|
||||||
|
}).finally(() => {
|
||||||
|
toast.done(toastId.current);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return <>
|
||||||
|
<div className="modal-header">
|
||||||
|
<h1 className="modal-title fs-5" id="autoNewCatModalLabel">{t('depuisUneCatégoriePrédéfinie')}</h1>
|
||||||
|
<button type="button" className="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
<div className="modal-body">
|
||||||
|
<div className="d-flex flex-wrap justify-content-around">
|
||||||
|
<ListPresetSelect value={preset} onChange={setPreset} returnId={false}/>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label className="form-label">{t('genre')}</label>
|
||||||
|
<div className="d-flex align-items-center">
|
||||||
|
<div className="form-check" style={{marginRight: '10px'}}>
|
||||||
|
<input className="form-check-input" type="checkbox" id="gridCheck" checked={gender.H}
|
||||||
|
onChange={e => setGender((prev) => {
|
||||||
|
return {...prev, H: e.target.checked}
|
||||||
|
})}/>
|
||||||
|
<label className="form-check-label" htmlFor="gridCheck">{t('genre.h')}</label>
|
||||||
|
</div>
|
||||||
|
<div className="form-check" style={{marginRight: '10px'}}>
|
||||||
|
<input className="form-check-input" type="checkbox" id="gridCheck2" checked={gender.F}
|
||||||
|
onChange={e => setGender((prev) => {
|
||||||
|
return {...prev, F: e.target.checked}
|
||||||
|
})}/>
|
||||||
|
<label className="form-check-label" htmlFor="gridCheck2">{t('genre.f')}</label>
|
||||||
|
</div>
|
||||||
|
<div className="form-check">
|
||||||
|
<input className="form-check-input" type="checkbox" id="gridCheck3" checked={gender.NA}
|
||||||
|
onChange={e => setGender((prev) => {
|
||||||
|
return {...prev, NA: e.target.checked}
|
||||||
|
})}/>
|
||||||
|
<label className="form-check-label" htmlFor="gridCheck3">{t('genre.na')}</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{preset !== undefined && <>
|
||||||
|
<div className="d-flex flex-wrap justify-content-around mb-1">
|
||||||
|
<div className="d-flex flex-wrap mb-3">
|
||||||
|
<label htmlFor="inputState2" className="form-label align-self-center" style={{margin: "0 0.5em 0 0"}}>
|
||||||
|
{t('catégorie')} :
|
||||||
|
</label>
|
||||||
|
{preset.categories.map(c => [c.categorie, CatList.indexOf(c.categorie)]).sort((a, b) => a[1] - b[1])
|
||||||
|
.map(([cat_, index]) => {
|
||||||
|
return <div key={index} className="input-group"
|
||||||
|
style={{display: "contents"}}>
|
||||||
|
<div className="input-group-text">
|
||||||
|
<input className="form-check-input mt-0" type="checkbox"
|
||||||
|
id={"categoriesInput" + index} checked={cat.includes(index)} aria-label={getCatName(cat_)}
|
||||||
|
onChange={e => setCat_(e, index)}/>
|
||||||
|
<label style={{marginLeft: "0.5em"}} htmlFor={"categoriesInput" + index}>{getCatName(cat_)}</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</>}
|
||||||
|
|
||||||
|
<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}
|
||||||
|
onChange={e => setLice(e.target.value)}/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="form-check">
|
||||||
|
<input className="form-check-input" type="checkbox" value="" id="checkDefault" checked={classement}
|
||||||
|
onChange={e => setClassement(e.target.checked)}/>
|
||||||
|
<label className="form-check-label" htmlFor="checkDefault">
|
||||||
|
{t('créerLaPhaseFinaleSilYADesPoules')}
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div className="form-check">
|
||||||
|
<input className="form-check-input" type="checkbox" value="" id="checkDefault2" disabled={!classement}
|
||||||
|
checked={fullClassement} onChange={e => setFullClassement(e.target.checked)}/>
|
||||||
|
<label className="form-check-label" htmlFor="checkDefault2">
|
||||||
|
{t('lesCombattantsEnDehors2')}
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<span>{dispoFiltered.length} {t('combattantsCorrespondentAuxSélectionnés')}</span><br/>
|
||||||
|
<span>{Math.ceil(dispoFiltered.length / 10)} {t('catégoriesVontêtreCréées')}</span><br/>
|
||||||
|
{dispoFiltered.length > 10 && dispoFiltered.some(c => !c.weight) &&
|
||||||
|
<span style={{color: "red"}}>{t('certainsCombattantsNontPasDePoidsRenseigné')}</span>}
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div className="modal-footer">
|
||||||
|
<button type="button" className="btn btn-secondary" data-bs-dismiss="modal">{t('fermer')}</button>
|
||||||
|
<button type="submit" className="btn btn-primary" onClick={handleSubmit}
|
||||||
|
disabled={dispoFiltered.length <= 0} data-bs-dismiss="modal">{t('ajouter')}</button>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import {AxiosError} from "../AxiosError.jsx";
|
|||||||
import {useTranslation} from "react-i18next";
|
import {useTranslation} from "react-i18next";
|
||||||
import React, {useId} from "react";
|
import React, {useId} from "react";
|
||||||
|
|
||||||
export function ListPresetSelect({disabled, value, onChange}) {
|
export function ListPresetSelect({disabled, value, onChange, returnId = true}) {
|
||||||
const id = useId()
|
const id = useId()
|
||||||
const {data, error} = useRequestWS("listPreset", {}, null);
|
const {data, error} = useRequestWS("listPreset", {}, null);
|
||||||
const {t} = useTranslation();
|
const {t} = useTranslation();
|
||||||
@ -12,9 +12,16 @@ export function ListPresetSelect({disabled, value, onChange}) {
|
|||||||
? <div className="mb-3">
|
? <div className="mb-3">
|
||||||
<label className="form-label" htmlFor={id}>{t('catégorie')}</label>
|
<label className="form-label" htmlFor={id}>{t('catégorie')}</label>
|
||||||
<select className="form-select" id={id} disabled={disabled}
|
<select className="form-select" id={id} disabled={disabled}
|
||||||
value={value} onChange={e => onChange(Number(e.target.value))}>
|
value={returnId ? value : (value ? value.id : -1)}
|
||||||
|
onChange={e => {
|
||||||
|
if (returnId) {
|
||||||
|
onChange(e.target.value)
|
||||||
|
} else {
|
||||||
|
onChange(data.find(c => c.id === Number(e.target.value)))
|
||||||
|
}
|
||||||
|
}}>
|
||||||
<option value={-1}>{t('sélectionner...')}</option>
|
<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>))}
|
{data.sort((a, b) => a.name.localeCompare(b.name)).map(o => (<option key={o.id} value={o.id}>{o.name}</option>))}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
: error
|
: error
|
||||||
|
|||||||
@ -20,6 +20,7 @@ import {StateWindow} from "./StateWindow.jsx";
|
|||||||
import {CombName, useCombs} from "../../../hooks/useComb.jsx";
|
import {CombName, useCombs} from "../../../hooks/useComb.jsx";
|
||||||
import {useCards, useCardsDispatch} from "../../../hooks/useCard.jsx";
|
import {useCards, useCardsDispatch} from "../../../hooks/useCard.jsx";
|
||||||
import {ListPresetSelect} from "../../../components/cm/ListPresetSelect.jsx";
|
import {ListPresetSelect} from "../../../components/cm/ListPresetSelect.jsx";
|
||||||
|
import {AutoNewCatModalContent} from "../../../components/cm/AutoCatModalContent.jsx";
|
||||||
|
|
||||||
const vite_url = import.meta.env.VITE_URL;
|
const vite_url = import.meta.env.VITE_URL;
|
||||||
|
|
||||||
@ -504,8 +505,9 @@ function CategoryHeader({
|
|||||||
cat, setCatId
|
cat, setCatId
|
||||||
}) {
|
}) {
|
||||||
const setLoading = useLoadingSwitcher()
|
const setLoading = useLoadingSwitcher()
|
||||||
const bthRef = useRef();
|
const bthRef = useRef(null);
|
||||||
const confirmRef = useRef();
|
const newBthRef = useRef(null);
|
||||||
|
const confirmRef = useRef(null);
|
||||||
const [modal, setModal] = useState({})
|
const [modal, setModal] = useState({})
|
||||||
const [confirm, setConfirm] = useState({})
|
const [confirm, setConfirm] = useState({})
|
||||||
const {t} = useTranslation("cm");
|
const {t} = useTranslation("cm");
|
||||||
@ -521,6 +523,7 @@ function CategoryHeader({
|
|||||||
])
|
])
|
||||||
}
|
}
|
||||||
const sendAddCategory = ({data}) => {
|
const sendAddCategory = ({data}) => {
|
||||||
|
console.log("add cat", data);
|
||||||
setCats([...cats, data])
|
setCats([...cats, data])
|
||||||
}
|
}
|
||||||
const sendDelCategory = ({data}) => {
|
const sendDelCategory = ({data}) => {
|
||||||
@ -554,8 +557,7 @@ function CategoryHeader({
|
|||||||
if (selectedCatId !== "-1") {
|
if (selectedCatId !== "-1") {
|
||||||
setCatId(selectedCatId);
|
setCatId(selectedCatId);
|
||||||
} else { // New category
|
} else { // New category
|
||||||
setModal({});
|
newBthRef.current.click();
|
||||||
bthRef.current.click();
|
|
||||||
e.target.value = cat?.id;
|
e.target.value = cat?.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -595,10 +597,58 @@ function CategoryHeader({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div className="modal fade" id="exampleModalToggle2" aria-hidden="true" aria-labelledby="exampleModalToggleLabel2" tabIndex="-1">
|
||||||
|
<div className="modal-dialog modal-dialog-centered">
|
||||||
|
<div className="modal-content">
|
||||||
|
<AutoNewCatModalContent/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="modal fade" id="autoNewCatModal" aria-hidden="true" aria-labelledby="autoNewCatModalLabel" tabIndex="-1">
|
||||||
|
<div className="modal-dialog modal-dialog-centered">
|
||||||
|
<div className="modal-content">
|
||||||
|
<AutoNewCatModalContent/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<button ref={confirmRef} data-bs-toggle="modal" data-bs-target="#confirm-dialog" style={{display: "none"}}>open</button>
|
<button ref={confirmRef} data-bs-toggle="modal" data-bs-target="#confirm-dialog" style={{display: "none"}}>open</button>
|
||||||
<ConfirmDialog id="confirm-dialog" onConfirm={confirm.confirm ? confirm.confirm : () => {
|
<ConfirmDialog id="confirm-dialog" onConfirm={confirm.confirm ? confirm.confirm : () => {
|
||||||
}} onCancel={confirm.cancel ? confirm.cancel : () => {
|
}} onCancel={confirm.cancel ? confirm.cancel : () => {
|
||||||
}} title={confirm ? confirm.title : ""} message={confirm ? confirm.message : ""}/>
|
}} title={confirm ? confirm.title : ""} message={confirm ? confirm.message : ""}/>
|
||||||
|
|
||||||
|
|
||||||
|
<button ref={newBthRef} data-bs-toggle="modal" data-bs-target="#newCatModal" style={{display: "none"}}>open</button>
|
||||||
|
|
||||||
|
<div className="modal fade" id="newCatModal" tabIndex="-1" aria-labelledby="newCatModalLabel" aria-hidden="true">
|
||||||
|
<div className="modal-dialog modal-dialog-centered">
|
||||||
|
<div className="modal-content">
|
||||||
|
<div className="modal-header">
|
||||||
|
<h1 className="modal-title fs-5" id="newCatModalLabel">{t('ajouter')} {t('uneCatégorie')}</h1>
|
||||||
|
<button type="button" className="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
<div className="modal-body text-center">
|
||||||
|
{t('modeDeCréation')} :
|
||||||
|
<div className="mb-2">
|
||||||
|
<button className="btn btn-primary" onClick={() => {
|
||||||
|
setModal({});
|
||||||
|
bthRef.current.click();
|
||||||
|
e.target.value = cat?.id;
|
||||||
|
}}>{t('personnaliser')}</button>
|
||||||
|
</div>
|
||||||
|
<div className="mb-2">
|
||||||
|
<button className="btn btn-primary" data-bs-target="#autoNewCatModal"
|
||||||
|
data-bs-toggle="modal">{t('depuisUneCatégoriePrédéfinie')}</button>
|
||||||
|
</div>
|
||||||
|
<div className="mb-2">
|
||||||
|
<button className="btn btn-primary" disabled={true}>{t('créerToutesLesCatégories')}</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -617,6 +667,7 @@ function ModalContent({state, setCatId, setConfirm, confirmRef}) {
|
|||||||
const {sendRequest} = useWS();
|
const {sendRequest} = useWS();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
console.log(state);
|
||||||
setName(state.name || "");
|
setName(state.name || "");
|
||||||
setLice(state.liceName || "1");
|
setLice(state.liceName || "1");
|
||||||
setPoule(((state.type || 1) & 1) !== 0);
|
setPoule(((state.type || 1) & 1) !== 0);
|
||||||
|
|||||||
@ -317,9 +317,9 @@ function MatchList({matches, cat, menuActions, classement = false, currentMatch
|
|||||||
|
|
||||||
const liceName = (cat.liceName || "N/A").split(";");
|
const liceName = (cat.liceName || "N/A").split(";");
|
||||||
const marches2 = classement
|
const marches2 = classement
|
||||||
? matches.filter(m => m.categorie_ord === -42)
|
? matches.filter(m => m.categorie_ord === -42 && m.categorie === cat.id)
|
||||||
.map(m => ({...m, ...win_end(m, cards_v)}))
|
.map(m => ({...m, ...win_end(m, cards_v)}))
|
||||||
: matches.filter(m => m.categorie_ord !== -42)
|
: matches.filter(m => m.categorie_ord !== -42 && m.categorie === cat.id)
|
||||||
.sort((a, b) => a.categorie_ord - b.categorie_ord)
|
.sort((a, b) => a.categorie_ord - b.categorie_ord)
|
||||||
.map(m => ({...m, ...win_end(m, cards_v)}))
|
.map(m => ({...m, ...win_end(m, cards_v)}))
|
||||||
const firstIndex = marches2.findLastIndex(m => m.poule === '-') + 1;
|
const firstIndex = marches2.findLastIndex(m => m.poule === '-') + 1;
|
||||||
|
|||||||
@ -433,7 +433,7 @@ function ListMatch({cat, matches, groups, reducer}) {
|
|||||||
matchOrderToUpdate: Object.fromEntries(matchOrderToUpdate),
|
matchOrderToUpdate: Object.fromEntries(matchOrderToUpdate),
|
||||||
matchPouleToUpdate: Object.fromEntries(matchPouleToUpdate),
|
matchPouleToUpdate: Object.fromEntries(matchPouleToUpdate),
|
||||||
matchesToRemove: matchesToRemove.map(m => m.id)
|
matchesToRemove: matchesToRemove.map(m => m.id)
|
||||||
}), getToastMessage("toast.matchs.create", "ns"))
|
}), getToastMessage("toast.matchs.create", "cm"))
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
console.log("Finished creating matches");
|
console.log("Finished creating matches");
|
||||||
})
|
})
|
||||||
@ -521,9 +521,9 @@ function MatchList({matches, cat, groups, reducer, classement = false}) {
|
|||||||
|
|
||||||
const liceName = (cat.liceName || "N/A").split(";");
|
const liceName = (cat.liceName || "N/A").split(";");
|
||||||
const marches2 = classement
|
const marches2 = classement
|
||||||
? matches.filter(m => m.categorie_ord === -42)
|
? matches.filter(m => m.categorie_ord === -42 && m.categorie === cat.id)
|
||||||
.map(m => ({...m, ...win_end(m, cards_v)}))
|
.map(m => ({...m, ...win_end(m, cards_v)}))
|
||||||
: matches.filter(m => m.categorie_ord !== -42)
|
: matches.filter(m => m.categorie_ord !== -42 && m.categorie === cat.id)
|
||||||
.sort((a, b) => a.categorie_ord - b.categorie_ord)
|
.sort((a, b) => a.categorie_ord - b.categorie_ord)
|
||||||
.map(m => ({...m, ...win_end(m, cards_v)}))
|
.map(m => ({...m, ...win_end(m, cards_v)}))
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user