Date filtering

+ Date filtering
+ Input styling
* Visual changes
+ Updated api calls
This commit is contained in:
2024-01-21 22:40:32 +02:00
parent 2776ad8e52
commit c8fa24f11c
6 changed files with 210 additions and 10 deletions

View File

@@ -79,7 +79,7 @@ func GetDiskGraphImage(hddID int, newerThan *time.Time, olderThan *time.Time) (*
// Fetch by a combination of fields
q := db.Where("id = ?", hddID)
if newerThan == nil && olderThan == nil {
if newerThan == nil || olderThan == nil {
q = q.Preload("Temperatures")
} else {
q = q.Preload("Temperatures", "time_stamp < ? AND time_stamp > ?", newerThan, olderThan)

View File

@@ -1,6 +1,7 @@
package web
import (
"fmt"
"net/http"
"strconv"
"time"
@@ -26,7 +27,28 @@ func setupApi(r *gin.Engine) {
return
}
graphData, err := svc.GetDiskGraphImage(diskId, nil, nil)
var olderThan, newerThan *time.Time
if ot := ctx.Query("older"); ot != "" {
fmt.Printf("ot = %s\n", ot)
if otInt, err := strconv.ParseInt(ot, 10, 64); err == nil {
otTime := time.UnixMilli(otInt)
olderThan = &otTime
}
}
if nt := ctx.Query("newer"); nt != "" {
fmt.Printf("nt = %s\n", nt)
if ntInt, err := strconv.ParseInt(nt, 10, 64); err == nil {
ntTime := time.UnixMilli(ntInt)
newerThan = &ntTime
}
}
fmt.Printf("olderThan = %s\n", olderThan)
fmt.Printf("newerThan = %s\n", newerThan)
graphData, err := svc.GetDiskGraphImage(diskId, newerThan, olderThan)
if err != nil {
ctx.AbortWithStatusJSON(500, gin.H{
"error": err.Error(),

View File

@@ -1,7 +1,9 @@
package web
import (
"fmt"
"net/http"
"strconv"
"time"
"github.com/gin-gonic/gin"
@@ -14,22 +16,51 @@ func setupFrontend(r *gin.Engine) {
r.Static("/static", "./static")
// Set up a route for the root URL
r.GET("/", func(c *gin.Context) {
olderThan := time.Now().Add(time.Minute * time.Duration(10) * -1)
newerThan := time.Now()
hardDrives, err := hardware.GetSystemHardDrives(svc.GetDatabaseRef(), &olderThan, &newerThan)
r.GET("/", func(ctx *gin.Context) {
hardDrives, err := hardware.GetSystemHardDrives(svc.GetDatabaseRef(), nil, nil)
if err != nil {
c.AbortWithStatus(500)
ctx.AbortWithStatus(500)
}
for _, hdd := range hardDrives {
hdd.GetTemperature()
}
var olderThan, newerThan *time.Time
if ot := ctx.Query("older"); ot != "" {
fmt.Printf("ot = %s\n", ot)
if otInt, err := strconv.ParseInt(ot, 10, 64); err == nil {
otTime := time.UnixMilli(otInt)
olderThan = &otTime
}
}
if nt := ctx.Query("newer"); nt != "" {
fmt.Printf("nt = %s\n", nt)
if ntInt, err := strconv.ParseInt(nt, 10, 64); err == nil {
ntTime := time.UnixMilli(ntInt)
newerThan = &ntTime
}
}
if olderThan == nil {
genTime := time.Now().Add(time.Hour * -1)
olderThan = &genTime
}
if newerThan == nil {
genTime := time.Now()
newerThan = &genTime
}
// Render the HTML template
c.HTML(http.StatusOK, "index.html", gin.H{
ctx.HTML(http.StatusOK, "index.html", gin.H{
"drives": hardDrives,
"older": olderThan.UnixMilli(),
"newer": newerThan.UnixMilli(),
})
})
}