smon/views/pages/datapoints.gotmpl

132 lines
4.3 KiB
Go Template
Raw Permalink Normal View History

2024-04-30 08:04:16 +02:00
{{ define "page" }}
2024-05-02 08:59:55 +02:00
{{ $version := .VERSION }}
{{ $theme := .CONFIG.THEME }}
2024-06-25 08:59:07 +02:00
<link rel="stylesheet" type="text/css" href="/css/{{ .VERSION }}/{{ .CONFIG.THEME }}/datapoints.css">
2024-06-30 11:27:49 +02:00
<script type="text/javascript" defer>
2024-07-06 09:43:18 +02:00
function validateRegex(rxp) {
try {
''.match(rxp)
return true
} catch {
return false
}
}
function showDatapoints(id) {
if (!id)
document
.querySelectorAll(`[x-datapoint-id]`)
.forEach(matchedDP=>matchedDP.classList.remove('hidden'))
else
document
.querySelectorAll(`[x-datapoint-id="${id}"]`)
.forEach(matchedDP=>matchedDP.classList.remove('hidden'))
}
function hideDatapoints(id) {
if (!id)
document.querySelectorAll(`[x-datapoint-id]`).forEach(matchedDP=>
matchedDP.classList.add('hidden')
)
else
document.querySelectorAll(`[x-datapoint-id="${id}"]`).forEach(matchedDP=>
matchedDP.classList.add('hidden')
)
}
function updateRegexValidatedStatus(validated) {
const inputFilter = document.getElementById('datapoints-filter')
if (validated)
inputFilter.classList.remove('invalid-regex')
else
inputFilter.classList.add('invalid-regex')
}
2024-06-30 11:27:49 +02:00
function filterDatapoints(inputFilter) {
const filter = inputFilter.value.toLowerCase()
const datapoints = document.querySelectorAll('#datapoints .name')
var datapointID
// Shortcut to show everything if a filter is not given.
if (filter == '') {
2024-07-06 09:43:18 +02:00
showDatapoints()
2024-06-30 11:27:49 +02:00
return
}
2024-07-06 09:43:18 +02:00
// Show nothing if the regex is invalid and can't matching anything.
if (!validateRegex(filter)) {
hideDatapoints()
updateRegexValidatedStatus(false)
return
} else
updateRegexValidatedStatus(true)
2024-06-30 11:27:49 +02:00
datapoints.forEach(dp=>{
const dpName = dp.getAttribute('x-datapoint-name')
2024-07-06 09:43:18 +02:00
datapointID = dp.getAttribute('x-datapoint-id')
if (dpName.toLowerCase().match(filter))
showDatapoints(datapointID)
else
hideDatapoints(datapointID)
2024-06-30 11:27:49 +02:00
})
}
function keyhandler(evt) {
if (evt.altKey && evt.shiftKey && evt.key == 'F') {
document.getElementById('datapoints-filter').focus()
evt.preventDefault()
evt.stopPropagation()
}
}
// Add the keymap for the keybindings
document.addEventListener('keydown', keyhandler)
</script>
2024-04-30 08:04:16 +02:00
{{ block "page_label" . }}{{end}}
<a href="/datapoint/edit/0">Create</a>
2024-06-30 11:27:49 +02:00
<div style="margin-top: 16px">
2024-07-06 09:43:18 +02:00
<input id="datapoints-filter" type="text" placeholder="Filter (regexp)" style="width: 320px;" oninput="filterDatapoints(this)">
2024-06-30 11:27:49 +02:00
</div>
2024-04-30 08:04:16 +02:00
<div id="datapoints">
2024-06-25 10:50:31 +02:00
{{ $prevGroup := "15ecfcc0-b1aa-45cd-af9c-74146a7e7f56-not-very-likely" }}
2024-04-30 08:04:16 +02:00
{{ range .Data.Datapoints }}
2024-05-20 19:40:19 +02:00
{{ if ne $prevGroup .Group }}
2024-05-28 07:37:22 +02:00
<h2 class="line">{{ .Group }}</h2>
2024-05-20 19:40:19 +02:00
<div class="header">Name</div>
<div class="header">Datatype</div>
<div class="header">No data</div>
2024-05-20 19:40:19 +02:00
<div class="header">Last value</div>
<div class="header">Value</div>
<div class="header"></div>
{{ else }}
2024-06-30 11:27:49 +02:00
<div x-datapoint-id="{{ .ID }}" class="line"></div>
2024-05-20 19:40:19 +02:00
{{ end }}
2024-06-30 11:27:49 +02:00
<div x-datapoint-id="{{ .ID }}" x-datapoint-name="{{ .Name }}" class="name"><a href="/datapoint/edit/{{ .ID }}">{{ .Name }}</a></div>
<div x-datapoint-id="{{ .ID }}" class="datatype">{{ .Datatype }}</div>
<div x-datapoint-id="{{ .ID }}" class="datatype">{{ .NodataProblemSeconds }}</div>
<div x-datapoint-id="{{ .ID }}" class="last-value">{{ format_time .LastValue }}</div>
2024-04-30 08:04:16 +02:00
{{ if eq .Datatype "DATETIME" }}
2024-06-30 11:27:49 +02:00
<div x-datapoint-id="{{ .ID }}" class="value">{{ if .LastDatapointValue.ValueDateTime.Valid }}{{ format_time .LastDatapointValue.Value }}{{ end }}</div>
2024-04-30 08:04:16 +02:00
{{ else }}
2024-06-30 11:27:49 +02:00
<div x-datapoint-id="{{ .ID }}" class="value">{{ .LastDatapointValue.Value }}</div>
2024-05-02 08:59:55 +02:00
{{ end }}
2024-06-30 11:27:49 +02:00
<div x-datapoint-id="{{ .ID }}" class="icons">
2024-06-24 11:18:51 +02:00
{{ if eq .Comment "" }}
<div class="values"><img class="info" src="/images/{{ $version }}/{{ $theme }}/info-outline.svg"></div>
2024-06-24 11:18:51 +02:00
{{ else }}
<div class="values"><img class="info" src="/images/{{ $version }}/{{ $theme }}/info-filled.svg" title="{{ .Comment }}"></div>
2024-06-24 11:18:51 +02:00
{{ end }}
<div class="values"><a href="/datapoint/values/{{ .ID }}"><img src="/images/{{ $version }}/{{ $theme }}/values.svg"></a></div>
2024-06-25 09:49:09 +02:00
<div class="delete"><a href="/datapoint/delete/{{ .ID }}" onclick="confirm(`Are you sure you want to delete '{{ .Name }}'?`)"><img src="/images/{{ $version }}/{{ $theme }}/delete.svg"></a></div>
2024-05-05 20:16:28 +02:00
</div>
2024-05-20 19:40:19 +02:00
{{ $prevGroup = .Group }}
2024-05-05 20:16:28 +02:00
{{ end }}
2024-04-30 08:04:16 +02:00
</div>
{{ end }}