#3, added datapoint comment

This commit is contained in:
Magnus Åhall 2024-06-24 11:18:51 +02:00
parent f29693a066
commit 42b1a20531
9 changed files with 173 additions and 3 deletions

View File

@ -25,6 +25,7 @@ type Datapoint struct {
Group string
Name string
Datatype DatapointType
Comment string
LastValue time.Time `db:"last_value"`
DatapointValueJSON []byte `db:"datapoint_value_json"`
LastDatapointValue DatapointValue
@ -73,11 +74,12 @@ func (dp Datapoint) Update() (err error) { // {{{
if dp.ID == 0 {
_, err = service.Db.Conn.Exec(
`INSERT INTO datapoint("group", name, datatype, nodata_problem_seconds) VALUES($1, $2, $3, $4)`,
`INSERT INTO datapoint("group", name, datatype, nodata_problem_seconds, comment) VALUES($1, $2, $3, $4, $5)`,
dp.Group,
name,
dp.Datatype,
dp.NodataProblemSeconds,
dp.Comment,
)
} else {
/* Keep nodata_is_problem as is unless the nodata_problem_seconds is changed.
@ -90,10 +92,11 @@ func (dp Datapoint) Update() (err error) { // {{{
"group"=$2,
name=$3,
datatype=$4,
nodata_problem_seconds=$5,
comment=$5,
nodata_problem_seconds=$6,
nodata_is_problem = (
CASE
WHEN $5 != nodata_problem_seconds THEN false
WHEN $6 != nodata_problem_seconds THEN false
ELSE
nodata_is_problem
END
@ -105,6 +108,7 @@ func (dp Datapoint) Update() (err error) { // {{{
dp.Group,
name,
dp.Datatype,
dp.Comment,
dp.NodataProblemSeconds,
)
}
@ -161,6 +165,7 @@ func DatapointsRetrieve() (dps []Datapoint, err error) { // {{{
dp.datatype,
dp.last_value,
dp.group,
dp.comment,
dp.nodata_problem_seconds,
dpv.id AS v_id,
@ -190,6 +195,7 @@ func DatapointsRetrieve() (dps []Datapoint, err error) { // {{{
Group string
Name string
Datatype DatapointType
Comment string
LastValue time.Time `db:"last_value"`
NodataProblemSeconds int `db:"nodata_problem_seconds"`
@ -214,6 +220,7 @@ func DatapointsRetrieve() (dps []Datapoint, err error) { // {{{
dp.Name = res.Name
dp.Group = res.Group
dp.Datatype = res.Datatype
dp.Comment = res.Comment
dp.LastValue = res.LastValue
dp.Found = true
dp.NodataProblemSeconds = res.NodataProblemSeconds

View File

@ -626,6 +626,7 @@ func actionDatapointUpdate(w http.ResponseWriter, r *http.Request, _ *session.T)
dp.Group = r.FormValue("group")
dp.Name = r.FormValue("name")
dp.Datatype = DatapointType(r.FormValue("datatype"))
dp.Comment = r.FormValue("comment")
dp.NodataProblemSeconds = nodataSeconds
err = dp.Update()
if err != nil {

1
sql/00017.sql Normal file
View File

@ -0,0 +1 @@
ALTER TABLE public.datapoint ADD COLUMN comment VARCHAR DEFAULT '' NOT NULL;

View File

@ -125,12 +125,16 @@ label {
}
#datapoints div {
white-space: nowrap;
align-self: center;
}
#datapoints .icons {
display: flex;
gap: 12px;
align-items: center;
}
#datapoints img.info {
height: 20px;
}
#values {
display: grid;
grid-template-columns: repeat(2, min-content);

View File

@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
width="17.999989"
height="18"
viewBox="0 0 4.7624969 4.7625001"
version="1.1"
id="svg8"
inkscape:version="1.3.2 (1:1.3.2+202311252150+091e20ef0f)"
sodipodi:docname="info-filled.svg"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/">
<defs
id="defs2" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="16"
inkscape:cx="6.84375"
inkscape:cy="0.6875"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
units="px"
inkscape:window-width="2190"
inkscape:window-height="1404"
inkscape:window-x="1463"
inkscape:window-y="16"
inkscape:window-maximized="0"
inkscape:showpageshadow="true"
inkscape:pagecheckerboard="0"
inkscape:deskcolor="#d6d6d6"
showborder="true" />
<metadata
id="metadata5">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(-90.222917,-148.43125)">
<title
id="title1">information-slab-circle</title>
<title
id="title1-6">information</title>
<path
d="m 92.842292,150.09812 h -0.47625 v -0.47625 h 0.47625 m 0,2.38126 h -0.47625 v -1.42875 h 0.47625 m -0.238125,-2.14313 a 2.3812503,2.3812503 0 0 0 -2.38125,2.38125 2.3812503,2.3812503 0 0 0 2.38125,2.38124 2.3812503,2.3812503 0 0 0 2.381246,-2.38124 2.3812503,2.3812503 0 0 0 -2.381246,-2.38125 z"
id="path1-2"
style="font-variation-settings:normal;opacity:1;vector-effect:none;fill:#fb4934;fill-opacity:1;stroke-width:0.311724;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;-inkscape-stroke:none;stop-color:#000000;stop-opacity:1" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
width="17.999989"
height="18"
viewBox="0 0 4.7624969 4.7625001"
version="1.1"
id="svg8"
inkscape:version="1.3.2 (1:1.3.2+202311252150+091e20ef0f)"
sodipodi:docname="info-outline.svg"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/">
<defs
id="defs2" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="11.313708"
inkscape:cx="21.610951"
inkscape:cy="4.5961941"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
units="px"
inkscape:window-width="2190"
inkscape:window-height="1404"
inkscape:window-x="1463"
inkscape:window-y="16"
inkscape:window-maximized="0"
inkscape:showpageshadow="true"
inkscape:pagecheckerboard="0"
inkscape:deskcolor="#d6d6d6"
showborder="true" />
<metadata
id="metadata5">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(-90.222917,-148.43125)">
<title
id="title1">information-slab-circle</title>
<title
id="title1-6">information-slab-circle-outline</title>
<title
id="title1-5">information-outline</title>
<path
d="m 92.366045,150.09812 h 0.47625 v -0.47625 h -0.47625 m 0.238125,3.09564 c -1.050132,0 -1.905003,-0.85488 -1.905003,-1.90501 0,-1.05013 0.854871,-1.90501 1.905003,-1.90501 1.050133,0 1.905006,0.85488 1.905006,1.90501 0,1.05013 -0.854873,1.90501 -1.905006,1.90501 m 0,-4.28626 a 2.381253,2.381253 0 0 0 -2.381253,2.38125 2.381253,2.381253 0 0 0 2.381253,2.38125 2.381253,2.381253 0 0 0 2.381256,-2.38125 2.381253,2.381253 0 0 0 -2.381256,-2.38125 m -0.238125,3.57188 h 0.47625 v -1.42875 h -0.47625 z"
id="path1-3"
style="font-variation-settings:normal;opacity:1;vector-effect:none;fill:#666666;fill-opacity:1;stroke-width:0.238125;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;-inkscape-stroke:none;stop-color:#000000;stop-opacity:1" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.8 KiB

View File

@ -13,6 +13,7 @@
margin-top: 1.5em;
padding-bottom: 4px;
}
h2 {
border-bottom: unset;
}
@ -26,6 +27,7 @@
div {
white-space: nowrap;
align-self: center;
}
.icons {
@ -33,6 +35,10 @@
gap: 12px;
align-items: center;
}
img.info {
height: 20px;
}
}
#values {

View File

@ -32,6 +32,12 @@
<div class="description">Set to 0 to disable.</div>
</div>
<div class="label">Comment</div>
<div>
<textarea name="comment" rows=4>{{ .Data.Datapoint.Comment }}</textarea>
</div>
<div></div>
<div class="action">
{{ if eq .Data.Datapoint.ID 0 }}

View File

@ -31,6 +31,11 @@
<div class="value">{{ .LastDatapointValue.Value }}</div>
{{ end }}
<div class="icons">
{{ if eq .Comment "" }}
<div class="values"><img class="info" src="/images/{{ $version }}/info-outline.svg"></div>
{{ else }}
<div class="values"><img class="info" src="/images/{{ $version }}/info-filled.svg" title="{{ .Comment }}"></div>
{{ end }}
<div class="values"><a href="/datapoint/values/{{ .ID }}"><img src="/images/{{ $version }}/values.svg"></a></div>
<div class="delete"><a href="/datapoint/delete/{{ .ID }}" onclick="confirm(`Are you sure you want to delete '{{ .Name }}'?`)"><img src="/images/{{ $version }}/delete.svg"></a></div>
</div>