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

693 lines
21 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" checked><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>Code couleur</p>
<ul class="couleurs">
<li><span title="Vert" class="present demo"></span> &rightarrow; présence de l'étudiant lors de la période
</li>
<li><span title="Bleu clair" class="nonwork demo"></span> &rightarrow; la période n'est pas travaillée
</li>
<li><span title="Rouge" class="absent demo"></span> &rightarrow; absence de l'étudiant lors de la période
</li>
<li><span title="Rose" class="demo color absent est_just"></span> &rightarrow; absence justifiée
</li>
<li><span title="Orange" class="retard demo"></span> &rightarrow; retard de l'étudiant lors de la période
</li>
<li><span title="Jaune clair" class="demo color retard est_just"></span> &rightarrow; retard justifié
</li>
<li><span title="Quart Bleu" class="est_just demo"></span> &rightarrow; la période est justifiée par un
justificatif valide</li>
<li><span title="Quart Violet" class="invalide demo"></span> &rightarrow; la période est
justifiée par un justificatif non valide / en attente de validation
</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 supplémentaires</p>
2023-06-30 14:38:56 +02:00
</div>
<ul class="couleurs print">
<li><span title="Vert" class="present demo"></span> présence
</li>
<li><span title="Bleu clair" class="nonwork demo"></span> non travaillé
</li>
<li><span title="Rouge" class="absent demo"></span> absence
</li>
<li><span title="Rose" class="demo color absent est_just"></span> absence justifiée
</li>
<li><span title="Orange" class="retard demo"></span> retard
</li>
<li><span title="Jaune clair" class="demo color retard est_just"></span>retard justifié
</li>
<li><span title="Quart Bleu" class="est_just demo"></span>
justificatif valide</li>
<li><span title="Quart Violet" class="invalide demo"></span> justificatif non valide
</li>
</ul>
</div>
<style>
.help .couleurs {
grid-template-columns: 2;
grid-template-rows: auto;
display: grid;
}
.couleurs.print {
display: none;
}
2023-11-15 17:34:13 +01:00
.help .couleurs li:nth-child(odd) {
grid-column: 1;
list-style-type: none;
}
2023-11-15 17:34:13 +01:00
.help .couleurs li:nth-child(even) {
grid-column: 2;
list-style-type: none;
2023-11-15 17:34:13 +01:00
}
.color.present {
background-color: var(--color-present) !important;
2023-11-15 17:34:13 +01:00
}
.color.absent {
background-color: var(--color-absent) !important;
}
.color.absent.est_just {
background-color: var(--color-absent-justi) !important;
2023-11-15 17:34:13 +01:00
}
.color.retard {
background-color: var(--color-retard) !important;
}
.color.retard.est_just {
background-color: var(--color-retard-justi) !important;
2023-11-15 17:34:13 +01:00
}
.color.nonwork {
background-color: var(--color-nonwork) !important;
2023-11-15 17:34:13 +01:00
}
.color {
background-color: var(--color-defaut) !important;
2023-11-15 17:34:13 +01:00
}
.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.nonwork {
text-align: left;
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;
display: flex;
justify-content: start;
}
.color.est_just.sans_etat::before {
content: "";
position: absolute;
width: 25%;
height: 100%;
background-color: var(--color-justi) !important;
right: 0;
}
.color.invalide::before {
content: "";
position: absolute;
width: 25%;
height: 100%;
right: 0;
background-color: var(--color-justi-invalide) !important;
}
2023-11-15 17:34:13 +01:00
.demo.invalide {
background-color: var(--color-justi-invalide) !important;
2023-11-15 17:34:13 +01:00
}
.demo.est_just {
background-color: var(--color-justi) !important;
}
.demi .day.nonwork>span {
flex: none;
border: none;
}
.demi .day {
border-radius: 0;
}
.day .dayline {
position: absolute;
display: none;
bottom: -390%;
z-index: 50;
width: max-content;
height: 75px;
background-color: #dedede;
border-radius: 15px;
padding: 5px;
}
.day:hover .dayline {
display: block;
}
.dayline .mini-timeline {
margin-top: 10%;
}
.dayline-title {
margin: 0;
}
.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,
#label-justi {
2023-11-15 17:34:13 +01:00
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;
position: relative;
2023-11-15 17:34:13 +01:00
}
.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;
}
2023-11-16 02:48:39 +01:00
.options label {
font-weight: normal;
margin-right: 16px;
}
2023-11-15 17:34:13 +01:00
@media print {
.couleurs.print {
display: flex;
justify-content: space-evenly;
align-items: center;
2023-11-15 17:34:13 +01:00
}
.couleurs.print li {
list-style-type: none !important;
-webkit-print-color-adjust: exact !important;
2023-11-15 17:34:13 +01:00
print-color-adjust: exact !important;
}
.day,
.demi .day.color.color.nonwork {
min-width: 5em;
font-size: 11px;
}
.demi .day>span:first-of-type {
width: 2.5em;
min-width: 2.5em;
2023-11-15 17:34:13 +01:00
}
.color {
-webkit-print-color-adjust: exact !important;
2023-11-15 17:34:13 +01:00
print-color-adjust: exact !important;
}
.day.est_just,
.demi .day span.est_just {
background-image: none;
2023-11-15 17:34:13 +01:00
}
.day.invalide,
2023-11-15 17:34:13 +01:00
.demi .day span.invalide {
background-image: none;
2023-11-15 17:34:13 +01:00
}
.demi .day span.est_just::before {
content: "J";
}
.demi .day span.invalide::before {
content: "JI";
}
2023-11-15 17:34:13 +01:00
#sidebar,
.help,
h2,
#annee,
#label-changer,
.options {
display: none;
}
#label-nom,
#label-justi {
2023-11-15 17:34:13 +01:00
display: inline;
}
#gtrcontent {
margin: 5px;
}
.annee {
display: flex;
justify-content: space-evenly;
align-items: center;
}
2023-11-15 17:34:13 +01:00
}
</style>
<script>
2023-11-22 15:53:25 +01:00
const datePivot = "{{scu.get_assiduites_time_config("pivot")}}".split(":").map((el) => Number(el))
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"),
2023-12-06 17:13:44 +01:00
new Date(assiduity.date_fin).endOf("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"),
2023-12-06 17:13:44 +01:00
new Date(justif.date_fin).endOf("day"),
"[]"
)
});
2023-11-08 15:12:42 +01:00
assiduitiesByDay[month][date.toLocaleDateString("en-US")] = {
assiduites: dayAssiduities,
justificatifs: dayJustificatifs
};
});
});
return assiduitiesByDay;
}
function generateCalendar(assiduitiesByDay, nonWorkdays = []) {
2023-12-06 17:13:44 +01:00
// assiduitiesByDay[month][date] avec date au format m/d/y !!!
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",
};
2023-12-06 17:13:44 +01:00
// XXX formats de données très exotiques !
// XXX assiduitiesByDay["oct."]["10/12/2023"]
// XXX Object { assiduites: [], justificatifs: [] }
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;
let color = "sans_etat";
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 = "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-20 16:55:26 +01:00
let isNonWorkDayVar = nonWorkdays.includes(dayOfWeek.toLowerCase());
const day = document.createElement('div');
2023-11-15 17:34:13 +01:00
day.className = `day`;
2023-11-20 16:55:26 +01:00
if (isNonWorkDayVar) {
2023-11-15 17:34:13 +01:00
color = "nonwork";
} else if (!options.mode_demi) {
day.className = `day ${est_just}`;
}
2023-11-20 16:55:26 +01:00
if (options.mode_demi && !isNonWorkDayVar) {
2023-11-15 17:34:13 +01:00
est_just = []
// affichage n° jour + matin + aprem
const span_jour = document.createElement("span")
span_jour.textContent = dayOfWeek[0] + dayOfMonth;
2023-11-15 17:34:13 +01:00
const span_matin = document.createElement("span");
span_matin.classList.add("color");
const matin = [new Date(date), new Date(date)]
color = "sans_etat"
2023-11-15 17:34:13 +01:00
matin[0].setHours(0, 0, 0, 0)
2023-11-22 15:53:25 +01:00
matin[1].setHours(...datePivot)
2023-11-15 17:34:13 +01:00
2023-11-15 17:34:13 +01:00
const assiduitesMatin = dayAssiduities.filter((el) => {
const deb = new Date(el.date_debut);
const fin = new Date(el.date_fin);
return Date.intersect({ deb: deb, fin: fin }, { deb: matin[0], fin: matin[1] })
2023-11-15 17:34:13 +01:00
})
const justificatifsMatin = dayJustificatifs.filter((el) => {
const deb = new Date(el.date_debut);
const fin = new Date(el.date_fin);
return Date.intersect({ deb: deb, fin: fin }, { deb: matin[0], fin: matin[1] })
2023-11-15 17:34:13 +01:00
})
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 = ["invalide"];
2023-11-15 17:34:13 +01:00
}
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 = "sans_etat"
2023-11-22 15:53:25 +01:00
aprem[0].setHours(...datePivot)
aprem[0].add(1, "seconds")
2023-11-15 17:34:13 +01:00
aprem[1].setHours(23, 59, 59)
2023-11-15 17:34:13 +01:00
const assiduitesAprem = dayAssiduities.filter((el) => {
const deb = new Date(el.date_debut);
const fin = new Date(el.date_fin);
return Date.intersect({ deb: deb, fin: fin }, { deb: aprem[0], fin: aprem[1] })
2023-11-15 17:34:13 +01:00
})
const justificatifsAprem = dayJustificatifs.filter((el) => {
const deb = new Date(el.date_debut);
const fin = new Date(el.date_fin);
return Date.intersect({ deb: deb, fin: fin }, { deb: aprem[0], fin: aprem[1] })
2023-11-15 17:34:13 +01:00
})
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"];
2023-11-15 17:34:13 +01:00
} else if (justificatifsAprem.some((j) => j.etat.toLowerCase() !== "valide")) {
est_just = ["invalide"];
2023-11-15 17:34:13 +01:00
}
span_aprem.classList.add(...est_just)
2023-11-15 17:34:13 +01:00
day.appendChild(span_jour)
day.appendChild(span_matin)
day.appendChild(span_aprem)
2023-11-15 17:34:13 +01:00
} else {
day.classList.add("color")
if (color != "") {
day.classList.add(color);
}
2023-11-20 16:55:26 +01:00
if (isNonWorkDayVar) {
const span_jour = document.createElement("span")
span_jour.textContent = dayOfWeek[0] + dayOfMonth;
day.appendChild(span_jour);
} else {
day.textContent = `${dayOfWeek} ${dayOfMonth}`;
}
2023-11-15 17:34:13 +01:00
}
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');
const title = document.createElement('div')
title.className = "dayline-title";
title.innerHTML = "<span>Assiduité du </span><br>" + `<span>${formatDate(momentDate)}</span>`;
cache.appendChild(title)
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-12-06 17:13:44 +01:00
{% endblock pageContent %}