Browse Source

fix max module name length and hidden module power (1. and 2. of #337)

pull/341/head
lumapu 2 years ago
parent
commit
f53933b473
  1. 13
      tools/esp8266/html/api.js
  2. 90
      tools/esp8266/html/setup.html

13
tools/esp8266/html/api.js

@ -1,5 +1,5 @@
function toggle(name, hide) {
var elm = document.getElementsByName(name)[0];
function toggle(id, hide) {
var elm = document.getElementById(id);
if(hide) {
if(!elm.classList.contains("hide"))
elm.classList.add("hide");
@ -32,19 +32,22 @@ function des(val) {
return e;
}
function lbl(id, val) {
function lbl(htmlfor, val, cl=null, id=null) {
e = document.createElement('label');
e.htmlFor = id;
e.htmlFor = htmlfor;
e.innerHTML = val;
if(null != cl) e.classList.add(...cl);
if(null != id) e.id = id;
return e;
}
function inp(name, val, max=32, cl=["text"]) {
function inp(name, val, max=32, cl=["text"], id=null) {
e = document.createElement('input');
e.classList.add(...cl);
e.name = name;
e.value = val;
e.maxLength = max;
if(null != id) e.id = id;
return e;
}

90
tools/esp8266/html/setup.html

@ -5,6 +5,17 @@
<link rel="stylesheet" type="text/css" href="style.css"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="text/javascript" src="api.js"></script>
<script type="text/javascript">
function load() {
for(it of document.getElementsByClassName("s_collapsible")) {
it.addEventListener("click", function() {
this.classList.toggle("active");
var content = this.nextElementSibling;
content.style.display = (content.style.display === "block") ? "none" : "block";
});
}
}
</script>
</head>
<body onload="load()">
<h1>Setup</h1>
@ -107,49 +118,11 @@
<p class="right"><a href="/reboot">Reboot</a></p>
</div>
<script type="text/javascript">
function load() {
document.querySelectorAll('input[name^="inv"][name$="Addr"]').forEach(elm => {
elm.addEventListener("keyup", (e) => {
serial = elm.value.substring(0,4);
iv = elm.name.substring(3,4);
max = 0;
for(i=0;i<4;i++) {
toggle("inv"+iv+"ModPwr"+i, true);
toggle("inv"+iv+"ModName"+i, true);
}
toggle("lbl"+iv+"ModPwr", true);
toggle("lbl"+iv+"ModName", true);
if(serial == "1161") max = 4;
else if(serial == "1141") max = 2;
else if(serial == "1121") max = 1;
for(i=0;i<max;i++) {
toggle("inv"+iv+"ModPwr"+i, false);
toggle("inv"+iv+"ModName"+i, false);
}
if(max != 0) {
toggle("lbl"+iv+"ModPwr", false);
toggle("lbl"+iv+"ModName", false);
}
});
evt = document.createEvent("HTMLEvents");
evt.initEvent("keyup", false, true);
elm.dispatchEvent(evt);
});
for(it of document.getElementsByClassName("s_collapsible")) {
it.addEventListener("click", function() {
this.classList.toggle("active");
var content = this.nextElementSibling;
content.style.display = (content.style.display === "block") ? "none" : "block";
});
}
}
var highestId = 0;
var maxInv = 0;
const re = /11[2,4,6]1.*/;
document.getElementsByName("btnAdd")[0].addEventListener("click", function() {
if(highestId < (maxInv-1))
ivHtml(JSON.parse('{"name":"","serial":"","channels":4,"ch_max_power":[0,0,0,0],"ch_name":["","","",""],"power_limit":1500,"power_limit_option":65535}'), highestId + 1);
@ -163,7 +136,34 @@
iv.appendChild(des("Inverter " + id));
id = "inv" + id;
for(var i of [["Addr", "serial", "Address*", 12], ["Name", "name", "Name*", 32], ["ActivePowerLimit", "power_limit", "Active Power Limit", 5]]) {
iv.appendChild(lbl(id + "Addr", "Address*"));
var addr = inp(id + "Addr", obj["serial"], 12)
iv.appendChild(addr);
addr.addEventListener("keyup", (e) => {
var serial = addr.value.substring(0,4);
var max = 0;
for(var i=0;i<4;i++) {
toggle(id+"ModPwr"+i, true);
toggle(id+"ModName"+i, true);
}
toggle("lbl"+id+"ModPwr", true);
toggle("lbl"+id+"ModName", true);
if(serial == "1161") max = 4;
else if(serial == "1141") max = 2;
else if(serial == "1121") max = 1;
for(var i=0;i<max;i++) {
toggle(id+"ModPwr"+i, false);
toggle(id+"ModName"+i, false);
}
if(max != 0) {
toggle("lbl"+id+"ModPwr", false);
toggle("lbl"+id+"ModName", false);
}
});
for(var i of [["Name", "name", "Name*", 32], ["ActivePowerLimit", "power_limit", "Active Power Limit", 5]]) {
iv.appendChild(lbl(id + i[0], i[2]));
iv.appendChild(inp(id + i[0], obj[i[1]], i[3]));
}
@ -177,12 +177,14 @@
[257, "relativ in percent persistent"]
], obj.power_limit_option));
for(var j of [["ModPwr", "ch_max_power", "Max Module Power (Wp)"], ["ModName", "ch_name", "Module Name"]]) {
iv.appendChild(lbl(id + j[0], j[2]));
for(var j of [["ModPwr", "ch_max_power", "Max Module Power (Wp)", 4], ["ModName", "ch_name", "Module Name", 16]]) {
var cl = (re.test(obj["serial"])) ? null : ["hide"];
iv.appendChild(lbl(null, j[2], cl, "lbl" + id + j[0]));
d = div([j[0]]);
i = 0;
cl = (re.test(obj["serial"])) ? ["text", "sh"] : ["text", "sh", "hide"];
for(it of obj[j[1]]) {
d.appendChild(inp(id + j[0] + i, it, 4, ["text", "sh"]));
d.appendChild(inp(id + j[0] + i, it, j[3], cl, id + j[0] + i));
i++;
}
iv.appendChild(d);

Loading…
Cancel
Save