From df8c74627b35cb5819af33ca816f57b969c6b9c1 Mon Sep 17 00:00:00 2001 From: sam Date: Thu, 5 Mar 2026 19:45:34 -0700 Subject: [PATCH] Dynamic port rendering for multi-port NID devices Replace hardcoded 4-port loops in renderPanel(), renderSfp(), and renderLldp() with dynamic iteration over connectors data. Devices like the AMO-10000-LT-S with more than 4 ports now render all ports automatically. Management port detected by connector name. Co-Authored-By: Claude Opus 4.6 --- build_nid_viewer.py | 59 +++++++++++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 21 deletions(-) diff --git a/build_nid_viewer.py b/build_nid_viewer.py index 4da0e86..3e00a89 100644 --- a/build_nid_viewer.py +++ b/build_nid_viewer.py @@ -734,6 +734,23 @@ function formatUptime(sec) {{ p.push(s+'s'); return p.join(' '); }} +// Derive data ports and management port from connectors dynamically +function getPortLists() {{ + const connectors = DATA.connectors || {{}}; + const keys = Object.keys(connectors).sort((a,b) => parseInt(a) - parseInt(b)); + const dataPorts = []; + let mgmtPort = null; + for (const k of keys) {{ + const c = connectors[k]; + if (c.name && c.name.toLowerCase() === 'management') {{ + mgmtPort = k; + }} else {{ + dataPorts.push(k); + }} + }} + return {{ dataPorts, mgmtPort }}; +}} + function sevLabel(s) {{ return {{'0':'INFO','1':'MINOR','2':'MAJOR','3':'CRITICAL'}}[s] || s; }} @@ -1150,15 +1167,15 @@ function renderPanel() {{ return {{ label, alias }}; }} - // Build port slots dynamically from connectors 1-4 + // Build port slots dynamically from connectors + const {{ dataPorts, mgmtPort }} = getPortLists(); let slots = ''; - for (let i = 1; i <= 4; i++) {{ - const idx = String(i); + for (const idx of dataPorts) {{ const conn = connectors[idx] || {{}}; const isSfp = connType(idx) === 'sfp'; const state = slotState(idx); const pi = portInfo(idx); - const slotName = conn.name || (isSfp ? `SFP-${{i}}` : `RJ45-${{i}}`); + const slotName = conn.name || (isSfp ? `SFP-${{idx}}` : `RJ45-${{idx}}`); let icon, detail; if (isSfp) {{ @@ -1178,7 +1195,7 @@ function renderPanel() {{ ? `
${{labelParts.join('
')}}
` : ''; slots += `
-
+
${{icon}}${{esc(slotName)}} ${{esc(detail)}}
@@ -1187,7 +1204,7 @@ function renderPanel() {{ }} // Management port - const mgmtIf = ifaces['5']; + const mgmtIf = mgmtPort ? ifaces[mgmtPort] : null; const mgmtUp = mgmtIf && isUp(mgmtIf.ifOperStatus); const mgmtSlot = `