added last value to index page

This commit is contained in:
BroodjeAap 2023-01-14 10:39:06 +00:00
parent bd20bb68ce
commit d2f30eb04f
4 changed files with 30 additions and 2 deletions

24
main.go
View file

@ -309,6 +309,30 @@ func (web *Web) index(c *gin.Context) {
watchMap[filter.WatchID].CronEntry = &entry
}
// get the last value stored, also doesn't really work with multiple values but meh again
rows, err := web.db.Table("watches").
Select("watches.id, max(filter_outputs.time) as time, filter_outputs.value").
Joins("left join filter_outputs on filter_outputs.watch_id = watches.id").
Order("filter_outputs.name").
Group("watches.id").
Rows()
if err != nil {
log.Println(err)
} else {
for rows.Next() {
var watchID uint
var _time string
var value string
err := rows.Scan(&watchID, &_time, &value)
if err != nil {
log.Println(err)
continue
}
watchMap[watchID].LastValue = value
}
}
c.HTML(http.StatusOK, "index", gin.H{
"watches": watches,
"warnings": web.startupWarnings,

View file

@ -12,6 +12,7 @@ type Watch struct {
ID uint `form:"watch_id" yaml:"watch_id"`
Name string `form:"watch_name" yaml:"watch_name" binding:"required" validate:"min=1"`
CronEntry *cron.Entry `gorm:"-:all"`
LastValue string `gorm:"-:all"`
}
type Filter struct {

View file

@ -21,6 +21,7 @@ GoWatch
<th>Name</th>
<th>Last Run</th>
<th>Next Run</th>
<th>Last Value</th>
<th>Edit</th>
<th>Delete</th>
</tr>
@ -36,6 +37,9 @@ GoWatch
{{ else }}
<td class="h3" colspan="2">No schedule (Add cron filter)</td>
{{ end }}
<td class="h3">
{{ .LastValue }}
</td>
<td>
<a href="/watch/edit/{{ .ID }}" class="btn btn-success">Edit</a>
</td>

View file

@ -10,4 +10,3 @@
- add index to docs/compose to fix link in pages
- safe escape {{ }} for pages
- xpath/css innerthtml option?
- display value(s) on index page?