improve some mesh ui, show more details

This commit is contained in:
Laura Klünder 2023-11-09 18:27:57 +01:00
parent 394450f4a3
commit 7bc7c5dbc9
5 changed files with 52 additions and 22 deletions

View file

@ -194,6 +194,9 @@ class MeshNode(models.Model):
sha256_hash=firmware_msg.app_desc.app_elf_sha256,
)
# overriden by prefetch_firmwares()
firmware_desc = None
@cached_property
def chip(self) -> ChipType:
return self.last_messages[MeshMessageType.CONFIG_HARDWARE].parsed.chip

View file

@ -13,8 +13,19 @@
</p>
<p>
{% comment %}todo: more details{% endcomment %}
<strong>Uplink:</strong> {% if node.uplink %}<a href="{% url "mesh.node.detail" pk=node.uplink.node_id %}">{{ node.uplink.node }}</a><br>{% endif %}
<strong>Uplink:</strong>
{% with uplink=node.get_uplink %}
{% if uplink %}
<a href="{% url "mesh.node.detail" pk=uplink.node_id %}">{{ uplink.node }}</a>
{% if uplink.node == node %}
<em>(direct)</em>
{% endif %}
{% else %}
<em>offline</em>
{% endif %}
{% endwith %}
</p>
<p>
<strong>Last signin:</strong>
{{ node.last_signin.date }} {{ node.last_signin.time|date:"H:i:s" }}
({% blocktrans trimmed with timesince=node.last_signin|timesince %}
@ -23,7 +34,7 @@
<br>
<strong>Last Message:</strong>
{{ node.last_msg.date }} {{ node.last_msg.time|date:"H:i:s" }}
{{ node.last_messages.any.datetime.date }} {{ node.last_messages.any.datetime|date:"H:i:s" }}
({% blocktrans trimmed with timesince=node.last_msg|timesince %}
{{ timesince }} ago
{% endblocktrans %})
@ -64,15 +75,19 @@
</p>
<h4>Firmware</h4>
<p>
<strong>Firmware:</strong> {{ node.last_messages.CONFIG_FIRMWARE.parsed.app_desc.project_name }} {{ node.last_messages.CONFIG_FIRMWARE.parsed.version }} (IDF {{ node.last_messages.CONFIG_FIRMWARE.parsed.app_desc.idf_version }})
<br>
<strong>Compile Date:</strong> {{ node.last_messages.CONFIG_FIRMWARE.parsed.app_desc.compile_date }} {{ node.last_messages.CONFIG_FIRMWARE.parsed.app_desc.compile_time }}
<br>
<strong>SHA256:</strong> <small>{{ node.last_messages.CONFIG_FIRMWARE.parsed.app_desc.app_elf_sha256 }}</small>
{% if node.firmware_desc.build %}
<strong>Firmware:</strong> <a href="{% url "mesh.firmwares.detail" pk=node.firmware_desc.build.firmware.pk %}">{{ node.firmware_desc.project_name }} {{ node.firmware_desc.version }}</a><br>
<strong>Build:</strong> <a href="{% url "mesh.firmwares.build.detail" pk=node.firmware_desc.build.pk %}">{{ node.firmware_desc.build.variant }}</a><br>
<strong>Created:</strong> {{ node.firmware_desc.created }}<br>
{% else %}
<strong>Firmware:</strong> {{ node.firmware_desc.project_name }} {{ node.firmware_desc.version }}<br>
<strong>First seen:</strong> {{ node.firmware_desc.created }}<br>
<strong>SHA256:</strong> <small>{{ node.firmware_desc.sha256_hash }}</small><br>
{% endif %}
</p>
</div>
<div>
<h4>Uplink</h4>
<h4>Uplink configuration</h4>
<p>
<strong>Enabled:</strong> {{ node.last_messages.CONFIG_UPLINK.parsed.enabled }},
<strong>SSID:</strong> {{ node.last_messages.CONFIG_UPLINK.parsed.ssid }},
@ -88,7 +103,7 @@
</a>
</p>
<h4>Position</h4>
<h4>Position configuration</h4>
<p>
<strong>X=</strong>{{ node.last_messages.CONFIG_POSITION.parsed.x_pos }}, <strong>Y=</strong>{{ node.last_messages.CONFIG_POSITION.parsed.y_pos }}, <strong>Z=</strong>{{ node.last_messages.CONFIG_POSITION.parsed.z_pos }}
</p>

View file

@ -17,15 +17,22 @@
<tr>
<td><a href="{% url "mesh.node.detail" pk=node.address %}">{{ node }}</a></td>
<td>
{{ node.last_messages.CONFIG_BOARD.parsed.board_config.board.pretty_name }}
({{ node.last_messages.CONFIG_HARDWARE.parsed.chip.pretty_name }} <small>rev{{ node.last_messages.CONFIG_HARDWARE.parsed.revision_major }}.{{ node.last_messages.CONFIG_HARDWARE.parsed.revision_minor }}</small>)
{{ node.last_messages.CONFIG_BOARD.parsed.board_config.board.pretty_name }}<br>
<small>({{ node.last_messages.CONFIG_HARDWARE.parsed.chip.pretty_name }} rev{{ node.last_messages.CONFIG_HARDWARE.parsed.revision_major }}.{{ node.last_messages.CONFIG_HARDWARE.parsed.revision_minor }})</small>
</td>
<td>
{{ node.last_messages.CONFIG_FIRMWARE.parsed.app_desc.version }}
<small>(IDF {{ node.last_messages.CONFIG_FIRMWARE.parsed.app_desc.idf_version }})</small>
{% if node.firmware_desc.build %}
<a href="{% url "mesh.firmwares.detail" pk=node.firmware_desc.build.firmware.pk %}">{{ node.firmware_desc.project_name }} {{ node.firmware_desc.version }}</a><br>
<a href="{% url "mesh.firmwares.build.detail" pk=node.firmware_desc.build.pk %}">
{{ node.firmware_desc.build.variant }}
</a>
{% else %}
{{ node.firmware_desc.project_name }} {{ node.firmware_desc.version }}<br>
<small>{{ node.firmware_desc.sha256_hash }}</small>
{% endif %}
</td>
<td>
{% blocktrans trimmed with timesince=node.last_msg|timesince %}
{% blocktrans trimmed with timesince=node.last_messages.any.datetime|timesince %}
{{ timesince }} ago
{% endblocktrans %}
</td>
@ -34,9 +41,15 @@
{{ timesince }} ago
{% endblocktrans %}
</td>
{% comment %}todo: hide uplink if timed out{% endcomment %}
{% comment %}todo: more details{% endcomment %}
<td>{% if node.uplink %}<a href="{% url "mesh.node.detail" pk=node.uplink.node_id %}">{{ node.uplink.node }}</a>{% endif %}</td>
<td>
{% with uplink=node_get_uplink %}
{% if uplink %}
<a href="{% url "mesh.node.detail" pk=uplink.node_id %}">{{ node.uplink.node }}</a>
{% else %}
<em>offline</em>
{% endif %}
{% endwith %}
</td>
</tr>
{% endfor %}
</table>

View file

@ -44,7 +44,7 @@ class FirmwareDetailView(MeshControlMixin, DetailView):
def get_context_data(self, **kwargs):
ctx = super().get_context_data()
nodes = list(MeshNode.objects.all().prefetch_firmwares().prefetch_last_messages(
nodes: list[MeshNode] = list(MeshNode.objects.all().prefetch_firmwares().prefetch_last_messages(
MeshMessageType.CONFIG_BOARD,
))
builds = self.get_object().builds.all()

View file

@ -1,5 +1,4 @@
from django.contrib.messages.views import SuccessMessageMixin
from django.db.models import Max
from django.shortcuts import redirect
from django.urls import reverse
from django.utils.translation import gettext_lazy as _
@ -17,7 +16,7 @@ class NodeListView(MeshControlMixin, ListView):
context_object_name = "nodes"
def get_queryset(self):
return super().get_queryset().annotate(last_msg=Max('received_messages__datetime')).prefetch_last_messages()
return super().get_queryset().prefetch_last_messages().prefetch_firmwares()
def post(self, request):
return redirect(
@ -32,7 +31,7 @@ class NodeDetailView(MeshControlMixin, DetailView):
context_object_name = "node"
def get_queryset(self):
return super().get_queryset().annotate(last_msg=Max('received_messages__datetime')).prefetch_last_messages()
return super().get_queryset().prefetch_last_messages().prefetch_firmwares()
class NodeEditView(MeshControlMixin, SuccessMessageMixin, UpdateView):