From f9b5d1d760ad1dca632b1a983ebae4f520671acf Mon Sep 17 00:00:00 2001 From: Andrew Dickinson Date: Tue, 2 Apr 2024 19:43:24 -0400 Subject: [PATCH] Only show node name labels on NN map dots (#315) * Only show node name labels on NN map dots * Fix null-pointer and add test case for new logic --- src/meshapi/serializers/map.py | 6 +++++- src/meshapi/tests/test_map_endpoints.py | 2 ++ src/meshapi/views/map.py | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/meshapi/serializers/map.py b/src/meshapi/serializers/map.py index af26a43d..330afc50 100644 --- a/src/meshapi/serializers/map.py +++ b/src/meshapi/serializers/map.py @@ -65,8 +65,12 @@ def get_building_coordinates(self, install: Install) -> List[float]: return [building.longitude, building.latitude, building.altitude] def get_node_name(self, install: Install) -> Optional[str]: + # Only include the node name if this is an old-school "node as install" situation + # to prevent showing the same name on multiple map dots. For the NN != install number + # case we add extra fake install objects with install_number = NN so that we can still + # see the node name node = install.node - return node.name if node else None + return node.name if node and install.node.network_number == install.install_number else None def get_synthetic_notes(self, install: Install) -> Optional[str]: if not install.node: diff --git a/src/meshapi/tests/test_map_endpoints.py b/src/meshapi/tests/test_map_endpoints.py index cf901fa8..5c52d1b6 100644 --- a/src/meshapi/tests/test_map_endpoints.py +++ b/src/meshapi/tests/test_map_endpoints.py @@ -175,6 +175,7 @@ def test_install_data(self): nodes.append( Node( network_number=567, + name="Fancy Node", status=Node.NodeStatus.PLANNED, latitude=40.724868, longitude=-73.987881, @@ -314,6 +315,7 @@ def test_install_data(self): }, { "id": 567, + "name": "Fancy Node", "coordinates": [-73.9917741, 40.6962265, 66.0], "requestDate": 1706331600000, "roofAccess": True, diff --git a/src/meshapi/views/map.py b/src/meshapi/views/map.py index 73d86fa7..c69f0082 100644 --- a/src/meshapi/views/map.py +++ b/src/meshapi/views/map.py @@ -70,6 +70,7 @@ def get_queryset(self): all_installs.append( Install( install_number=node.network_number, + node=node, status=Install.InstallStatus.NN_REASSIGNED if node.status == node.NodeStatus.ACTIVE else Install.InstallStatus.REQUEST_RECEIVED,