From 5ba9b1faf7c5d353aeeaa8420f8f9ea6416e3db3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Sat, 12 Sep 2020 16:19:52 +0200 Subject: [PATCH] Adjust index for log (#5) * Adjust index for log * Strip ascii with regex * Style * format --- http.go | 10 ++++++++-- main.go | 1 - rootfs/usr/share/www/index.html | 7 ++++--- rootfs/usr/share/www/observer.css | 4 ++++ rootfs/usr/share/www/observer.js | 15 --------------- 5 files changed, 16 insertions(+), 21 deletions(-) delete mode 100644 rootfs/usr/share/www/observer.js diff --git a/http.go b/http.go index c7779a8..c6cf4a8 100644 --- a/http.go +++ b/http.go @@ -6,6 +6,7 @@ import ( "log" "net" "net/http" + "regexp" "strings" ) @@ -84,10 +85,15 @@ func statusIndex(w http.ResponseWriter, r *http.Request) { // Set logs if !data.On { var buf bytes.Buffer + var re = regexp.MustCompile(`\[\d+m`) logWriter := bufio.NewWriter(&buf) - supervisorLogs(logWriter) - data.Logs = buf.String() + err := supervisorLogs(logWriter) + if err != nil { + data.Logs = err.Error() + } else { + data.Logs = re.ReplaceAllLiteralString(buf.String(), "") + } } // Render Website diff --git a/main.go b/main.go index c222eb7..eb10ab6 100644 --- a/main.go +++ b/main.go @@ -45,7 +45,6 @@ func main() { // Serve static help files staticFiles := http.FileServer(http.Dir(wwwRoot)) http.Handle("/observer.css", staticFiles) - http.Handle("/observer.js", staticFiles) log.Print("Start webserver on http://0.0.0.0:80") http.ListenAndServe(":80", nil) diff --git a/rootfs/usr/share/www/index.html b/rootfs/usr/share/www/index.html index 36eb65d..7a56863 100644 --- a/rootfs/usr/share/www/index.html +++ b/rootfs/usr/share/www/index.html @@ -5,18 +5,19 @@ Home Assistant observer -

Home Assistant observer

Supervisor: - + {{if .On}}Connected{{else}}Disconnected{{end}}
-
{{.Logs}}
+ {{ if not .On }} +
{{.Logs}}
+ {{ end }}
diff --git a/rootfs/usr/share/www/observer.css b/rootfs/usr/share/www/observer.css index 09a4098..e753b29 100644 --- a/rootfs/usr/share/www/observer.css +++ b/rootfs/usr/share/www/observer.css @@ -41,7 +41,11 @@ h1 { white-space: pre-wrap; overflow-wrap: break-word; font-size: 12px; + line-height: 18px; font-family: monospace; + padding: 4px; + border-radius: 8px; + background-color: #fafafa; } @media only screen and (max-width: 600px) { diff --git a/rootfs/usr/share/www/observer.js b/rootfs/usr/share/www/observer.js deleted file mode 100644 index 371fb2d..0000000 --- a/rootfs/usr/share/www/observer.js +++ /dev/null @@ -1,15 +0,0 @@ -async function updateLog() { - const logElement = document.querySelector("#log") - const connectionElement = document.querySelector("#connection") - - if (connectionElement.innerText == "Disconnected" && logElement.innerText == "") { - logElement.innerText = "Loading Supervisor logs..." - - const logEntries = await fetch("/logs") - logElement.innerText = await logEntries.text() - } -} - -window.addEventListener('DOMContentLoaded', () => { - updateLog() -}); \ No newline at end of file