mirror of
https://github.com/logicog/RTLPlayground.git
synced 2026-10-29 17:54:14 +08:00
The LAG page draws four sections headed LAG 1 to LAG 4 and wires their buttons to lagSub(0) through lagSub(3), which then sends the index straight through as the group number. So the first button asks for "lag 0", which the parser rejects, and the page shows nothing at all because the error only goes to the console. Every other button is off by one: the section headed LAG 2 creates group 1. The index stays 0-based for the element ids and only the command gets the 1-based number the CLI documents.
82 lines
2.2 KiB
JavaScript
82 lines
2.2 KiB
JavaScript
var lagInterval = Number();
|
|
|
|
function lagForm() {
|
|
if (!numPorts)
|
|
return;
|
|
for (let j=0; j < 4; j++) {
|
|
var lag = "mLAG" + j
|
|
console.log("Adding LAG " + lag)
|
|
var m = document.getElementById(lag);
|
|
for (let i = 1; i <= numPorts; i++) {
|
|
const d = document.createElement("div");
|
|
d.classList.add("cbgroup");
|
|
const l = document.createElement("label");
|
|
l.innerHTML = "" + i;
|
|
l.classList.add("cbgroup");
|
|
const inp = document.createElement("input");
|
|
inp.type = "checkbox"; inp.setAttribute("class","psel");
|
|
inp.id = "p_" + lag + "_" + i;
|
|
const o = document.createElement("img");
|
|
if (pIsSFP[i - 1]) {
|
|
o.src = "sfp.svg"; o.width ="60"; o.height ="60";
|
|
} else {
|
|
o.src = "port.svg"; o.width = "40"; o.height = "40";
|
|
}
|
|
l.appendChild(inp); l.appendChild(o);
|
|
d.appendChild(l)
|
|
m.appendChild(d);
|
|
}
|
|
}
|
|
fetchLag();
|
|
}
|
|
|
|
function setL(p, c){
|
|
console.log("LAG setting: ", p, " to ", c);
|
|
document.getElementById(p).checked=c;
|
|
}
|
|
|
|
function fetchLag() {
|
|
var xhttp = new XMLHttpRequest();
|
|
xhttp.onreadystatechange = function() {
|
|
if (this.readyState == 4 && this.status == 200) {
|
|
const s = JSON.parse(xhttp.responseText);
|
|
console.log("LAG: ", JSON.stringify(s));
|
|
for (let l = 0; l < 4; l++) {
|
|
let members = parseInt(s[l].members, 2);
|
|
let hash = parseInt(s[l].hash, 16);
|
|
for (let i = 1; i <= numPorts; i++) {
|
|
let p = i - 1;
|
|
if (numPorts < 9)
|
|
p = physToLogPort[p];
|
|
setL("p_mLAG"+l+"_"+i, members & (1<<p));
|
|
}
|
|
}
|
|
}
|
|
};
|
|
xhttp.open("GET", `/lag.json`, true);
|
|
sendXHTTP(xhttp);
|
|
}
|
|
async function lagSub(l) {
|
|
var cmd = "lag " + (l + 1);
|
|
for (let i = 1; i <= numPorts; i++) {
|
|
if (document.getElementById("p_mLAG"+l+"_"+i).checked)
|
|
cmd = cmd + ` ${i}`;
|
|
}
|
|
try {
|
|
const response = await fetch('/cmd', {
|
|
method: 'POST',
|
|
body: cmd
|
|
});
|
|
console.log('Completed!', response);
|
|
} catch(err) {
|
|
console.error(`Error: ${err}`);
|
|
}
|
|
}
|
|
|
|
window.addEventListener("load", function() {
|
|
update( () => {
|
|
lagForm();
|
|
const interval = setInterval(update, 2000);
|
|
});
|
|
});
|