Compare commits

..

No commits in common. "317c2332555078f9ce0c18b0b6641e14ef41ea2e" and "ac7ffcda23590ba805e99d26ffe7c58ae271c839" have entirely different histories.

6 changed files with 12 additions and 53 deletions

View File

@ -27,7 +27,6 @@ type Datapoint struct {
LastValue time.Time `db:"last_value"` LastValue time.Time `db:"last_value"`
DatapointValueJSON []byte `db:"datapoint_value_json"` DatapointValueJSON []byte `db:"datapoint_value_json"`
LastDatapointValue DatapointValue LastDatapointValue DatapointValue
Found bool
} }
type DatapointValue struct { type DatapointValue struct {
@ -178,7 +177,6 @@ func DatapointsRetrieve() (dps []Datapoint, err error) { // {{{
dp.Name = res.Name dp.Name = res.Name
dp.Datatype = res.Datatype dp.Datatype = res.Datatype
dp.LastValue = res.LastValue dp.LastValue = res.LastValue
dp.Found = true
if res.VID.Valid { if res.VID.Valid {
dpv.ID = int(res.VID.Int64) dpv.ID = int(res.VID.Int64)
@ -198,25 +196,16 @@ func DatapointRetrieve(id int, name string) (dp Datapoint, err error) { // {{{
var query string var query string
var param any var param any
if id > 0 { if id > 0 {
query = `SELECT *, true AS found FROM datapoint WHERE id = $1` query = `SELECT * FROM datapoint WHERE id = $1`
param = id param = id
dp.ID = id dp.ID = id
} else { } else {
query = `SELECT *, true AS found FROM datapoint WHERE name = $1` query = `SELECT * FROM datapoint WHERE name = $1`
param = name param = name
} }
row := service.Db.Conn.QueryRowx(query, param) row := service.Db.Conn.QueryRowx(query, param)
err = row.StructScan(&dp) err = row.StructScan(&dp)
if err == sql.ErrNoRows {
dp = Datapoint{
Name: name,
}
err = nil
return
}
if err != nil { if err != nil {
err = we.Wrap(err).WithData(name) err = we.Wrap(err).WithData(name)
return return

View File

@ -23,7 +23,7 @@ import (
"time" "time"
) )
const VERSION = "v6" const VERSION = "v5"
var ( var (
logger *slog.Logger logger *slog.Logger

View File

@ -112,16 +112,9 @@ label {
.widgets .datapoints { .widgets .datapoints {
font: "Roboto Mono", monospace; font: "Roboto Mono", monospace;
display: grid; display: grid;
grid-template-columns: min-content min-content 1fr; grid-template-columns: min-content 1fr;
gap: 6px 8px; gap: 6px 8px;
margin-bottom: 8px; margin-bottom: 8px;
white-space: nowrap;
}
.widgets .datapoints .invalid {
color: #c83737;
}
.widgets .datapoints .delete img {
height: 16px;
} }
.widgets .action { .widgets .action {
display: grid; display: grid;

View File

@ -1,5 +1,5 @@
export class UI { export class UI {
constructor(version) {//{{{ constructor() {//{{{
document.getElementById('button-run'). document.getElementById('button-run').
addEventListener('click', evt => evt.preventDefault()) addEventListener('click', evt => evt.preventDefault())
@ -7,7 +7,6 @@ export class UI {
document.querySelector('input[name="name"]').focus() document.querySelector('input[name="name"]').focus()
this.version = version
this.datapoints = [] this.datapoints = []
}//}}} }//}}}
render() {//{{{ render() {//{{{
@ -18,9 +17,8 @@ export class UI {
let html = Object.keys(this.trigger.datapoints).sort().map(dpName => { let html = Object.keys(this.trigger.datapoints).sort().map(dpName => {
const dp = this.trigger.datapoints[dpName] const dp = this.trigger.datapoints[dpName]
return ` return `
<div class="datapoint delete"><a href="#" onclick="_ui.deleteDatapoint('${dp.Name}')"><img src="/images/${this.version}/delete.svg"></a></div> <div class="datapoint name"><b>${dp.Name}</b></div>
<div class="datapoint name ${dp.Found ? 'valid' : 'invalid'}"><b>${dp.Name}</b></div> <div class="datapoint value">${dp.LastDatapointValue.TemplateValue}</div>
<div class="datapoint value">${dp.Found ? dp.LastDatapointValue.TemplateValue : ''}</div>
` `
}).join('') }).join('')
datapoints.innerHTML += html datapoints.innerHTML += html
@ -80,15 +78,7 @@ export class UI {
dlg.close() dlg.close()
this.render() this.render()
}//}}} }//}}}
deleteDatapoint(name) {//{{{ update() {//{{{
if (!confirm(`Delete ${name}?`)) {
return
}
delete this.trigger.datapoints[name]
_ui.update(true)
}//}}}
update(stayOnSamePage) {//{{{
const form = document.getElementById('form-trigger') const form = document.getElementById('form-trigger')
var formData = new FormData(form) var formData = new FormData(form)
Object.keys(this.trigger.datapoints).forEach(name => formData.append("datapoints[]", name)) Object.keys(this.trigger.datapoints).forEach(name => formData.append("datapoints[]", name))
@ -97,11 +87,6 @@ export class UI {
body: formData, body: formData,
}) })
.then(resp => { .then(resp => {
if (stayOnSamePage) {
location.reload()
return
}
if (resp.redirected) { if (resp.redirected) {
location.href = resp.url location.href = resp.url
return return

View File

@ -19,18 +19,9 @@
.datapoints { .datapoints {
font: "Roboto Mono", monospace; font: "Roboto Mono", monospace;
display: grid; display: grid;
grid-template-columns: min-content min-content 1fr; grid-template-columns: min-content 1fr;
gap: 6px 8px; gap: 6px 8px;
margin-bottom: 8px; margin-bottom: 8px;
white-space: nowrap;
.invalid {
color: #c83737;
}
.delete img {
height: 16px;
}
} }
.action { .action {

View File

@ -2,7 +2,7 @@
<script type="module" defer> <script type="module" defer>
import {UI, Trigger} from "/js/{{ .VERSION }}/trigger_edit.mjs" import {UI, Trigger} from "/js/{{ .VERSION }}/trigger_edit.mjs"
window._ui = new UI({{ .VERSION }}) window._ui = new UI()
let trigger = new Trigger( let trigger = new Trigger(
{{ .Data.Trigger.ID }}, {{ .Data.Trigger.ID }},
'{{ .Data.Trigger.Name }}', '{{ .Data.Trigger.Name }}',
@ -29,7 +29,8 @@
<div class="label">Datapoints</div> <div class="label">Datapoints</div>
<div class="datapoints" style="margin-top: 4px"> <div class="datapoints" style="margin-top: 4px">
<div style="grid-column: 1 / -1"><a onclick="_ui.addDatapoint()">Add</a></div> <div><a onclick="_ui.addDatapoint()">Add</a></div>
<div></div>
</div> </div>
<div class="label">Expression</div> <div class="label">Expression</div>