fixed categorical values view

This commit is contained in:
BroodjeAap 2023-03-05 14:36:07 +00:00
parent 0c73b3af4b
commit 9894fac8ea
2 changed files with 27 additions and 20 deletions

View file

@ -38,34 +38,38 @@ GoWatch {{ .Watch.Name }}
</canvas>
{{ end }}
{{ $first := true }}
{{ if .categoricalMap }}
<ul class="nav nav-tabs" id="categoricalTab" role="tablist">
{{ range $name, $values := .categoricalMap }}
<li class="nav-item" role="presentation">
<button class="nav-link active" id="{{ $name }}-tab" data-bs-toggle="tab" data-bs-target="#{{ $name }}-tab-pane" type="button" role="tab" aria-controls="{{ $name }}-tab-pane" aria-selected="true">{{ $name }}</button>
<button class="nav-link {{ if $first }}active{{ end }}" id="{{ $name }}-tab" data-bs-toggle="tab" data-bs-target="#{{ $name }}-tab-pane" type="button" role="tab" aria-controls="{{ $name }}-tab-pane" aria-selected="{{ if $first }}true{{ else }}false{{ end }}">{{ $name }}</button>
</li>
{{ $first = false }}
{{ end }}
</ul>
<div class="tab-content" id="categoricalTabContent">
{{ $first = true }}
{{ range $name, $values := .categoricalMap }}
<div class="tab-pane fade show active" id="{{ $name }}-tab-pane" role="tabpanel" aria-labelledby="{{ $name }}-tab" tabindex="0">
<table class="table">
<thead>
<tr>
<th>When</th>
<th>Value</th>
</tr>
</thead>
<tbody>
{{ range $value := $values }}
<tr>
<td>{{ $value.Time.Format "2006-01-02 15:04:05" }}</td>
<td>{{ $value.Value }}</td>
</tr>
{{ end }}
</tbody>
</table>
</div>
<div class="tab-pane {{ if $first }}active{{ end }}" id="{{ $name }}-tab-pane" role="tabpanel" aria-labelledby="{{ $name }}-tab" tabindex="0">
<table class="table">
<thead>
<tr>
<th>When</th>
<th>Value</th>
</tr>
</thead>
<tbody>
{{ range $value := $values }}
<tr>
<td>{{ $value.Time.Format "2006-01-02 15:04:05" }}</td>
<td>{{ $value.Value }}</td>
</tr>
{{ end }}
</tbody>
</table>
</div>
{{ $first = false }}
{{ end }}
</div>
{{ end }}

View file

@ -714,7 +714,10 @@ func (web *Web) watchView(c *gin.Context) {
numericalMap[value.Name] = append(numericalMap[value.Name], value)
} else {
// probably very inefficient to prepend, but want newest values at the top
categoricalMap[value.Name] = append([]*FilterOutput{value}, categoricalMap[value.Name]...)
valueName := strings.ReplaceAll(value.Name, " ", "_")
valueName = strings.ToLower(valueName)
categoricalMap[valueName] = append([]*FilterOutput{value}, categoricalMap[valueName]...)
log.Println(categoricalMap)
}
}