Basic disk page implementation

+ Basic information about the disk
This commit is contained in:
Daniel Legt 2024-01-22 23:12:15 +02:00
parent f17d8b44a3
commit 145362b7ef
2 changed files with 35 additions and 36 deletions

View File

@ -15,6 +15,21 @@ func setupFrontend(r *gin.Engine) {
r.LoadHTMLGlob("templates/*") r.LoadHTMLGlob("templates/*")
r.Static("/static", "./static") 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 // Set up a route for the root URL
r.GET("/", func(ctx *gin.Context) { r.GET("/", func(ctx *gin.Context) {
hardDrives, err := hardware.GetSystemHardDrives(svc.GetDatabaseRef(), nil, nil) hardDrives, err := hardware.GetSystemHardDrives(svc.GetDatabaseRef(), nil, nil)

View File

@ -12,13 +12,12 @@
<div class="container-titlebar"> <div class="container-titlebar">
<div class="pad"> <div class="pad">
<h4>Available Disks</h4> <h4>{{ .hdd.Model }} <span class="grooved">{{ .hdd.Size }}</span></h4>
</div> </div>
</div> </div>
<div class="container-body"> <div class="container-body">
<div class="pad"> <div class="pad">
{{ if len .drives }}
<table id="disks-table"> <table id="disks-table">
<thead> <thead>
<tr> <tr>
@ -30,29 +29,14 @@
</tr> </tr>
</thead> </thead>
<tbody id="disk-table-body"> <tbody id="disk-table-body">
{{ range .drives }}
{{ $temp := .GetTemperature }}
<tr> <tr>
<td>#{{ .ID }}</td> <td>#{{ .hdd.ID }}</td>
<td> {{ .Name }}</td> <td> {{ .hdd.Name }}</td>
<td> {{ .Model }}</td> <td> {{ .hdd.Model }}</td>
<td> {{ .Serial }}</td> <td> {{ .hdd.Serial }}</td>
{{ if gt $temp 50 }} <!-- Temperature greater than 50°C -->
<td style="color: red;">{{ $temp }}&deg;C</td>
{{ else if gt $temp 30 }} <!-- Temperature between 31°C and 50°C -->
<td style="color: orange;">{{ $temp }}&deg;C</td>
{{ else }} <!-- Temperature 30°C or below -->
<td style="color: lime;">{{ $temp }}&deg;C</td>
{{ end }}
</tr> </tr>
{{ end }}
</tbody> </tbody>
</table> </table>
{{ else }}
<p>No hard drives found.</p>
{{ end }}
</div> </div>
</div> </div>