diff --git a/data/modules.js b/data/modules.js index ff36a816..3e0e3db2 100644 --- a/data/modules.js +++ b/data/modules.js @@ -17,6 +17,12 @@ class Modules { let code = "" controller.modules.test("ew") // this.test("ew") //this.otherMethodInThisClass: [Error] Unhandled Promise Rejection: TypeError: this.test is not a function. (In 'this.test("ew")', 'this.test' is undefined) + + // sort module variables + moduleJson.n.sort(function(a,b) { + return Math.abs(a.o) - Math.abs(b.o); //o is order nr (ignore negatives for the time being) + }); + for (let variable of moduleJson.n) { let variableClass = varJsonToClass(variable); @@ -43,6 +49,7 @@ class Modules { //used by fetchModel and by makeWS addModule(moduleJson) { + moduleJson.type = moduleJson.type=="appmod"?appName():moduleJson.type=="usermod"?"User":"System"; this.model.push(moduleJson); //updateUI is made after all modules have been fetched, how to adapt to add one module? @@ -89,12 +96,16 @@ class Modules { //creates the right class based on variable.type function varJsonToClass(variable) { switch (variable.type) { + case "button": + return new ButtonVariable(variable); case "progress": return new ProgressVariable(variable); case "text": return new TextVariable(variable); case "select": return new SelectVariable(variable); + case "checkbox": + return new CheckboxVariable(variable); default: return new Variable(variable); } @@ -107,43 +118,85 @@ class Variable { this.node = document.getElementById(variable.id); } - createHTML() { //base + createHTML(node = ``) { //base return `
- - + + ${node}
`
-
}
//sets the value of the node to value of properties
receiveData(properties) { //base
- if (this.node && properties.value)
- this.node.value = properties.value;
+ if (this.node) {
+ if (properties.label) {
+ let labelNode = this.node.parentNode.querySelector("label")
+ if (labelNode)
+ labelNode.innerText = properties.label;
+ else
+ this.node.parentNode.innerHTML = `` + this.node.parentNode.innerHTML
+ }
+ if (properties.value != null && this.node.value != null) {
+ this.node.value = properties.value;
+ }
+ if (properties.comment) {
+ let commentNode = this.node.parentNode.querySelector("comment")
+ if (commentNode)
+ commentNode.innerText = properties.comment
+ else
+ this.node.parentNode.innerHTML += `
- - -
` + return super.createHTML(``) + } + + generateData() { + super.generateData("") //no value update } -} //class ProgressVariable + +} //class ButtonVariable class SelectVariable extends Variable { createHTML() { //override - return `
- - -
` + return super.createHTML(``) } generateData() { @@ -151,15 +204,15 @@ class SelectVariable extends Variable { if (this.node && this.node.childNodes.length == 0) this.node.innerHTML+='' - controller.receiveData(JSON.parse(`{"${this.variable.id}":{"value":${Math.random() <.33?0:Math.random() <.66?1:2}}}`)); + super.generateData(`"value":${Math.random() <.33?0:Math.random() <.66?1:2}`) } } //class SelectVariable -class TextVariable extends Variable { +class ProgressVariable extends Variable { - generateData() { - controller.receiveData(JSON.parse(`{"${this.variable.id}":{"value":"${Math.random().toString(36).slice(2)}"}}`)); + createHTML() { //override + return super.createHTML(``) } -} //class TextVariable \ No newline at end of file +} //class ProgressVariable \ No newline at end of file diff --git a/data/newui.htm b/data/newui.htm index a38f4ea5..c98e438e 100644 --- a/data/newui.htm +++ b/data/newui.htm @@ -18,7 +18,6 @@