From 71d4eb6cc38bc88086bd70f7608368dda50714be Mon Sep 17 00:00:00 2001 From: Daniel Legt Date: Sat, 20 Jan 2024 01:40:55 +0200 Subject: [PATCH] Api and Frontend + Snapshot get API + Frontend Starting --- lib/web/api.go | 7 +++++++ lib/web/frontend.go | 26 ++++++++++++++++++++++++- static/style.css | 45 ++++++++++++++++++++++++++++++++++++++++++++ templates/index.html | 35 +++++++++++++++++++++++++++++++--- 4 files changed, 109 insertions(+), 4 deletions(-) create mode 100644 static/style.css diff --git a/lib/web/api.go b/lib/web/api.go index 9cbd63a..3cf1c18 100644 --- a/lib/web/api.go +++ b/lib/web/api.go @@ -6,6 +6,7 @@ import ( "github.com/gin-gonic/gin" "tea.chunkbyte.com/kato/drive-health/lib/hardware" + "tea.chunkbyte.com/kato/drive-health/lib/svc" ) func setupApi(r *gin.Engine) { @@ -31,4 +32,10 @@ func setupApi(r *gin.Engine) { }) }) + api.GET("/snapshots", func(ctx *gin.Context) { + snapshots := svc.GetHardwareSnapshot() + + ctx.JSON(http.StatusOK, snapshots) + }) + } diff --git a/lib/web/frontend.go b/lib/web/frontend.go index ef4980f..a6e9d47 100644 --- a/lib/web/frontend.go +++ b/lib/web/frontend.go @@ -1,7 +1,31 @@ package web -import "github.com/gin-gonic/gin" +import ( + "net/http" + + "github.com/gin-gonic/gin" + "tea.chunkbyte.com/kato/drive-health/lib/hardware" +) func setupFrontend(r *gin.Engine) { + r.LoadHTMLGlob("templates/*") + r.Static("/static", "./static") + // Set up a route for the root URL + r.GET("/", func(c *gin.Context) { + + hardDrives, err := hardware.GetSystemHardDrives() + if err != nil { + c.AbortWithStatus(500) + } + + for _, hdd := range hardDrives { + hdd.GetTemperature(true) + } + + // Render the HTML template + c.HTML(http.StatusOK, "index.html", gin.H{ + "drives": hardDrives, + }) + }) } diff --git a/static/style.css b/static/style.css new file mode 100644 index 0000000..7381c57 --- /dev/null +++ b/static/style.css @@ -0,0 +1,45 @@ +body { + font-family: Arial, sans-serif; + background-color: #333; + color: #fff; + margin: 0; + padding: 0; +} + +.container { + width: 80%; + margin: auto; + overflow: hidden; +} + +h1 { + text-align: center; + padding: 20px 0; +} + +table { + width: 100%; + margin-top: 20px; + border-collapse: collapse; +} + +table, th, td { + border: 1px solid #ddd; +} + +th, td { + text-align: left; + padding: 8px; +} + +th { + background-color: #555; +} + +tr:nth-child(even) { + background-color: #666; +} + +tr:hover { + background-color: #555; +} \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index 3439e3b..d2430d8 100644 --- a/templates/index.html +++ b/templates/index.html @@ -3,9 +3,38 @@ - Drive Health + + Drive Health Dashboard - +
+

Drive Health Dashboard

+ + + + + + + + + + + + + + {{range .drives}} + + + + + + + + + + {{end}} + +
NameTransportSizeModelSerialTypeTemperature
{{.Name}}{{.Transport}}{{.Size}}{{.Model}}{{.Serial}}{{.Type}}{{.Temperature}}
+
- \ No newline at end of file +