sensors added to settings

This commit is contained in:
Joren de Graaf
2026-10-02 15:38:18 +02:00
parent 428caef29d
commit ab6cfc0bae
19 changed files with 360 additions and 19 deletions
@@ -0,0 +1,52 @@
{% load i18n vite %}
<!doctype html>
<html lang="{{ request.LANGUAGE_CODE }}" data-theme="dark">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{ sensor.name }} · {% trans "Settings" %}</title>
{% vite_asset "frontend/src/entries/settings.js" %}
</head>
<body><main class="card">
<a href="{% url 'user_settings' %}">← {% trans "Settings" %}</a>
<h1>{{ sensor.name }}</h1>
{% if messages %}<ul class="messages">{% for message in messages %}<li class="alert alert--error">{{ message }}</li>{% endfor %}</ul>{% endif %}
{% if token %}<section class="token-once" aria-label="{% trans 'New API token' %}">
<strong>{% trans "Copy this token now. For security reasons it will not be shown again." %}</strong>
<code id="sensor-token">{{ token }}</code>
<button class="button button--secondary" type="button" onclick="navigator.clipboard.writeText(document.getElementById('sensor-token').textContent)">{% trans "Copy token" %}</button>
</section>{% endif %}
<section class="section">
{% with status=heartbeat %}<p class="sensor-status sensor-status--{{ status.0 }}">● {{ status.1 }}</p>{% endwith %}
<p>{% trans "Last heartbeat" %}: {{ sensor.last_heartbeat|date:"j M Y, H:i"|default:"—" }}</p>
<p>{% trans "Last submission" %}: {{ sensor.last_submission|date:"j M Y, H:i"|default:"—" }}</p>
<p>{% trans "Token prefix" %}: {{ sensor.token_prefix|default:"—" }}</p>
<p>{% trans "Created" %}: {{ sensor.created_at|date:"j M Y, H:i" }}</p>
</section>
<section class="section"><h2>{% trans "Rename" %}</h2>
<form method="post" action="{% url 'rename_sensor' sensor.pk %}">{% csrf_token %}
<label for="id_name">{% trans "Device name" %}</label>{{ form.name }}{{ form.name.errors }}
<button class="button" type="submit">{% trans "Save name" %}</button>
</form>
</section>
<section class="section"><h2>{% trans "Device access" %}</h2>
<p>{% if sensor.is_active %}{% trans "Enabled" %}{% else %}{% trans "Disabled" %}{% endif %}</p>
<form method="post" action="{% url 'toggle_sensor' sensor.pk %}">{% csrf_token %}
<button class="button button--secondary" type="submit">{% if sensor.is_active %}{% trans "Disable sensor" %}{% else %}{% trans "Enable sensor" %}{% endif %}</button>
</form>
</section>
<section class="section"><h2>{% trans "Reissue API token" %}</h2>
<p class="help">{% trans "The old token will immediately stop authenticating." %}</p>
<form method="post" action="{% url 'rotate_sensor' sensor.pk %}">{% csrf_token %}
<div class="check"><input type="checkbox" id="confirm-rotate" name="confirm" value="rotate" required><label for="confirm-rotate">{% trans "I understand the old token will stop working" %}</label></div>
<button class="button" type="submit">{% trans "Reissue token" %}</button>
</form>
</section>
<section class="section"><h2>{% trans "Remove sensor" %}</h2>
<p class="help">{% trans "This disables the device and revokes its token. Historical events remain linked to it." %}</p>
<form method="post" action="{% url 'remove_sensor' sensor.pk %}">{% csrf_token %}
<div class="check"><input type="checkbox" id="confirm-remove" name="confirm" value="remove" required><label for="confirm-remove">{% trans "I understand this device will be removed" %}</label></div>
<button class="button button--danger" type="submit">{% trans "Remove sensor" %}</button>
</form>
</section>
</main></body></html>
@@ -37,6 +37,27 @@
</section>
<button class="button" type="submit">{% trans "Save settings" %}</button>
</form>
<section class="section" aria-labelledby="sensors-title">
<h2 id="sensors-title">{% trans "My sensors" %}</h2>
<p class="help">{% trans "Manage the devices that authenticate with BoomCast." %}</p>
{% for sensor in sensors %}
<div class="sensor-card">
<strong>{{ sensor.name }}</strong>
{% with status=sensor.heartbeat_status %}<span class="sensor-status sensor-status--{{ status.0 }}">● {{ status.1 }}</span>{% endwith %}
<p>{% if sensor.is_active %}{% trans "Enabled" %}{% else %}{% trans "Disabled" %}{% endif %} · {% trans "Token prefix" %}: {{ sensor.token_prefix|default:"—" }}</p>
<p>{% trans "Last heartbeat" %}: {{ sensor.last_heartbeat|date:"j M Y, H:i"|default:"—" }} · {% trans "Created" %}: {{ sensor.created_at|date:"j M Y" }}</p>
<a class="button button--secondary" href="{% url 'manage_sensor' sensor.pk %}">{% trans "Manage" %}</a>
</div>
{% empty %}
<p class="help">{% trans "No sensors yet. Add a device to receive an API token for hardware submissions." %}</p>
{% endfor %}
<form method="post" action="{% url 'create_sensor' %}">
{% csrf_token %}
<label for="new-sensor-name">{% trans "Device name" %}</label>
<input id="new-sensor-name" name="name" type="text" maxlength="100" required>
<button class="button" type="submit">{% trans "Add sensor" %}</button>
</form>
</section>
</main>
</body>
</html>