|
| 1 | +var mirrorInterval = Number(); |
| 2 | +const mirrors = ["mPortsTX", "mPortsRX"]; |
| 3 | + |
| 4 | +function mirrorForm() { |
| 5 | + if (!numPorts) |
| 6 | + return; |
| 7 | + clearInterval(mirrorInterval); |
| 8 | + for (let j=0; j < mirrors.length; j++) { |
| 9 | + console.log("Adding Mirror " + j) |
| 10 | + var m = document.getElementById(mirrors[j]); |
| 11 | + for (let i = 1; i <= numPorts; i++) { |
| 12 | + const d = document.createElement("div"); |
| 13 | + d.classList.add("cbgroup"); |
| 14 | + const l = document.createElement("label"); |
| 15 | + l.innerHTML = "" + i; |
| 16 | + l.classList.add("cbgroup"); |
| 17 | + const inp = document.createElement("input"); |
| 18 | + inp.type = "checkbox"; inp.setAttribute("class","psel"); |
| 19 | + inp.id = mirrors[j] + i; |
| 20 | + const o = document.createElement("img"); |
| 21 | + if (pIsSFP[i - 1]) { |
| 22 | + o.src = "sfp.svg"; o.width ="60"; o.height ="60"; |
| 23 | + } else { |
| 24 | + o.src = "port.svg"; o.width = "40"; o.height = "40"; |
| 25 | + } |
| 26 | + l.appendChild(inp); l.appendChild(o); |
| 27 | + d.appendChild(l) |
| 28 | + m.appendChild(d); |
| 29 | + } |
| 30 | + } |
| 31 | + fetchMirror(); |
| 32 | +} |
| 33 | + |
| 34 | +function setM(p, c){ |
| 35 | + document.getElementById(p).checked=c; |
| 36 | +} |
| 37 | +window.addEventListener("load", function() { |
| 38 | + mirrorInterval = setInterval(mirrorForm, 200); |
| 39 | +}); |
| 40 | + |
| 41 | +function fetchMirror() { |
| 42 | + var xhttp = new XMLHttpRequest(); |
| 43 | + xhttp.onreadystatechange = function() { |
| 44 | + if (this.readyState == 4 && this.status == 200) { |
| 45 | + const s = JSON.parse(xhttp.responseText); |
| 46 | + console.log("MIRROR: ", JSON.stringify(s)); |
| 47 | + document.getElementById('me').checked = s.enabled; |
| 48 | + document.getElementById('mp').value = s.mPort; |
| 49 | + let m_tx = parseInt(s.mirror_tx, 2); |
| 50 | + let m_rx = parseInt(s.mirror_rx, 2); |
| 51 | + for (let i = 1; i <= numPorts; i++) { |
| 52 | + setM("mPortsTX"+i, m_tx&1); setM("mPortsRX"+i, m_rx&1); |
| 53 | + m_tx = m_tx >> 1; m_rx = m_tx >> 1; |
| 54 | + } |
| 55 | + } |
| 56 | + }; |
| 57 | + xhttp.open("GET", `/mirror.json`, true); |
| 58 | + xhttp.send(); |
| 59 | +} |
0 commit comments