From 83765b584e5488408c91be6e1607d8e5e03f87a5 Mon Sep 17 00:00:00 2001 From: Iziram Date: Mon, 13 Nov 2023 08:35:19 +0100 Subject: [PATCH] Assiduites : champs "heure_deb" "heure_fin" timeline --- app/templates/assiduites/widgets/timeline.j2 | 29 +++++++++++++++++--- app/views/assiduites.py | 19 +++++++++---- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/app/templates/assiduites/widgets/timeline.j2 b/app/templates/assiduites/widgets/timeline.j2 index 3a450708..9d614195 100644 --- a/app/templates/assiduites/widgets/timeline.j2 +++ b/app/templates/assiduites/widgets/timeline.j2 @@ -131,12 +131,12 @@ document.addEventListener( "mouseup", mouseUp, - {once:true} + { once: true } ); document.addEventListener( "touchend", mouseUp, - {once:true} + { once: true } ); } else if (event.target === periodTimeLine) { @@ -217,6 +217,14 @@ } function setPeriodValues(deb, fin) { + if (fin < deb) { + throw new RangeError(`le paramètre 'deb' doit être inférieur au paramètre 'fin' ([${deb};${fin}])`) + } + + if (deb < 0 || fin < 0) { + throw new RangeError(`Les paramètres doivent être des entiers positifis ([${deb};${fin}])`) + } + deb = snapToQuarter(deb); fin = snapToQuarter(fin); let leftPercentage = (deb - t_start) / (t_end - t_start) * 100; @@ -231,13 +239,13 @@ function snapHandlesToQuarters() { const periodValues = getPeriodValues(); - let lef = Math.min(computePercentage(periodValues[0], t_start), computePercentage(t_end, tick_delay)); + let lef = Math.min(computePercentage(Math.abs(periodValues[0]), t_start), computePercentage(Math.abs(t_end), tick_delay)); if (lef < 0) { lef = 0; } const left = `${lef}%`; - let wid = Math.max(computePercentage(periodValues[1], periodValues[0]), computePercentage(tick_delay, 0)); + let wid = Math.max(computePercentage(Math.abs(periodValues[1]), Math.abs(periodValues[0])), computePercentage(tick_delay, 0)); if (wid > 100) { wid = 100; } @@ -251,10 +259,23 @@ function computePercentage(a, b) { return ((a - b) / (t_end - t_start)) * 100; } + function fromTime(time, separator = ":") { + const [hours, minutes] = time.split(separator).map((el) => Number(el)) + return hours + minutes / 60 + } createTicks(); setPeriodValues(t_start, t_start + period_default); + {% if heures %} + let [heure_deb, heure_fin] = [{{ heures | safe }}] + if (heure_deb != '' && heure_fin != '') { + heure_deb = fromTime(heure_deb); + heure_fin = fromTime(heure_fin); + setPeriodValues(heure_deb, heure_fin) + } + {% endif %} +