Created
January 4, 2024 01:30
-
-
Save RenatoExpert/7c167aa2166947a361f2b9d7b3797b1f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Example of what I think a Scada-LTS script would be written like. | |
* 1 - Using DOM instead of strings | |
* 2 - Using a native API to fetch info from backend | |
*/ | |
var pontos = {}; | |
for(let i = 1; i <= 15; i++) { | |
pontos[i] = scada.getDatapointById(`user${i}`); | |
} | |
let select = document.createElement("select"); | |
let on_change = `mango.view.setPoint(${point.id}, ${pointComponent.id}, ${this.options[this.selectedIndex].value})`; | |
select.setAttribute("onChange", on_change); | |
function make_option (id) { | |
let default = "selecione o usuário"; | |
let last_value = id > 0 ? pontos[id].ultimoValor() : null; | |
let text_str = id > 0 ? `Usuário ${id} - ${last_value}` : default; | |
let option = document.createElement("option"); | |
option.setAttribute("value", id); | |
if (id == value) { | |
option.setAttribute("selected", "selected"); | |
} | |
let text = document.createTextNode(text_str); | |
option.appendChild(text); | |
return option; | |
} | |
for(let i = 0; i <= 15; i++) { | |
let option = make_option(i); | |
select.appendChild(option); | |
} | |
return select; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment