97 lines
3.6 KiB
HTML
97 lines
3.6 KiB
HTML
{% extends 'base.html' %}
|
|
|
|
{% block content %}
|
|
<h1>{% block title %} Partey! {% endblock %}</h1>
|
|
<div class="grid-container">
|
|
<div class="savedLogs">
|
|
<h3>Logs</h3>
|
|
{% for log in logs %}
|
|
<div>
|
|
{{ log.datetime }}: {{ log.message }}
|
|
</div>
|
|
{% endfor %}
|
|
</div>
|
|
<div class="savedAlarms" >
|
|
<h3>Upcoming Alarms</h3>
|
|
{% for alarm in alarms %}
|
|
<div>
|
|
{{ alarm.datetime }}: {{ alarm.message }}
|
|
</div>
|
|
{% endfor %}
|
|
</div>
|
|
<div class="log">
|
|
<form method="post" action="/sendLog">
|
|
|
|
<div class="form-group">
|
|
<label for="logMessage">logMessage</label>
|
|
<input type="text" name="logMessage"
|
|
class="form-control"
|
|
value="{{ request.form['logMessage'] }}"></input>
|
|
<input type="submit" id="saveLog" value="Speichern"/>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
<div class="alarms">
|
|
<form method="post" action="/setAlarm">
|
|
|
|
<div class="form-group">
|
|
<label for="time">Time</label>
|
|
<input type="datetime-local" name="datetime"
|
|
class="form-control"
|
|
value="{{ request.form['datetime'] }}"></input>
|
|
<label for="alarmMessage">alarmMessage</label>
|
|
<input type="text" name="alarmMessage"
|
|
class="form-control"
|
|
value="{{ request.form['alarmMessage'] }}"></input>
|
|
<input type="submit" id="saveAlarm" value="Speichern"/>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
|
|
<div>
|
|
<h3>Previous Alarm</h3>
|
|
<script>
|
|
async function getAlarms(){
|
|
const response = await fetch("http://127.0.0.1:5000/alarms", {method:"GET"});
|
|
const alarms = await response.json();
|
|
return alarms
|
|
}
|
|
async function postAlarm(alarm){
|
|
var body = JSON.stringify(alarm)
|
|
const response = await fetch("http://127.0.0.1:5000/alarms", {
|
|
method: "POST",
|
|
body: body,
|
|
});
|
|
}
|
|
alarms = getAlarms();
|
|
function checkAlarms(){
|
|
alarms.then( (alarms) => {
|
|
for(var i = 0; i < alarms.length; i++){
|
|
|
|
const [dateComponents, timeComponents] = alarms[i].datetime.split(' ');
|
|
|
|
const [day, month, year] = dateComponents.split('.');
|
|
const [hours, minutes] = timeComponents.split(':');
|
|
|
|
const date = new Date(+year, +month - 1, +day, +hours, +minutes);
|
|
if(date <=new Date()){
|
|
console.log("ALARM!");
|
|
postAlarm(alarms[i]);
|
|
alert(alarms[i].message);
|
|
}
|
|
}
|
|
setTimeout(checkAlarms, 15000);
|
|
}
|
|
|
|
)
|
|
}
|
|
checkAlarms();
|
|
</script>
|
|
{% for alarm in previousAlarms %}
|
|
<div>
|
|
{{ alarm.datetime }}: {{ alarm.message }}
|
|
</div>
|
|
{% endfor %}
|
|
</div>
|
|
</div>
|
|
{% endblock %} |