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() {{ ? `