export class UI { constructor(version) {//{{{ document.getElementById('button-run'). addEventListener('click', evt => evt.preventDefault()) document.addEventListener('keydown', evt => this.keyHandler(evt)) document.querySelector('input[name="name"]').focus() this.version = version this.datapoints = [] }//}}} render() {//{{{ document.querySelectorAll('.datapoints .datapoint').forEach(el => el.remove()); const datapoints = document.querySelector('.datapoints') let html = Object.keys(this.trigger.datapoints).sort().map(dpName => { const dp = this.trigger.datapoints[dpName] return `
${dp.Name}
${dp.Found ? dp.LastDatapointValue.TemplateValue : ''}
` }).join('') datapoints.innerHTML += html }//}}} setTrigger(t) {//{{{ this.trigger = t }//}}} run() {//{{{ this.trigger.run() }//}}} keyHandler(evt) {//{{{ if (!(evt.altKey && evt.shiftKey)) return evt.preventDefault() evt.stopPropagation() switch (evt.key) { case 'T': this.run() break case 'S': this.update() break } }//}}} addDatapoint() {//{{{ const dlg = document.getElementById('dlg-datapoints') const datalist = document.getElementById('list-datapoints') dlg.showModal() fetch('/datapoints?format=json') .then(data => data.json()) .then(json => { this.datapoints = json let html = '' this.datapoints.forEach(dp => { html += `