Add portnum filtering to the firehose.

This commit is contained in:
Jason Michalski
2024-05-10 22:59:37 -07:00
parent 2e46971896
commit fbe4bff44b
2 changed files with 38 additions and 11 deletions

View File

@@ -1,16 +1,39 @@
{% extends "base.html" %}
{% block body %}
<div class="container" hx-ext="sse" sse-connect="/events">
<div class="row">
<div class="col-6" id="packet_list" sse-swap="packet" hx-swap="afterbegin">
{% for packet in packets %}
{% include 'packet.html' %}
{% else %}
No packets found.
{% endfor %}
</div>
<div class="col-6 sticky-top" id="packet_details" style="height: 95vh; overflow: scroll">
<div class="container" hx-ext="sse" sse-connect="/events{% if portnum %}?portnum={{portnum}}{% endif%}">
<form class="row">
{% set options = {
1: "Text Message",
3: "Position",
4: "Node Info",
67: "Telemetry",
71: "Neighbor Info",
}
%}
<select name="portnum" class="col-2 m-2">
<option
value = ""
{% if portnum not in options %}selected{% endif %}
>All</option>
{% for value, name in options.items() %}
<option
value="{{value}}"
{% if value == portnum %}selected{% endif %}
>{{ name }}</option>
{% endfor %}
</select>
<input type="submit" class="col-2 m-2"/>
</form>
<div class="row">
<div class="col-6" id="packet_list" sse-swap="packet" hx-swap="afterbegin">
{% for packet in packets %}
{% include 'packet.html' %}
{% else %}
No packets found.
{% endfor %}
</div>
<div class="col-6 sticky-top" id="packet_details" style="height: 95vh; overflow: scroll">
</div>
</div>
{% endblock %}

View File

@@ -331,11 +331,15 @@ async def packet_details(request):
@routes.get("/firehose")
async def packet_details(request):
packets = await store.get_packets()
portnum = request.query.get("portnum")
if portnum:
portnum = int(portnum)
packets = await store.get_packets(portnum=portnum)
template = env.get_template("firehose.html")
return web.Response(
text=template.render(
packets=(Packet.from_model(p) for p in packets),
portnum=portnum,
),
content_type="text/html",
)