Auto-commit for deploy to production - 2025-12-09 16:01:18
This commit is contained in:
@@ -166,7 +166,7 @@ function addSchoolHolidayEventsFromRecords(records, events) {
|
|||||||
const tbody = document.querySelector("#schoolHolidaysTable tbody");
|
const tbody = document.querySelector("#schoolHolidaysTable tbody");
|
||||||
if (tbody) tbody.innerHTML = "";
|
if (tbody) tbody.innerHTML = "";
|
||||||
|
|
||||||
// 1) Regrouper par (start_date, end_date, description)
|
// 1) Regrouper par période pour éviter les doublons d'académies
|
||||||
const groups = new Map();
|
const groups = new Map();
|
||||||
|
|
||||||
records.forEach((record) => {
|
records.forEach((record) => {
|
||||||
@@ -174,28 +174,37 @@ function addSchoolHolidayEventsFromRecords(records, events) {
|
|||||||
const endIso = record.end_date;
|
const endIso = record.end_date;
|
||||||
const desc = record.description || "";
|
const desc = record.description || "";
|
||||||
const zones = record.zones || "";
|
const zones = record.zones || "";
|
||||||
|
|
||||||
const key = `${startIso}|${endIso}|${desc}`;
|
const key = `${startIso}|${endIso}|${desc}`;
|
||||||
|
|
||||||
if (!groups.has(key)) {
|
if (!groups.has(key)) {
|
||||||
groups.set(key, {
|
groups.set(key, { startIso, endIso, description: desc, zones });
|
||||||
startIso,
|
|
||||||
endIso,
|
|
||||||
description: desc,
|
|
||||||
zones,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 2) Tableau récap (une ligne par période, dates telles que fournies par l'API)
|
// 2) Remplir le tableau récap ET créer les événements pour la coloration
|
||||||
if (tbody) {
|
if (tbody) {
|
||||||
Array.from(groups.values())
|
Array.from(groups.values())
|
||||||
.sort((a, b) => new Date(a.startIso) - new Date(b.startIso))
|
.sort((a, b) => new Date(a.startIso) - new Date(b.startIso))
|
||||||
.forEach((g) => {
|
.forEach((g) => {
|
||||||
const start = new Date(g.startIso);
|
// On travaille avec des dates UTC pour éviter les décalages de fuseau horaire
|
||||||
const end = new Date(g.endIso);
|
const startDate = new Date(g.startIso);
|
||||||
const startStr = formatDayMonth(start) + "/" + start.getFullYear();
|
const endDate = new Date(g.endIso);
|
||||||
const endStr = formatDayMonth(end) + "/" + end.getFullYear();
|
|
||||||
|
// --- Logique pour le tableau récap ---
|
||||||
|
// Le 1er jour de vacances est le lendemain de start_date (ex: "vendredi soir" -> samedi)
|
||||||
|
const displayStartDate = new Date(startDate);
|
||||||
|
displayStartDate.setUTCDate(startDate.getUTCDate() + 1);
|
||||||
|
|
||||||
|
// La date de reprise est le lendemain de end_date
|
||||||
|
const repriseDate = new Date(endDate);
|
||||||
|
repriseDate.setUTCDate(endDate.getUTCDate() + 1);
|
||||||
|
|
||||||
|
const startStr =
|
||||||
|
formatDayMonth(displayStartDate) +
|
||||||
|
"/" +
|
||||||
|
displayStartDate.getFullYear();
|
||||||
|
const endStr =
|
||||||
|
formatDayMonth(repriseDate) + "/" + repriseDate.getFullYear();
|
||||||
|
|
||||||
const tr = document.createElement("tr");
|
const tr = document.createElement("tr");
|
||||||
tr.innerHTML = `
|
tr.innerHTML = `
|
||||||
@@ -205,33 +214,51 @@ function addSchoolHolidayEventsFromRecords(records, events) {
|
|||||||
<td>${g.zones}</td>
|
<td>${g.zones}</td>
|
||||||
`;
|
`;
|
||||||
tbody.appendChild(tr);
|
tbody.appendChild(tr);
|
||||||
|
|
||||||
|
// --- Logique pour la coloration du calendrier ---
|
||||||
|
// On boucle du 1er jour de vacances (start_date + 1) au dernier jour inclus (end_date)
|
||||||
|
let current = new Date(displayStartDate);
|
||||||
|
while (current <= endDate) {
|
||||||
|
const year = current.getFullYear();
|
||||||
|
const month = String(current.getMonth() + 1).padStart(2, "0");
|
||||||
|
const day = String(current.getDate()).padStart(2, "0");
|
||||||
|
const isoDate = `${year}-${month}-${day}`;
|
||||||
|
|
||||||
|
events.push({
|
||||||
|
date: isoDate,
|
||||||
|
type: "VACANCES_SCOLAIRES",
|
||||||
|
duration: 1,
|
||||||
|
});
|
||||||
|
|
||||||
|
current.setDate(current.getDate() + 1);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3) Créer les événements jour par jour (VACANCES_SCOLAIRES)
|
|
||||||
// end = date de reprise => on s'arrête la veille (current < end)
|
|
||||||
groups.forEach((g) => {
|
|
||||||
const start = new Date(g.startIso);
|
|
||||||
const end = new Date(g.endIso);
|
|
||||||
|
|
||||||
let current = new Date(start);
|
|
||||||
while (current < end) {
|
|
||||||
const year = current.getFullYear();
|
|
||||||
const month = String(current.getMonth() + 1).padStart(2, "0");
|
|
||||||
const day = String(current.getDate()).padStart(2, "0");
|
|
||||||
const isoDate = `${year}-${month}-${day}`;
|
|
||||||
|
|
||||||
events.push({
|
|
||||||
date: isoDate,
|
|
||||||
type: "VACANCES_SCOLAIRES",
|
|
||||||
duration: 1,
|
|
||||||
});
|
|
||||||
|
|
||||||
current.setDate(current.getDate() + 1);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 3) Créer les événements jour par jour (VACANCES_SCOLAIRES)
|
||||||
|
// end = date de reprise => on s'arrête la veille (current < end)
|
||||||
|
groups.forEach((g) => {
|
||||||
|
const start = new Date(g.startIso);
|
||||||
|
const end = new Date(g.endIso);
|
||||||
|
|
||||||
|
let current = new Date(start);
|
||||||
|
while (current < end) {
|
||||||
|
const year = current.getFullYear();
|
||||||
|
const month = String(current.getMonth() + 1).padStart(2, "0");
|
||||||
|
const day = String(current.getDate()).padStart(2, "0");
|
||||||
|
const isoDate = `${year}-${month}-${day}`;
|
||||||
|
|
||||||
|
events.push({
|
||||||
|
date: isoDate,
|
||||||
|
type: "VACANCES_SCOLAIRES",
|
||||||
|
duration: 1,
|
||||||
|
});
|
||||||
|
|
||||||
|
current.setDate(current.getDate() + 1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Marque les jours et les semaines de vacances scolaires dans weeks.
|
* Marque les jours et les semaines de vacances scolaires dans weeks.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user