mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-29 07:53:23 +00:00
feat: Configuration et gestion du planning [#2]
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
import React, { createContext, useContext } from 'react';
|
||||
import { School } from 'lucide-react';
|
||||
|
||||
const ClassesContext = createContext();
|
||||
|
||||
@ -9,9 +10,9 @@ export const ClassesProvider = ({ children }) => {
|
||||
|
||||
const schoolYears = [
|
||||
{ value: '', label: 'Sélectionner une période' },
|
||||
{ value: `${currentYear - 1}-${currentYear}`, label: `${currentYear - 1}-${currentYear}` },
|
||||
{ value: `${currentYear}-${currentYear + 1}`, label: `${currentYear}-${currentYear + 1}` },
|
||||
{ value: `${currentYear + 1}-${currentYear + 2}`, label: `${currentYear + 1}-${currentYear + 2}` },
|
||||
{ value: `${currentYear + 2}-${currentYear + 3}`, label: `${currentYear + 2}-${currentYear + 3}` },
|
||||
];
|
||||
|
||||
const niveauxPremierCycle = [
|
||||
@ -57,6 +58,18 @@ export const ClassesProvider = ({ children }) => {
|
||||
});
|
||||
};
|
||||
|
||||
const getNiveauxTabs = (niveaux) => {
|
||||
// Trier les niveaux par id
|
||||
const sortedNiveaux = niveaux.sort((a, b) => a - b);
|
||||
|
||||
// Mapper les labels correspondants
|
||||
return sortedNiveaux.map(niveauId => {
|
||||
const niveau = allNiveaux.find(n => n.id === niveauId);
|
||||
return niveau ? { id: niveau.id, title: niveau.name, icon: School } : { id: 'unknown', title: 'Niveau inconnu', icon: null };
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
const generateAgeToNiveaux = (minAge, maxAge) => {
|
||||
if (minAge === null || isNaN(minAge)) {
|
||||
return [];
|
||||
@ -67,73 +80,149 @@ export const ClassesProvider = ({ children }) => {
|
||||
.map(({ id }) => id);
|
||||
};
|
||||
|
||||
const updatePlanning = (formData) => {
|
||||
const getNiveauNameById = (id) => {
|
||||
const niveau = allNiveaux.find(item => item.id.toString() === id);
|
||||
return niveau ? niveau.name : '';
|
||||
};
|
||||
|
||||
let updatedPlanning = { ...formData.planning };
|
||||
const getAmbianceText = (classe) => {
|
||||
const ambiance = classe.nom_ambiance ? classe.nom_ambiance : '';
|
||||
const trancheAge = classe.tranche_age ? `${classe.tranche_age} ans` : '';
|
||||
|
||||
const emploiDuTemps = formData.jours_ouverture.reduce((acc, dayId) => {
|
||||
const dayName = selectedDays[dayId];
|
||||
if (dayName) {
|
||||
acc[dayName] = [];
|
||||
}
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
if (formData.planning_type === 1) {
|
||||
updatedPlanning = {
|
||||
type: 1,
|
||||
plageHoraire: formData.plage_horaire,
|
||||
joursOuverture: formData.jours_ouverture,
|
||||
emploiDuTemps
|
||||
};
|
||||
} else if (formData.planning_type === 2) {
|
||||
updatedPlanning = {
|
||||
type: 2,
|
||||
plageHoraire: formData.plage_horaire,
|
||||
joursOuverture: formData.jours_ouverture,
|
||||
emploiDuTemps: {
|
||||
S1: {
|
||||
DateDebut: formData.date_debut_semestre_1,
|
||||
DateFin: formData.date_fin_semestre_1,
|
||||
...emploiDuTemps
|
||||
},
|
||||
S2: {
|
||||
DateDebut: formData.date_debut_semestre_2,
|
||||
DateFin: formData.date_fin_semestre_2,
|
||||
...emploiDuTemps
|
||||
}
|
||||
}
|
||||
};
|
||||
} else if (formData.planning_type === 3) {
|
||||
updatedPlanning = {
|
||||
type: 3,
|
||||
plageHoraire: formData.plage_horaire,
|
||||
joursOuverture: formData.jours_ouverture,
|
||||
emploiDuTemps: {
|
||||
T1: {
|
||||
DateDebut: formData.date_debut_trimestre_1,
|
||||
DateFin: formData.date_fin_trimestre_1,
|
||||
...emploiDuTemps
|
||||
},
|
||||
T2: {
|
||||
DateDebut: formData.date_debut_trimestre_2,
|
||||
DateFin: formData.date_fin_trimestre_2,
|
||||
...emploiDuTemps
|
||||
},
|
||||
T3: {
|
||||
DateDebut: formData.date_debut_trimestre_3,
|
||||
DateFin: formData.date_fin_trimestre_3,
|
||||
...emploiDuTemps
|
||||
}
|
||||
}
|
||||
};
|
||||
if (ambiance && trancheAge) {
|
||||
return `${ambiance} (${trancheAge})`;
|
||||
} else if (ambiance) {
|
||||
return ambiance;
|
||||
} else if (trancheAge) {
|
||||
return trancheAge;
|
||||
} else {
|
||||
return 'Non spécifié';
|
||||
}
|
||||
};
|
||||
|
||||
return updatedPlanning;
|
||||
const getAmbianceName = (classe) => {
|
||||
const ambiance = classe.nom_ambiance ? classe.nom_ambiance : '';
|
||||
|
||||
if (ambiance) {
|
||||
return ambiance;
|
||||
} else {
|
||||
return 'Non spécifié';
|
||||
}
|
||||
};
|
||||
|
||||
const updatePlannings = (formData, existingPlannings) => {
|
||||
return formData.niveaux.map(niveau => {
|
||||
let existingPlanning = existingPlannings.find(planning => planning.niveau === niveau);
|
||||
|
||||
const emploiDuTemps = formData.jours_ouverture.reduce((acc, dayId) => {
|
||||
const dayName = selectedDays[dayId];
|
||||
console.log('dayId:', dayId, 'dayName:', dayName); // Ajout de log pour vérifier les correspondances
|
||||
if (dayName) {
|
||||
acc[dayName] = existingPlanning?.emploiDuTemps?.[dayName] || [];
|
||||
}
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
console.log('Emploi du Temps initialisé :', emploiDuTemps);
|
||||
|
||||
let updatedPlanning;
|
||||
if (formData.type === 1) {
|
||||
updatedPlanning = {
|
||||
niveau: niveau,
|
||||
emploiDuTemps
|
||||
};
|
||||
} else if (formData.type === 2) {
|
||||
updatedPlanning = {
|
||||
niveau: niveau,
|
||||
emploiDuTemps: {
|
||||
S1: {
|
||||
DateDebut: formData.date_debut_semestre_1,
|
||||
DateFin: formData.date_fin_semestre_1,
|
||||
...emploiDuTemps
|
||||
},
|
||||
S2: {
|
||||
DateDebut: formData.date_debut_semestre_2,
|
||||
DateFin: formData.date_fin_semestre_2,
|
||||
...emploiDuTemps
|
||||
}
|
||||
}
|
||||
};
|
||||
} else if (formData.type === 3) {
|
||||
updatedPlanning = {
|
||||
niveau: niveau,
|
||||
emploiDuTemps: {
|
||||
T1: {
|
||||
DateDebut: formData.date_debut_trimestre_1,
|
||||
DateFin: formData.date_fin_trimestre_1,
|
||||
...emploiDuTemps
|
||||
},
|
||||
T2: {
|
||||
DateDebut: formData.date_debut_trimestre_2,
|
||||
DateFin: formData.date_fin_trimestre_2,
|
||||
...emploiDuTemps
|
||||
},
|
||||
T3: {
|
||||
DateDebut: formData.date_debut_trimestre_3,
|
||||
DateFin: formData.date_fin_trimestre_3,
|
||||
...emploiDuTemps
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
console.log('Updated Planning:', updatedPlanning);
|
||||
|
||||
// Fusionner les plannings existants avec les nouvelles données
|
||||
return existingPlanning
|
||||
? { ...existingPlanning, ...updatedPlanning }
|
||||
: updatedPlanning;
|
||||
});
|
||||
};
|
||||
|
||||
const groupSpecialitiesBySubject = (enseignants) => {
|
||||
const groupedSpecialities = {};
|
||||
|
||||
enseignants.forEach(teacher => {
|
||||
teacher.specialites.forEach(specialite => {
|
||||
if (!groupedSpecialities[specialite.id]) {
|
||||
groupedSpecialities[specialite.id] = {
|
||||
...specialite,
|
||||
teachers: [`${teacher.nom} ${teacher.prenom}`],
|
||||
};
|
||||
} else {
|
||||
groupedSpecialities[specialite.id].teachers.push(`${teacher.nom} ${teacher.prenom}`);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return Object.values(groupedSpecialities);
|
||||
};
|
||||
|
||||
const determineInitialPeriod = (emploiDuTemps) => {
|
||||
if (emploiDuTemps.S1 && emploiDuTemps.S2) {
|
||||
return 'S1'; // Planning semestriel
|
||||
} else if (emploiDuTemps.T1 && emploiDuTemps.T2 && emploiDuTemps.T3) {
|
||||
return 'T1'; // Planning trimestriel
|
||||
}
|
||||
return ''; // Planning annuel ou autre
|
||||
};
|
||||
|
||||
return (
|
||||
<ClassesContext.Provider value={{ schoolYears, getNiveauxLabels, generateAgeToNiveaux, niveauxPremierCycle, niveauxSecondCycle, niveauxTroisiemeCycle, typeEmploiDuTemps, updatePlanning }}>
|
||||
<ClassesContext.Provider value={{ schoolYears,
|
||||
getNiveauxLabels,
|
||||
getNiveauxTabs,
|
||||
generateAgeToNiveaux,
|
||||
niveauxPremierCycle,
|
||||
niveauxSecondCycle,
|
||||
niveauxTroisiemeCycle,
|
||||
typeEmploiDuTemps,
|
||||
updatePlannings,
|
||||
getAmbianceText,
|
||||
getAmbianceName,
|
||||
groupSpecialitiesBySubject,
|
||||
getNiveauNameById,
|
||||
determineInitialPeriod
|
||||
}}>
|
||||
{children}
|
||||
</ClassesContext.Provider>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user