From 2345ce8bf6f845ccf8bcb5e94af052236f44ad36 Mon Sep 17 00:00:00 2001
From: Dorian Lesbre <dorian.lesbre@gmail.com>
Date: Tue, 30 Mar 2021 10:28:53 +0200
Subject: [PATCH] Fixed multiday activites in planning

---
 home/templates/activites.html | 45 ++++++++++++++++++++++++++---------
 1 file changed, 34 insertions(+), 11 deletions(-)

diff --git a/home/templates/activites.html b/home/templates/activites.html
index 74190ae..496bba6 100644
--- a/home/templates/activites.html
+++ b/home/templates/activites.html
@@ -11,7 +11,10 @@
 	{% if settings.display_planning %}
 		<h2>Planning</h2>
 		<div id="planning"></div>
-
+<!--
+In order to limit the planning's width, we cheat using the timeline's groups
+I.E we set all dates to the first day (Friday) and set groups allowing vertical display:
+-->
 		<script type="text/javascript">
 			// https://visjs.org/
 			// DOM element where the Timeline will be attached
@@ -26,16 +29,36 @@
 			// Items in the timeline
 			const items = new vis.DataSet([
 				{% for act in planning %}
-				{
-					id: {{ act.id }},
-					content: '<a class="hidden" href="#{{ act.slug }}"><div><strong>{{ act.title }}</strong><br>{{ act.room }}</div></a>',
-					title: '<strong>{{ act.title }}</strong><br>{{ act.room }}',
-					start: '{{ settings.date_start|date:"Y-m-d"}} {{ act.start|date:"H:i:s" }}',
-					align: 'left',
-					group: {{ act.start|date:"d" }},
-					subgroup: '{{ act.room }}',
-					end:'{{ settings.date_start|date:"Y-m-d"}} {{ act.end|date:"H:i:s" }}'
-				},
+					{% if act.start|date:"d" == act.end|date:"d" %}
+					{
+						content: '<a class="hidden" href="#{{ act.slug }}"><div><strong>{{ act.title }}</strong><br>{{ act.room }}</div></a>',
+						title: '<strong>{{ act.title }}</strong><br>{{ act.room }}',
+						start: '{{ settings.date_start|date:"Y-m-d"}} {{ act.start|date:"H:i:s" }}',
+						align: 'left',
+						group: {{ act.start|date:"d" }},
+						subgroup: '{{ act.room }}',
+						end:'{{ settings.date_start|date:"Y-m-d"}} {{ act.end|date:"H:i:s" }}'
+					},
+					{% else %} // activity spans multiple days
+					{
+						content: '<a class="hidden" href="#{{ act.slug }}"><div><strong>{{ act.title }}</strong><br>{{ act.room }}</div></a>',
+						title: '<strong>{{ act.title }}</strong><br>{{ act.room }}',
+						start: '{{ settings.date_start|date:"Y-m-d"}} {{ act.start|date:"H:i:s" }}',
+						align: 'left',
+						group: {{ act.start|date:"d" }},
+						subgroup: '{{ act.room }}',
+						end:'{{ settings.date_start|date:"Y-m-d"}} 23:59:59'
+					},
+					{
+						content: '<a class="hidden" href="#{{ act.slug }}"><div><strong>{{ act.title }}</strong><br>{{ act.room }}</div></a>',
+						title: '<strong>{{ act.title }}</strong><br>{{ act.room }}',
+						start: '{{ settings.date_start|date:"Y-m-d"}} 00:00:00',
+						align: 'left',
+						group: {{ act.start|date:"d"|add:"1" }},
+						subgroup: '{{ act.room }}',
+						end:'{{ settings.date_start|date:"Y-m-d"}} {{ act.end|date:"H:i:s" }}'
+					},
+					{% endif %}
 				{% endfor %}
 			]);
 
-- 
GitLab