From 4b2bb54c406ba963cda92d17eccc99d6bb62fd8b Mon Sep 17 00:00:00 2001 From: Lars Wikman Date: Tue, 29 Oct 2024 15:26:16 +0100 Subject: [PATCH] Tidy up logging --- assets/js/app.js | 87 ++++++++++------------ lib/nerves_hub_web/live/dashboard/index.ex | 9 +-- 2 files changed, 44 insertions(+), 52 deletions(-) diff --git a/assets/js/app.js b/assets/js/app.js index 613f8fdc6..04261e88f 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -248,8 +248,6 @@ Hooks.WorldMap = { // progressBar.style.width = Math.round(processed / total * 100) + '%'; } - console.log(processed, total) - if (processed === total) { // all markers processed - hide the progress bar: // progress.classList.add = 'hidden'; @@ -300,43 +298,15 @@ Hooks.WorldMap = { let mode = this.el.dataset.mode; var devices = []; - var clusterLayer = L.markerClusterGroup({ chunkedLoading: true, chunkProgress: this.updateProgressBar }); - for (let i = 0; i < markers.length; i++) { - let marker = markers[i]; - let location = marker["l"]; - if (location["ng"] !== undefined && location["at"] !== undefined) { - let latlng = [location["at"], location["ng"]]; - let newMarker; - switch (mode) { - case 'connected': - if (marker["s"] == "connected") { - newMarker = L.marker(latlng, markerConnectedOptions); - } else { - newMarker = L.marker(latlng, markerOfflineOptions); - } - break; - case 'updated': - // Only show connected ones, the offline ones are just confusing - if (marker["s"] == "connected") { - if (marker["lf"]) { - newMarker = L.marker(latlng, markerUpdatedOptions); - } else { - newMarker = L.marker(latlng, markerOutdatedOptions); - } - } - break; - default: - } - devices.push(newMarker); - } - } + var myRenderer = L.canvas({ padding: 0.5 }); var markerConnectedOptions = { radius: 6, fillColor: "#4dd54f", weight: 1, opacity: 0, - fillOpacity: 1 + fillOpacity: 1, + renderer: myRenderer }; var markerOfflineOptions = { @@ -344,7 +314,8 @@ Hooks.WorldMap = { fillColor: "rgba(196,49,49,1)", weight: 1, opacity: 0, - fillOpacity: 1 + fillOpacity: 1, + renderer: myRenderer }; var markerUpdatedOptions = { @@ -352,7 +323,8 @@ Hooks.WorldMap = { fillColor: "#4dd54f", weight: 1, opacity: 0, - fillOpacity: 1 + fillOpacity: 1, + renderer: myRenderer }; var markerOutdatedOptions = { @@ -360,20 +332,43 @@ Hooks.WorldMap = { fillColor: "rgba(99,99,99,1)", weight: 1, opacity: 0, - fillOpacity: 1 + fillOpacity: 1, + renderer: myRenderer }; - // Clear previous defined device layer before adding markers - // if (this.deviceLayer !== undefined) { this.map.removeLayer(this.deviceLayer); } - - // let f = 0; - // this.deviceLayer = L.geoJson(devices, { - // pointToLayer: function (feature, latlng) { + var clusterLayer = L.markerClusterGroup({ chunkedLoading: true, chunkProgress: this.updateProgressBar }); + for (let i = 0; i < markers.length; i++) { + let marker = markers[i]; + let location = marker["l"]; + if (location["ng"] !== undefined && location["at"] !== undefined) { + let latlng = [location["at"], location["ng"]]; + let newMarker = false; + switch (mode) { + case 'connected': + if (marker["s"] == "connected") { + newMarker = L.circleMarker(latlng, markerConnectedOptions); + } else { + newMarker = L.circleMarker(latlng, markerOfflineOptions); + } + break; + case 'updated': + // Only show connected ones, the offline ones are just confusing + if (marker["s"] == "connected") { + if (marker["lf"]) { + newMarker = L.circleMarker(latlng, markerUpdatedOptions); + } else { + newMarker = L.circleMarker(latlng, markerOutdatedOptions); + } + } + break; + default: + } + if (newMarker) { + devices.push(newMarker); + } + } + } - // } - // }); - console.log(devices.length) - console.log("updated end") clusterLayer.addLayers(devices); this.map.addLayer(clusterLayer) } diff --git a/lib/nerves_hub_web/live/dashboard/index.ex b/lib/nerves_hub_web/live/dashboard/index.ex index a92da4a6d..365da7659 100644 --- a/lib/nerves_hub_web/live/dashboard/index.ex +++ b/lib/nerves_hub_web/live/dashboard/index.ex @@ -19,7 +19,7 @@ defmodule NervesHubWeb.Live.Dashboard.Index do |> assign(:time, time()) |> assign(:next_timer, nil) |> assign(:loading?, true) - |> assign(:mode, "connected") + |> assign(:mode, "updated") |> assign(:device_count, 0) |> assign(:marker_count, 0) |> refresh_after(1) @@ -81,7 +81,6 @@ defmodule NervesHubWeb.Live.Dashboard.Index do end defp update_devices_and_markers(%{assigns: %{org: org, product: product}} = socket) do - IO.puts("Starting...") t = time() duration = t - socket.assigns.time @@ -101,8 +100,6 @@ defmodule NervesHubWeb.Live.Dashboard.Index do subscribe_to_devices(socket, devices) - IO.puts("Done!") - socket |> assign(:time, t) |> assign(:loading?, false) @@ -120,8 +117,8 @@ defmodule NervesHubWeb.Live.Dashboard.Index do defp generate_map_marker( %{ - id: id, - identifier: identifier, + id: _id, + identifier: _identifier, connection_status: connection_status, longitude: longitude, latitude: latitude,