diff --git a/fireworks_detect/__pycache__/urls.cpython-312.pyc b/fireworks_detect/__pycache__/urls.cpython-312.pyc
index 143cbe3..91c6fbb 100644
Binary files a/fireworks_detect/__pycache__/urls.cpython-312.pyc and b/fireworks_detect/__pycache__/urls.cpython-312.pyc differ
diff --git a/fireworks_detect/__pycache__/views.cpython-312.pyc b/fireworks_detect/__pycache__/views.cpython-312.pyc
index 79a9eef..3ffa1d9 100644
Binary files a/fireworks_detect/__pycache__/views.cpython-312.pyc and b/fireworks_detect/__pycache__/views.cpython-312.pyc differ
diff --git a/fireworks_detect/__pycache__/views.cpython-313.pyc b/fireworks_detect/__pycache__/views.cpython-313.pyc
index 099e138..182479e 100644
Binary files a/fireworks_detect/__pycache__/views.cpython-313.pyc and b/fireworks_detect/__pycache__/views.cpython-313.pyc differ
diff --git a/fireworks_detect/templates/fireworks_detect/includes/manual_direction_panel.html b/fireworks_detect/templates/fireworks_detect/includes/manual_direction_panel.html
new file mode 100644
index 0000000..051bf1c
--- /dev/null
+++ b/fireworks_detect/templates/fireworks_detect/includes/manual_direction_panel.html
@@ -0,0 +1,16 @@
+{% load i18n %}
+
+ {% if measuring %}
+
+ {% trans "Capture direction" %}
+
+
+
{% trans "Point the top of your phone toward the fireworks, then capture a single compass reading." %}
+
+
+ {% else %}
+
{% trans "Direction" %} ({% trans "optional" %})
+
{% trans "Not captured" %}
+
+ {% endif %}
+
diff --git a/fireworks_detect/templates/fireworks_detect/includes/manual_report_form.html b/fireworks_detect/templates/fireworks_detect/includes/manual_report_form.html
index cd0ab99..352cf0b 100644
--- a/fireworks_detect/templates/fireworks_detect/includes/manual_report_form.html
+++ b/fireworks_detect/templates/fireworks_detect/includes/manual_report_form.html
@@ -13,16 +13,15 @@
-
-
{% trans "Direction" %} ({% trans "optional" %})
-
{% trans "Point the top of your phone toward the fireworks, then capture a single compass reading." %}
-
-
-
-
+ {% include "fireworks_detect/includes/manual_direction_panel.html" %}
+
{% trans "Automatic detection" %}
diff --git a/fireworks_detect/tests.py b/fireworks_detect/tests.py
index 2f4f40e..76bfec8 100644
--- a/fireworks_detect/tests.py
+++ b/fireworks_detect/tests.py
@@ -157,9 +157,12 @@ 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")
@@ -169,6 +172,16 @@ 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_old_route_preserves_the_previous_landing_page(self):
response = self.client.get(reverse("old_home"))
diff --git a/fireworks_detect/urls.py b/fireworks_detect/urls.py
index 36b583f..d727123 100644
--- a/fireworks_detect/urls.py
+++ b/fireworks_detect/urls.py
@@ -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//", pending_audio, name="pending_audio"),
diff --git a/fireworks_detect/views.py b/fireworks_detect/views.py
index 06537c7..d57a0dd 100644
--- a/fireworks_detect/views.py
+++ b/fireworks_detect/views.py
@@ -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):
diff --git a/frontend/src/scripts/manual-report.js b/frontend/src/scripts/manual-report.js
index 1dc1964..4a25be0 100644
--- a/frontend/src/scripts/manual-report.js
+++ b/frontend/src/scripts/manual-report.js
@@ -3,20 +3,19 @@
const manualForm = document.querySelector("#manual-report-form");
const manualSubmit = document.querySelector("#manual-submit");
+ const occurrences = document.querySelector("#manual-occurrences");
+ const decrease = document.querySelector("#manual-decrease");
+ const increase = document.querySelector("#manual-increase");
const manualStatus = document.querySelector("#manual-submission");
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 captureDirectionButton = () => document.querySelector("#manual-capture-direction");
+ const directionStatus = () => document.querySelector("#manual-direction-status");
const compass = document.querySelector("#manual-compass");
const compassRose = document.querySelector("#manual-compass-rose");
const compassHeading = document.querySelector("#manual-compass-heading");
- const isMobileDevice = /Android|iPhone|iPad|iPod|IEMobile|Opera Mini/.test(navigator.userAgent)
- || (navigator.userAgent.includes("Macintosh") && navigator.maxTouchPoints > 1);
- if (isMobileDevice) directionPanel.hidden = false;
let orientationListener;
let compassUnavailableTimeout;
let compassRotation = null;
@@ -26,6 +25,17 @@
const cardinalDirection = (heading) => ["N", "NE", "E", "SE", "S", "SW", "W", "NW"][Math.floor(((heading + 22.5) % 360) / 45)];
const displayDegrees = (value) => Number(value.toFixed(1)).toString();
+ 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);
@@ -56,13 +66,16 @@
const showCapturedDirection = (heading, accuracy) => {
const accuracyText = accuracy === null ? (t.accuracyUnavailable || "Accuracy unavailable") : (t.accuracy || "Accuracy") + ": ±" + displayDegrees(accuracy) + "°";
- directionStatus.innerHTML = "" + displayDegrees(heading) + "° · " + cardinalDirection(heading) + "
" + accuracyText;
- captureDirectionButton.textContent = (t.stopCapture || "Stop direction capture");
+ const status = directionStatus();
+ if (status) status.innerHTML = "" + cardinalDirection(heading) + " · " + displayDegrees(heading) + "°
" + accuracyText;
+ 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.");
+ 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)
@@ -84,34 +97,36 @@
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.");
}, 15000);
};
const captureDirection = async () => {
if (orientationListener) {
stopCompassReading();
- captureDirectionButton.textContent = (t.captureAgain || "Capture again");
+ captureDirectionButton().textContent = (t.captureAgain || "Measure again");
return;
}
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.");
return;
}
if (typeof window.DeviceOrientationEvent === "undefined") {
- directionStatus.textContent = (t.compassUnavailable || "Compass unavailable on this device.");
+ directionStatus().textContent = (t.compassUnavailable || "Compass unavailable on this device.");
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.");
return;
}
} catch (error) {
- directionStatus.textContent = (t.compassDenied || "Compass permission denied.");
+ if (directionStatus()) directionStatus().textContent = (t.compassDenied || "Compass permission denied.");
return;
}
}
@@ -119,6 +134,7 @@
};
const submitManualReport = async () => {
+ setCount(occurrences.value);
stopCompassReading();
manualSubmit.disabled = true;
if (burstListener?.active) {
@@ -148,8 +164,21 @@
}
};
- 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();
+ });
+ document.body.addEventListener("htmx:afterSwap", (event) => {
+ if (event.detail.target?.id !== "manual-direction-panel") return;
+ const summary = document.querySelector("#manual-direction-summary");
+ if (summary && directionDegrees.value !== "") {
+ const heading = Number(directionDegrees.value);
+ summary.textContent = `${cardinalDirection(heading)} · ${displayDegrees(heading)}°`;
+ }
+ });
manualSubmit.addEventListener("click", () => {
+ if (manualSubmit.disabled) return;
+ manualSubmit.disabled = true;
if (!navigator.geolocation) {
submitManualReport();
return;
diff --git a/frontend/src/styles/components/manual-report-structure.css b/frontend/src/styles/components/manual-report-structure.css
index f344890..d15660c 100644
--- a/frontend/src/styles/components/manual-report-structure.css
+++ b/frontend/src/styles/components/manual-report-structure.css
@@ -16,18 +16,48 @@
}
.manual-report__quantity #manual-occurrences {
- margin-bottom: 0;
+ 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 { width: 3.5rem; min-height: 3.5rem; border: 1px solid #6d54ac; border-radius: 50%; color: #f5f0ff; font: inherit; font-size: 2rem; background: #302553; cursor: pointer; }
+.manual-report__stepper button:disabled { opacity: .4; cursor: default; }
+
.manual-report__primary .manual-direction-panel {
width: 100%;
margin: 0;
+ border-radius: 1rem;
+ background: #1a1739;
}
+.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-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__primary .manual-report__submit {
width: 100%;
+ min-height: 4.5rem;
}
+.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: 1.5rem;
@@ -50,6 +80,12 @@
background: #fff8fb;
}
+:root[data-theme="light"] .manual-report__quantity #manual-occurrences { color: #321d42; }
+: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__supporting {
border-color: #d9b4d8;
}
diff --git a/frontend/tests/manual-compass.test.mjs b/frontend/tests/manual-compass.test.mjs
index f2620b4..94f4d5c 100644
--- a/frontend/tests/manual-compass.test.mjs
+++ b/frontend/tests/manual-compass.test.mjs
@@ -7,6 +7,7 @@ test("compass stays hidden until permission and a heading, then rotates and hide