aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJP Appel <jeanpierre.appel01@gmail.com>2024-10-08 15:22:58 -0400
committerJP Appel <jeanpierre.appel01@gmail.com>2024-10-08 15:52:07 -0400
commit9b13628980d48e5efd0cc582c80a4a3e94a59a25 (patch)
treece61517801f7a4510d02ee8fa6cf830d41e452c3
parent3f5e6e9c3ebb396949b091ee43b76d3303401fd3 (diff)
Remove dashboard rendering
The dashboard html falls out of the responsibility of the backend. The static site provides the html.
-rw-r--r--dashboard/dashboard.go54
-rw-r--r--nonsense-time.go3
-rw-r--r--templates/base.html12
-rw-r--r--templates/dashboard/dashboard.html9
-rw-r--r--templates/dashboard/server_controls.html7
-rw-r--r--templates/dashboard/server_logs.html10
-rw-r--r--templates/dashboard/server_status.html15
7 files changed, 0 insertions, 110 deletions
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 @@
-<!DOCTYPE html>
-<html lang=en>
-<head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- {{ block "head" . }}<title>Nonsense Time Dashboard</title>{{ end }}
- <link rel="stylesheet" href="/static/styles.css">
-</head>
-<body>
- {{ block "body" . }}{{ end }}
-</body>
-</html>
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" }}
-<h1>Dashboard Home</h1>
-<p>Welcome to the Dashboard! It is still under construction so please be patient :) </p>
-<main>
- {{template "server_status" . }}
- {{template "server_controls" . }}
- {{template "server_logs" . }}
-</main>
-{{ 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" }}
-<section class="dashboard-item server-controls">
- <h2>Server Controls</h2>
- <button>Start</button>
- <button>Stop</button>
-</section>
-{{ 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" }}
-<section class="dashboard-item server-logs">
- <h2>Server Logs</h2>
- <div class="logs-viewer">
- <label for="logs-viewer-area">Foundry Logs</label>
- <textarea id="logs-viewer-area" name="logs-viewer-area" readonly="true" placeholder="Loading..."></textarea>
- <button>Download</button>
- </div>
-</section>
-{{ 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"}}
-<section class="dashboard-item server-status">
- <h2>Server Status</h2>
- <div id=uptime>
- <dl>
- <dt>Url</dt>
- <dd>{{ .ServerStatus.Site }}</dd>
- <dt>Online</dt>
- <dd>{{ .ServerStatus.Online }}</dd>
- <dt>Timestamp</dt>
- <dd>{{ .ServerStatus.Timestamp }}</dd>
- </dl>
- </div>
-</section>
-{{end}}