From 9b13628980d48e5efd0cc582c80a4a3e94a59a25 Mon Sep 17 00:00:00 2001 From: JP Appel Date: Tue, 8 Oct 2024 15:22:58 -0400 Subject: Remove dashboard rendering The dashboard html falls out of the responsibility of the backend. The static site provides the html. --- dashboard/dashboard.go | 54 -------------------------------- nonsense-time.go | 3 -- templates/base.html | 12 ------- templates/dashboard/dashboard.html | 9 ------ templates/dashboard/server_controls.html | 7 ----- templates/dashboard/server_logs.html | 10 ------ templates/dashboard/server_status.html | 15 --------- 7 files changed, 110 deletions(-) delete mode 100644 dashboard/dashboard.go delete mode 100644 templates/base.html delete mode 100644 templates/dashboard/dashboard.html delete mode 100644 templates/dashboard/server_controls.html delete mode 100644 templates/dashboard/server_logs.html delete mode 100644 templates/dashboard/server_status.html diff --git a/dashboard/dashboard.go b/dashboard/dashboard.go deleted file mode 100644 index 8daf375..0000000 --- a/dashboard/dashboard.go +++ /dev/null @@ -1,54 +0,0 @@ -package dashboard - -import ( - "html/template" - "log/slog" - "net/http" - "nonsense-time/api" - "path/filepath" -) - -var Logger *slog.Logger -var templates map[string]*template.Template - -func getStatuses() { - -} - -func Index(w http.ResponseWriter, req *http.Request) { - t, ok := templates["dashboard"] - - if !ok { - panic(t) - } - - // TODO: poll database - data := struct { - ServerStatus api.ServerStatus - }{ - ServerStatus: api.ServerStatus{}, - } - - err := t.Execute(w, data) - if err != nil { - Logger.Error("Unable to execute template", slog.Any("err", err)) - http.Error(w, "Internal Server Error", http.StatusInternalServerError) - return - } -} - -func StaticHandler(w http.ResponseWriter, req *http.Request) { - http.StripPrefix("/static", http.FileServer(http.Dir("static"))).ServeHTTP(w, req) -} - -func init() { - Logger = slog.Default() - templates = make(map[string]*template.Template) - templates["dashboard"] = template.Must(template.New("base.html").ParseFiles( - filepath.Join("templates", "base.html"), - filepath.Join("templates", "dashboard", "dashboard.html"), - filepath.Join("templates", "dashboard", "server_status.html"), - filepath.Join("templates", "dashboard", "server_controls.html"), - filepath.Join("templates", "dashboard", "server_logs.html"), - )) -} diff --git a/nonsense-time.go b/nonsense-time.go index 2a8debc..e57e048 100644 --- a/nonsense-time.go +++ b/nonsense-time.go @@ -7,7 +7,6 @@ import ( "log/slog" "net/http" "nonsense-time/api" - "nonsense-time/dashboard" "os" "time" ) @@ -60,13 +59,11 @@ func main() { logger = slog.New(slog.NewTextHandler(os.Stdout, loggerOpts)) api.Logger = logger - dashboard.Logger = logger vtt := timeoutMiddleware(http.HandlerFunc(api.VttOnline), *waitTime) mux.Handle("GET /vtt/status", vtt) mux.HandleFunc("GET /vtt", api.VttRedirect) - mux.HandleFunc("GET /", dashboard.Index) mux.HandleFunc("GET /vtt/logs", api.VttLogs) logger.Info(fmt.Sprint("Listening on ", addr)) diff --git a/templates/base.html b/templates/base.html deleted file mode 100644 index 768d7eb..0000000 --- a/templates/base.html +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - {{ block "head" . }}Nonsense Time Dashboard{{ end }} - - - - {{ block "body" . }}{{ end }} - - diff --git a/templates/dashboard/dashboard.html b/templates/dashboard/dashboard.html deleted file mode 100644 index b0f7eb3..0000000 --- a/templates/dashboard/dashboard.html +++ /dev/null @@ -1,9 +0,0 @@ -{{ define "body" }} -

Dashboard Home

-

Welcome to the Dashboard! It is still under construction so please be patient :)

-
- {{template "server_status" . }} - {{template "server_controls" . }} - {{template "server_logs" . }} -
-{{ end }} diff --git a/templates/dashboard/server_controls.html b/templates/dashboard/server_controls.html deleted file mode 100644 index eba93e8..0000000 --- a/templates/dashboard/server_controls.html +++ /dev/null @@ -1,7 +0,0 @@ -{{ define "server_controls" }} -
-

Server Controls

- - -
-{{ end }} diff --git a/templates/dashboard/server_logs.html b/templates/dashboard/server_logs.html deleted file mode 100644 index f1977ac..0000000 --- a/templates/dashboard/server_logs.html +++ /dev/null @@ -1,10 +0,0 @@ -{{ define "server_logs" }} -
-

Server Logs

-
- - - -
-
-{{ end }} diff --git a/templates/dashboard/server_status.html b/templates/dashboard/server_status.html deleted file mode 100644 index d118714..0000000 --- a/templates/dashboard/server_status.html +++ /dev/null @@ -1,15 +0,0 @@ -{{define "server_status"}} -
-

Server Status

-
-
-
Url
-
{{ .ServerStatus.Site }}
-
Online
-
{{ .ServerStatus.Online }}
-
Timestamp
-
{{ .ServerStatus.Timestamp }}
-
-
-
-{{end}} -- cgit v1.2.3