From dd9afca5363a89273ddddcc504f953bcbc7eb57c Mon Sep 17 00:00:00 2001
From: Martin Mares <mj@ucw.cz>
Date: Mon, 23 Mar 2020 23:55:16 +0100
Subject: [PATCH] App: Math/CS switch

---
 app/templates/main.html | 11 ++++++++---
 app/zoom.py             | 39 +++++++++++++++++++++++++++------------
 2 files changed, 35 insertions(+), 15 deletions(-)

diff --git a/app/templates/main.html b/app/templates/main.html
index 6b138a7..8e4eae8 100644
--- a/app/templates/main.html
+++ b/app/templates/main.html
@@ -53,6 +53,7 @@
 </head>
 <body>
 	<h1>MFF Zoom</h1>
+	<p><b>This is still experimental, there might be dragons. Please report all bugs to Martin Mareš.</b>
 	<form method=GET action="?">
 		<label for=date>Date:</label>
 		<input id=date type=date name=date value="{{ g.date }}">
@@ -60,23 +61,27 @@
 			<option value=0{{ " selected" if g.hours==0 else "" }}>Working hours</option>
 			<option value=1{{ " selected" if g.hours==1 else "" }}>Whole day</option>
 		</select>
+		<select name=rooms>
+			<option value=i{{ " selected" if g.rooms=="i" else "" }}>CompSci rooms</option>
+			<option value=m{{ " selected" if g.rooms=="m" else "" }}>Math rooms</option>
+		</select>
 		<input type=submit name=submit value="Submit">
 	</form>
 
 	<h2>Schedule for {{ g.dow }} {{ g.date }}</h2>
 
 	<div id=heading>
-{% for r in g.rooms %}
+{% for r in g.room_boxes %}
 		<div class=roomhead style='position: absolute; left: {{ r.x }}px; top: 0px; width: {{ r.w }}px;'>
 			<p>{{ r.name }}</p>
 		</div>
 {% endfor %}
 	</div>
 	<div id=schedule>
-{% for r in g.rooms %}
+{% for r in g.room_boxes %}
 		<div class=room style='position: absolute; left: {{ r.x }}px; top: 0px; width: {{ r.w }}px; height: {{ r.h }}px;'></div>
 {% endfor %}
-{% for h in g.hours %}
+{% for h in g.hour_boxes %}
 		<div class=hour style='position: absolute; left: {{ h.x }}px; top: {{ h.y }}px; width: {{ h.w }}px; height: {{ h.h }}px;'></div>
 {% endfor %}
 {% for m in g.meetings %}
diff --git a/app/zoom.py b/app/zoom.py
index c6fd979..cf9d37f 100644
--- a/app/zoom.py
+++ b/app/zoom.py
@@ -54,16 +54,26 @@ def get_date():
     tz = dateutil.tz.tzlocal()
     return dt.replace(hour=0, minute=0, second=0, microsecond=0, tzinfo=tz)
 
-rooms = [
-    ('Z1', 'zoom-1@d3s.mff.cuni.cz'),
-    ('Z2', 'zoom-2@d3s.mff.cuni.cz'),
-    ('Z3', 'zoom-3@d3s.mff.cuni.cz'),
-    ('Z4', 'zoom-4@d3s.mff.cuni.cz'),
-    ('Z5', 'zoom-5@d3s.mff.cuni.cz'),
-    ('Z6', 'zoom-6@d3s.mff.cuni.cz'),
-    ('Z7', 'zoom-7@d3s.mff.cuni.cz'),
-    ('Z8', 'zoom-8@d3s.mff.cuni.cz'),
-]
+room_list = {
+    'i': [
+        ('Z1', 'zoom-1@d3s.mff.cuni.cz'),
+        ('Z2', 'zoom-2@d3s.mff.cuni.cz'),
+        ('Z3', 'zoom-3@d3s.mff.cuni.cz'),
+        ('Z4', 'zoom-4@d3s.mff.cuni.cz'),
+        ('Z5', 'zoom-5@d3s.mff.cuni.cz'),
+        ('Z6', 'zoom-6@d3s.mff.cuni.cz'),
+        ('Z7', 'zoom-7@d3s.mff.cuni.cz'),
+        ('Z8', 'zoom-8@d3s.mff.cuni.cz'),
+    ],
+    'm': [
+        ('ZM1', 'zoom-m-1@d3s.mff.cuni.cz'),
+        ('ZM2', 'zoom-m-2@d3s.mff.cuni.cz'),
+        ('ZM3', 'zoom-m-3@d3s.mff.cuni.cz'),
+        ('ZM4', 'zoom-m-4@d3s.mff.cuni.cz'),
+        ('ZM7', 'zoom-m-7@d3s.mff.cuni.cz'),
+        ('ZM8', 'zoom-m-8@d3s.mff.cuni.cz'),
+    ],
+}
 
 @app.route('/')
 def main_page():
@@ -85,20 +95,25 @@ def main_page():
         hour_max = 24
     num_hours = hour_max - hour_min
 
+    g.rooms = request.args.get("rooms", "")
+    if g.rooms not in room_list:
+        g.rooms = "i"
+    rooms = room_list[g.rooms]
+
     num_rooms = len(rooms)
     email_to_room_index = { rooms[i][1]: i for i in range(num_rooms) }
     room_box_width = 100
     room_hour_height = 50
     g.total_width = room_box_width * num_rooms
     g.total_height = num_hours * room_hour_height
-    g.rooms = [{
+    g.room_boxes = [{
             "x": i * room_box_width + 1,
             "w": room_box_width - 1,
             "h": g.total_height - 1,
             "name": rooms[i][0],
         } for i in range(num_rooms)]
 
-    g.hours = [{
+    g.hour_boxes = [{
             "x": 1,
             "y": i * room_hour_height + 1,
             "w": num_rooms * room_box_width - 1,
-- 
GitLab