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, sha256_hash=firmware_msg.app_desc.app_elf_sha256,
) )
# overriden by prefetch_firmwares()
firmware_desc = None
@cached_property @cached_property
def chip(self) -> ChipType: def chip(self) -> ChipType:
return self.last_messages[MeshMessageType.CONFIG_HARDWARE].parsed.chip return self.last_messages[MeshMessageType.CONFIG_HARDWARE].parsed.chip

View file

@ -13,8 +13,19 @@
</p> </p>
<p> <p>
{% comment %}todo: more details{% endcomment %} {% 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> <strong>Last signin:</strong>
{{ node.last_signin.date }} {{ node.last_signin.time|date:"H:i:s" }} {{ node.last_signin.date }} {{ node.last_signin.time|date:"H:i:s" }}
({% blocktrans trimmed with timesince=node.last_signin|timesince %} ({% blocktrans trimmed with timesince=node.last_signin|timesince %}
@ -23,7 +34,7 @@
<br> <br>
<strong>Last Message:</strong> <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 %} ({% blocktrans trimmed with timesince=node.last_msg|timesince %}
{{ timesince }} ago {{ timesince }} ago
{% endblocktrans %}) {% endblocktrans %})
@ -64,15 +75,19 @@
</p> </p>
<h4>Firmware</h4> <h4>Firmware</h4>
<p> <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 }}) {% if node.firmware_desc.build %}
<br> <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>Compile Date:</strong> {{ node.last_messages.CONFIG_FIRMWARE.parsed.app_desc.compile_date }} {{ node.last_messages.CONFIG_FIRMWARE.parsed.app_desc.compile_time }} <strong>Build:</strong> <a href="{% url "mesh.firmwares.build.detail" pk=node.firmware_desc.build.pk %}">{{ node.firmware_desc.build.variant }}</a><br>
<br> <strong>Created:</strong> {{ node.firmware_desc.created }}<br>
<strong>SHA256:</strong> <small>{{ node.last_messages.CONFIG_FIRMWARE.parsed.app_desc.app_elf_sha256 }}</small> {% 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> </p>
</div> </div>
<div> <div>
<h4>Uplink</h4> <h4>Uplink configuration</h4>
<p> <p>
<strong>Enabled:</strong> {{ node.last_messages.CONFIG_UPLINK.parsed.enabled }}, <strong>Enabled:</strong> {{ node.last_messages.CONFIG_UPLINK.parsed.enabled }},
<strong>SSID:</strong> {{ node.last_messages.CONFIG_UPLINK.parsed.ssid }}, <strong>SSID:</strong> {{ node.last_messages.CONFIG_UPLINK.parsed.ssid }},
@ -88,7 +103,7 @@
</a> </a>
</p> </p>
<h4>Position</h4> <h4>Position configuration</h4>
<p> <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 }} <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> </p>

View file

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

View file

@ -44,7 +44,7 @@ class FirmwareDetailView(MeshControlMixin, DetailView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
ctx = super().get_context_data() 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, MeshMessageType.CONFIG_BOARD,
)) ))
builds = self.get_object().builds.all() builds = self.get_object().builds.all()

View file

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