From 145362b7ef36c05c4200bb647795f88ef16d27c7 Mon Sep 17 00:00:00 2001 From: Daniel Legt Date: Mon, 22 Jan 2024 23:12:15 +0200 Subject: [PATCH] Basic disk page implementation + Basic information about the disk --- lib/web/frontend.go | 15 ++++++++++++ templates/drive.html | 56 ++++++++++++++++---------------------------- 2 files changed, 35 insertions(+), 36 deletions(-) diff --git a/lib/web/frontend.go b/lib/web/frontend.go index f0f65cf..6bf7b1c 100644 --- a/lib/web/frontend.go +++ b/lib/web/frontend.go @@ -15,6 +15,21 @@ func setupFrontend(r *gin.Engine) { r.LoadHTMLGlob("templates/*") r.Static("/static", "./static") + r.GET("/disk/:id", func(ctx *gin.Context) { + id := ctx.Param("id") + var hdd hardware.HardDrive + tx := svc.GetDatabaseRef().Where("id = ?", id).Preload("Temperatures").First(&hdd) + if tx.Error != nil { + ctx.AbortWithError(500, tx.Error) + return + } + + // Render the HTML template + ctx.HTML(http.StatusOK, "drive.html", gin.H{ + "hdd": hdd, + }) + }) + // Set up a route for the root URL r.GET("/", func(ctx *gin.Context) { hardDrives, err := hardware.GetSystemHardDrives(svc.GetDatabaseRef(), nil, nil) diff --git a/templates/drive.html b/templates/drive.html index 5eb6b28..8ae4c24 100644 --- a/templates/drive.html +++ b/templates/drive.html @@ -12,47 +12,31 @@
-

Available Disks

+

{{ .hdd.Model }} {{ .hdd.Size }}

- {{ if len .drives }} - - - - - - - - - - - - {{ range .drives }} - {{ $temp := .GetTemperature }} - - - - - - - - {{ if gt $temp 50 }} - - {{ else if gt $temp 30 }} - - {{ else }} - - {{ end }} - - {{ end }} - -
IDNameModelSerialTemperature
#{{ .ID }} {{ .Name }} {{ .Model }} {{ .Serial }}{{ $temp }}°C{{ $temp }}°C{{ $temp }}°C
- {{ else }} -

No hard drives found.

- {{ end }} + + + + + + + + + + + + + + + + + + +
IDNameModelSerialTemperature
#{{ .hdd.ID }} {{ .hdd.Name }} {{ .hdd.Model }} {{ .hdd.Serial }}