Add nice quit and restarting pages.

This commit is contained in:
Matthew Stratford 2021-04-18 22:23:25 +01:00
parent f03a3d9377
commit c13e2105da
3 changed files with 51 additions and 2 deletions

View file

@ -34,6 +34,7 @@
<a href="/">
<h1 class="h1 text-light d-inline">BAPSicle</h1>
</a>
{% if data.ui_menu is undefined or data.ui_menu is true %}
<div class="d-inline float-right">
<a href="/status" class="btn btn-user btn-outline-light btn-primary ml-4 {% if data.ui_page == 'status' %}active{% endif %}">
Status
@ -48,6 +49,7 @@
Logs
</a>
</div>
{% endif %}
<div class="card o-hidden border-0 shadow-lg my-3">
{% block content %}

29
ui-templates/message.html Normal file
View file

@ -0,0 +1,29 @@
{% extends 'base.html' %}
{% block content_inner %}
<div class="text-center">
<p class="lead text-gray-800 mb-2">{{ data.title }}</p>
<p class="text-gray-900 mb-3">{{ data.message }}</p>
</div>
{% if data.redirect_to %}
<script>
function check_and_redirect() {
var myRequest = new Request('{{data.redirect_to}}');
console.log("Requesting {{data.redirect_to}}")
fetch(myRequest).then(function(response) {
console.log("Fetched new page, got status code: ", response.status)
if (response.status == 200) {
window.location.href = "{{data.redirect_to}}"
}
});
}
setTimeout(
() => {
setInterval(check_and_redirect, 5000)
},
{{data.redirect_wait_ms or '5000'}}
)
</script>
{% endif %}
{% endblock %}

View file

@ -338,13 +338,31 @@ def status(channel: int):
@app.route("/quit")
def quit(request):
server_state.update("running_state", "quitting")
return text("Server quitting...")
data = {
"ui_page": "message",
"ui_title": "Quitting BAPSicle",
"title": "See you later!",
"ui_menu": False,
"message": "BAPSicle is going back into winter hibernation, see you again soon!"
}
return render_template("message.html", data)
@app.route("/restart")
def restart(request):
server_state.update("running_state", "restarting")
return text("Server restarting...")
data = {
"ui_page": "message",
"ui_title": "Restarting BAPSicle",
"title": "Please Wait...",
"ui_menu": False,
"message": "Just putting BAPSicle back in the freezer for a moment!",
"redirect_to": "/",
"redirect_wait_ms": 10000
}
return render_template("message.html", data)
# Don't use reloader, it causes Nested Processes!