Compare commits
26
Commits
d427d73b8d
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5999192888 | ||
|
|
2e624d902d | ||
|
|
a1662384dc | ||
|
|
686f536676 | ||
|
|
7d83caa27c | ||
|
|
c0c0bd7db8 | ||
|
|
d112028eb1 | ||
|
|
5820ea850a | ||
|
|
a54494c6a1 | ||
|
|
acb3b1f042 | ||
|
|
3c8bf956bf | ||
|
|
23b94b2b24 | ||
|
|
661bf3beaf | ||
|
|
c13a405d96 | ||
|
|
46ad514a70 | ||
|
|
1de4b8a0b3 | ||
|
|
c68e4b95ba | ||
|
|
beeb2b5e0e | ||
|
|
c93bead437 | ||
|
|
c047bd9843 | ||
|
|
13258e76c3 | ||
|
|
b676f35f0a | ||
|
|
66db97b6f7 | ||
|
|
884e2e8a11 | ||
|
|
a5dbbf3aed | ||
|
|
e572257f67 |
@@ -1,3 +1,10 @@
|
||||
vite_integration/static/vite/*
|
||||
!vite_integration/static/vite/.gitkeep
|
||||
node_modules/
|
||||
|
||||
# Local database and uploaded media
|
||||
/db.sqlite3
|
||||
/media/
|
||||
|
||||
# Local archives
|
||||
*.zip
|
||||
|
||||
@@ -0,0 +1,245 @@
|
||||
# Ntfy blueprint for a Django tasks and health tracker
|
||||
|
||||
This is a portable version of this project's `/settings` integration. It gives each user a topic URL, a test button, an enable switch, and one function that task or health code can call. Replace `accounts` with the app that owns your user preferences. The examples assume an authenticated `/settings/` page and Django's standard CSRF and messages middleware.
|
||||
|
||||
## 1. Store preferences
|
||||
|
||||
In `accounts/models.py` (merge these fields into an existing per-user settings model if you have one):
|
||||
|
||||
```python
|
||||
from django.conf import settings
|
||||
from django.db import models
|
||||
|
||||
class NotificationSettings(models.Model):
|
||||
user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
|
||||
ntfy_url = models.URLField(blank=True)
|
||||
ntfy_enabled = models.BooleanField(default=False)
|
||||
ntfy_last_tested_at = models.DateTimeField(null=True, blank=True)
|
||||
```
|
||||
|
||||
Run `python manage.py makemigrations accounts` and `python manage.py migrate`.
|
||||
|
||||
## 2. Add the sender
|
||||
|
||||
Create `notifications/services.py` (and an empty `notifications/__init__.py` if needed):
|
||||
|
||||
```python
|
||||
import socket
|
||||
from urllib.error import HTTPError, URLError
|
||||
from urllib.request import Request, urlopen
|
||||
|
||||
class NotificationError(Exception):
|
||||
"""A delivery error safe to display to a user."""
|
||||
|
||||
def send_ntfy_notification(url, title, message, timeout=10):
|
||||
request = Request(
|
||||
url,
|
||||
data=message.encode("utf-8"),
|
||||
headers={"Content-Type": "text/plain; charset=utf-8", "Title": title},
|
||||
method="POST",
|
||||
)
|
||||
try:
|
||||
with urlopen(request, timeout=timeout) as response:
|
||||
status = response.getcode()
|
||||
except HTTPError as error:
|
||||
raise NotificationError(f"ntfy server responded with HTTP {error.code}.") from error
|
||||
except (TimeoutError, socket.timeout):
|
||||
raise NotificationError("Connection to the ntfy server timed out.") from None
|
||||
except URLError as error:
|
||||
raise NotificationError("Could not connect to the ntfy server.") from error
|
||||
except OSError as error:
|
||||
raise NotificationError("Could not connect to the ntfy server.") from error
|
||||
if not 200 <= status < 300:
|
||||
raise NotificationError(f"ntfy server responded with HTTP {status}.")
|
||||
|
||||
def send_notification(user, title, message):
|
||||
from accounts.models import NotificationSettings
|
||||
preferences = NotificationSettings.objects.filter(user=user).first()
|
||||
if not preferences or not preferences.ntfy_enabled or not preferences.ntfy_url:
|
||||
return False
|
||||
send_ntfy_notification(preferences.ntfy_url, title, message)
|
||||
return True
|
||||
```
|
||||
|
||||
The URL is a destination and may contain a private topic name. Keep it out of logs and error messages. A user supplied server URL also lets the server make outbound requests; restrict destinations or allow only your trusted ntfy host if your deployment needs that boundary. Add authentication headers if your ntfy server requires them; this example uses a topic URL only.
|
||||
|
||||
## 3. Form, views, and routes
|
||||
|
||||
In `accounts/forms.py`:
|
||||
|
||||
```python
|
||||
from django import forms
|
||||
from .models import NotificationSettings
|
||||
|
||||
class NotificationSettingsForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = NotificationSettings
|
||||
fields = ["ntfy_url", "ntfy_enabled"]
|
||||
widgets = {"ntfy_url": forms.URLInput(attrs={"id": "ntfy-url", "placeholder": "https://ntfy.example.com/my-topic"})}
|
||||
|
||||
def clean_ntfy_url(self):
|
||||
return self.cleaned_data["ntfy_url"].strip()
|
||||
|
||||
def clean(self):
|
||||
data = super().clean()
|
||||
if data.get("ntfy_enabled") and not data.get("ntfy_url"):
|
||||
self.add_error("ntfy_url", "Enter a topic URL before enabling notifications.")
|
||||
return data
|
||||
```
|
||||
|
||||
In `accounts/views.py`:
|
||||
|
||||
```python
|
||||
from hashlib import sha256
|
||||
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.core.validators import URLValidator
|
||||
from django.shortcuts import redirect, render
|
||||
from django.utils import timezone
|
||||
from django.views.decorators.http import require_POST
|
||||
|
||||
from notifications.services import NotificationError, send_ntfy_notification
|
||||
from .forms import NotificationSettingsForm
|
||||
from .models import NotificationSettings
|
||||
|
||||
def test_key(user):
|
||||
return f"ntfy_tested_url_fingerprint:{user.pk}"
|
||||
|
||||
def fingerprint(url):
|
||||
return sha256(url.encode("utf-8")).hexdigest()
|
||||
|
||||
@login_required
|
||||
def settings_page(request):
|
||||
preferences, _ = NotificationSettings.objects.get_or_create(user=request.user)
|
||||
old_url = preferences.ntfy_url
|
||||
form = NotificationSettingsForm(request.POST or None, instance=preferences)
|
||||
if request.method == "POST" and form.is_valid():
|
||||
url = form.cleaned_data["ntfy_url"]
|
||||
just_tested = bool(url) and request.session.get(test_key(request.user)) == fingerprint(url)
|
||||
previously_tested = url == old_url and preferences.ntfy_last_tested_at is not None
|
||||
if form.cleaned_data["ntfy_enabled"] and not (just_tested or previously_tested):
|
||||
form.add_error("ntfy_url", "Test this URL successfully before enabling notifications.")
|
||||
else:
|
||||
preferences = form.save(commit=False)
|
||||
if not url:
|
||||
preferences.ntfy_enabled = False
|
||||
preferences.ntfy_last_tested_at = None
|
||||
elif just_tested:
|
||||
preferences.ntfy_last_tested_at = timezone.now()
|
||||
elif url != old_url:
|
||||
preferences.ntfy_last_tested_at = None
|
||||
preferences.save()
|
||||
request.session.pop(test_key(request.user), None)
|
||||
messages.success(request, "Notification settings saved.")
|
||||
return redirect("settings_page")
|
||||
return render(request, "accounts/settings.html", {"form": form})
|
||||
|
||||
@login_required
|
||||
@require_POST
|
||||
def test_ntfy(request):
|
||||
url = request.POST.get("ntfy_url", "").strip()
|
||||
try:
|
||||
URLValidator(schemes=["http", "https"])(url)
|
||||
except ValidationError:
|
||||
return render(request, "accounts/ntfy_test_result.html", {"error": "Enter a valid HTTP or HTTPS topic URL."}, status=400)
|
||||
try:
|
||||
send_ntfy_notification(url, "Tasks & Health", "Test notification sent successfully.")
|
||||
except NotificationError as error:
|
||||
return render(request, "accounts/ntfy_test_result.html", {"error": str(error)}, status=502)
|
||||
request.session[test_key(request.user)] = fingerprint(url)
|
||||
return render(request, "accounts/ntfy_test_result.html", {"success": True})
|
||||
```
|
||||
|
||||
In `accounts/urls.py`, include these routes under `/settings/` in the project URLconf:
|
||||
|
||||
```python
|
||||
from django.urls import path
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path("", views.settings_page, name="settings_page"),
|
||||
path("notifications/ntfy/test/", views.test_ntfy, name="ntfy_test"),
|
||||
]
|
||||
```
|
||||
|
||||
## 4. Settings UI
|
||||
|
||||
Put this section inside your existing `/settings/` template. It uses htmx for the inline test response; load htmx once in the page layout (or replace `hx-post` with a small `fetch` handler). Keep the CSRF input inside the form.
|
||||
|
||||
```html
|
||||
<form method="post" action="{% url 'settings_page' %}">
|
||||
{% csrf_token %}
|
||||
<section aria-labelledby="ntfy-title">
|
||||
<h2 id="ntfy-title">Notifications / ntfy</h2>
|
||||
<p>Use a topic URL from your ntfy server. Test it before enabling notifications.</p>
|
||||
<label for="ntfy-url">Topic URL</label>
|
||||
{{ form.ntfy_url }} {{ form.ntfy_url.errors }}
|
||||
<div class="check">
|
||||
{{ form.ntfy_enabled }}
|
||||
<label for="{{ form.ntfy_enabled.id_for_label }}">Enable ntfy notifications</label>
|
||||
</div>
|
||||
<button type="button" hx-post="{% url 'ntfy_test' %}"
|
||||
hx-include="#ntfy-url, [name='csrfmiddlewaretoken']"
|
||||
hx-target="#ntfy-test-result" hx-swap="innerHTML">Test notification</button>
|
||||
<div id="ntfy-test-result" aria-live="polite"></div>
|
||||
</section>
|
||||
<button type="submit">Save settings</button>
|
||||
</form>
|
||||
<script>
|
||||
document.querySelector("#ntfy-url").addEventListener("input", () => {
|
||||
document.querySelector("#ntfy-test-result").replaceChildren();
|
||||
});
|
||||
</script>
|
||||
```
|
||||
|
||||
`accounts/ntfy_test_result.html`:
|
||||
|
||||
```html
|
||||
{% if success %}<div class="alert alert--success">✓ Test notification sent successfully.</div>
|
||||
{% else %}<div class="alert alert--error">Could not send the test notification: {{ error }}</div>{% endif %}
|
||||
```
|
||||
|
||||
Suggested CSS, scoped to your existing settings styles:
|
||||
|
||||
```css
|
||||
#ntfy-url { width: 100%; box-sizing: border-box; min-height: 2.8rem; }
|
||||
.check { display: flex; gap: .6rem; align-items: center; }
|
||||
.check label { margin: 0; }
|
||||
.alert { margin-top: 1rem; padding: .75rem; border-radius: .55rem; }
|
||||
.alert--success { color: #d1fae5; background: #14532d; }
|
||||
.alert--error { color: #fee2e2; background: #7f1d1d; }
|
||||
```
|
||||
|
||||
## 5. Trigger from tasks or health events
|
||||
|
||||
Call the provider agnostic `send_notification` after a meaningful state change. Put delivery on a background worker for normal operation, since the HTTP call can take up to ten seconds. Queue the job after the database commit so it cannot announce a rolled back change.
|
||||
|
||||
```python
|
||||
from django.db import transaction
|
||||
|
||||
# After saving a task completion, missed deadline, check-in, or health alert:
|
||||
user_id = task.user_id
|
||||
task_id = task.pk
|
||||
transaction.on_commit(lambda: enqueue_task_event_notification(user_id, task_id))
|
||||
```
|
||||
|
||||
`enqueue_task_event_notification` is your existing Celery, RQ, or job queue entry point. In its worker, reload the user and task, confirm that the event still qualifies, then call `send_notification(user, "Task due", "Your task is due today.")`. Catch `NotificationError`, log a safe error without the topic URL, and retry according to your queue policy. Use an event ID or unique job key if duplicate delivery matters. If you have no worker yet, a management command run by cron can drain a small notification outbox instead.
|
||||
|
||||
Typical mapping for this app:
|
||||
|
||||
| App event | Suggested message | Trigger location |
|
||||
| --- | --- | --- |
|
||||
| Task due | “Your task is due today.” | Scheduled due-date job |
|
||||
| Task completed | “Task completed.” | Completion service, after commit |
|
||||
| Check-in missed | “Your daily check-in is still open.” | Scheduled reminder job |
|
||||
| Health threshold crossed | “A tracked value crossed your chosen threshold.” | Threshold evaluator, after commit |
|
||||
|
||||
Avoid including sensitive health measurements in the notification unless the user explicitly opts in. Define the event's recipient and idempotency rule in the app service, rather than in the ntfy sender.
|
||||
|
||||
## 6. Minimum verification
|
||||
|
||||
Test an invalid URL, a failed test, a successful test followed by save, a changed URL requiring a new test, and disabled settings suppressing sends. Mock `urlopen` or `send_ntfy_notification`; do not send real notifications in tests. Check one actual device delivery manually with a private topic before enabling event triggers.
|
||||
|
||||
Source implementation in this repo: `members/views.py`, `members/forms.py`, `members/models.py`, `members/templates/members/user_settings.html`, `notifications/services.py`, and `fireworks_detect/signals.py`. The source app groups Pending events by minute with `PendingNotificationBatch` and a scheduled command; use that pattern if your tracker needs digest notifications.
|
||||
@@ -121,3 +121,32 @@ server mode requires an audio file or browser mode.
|
||||
Browser assets are loaded only after the user enables the toggle and selects a
|
||||
file. Regenerate the self-hosted model using [the YAMNet build guide](scripts/BROWSER_YAMNET.md),
|
||||
then run `npm run build` and `python manage.py collectstatic --noinput`.
|
||||
# Pending event notifications
|
||||
|
||||
Users can test and enable an ntfy topic in Settings. New Pending events are
|
||||
counted by source (manual or sensor) in one-minute batches per enabled user.
|
||||
Run `python manage.py send_pending_notifications` once per minute with the
|
||||
application's Python environment and working directory. For example, a cron
|
||||
entry can use `* * * * * cd /path/to/django && /path/to/python manage.py send_pending_notifications`.
|
||||
It sends completed minute batches,
|
||||
then removes them; failed deliveries remain queued for the next run.
|
||||
|
||||
For a systemd user timer on the laptop, install the units in
|
||||
[`deploy/systemd/`](deploy/systemd/) and start the timer:
|
||||
|
||||
```sh
|
||||
cd /home/jorenmartijn/python/django
|
||||
/usr/bin/python3 -m venv /home/jorenmartijn/python/.venv-notifications
|
||||
/home/jorenmartijn/python/.venv-notifications/bin/python -m pip install -r requirements.txt
|
||||
/home/jorenmartijn/python/.venv-notifications/bin/python manage.py check
|
||||
mkdir -p ~/.config/systemd/user
|
||||
cp deploy/systemd/send-pending-notifications.service deploy/systemd/send-pending-notifications.timer ~/.config/systemd/user/
|
||||
systemctl --user daemon-reload
|
||||
systemctl --user enable --now send-pending-notifications.timer
|
||||
systemctl --user list-timers send-pending-notifications.timer
|
||||
```
|
||||
|
||||
The service runs `/home/jorenmartijn/python/.venv-notifications/bin/python` with this
|
||||
project as its working directory. To keep the user timer running after logout,
|
||||
run `sudo loginctl enable-linger jorenmartijn` once on the laptop. Check a run
|
||||
with `journalctl --user -u send-pending-notifications.service -n 30`.
|
||||
|
||||
BIN
Binary file not shown.
@@ -0,0 +1,7 @@
|
||||
[Unit]
|
||||
Description=Send batched Pending event ntfy notifications
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
WorkingDirectory=/home/jorenmartijn/python/django
|
||||
ExecStart=/home/jorenmartijn/python/.venv-notifications/bin/python /home/jorenmartijn/python/django/manage.py send_pending_notifications
|
||||
@@ -0,0 +1,11 @@
|
||||
[Unit]
|
||||
Description=Send Pending event ntfy summaries every minute
|
||||
|
||||
[Timer]
|
||||
OnCalendar=*-*-* *:*:00
|
||||
AccuracySec=1s
|
||||
Persistent=true
|
||||
Unit=send-pending-notifications.service
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -3,3 +3,6 @@ from django.apps import AppConfig
|
||||
|
||||
class FireworksDetectConfig(AppConfig):
|
||||
name = 'fireworks_detect'
|
||||
|
||||
def ready(self):
|
||||
from . import signals # noqa: F401
|
||||
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
@@ -0,0 +1,19 @@
|
||||
from django.db.models import F
|
||||
from django.db.models.signals import post_save
|
||||
from django.dispatch import receiver
|
||||
from django.utils import timezone
|
||||
|
||||
from members.models import PendingNotificationBatch, UserSettings
|
||||
|
||||
from .models import PendingEvent
|
||||
|
||||
|
||||
@receiver(post_save, sender=PendingEvent)
|
||||
def count_new_pending_event(sender, instance, created, **kwargs):
|
||||
if not created:
|
||||
return
|
||||
minute = timezone.now().replace(second=0, microsecond=0)
|
||||
field = "manual_count" if instance.source_type == PendingEvent.SourceType.MANUAL else "sensor_count"
|
||||
for user_id in UserSettings.objects.filter(ntfy_enabled=True).exclude(ntfy_url="").values_list("user_id", flat=True):
|
||||
batch, _ = PendingNotificationBatch.objects.get_or_create(user_id=user_id, minute=minute)
|
||||
PendingNotificationBatch.objects.filter(pk=batch.pk).update(**{field: F(field) + 1})
|
||||
@@ -3,7 +3,7 @@
|
||||
<html lang="{{ request.LANGUAGE_CODE|default:'en' }}" data-theme="dark">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
|
||||
<title>{% trans "Report fireworks · Sound Signal" %}</title>
|
||||
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css">
|
||||
<script src="https://cdn.jsdelivr.net/npm/htmx.org@2.0.4/dist/htmx.min.js"></script>
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
{% load i18n %}
|
||||
<div class="manual-direction-panel{% if measuring %} manual-direction-panel--open{% endif %}" id="manual-direction-panel" data-state="{% if measuring %}ready{% else %}idle{% endif %}">
|
||||
{% if measuring %}
|
||||
<div class="manual-direction-panel__topline">
|
||||
<strong class="manual-direction-panel__heading">{% trans "Capture direction" %}</strong>
|
||||
<button class="manual-direction-panel__close" type="button" hx-get="{% url 'fireworks_detect:manual_direction_panel' %}" hx-target="#manual-direction-panel" hx-swap="outerHTML" aria-label="{% trans 'Close direction capture' %}">×</button>
|
||||
</div>
|
||||
<p class="manual-direction-panel__copy">{% trans "Point the top of your phone toward the fireworks, then capture a single compass reading." %}</p>
|
||||
<div id="manual-direction-status" class="manual-direction-panel__status" aria-live="polite"></div>
|
||||
<button id="manual-capture-direction" class="manual-direction-panel__button" type="button">{% trans "Start measuring direction" %}</button>
|
||||
{% else %}
|
||||
<strong class="manual-direction-panel__heading">{% trans "Direction" %} <span>({% trans "optional" %})</span></strong>
|
||||
<p id="manual-direction-summary" class="manual-direction-panel__summary">{% trans "Not captured" %}</p>
|
||||
<button class="manual-direction-panel__open" type="button" hx-get="{% url 'fireworks_detect:manual_direction_panel' %}?mode=measure" hx-target="#manual-direction-panel" hx-swap="outerHTML">{% trans "Capture direction" %}</button>
|
||||
{% endif %}
|
||||
</div>
|
||||
@@ -1,25 +1,46 @@
|
||||
{% load i18n %}
|
||||
<section class="manual-report" aria-labelledby="manual-report-title">
|
||||
<p class="eyebrow">{% trans "Recording optional" %}</p>
|
||||
<h2 class="manual-report__title" id="manual-report-title">{% trans "Report fireworks now" %}</h2>
|
||||
<p class="manual-report__intro">{% trans "Choose how many times you heard fireworks, then send it straight to Pending. The report is timestamped now." %}</p>
|
||||
<form id="manual-report-form" action="{% url "fireworks_detect:submit_manual_pending" %}" method="post" enctype="multipart/form-data" hx-post="{% url "fireworks_detect:submit_manual_pending" %}" hx-target="#manual-submission" hx-swap="outerHTML">
|
||||
<header class="manual-report__header">
|
||||
<p class="eyebrow">{% trans "Quick report" %}</p>
|
||||
<div class="manual-report__heading-row"><span class="manual-report__fire" aria-hidden="true">🔥</span><h2 class="manual-report__title" id="manual-report-title">{% trans "Report fireworks now" %}</h2></div>
|
||||
<p class="manual-report__intro">{% trans "Did you hear a bang? Report what you heard in a few taps." %}</p>
|
||||
<div class="report-clock" role="group" aria-label="{% trans 'Report time' %}">
|
||||
<span class="report-clock__label" aria-hidden="true">{% trans "Report time" %}</span>
|
||||
<div class="report-clock__display">
|
||||
<time id="manual-report-time" class="report-clock__time" aria-label="{% trans 'Now' %}">
|
||||
<span id="report-clock-hours" aria-hidden="true">--</span><span class="report-clock__colon" aria-hidden="true">:</span><span id="report-clock-minutes" aria-hidden="true">--</span>
|
||||
</time>
|
||||
<span class="report-clock__now" aria-hidden="true"><span class="report-clock__dot"></span>{% trans "Now" %}</span>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
<form id="manual-report-form" action="{% url "fireworks_detect:submit_manual_pending" %}" method="post" enctype="multipart/form-data">
|
||||
{% csrf_token %}
|
||||
<label class="manual-report__label" for="manual-occurrences">{% trans "Number of occurrences" %}</label>
|
||||
<input id="manual-latitude" name="latitude" type="hidden">
|
||||
<input id="manual-longitude" name="longitude" type="hidden">
|
||||
<input id="manual-direction-degrees" name="direction_degrees" type="hidden">
|
||||
<input id="manual-direction-accuracy" name="direction_accuracy_degrees" type="hidden">
|
||||
<div class="manual-report__primary">
|
||||
<div class="manual-report__quantity">
|
||||
<label class="manual-report__label" for="manual-occurrences">{% trans "How many times did you hear it?" %}</label>
|
||||
<div class="manual-report__stepper">
|
||||
<button id="manual-decrease" type="button" aria-label="{% trans 'Decrease occurrences' %}">−</button>
|
||||
<input id="manual-occurrences" name="occurrences" type="number" min="1" max="1000" value="1" required inputmode="numeric">
|
||||
<div class="manual-direction-panel" id="manual-direction-panel" hidden>
|
||||
<strong class="manual-direction-panel__heading">{% trans "Direction" %} <span>({% trans "optional" %})</span></strong>
|
||||
<p class="manual-direction-panel__copy">{% trans "Point the top of your phone toward the fireworks, then capture a single compass reading." %}</p>
|
||||
<button id="manual-capture-direction" class="manual-direction-panel__button" type="button">{% trans "Capture direction" %}</button>
|
||||
<div id="manual-direction-status" class="manual-direction-panel__status" aria-live="polite"></div>
|
||||
<button id="manual-increase" type="button" aria-label="{% trans 'Increase occurrences' %}">+</button>
|
||||
</div>
|
||||
<button id="manual-submit" class="manual-report__submit" type="button">{% trans "I heard fireworks — send to Pending" %}</button>
|
||||
<div class="burst-listener">
|
||||
<button id="burst-start" class="burst-listener__button" type="button">{% trans "Listen for next bang" %}</button>
|
||||
</div>
|
||||
{% include "fireworks_detect/includes/manual_direction_panel.html" %}
|
||||
</div>
|
||||
<section class="manual-report__supporting" data-state="off" aria-labelledby="manual-listening-title">
|
||||
<div class="manual-report__supporting-header">
|
||||
<span class="manual-report__microphone" aria-hidden="true">🎙</span>
|
||||
<div>
|
||||
<h3 id="manual-listening-title">{% trans "Automatic detection" %}</h3>
|
||||
<span id="burst-state" class="burst-listener__state" aria-live="polite">{% trans "Not listening" %}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="burst-listener" data-state="off">
|
||||
<button id="burst-start" class="burst-listener__button" type="button">{% trans "Start listening" %}</button>
|
||||
<div id="burst-panel" class="burst-listener__panel" hidden>
|
||||
<strong id="burst-heading" aria-live="polite"></strong>
|
||||
<canvas id="burst-waveform" width="600" height="90" aria-label="{% trans 'Live microphone waveform' %}"></canvas>
|
||||
@@ -33,6 +54,23 @@
|
||||
</div>
|
||||
<p id="burst-error" role="alert" hidden></p>
|
||||
</div>
|
||||
</section>
|
||||
<button id="manual-submit" class="manual-report__submit" type="button"><span aria-hidden="true">🔥</span> <span id="manual-submit-label">{% trans "I heard fireworks" %}</span></button>
|
||||
</form>
|
||||
<div id="manual-submission" class="manual-report__submission" aria-live="polite"></div>
|
||||
<div id="manual-compass-home">
|
||||
<div id="manual-compass" class="manual-compass" role="img" aria-label="{% trans 'Compass direction' %}" hidden>
|
||||
<div class="manual-compass__dial" aria-hidden="true">
|
||||
<div id="manual-compass-rose" class="manual-compass__rose">
|
||||
<span class="manual-compass__north">N</span>
|
||||
<span class="manual-compass__east">E</span>
|
||||
<span class="manual-compass__south">S</span>
|
||||
<span class="manual-compass__west">W</span>
|
||||
</div>
|
||||
<span class="manual-compass__pointer"></span>
|
||||
<span class="manual-compass__center"></span>
|
||||
</div>
|
||||
<span id="manual-compass-heading" class="manual-compass__heading"></span>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@@ -7,6 +7,14 @@
|
||||
<a href="{% url "fireworks_detect:fireworks" %}"{% if active_page == "analyse" %} aria-current="page"{% endif %}>{% trans "Analyse" %}</a>
|
||||
<a href="{% url "fireworks_detect:map" %}"{% if active_page == "map" %} aria-current="page"{% endif %}>{% trans "Map" %}</a>
|
||||
<a href="{% url "fireworks_detect:events" %}"{% if active_page == "events" %} aria-current="page"{% endif %}>{% trans "Events" %}</a>
|
||||
{% if request.user.is_authenticated %}
|
||||
<form action="{% url 'logout' %}" method="post">
|
||||
{% csrf_token %}
|
||||
<button type="submit">{% trans "Sign out" %}</button>
|
||||
</form>
|
||||
{% else %}
|
||||
<a href="{% url 'login' %}">{% trans "Sign in" %}</a>
|
||||
{% endif %}
|
||||
</nav>
|
||||
{% if not request.user.is_authenticated %}
|
||||
<form class="public-language" action="{% url 'set_anonymous_language' %}" method="post" style="display:flex;align-items:center;gap:.3rem;color:var(--muted,#aab9d8);font-size:.78rem">
|
||||
|
||||
@@ -1,8 +1,17 @@
|
||||
{% load i18n %}
|
||||
<div id="manual-submission" role="status">
|
||||
<div id="manual-submission" class="manual-submission{% if error %} manual-submission--error{% else %} manual-submission--success{% endif %}" role="status" data-result="{% if error %}error{% else %}success{% endif %}">
|
||||
{% if error %}
|
||||
<strong>{% trans "Could not report fireworks" %}</strong><p>{{ error }}</p>
|
||||
<span class="manual-submission__icon" aria-hidden="true">!</span>
|
||||
<strong>{% trans "Could not report fireworks" %}</strong>
|
||||
<p>{{ error }}</p>
|
||||
{% else %}
|
||||
<strong>{% trans "Report sent to Pending" %}</strong><p>{% blocktrans count count=pending.occurrences with time=pending.created_at|date:"H:i" %}{{ count }} occurrence reported at {{ time }}.{% plural %}{{ count }} occurrences reported at {{ time }}.{% endblocktrans %}</p>
|
||||
<span class="manual-submission__icon" aria-hidden="true">✓</span>
|
||||
<strong>{% trans "Report received!" %}</strong>
|
||||
<p>{% trans "Thank you. Your report helps map fireworks nearby." %}</p>
|
||||
<p class="manual-submission__summary">
|
||||
{{ pending.created_at|date:"H:i" }} ·
|
||||
{% blocktrans count count=pending.occurrences %}{{ count }} occurrence{% plural %}{{ count }} occurrences{% endblocktrans %}
|
||||
{% if direction_label %} · {{ direction_label }} {{ pending.direction_degrees|floatformat:0 }}°{% endif %}
|
||||
</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
@@ -62,7 +62,9 @@ class ManualPendingEventTests(TestCase):
|
||||
})
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertContains(response, "Report sent to Pending")
|
||||
self.assertContains(response, "Report received!")
|
||||
self.assertContains(response, "4 occurrences")
|
||||
self.assertContains(response, 'data-result="success"')
|
||||
pending = PendingEvent.objects.get()
|
||||
self.assertEqual(pending.original_filename, "Manual fireworks report")
|
||||
self.assertEqual(pending.source_type, PendingEvent.SourceType.MANUAL)
|
||||
@@ -83,6 +85,7 @@ class ManualPendingEventTests(TestCase):
|
||||
|
||||
self.assertEqual(response.status_code, 400)
|
||||
self.assertContains(response, "Choose between 1 and 1,000 occurrences.", status_code=400)
|
||||
self.assertContains(response, 'data-result="error"', status_code=400)
|
||||
self.assertFalse(PendingEvent.objects.exists())
|
||||
|
||||
def test_manual_report_accepts_optional_wav_on_the_same_pending_event(self):
|
||||
@@ -157,9 +160,14 @@ class ManualPendingEventTests(TestCase):
|
||||
response = self.client.get(reverse("hello"))
|
||||
|
||||
self.assertContains(response, "Report fireworks now")
|
||||
self.assertContains(response, "I heard fireworks — send to Pending")
|
||||
self.assertContains(response, "I heard fireworks")
|
||||
self.assertContains(response, "Capture direction")
|
||||
self.assertContains(response, 'manual-direction-panel" hidden')
|
||||
self.assertContains(response, 'id="manual-decrease"')
|
||||
self.assertContains(response, 'id="manual-increase"')
|
||||
self.assertContains(response, 'id="manual-direction-panel"')
|
||||
self.assertContains(response, 'hx-get="/fireworks/manual-direction/?mode=measure"')
|
||||
self.assertContains(response, 'id="manual-compass"')
|
||||
self.assertContains(response, 'aria-label="Compass direction" hidden')
|
||||
self.assertContains(response, "htmx.min.js")
|
||||
self.assertContains(response, "/static/vite/")
|
||||
self.assertContains(response, 'type="module"')
|
||||
@@ -167,6 +175,29 @@ class ManualPendingEventTests(TestCase):
|
||||
self.assertContains(response, "Open map controls")
|
||||
self.assertContains(response, "Classify a recording")
|
||||
|
||||
def test_direction_subsection_opens_and_closes_with_htmx_fragments(self):
|
||||
url = reverse("fireworks_detect:manual_direction_panel")
|
||||
measuring = self.client.get(url, {"mode": "measure"}, HTTP_HX_REQUEST="true")
|
||||
self.assertContains(measuring, 'id="manual-capture-direction"')
|
||||
self.assertContains(measuring, 'hx-target="#manual-direction-panel"')
|
||||
|
||||
closed = self.client.get(url, HTTP_HX_REQUEST="true")
|
||||
self.assertContains(closed, 'id="manual-direction-summary"')
|
||||
self.assertNotContains(closed, 'id="manual-capture-direction"')
|
||||
|
||||
def test_dutch_report_labels_and_direction_are_translated(self):
|
||||
self.client.cookies["django_language"] = "nl"
|
||||
page = self.client.get(reverse("hello"))
|
||||
self.assertContains(page, "Hoe vaak hoorde je het?")
|
||||
self.assertContains(page, "Ik hoorde vuurwerk")
|
||||
self.assertContains(page, "Start luisteren")
|
||||
|
||||
response = self.client.post(reverse("fireworks_detect:submit_manual_pending"), {
|
||||
"occurrences": "1", "direction_degrees": "192",
|
||||
})
|
||||
self.assertContains(response, "Melding ontvangen!")
|
||||
self.assertContains(response, "Zuid 192°")
|
||||
|
||||
def test_old_route_preserves_the_previous_landing_page(self):
|
||||
response = self.client.get(reverse("old_home"))
|
||||
|
||||
@@ -275,6 +306,9 @@ class ManualPendingEventTests(TestCase):
|
||||
"direction_accuracy_degrees": "8",
|
||||
})
|
||||
|
||||
self.assertContains(response, "2 occurrences")
|
||||
self.assertContains(response, "Southwest 237°")
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
pending = PendingEvent.objects.get()
|
||||
self.assertEqual(pending.direction_degrees, 237)
|
||||
|
||||
@@ -10,6 +10,7 @@ from .views import (
|
||||
fireworks_map_view,
|
||||
fireworks_view,
|
||||
pending_audio,
|
||||
manual_direction_panel,
|
||||
submit_manual_pending_event,
|
||||
submit_pending_event,
|
||||
sensor_heartbeat,
|
||||
@@ -27,6 +28,7 @@ urlpatterns = [
|
||||
path("heartbeat/", sensor_heartbeat, name="sensor_heartbeat"),
|
||||
path("submit-pending/", submit_pending_event, name="submit_pending"),
|
||||
path("submit-manual-pending/", submit_manual_pending_event, name="submit_manual_pending"),
|
||||
path("manual-direction/", manual_direction_panel, name="manual_direction_panel"),
|
||||
path("events/", events_view, name="events"),
|
||||
path("events/list/", events_list, name="events_list"),
|
||||
path("admin-audio/pending/<int:event_id>/", pending_audio, name="pending_audio"),
|
||||
|
||||
@@ -363,6 +363,15 @@ def _manual_direction(request):
|
||||
accuracy = None
|
||||
return heading, accuracy
|
||||
|
||||
|
||||
@require_http_methods(["GET"])
|
||||
@never_cache
|
||||
def manual_direction_panel(request):
|
||||
return render(request, "fireworks_detect/includes/manual_direction_panel.html", {
|
||||
"measuring": request.GET.get("mode") == "measure",
|
||||
})
|
||||
|
||||
|
||||
@require_http_methods(["POST"])
|
||||
@never_cache
|
||||
def submit_manual_pending_event(request):
|
||||
@@ -406,7 +415,14 @@ def submit_manual_pending_event(request):
|
||||
direction_accuracy_degrees=direction_accuracy_degrees,
|
||||
direction_source="device_compass" if direction_degrees is not None else "",
|
||||
)
|
||||
return render(request, "fireworks_detect/manual_pending_submission.html", {"pending": pending})
|
||||
direction_names = {
|
||||
"N": _("North"), "NE": _("Northeast"), "E": _("East"), "SE": _("Southeast"),
|
||||
"S": _("South"), "SW": _("Southwest"), "W": _("West"), "NW": _("Northwest"),
|
||||
}
|
||||
return render(request, "fireworks_detect/manual_pending_submission.html", {
|
||||
"pending": pending,
|
||||
"direction_label": direction_names.get(pending.direction_cardinal) if direction_degrees is not None else "",
|
||||
})
|
||||
|
||||
@never_cache
|
||||
def events_list(request):
|
||||
|
||||
@@ -3,6 +3,8 @@ import "../styles/pages/fireworks-home.css";
|
||||
import "../styles/pages/map.css";
|
||||
import "../styles/pages/dashboard.css";
|
||||
import "../styles/components/burst-listener.css";
|
||||
import "../styles/components/manual-compass.css";
|
||||
import "../styles/components/manual-report-structure.css";
|
||||
import "../styles/theme.css";
|
||||
import "../scripts/theme.js";
|
||||
import "../scripts/manual-report.js";
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import "../styles/pages/home.css";
|
||||
import "../styles/components/burst-listener.css";
|
||||
import "../styles/components/manual-compass.css";
|
||||
import "../styles/components/manual-report-structure.css";
|
||||
import "../styles/theme.css";
|
||||
import "../scripts/theme.js";
|
||||
import "../scripts/manual-report.js";
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import "../styles/pages/settings.css";
|
||||
import "../styles/components/fireworks-navigation.css";
|
||||
import "../styles/theme.css";
|
||||
import "../scripts/theme.js";
|
||||
import "../scripts/user-settings.js";
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
const form = document.querySelector("#manual-report-form");
|
||||
const t = window.BOOMCAST_I18N || {};
|
||||
|
||||
export function createBurstListener() {
|
||||
if (!form) return null;
|
||||
const start = document.querySelector("#burst-start");
|
||||
const container = start.closest(".burst-listener");
|
||||
const section = start.closest(".manual-report__supporting");
|
||||
const stateLabel = document.querySelector("#burst-state");
|
||||
const panel = document.querySelector("#burst-panel");
|
||||
const heading = document.querySelector("#burst-heading");
|
||||
const detail = document.querySelector("#burst-detail");
|
||||
@@ -42,11 +46,14 @@ export function createBurstListener() {
|
||||
|
||||
function setState(next) {
|
||||
state = next;
|
||||
if (container) container.dataset.state = next;
|
||||
if (section) section.dataset.state = next;
|
||||
if (stateLabel) stateLabel.textContent = next === "listening" ? (t.listeningNextBang || "Listening for the next bang") : next === "tail" ? (t.soundDetected || "Sound detected") : next === "captured" ? (t.soundCaptured || "Sound captured") : (t.notListening || "Not listening");
|
||||
start.hidden = next !== "off";
|
||||
panel.hidden = next === "off";
|
||||
resume.hidden = discard.hidden = next !== "captured";
|
||||
heading.textContent = next === "captured" ? "Sound captured" : next === "tail" ? "Sound detected — finishing clip…" : "Listening for the next sound…";
|
||||
detail.textContent = next === "listening" ? "Keeping the most recent ~10 seconds" : next === "captured" ? "Preview the clip or send your report." : "";
|
||||
heading.textContent = next === "captured" ? (t.soundCaptured || "Sound captured") : next === "tail" ? (t.soundDetectedFinishing || "Sound detected — finishing clip…") : (t.listeningNextSound || "Listening for the next sound…");
|
||||
detail.textContent = next === "listening" ? (t.keepingRecentAudio || "Keeping the most recent ~10 seconds") : next === "captured" ? (t.previewClipOrSend || "Preview the clip or send your report.") : "";
|
||||
}
|
||||
|
||||
function wav(samples, rate) {
|
||||
@@ -73,6 +80,9 @@ export function createBurstListener() {
|
||||
async function begin() {
|
||||
error.hidden = true;
|
||||
start.disabled = true;
|
||||
if (container) container.dataset.state = "starting";
|
||||
if (section) section.dataset.state = "starting";
|
||||
if (stateLabel) stateLabel.textContent = t.startingMicrophone || "Starting microphone…";
|
||||
try {
|
||||
if (!navigator.mediaDevices?.getUserMedia || !window.AudioWorkletNode) throw new Error("Microphone listening is unavailable in this browser or connection.");
|
||||
stream = await navigator.mediaDevices.getUserMedia({ audio: { channelCount: 1 }, video: false });
|
||||
@@ -111,7 +121,10 @@ export function createBurstListener() {
|
||||
setState("listening");
|
||||
} catch (cause) {
|
||||
await end();
|
||||
error.textContent = cause.name === "NotAllowedError" ? "Microphone permission was denied. Manual reporting is still available." : (cause.message || "Microphone capture failed.");
|
||||
if (container) container.dataset.state = "error";
|
||||
if (section) section.dataset.state = "error";
|
||||
if (stateLabel) stateLabel.textContent = t.microphoneUnavailable || "Microphone unavailable";
|
||||
error.textContent = cause.name === "NotAllowedError" ? (t.microphoneDenied || "Microphone permission was denied. Manual reporting is still available.") : (t.microphoneFailed || "Microphone capture failed.");
|
||||
error.hidden = false;
|
||||
} finally {
|
||||
start.disabled = false;
|
||||
|
||||
@@ -3,41 +3,135 @@
|
||||
|
||||
const manualForm = document.querySelector("#manual-report-form");
|
||||
const manualSubmit = document.querySelector("#manual-submit");
|
||||
const manualStatus = document.querySelector("#manual-submission");
|
||||
const submitLabel = document.querySelector("#manual-submit-label");
|
||||
const occurrences = document.querySelector("#manual-occurrences");
|
||||
const decrease = document.querySelector("#manual-decrease");
|
||||
const increase = document.querySelector("#manual-increase");
|
||||
const latitude = document.querySelector("#manual-latitude");
|
||||
const longitude = document.querySelector("#manual-longitude");
|
||||
const directionDegrees = document.querySelector("#manual-direction-degrees");
|
||||
const directionAccuracy = document.querySelector("#manual-direction-accuracy");
|
||||
const captureDirectionButton = document.querySelector("#manual-capture-direction");
|
||||
const directionStatus = document.querySelector("#manual-direction-status");
|
||||
const directionPanel = document.querySelector("#manual-direction-panel");
|
||||
const isMobileDevice = /Android|iPhone|iPad|iPod|IEMobile|Opera Mini/.test(navigator.userAgent)
|
||||
|| (navigator.userAgent.includes("Macintosh") && navigator.maxTouchPoints > 1);
|
||||
if (isMobileDevice) directionPanel.hidden = false;
|
||||
const captureDirectionButton = () => document.querySelector("#manual-capture-direction");
|
||||
const directionStatus = () => document.querySelector("#manual-direction-status");
|
||||
const directionPanel = () => document.querySelector("#manual-direction-panel");
|
||||
const compass = document.querySelector("#manual-compass");
|
||||
const compassHome = document.querySelector("#manual-compass-home");
|
||||
const compassRose = document.querySelector("#manual-compass-rose");
|
||||
const compassHeading = document.querySelector("#manual-compass-heading");
|
||||
const reportTime = document.querySelector("#manual-report-time");
|
||||
const reportHours = document.querySelector("#report-clock-hours");
|
||||
const reportMinutes = document.querySelector("#report-clock-minutes");
|
||||
let orientationListener;
|
||||
let compassUnavailableTimeout;
|
||||
let compassRotation = null;
|
||||
const burstListener = createBurstListener();
|
||||
|
||||
const isUsableNumber = (value) => Number.isFinite(value);
|
||||
const cardinalDirection = (heading) => ["N", "NE", "E", "SE", "S", "SW", "W", "NW"][Math.floor(((heading + 22.5) % 360) / 45)];
|
||||
const cardinalDirection = (heading) => [
|
||||
t.north || "North", t.northeast || "Northeast", t.east || "East", t.southeast || "Southeast",
|
||||
t.south || "South", t.southwest || "Southwest", t.west || "West", t.northwest || "Northwest",
|
||||
][Math.floor(((heading + 22.5) % 360) / 45)];
|
||||
const displayDegrees = (value) => Number(value.toFixed(1)).toString();
|
||||
const updateReportTime = () => {
|
||||
if (!reportTime) return;
|
||||
const now = new Date();
|
||||
reportTime.dateTime = now.toISOString();
|
||||
const parts = new Intl.DateTimeFormat(document.documentElement.lang || undefined, { hour: "2-digit", minute: "2-digit", hourCycle: "h23" }).formatToParts(now);
|
||||
const hours = parts.find((part) => part.type === "hour")?.value;
|
||||
const minutes = parts.find((part) => part.type === "minute")?.value;
|
||||
if (!hours || !minutes || !reportHours || !reportMinutes) return;
|
||||
reportHours.textContent = hours;
|
||||
reportMinutes.textContent = minutes;
|
||||
reportTime.setAttribute("aria-label", `${hours}:${minutes}`);
|
||||
};
|
||||
updateReportTime();
|
||||
if (reportTime) window.setInterval(updateReportTime, 60000);
|
||||
const idleSubmitLabel = submitLabel?.textContent || "I heard fireworks";
|
||||
|
||||
const setSubmissionState = (next, message = "") => {
|
||||
manualForm.dataset.state = next;
|
||||
manualSubmit.disabled = next === "submitting";
|
||||
if (submitLabel) submitLabel.textContent = next === "submitting" ? (t.sendingReport || "Sending…") : idleSubmitLabel;
|
||||
if (message) {
|
||||
const status = document.querySelector("#manual-submission");
|
||||
status.className = "manual-report__submission";
|
||||
status.textContent = message;
|
||||
}
|
||||
};
|
||||
|
||||
const showResponse = (html, successful) => {
|
||||
const parsed = new DOMParser().parseFromString(html, "text/html").querySelector("#manual-submission");
|
||||
if (!parsed) {
|
||||
setSubmissionState("error", t.reportFailed || "Could not send the report. Please try again.");
|
||||
return false;
|
||||
}
|
||||
document.querySelector("#manual-submission").replaceWith(parsed);
|
||||
setSubmissionState(successful ? "submitted" : "error");
|
||||
return successful;
|
||||
};
|
||||
|
||||
const setCount = (value) => {
|
||||
const count = Number.parseInt(value, 10);
|
||||
occurrences.value = String(Math.min(1000, Math.max(1, Number.isFinite(count) ? count : 1)));
|
||||
decrease.disabled = occurrences.value === "1";
|
||||
increase.disabled = occurrences.value === "1000";
|
||||
};
|
||||
setCount(occurrences.value);
|
||||
decrease.addEventListener("click", () => setCount(Number(occurrences.value) - 1));
|
||||
increase.addEventListener("click", () => setCount(Number(occurrences.value) + 1));
|
||||
occurrences.addEventListener("change", () => setCount(occurrences.value));
|
||||
|
||||
const stopCompassReading = () => {
|
||||
if (orientationListener) window.removeEventListener("deviceorientation", orientationListener);
|
||||
window.clearTimeout(compassUnavailableTimeout);
|
||||
orientationListener = null;
|
||||
compassUnavailableTimeout = null;
|
||||
compass.hidden = true;
|
||||
compassRotation = null;
|
||||
};
|
||||
|
||||
const updateCompass = (heading) => {
|
||||
const targetRotation = -heading;
|
||||
if (compassRotation === null) {
|
||||
compassRotation = targetRotation;
|
||||
compassRose.style.transition = "none";
|
||||
compassRose.style.transform = `rotate(${compassRotation}deg)`;
|
||||
// Restore the short rotation animation after the initial reading.
|
||||
compassRose.offsetWidth;
|
||||
compassRose.style.transition = "";
|
||||
} else {
|
||||
const change = ((targetRotation - compassRotation + 540) % 360) - 180;
|
||||
compassRotation += change;
|
||||
compassRose.style.transform = `rotate(${compassRotation}deg)`;
|
||||
}
|
||||
compassHeading.textContent = `${displayDegrees(heading)}° · ${cardinalDirection(heading)}`;
|
||||
compass.setAttribute("aria-label", `${t.compassDirection || "Compass direction"} ${displayDegrees(heading)}° ${cardinalDirection(heading)}`);
|
||||
compass.hidden = false;
|
||||
};
|
||||
|
||||
const showCapturedDirection = (heading, accuracy) => {
|
||||
const accuracyText = accuracy === null ? (t.accuracyUnavailable || "Accuracy unavailable") : (t.accuracy || "Accuracy") + ": ±" + displayDegrees(accuracy) + "°";
|
||||
directionStatus.innerHTML = "<strong>" + displayDegrees(heading) + "° · " + cardinalDirection(heading) + "</strong><br>" + accuracyText;
|
||||
captureDirectionButton.textContent = (t.stopCapture || "Stop direction capture");
|
||||
const status = directionStatus();
|
||||
if (status) {
|
||||
status.classList.toggle("manual-direction-panel__status--accuracy", accuracy !== null);
|
||||
if (accuracy === null) {
|
||||
status.textContent = t.accuracyUnavailable || "Accuracy unavailable";
|
||||
} else {
|
||||
const label = document.createElement("span");
|
||||
label.textContent = t.accuracy || "Accuracy";
|
||||
const value = document.createElement("strong");
|
||||
value.textContent = `±${displayDegrees(accuracy)}°`;
|
||||
status.replaceChildren(label, value);
|
||||
}
|
||||
}
|
||||
const button = captureDirectionButton();
|
||||
if (button) button.textContent = (t.stopCapture || "Stop measuring direction");
|
||||
};
|
||||
|
||||
const listenForCompassReading = () => {
|
||||
if (!directionStatus()) return;
|
||||
stopCompassReading();
|
||||
directionStatus.textContent = (t.pointPhone || "Point the top of your phone toward the sound — direction will update live.");
|
||||
if (directionPanel()) directionPanel().dataset.state = "measuring";
|
||||
directionStatus().textContent = (t.pointPhone || "Point the top of your phone toward the sound — direction will update live.");
|
||||
orientationListener = (event) => {
|
||||
const isWebKitCompass = "webkitCompassHeading" in event;
|
||||
const heading = isUsableNumber(event.webkitCompassHeading)
|
||||
@@ -53,39 +147,49 @@
|
||||
directionDegrees.value = heading;
|
||||
directionAccuracy.value = accuracy === null ? "" : accuracy;
|
||||
showCapturedDirection(heading, accuracy);
|
||||
updateCompass(heading);
|
||||
window.clearTimeout(compassUnavailableTimeout);
|
||||
};
|
||||
window.addEventListener("deviceorientation", orientationListener);
|
||||
compassUnavailableTimeout = window.setTimeout(() => {
|
||||
stopCompassReading();
|
||||
captureDirectionButton.textContent = (t.captureDirection || "Capture direction");
|
||||
directionStatus.textContent = (t.compassUnavailable || "Compass unavailable on this device.");
|
||||
const button = captureDirectionButton();
|
||||
const status = directionStatus();
|
||||
if (button) button.textContent = (t.captureDirection || "Start measuring direction");
|
||||
if (status) status.textContent = (t.compassUnavailable || "Compass unavailable on this device.");
|
||||
if (directionPanel()) directionPanel().dataset.state = "unavailable";
|
||||
}, 15000);
|
||||
};
|
||||
|
||||
const captureDirection = async () => {
|
||||
if (orientationListener) {
|
||||
stopCompassReading();
|
||||
captureDirectionButton.textContent = (t.captureAgain || "Capture again");
|
||||
captureDirectionButton().textContent = (t.captureAgain || "Measure again");
|
||||
if (directionPanel()) directionPanel().dataset.state = directionDegrees.value ? "captured" : "ready";
|
||||
return;
|
||||
}
|
||||
directionStatus()?.classList.remove("manual-direction-panel__status--accuracy");
|
||||
if (!window.isSecureContext) {
|
||||
directionStatus.textContent = (t.secureCompass || "Compass capture requires a secure HTTPS connection.");
|
||||
directionStatus().textContent = (t.secureCompass || "Compass capture requires a secure HTTPS connection.");
|
||||
if (directionPanel()) directionPanel().dataset.state = "unavailable";
|
||||
return;
|
||||
}
|
||||
if (typeof window.DeviceOrientationEvent === "undefined") {
|
||||
directionStatus.textContent = (t.compassUnavailable || "Compass unavailable on this device.");
|
||||
directionStatus().textContent = (t.compassUnavailable || "Compass unavailable on this device.");
|
||||
if (directionPanel()) directionPanel().dataset.state = "unavailable";
|
||||
return;
|
||||
}
|
||||
if (typeof DeviceOrientationEvent.requestPermission === "function") {
|
||||
directionStatus.textContent = (t.compassPermission || "Requesting compass permission…");
|
||||
directionStatus().textContent = (t.compassPermission || "Requesting compass permission…");
|
||||
try {
|
||||
if (await DeviceOrientationEvent.requestPermission(true) !== "granted") {
|
||||
directionStatus.textContent = (t.compassDenied || "Compass permission denied.");
|
||||
if (directionStatus()) directionStatus().textContent = (t.compassDenied || "Compass permission denied.");
|
||||
if (directionPanel()) directionPanel().dataset.state = "unavailable";
|
||||
return;
|
||||
}
|
||||
} catch (error) {
|
||||
directionStatus.textContent = (t.compassDenied || "Compass permission denied.");
|
||||
if (directionStatus()) directionStatus().textContent = (t.compassDenied || "Compass permission denied.");
|
||||
if (directionPanel()) directionPanel().dataset.state = "unavailable";
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -93,8 +197,9 @@
|
||||
};
|
||||
|
||||
const submitManualReport = async () => {
|
||||
setCount(occurrences.value);
|
||||
stopCompassReading();
|
||||
manualSubmit.disabled = true;
|
||||
setSubmissionState("submitting", t.sendingReport || "Sending…");
|
||||
if (burstListener?.active) {
|
||||
try {
|
||||
const audio = await burstListener.clipForSubmission();
|
||||
@@ -102,33 +207,54 @@
|
||||
if (audio) data.append("audio", audio);
|
||||
const response = await fetch(manualForm.action, { method: "POST", body: data, credentials: "same-origin" });
|
||||
const html = await response.text();
|
||||
document.querySelector("#manual-submission").outerHTML = html;
|
||||
if (response.ok) burstListener.submissionSucceeded();
|
||||
if (showResponse(html, response.ok)) burstListener.submissionSucceeded();
|
||||
} catch (error) {
|
||||
document.querySelector("#manual-submission").textContent = "Could not send the report. Please try again.";
|
||||
} finally {
|
||||
manualSubmit.disabled = false;
|
||||
setSubmissionState("error", t.reportFailed || "Could not send the report. Please try again.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (window.htmx) {
|
||||
try {
|
||||
htmx.ajax("POST", manualForm.action, {
|
||||
source: manualForm,
|
||||
target: "#manual-submission",
|
||||
swap: "outerHTML",
|
||||
});
|
||||
} catch (error) {
|
||||
setSubmissionState("error", t.reportFailed || "Could not send the report. Please try again.");
|
||||
}
|
||||
} else {
|
||||
manualForm.submit();
|
||||
}
|
||||
};
|
||||
|
||||
captureDirectionButton.addEventListener("click", captureDirection);
|
||||
manualForm.addEventListener("click", (event) => {
|
||||
if (event.target.closest("#manual-capture-direction")) captureDirection();
|
||||
if (event.target.closest(".manual-direction-panel__close")) {
|
||||
stopCompassReading();
|
||||
if (compassHome) compassHome.append(compass);
|
||||
}
|
||||
});
|
||||
document.body.addEventListener("htmx:beforeSwap", (event) => {
|
||||
if (event.detail.target?.id === "manual-direction-panel" && compassHome) compassHome.append(compass);
|
||||
});
|
||||
document.body.addEventListener("htmx:afterSwap", (event) => {
|
||||
if (event.detail.target?.id !== "manual-direction-panel") return;
|
||||
if (captureDirectionButton()) directionPanel().querySelector(".manual-direction-panel__copy")?.after(compass);
|
||||
const summary = document.querySelector("#manual-direction-summary");
|
||||
if (summary && directionDegrees.value !== "") {
|
||||
const heading = Number(directionDegrees.value);
|
||||
summary.textContent = `${cardinalDirection(heading)} · ${displayDegrees(heading)}°`;
|
||||
directionPanel().dataset.state = "captured";
|
||||
}
|
||||
});
|
||||
manualSubmit.addEventListener("click", () => {
|
||||
if (manualSubmit.disabled) return;
|
||||
setSubmissionState("submitting", t.requestingLocation || "Requesting your optional location…");
|
||||
if (!navigator.geolocation) {
|
||||
submitManualReport();
|
||||
return;
|
||||
}
|
||||
manualStatus.textContent = (t.requestingLocation || "Requesting your optional location…");
|
||||
navigator.geolocation.getCurrentPosition(
|
||||
(position) => {
|
||||
latitude.value = position.coords.latitude;
|
||||
@@ -139,7 +265,22 @@
|
||||
{ enableHighAccuracy: false, maximumAge: 300000, timeout: 10000 },
|
||||
);
|
||||
});
|
||||
manualForm.addEventListener("submit", (event) => {
|
||||
event.preventDefault();
|
||||
if (!manualSubmit.disabled) manualSubmit.click();
|
||||
});
|
||||
document.body.addEventListener("htmx:afterRequest", (event) => {
|
||||
if (event.detail.elt === manualForm) manualSubmit.disabled = false;
|
||||
if (event.detail.elt !== manualForm) return;
|
||||
const response = event.detail.xhr;
|
||||
if (!response) {
|
||||
setSubmissionState("error", t.reportFailed || "Could not send the report. Please try again.");
|
||||
} else if (response.status >= 400) {
|
||||
showResponse(response.responseText, false);
|
||||
} else {
|
||||
setSubmissionState("submitted");
|
||||
}
|
||||
});
|
||||
document.body.addEventListener("htmx:sendError", (event) => {
|
||||
if (event.detail.elt === manualForm) setSubmissionState("error", t.reportFailed || "Could not send the report. Please try again.");
|
||||
});
|
||||
|
||||
|
||||
@@ -1 +1,10 @@
|
||||
document.querySelector("#ntfy-url").addEventListener("input", () => { document.querySelector("#ntfy-test-result").replaceChildren(); });
|
||||
document.querySelector("#ntfy-url")?.addEventListener("input", () => {
|
||||
document.querySelector("#ntfy-test-result")?.replaceChildren();
|
||||
});
|
||||
|
||||
document.addEventListener("click", async (event) => {
|
||||
const button = event.target.closest("[data-copy-sensor-token]");
|
||||
if (!button) return;
|
||||
const token = document.querySelector("#sensor-token")?.textContent;
|
||||
if (token) await navigator.clipboard.writeText(token);
|
||||
});
|
||||
|
||||
@@ -1,9 +1,26 @@
|
||||
.burst-listener { width:min(100%,36rem); margin-top:1rem; }
|
||||
.burst-listener__button,.burst-listener__actions button { min-height:2.75rem; padding:.65rem 1rem; border:1px solid #ffd18c; border-radius:.7rem; color:#fff2df; font:inherit; font-weight:750; background:#39243a; cursor:pointer; }
|
||||
.burst-listener__panel { margin-top:.8rem; padding:1rem; border:1px solid #aa7294; border-radius:.8rem; background:#1b1730; color:#fff2df; }
|
||||
.burst-listener__panel canvas { display:block; width:100%; height:90px; margin:.8rem 0; background:#171225; border-radius:.4rem; }
|
||||
.burst-listener__panel p { margin:.5rem 0 1rem; color:#efc9dc; }
|
||||
.burst-listener__panel audio { width:100%; margin-bottom:1rem; }
|
||||
.burst-listener__actions { display:flex; flex-wrap:wrap; gap:.5rem; }
|
||||
.burst-listener [hidden] { display:none !important; }
|
||||
.burst-listener [role="alert"] { color:#ffd18c; }
|
||||
.manual-report__supporting { padding: 1rem; border: 1px solid #514282; border-radius: 1rem; background: #11152c; }
|
||||
.manual-report__supporting-header { display: flex; align-items: center; gap: .7rem; }
|
||||
.manual-report__microphone { display: grid; width: 2.5rem; height: 2.5rem; flex: none; place-items: center; border-radius: .7rem; background: #2a2051; font-size: 1.3rem; }
|
||||
.burst-listener__state { display: block; margin-top: .15rem; color: #b9addb; font-size: .84rem; }
|
||||
.manual-report__supporting[data-state="listening"] .burst-listener__state { color: #8fe5cc; }
|
||||
.manual-report__supporting[data-state="error"] .burst-listener__state { color: #ffbd9d; }
|
||||
.burst-listener { width: 100%; margin-top: .85rem; }
|
||||
.burst-listener__button, .burst-listener__actions button { min-height: 2.75rem; padding: .65rem 1rem; border: 1px solid #8d77d2; border-radius: .7rem; color: #e8dcff; font: inherit; font-weight: 750; background: #292148; cursor: pointer; }
|
||||
.burst-listener__button { width: 100%; }
|
||||
.burst-listener__panel { color: #f0eaff; }
|
||||
.burst-listener__panel strong { font-size: .92rem; }
|
||||
.burst-listener__panel canvas { display: block; width: 100%; height: 4rem; margin: .7rem 0 .35rem; border-radius: .5rem; background: linear-gradient(90deg, #191738, #241b44); }
|
||||
.burst-listener__panel p { margin: .35rem 0 .75rem; color: #b9addb; font-size: .82rem; }
|
||||
.burst-listener__panel audio { width: 100%; margin-bottom: .75rem; }
|
||||
.burst-listener__actions { display: flex; flex-wrap: wrap; gap: .5rem; }
|
||||
.burst-listener__actions button { flex: 1 1 10rem; }
|
||||
.burst-listener__actions #burst-stop { border-color: #fb9b72; color: #ffd8c4; background: #2e1b31; }
|
||||
.burst-listener [hidden] { display: none !important; }
|
||||
.burst-listener [role="alert"] { margin: .65rem 0 0; color: #ffd1b6; }
|
||||
.burst-listener button:focus-visible { outline: 3px solid #c9b4ff; outline-offset: 3px; }
|
||||
:root[data-theme="light"] .manual-report__supporting { border-color: #d9b4d8; background: #fff8fb; }
|
||||
:root[data-theme="light"] .manual-report__microphone { background: #ead2eb; }
|
||||
:root[data-theme="light"] .burst-listener__state, :root[data-theme="light"] .burst-listener__panel p { color: #694b68; }
|
||||
:root[data-theme="light"] .burst-listener__panel { color: #321d42; }
|
||||
:root[data-theme="light"] .burst-listener__button, :root[data-theme="light"] .burst-listener__actions button { border-color: #b68bb5; color: #321d42; background: #ead2eb; }
|
||||
:root[data-theme="light"] .burst-listener__actions #burst-stop { border-color: #cf7957; color: #71331d; background: #ffe9de; }
|
||||
|
||||
@@ -37,7 +37,8 @@
|
||||
background: #111a31d9;
|
||||
box-shadow: 0 .5rem 1.5rem #03071440;
|
||||
}
|
||||
.fireworks-nav a {
|
||||
.fireworks-nav a,
|
||||
.fireworks-nav button {
|
||||
padding: .5rem .75rem;
|
||||
border-radius: .5rem;
|
||||
color: var(--muted, var(--m, #aab9d8));
|
||||
@@ -45,7 +46,10 @@
|
||||
font-weight: 750;
|
||||
text-decoration: none;
|
||||
}
|
||||
.fireworks-nav a:hover { color: var(--ink, var(--i, #eef3ff)); background: #20345f; }
|
||||
.fireworks-nav form { display: flex; margin: 0; }
|
||||
.fireworks-nav button { border: 0; background: transparent; font: inherit; cursor: pointer; }
|
||||
.fireworks-nav a:hover,
|
||||
.fireworks-nav button:hover { color: var(--ink, var(--i, #eef3ff)); background: #20345f; }
|
||||
.fireworks-nav a[aria-current="page"] { color: var(--ink, var(--i, #eef3ff)); background: #2a3b67; }
|
||||
.theme-toggle--inline {
|
||||
position: static;
|
||||
@@ -59,8 +63,10 @@
|
||||
background: #edf4ff;
|
||||
box-shadow: 0 .45rem 1.25rem rgba(34, 68, 117, .12);
|
||||
}
|
||||
:root[data-theme="light"] .fireworks-nav a { color: #47617f; }
|
||||
:root[data-theme="light"] .fireworks-nav a:hover { color: #234a7b; background: #dceaff; }
|
||||
:root[data-theme="light"] .fireworks-nav a,
|
||||
:root[data-theme="light"] .fireworks-nav button { color: #47617f; }
|
||||
:root[data-theme="light"] .fireworks-nav a:hover,
|
||||
:root[data-theme="light"] .fireworks-nav button:hover { color: #234a7b; background: #dceaff; }
|
||||
:root[data-theme="light"] .fireworks-nav a[aria-current="page"] {
|
||||
color: #173d6a;
|
||||
background: #cfe3ff;
|
||||
@@ -89,6 +95,10 @@
|
||||
.fireworks-header__controls { display: none; flex-basis: 100%; width: 100%; flex-direction: column; align-items: stretch; }
|
||||
.fireworks-menu-toggle[aria-expanded="true"] ~ .fireworks-header__controls { display: flex; }
|
||||
.fireworks-nav { flex-direction: column; }
|
||||
.fireworks-nav a { padding: .75rem; }
|
||||
.fireworks-nav a,
|
||||
.fireworks-nav button { padding: .75rem; }
|
||||
.fireworks-nav form,
|
||||
.fireworks-nav button { width: 100%; }
|
||||
.fireworks-nav button { text-align: left; }
|
||||
.theme-toggle--inline { width: 100%; }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
.manual-compass {
|
||||
display: grid;
|
||||
justify-items: center;
|
||||
width: 7rem;
|
||||
margin: .6rem 0 0 auto;
|
||||
color: #fff3d7;
|
||||
font-size: .78rem;
|
||||
font-weight: 850;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
.manual-compass[hidden] { display: none; }
|
||||
.manual-compass__dial {
|
||||
position: relative;
|
||||
width: 5.75rem;
|
||||
aspect-ratio: 1;
|
||||
border: 2px solid #f2d7a8;
|
||||
border-radius: 50%;
|
||||
background: radial-gradient(circle, #342441 0 28%, #211a32 75%);
|
||||
box-shadow: 0 .35rem 1rem #09061566, inset 0 0 0 .25rem #ffffff12;
|
||||
}
|
||||
.manual-compass__rose { position: absolute; inset: 0; transition: transform 120ms ease-out; }
|
||||
.manual-compass__rose span { position: absolute; line-height: 1; }
|
||||
.manual-compass__north { top: .38rem; left: 50%; color: #ff9e78; transform: translateX(-50%); }
|
||||
.manual-compass__east { right: .47rem; top: 50%; transform: translateY(-50%); }
|
||||
.manual-compass__south { bottom: .38rem; left: 50%; transform: translateX(-50%); }
|
||||
.manual-compass__west { left: .47rem; top: 50%; transform: translateY(-50%); }
|
||||
.manual-compass__pointer {
|
||||
position: absolute;
|
||||
top: -.55rem;
|
||||
left: 50%;
|
||||
width: 0;
|
||||
height: 0;
|
||||
border-right: .37rem solid transparent;
|
||||
border-bottom: .65rem solid #ffbd62;
|
||||
border-left: .37rem solid transparent;
|
||||
transform: translateX(-50%);
|
||||
filter: drop-shadow(0 .1rem .15rem #160d1b);
|
||||
}
|
||||
.manual-compass__center {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
width: .5rem;
|
||||
aspect-ratio: 1;
|
||||
border-radius: 50%;
|
||||
background: #ffbd62;
|
||||
transform: translate(-50%, -50%);
|
||||
}
|
||||
.manual-compass__heading { margin-top: .5rem; white-space: nowrap; }
|
||||
:root[data-theme="light"] .manual-compass { color: #43243d; }
|
||||
:root[data-theme="light"] .manual-compass__dial { border-color: #996a9b; background: radial-gradient(circle, #f8ebf8 0 28%, #e8d7e9 75%); }
|
||||
:root[data-theme="light"] .manual-compass__east,
|
||||
:root[data-theme="light"] .manual-compass__south,
|
||||
:root[data-theme="light"] .manual-compass__west { color: #43243d; }
|
||||
@media (prefers-reduced-motion: reduce) { .manual-compass__rose { transition: none; } }
|
||||
@@ -0,0 +1,218 @@
|
||||
.manual-report__header {
|
||||
max-width: 42rem;
|
||||
}
|
||||
|
||||
.manual-report { --manual-report-section-gap: 1rem; }
|
||||
|
||||
.manual-report__primary {
|
||||
display: grid;
|
||||
gap: var(--manual-report-section-gap);
|
||||
max-width: 36rem;
|
||||
}
|
||||
|
||||
.manual-report__quantity {
|
||||
padding: 1rem;
|
||||
border: 1px solid #584891;
|
||||
border-radius: 1rem;
|
||||
background: #151932;
|
||||
}
|
||||
|
||||
.manual-report .manual-report__quantity #manual-occurrences {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
min-height: 3.75rem;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
color: #f5f0ff;
|
||||
font-size: clamp(2.25rem, 8vw, 3.5rem);
|
||||
font-weight: 850;
|
||||
text-align: center;
|
||||
background: transparent;
|
||||
appearance: textfield;
|
||||
-moz-appearance: textfield;
|
||||
}
|
||||
|
||||
.manual-report__quantity #manual-occurrences::-webkit-inner-spin-button,
|
||||
.manual-report__quantity #manual-occurrences::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
|
||||
|
||||
.manual-report__stepper { display: grid; grid-template-columns: 3.5rem minmax(0, 1fr) 3.5rem; align-items: center; gap: .5rem; }
|
||||
.manual-report__stepper button { display: grid; place-items: center; width: 3.5rem; height: 3.5rem; min-height: 0; padding: 0; border: 1px solid #6d54ac; border-radius: 50%; color: #f5f0ff; font: inherit; font-size: 2rem; line-height: 1; background: #302553; cursor: pointer; }
|
||||
.manual-report__stepper button:disabled { opacity: .4; cursor: default; }
|
||||
|
||||
.manual-report .manual-report__primary .manual-direction-panel {
|
||||
width: 100%;
|
||||
margin: 0;
|
||||
border-radius: 1rem;
|
||||
background: #1a1739;
|
||||
}
|
||||
.manual-direction-panel[data-state="measuring"] { border-color: #a27cff; }
|
||||
.manual-direction-panel[data-state="captured"] { border-color: #68dba1; }
|
||||
.manual-direction-panel[data-state="unavailable"] { border-color: #d38b7a; }
|
||||
|
||||
.manual-direction-panel__topline { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
|
||||
.manual-direction-panel__summary { margin: .35rem 0 .8rem; color: #f5f0ff; font-weight: 700; }
|
||||
.manual-report .manual-direction-panel__status--accuracy { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin: .75rem 0; padding: .55rem .75rem; border: 1px solid #5d4d92; border-radius: .7rem; color: #d9cfee; background: #191630; font-size: .85rem; }
|
||||
.manual-direction-panel__status--accuracy strong { color: #f5edff; font-size: 1rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
|
||||
.manual-direction-panel__open, .manual-direction-panel__close { min-height: 2.75rem; border: 1px solid #8d77d2; border-radius: .7rem; color: #e8dcff; font: inherit; font-weight: 750; background: #302553; cursor: pointer; }
|
||||
.manual-direction-panel__open { padding: .5rem .85rem; }
|
||||
.manual-direction-panel__close { min-width: 2.75rem; font-size: 1.4rem; }
|
||||
|
||||
.manual-report #manual-submit {
|
||||
width: 100%;
|
||||
max-width: 36rem;
|
||||
min-height: 4.5rem;
|
||||
margin-top: var(--manual-report-section-gap);
|
||||
}
|
||||
|
||||
.manual-report__submit:disabled { cursor: wait; opacity: .72; }
|
||||
.manual-submission { display: grid; justify-items: center; gap: .5rem; max-width: 36rem; margin-top: 1rem; padding: 1.3rem; border: 1px solid #4caa82; border-radius: 1rem; color: #eafff2; text-align: center; background: #10352e; }
|
||||
.manual-submission__icon { display: grid; width: 3.5rem; height: 3.5rem; place-items: center; border: 2px solid #6ce4a8; border-radius: 50%; color: #eafff2; font-size: 2rem; background: #226c51; }
|
||||
.manual-submission strong { font-size: 1.35rem; }
|
||||
.manual-submission p { margin: 0; line-height: 1.45; }
|
||||
.manual-submission__summary { margin-top: .35rem !important; color: #b2e8cf; font-size: .9rem; }
|
||||
.manual-submission--error { border-color: #d37c6a; color: #fff0e8; background: #3a1c2b; }
|
||||
.manual-submission--error .manual-submission__icon { border-color: #ffac8c; background: #9b493a; }
|
||||
.manual-report__submission:empty { display: none; }
|
||||
|
||||
.manual-report button:focus-visible, .manual-report input:focus-visible { outline: 3px solid #c9b4ff; outline-offset: 3px; }
|
||||
|
||||
.manual-report__supporting {
|
||||
max-width: 36rem;
|
||||
margin-top: var(--manual-report-section-gap);
|
||||
padding-top: 1.25rem;
|
||||
border-top: 1px solid #584891;
|
||||
}
|
||||
|
||||
.manual-report__supporting h3 {
|
||||
margin: 0;
|
||||
color: #d8cffd;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.manual-report__supporting .burst-listener {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
:root[data-theme="light"] .manual-report__quantity {
|
||||
border-color: #d9b4d8;
|
||||
background: #fff8fb;
|
||||
}
|
||||
|
||||
:root[data-theme="light"] .manual-report__quantity #manual-occurrences { border: 0 !important; color: #321d42 !important; background: transparent !important; }
|
||||
:root[data-theme="light"] .manual-report__stepper button,
|
||||
:root[data-theme="light"] .manual-direction-panel__open,
|
||||
:root[data-theme="light"] .manual-direction-panel__close { color: #321d42; border-color: #b68bb5; background: #ead2eb; }
|
||||
:root[data-theme="light"] .manual-direction-panel__summary { color: #321d42; }
|
||||
:root[data-theme="light"] .manual-report .manual-direction-panel__status--accuracy { border-color: #cfaad1; color: #694b68; background: #fff8fb; }
|
||||
:root[data-theme="light"] .manual-direction-panel__status--accuracy strong { color: #321d42; }
|
||||
:root[data-theme="light"] .manual-submission { border-color: #54a67b; color: #164d34; background: #e8fff2; }
|
||||
:root[data-theme="light"] .manual-submission__icon { color: #fff; }
|
||||
:root[data-theme="light"] .manual-submission__summary { color: #2b6b48; }
|
||||
:root[data-theme="light"] .manual-submission--error { border-color: #ca7d65; color: #743520; background: #fff0e8; }
|
||||
|
||||
:root[data-theme="light"] .manual-report__supporting {
|
||||
border-color: #d9b4d8;
|
||||
}
|
||||
|
||||
:root[data-theme="light"] .manual-report__supporting h3 {
|
||||
color: #492846;
|
||||
}
|
||||
|
||||
@media (max-width: 42rem) {
|
||||
.home-grid { grid-template-columns: minmax(0, 1fr); }
|
||||
body:not(.dashboard-page) { padding: max(1rem, env(safe-area-inset-top, 0px)) max(.5rem, env(safe-area-inset-right, 0px)) max(1rem, env(safe-area-inset-bottom, 0px)) max(.5rem, env(safe-area-inset-left, 0px)); }
|
||||
.home-grid .manual-report, .dashboard-report, .dashboard-report .manual-report { overflow: visible; }
|
||||
.manual-report { padding: 1.25rem; }
|
||||
.dashboard-report .manual-report { padding: 0; }
|
||||
.manual-report__header { padding-right: 2.5rem; }
|
||||
.manual-report form { padding-bottom: calc(5rem + env(safe-area-inset-bottom, 0px)); }
|
||||
.manual-report #manual-submit {
|
||||
position: sticky;
|
||||
bottom: calc(.5rem + env(safe-area-inset-bottom, 0px));
|
||||
z-index: 10;
|
||||
box-shadow: 0 .7rem 1.6rem #070a18b3;
|
||||
}
|
||||
body:has(#manual-occurrences:focus) .manual-report #manual-submit { position: static; }
|
||||
.dashboard-intro { margin-bottom: 1rem; }
|
||||
.dashboard-intro h1 { font-size: clamp(2rem, 8vw, 2.8rem); }
|
||||
.dashboard-intro p:last-child { margin-top: .75rem; font-size: .95rem; line-height: 1.4; }
|
||||
.dashboard-section { margin-top: 1rem; }
|
||||
.dashboard-shell { padding-bottom: calc(2rem + env(safe-area-inset-bottom, 0px)); }
|
||||
.manual-report__stepper { grid-template-columns: 3.5rem minmax(0, 1fr) 3.5rem; }
|
||||
}
|
||||
|
||||
@media (max-width: 23.5rem) {
|
||||
.manual-report { padding: 1rem; }
|
||||
.manual-report__quantity { padding: .75rem; }
|
||||
.manual-report__stepper { grid-template-columns: 3rem minmax(0, 1fr) 3rem; gap: .25rem; }
|
||||
.manual-report__stepper button { width: 3rem; height: 3rem; }
|
||||
}
|
||||
|
||||
.manual-report__heading-row { display: flex; align-items: center; gap: .7rem; }
|
||||
.manual-report__fire { flex: none; font-size: clamp(1.8rem, 5vw, 2.5rem); filter: drop-shadow(0 .2rem .65rem #ff703b88); }
|
||||
.manual-report__intro, .dashboard-report .manual-report__intro { margin-bottom: .85rem; }
|
||||
.report-clock {
|
||||
box-sizing: border-box;
|
||||
width: 100%;
|
||||
max-width: 36rem;
|
||||
margin: 0 0 1rem;
|
||||
padding: .65rem .95rem .7rem;
|
||||
border: 1px solid #69539d;
|
||||
border-radius: .85rem;
|
||||
background: linear-gradient(115deg, #17162d, #10182c);
|
||||
box-shadow: inset 0 1px #ffffff0a;
|
||||
}
|
||||
.report-clock__label { color: #cbbce5; font-size: .66rem; font-weight: 750; letter-spacing: .13em; text-transform: uppercase; }
|
||||
.report-clock__display { display: flex; align-items: end; justify-content: space-between; gap: .75rem; }
|
||||
.report-clock__time {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
color: #ffbf72;
|
||||
font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
|
||||
font-size: clamp(2rem, 9vw, 2.45rem);
|
||||
font-weight: 700;
|
||||
line-height: 1.1;
|
||||
letter-spacing: 0;
|
||||
font-variant-numeric: tabular-nums;
|
||||
text-shadow: 0 0 .7rem #ff963b55;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.report-clock__time span { display: inline-block; }
|
||||
.report-clock__time #report-clock-hours, .report-clock__time #report-clock-minutes { width: 2ch; }
|
||||
.report-clock__colon { width: 1ch; flex: none; margin-inline: -.08em; line-height: 1; text-align: center; transform: translateY(-.06em); animation: report-clock-blink 2s steps(1, end) infinite; }
|
||||
.report-clock__now { display: inline-flex; align-items: center; gap: .4rem; flex: none; padding: .2rem .45rem; border: 1px solid #93634d; border-radius: 999px; color: #ffd2a2; font-size: .7rem; font-weight: 750; letter-spacing: .08em; text-transform: uppercase; }
|
||||
.report-clock__dot { width: .4rem; height: .4rem; border-radius: 50%; background: #ffab5d; }
|
||||
@keyframes report-clock-blink { 50% { opacity: 0; } }
|
||||
.manual-direction-panel__open { width: 100%; text-align: left; }
|
||||
.manual-direction-panel--open .manual-compass { width: 100%; margin: .5rem auto 1rem; }
|
||||
.manual-direction-panel--open .manual-compass__dial { width: min(100%, 12rem); border-color: #8b67d4; background: radial-gradient(circle, #302054 0 20%, #17132d 70%); box-shadow: 0 0 0 .35rem #6640a228, 0 0 2rem #ac6aff35; }
|
||||
.manual-direction-panel--open .manual-compass__pointer { border-bottom-color: #ff925f; }
|
||||
.manual-direction-panel--open .manual-compass__heading { font-size: 1.1rem; }
|
||||
.manual-report__stepper button, .manual-direction-panel__open, .manual-direction-panel__close, .manual-report__submit { transition: transform .15s ease, box-shadow .15s ease, filter .15s ease; }
|
||||
.manual-report__stepper button:not(:disabled):active, .manual-direction-panel__open:active, .manual-report__submit:not(:disabled):active { transform: scale(.97); }
|
||||
.manual-report__submit:not(:disabled):hover { filter: brightness(1.05); }
|
||||
.manual-submission--success .manual-submission__icon { animation: manual-confirm .35s ease-out both; }
|
||||
@keyframes manual-confirm { from { transform: scale(.75); opacity: .3; } to { transform: scale(1); opacity: 1; } }
|
||||
|
||||
:root[data-theme="dark"] .home-grid .manual-report,
|
||||
:root[data-theme="dark"] .dashboard-report { border-color: #7256ab; background: radial-gradient(circle at 88% 5%, #58254a55, transparent 13rem), linear-gradient(155deg, #151326, #0d1022 72%); box-shadow: 0 1rem 3rem #02041399; }
|
||||
:root[data-theme="dark"] .manual-report__title { color: #fff8f3; }
|
||||
:root[data-theme="dark"] .manual-report__intro { color: #d6cce4; }
|
||||
:root[data-theme="dark"] .manual-report__quantity { border-color: #514896; background: linear-gradient(145deg, #19183a, #121834); box-shadow: inset 0 0 0 1px #ffffff08; }
|
||||
:root[data-theme="dark"] .home-grid .manual-direction-panel,
|
||||
:root[data-theme="dark"] .dashboard-report .manual-direction-panel { border-color: #59499b; background: linear-gradient(145deg, #211945, #151835); }
|
||||
:root[data-theme="dark"] .manual-report__supporting { border-color: #493d7d; background: linear-gradient(145deg, #15142f, #10162d); }
|
||||
:root[data-theme="dark"] .manual-report__stepper button { box-shadow: 0 .25rem .7rem #07041655; }
|
||||
:root[data-theme="dark"] .manual-report__submit { background: linear-gradient(110deg, #ffc276, #ff7654); box-shadow: 0 .55rem 1.35rem #e2633a4d; }
|
||||
:root[data-theme="dark"] .manual-direction-panel[data-state="measuring"] { border-color: #a27cff; }
|
||||
:root[data-theme="dark"] .manual-direction-panel[data-state="captured"] { border-color: #68dba1; }
|
||||
:root[data-theme="dark"] .manual-direction-panel[data-state="unavailable"] { border-color: #d38b7a; }
|
||||
|
||||
:root[data-theme="light"] .report-clock { border-color: #8b6bab; background: linear-gradient(115deg, #221b37, #182039); }
|
||||
:root[data-theme="light"] .manual-direction-panel--open .manual-compass__dial { background: radial-gradient(circle, #f8ebf8 0 25%, #e8d7e9 75%); }
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.manual-report__stepper button, .manual-direction-panel__open, .manual-direction-panel__close, .manual-report__submit { transition: none; }
|
||||
.manual-submission--success .manual-submission__icon { animation: none; }
|
||||
.report-clock__colon { animation: none; opacity: 1; }
|
||||
}
|
||||
@@ -1,11 +1,51 @@
|
||||
body{min-width:320px;margin:0;padding:2rem;color:#eef3ff;font-family:Inter,system-ui,sans-serif;background:#090e1d}.card{width:min(100%,42rem);margin:auto;padding:2rem;border:1px solid #2b3d68;border-radius:1rem;background:#172443}h1{margin-top:0}h2{margin:0}.intro,.help{color:#aab9d8;line-height:1.5}.section{margin-top:2rem;padding-top:1.5rem;border-top:1px solid #2b3d68}label{display:block;margin:.9rem 0 .35rem;font-weight:700}input[type=url]{width:100%;min-height:2.8rem;padding:.65rem;border:1px solid #526b9f;border-radius:.55rem;color:#eef3ff;font:inherit;background:#0a1123}.check{display:flex;gap:.6rem;align-items:center}.check label{margin:0}.button{min-height:2.8rem;margin-top:1rem;padding:.6rem 1rem;border:0;border-radius:.55rem;color:#17132b;font:inherit;font-weight:800;background:#a6ccff;cursor:pointer}.button--secondary{margin-right:.7rem;background:#d8c1fb}.alert,.errorlist{margin-top:1rem;padding:.75rem;border-radius:.55rem}.alert--success{color:#d1fae5;background:#14532d}.alert--error,.errorlist{color:#fee2e2;background:#7f1d1d}.messages{padding:0;list-style:none}@media(max-width:32rem){body{padding:1rem}.card{padding:1.4rem}}
|
||||
.sensor-card{margin:1rem 0;padding:1rem;border:1px solid var(--theme-line);border-radius:.7rem;background:var(--theme-surface-raised)}
|
||||
.sensor-card p{margin:.5rem 0;color:var(--theme-muted)}
|
||||
.sensor-card .button{display:inline-block;text-decoration:none}
|
||||
.sensor-status{display:inline-block;margin-left:.5rem;color:#ef4444;font-weight:700}
|
||||
.sensor-status--online{color:#22c55e}.sensor-status--delayed{color:#f59e0b}
|
||||
input[type=text]{box-sizing:border-box;width:100%;min-height:2.8rem;padding:.65rem;border:1px solid var(--theme-line);border-radius:.55rem;color:var(--theme-ink);font:inherit;background:var(--theme-input)}
|
||||
.token-once{margin:1rem 0;padding:1rem;border:1px solid #f59e0b;border-radius:.7rem;background:var(--theme-surface-raised)}
|
||||
.token-once code{display:block;overflow-wrap:anywhere;margin-top:.7rem;padding:.7rem;border-radius:.4rem;background:var(--theme-input);user-select:all}
|
||||
.button--danger{color:#fff;background:#991b1b}
|
||||
:root[data-theme=light] .sensor-status:not(.sensor-status--online):not(.sensor-status--delayed){color:#b91c1c}
|
||||
/* Settings cards follow the shared blue and violet theme. */
|
||||
*{box-sizing:border-box}
|
||||
body{min-height:100vh;padding:0;color:var(--theme-ink);background:var(--theme-bg)}
|
||||
.settings-shell{width:min(100% - 3.5rem,73.75rem);margin:auto;padding:4rem 0 5rem}
|
||||
.settings-content{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:2.25rem 2rem;width:100%}
|
||||
.settings-heading,.messages{grid-column:1/-1}
|
||||
.settings-heading{margin-bottom:0}
|
||||
.eyebrow{margin:0 0 .7rem;color:#9fc5ff;font-size:.74rem;font-weight:800;letter-spacing:.1em;text-transform:uppercase}
|
||||
h1,h2{font-family:Georgia,ui-serif,serif;font-weight:700}
|
||||
h1{margin:0;font-size:clamp(2.3rem,4vw,3.5rem);letter-spacing:-.045em;line-height:1.12}
|
||||
h2{margin:0 0 .45rem;font-size:1.5rem;letter-spacing:-.02em}
|
||||
.intro,.help{margin:.45rem 0 0;color:var(--theme-muted);line-height:1.55}
|
||||
.card{min-width:0;width:100%;margin:0;padding:1.75rem;border:1px solid var(--theme-line);border-radius:1.125rem;background:var(--theme-surface);box-shadow:0 1.125rem 2.8rem #02071429}
|
||||
.settings-form{display:flex;flex-direction:column;gap:1rem}.settings-form h2+.field{margin-top:.4rem}
|
||||
.settings-form>.button[type=submit]{margin-top:auto}
|
||||
.field label{display:block;margin:0 0 .375rem;font-size:.85rem;font-weight:700}
|
||||
.field input,.field select{display:block;width:100%;min-height:2.625rem;padding:.55rem .625rem;border:1px solid var(--theme-line);border-radius:.56rem;color:var(--theme-ink);background:var(--theme-input);font:inherit}
|
||||
.field input:focus-visible,.field select:focus-visible,.button:focus-visible,.switch-control input:focus-visible+.switch-track{outline:3px solid #80b6ff;outline-offset:3px}
|
||||
.errorlist{margin:.5rem 0 0;padding:.7rem .9rem;border-radius:.55rem;color:#fee2e2;background:#7f1d1d}
|
||||
.button{display:inline-flex;align-items:center;justify-content:center;width:100%;min-height:2.875rem;margin:0;padding:.65rem 1.2rem;border:1px solid transparent;border-radius:999px;color:#111c30;background:#a6ccff;font:inherit;font-size:.9rem;font-weight:800;text-align:center;text-decoration:none;cursor:pointer;transition:transform .16s ease,box-shadow .16s ease,background .16s ease}
|
||||
.button:hover{transform:translateY(-1px);background:#c0ddff;box-shadow:0 .45rem 1rem #5899f733}
|
||||
.button--secondary{border-color:#6386bd;color:#d7e8ff;background:#223755}.button--secondary:hover{color:#111c30;background:#a6ccff}
|
||||
.switch-row{display:flex;align-items:center;justify-content:space-between;gap:1.125rem;min-height:4.375rem;padding:.8rem 1rem;border:1px solid #3d5879;border-radius:.94rem;background:#1a2a43;cursor:pointer}
|
||||
.switch-row:hover{border-color:#739ad0;background:#203554}.switch-copy{display:grid;gap:.2rem;min-width:0}.switch-copy strong{font-size:.92rem}.switch-copy small{color:var(--theme-muted);font-size:.77rem;line-height:1.35}
|
||||
.switch-control{position:relative;display:block;flex:0 0 3.1875rem;width:3.1875rem;height:1.9375rem}.switch-control input{position:absolute;width:100%;height:100%;margin:0;opacity:0;cursor:pointer}.switch-track{display:block;width:100%;height:100%;border-radius:999px;background:#62758b;pointer-events:none;transition:background .16s ease}
|
||||
.switch-track::after{content:"";position:absolute;top:2px;left:2px;width:27px;height:27px;border-radius:50%;background:#fff;box-shadow:0 1px 4px #0004;transition:transform .16s ease}.switch-control input:checked+.switch-track{background:#34c76a}.switch-control input:checked+.switch-track::after{transform:translateX(20px)}
|
||||
.messages{margin:0;padding:0;list-style:none}.alert{margin:.5rem 0 0;padding:.75rem 1rem;border-radius:.65rem;line-height:1.45}#ntfy-test-result:empty{display:none}
|
||||
.sensor-list__intro{padding-bottom:1.25rem;border-bottom:1px solid var(--theme-line)}.sensor-list__intro .eyebrow{margin-bottom:.35rem}
|
||||
.sensor-list{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:1rem;margin:1.5rem 0}.sensor-card{display:flex;flex-direction:column;min-width:0;margin:0;padding:1.3rem;border:1px solid var(--theme-line);border-radius:1rem;background:var(--theme-surface-raised)}
|
||||
.sensor-card__heading{display:flex;align-items:center;justify-content:space-between;flex-wrap:wrap;gap:.5rem 1rem}.sensor-card__heading h3{margin:0;font-family:Georgia,ui-serif,serif;font-size:1.25rem;overflow-wrap:anywhere}.sensor-card .sensor-status{display:inline-flex;padding:.32rem .65rem;border-radius:999px;background:var(--theme-input);font-size:.78rem;white-space:nowrap}
|
||||
.sensor-status{color:var(--theme-muted);font-weight:700}.sensor-status--online{color:#64dca0}.sensor-status--delayed{color:#f5c46b}.sensor-status--offline{color:#f49aa7}
|
||||
.sensor-access{align-self:flex-start;margin-top:.7rem;padding:.25rem .55rem;border:1px solid #3d806b;border-radius:999px;color:#8be0b9;font-size:.72rem;font-weight:800}.sensor-access--off{border-color:#806b75;color:#d4b9c5}
|
||||
.sensor-card__facts{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:.8rem 1rem;margin:1.3rem 0}.sensor-card__facts div{min-width:0}.sensor-card__facts dt{margin-bottom:.25rem;color:var(--theme-muted);font-size:.75rem;font-weight:700}.sensor-card__facts dd{margin:0;font-size:.88rem;font-weight:600;overflow-wrap:anywhere}.sensor-card__facts code{font:inherit}.sensor-card__facts div:last-child{grid-column:1/-1}
|
||||
.sensor-card .button{margin-top:auto}.sensor-empty{grid-column:1/-1;margin:0;padding:1.5rem;border:1px dashed var(--theme-line);border-radius:1rem;color:var(--theme-muted);text-align:center;line-height:1.5}
|
||||
.sensor-form{margin-top:1.5rem;padding:1.3rem;border:1px dashed #6386bd;border-radius:1rem;background:var(--theme-surface-raised)}.sensor-form h3{margin:0;font-family:Georgia,ui-serif,serif;font-size:1.2rem}.sensor-form .help{margin-top:.3rem}.sensor-form__controls{display:grid;grid-template-columns:minmax(0,1fr) 11rem;align-items:end;gap:1rem}
|
||||
.settings-content>#sensor-card{grid-column:1/-1}
|
||||
.sensor-detail__header{display:flex;align-items:start;justify-content:space-between;gap:1rem;padding-bottom:1.2rem;border-bottom:1px solid var(--theme-line)}.sensor-detail__header .eyebrow{margin-bottom:.35rem}.sensor-detail__header h2{margin:0;font-size:clamp(1.6rem,3vw,2rem);overflow-wrap:anywhere}.sensor-close{display:inline-flex;align-items:center;gap:.35rem;flex:none;padding:.45rem .85rem;border:1px solid var(--theme-line);border-radius:999px;color:var(--theme-ink);background:var(--theme-surface-raised);font-size:.85rem;font-weight:700;text-decoration:none}.sensor-close:hover{border-color:#86ade0;background:#2b4266}.sensor-close:focus-visible{outline:3px solid #80b6ff;outline-offset:3px}
|
||||
.sensor-detail__overview{margin:1.25rem 0 1.5rem;padding:1.2rem;border:1px solid var(--theme-line);border-radius:1rem;background:var(--theme-surface-raised)}.sensor-detail__overview>.sensor-status{display:inline-flex;margin:0 0 1rem;padding:.35rem .7rem;border-radius:999px;background:var(--theme-input);font-size:.85rem}
|
||||
.sensor-detail__facts{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:1rem 1.5rem;margin:0}.sensor-detail__facts div{min-width:0}.sensor-detail__facts dt{margin:0 0 .3rem;color:var(--theme-muted);font-size:.78rem;font-weight:700}.sensor-detail__facts dd{margin:0;overflow-wrap:anywhere;font-size:.92rem;font-weight:600}.sensor-detail__facts code{font:inherit}
|
||||
.sensor-detail__actions{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:1rem}.sensor-detail__section{display:flex;flex-direction:column;min-width:0;padding:1.2rem;border:1px solid var(--theme-line);border-radius:1rem;background:var(--theme-surface-raised)}.sensor-detail__section h3{margin:0 0 .35rem;font-family:Georgia,ui-serif,serif;font-size:1.15rem}.sensor-detail__section>.help{margin:0}.sensor-detail__section form{display:flex;flex:1;flex-direction:column;gap:.8rem;margin-top:1rem}.sensor-detail__section form .button{margin-top:auto}.sensor-detail__section .field{width:100%}.sensor-detail__section:last-child{border-color:#945f68;background:#392432}.sensor-detail__section:last-child .button--danger{border-color:#dc7b89;color:#fff;background:#a43c50}.sensor-detail__section:last-child .button--danger:hover{background:#bd4a60}
|
||||
.sensor-confirm{display:flex;align-items:start;gap:.6rem;line-height:1.4;font-size:.82rem;cursor:pointer}.sensor-confirm input{flex:none;width:1.1rem;height:1.1rem;margin:.15rem 0 0;accent-color:#84baff}.sensor-confirm input:focus-visible{outline:3px solid #80b6ff;outline-offset:3px}
|
||||
.sensor-messages{margin-top:1rem}.token-once{margin:1.25rem 0;padding:1rem;border:1px solid #e4ad55;border-radius:.8rem;background:var(--theme-surface-raised)}.token-once code{display:block;margin:.75rem 0;padding:.7rem;border-radius:.5rem;background:var(--theme-input);overflow-wrap:anywhere;user-select:all}
|
||||
.button--danger{color:#fff;background:#991b1b}.button--danger:hover{color:#fff;background:#b91c1c}
|
||||
:root[data-theme=light] .eyebrow{color:#23578d}:root[data-theme=light] .card{box-shadow:0 1.125rem 2.8rem #20365c1a}:root[data-theme=light] .button:not(.button--secondary):not(.button--danger){color:#fff;background:#245b96}:root[data-theme=light] .button:not(.button--secondary):not(.button--danger):hover{background:#174877}:root[data-theme=light] .button--secondary{border-color:#9cc0ed;color:#245b96;background:#edf4ff}:root[data-theme=light] .button--secondary:hover{color:#fff;background:#245b96}:root[data-theme=light] .switch-row{border-color:#d4e0ef;background:#f2f7fe}:root[data-theme=light] .switch-row:hover{border-color:#9cc0ed;background:#eaf3ff}:root[data-theme=light] .switch-track{background:#c1cbd8}:root[data-theme=light] .switch-control input:checked+.switch-track{background:#34c76a}
|
||||
:root[data-theme=light] .sensor-close:hover{background:#e4efff}:root[data-theme=light] .sensor-detail__section:last-child{border-color:#ecc6cb;background:#fff5f6}:root[data-theme=light] .sensor-detail__section:last-child .button--danger{color:#fff;background:#a43c50}
|
||||
:root[data-theme=light] .sensor-access{border-color:#b8dfca;color:#256147;background:#ecf8f0}:root[data-theme=light] .sensor-access--off{border-color:#dbcbd3;color:#80556a;background:#fbf4f7}:root[data-theme=light] .sensor-form{border-color:#9cc0ed}
|
||||
@media(max-width:48rem){.settings-content{grid-template-columns:minmax(0,1fr)}.settings-shell{width:min(100% - 2.25rem,73.75rem);padding:2.5rem 0 3rem}}
|
||||
@media(max-width:48rem){.sensor-detail__actions,.sensor-list{grid-template-columns:minmax(0,1fr)}}
|
||||
@media(max-width:30rem){.sensor-detail__facts{grid-template-columns:minmax(0,1fr)}.sensor-detail__header{align-items:start}.sensor-close span{display:none}}
|
||||
@media(max-width:35rem){.card{padding:1.25rem}.sensor-form__controls{grid-template-columns:minmax(0,1fr)}}
|
||||
@media(prefers-reduced-motion:reduce){.button,.switch-track,.switch-track::after{transition:none}.button:hover{transform:none}}
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { JSDOM } from "jsdom";
|
||||
|
||||
test("compass stays hidden until permission and a heading, then rotates and hides when stopped", async () => {
|
||||
const dom = new JSDOM(`<!doctype html><html><body>
|
||||
<time id="manual-report-time"><span id="report-clock-hours">--</span><span class="report-clock__colon">:</span><span id="report-clock-minutes">--</span></time>
|
||||
<form id="manual-report-form" action="/submit">
|
||||
<input id="manual-latitude"><input id="manual-longitude">
|
||||
<input id="manual-direction-degrees"><input id="manual-direction-accuracy">
|
||||
<button id="manual-decrease" type="button"></button><input id="manual-occurrences" value="1"><button id="manual-increase" type="button"></button>
|
||||
<div id="manual-direction-panel" hidden><button id="manual-capture-direction" type="button"></button><div id="manual-direction-status"></div></div>
|
||||
<button id="manual-submit" type="button"></button>
|
||||
<button id="burst-start" type="button"></button><div id="burst-panel"></div><strong id="burst-heading"></strong>
|
||||
<div id="burst-detail"></div><canvas id="burst-waveform"></canvas><audio id="burst-preview"></audio>
|
||||
<button id="burst-resume" type="button"></button><button id="burst-discard" type="button"></button>
|
||||
<button id="burst-stop" type="button"></button><p id="burst-error"></p>
|
||||
</form>
|
||||
<div id="manual-submission"></div>
|
||||
<div id="manual-compass-home"><div id="manual-compass" hidden><div id="manual-compass-rose"></div><span id="manual-compass-heading"></span></div></div>
|
||||
</body></html>`, { url: "https://example.test/" });
|
||||
const { window } = dom;
|
||||
Object.defineProperty(window, "isSecureContext", { value: true });
|
||||
let resolvePermission;
|
||||
class MockOrientation {}
|
||||
MockOrientation.requestPermission = () => new Promise((resolve) => { resolvePermission = resolve; });
|
||||
window.DeviceOrientationEvent = MockOrientation;
|
||||
let submissions = 0;
|
||||
window.htmx = { ajax: () => { submissions++; } };
|
||||
const previous = Object.fromEntries(["window", "document", "navigator", "DeviceOrientationEvent", "htmx", "DOMParser"].map((key) => [key, Object.getOwnPropertyDescriptor(globalThis, key)]));
|
||||
for (const [key, value] of Object.entries({ window, document: window.document, navigator: window.navigator, DeviceOrientationEvent: MockOrientation, htmx: window.htmx, DOMParser: window.DOMParser })) {
|
||||
Object.defineProperty(globalThis, key, { configurable: true, writable: true, value });
|
||||
}
|
||||
try {
|
||||
await import("../src/scripts/manual-report.js?compass=visual");
|
||||
const reportTime = window.document.querySelector("#manual-report-time");
|
||||
assert.match(reportTime.getAttribute("aria-label"), /^\d{2}:\d{2}$/);
|
||||
assert.equal(reportTime.querySelector(".report-clock__colon").textContent, ":");
|
||||
assert.match(reportTime.dateTime, /^\d{4}-\d{2}-\d{2}T/);
|
||||
const compass = window.document.querySelector("#manual-compass");
|
||||
const rose = window.document.querySelector("#manual-compass-rose");
|
||||
const button = window.document.querySelector("#manual-capture-direction");
|
||||
assert.equal(compass.hidden, true);
|
||||
button.click();
|
||||
assert.equal(compass.hidden, true);
|
||||
resolvePermission("granted");
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
const reading = (heading, accuracy) => {
|
||||
const event = new window.Event("deviceorientation");
|
||||
Object.defineProperty(event, "webkitCompassHeading", { value: heading });
|
||||
if (accuracy !== undefined) Object.defineProperty(event, "webkitCompassAccuracy", { value: accuracy });
|
||||
window.dispatchEvent(event);
|
||||
};
|
||||
reading(359);
|
||||
assert.equal(compass.hidden, false);
|
||||
assert.equal(rose.style.transform, "rotate(-359deg)");
|
||||
reading(1, 14.8);
|
||||
assert.equal(rose.style.transform, "rotate(-361deg)");
|
||||
assert.equal(window.document.querySelector("#manual-direction-degrees").value, "1");
|
||||
assert.equal(window.document.querySelector("#manual-compass-heading").textContent, "1° · North");
|
||||
assert.equal(window.document.querySelector("#manual-direction-status").textContent, "Accuracy±14.8°");
|
||||
button.click();
|
||||
assert.equal(compass.hidden, true);
|
||||
window.document.querySelector("#manual-increase").click();
|
||||
assert.equal(window.document.querySelector("#manual-occurrences").value, "2");
|
||||
window.document.querySelector("#manual-decrease").click();
|
||||
assert.equal(window.document.querySelector("#manual-occurrences").value, "1");
|
||||
|
||||
window.document.querySelector("#manual-direction-panel").outerHTML = '<div id="manual-direction-panel"><p class="manual-direction-panel__copy"></p><button id="manual-capture-direction"></button><div id="manual-direction-status"></div></div>';
|
||||
const opened = window.document.querySelector("#manual-direction-panel");
|
||||
window.document.body.dispatchEvent(new window.CustomEvent("htmx:afterSwap", { detail: { target: opened } }));
|
||||
assert.equal(compass.parentElement.id, "manual-direction-panel");
|
||||
window.document.body.dispatchEvent(new window.CustomEvent("htmx:beforeSwap", { detail: { target: opened } }));
|
||||
assert.equal(compass.parentElement.id, "manual-compass-home");
|
||||
opened.outerHTML = '<div id="manual-direction-panel"><p id="manual-direction-summary">Not captured</p></div>';
|
||||
const closed = window.document.querySelector("#manual-direction-panel");
|
||||
window.document.body.dispatchEvent(new window.CustomEvent("htmx:afterSwap", { detail: { target: closed } }));
|
||||
assert.equal(window.document.querySelector("#manual-direction-summary").textContent, "North · 1°");
|
||||
|
||||
const submit = window.document.querySelector("#manual-submit");
|
||||
const form = window.document.querySelector("#manual-report-form");
|
||||
submit.click();
|
||||
submit.click();
|
||||
assert.equal(submissions, 1);
|
||||
assert.equal(submit.disabled, true);
|
||||
window.document.querySelector("#manual-submission").outerHTML = '<div id="manual-submission" data-result="success">Received</div>';
|
||||
window.document.body.dispatchEvent(new window.CustomEvent("htmx:afterRequest", { detail: { elt: form, xhr: { status: 200 } } }));
|
||||
assert.equal(submit.disabled, false);
|
||||
submit.click();
|
||||
assert.equal(submissions, 2);
|
||||
window.document.body.dispatchEvent(new window.CustomEvent("htmx:afterRequest", { detail: { elt: form, xhr: { status: 400, responseText: '<div id="manual-submission" data-result="error">Try again</div>' } } }));
|
||||
assert.equal(window.document.querySelector("#manual-submission").dataset.result, "error");
|
||||
assert.equal(submit.disabled, false);
|
||||
} finally {
|
||||
for (const [key, descriptor] of Object.entries(previous)) {
|
||||
if (descriptor === undefined) delete globalThis[key];
|
||||
else Object.defineProperty(globalThis, key, descriptor);
|
||||
}
|
||||
dom.window.close();
|
||||
}
|
||||
});
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -3,7 +3,7 @@
|
||||
<html lang="{{ request.LANGUAGE_CODE|default:'en' }}" data-theme="dark">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover">
|
||||
<title>{% trans "Welcome · Sound Signal" %}</title>
|
||||
<script src="https://cdn.jsdelivr.net/npm/htmx.org@2.0.4/dist/htmx.min.js"></script>
|
||||
{% vite_asset "frontend/src/entries/home.js" %}
|
||||
@@ -11,6 +11,7 @@
|
||||
<body>
|
||||
{% if user.is_authenticated %}<a class="profile-circle" href="{% url 'user_settings' %}" aria-label="{% blocktrans with username=user.get_username %}Open settings for {{ username }}{% endblocktrans %}" title="{% trans "Settings" %}">{{ user.get_username|first|upper }}</a>{% endif %}
|
||||
<div class="home-grid">
|
||||
{% include "fireworks_detect/includes/manual_report_form.html" %}
|
||||
<main class="welcome-card">
|
||||
<div class="brand"><span class="brand-mark">✦</span> Sound Signal</div>
|
||||
<p class="eyebrow">{% trans "Control room" %}</p>
|
||||
@@ -24,7 +25,6 @@
|
||||
<span class="hint">{% trans "Audio analysis · Sensor map" %}</span>
|
||||
</div>
|
||||
</main>
|
||||
{% include "fireworks_detect/includes/manual_report_form.html" %}
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Binary file not shown.
@@ -924,9 +924,20 @@ msgid "Notifications / ntfy"
|
||||
msgstr "Meldingen / ntfy"
|
||||
|
||||
#: members/templates/members/user_settings.html:30
|
||||
msgid ""
|
||||
"Use a topic URL from your ntfy server. Test the current URL before saving it."
|
||||
msgstr "Gebruik een onderwerp-URL van je ntfy-server. Test de URL voordat je hem opslaat."
|
||||
msgid "Use a topic URL from your ntfy server. Test the URL before enabling notifications."
|
||||
msgstr "Gebruik een onderwerp-URL van je ntfy-server. Test de URL voordat je meldingen inschakelt."
|
||||
|
||||
msgid "Pending events"
|
||||
msgstr "Wachtende meldingen"
|
||||
|
||||
msgid "%(count)d manual"
|
||||
msgstr "%(count)d handmatig"
|
||||
|
||||
msgid "%(count)d sensor"
|
||||
msgstr "%(count)d sensor"
|
||||
|
||||
msgid "%(count)d new Pending event(s): %(sources)s."
|
||||
msgstr "%(count)d nieuwe wachtende melding(en): %(sources)s."
|
||||
|
||||
#: members/templates/members/user_settings.html:31
|
||||
msgid "Topic URL"
|
||||
@@ -1275,3 +1286,120 @@ msgstr "De server verwerkt momenteel alleen audio-opnamen. Kies een audiobestand
|
||||
|
||||
msgid "Local checking was unavailable. BoomCast will use normal server processing."
|
||||
msgstr "Lokale controle was niet beschikbaar. BoomCast gebruikt de normale verwerking op de server."
|
||||
|
||||
msgid "Quick report"
|
||||
msgstr "Snelle melding"
|
||||
|
||||
msgid "Did you hear a bang? Report what you heard in a few taps."
|
||||
msgstr "Heb je een knal gehoord? Meld in een paar tikken wat je hoorde."
|
||||
|
||||
msgid "Now"
|
||||
msgstr "Nu"
|
||||
|
||||
msgid "Report time"
|
||||
msgstr "Tijdstip melding"
|
||||
|
||||
msgid "How many times did you hear it?"
|
||||
msgstr "Hoe vaak hoorde je het?"
|
||||
|
||||
msgid "Decrease occurrences"
|
||||
msgstr "Aantal verlagen"
|
||||
|
||||
msgid "Increase occurrences"
|
||||
msgstr "Aantal verhogen"
|
||||
|
||||
msgid "I heard fireworks"
|
||||
msgstr "Ik hoorde vuurwerk"
|
||||
|
||||
msgid "Automatic detection"
|
||||
msgstr "Automatische detectie"
|
||||
|
||||
msgid "Not listening"
|
||||
msgstr "Luistert niet"
|
||||
|
||||
msgid "Start listening"
|
||||
msgstr "Start luisteren"
|
||||
|
||||
msgid "Close direction capture"
|
||||
msgstr "Richtingmeting sluiten"
|
||||
|
||||
msgid "Start measuring direction"
|
||||
msgstr "Richting meten"
|
||||
|
||||
msgid "Not captured"
|
||||
msgstr "Niet vastgelegd"
|
||||
|
||||
msgid "Report received!"
|
||||
msgstr "Melding ontvangen!"
|
||||
|
||||
msgid "Thank you. Your report helps map fireworks nearby."
|
||||
msgstr "Bedankt voor je bijdrage. Je melding helpt om vuurwerk in de buurt in kaart te brengen."
|
||||
|
||||
msgid "Stop measuring direction"
|
||||
msgstr "Stop richting meten"
|
||||
|
||||
msgid "Measure again"
|
||||
msgstr "Opnieuw meten"
|
||||
|
||||
msgid "Sending…"
|
||||
msgstr "Versturen…"
|
||||
|
||||
msgid "Could not send the report. Please try again."
|
||||
msgstr "De melding kon niet worden verzonden. Probeer het opnieuw."
|
||||
|
||||
msgid "North"
|
||||
msgstr "Noord"
|
||||
|
||||
msgid "Northeast"
|
||||
msgstr "Noordoost"
|
||||
|
||||
msgid "East"
|
||||
msgstr "Oost"
|
||||
|
||||
msgid "Southeast"
|
||||
msgstr "Zuidoost"
|
||||
|
||||
msgid "South"
|
||||
msgstr "Zuid"
|
||||
|
||||
msgid "Southwest"
|
||||
msgstr "Zuidwest"
|
||||
|
||||
msgid "West"
|
||||
msgstr "West"
|
||||
|
||||
msgid "Northwest"
|
||||
msgstr "Noordwest"
|
||||
|
||||
msgid "Listening for the next bang"
|
||||
msgstr "Luistert naar de volgende knal"
|
||||
|
||||
msgid "Sound detected"
|
||||
msgstr "Geluid gedetecteerd"
|
||||
|
||||
msgid "Sound captured"
|
||||
msgstr "Geluid vastgelegd"
|
||||
|
||||
msgid "Sound detected — finishing clip…"
|
||||
msgstr "Geluid gedetecteerd — opname afronden…"
|
||||
|
||||
msgid "Listening for the next sound…"
|
||||
msgstr "Luistert naar het volgende geluid…"
|
||||
|
||||
msgid "Keeping the most recent ~10 seconds"
|
||||
msgstr "Bewaart de laatste ~10 seconden"
|
||||
|
||||
msgid "Preview the clip or send your report."
|
||||
msgstr "Luister de opname terug of dien je melding in."
|
||||
|
||||
msgid "Starting microphone…"
|
||||
msgstr "Microfoon starten…"
|
||||
|
||||
msgid "Microphone unavailable"
|
||||
msgstr "Microfoon niet beschikbaar"
|
||||
|
||||
msgid "Microphone permission was denied. Manual reporting is still available."
|
||||
msgstr "Toegang tot de microfoon is geweigerd. Je kunt nog steeds handmatig melden."
|
||||
|
||||
msgid "Microphone capture failed."
|
||||
msgstr "Opnemen met de microfoon is mislukt."
|
||||
|
||||
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1 +0,0 @@
|
||||
RIFF0000WAVEdata
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,37 @@
|
||||
import logging
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.utils import timezone
|
||||
from django.utils import translation
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from members.models import PendingNotificationBatch, UserSettings
|
||||
from notifications.services import NotificationError, send_notification
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Send one ntfy summary per user for each completed minute of Pending arrivals."
|
||||
|
||||
def handle(self, *args, **options):
|
||||
current_minute = timezone.now().replace(second=0, microsecond=0)
|
||||
batches = PendingNotificationBatch.objects.filter(minute__lt=current_minute).select_related("user").order_by("minute", "pk")
|
||||
for batch in batches.iterator():
|
||||
if not UserSettings.objects.filter(user=batch.user, ntfy_enabled=True).exclude(ntfy_url="").exists():
|
||||
batch.delete()
|
||||
continue
|
||||
try:
|
||||
with translation.override(batch.user.notification_settings.preferred_language):
|
||||
parts = []
|
||||
if batch.manual_count:
|
||||
parts.append(_("%(count)d manual") % {"count": batch.manual_count})
|
||||
if batch.sensor_count:
|
||||
parts.append(_("%(count)d sensor") % {"count": batch.sensor_count})
|
||||
total = batch.manual_count + batch.sensor_count
|
||||
message = _("%(count)d new Pending event(s): %(sources)s.") % {"count": total, "sources": ", ".join(parts)}
|
||||
send_notification(batch.user, _("Pending events"), message)
|
||||
except NotificationError as error:
|
||||
logger.warning("Could not send Pending notification for user %s: %s", batch.user_id, error)
|
||||
continue
|
||||
batch.delete()
|
||||
@@ -0,0 +1,27 @@
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
("members", "0003_usersettings_preferred_language"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name="PendingNotificationBatch",
|
||||
fields=[
|
||||
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
|
||||
("minute", models.DateTimeField()),
|
||||
("manual_count", models.PositiveIntegerField(default=0)),
|
||||
("sensor_count", models.PositiveIntegerField(default=0)),
|
||||
("user", models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name="pendingnotificationbatch",
|
||||
constraint=models.UniqueConstraint(fields=("user", "minute"), name="unique_pending_notification_minute"),
|
||||
),
|
||||
]
|
||||
Binary file not shown.
@@ -29,3 +29,15 @@ class UserSettings(models.Model):
|
||||
|
||||
def __str__(self):
|
||||
return _("Settings for %(user)s") % {"user": self.user}
|
||||
|
||||
|
||||
class PendingNotificationBatch(models.Model):
|
||||
"""One minute of new Pending events for one notification recipient."""
|
||||
|
||||
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
|
||||
minute = models.DateTimeField()
|
||||
manual_count = models.PositiveIntegerField(default=0)
|
||||
sensor_count = models.PositiveIntegerField(default=0)
|
||||
|
||||
class Meta:
|
||||
constraints = [models.UniqueConstraint(fields=["user", "minute"], name="unique_pending_notification_minute")]
|
||||
|
||||
+33
-1
@@ -19,13 +19,33 @@ def owned_sensor(request, pk):
|
||||
return get_object_or_404(Sensor, pk=pk, owner=request.user, archived_at__isnull=True)
|
||||
|
||||
|
||||
def is_htmx(request):
|
||||
return request.headers.get("HX-Request") == "true"
|
||||
|
||||
|
||||
def render_sensor_list(request):
|
||||
return render(request, "members/partials/sensor_list.html", {
|
||||
"sensors": Sensor.objects.filter(owner=request.user, archived_at__isnull=True),
|
||||
})
|
||||
|
||||
|
||||
def render_sensor(request, sensor, form=None, token=None):
|
||||
return render(request, "members/sensor_manage.html", {
|
||||
response = render(request, "members/partials/sensor_detail.html" if is_htmx(request) else "members/sensor_manage.html", {
|
||||
"sensor": sensor,
|
||||
"form": form or SensorForm(instance=sensor),
|
||||
"token": token,
|
||||
"heartbeat": sensor.heartbeat_status(),
|
||||
})
|
||||
if token:
|
||||
response["Cache-Control"] = "no-store"
|
||||
return response
|
||||
|
||||
|
||||
@login_required
|
||||
def sensor_list(request):
|
||||
if is_htmx(request):
|
||||
return render_sensor_list(request)
|
||||
return redirect("user_settings")
|
||||
|
||||
|
||||
@login_required
|
||||
@@ -35,6 +55,8 @@ def create_sensor(request):
|
||||
form = SensorForm(request.POST)
|
||||
if not form.is_valid():
|
||||
messages.error(request, _("Enter a valid sensor name. Names must be unique."))
|
||||
if is_htmx(request):
|
||||
return render_sensor_list(request)
|
||||
return redirect("user_settings")
|
||||
sensor = form.save(commit=False)
|
||||
sensor.owner = request.user
|
||||
@@ -57,6 +79,8 @@ def rename_sensor(request, pk):
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
messages.success(request, _("Sensor renamed."))
|
||||
if is_htmx(request):
|
||||
return render_sensor(request, sensor)
|
||||
return redirect("manage_sensor", pk=pk)
|
||||
return render_sensor(request, sensor, form=form)
|
||||
|
||||
@@ -67,6 +91,8 @@ def toggle_sensor(request, pk):
|
||||
sensor = owned_sensor(request, pk)
|
||||
sensor.is_active = not sensor.is_active
|
||||
sensor.save(update_fields=["is_active"])
|
||||
if is_htmx(request):
|
||||
return render_sensor(request, sensor)
|
||||
return redirect("manage_sensor", pk=pk)
|
||||
|
||||
|
||||
@@ -77,6 +103,8 @@ def rotate_sensor(request, pk):
|
||||
sensor = owned_sensor(request, pk)
|
||||
if request.POST.get("confirm") != "rotate":
|
||||
messages.error(request, _("Confirm token rotation first."))
|
||||
if is_htmx(request):
|
||||
return render_sensor(request, sensor)
|
||||
return redirect("manage_sensor", pk=pk)
|
||||
token = sensor.issue_token()
|
||||
return render_sensor(request, sensor, token=token)
|
||||
@@ -88,7 +116,11 @@ def remove_sensor(request, pk):
|
||||
sensor = owned_sensor(request, pk)
|
||||
if request.POST.get("confirm") != "remove":
|
||||
messages.error(request, _("Confirm sensor removal first."))
|
||||
if is_htmx(request):
|
||||
return render_sensor(request, sensor)
|
||||
return redirect("manage_sensor", pk=pk)
|
||||
sensor.archive()
|
||||
messages.success(request, _("Sensor removed. Historical events were preserved."))
|
||||
if is_htmx(request):
|
||||
return render_sensor_list(request)
|
||||
return redirect("user_settings")
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user