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:
|
||||
todos_dict[todo] = todoFile[todo]
|
||||
if todoFile[todo]['done'] and todo in activeAlarms:
|
||||
previousAlarms[id] = activeAlarms[id]
|
||||
activeAlarms.pop(id)
|
||||
previousAlarms[todo] = activeAlarms[todo]
|
||||
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
|
||||
for log in logsFile:
|
||||
logs.append(log)
|
||||
|
@ -54,8 +57,13 @@ def preprocess():
|
|||
def index():
|
||||
if not preprocessed:
|
||||
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'))
|
||||
def setAlarm():
|
||||
|
@ -72,9 +80,9 @@ def setAlarm():
|
|||
content = request.form['alarmMessage']
|
||||
global alarmIndex
|
||||
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:
|
||||
json.dump(allAlarms, f, indent=2)
|
||||
f.close()
|
||||
|
@ -92,6 +100,19 @@ def sendLog():
|
|||
|
||||
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
|
||||
@app.route('/alarms', methods=('GET','POST'))
|
||||
def alarm():
|
||||
|
@ -113,6 +134,8 @@ def deleteAlarm():
|
|||
alarm = activeAlarms[id]
|
||||
previousAlarms[id] = alarm
|
||||
activeAlarms.pop(id)
|
||||
if id in todos_dict:
|
||||
todos_dict[id] = {'done': True, 'message': todos_dict[id]['message']}
|
||||
return redirect(url_for('index'))
|
||||
|
||||
# invert todo checkbox
|
||||
|
@ -137,31 +160,33 @@ def upload():
|
|||
# if upload successful back to index
|
||||
# else show error und bleib auf der Seite
|
||||
if request.method == 'POST':
|
||||
data = json.load(request.files['alarmFile'].stream)
|
||||
for alarm in data:
|
||||
content = alarm["message"]
|
||||
global alarmIndex
|
||||
alarmIndex += 1
|
||||
if alarm["type"] != "checkbox":
|
||||
time = datetime.combine(datetime.today(),datetime.strptime(alarm["time"], "%H:%M").time())
|
||||
if time<datetime.now():
|
||||
time = time + timedelta(days=1)
|
||||
activeAlarms[str(alarmIndex)] = {'datetime':datetime.strftime(time,"%d.%m.%Y %H:%M"),'message':content}
|
||||
if(alarm["type"]=="both"):
|
||||
try:
|
||||
data = json.load(request.files['alarmFile'].stream)
|
||||
for alarm in data:
|
||||
content = alarm["message"]
|
||||
global alarmIndex
|
||||
alarmIndex += 1
|
||||
if alarm["type"] != "checkbox":
|
||||
time = datetime.combine(datetime.today(),datetime.strptime(alarm["time"], "%H:%M").time())
|
||||
if time<datetime.now():
|
||||
time = time + timedelta(days=1)
|
||||
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}
|
||||
else:
|
||||
todos_dict[str(alarmIndex)]= {'done':False, 'message':content}
|
||||
# ja, wir schreiben einfach das ganze File neu, ist aber einfacher
|
||||
with open('alarms.json', 'w') as f:
|
||||
json.dump(activeAlarms, f, indent=2)
|
||||
with open('todos.json', 'w') as g:
|
||||
json.dump(todos_dict, g, indent=2)
|
||||
f.close()
|
||||
g.close()
|
||||
# ja, wir schreiben einfach das ganze File neu, ist aber einfacher
|
||||
with open('alarms.json', 'w') as f:
|
||||
json.dump(activeAlarms, f, indent=2)
|
||||
with open('todos.json', 'w') as g:
|
||||
json.dump(todos_dict, g, indent=2)
|
||||
f.close()
|
||||
g.close()
|
||||
|
||||
return redirect(url_for('index'))
|
||||
|
||||
return render_template('upload.html', uploadFailed=True)
|
||||
return redirect(url_for('index'))
|
||||
except:
|
||||
return render_template('upload.html', uploadFailed=True)
|
||||
return render_template('upload.html', uploadFailed=False)
|
||||
|
||||
|
||||
# ab hier statisches gerendere, keine große Logik mehr :D
|
||||
|
|
|
@ -43,6 +43,14 @@ div.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/)
|
||||
* Copyright 2011-2019 The Bootstrap Authors
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<h3>Upcoming Alarms</h3>
|
||||
<h3>Anstehende Alarme</h3>
|
||||
{% for alarm in alarms %}
|
||||
<div>
|
||||
{{ 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>
|
||||
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.
|
||||
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.
|
||||
</p>
|
||||
<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>
|
||||
<h5><u>ToDos</u></h5>
|
||||
<p>
|
||||
Todo Listeneinträge können aktuell nicht in der UI erstellt werden. Wahrscheinlich ändere ich das noch.
|
||||
Ansonsten; abhaken, wenn ein Alarm mit dem ToDo asoziiert ist (über Upload), wird der Alarm automatisch in die vergangenen Alarme geschoben.
|
||||
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.
|
||||
Todos werden automatisch abgehakt, wenn der asoziierte Alarm gelöscht wird.
|
||||
<br>
|
||||
<i>"Aber Anika, ich bin doof und hab Fetengehirn und ausversehen das falsche abgehakt. Was mach ich denn jetzt?"</i>
|
||||
<br>
|
||||
Fear not, mein junger Padawan. I got you. Unchecking der Checkbox macht den Alarm wieder zurück.
|
||||
</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>
|
||||
Wird gefüllt, sobald ich Probleme/Unklarheiten identifiziere oder gesagt bekomme
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
{% block content %}
|
||||
<h1>{% block title %} ToDos {% endblock %}</h1>
|
||||
<div id="todoList">
|
||||
<div id="todoList" class="savedTodos">
|
||||
{% for todo in todos %}
|
||||
<div>
|
||||
{% if todos[todo].done%}
|
||||
|
@ -13,6 +13,15 @@
|
|||
</div>
|
||||
{% endfor %}
|
||||
</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>
|
||||
async function checkTodo(id){
|
||||
|
|
|
@ -7,7 +7,10 @@
|
|||
|
||||
Akzeptiert .json Dateien. Für den Aufbau der Datei, schau in der Hilfe.
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
{% if uploadFailed %}
|
||||
<b>Upload fehlgeschlagen!</b>
|
||||
{% endif %}
|
||||
<form method="post" action="/upload" enctype="multipart/form-data">
|
||||
<div class="form-group">
|
||||
<div class="upload" >
|
||||
|
|
Loading…
Reference in New Issue