From 228b86f8be3da39f00d3e91ffd9632136eae0825 Mon Sep 17 00:00:00 2001
From: Jonathan Weth <git@jonathanweth.de>
Date: Thu, 2 Apr 2020 14:38:00 +0200
Subject: [PATCH] Add option to shorten groups via text collapsible

- Add CSS fix for correct style of text collapsibles in timetables

Advances #71
---
 aleksis/apps/chronos/settings.py                   | 14 ++++++++++++++
 .../apps/chronos/static/css/chronos/timetable.css  |  2 +-
 .../chronos/templates/chronos/partials/group.html  |  3 +++
 .../templates/chronos/partials/groups_part.html    | 12 +++++++-----
 4 files changed, 25 insertions(+), 6 deletions(-)
 create mode 100644 aleksis/apps/chronos/templates/chronos/partials/group.html

diff --git a/aleksis/apps/chronos/settings.py b/aleksis/apps/chronos/settings.py
index 9c0df07f..559cdca9 100644
--- a/aleksis/apps/chronos/settings.py
+++ b/aleksis/apps/chronos/settings.py
@@ -9,6 +9,18 @@ CONSTANCE_CONFIG = {
             " show the parent groups instead of the original group."
         ),
     ),
+    "CHRONOS_SHORTEN_GROUPS": (
+        False,
+        _(
+            "If there are more groups than the limit set in CHRONOS_SHORTEN_GROUPS_LIMIT, add text collapsible."
+        ),
+    ),
+    "CHRONOS_SHORTEN_GROUPS_LIMIT": (
+        4,
+        _(
+            "If there are more groups than this limit and CHRONOS_SHORTEN_GROUPS is enabled, add text collapsible."
+        ),
+    ),
     "CHRONOS_SUBSTITUTIONS_PRINT_DAY_NUMBER": (
         2,
         _("Number of days shown on substitutions print view"),
@@ -21,6 +33,8 @@ CONSTANCE_CONFIG = {
 CONSTANCE_CONFIG_FIELDSETS = {
     "Chronos settings": (
         "CHRONOS_USE_PARENT_GROUPS",
+        "CHRONOS_SHORTEN_GROUPS",
+        "CHRONOS_SHORTEN_GROUPS_LIMIT",
         "CHRONOS_SUBSTITUTIONS_PRINT_DAY_NUMBER",
         "CHRONOS_SUBSTITUTIONS_SHOW_HEADER_BOX",
     ),
diff --git a/aleksis/apps/chronos/static/css/chronos/timetable.css b/aleksis/apps/chronos/static/css/chronos/timetable.css
index 16846c60..c25d6750 100644
--- a/aleksis/apps/chronos/static/css/chronos/timetable.css
+++ b/aleksis/apps/chronos/static/css/chronos/timetable.css
@@ -35,7 +35,7 @@ li.active > a > .sidenav-badge {
     flex-direction: column;
 }
 
-.lesson-card .card-content div {
+.lesson-card .card-content > div {
     padding: 3px;
     flex: auto;
     width: 100%;
diff --git a/aleksis/apps/chronos/templates/chronos/partials/group.html b/aleksis/apps/chronos/templates/chronos/partials/group.html
new file mode 100644
index 00000000..d2e345d5
--- /dev/null
+++ b/aleksis/apps/chronos/templates/chronos/partials/group.html
@@ -0,0 +1,3 @@
+<a href="{% url "timetable" "group" item.pk %}">
+  {{ item.short_name }}{% if not forloop.last %},{% endif %}
+</a>
diff --git a/aleksis/apps/chronos/templates/chronos/partials/groups_part.html b/aleksis/apps/chronos/templates/chronos/partials/groups_part.html
index 3ccfc00c..fea197c9 100644
--- a/aleksis/apps/chronos/templates/chronos/partials/groups_part.html
+++ b/aleksis/apps/chronos/templates/chronos/partials/groups_part.html
@@ -1,5 +1,7 @@
-{% for group in groups %}
-  <a href="{% url "timetable" "group" group.pk %}">
-    {{ group.short_name }}{% if not forloop.last %},{% endif %}
-  </a>
-{% endfor %}
+{% if groups.count > config.CHRONOS_SHORTEN_GROUPS_LIMIT and config.CHRONOS_SHORTEN_GROUPS %}
+  {% include "components/text_collapsible.html" with template="chronos/partials/group.html" qs=groups %}
+{% else %}
+  {% for group in groups %}
+    {% include "chronos/partials/group.html" with item=group %}
+  {% endfor %}
+{% endif %}
-- 
GitLab