Refresh queue regularly

This commit is contained in:
Joscha 2023-08-06 20:49:07 +02:00
parent ad5da60b5a
commit 6af47b8c30
3 changed files with 23 additions and 9 deletions

View file

@ -1,6 +0,0 @@
function main() {
alert("Hello world!");
}
const BUTTON = document.getElementById("button");
BUTTON?.addEventListener("click", main);

16
static/queue/main.ts Normal file
View file

@ -0,0 +1,16 @@
const COUNT = document.getElementById("count")!;
const QUEUE = document.getElementById("queue")!;
const REFRESH_SECONDS = 10;
function update() {
fetch("table")
.then(response => response.text())
.then(text => {
QUEUE.innerHTML = text;
let count = QUEUE.querySelectorAll("tbody tr").length;
COUNT.textContent = String(count);
document.title = document.title.replace(/^queue \(\d+\)/, `queue (${count})`);
});
}
setInterval(update, REFRESH_SECONDS * 1000);

View file

@ -2,7 +2,11 @@
{% block title %}queue ({{ table.tasks.len() }}){% endblock %} {% block title %}queue ({{ table.tasks.len() }}){% endblock %}
{% block body %} {% block head %}
<h2>Queue ({{ table.tasks.len() }})</h2> <script type="module" src="main.js"></script>
{{ table|safe }} {% endblock %}
{% block body %}
<h2>Queue (<span id="count">{{ table.tasks.len() }}</span>)</h2>
<div id="queue">{{ table|safe }}</div>
{% endblock %} {% endblock %}