Alarm einfügen funktioniert wieder, Alarms sind jetzt sortiert
This commit is contained in:
parent
56cdca0998
commit
5e3a3a8272
81
app.py
81
app.py
|
@ -41,8 +41,11 @@ def preprocess():
|
||||||
for todo in todoFile:
|
for todo in todoFile:
|
||||||
todos_dict[todo] = todoFile[todo]
|
todos_dict[todo] = todoFile[todo]
|
||||||
if todoFile[todo]['done'] and todo in activeAlarms:
|
if todoFile[todo]['done'] and todo in activeAlarms:
|
||||||
previousAlarms[id] = activeAlarms[id]
|
previousAlarms[todo] = activeAlarms[todo]
|
||||||
activeAlarms.pop(id)
|
activeAlarms.pop(todo)
|
||||||
|
elif not todoFile[todo]['done'] and todo in previousAlarms:
|
||||||
|
activeAlarms[todo] = previousAlarms[todo]
|
||||||
|
previousAlarms.pop(todo)
|
||||||
# lies alle log aus dem file ein
|
# lies alle log aus dem file ein
|
||||||
for log in logsFile:
|
for log in logsFile:
|
||||||
logs.append(log)
|
logs.append(log)
|
||||||
|
@ -54,8 +57,13 @@ def preprocess():
|
||||||
def index():
|
def index():
|
||||||
if not preprocessed:
|
if not preprocessed:
|
||||||
preprocess()
|
preprocess()
|
||||||
|
sorted_alarms = dict(sorted(activeAlarms.items(), key=lambda x:x[1]['datetime']))
|
||||||
|
sorted_prevAlarms = dict(sorted(previousAlarms.items(), key=lambda x:x[1]['datetime']))
|
||||||
|
|
||||||
return render_template('index.html', logs = logs, alarms = activeAlarms, previousAlarms=previousAlarms)
|
|
||||||
|
print(sorted_alarms)
|
||||||
|
|
||||||
|
return render_template('index.html', logs = logs, alarms = sorted_alarms, previousAlarms=sorted_prevAlarms)
|
||||||
|
|
||||||
@app.route('/setAlarm', methods=('GET', 'POST'))
|
@app.route('/setAlarm', methods=('GET', 'POST'))
|
||||||
def setAlarm():
|
def setAlarm():
|
||||||
|
@ -72,9 +80,9 @@ def setAlarm():
|
||||||
content = request.form['alarmMessage']
|
content = request.form['alarmMessage']
|
||||||
global alarmIndex
|
global alarmIndex
|
||||||
alarmIndex += 1
|
alarmIndex += 1
|
||||||
activeAlarms[alarmIndex]({'datetime':datetime.strftime(time,"%d.%m.%Y %H:%M"),'message':content})
|
activeAlarms[str(alarmIndex)] = {'datetime':datetime.strftime(time,"%d.%m.%Y %H:%M"),'message':content}
|
||||||
|
|
||||||
allAlarms = activeAlarms+previousAlarms
|
allAlarms = {**activeAlarms, **previousAlarms}
|
||||||
with open('alarms.json', 'w') as f:
|
with open('alarms.json', 'w') as f:
|
||||||
json.dump(allAlarms, f, indent=2)
|
json.dump(allAlarms, f, indent=2)
|
||||||
f.close()
|
f.close()
|
||||||
|
@ -92,6 +100,19 @@ def sendLog():
|
||||||
|
|
||||||
return redirect(url_for('index'))
|
return redirect(url_for('index'))
|
||||||
|
|
||||||
|
@app.route('/sendTodo', methods=('GET', 'POST'))
|
||||||
|
def sendTodo():
|
||||||
|
if request.method == 'POST':
|
||||||
|
content = request.form['todoMessage']
|
||||||
|
global alarmIndex
|
||||||
|
alarmIndex +=1
|
||||||
|
todos_dict[str(alarmIndex)]= {'done':False, 'message':content}
|
||||||
|
with open('todos.json', 'w') as f:
|
||||||
|
json.dump(todos_dict, f, indent=2)
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
return redirect(url_for('todos'))
|
||||||
|
|
||||||
# sounds the alarm
|
# sounds the alarm
|
||||||
@app.route('/alarms', methods=('GET','POST'))
|
@app.route('/alarms', methods=('GET','POST'))
|
||||||
def alarm():
|
def alarm():
|
||||||
|
@ -113,6 +134,8 @@ def deleteAlarm():
|
||||||
alarm = activeAlarms[id]
|
alarm = activeAlarms[id]
|
||||||
previousAlarms[id] = alarm
|
previousAlarms[id] = alarm
|
||||||
activeAlarms.pop(id)
|
activeAlarms.pop(id)
|
||||||
|
if id in todos_dict:
|
||||||
|
todos_dict[id] = {'done': True, 'message': todos_dict[id]['message']}
|
||||||
return redirect(url_for('index'))
|
return redirect(url_for('index'))
|
||||||
|
|
||||||
# invert todo checkbox
|
# invert todo checkbox
|
||||||
|
@ -137,31 +160,33 @@ def upload():
|
||||||
# if upload successful back to index
|
# if upload successful back to index
|
||||||
# else show error und bleib auf der Seite
|
# else show error und bleib auf der Seite
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
data = json.load(request.files['alarmFile'].stream)
|
try:
|
||||||
for alarm in data:
|
data = json.load(request.files['alarmFile'].stream)
|
||||||
content = alarm["message"]
|
for alarm in data:
|
||||||
global alarmIndex
|
content = alarm["message"]
|
||||||
alarmIndex += 1
|
global alarmIndex
|
||||||
if alarm["type"] != "checkbox":
|
alarmIndex += 1
|
||||||
time = datetime.combine(datetime.today(),datetime.strptime(alarm["time"], "%H:%M").time())
|
if alarm["type"] != "checkbox":
|
||||||
if time<datetime.now():
|
time = datetime.combine(datetime.today(),datetime.strptime(alarm["time"], "%H:%M").time())
|
||||||
time = time + timedelta(days=1)
|
if time<datetime.now():
|
||||||
activeAlarms[str(alarmIndex)] = {'datetime':datetime.strftime(time,"%d.%m.%Y %H:%M"),'message':content}
|
time = time + timedelta(days=1)
|
||||||
if(alarm["type"]=="both"):
|
activeAlarms[str(alarmIndex)] = {'datetime':datetime.strftime(time,"%d.%m.%Y %H:%M"),'message':content}
|
||||||
|
if(alarm["type"]=="both"):
|
||||||
|
todos_dict[str(alarmIndex)]= {'done':False, 'message':content}
|
||||||
|
else:
|
||||||
todos_dict[str(alarmIndex)]= {'done':False, 'message':content}
|
todos_dict[str(alarmIndex)]= {'done':False, 'message':content}
|
||||||
else:
|
# ja, wir schreiben einfach das ganze File neu, ist aber einfacher
|
||||||
todos_dict[str(alarmIndex)]= {'done':False, 'message':content}
|
with open('alarms.json', 'w') as f:
|
||||||
# ja, wir schreiben einfach das ganze File neu, ist aber einfacher
|
json.dump(activeAlarms, f, indent=2)
|
||||||
with open('alarms.json', 'w') as f:
|
with open('todos.json', 'w') as g:
|
||||||
json.dump(activeAlarms, f, indent=2)
|
json.dump(todos_dict, g, indent=2)
|
||||||
with open('todos.json', 'w') as g:
|
f.close()
|
||||||
json.dump(todos_dict, g, indent=2)
|
g.close()
|
||||||
f.close()
|
|
||||||
g.close()
|
|
||||||
|
|
||||||
return redirect(url_for('index'))
|
return redirect(url_for('index'))
|
||||||
|
except:
|
||||||
return render_template('upload.html', uploadFailed=True)
|
return render_template('upload.html', uploadFailed=True)
|
||||||
|
return render_template('upload.html', uploadFailed=False)
|
||||||
|
|
||||||
|
|
||||||
# ab hier statisches gerendere, keine große Logik mehr :D
|
# ab hier statisches gerendere, keine große Logik mehr :D
|
||||||
|
|
|
@ -43,6 +43,14 @@ div.savedAlarms {
|
||||||
grid-area: savedAlarms;
|
grid-area: savedAlarms;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
div.savedTodos {
|
||||||
|
border:1px solid gray;
|
||||||
|
border-radius: 10px;
|
||||||
|
padding: 3mm;
|
||||||
|
margin-right: 2cm;
|
||||||
|
margin-bottom: 2mm;
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Bootstrap v4.3.1 (https://getbootstrap.com/)
|
* Bootstrap v4.3.1 (https://getbootstrap.com/)
|
||||||
* Copyright 2011-2019 The Bootstrap Authors
|
* Copyright 2011-2019 The Bootstrap Authors
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
<h3>Upcoming Alarms</h3>
|
<h3>Anstehende Alarme</h3>
|
||||||
{% for alarm in alarms %}
|
{% for alarm in alarms %}
|
||||||
<div>
|
<div>
|
||||||
{{ alarms[alarm].datetime }}: {{ alarms[alarm].message }} <input style="text-align: right;" type="button" value="❌" onclick="deleteAlarm({{alarm}})"/>
|
{{ alarms[alarm].datetime }}: {{ alarms[alarm].message }} <input style="text-align: right;" type="button" value="❌" onclick="deleteAlarm({{alarm}})"/>
|
||||||
|
|
|
@ -33,9 +33,11 @@ Die Datei zum hochladen, sollte folgenden Aufbau haben:
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
</pre>
|
</pre>
|
||||||
Alarme/Beides braucht eine Uhrzeit und eine Alarm Nachricht.
|
Alarme brauchen eine Uhrzeit und eine Alarm Nachricht.
|
||||||
Als Datum wird heute genommen, außer der Zeitpunkt liegt in der Vergangenheit.
|
Als Datum wird heute genommen, außer der Zeitpunkt liegt in der Vergangenheit.
|
||||||
Dann wird der Alarm morgen zur angegeben Uhrzeit eingetragen. Todo-Listeneinträge haben keine Uhrzeit.<br>
|
Dann wird der Alarm morgen zur angegeben Uhrzeit eingetragen. <br>
|
||||||
|
Todo-Listeneinträge haben keine Uhrzeit. Wenn was beides hat, braucht es eine Uhrzeit.
|
||||||
|
<b>Typ "both": sei dir sicher, dass du die zusammen haben willst. Du kannst weder den Alarm löschen ohne das Todo abzuhaken, noch andersrum. </b><br>
|
||||||
Falls ein separates Datumsfeld gewünscht ist, sagt Bescheid, ich sehe da ehrlich gesagt noch keine Notwendikeit.
|
Falls ein separates Datumsfeld gewünscht ist, sagt Bescheid, ich sehe da ehrlich gesagt noch keine Notwendikeit.
|
||||||
</p>
|
</p>
|
||||||
<h5><u>Alarm eintragen</u></h5>
|
<h5><u>Alarm eintragen</u></h5>
|
||||||
|
@ -49,15 +51,23 @@ Schreibe einen Text, drücke Enter, sei glücklich. Nein, du kannst das nicht ko
|
||||||
</p>
|
</p>
|
||||||
<h5><u>ToDos</u></h5>
|
<h5><u>ToDos</u></h5>
|
||||||
<p>
|
<p>
|
||||||
Todo Listeneinträge können aktuell nicht in der UI erstellt werden. Wahrscheinlich ändere ich das noch.
|
Abhaken, wenn ein Alarm mit dem ToDo asoziiert ist (über Upload), wird der Alarm automatisch in die vergangenen Alarme geschoben.
|
||||||
Ansonsten; abhaken, wenn ein Alarm mit dem ToDo asoziiert ist (über Upload), wird der Alarm automatisch in die vergangenen Alarme geschoben.
|
|
||||||
Abgehakte ToDos werden grün.
|
Abgehakte ToDos werden grün.
|
||||||
|
Todos werden automatisch abgehakt, wenn der asoziierte Alarm gelöscht wird.
|
||||||
<br>
|
<br>
|
||||||
<i>"Aber Anika, ich bin doof und hab Fetengehirn und ausversehen das falsche abgehakt. Was mach ich denn jetzt?"</i>
|
<i>"Aber Anika, ich bin doof und hab Fetengehirn und ausversehen das falsche abgehakt. Was mach ich denn jetzt?"</i>
|
||||||
<br>
|
<br>
|
||||||
Fear not, mein junger Padawan. I got you. Unchecking der Checkbox macht den Alarm wieder zurück.
|
Fear not, mein junger Padawan. I got you. Unchecking der Checkbox macht den Alarm wieder zurück.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<h2>Server-Neustart</h2>
|
||||||
|
Wenn der Server neu gestartet wird, müssen ein paar Kleinigkeiten beachtet werden.
|
||||||
|
<ul>
|
||||||
|
<li>Es wird generell alles geladen, der Server vergisst wenig</li>
|
||||||
|
<li>Überprüf die aktiven Alarme, da stehen jetzt potenziell mehr als du willst. Mach das sofort und unmittelbar,
|
||||||
|
du hast 15s bis das erste Mal ein Alarm aus den letzten 2 Minuten tönen kann</li>
|
||||||
|
<li>Bestimmt noch was, das ich nicht weiß</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
<h2>Debugging Hilfe</h2>
|
<h2>Debugging Hilfe</h2>
|
||||||
Wird gefüllt, sobald ich Probleme/Unklarheiten identifiziere oder gesagt bekomme
|
Wird gefüllt, sobald ich Probleme/Unklarheiten identifiziere oder gesagt bekomme
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h1>{% block title %} ToDos {% endblock %}</h1>
|
<h1>{% block title %} ToDos {% endblock %}</h1>
|
||||||
<div id="todoList">
|
<div id="todoList" class="savedTodos">
|
||||||
{% for todo in todos %}
|
{% for todo in todos %}
|
||||||
<div>
|
<div>
|
||||||
{% if todos[todo].done%}
|
{% if todos[todo].done%}
|
||||||
|
@ -13,6 +13,15 @@
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
<form method="post" action="/sendTodo">
|
||||||
|
<div class="form-group" style="margin-left:2mm">
|
||||||
|
<label for="todoMessage">Todo:</label>
|
||||||
|
<input type="text" name="todoMessage" style="width:90%"
|
||||||
|
class="form-control"
|
||||||
|
value="{{ request.form['todoMessage'] }}" required></input>
|
||||||
|
<input type="submit" id="saveTodo" value="Speichern" style="margin-top: 3mm;"/>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
async function checkTodo(id){
|
async function checkTodo(id){
|
||||||
|
|
|
@ -7,7 +7,10 @@
|
||||||
|
|
||||||
Akzeptiert .json Dateien. Für den Aufbau der Datei, schau in der Hilfe.
|
Akzeptiert .json Dateien. Für den Aufbau der Datei, schau in der Hilfe.
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
{% if uploadFailed %}
|
||||||
|
<b>Upload fehlgeschlagen!</b>
|
||||||
|
{% endif %}
|
||||||
<form method="post" action="/upload" enctype="multipart/form-data">
|
<form method="post" action="/upload" enctype="multipart/form-data">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="upload" >
|
<div class="upload" >
|
||||||
|
|
Loading…
Reference in New Issue