feat: cat remove
This commit is contained in:
parent
f76ca43ed6
commit
0dace76fc3
@ -335,4 +335,34 @@ public class Utils {
|
||||
|
||||
return (int) ((calendar.getTimeInMillis() - now.getTimeInMillis()) / (1000 * 60 * 60 * 24));
|
||||
}
|
||||
|
||||
public static String formatPrenom(String input) {
|
||||
if (input == null || input.isEmpty()) {
|
||||
return input;
|
||||
}
|
||||
|
||||
StringBuilder result = new StringBuilder();
|
||||
String[] mots = input.split(" ");
|
||||
|
||||
for (String mot : mots) {
|
||||
if (!mot.isEmpty()) {
|
||||
String[] parties = mot.split("[-']");
|
||||
StringBuilder motFormate = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < parties.length; i++) {
|
||||
if (!parties[i].isEmpty()) {
|
||||
String premiereLettre = parties[i].substring(0, 1).toUpperCase();
|
||||
String reste = parties[i].substring(1).toLowerCase();
|
||||
motFormate.append(premiereLettre).append(reste);
|
||||
}
|
||||
|
||||
if (i < parties.length - 1) {
|
||||
motFormate.append(mot.charAt(mot.indexOf(parties[i]) + parties[i].length()));
|
||||
}
|
||||
}
|
||||
result.append(motFormate).append(" ");
|
||||
}
|
||||
}
|
||||
return result.toString().trim();
|
||||
}
|
||||
}
|
||||
|
||||
@ -118,7 +118,8 @@ public class RCategorie {
|
||||
uni = uni.chain(__ -> treeRepository.delete("category = ?1", cat.getId()))
|
||||
.chain(__ -> matchRepository.delete("category = ?1 AND category_ord = -42", cat));
|
||||
}
|
||||
return uni;
|
||||
Uni<Long> finalUni = uni;
|
||||
return Panache.withTransaction(() -> finalUni);
|
||||
})
|
||||
.call(cat -> SSCategorie.sendCategory(connection, cat))
|
||||
.replaceWithVoid();
|
||||
@ -205,6 +206,16 @@ public class RCategorie {
|
||||
.replaceWithVoid();
|
||||
}
|
||||
|
||||
@WSReceiver(code = "deleteCategory", permission = PermLevel.ADMIN)
|
||||
public Uni<Void> deleteCategory(WebSocketConnection connection, Long id) {
|
||||
return getById(id, connection)
|
||||
.call(cat -> Panache.withTransaction(() -> treeRepository.delete("category = ?1", cat.getId())
|
||||
.call(__ -> matchRepository.delete("category = ?1", cat))))
|
||||
.chain(cat -> Panache.withTransaction(() -> categoryRepository.delete(cat)))
|
||||
.call(__ -> SSCategorie.sendDelCategory(connection, id))
|
||||
.replaceWithVoid();
|
||||
}
|
||||
|
||||
@RegisterForReflection
|
||||
public record JustCategorie(long id, String name, int type, String liceName) {
|
||||
public static JustCategorie from(CategoryModel m) {
|
||||
|
||||
@ -30,4 +30,8 @@ public class SSCategorie {
|
||||
public static Uni<Void> sendTreeCategory(WebSocketConnection connection, List<TreeEntity> treeEntities) {
|
||||
return CompetitionWS.sendNotifyToOtherEditor(connection, "sendTreeCategory", treeEntities);
|
||||
}
|
||||
|
||||
public static Uni<?> sendDelCategory(WebSocketConnection connection, Long id) {
|
||||
return CompetitionWS.sendNotifyToOtherEditor(connection, "sendDelCategory", id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -63,22 +63,31 @@ function CategoryHeader({cat, setCatId}) {
|
||||
const sendAddCategory = ({data}) => {
|
||||
setCats([...cats, data])
|
||||
}
|
||||
const sendDelCategory = ({data}) => {
|
||||
setCatId(catId => {
|
||||
if (catId === data) return null;
|
||||
return catId;
|
||||
})
|
||||
setCats([...cats.filter(c => c.id !== data)])
|
||||
}
|
||||
dispatch({type: 'addListener', payload: {callback: categoryListener, code: 'sendCategory'}})
|
||||
dispatch({type: 'addListener', payload: {callback: sendAddCategory, code: 'sendAddCategory'}})
|
||||
dispatch({type: 'addListener', payload: {callback: sendDelCategory, code: 'sendDelCategory'}})
|
||||
return () => {
|
||||
dispatch({type: 'removeListener', payload: categoryListener})
|
||||
dispatch({type: 'removeListener', payload: sendAddCategory})
|
||||
dispatch({type: 'removeListener', payload: sendDelCategory})
|
||||
}
|
||||
}, [cats]);
|
||||
|
||||
useEffect(() => {
|
||||
if (cats && cats.length > 0 && !cat) {
|
||||
if (cats && cats.length > 0 && !cat || (cats && !cats.find(c => c.id === cat.id))) {
|
||||
setCatId(cats.sort((a, b) => a.name.localeCompare(b.name))[0].id);
|
||||
} else if (cats && cats.length === 0) {
|
||||
setModal({});
|
||||
bthRef.current.click();
|
||||
}
|
||||
}, [cats]);
|
||||
}, [cats, cat]);
|
||||
|
||||
const handleCatChange = (e) => {
|
||||
const selectedCatId = e.target.value;
|
||||
@ -306,7 +315,7 @@ function ModalContent({state, setCatId, setConfirm, confirmRef}) {
|
||||
|
||||
return <form onSubmit={handleSubmit}>
|
||||
<div className="modal-header">
|
||||
<h1 className="modal-title fs-5" id="CategorieModalLabel">Ajouter une catégorie</h1>
|
||||
<h1 className="modal-title fs-5" id="CategorieModalLabel">{state.id === undefined ? "Ajouter" : "Modifier"} une catégorie</h1>
|
||||
<button type="button" className="btn-close" data-bs-dismiss="modal"
|
||||
aria-label="Close"></button>
|
||||
</div>
|
||||
@ -380,6 +389,22 @@ function ModalContent({state, setCatId, setConfirm, confirmRef}) {
|
||||
<div className="modal-footer">
|
||||
<button type="button" className="btn btn-secondary" data-bs-dismiss="modal">Fermer</button>
|
||||
<button type="submit" className="btn btn-primary" data-bs-dismiss="modal">Enregistrer</button>
|
||||
{state.id !== undefined && <button type="button" className="btn btn-danger" data-bs-dismiss="modal" onClick={() => {
|
||||
setConfirm({
|
||||
title: "Suppression de la catégorie",
|
||||
message: `Voulez-vous vraiment supprimer la catégorie ${state.name}. Cela va supprimer tous les matchs associés !`,
|
||||
confirm: () => {
|
||||
toast.promise(sendRequest('deleteCategory', state.id),
|
||||
{
|
||||
pending: 'Suppression de la catégorie...',
|
||||
success: 'Catégorie supprimée !',
|
||||
error: 'Erreur lors de la suppression de la catégorie'
|
||||
}
|
||||
).then(() => setCatId(null));
|
||||
}
|
||||
})
|
||||
confirmRef.current.click();
|
||||
}}>Supprimer</button>}
|
||||
</div>
|
||||
</form>
|
||||
}
|
||||
|
||||
@ -27,8 +27,22 @@ export function CategorieSelect({catId, setCatId, menuActions}) {
|
||||
const categoryListener = ({data}) => {
|
||||
setCats([...cats.filter(c => c.id !== data.id), data])
|
||||
}
|
||||
const sendAddCategory = ({data}) => {
|
||||
setCats([...cats, data])
|
||||
}
|
||||
const sendDelCategory = ({data}) => {
|
||||
if (catId === data)
|
||||
setCatId(-1);
|
||||
setCats([...cats.filter(c => c.id !== data)])
|
||||
}
|
||||
dispatch({type: 'addListener', payload: {callback: categoryListener, code: 'sendCategory'}})
|
||||
return () => dispatch({type: 'removeListener', payload: categoryListener})
|
||||
dispatch({type: 'addListener', payload: {callback: sendAddCategory, code: 'sendAddCategory'}})
|
||||
dispatch({type: 'addListener', payload: {callback: sendDelCategory, code: 'sendDelCategory'}})
|
||||
return () => {
|
||||
dispatch({type: 'removeListener', payload: categoryListener})
|
||||
dispatch({type: 'removeListener', payload: sendAddCategory})
|
||||
dispatch({type: 'removeListener', payload: sendDelCategory})
|
||||
}
|
||||
}, [cats]);
|
||||
|
||||
const cat = cats?.find(c => c.id === catId);
|
||||
@ -131,10 +145,15 @@ function ListMatch({cat, matches, trees, menuActions}) {
|
||||
const [type, setType] = useState(1);
|
||||
|
||||
useEffect(() => {
|
||||
if (!cat)
|
||||
return;
|
||||
if ((cat.type & type) === 0)
|
||||
setType(cat.type);
|
||||
}, [cat]);
|
||||
|
||||
if (!cat)
|
||||
return <></>;
|
||||
|
||||
return <div style={{marginTop: "1em"}}>
|
||||
{cat && cat.type === 3 && <>
|
||||
<ul className="nav nav-tabs">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user