diff options
author | Christopher Baines <mail@cbaines.net> | 2025-06-24 22:41:48 +0200 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2025-06-24 22:41:48 +0200 |
commit | dcf010a1a35730fd3c9bd96c2359ae22d7547839 (patch) | |
tree | 1a99eebd7ff3b6104fbdee3fbbd1cd4c0516619e | |
parent | f9a5b5524d053ee07fd80943d8ef0e81878c3a17 (diff) | |
download | bffe-dcf010a1a35730fd3c9bd96c2359ae22d7547839.tar bffe-dcf010a1a35730fd3c9bd96c2359ae22d7547839.tar.gz |
Avoid error when load element is missing
I think this is happening since the activity page doesn't handle agents coming
and going.
-rw-r--r-- | assets/js/activity.js | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/assets/js/activity.js b/assets/js/activity.js index 3de5bd5..3e8e814 100644 --- a/assets/js/activity.js +++ b/assets/js/activity.js @@ -325,20 +325,23 @@ function agentStatusUpdateHandler(e) { "agent-" + data.agent_id + "-load" ); - const loadPercentage = Math.round((100 * data.load_average["1"]) / data.processor_count); - loadElement.textContent = `Load: ${loadPercentage}%`; + // TODO When agents come and go, this might be missing + if (loadElement) { + const loadPercentage = Math.round((100 * data.load_average["1"]) / data.processor_count); + loadElement.textContent = `Load: ${loadPercentage}%`; - var loadClass; - if (loadPercentage < 150) { - loadClass = "agent-load-normal"; - } else if (loadPercentage < 250) { - loadClass = "agent-load-medium"; - } else { - loadClass = "agent-load-high"; - } - loadElement.className = `agent-load ${loadClass}`; + var loadClass; + if (loadPercentage < 150) { + loadClass = "agent-load-normal"; + } else if (loadPercentage < 250) { + loadClass = "agent-load-medium"; + } else { + loadClass = "agent-load-high"; + } + loadElement.className = `agent-load ${loadClass}`; - animateElementChange(loadElement); + animateElementChange(loadElement); + } } const lastEventId = document.getElementById("main").dataset.stateid; |