From 409274759f94b24d3cb10fd2626c3a055a78d9c7 Mon Sep 17 00:00:00 2001 From: aceberg <1502200+aceberg@users.noreply.github.com> Date: Fri, 23 Aug 2024 13:59:32 +0700 Subject: [PATCH] Host page --- internal/web/api.go | 11 ++++++++- internal/web/{helpers.go => functions.go} | 0 internal/web/host.go | 23 +++++++++++++++++++ internal/web/public/js/filter.js | 5 ++++ internal/web/public/js/index.js | 2 +- internal/web/public/js/sort.js | 28 ++++++++++++++++++----- internal/web/templates/host.html | 28 +++++++++++++++++++++++ internal/web/templates/index.html | 1 + internal/web/webgui.go | 2 ++ 9 files changed, 92 insertions(+), 8 deletions(-) rename internal/web/{helpers.go => functions.go} (100%) create mode 100644 internal/web/host.go create mode 100644 internal/web/templates/host.html diff --git a/internal/web/api.go b/internal/web/api.go index 623ea7e..a4ef539 100644 --- a/internal/web/api.go +++ b/internal/web/api.go @@ -22,6 +22,15 @@ func apiHistory(c *gin.Context) { c.IndentedJSON(http.StatusOK, histHosts) } +func apiHost(c *gin.Context) { + + idStr := c.Param("id") + id, _ := strconv.Atoi(idStr) + host := getHostByID(id, allHosts) // functions.go + + c.IndentedJSON(http.StatusOK, host) +} + func apiEdit(c *gin.Context) { idStr := c.Param("id") @@ -30,7 +39,7 @@ func apiEdit(c *gin.Context) { id, _ := strconv.Atoi(idStr) - host := getHostByID(id, allHosts) + host := getHostByID(id, allHosts) // functions.go if host.Date != "" { host.Name = name diff --git a/internal/web/helpers.go b/internal/web/functions.go similarity index 100% rename from internal/web/helpers.go rename to internal/web/functions.go diff --git a/internal/web/host.go b/internal/web/host.go new file mode 100644 index 0000000..95b8b43 --- /dev/null +++ b/internal/web/host.go @@ -0,0 +1,23 @@ +package web + +import ( + "log" + "net/http" + + "github.com/gin-gonic/gin" + + "github.com/aceberg/WatchYourLAN/internal/models" +) + +func hostHandler(c *gin.Context) { + var guiData models.GuiData + guiData.Config = appConfig + + idStr := c.Param("id") + log.Println("ID =", idStr) + + guiData.Version = idStr + + c.HTML(http.StatusOK, "header.html", guiData) + c.HTML(http.StatusOK, "host.html", guiData) +} diff --git a/internal/web/public/js/filter.js b/internal/web/public/js/filter.js index 6760111..f29aa7e 100644 --- a/internal/web/public/js/filter.js +++ b/internal/web/public/js/filter.js @@ -23,5 +23,10 @@ function filterFunc(field, value) { oldFilter = field; + displayArrayData(addrsArray); +} + +function resetFilter() { + addrsArray = bkpArray; displayArrayData(addrsArray); } \ No newline at end of file diff --git a/internal/web/public/js/index.js b/internal/web/public/js/index.js index 196a741..d48c548 100644 --- a/internal/web/public/js/index.js +++ b/internal/web/public/js/index.js @@ -28,7 +28,7 @@ function createHTML(addr, i) {