From 7aaf75d1f1a014b5c7ac2f722a4cf48907b0cbb7 Mon Sep 17 00:00:00 2001 From: Joerg Lehmann Date: Sat, 11 Apr 2020 15:32:43 +0200 Subject: [PATCH] add feature for read-only devs (prefixed with @) --- helper.go | 3 +++ main.go | 10 +++++++++- metrics.go | 2 ++ snippets/scales.html | 2 +- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/helper.go b/helper.go index e21f3ed..0171a3e 100644 --- a/helper.go +++ b/helper.go @@ -12,6 +12,9 @@ func Contains(a []string, x string) bool { if x == n { return true } + if "@" + x == n { + return true + } } return false } diff --git a/main.go b/main.go index 01e7bd8..e602a02 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( "os" "path" "time" + "strings" ) func serveTemplate(w http.ResponseWriter, r *http.Request) { @@ -47,7 +48,14 @@ func serveTemplate(w http.ResponseWriter, r *http.Request) { if r.URL.Path == "/scales.html" { // wir holen noch die letzten Metriken for _, v := range scales { - last_metric := getLastMetrics(v) + deveui := v + readonly := false + if strings.HasPrefix(deveui, "@") { + deveui = deveui[1:] + readonly = true + } + last_metric := getLastMetrics(deveui) + last_metric.Readonly = readonly last_metrics = append(last_metrics, last_metric) } } diff --git a/metrics.go b/metrics.go index bade870..9c5f2ed 100644 --- a/metrics.go +++ b/metrics.go @@ -15,6 +15,7 @@ import ( type OneMetric struct { Deveui string Alias string + Readonly bool Alarmactive string Smsnumber string Timestamp string @@ -346,6 +347,7 @@ func getLastMetrics(deveui string) OneMetric { } res.Deveui = deveui res.Alias = getDevAlias(deveui) + res.Readonly = false res.Alarmactive = getDevAlarmactive(deveui) res.Smsnumber = getDevSmsnumber(deveui) res.ActiveUntil = getActiveUntil(deveui) diff --git a/snippets/scales.html b/snippets/scales.html index c766411..d155225 100644 --- a/snippets/scales.html +++ b/snippets/scales.html @@ -106,7 +106,7 @@ Sie erhalten eine E-Mail, sobald die Zahlung erfolgreich abgeschlossen ist. {{range .LastMetrics}}
-

{{.Alias}}

+

{{.Alias}}{{ if not .Readonly }}{{ end }}

letzte übermittelte Messung: {{.Timestamp}}