ScoDoc/app/templates/assiduites/pages/calendrier.j2

590 lines
19 KiB
Plaintext
Raw Normal View History

{% block pageContent %}
{% include "assiduites/widgets/alert.j2" %}
<div class="pageContent">
{{minitimeline | safe }}
<h2>Assiduité de {{sco.etud.nomprenom}}</h2>
2023-11-15 17:34:13 +01:00
<div class="options">
2023-11-16 02:48:39 +01:00
<input type="checkbox" id="show_pres" name="show_pres"><label for="show_pres">afficher les présences</label>
<input type="checkbox" name="show_reta" id="show_reta"><label for="show_reta">afficher les retards</label>
<input type="checkbox" name="mode_demi" id="mode_demi"><label for="mode_demi">mode demi journée</label>
2023-11-15 17:34:13 +01:00
</div>
<div class="calendrier">
</div>
<div class="annee">
2023-11-15 17:34:13 +01:00
<span id="label-annee">Année scolaire 2022-2023</span><span id="label-changer" style="margin-left: 5px;">Changer
année: </span>
<select name="" id="annee" onchange="setterAnnee(this.value)">
</select>
2023-11-15 17:34:13 +01:00
<span id="label-nom">Assiduité de {{sco.etud.nomprenom}}</span>
</div>
2023-06-30 14:38:56 +02:00
<div class="help">
2023-06-30 14:38:56 +02:00
<h3>Calendrier</h3>
<p>Les jours non travaillés sont affiché en violet</p>
<p>Les jours possèdant une bordure "bleu" sont des jours où des absences/retards ont été justifiées par un
2023-06-30 14:38:56 +02:00
justificatif valide</p>
<p>Les jours possèdant une bordure "rouge" sont des jours où des absences/retards ont été justifiées par un
2023-06-30 14:38:56 +02:00
justificatif non valide</p>
<p>Le jour sera affiché en : </p>
<ul>
<li>Rouge : s'il y a une absence enregistrée</li>
<li>Orange : s'il y a un retard et pas d'absence</li>
<li>Vert : s'il y a une présence enregistrée mais pas d'absence ni de retard</li>
<li>Blanc : s'il n'y a rien d'enregistré</li>
2023-06-30 14:38:56 +02:00
</ul>
<p>Vous pouvez passer le curseur sur les jours colorés afin de voir les informations de cette journée.</p>
2023-06-30 14:38:56 +02:00
</div>
</div>
2023-11-15 17:34:13 +01:00
<style>
2023-11-15 17:34:13 +01:00
:root {
--color-present: #6bdb83;
--color-absent: #F1A69C;
--color-retard: #f0c865;
2023-11-16 02:48:39 +01:00
--color-nonwork: #badfff;
2023-11-15 17:34:13 +01:00
--color-defaut: #FFF;
}
.color.present {
background-color: var(--color-present);
}
.color.absent {
background-color: var(--color-absent);
}
.color.retard {
background-color: var(--color-retard);
}
.color.nonwork {
background-color: var(--color-nonwork);
}
.color {
background-color: var(--color-defaut);
}
.pageContent {
margin-top: 1vh;
max-width: var(--sco-content-max-width);
}
.calendrier {
display: flex;
justify-content: space-evenly;
flex-wrap: wrap;
border: 1px solid #444;
2023-11-16 02:48:39 +01:00
border-radius: 12px;
margin-bottom: 12px;
}
2023-11-15 17:34:13 +01:00
.month h3 {
text-align: center;
}
2023-11-15 17:34:13 +01:00
.day,
.demi .day.color.color.nonwork {
/* border: 1px solid #444; */
/* border-radius: 8px; */
text-align: center;
margin: 2px;
cursor: default;
2023-11-16 02:48:39 +01:00
font-size: 13px;
position: relative;
2023-11-16 02:48:39 +01:00
font-weight: normal;
2023-11-15 17:34:13 +01:00
min-width: 6em;
}
2023-11-15 17:34:13 +01:00
.demi .day {
border-radius: none;
}
2023-11-15 17:34:13 +01:00
.day.est_just,
.demi .day span.est_just {
background-image: repeating-linear-gradient(135deg, transparent, transparent 4px, #7059FFA0 4px, #7059FFA0 8px);
}
.day.est_just.invalide,
.demi .day span.invalide {
background-image: repeating-linear-gradient(-135deg, transparent, transparent 4px, #d61616A0 4px, #d61616A0 8px);
}
.day .dayline {
position: absolute;
display: none;
left: -237%;
bottom: -420%;
z-index: 50;
width: 250px;
height: 75px;
background-color: #dedede;
border-radius: 15px;
padding: 5px;
}
.day:hover .dayline {
display: block;
}
.dayline .mini-timeline {
margin-top: 14%;
}
.dayline .mini_tick {
position: absolute;
text-align: center;
top: 0;
transform: translateY(-110%);
z-index: 50;
}
.dayline .mini_tick::after {
display: block;
content: "|";
position: absolute;
bottom: -69%;
z-index: 2;
transform: translateX(200%);
}
2023-11-15 17:34:13 +01:00
#label-nom {
display: none;
}
.demi .day {
display: flex;
justify-content: space-evenly;
}
.demi .day>span {
display: block;
flex: 1;
text-align: center;
z-index: 1;
width: 100%;
2023-11-16 02:48:39 +01:00
border: 1px solid #d5d5d5;
2023-11-15 17:34:13 +01:00
/*border-radius: 3px;*/
}
.demi .day>span:first-of-type {
width: 3em;
min-width: 3em;
}
.options>* {
margin-right: 5px;
}
2023-11-16 02:48:39 +01:00
.options input {
margin-right: 6px;
}
.options label {
font-weight: normal;
margin-right: 16px;
}
2023-11-15 17:34:13 +01:00
@media print {
.color.present {
background-color: var(--color-present) !important;
print-color-adjust: exact !important;
}
.color.absent {
background-color: var(--color-absent) !important;
print-color-adjust: exact !important;
}
.color.retard {
background-color: var(--color-retard) !important;
print-color-adjust: exact !important;
}
.color.nonwork {
background-color: var(--color-nonwork) !important;
print-color-adjust: exact !important;
}
.day.est_just,
.demi .day span.est_just {
background-image: repeating-linear-gradient(135deg, transparent, transparent 4px, #7059FFA0 4px, #7059FFA0 8px) !important;
print-color-adjust: exact !important;
}
.day.est_just.invalide,
.demi .day span.invalide {
print-color-adjust: exact !important;
background-image: repeating-linear-gradient(-135deg, transparent, transparent 4px, #d61616A0 4px, #d61616A0 8px) !important;
}
#sidebar,
.help,
h2,
#annee,
#label-changer,
.options {
display: none;
}
#label-nom {
display: inline;
}
#gtrcontent {
margin: 5px;
}
}
</style>
<script>
function getDaysBetweenDates(start, end) {
2023-11-08 15:12:42 +01:00
let now = new Date(start);
end = new Date(end);
let dates = [];
2023-11-08 15:12:42 +01:00
while (now.isBefore(end) || now.isSame(end)) {
dates.push(now.clone());
now.add(1, "days");
}
return dates;
}
function organizeByMonth(dates) {
let datesByMonth = {};
dates.forEach((date) => {
2023-11-03 16:55:26 +01:00
let month = date.toLocaleString('fr-FR', { month: "short" }); // Obtenir le mois
if (!datesByMonth[month]) {
datesByMonth[month] = [];
}
datesByMonth[month].push(date);
});
return datesByMonth;
}
function organizeAssiduitiesByDay(datesByMonth, assiduities, justificatifs) {
let assiduitiesByDay = {};
Object.keys(datesByMonth).forEach((month) => {
assiduitiesByDay[month] = {};
datesByMonth[month].forEach((date) => {
let dayAssiduities = assiduities.filter((assiduity) => {
2023-11-03 16:55:26 +01:00
return new Date(date).isBetween(
new Date(assiduity.date_debut).startOf("day"),
new Date(assiduity.date_fin).startOf("day"),
"[]"
)
});
let dayJustificatifs = justificatifs.filter((justif) => {
2023-11-03 16:55:26 +01:00
return new Date(date).isBetween(
new Date(justif.date_debut).startOf("day"),
new Date(justif.date_fin).startOf("day"),
"[]"
)
});
2023-11-08 15:12:42 +01:00
assiduitiesByDay[month][date.toLocaleDateString("en-US")] = {
assiduites: dayAssiduities,
justificatifs: dayJustificatifs
};
});
});
return assiduitiesByDay;
}
function getDayColor(etat) {
let color;
switch (etat.toUpperCase()) {
case "PRESENT":
2023-11-15 17:34:13 +01:00
color = "";
break;
case "ABSENT":
color = "#F1A69C";
break;
case "RETARD":
color = "#f0c865";
break;
case "NONWORK":
color = "#bd81ca"
break;
default:
color = "#FFF";
break;
}
return color;
}
function generateCalendar(assiduitiesByDay, nonWorkdays = []) {
const calendar = document.querySelector('.calendrier')
2023-11-15 17:34:13 +01:00
const options = getOptions();
calendar.innerHTML = ""
const days = {
2023-11-08 15:12:42 +01:00
1: "Lun",
2: "Mar",
3: "Mer",
4: "Jeu",
5: "Ven",
6: "Sam",
0: "Dim",
};
Object.keys(assiduitiesByDay).forEach((month) => {
const monthEl = document.createElement('div')
monthEl.classList.add("month")
2023-11-15 17:34:13 +01:00
const title = document.createElement('h3');
2023-11-08 15:12:42 +01:00
title.textContent = `${month.capitalize()}`;
monthEl.appendChild(title)
const daysEl = document.createElement('div')
daysEl.classList.add('days');
2023-11-15 17:34:13 +01:00
if (options.mode_demi) daysEl.classList.add("demi");
Object.keys(assiduitiesByDay[month]).forEach((date) => {
let dayAssiduities = assiduitiesByDay[month][date].assiduites;
let dayJustificatifs = assiduitiesByDay[month][date].justificatifs;
2023-11-15 17:34:13 +01:00
let color = "";
if (dayAssiduities.some((a) => a.etat.toLowerCase() === "absent")) color = "absent";
2023-11-15 17:34:13 +01:00
else if (dayAssiduities.some((a) => a.etat.toLowerCase() === "retard") && options.show_reta)
color = "retard";
2023-11-15 17:34:13 +01:00
else if (dayAssiduities.some((a) => a.etat.toLowerCase() === "present") && options.show_pres)
color = "present";
2023-11-15 17:34:13 +01:00
let est_just = ""
if (dayJustificatifs.some((j) => j.etat.toLowerCase() === "valide")) {
est_just = "est_just";
} else if (dayJustificatifs.some((j) => j.etat.toLowerCase() !== "valide")) {
est_just = "est_just invalide";
}
2023-11-03 16:55:26 +01:00
const momentDate = new Date(date);
2023-11-08 15:12:42 +01:00
let dayOfMonth = momentDate.getDate();
let dayOfWeek = momentDate.getDay();
dayOfWeek = days[dayOfWeek];
2023-11-15 17:34:13 +01:00
let isWorkDay = nonWorkdays.includes(dayOfWeek.toLowerCase());
const day = document.createElement('div');
2023-11-15 17:34:13 +01:00
day.className = `day`;
if (isWorkDay) {
color = "nonwork";
} else if (!options.mode_demi) {
day.className = `day ${est_just}`;
}
2023-11-15 17:34:13 +01:00
if (options.mode_demi && !isWorkDay) {
est_just = []
// affichage n° jour + matin + aprem
const span_jour = document.createElement("span")
span_jour.textContent = dayOfMonth + dayOfWeek[0];
const span_matin = document.createElement("span");
span_matin.classList.add("color");
const matin = [new Date(date), new Date(date)]
color = ""
matin[0].setHours(0, 0, 0, 0)
matin[1].setHours(12, 59, 59)
const assiduitesMatin = dayAssiduities.filter((el) => {
const deb = new Date(el.date_debut);
const fin = new Date(el.date_fin);
return deb.isBetween(matin[0], matin[1]) || fin.isBetween(matin[0], matin[1])
})
const justificatifsMatin = dayJustificatifs.filter((el) => {
const deb = new Date(el.date_debut);
const fin = new Date(el.date_fin);
return deb.isBetween(matin[0], matin[1]) || fin.isBetween(matin[0], matin[1])
})
if (assiduitesMatin.some((a) => a.etat.toLowerCase() === "absent")) color = "absent";
else if (assiduitesMatin.some((a) => a.etat.toLowerCase() === "retard") && options.show_reta)
color = "retard";
else if (assiduitesMatin.some((a) => a.etat.toLowerCase() === "present") && options.show_pres)
color = "present";
if (color != "") {
span_matin.classList.add(color);
}
if (justificatifsMatin.some((j) => j.etat.toLowerCase() === "valide")) {
est_just = ["est_just"];
} else if (justificatifsMatin.some((j) => j.etat.toLowerCase() !== "valide")) {
est_just = ["est_just", "invalide"];
}
span_matin.classList.add(...est_just)
est_just = []
const span_aprem = document.createElement("span");
span_aprem.classList.add("color");
const aprem = [new Date(date), new Date(date)]
color = ""
aprem[0].setHours(13, 0, 0, 0)
aprem[1].setHours(23, 59, 59)
const assiduitesAprem = dayAssiduities.filter((el) => {
const deb = new Date(el.date_debut);
const fin = new Date(el.date_fin);
return deb.isBetween(aprem[0], aprem[1]) || fin.isBetween(aprem[0], aprem[1])
})
const justificatifsAprem = dayJustificatifs.filter((el) => {
const deb = new Date(el.date_debut);
const fin = new Date(el.date_fin);
return deb.isBetween(aprem[0], aprem[1]) || fin.isBetween(aprem[0], aprem[1])
})
if (assiduitesAprem.some((a) => a.etat.toLowerCase() === "absent")) color = "absent";
else if (assiduitesAprem.some((a) => a.etat.toLowerCase() === "retard") && options.show_reta)
color = "retard";
else if (assiduitesAprem.some((a) => a.etat.toLowerCase() === "present") && options.show_pres)
color = "present";
if (color != "") {
span_aprem.classList.add(color);
}
if (justificatifsAprem.some((j) => j.etat.toLowerCase() === "valide")) {
est_just = ["est_just"];;
} else if (justificatifsAprem.some((j) => j.etat.toLowerCase() !== "valide")) {
est_just = ["est_just", "invalide"];;
}
span_matin.classList.add(...est_just)
day.appendChild(span_jour)
day.appendChild(span_matin)
day.appendChild(span_aprem)
} else {
day.classList.add("color")
if (color != "") {
day.classList.add(color);
}
day.textContent = `${dayOfWeek} ${dayOfMonth}`;
}
2023-06-23 16:12:36 +02:00
if (!nonWorkdays.includes(dayOfWeek.toLowerCase()) && dayAssiduities.length > 0) {
const cache = document.createElement('div')
cache.classList.add('dayline');
cache.appendChild(
createMiniTimeline(dayAssiduities, date)
)
day.appendChild(cache)
}
daysEl.appendChild(day);
});
monthEl.appendChild(daysEl)
calendar.appendChild(monthEl)
});
}
function getEtudAssiduites(deb, fin, callback = () => { }) {
const url_api =
getUrl() +
`/api/assiduites/${etudid}/query?date_debut=${deb}&date_fin=${fin}`;
2023-11-15 17:34:13 +01:00
async_get(url_api, (data) => {
callback(data);
});
}
2023-11-15 17:34:13 +01:00
function getOptions() {
return {
"show_pres": document.getElementById("show_pres").checked,
"show_reta": document.getElementById("show_reta").checked,
"mode_demi": document.getElementById("mode_demi").checked,
}
}
function getEtudJustificatifs(deb, fin) {
let list = [];
const url_api =
getUrl() +
`/api/justificatifs/${etudid}/query?date_debut=${deb}&date_fin=${fin}`;
sync_get(url_api, (data, status) => {
if (status === "success") {
list = data;
}
});
return list
}
function generate(annee) {
if (annee < 1999 || annee > 2999) {
openAlertModal("Année impossible", document.createTextNode("L'année demandé n'existe pas."));
return;
}
const bornes = {
deb: `${annee}-09-01T00:00`,
2023-07-25 14:06:49 +02:00
fin: `${annee + 1}-08-31T23:59`
}
let assiduities = getEtudAssiduites(bornes.deb, bornes.fin, (data) => {
let dates = getDaysBetweenDates(bornes.deb, bornes.fin);
let datesByMonth = organizeByMonth(dates);
const justifs = getEtudJustificatifs(bornes.deb, bornes.fin);
let assiduitiesByDay = organizeAssiduitiesByDay(datesByMonth, data, justifs);
generateCalendar(assiduitiesByDay, nonwork);
});
}
function setterAnnee(annee) {
annee = parseInt(annee);
2023-11-15 17:34:13 +01:00
document.querySelector('.annee #label-annee').textContent = `Année scolaire ${annee}-${annee + 1}`
generate(annee)
}
2023-11-15 17:34:13 +01:00
const defAnnee = {{ annee }}
let annees = {{ annees | safe }}
annees = annees.filter((x, i) => annees.indexOf(x) === i)
const etudid = {{ sco.etud.id }};
const nonwork = [{{ nonworkdays | safe }}];
window.onload = () => {
const select = document.querySelector('#annee');
annees.forEach((a) => {
const opt = document.createElement("option");
opt.value = a + "",
opt.textContent = `${a} - ${a + 1}`;
if (a === defAnnee) {
opt.selected = true;
}
select.appendChild(opt)
})
2023-11-15 17:34:13 +01:00
document.querySelectorAll(".options input").forEach((e) => {
e.addEventListener("click", () => {
setterAnnee(select.value)
})
})
setterAnnee(defAnnee)
};
2023-09-11 15:55:18 +02:00
function isCalendrier() { return true }
</script>
2023-11-16 02:48:39 +01:00
{% endblock pageContent %}