Add highlight current period

This commit is contained in:
Aaron Lee 2021-09-12 21:59:31 +08:00
parent 6c78684fe9
commit 2be1b63628
2 changed files with 71 additions and 49 deletions

30
app.py
View file

@ -1,3 +1,4 @@
from typing import OrderedDict
from flask import * from flask import *
import pyrebase import pyrebase
from datetime import datetime from datetime import datetime
@ -30,6 +31,10 @@ storage = firebase.storage()
tz = pytz.timezone('Asia/Taipei') tz = pytz.timezone('Asia/Taipei')
def next_item(odic, key):
return list(odic)[list(odic.keys()).index(key) + 1]
def check_login_status(): def check_login_status():
return ('is_logged_in' not in session or return ('is_logged_in' not in session or
session['is_logged_in'] == False or session['is_logged_in'] == False or
@ -167,6 +172,27 @@ def manageProcess(fCommand, fData):
session['uid']).child("homeroom").get().val().split('^') session['uid']).child("homeroom").get().val().split('^')
homeroomData = db.child("Homerooms").child(homeroom[0]).child( homeroomData = db.child("Homerooms").child(homeroom[0]).child(
homeroom[1]).get().val() homeroom[1]).get().val()
times = OrderedDict({
'm': '00:00',
'1': '08:15',
'2': '09:10',
'3': '10:05',
'4': '11:00',
'n': '11:55',
'5': '13:10',
'6': '14:05',
'7': '15:00',
'8': '15:53',
'9': '16:43',
'ph': '23:59'
})
currPeriod = ""
currTime = datetime.now(tz).strftime("%H:%M")
for i in times:
if (times[i] <= currTime and
currTime <= times[next_item(times, i)]):
currPeriod = i
break
absData = homeroomData["Absent"] absData = homeroomData["Absent"]
homeroomData.pop('Absent') homeroomData.pop('Absent')
homeroomData.pop('placeholder') homeroomData.pop('placeholder')
@ -178,7 +204,9 @@ def manageProcess(fCommand, fData):
currDate = i currDate = i
if i >= datetime.now(tz).strftime("%Y-%m-%d"): if i >= datetime.now(tz).strftime("%Y-%m-%d"):
break break
return render_template('homeroom.html', absData=absData, homeroomCode=homeroom, homeroomData=homeroomData, currDate=currDate, periods=['m', '1', '2', '3', '4', 'n', '5', '6', '7', '8', '9']) print(currPeriod)
return render_template('homeroom.html', absData=absData, homeroomCode=homeroom, homeroomData=homeroomData,
currDate=currDate, periods=['m', '1', '2', '3', '4', 'n', '5', '6', '7', '8', '9'], currPeriod=currPeriod)
else: else:
return redirect('/logout') return redirect('/logout')

View file

@ -40,25 +40,8 @@
<div class="col">Number</div> <div class="col">Number</div>
<div class="col">Name</div> <div class="col">Name</div>
<div class="col">Eng Name</div> <div class="col">Eng Name</div>
<div class="col">Morning</div>
<div class="col">1</div>
<div class="col">2</div>
<div class="col">3</div>
<div class="col">4</div>
<div class="col">Nap</div>
<div class="col">5</div>
<div class="col">6</div>
<div class="col">7</div>
<div class="col">8</div>
<div class="col">9</div>
</div>
<div class="row title">
<div class="col"></div>
<div class="col"></div>
<div class="col"></div>
<div class="col"></div>
{% for i in periods %} {% for i in periods %}
<div class="col">{{absData[currDate][i]['name']}}</div> <div class="col" {% if currPeriod==i %} style="background-color: #ffdf81;" {% endif %}>{{i}}</div>
{% endfor %} {% endfor %}
</div> </div>
<div class="row title"> <div class="row title">
@ -67,7 +50,18 @@
<div class="col"></div> <div class="col"></div>
<div class="col"></div> <div class="col"></div>
{% for i in periods %} {% for i in periods %}
<div class="col">{{absData[currDate][i]['teacher']}}</div> <div class="col" {% if currPeriod==i %} style="background-color: #ffdf81;" {% endif %}>
{{absData[currDate][i]['name']}}</div>
{% endfor %}
</div>
<div class="row title">
<div class="col"></div>
<div class="col"></div>
<div class="col"></div>
<div class="col"></div>
{% for i in periods %}
<div class="col" {% if currPeriod==i %} style="background-color: #ffdf81;" {% endif %}>
{{absData[currDate][i]['teacher']}}</div>
{% endfor %} {% endfor %}
</div> </div>
{% if data != None %} {% if data != None %}
@ -78,42 +72,32 @@
<div class="col">{{ homeroomData[i]['name'] }}</div> <div class="col">{{ homeroomData[i]['name'] }}</div>
<div class="col">{{ homeroomData[i]['eng_name'] }}</div> <div class="col">{{ homeroomData[i]['eng_name'] }}</div>
{% for j in periods %} {% for j in periods %}
<div class="col" {% if currPeriod==j %} style="background-color: #ffdf81;" {% endif %}>
{% if 'signature' in absData[currDate][j] %} {% if 'signature' in absData[currDate][j] %}
{% if i in absData[currDate][j] %} {% if i in absData[currDate][j] %}
<div class="col">
<p class="highlightAbs n-2">X</p> <p class="highlightAbs n-2">X</p>
</div>
{% else %} {% else %}
{% if absData[currDate][j]['name'] != 'GP' %} {% if absData[currDate][j]['name'] != 'GP' %}
<div class="col">
<p class="highlightAbs n-1">V</p> <p class="highlightAbs n-1">V</p>
</div>
{% else %} {% else %}
{% if (homeroomData[i]['GP_Class'][absData[currDate][j]['teacher']] in {% if (homeroomData[i]['GP_Class'][absData[currDate][j]['teacher']] in
absData[currDate][j]['signature'])%} absData[currDate][j]['signature'])%}
<div class="col">
<p class="highlightAbs n-1">V</p> <p class="highlightAbs n-1">V</p>
</div>
{% else %} {% else %}
<div class="col">
<p class="highlightAbs n-2"></p> <p class="highlightAbs n-2"></p>
</div>
{% endif %} {% endif %}
{% endif %} {% endif %}
{% endif %} {% endif %}
{% elif absData[currDate][j]['name'] == 'GP' %} {% elif absData[currDate][j]['name'] == 'GP' %}
<div class="col">
<p class="highlightAbs"></p> <p class="highlightAbs"></p>
</div>
{% else %} {% else %}
<div class="col">
{% if 'confirm' in absData[currDate] %} {% if 'confirm' in absData[currDate] %}
<p class="highlightAbs"></p> <p class="highlightAbs"></p>
{% else %} {% else %}
<input type="checkbox" class="tobeform {{j}}^{{i}}"> <input type="checkbox" class="tobeform {{j}}^{{i}}">
{% endif %} {% endif %}
</div>
{% endif %} {% endif %}
</div>
{% endfor %} {% endfor %}
</div> </div>
{% endfor %} {% endfor %}
@ -123,14 +107,14 @@
<div class="col"></div> <div class="col"></div>
<div class="col"></div> <div class="col"></div>
{% for i in periods %} {% for i in periods %}
<div class="col"> <div class="col" {% if currPeriod==i %} style="background-color: #ffdf81;" {% endif %}>
{% if ('signature' in absData[currDate][i] or absData[currDate][i]['name'] == 'GP' or {% if ('signature' in absData[currDate][i] or absData[currDate][i]['name'] == 'GP' or
'confirm' in absData[currDate]) %} 'confirm' in absData[currDate]) %}
<button class="btn btn-primary afterSelButton" disabled="disabled" <button class="btn btn-primary afterSelButton" disabled="disabled"
onclick="afterSelAbs('{{i|string}}')">Confirm</button> onclick="afterSelAbs('{{i|string}}')"></button>
{% else %} {% else %}
<button class="btn btn-primary afterSelButton" <button class="btn btn-primary afterSelButton"
onclick="afterSelAbs('{{i|string}}')">Confirm</button> onclick="afterSelAbs('{{i|string}}')">Confirm<br>{{absData[currDate][i]['name']}}</button>
{% endif %} {% endif %}
</div> </div>
{% endfor %} {% endfor %}
@ -150,7 +134,10 @@
Teacher Confirm</button> Teacher Confirm</button>
{% endif %} {% endif %}
<div id="finalCheck" hidden="hidden"> <div id="finalCheck" hidden="hidden">
<h3>Please Sign Below</h3> <h3>Please Sign Below <br>
Period: <span id="showSignPeriod"></span> <br>
Subject: <span id="showSignSubjectName"></span>
</h3>
<div class="forSign"><canvas id="signature_pad"></canvas></div> <div class="forSign"><canvas id="signature_pad"></canvas></div>
<button class="btn btn-secondary" type="button" onclick="signaturePad.clear()">Clear Signature</button> <button class="btn btn-secondary" type="button" onclick="signaturePad.clear()">Clear Signature</button>
<button class="btn btn-primary" type="button" onclick="submitForm()">Submit</button> <button class="btn btn-primary" type="button" onclick="submitForm()">Submit</button>
@ -205,6 +192,11 @@
</footer> </footer>
<script> <script>
var signaturePad, hrCfrm = false; var signaturePad, hrCfrm = false;
var periodData = {}
{% for i in periods %}
periodData['{{i}}'] = '{{ absData[currDate][i]['name'] }}'
{% endfor %}
function loadingAnimation() { function loadingAnimation() {
$('.container').hide(); $('.container').hide();
$('#loading').show(); $('#loading').show();
@ -249,6 +241,8 @@
$('#postHomeroomAbs #HR-period').val(period); $('#postHomeroomAbs #HR-period').val(period);
$('.tobeform').attr('disabled', 'disabled'); $('.tobeform').attr('disabled', 'disabled');
$('.afterSelButton').attr('disabled', 'disabled'); $('.afterSelButton').attr('disabled', 'disabled');
$('#showSignPeriod').text(period);
$('#showSignSubjectName').text(periodData[period]);
$('.tobeform').each(function (i, obj) { $('.tobeform').each(function (i, obj) {
if ($(this).attr('class').split(' ')[1].split('^')[0] == period && if ($(this).attr('class').split(' ')[1].split('^')[0] == period &&
$(this).is(":checked")) { $(this).is(":checked")) {