From de78f40b39b970570ffbd2d059a0329376141e75 Mon Sep 17 00:00:00 2001
From: Jonathan Weth <git@jonathanweth.de>
Date: Sat, 11 Jan 2020 15:06:53 +0100
Subject: [PATCH] Add mobile view with new vars in plan.html and move time
 cards to new file

---
 .../templates/chronos/period_time.html        | 20 +++++++
 .../apps/chronos/templates/chronos/plan.html  | 60 +++++--------------
 aleksis/apps/chronos/views.py                 | 18 +++---
 3 files changed, 45 insertions(+), 53 deletions(-)
 create mode 100644 aleksis/apps/chronos/templates/chronos/period_time.html

diff --git a/aleksis/apps/chronos/templates/chronos/period_time.html b/aleksis/apps/chronos/templates/chronos/period_time.html
new file mode 100644
index 00000000..83c27b7b
--- /dev/null
+++ b/aleksis/apps/chronos/templates/chronos/period_time.html
@@ -0,0 +1,20 @@
+{% load data_helpers %}
+
+<div class="card timetable-title-card">
+  <div class="card-content">
+
+    {# Lesson number #}
+    <span class="card-title left">
+                                {{ period }}.
+                            </span>
+
+    {# Time dimension of lesson #}
+    <div class="right timetable-time grey-text text-darken-2">
+      {% with period_obj=periods|get_dict:period %}
+        <span>{{ period_obj.0|date:"H:i" }}</span>
+        <br>
+        <span>{{ period_obj.1|date:"H:i" }}</span>
+      {% endwith %}
+    </div>
+  </div>
+</div>
diff --git a/aleksis/apps/chronos/templates/chronos/plan.html b/aleksis/apps/chronos/templates/chronos/plan.html
index 11a92c55..518d958b 100644
--- a/aleksis/apps/chronos/templates/chronos/plan.html
+++ b/aleksis/apps/chronos/templates/chronos/plan.html
@@ -191,26 +191,9 @@
 
       <div class="row">
         <div class="col s2">
-          <div class="card timetable-title-card">
-            <div class="card-content">
-
-              {# Lesson number #}
-              <span class="card-title left">
-                                {{ period }}.
-                            </span>
-
-              {# Time dimension of lesson #}
-              <div class="right timetable-time grey-text text-darken-2">
-                {% with period_obj=periods|get_dict:period %}
-                  <span>{{ period_obj.0|date:"H:i" }}</span>
-                  <br>
-                  <span>{{ period_obj.1|date:"H:i" }}</span>
-                {% endwith %}
-              </div>
-            </div>
-          </div>
-
+          {% include "chronos/period_time.html" with period=period periods=periods %}
         </div>
+
         {% for weekday, lessons in lesson_periods_period.items %}
           {# A lesson #}
           <div class="col s2">
@@ -223,44 +206,29 @@
 
   {# show 5 seperate ones on mobiles #}
   <div class="timetable-plan hide-on-med-and-up">
-    {% for day in long_week_days %}
+    {% for day in weekdays.items %}
       <div class="card timetable-mobile-title-card">
         <div class="card-content">
                     <span class="card-title">
-                        {{ day.0.0 }}
+                        {{ day.1 }}
                     </span>
-          {% if day.1 %}
-            <span class="badge new blue center-align holiday-badge">{{ day.1.0 }}</span>
-          {% endif %}
-          &nbsp;
+          {#          {% if day.1 %}#}
+          {#            <span class="badge new blue center-align holiday-badge">{{ day.1.0 }}</span>#}
+          {#          {% endif %}#}
+          {#          &nbsp;#}
         </div>
       </div>
-      {% for row, time in plan %}
+      {% for period, lesson_periods_period in lesson_periods.items %}
         <div class="row">
           <div class="col s4">
-            <div class="card timetable-title-card">
-              <div class="card-content">
-
-                {# Lesson number #}
-                <span class="card-title left">
-                                    {{ time.number_format }}
-                                </span>
-
-                {# Time dimension of lesson #}
-                <div class="right timetable-time grey-text text-darken-2">
-                  <span>{{ time.start|date:"H:i" }}</span>
-                  <br>
-                  <span>{{ time.end|date:"H:i" }}</span>
-                </div>
-              </div>
-            </div>
-
+            {% include "chronos/period_time.html" with period=period periods=periods %}
           </div>
-          {% for weekday, col in row %}
-            {% if forloop.counter0 == day.0.1 %}
+
+          {% for weekday, lessons in lesson_periods_period.items %}
+            {% if forloop.counter0|add:"1" == day.0 %}
               <div class="col s8">
                 {# A lesson #}
-                {% include "timetable/lesson.html" %}
+                {% include "chronos/lesson.html" with lessons=lessons %}
               </div>
             {% endif %}
           {% endfor %}
diff --git a/aleksis/apps/chronos/views.py b/aleksis/apps/chronos/views.py
index 057c8c6b..19a883e3 100644
--- a/aleksis/apps/chronos/views.py
+++ b/aleksis/apps/chronos/views.py
@@ -4,7 +4,7 @@ from typing import Optional
 
 from django.contrib.auth.decorators import login_required
 from django.db.models import Count, Max, Min
-from django.http import HttpRequest, HttpResponse
+from django.http import HttpRequest, HttpResponse, HttpResponseNotFound
 from django.shortcuts import get_object_or_404, redirect, render
 from django.urls import reverse
 from django.utils import timezone
@@ -43,6 +43,15 @@ def timetable(
 ) -> HttpResponse:
     context = {}
 
+    if _type == "group":
+        el = get_object_or_404(Group, pk=pk)
+    elif _type == "teacher":
+        el = get_object_or_404(Person, pk=pk)
+    elif _type == "room":
+        el = get_object_or_404(Room, pk=pk)
+    else:
+        return HttpResponseNotFound()
+
     if year and week:
         wanted_week = CalendarWeek(year=year, week=week)
     else:
@@ -50,12 +59,6 @@ def timetable(
 
     lesson_periods = LessonPeriod.objects.in_week(wanted_week)
 
-    # Incrementally filter lesson periods by GET parameters
-    # if (
-    #     request.GET.get("group", None)
-    #     or request.GET.get("teacher", None)
-    #     or request.GET.get("room", None)
-    # ):
 
     lesson_periods = lesson_periods.filter_from_type(_type, pk)
     # else:
@@ -120,6 +123,7 @@ def timetable(
     context["week"] = wanted_week
     context["type"] = _type
     context["pk"] = pk
+    context["el"] = el
 
     week_prev = wanted_week - 1
     week_next = wanted_week + 1
-- 
GitLab