From bd0387976fffa3769ddda800a44771c96b9d53ab Mon Sep 17 00:00:00 2001 From: Arthur Lu Date: Wed, 2 Apr 2025 20:39:38 +0000 Subject: [PATCH] rename instance to config, simplify resource-chart code --- app/app.go | 2 +- app/common/utils.go | 2 +- app/routes/{instance.go => config.go} | 6 +++--- app/routes/index.go | 2 +- web/html/{instance.html => config.html} | 2 +- web/html/index.html | 2 +- web/html/instances.frag | 3 +++ web/scripts/{instance.js => config.js} | 0 web/scripts/index.js | 2 +- web/templates/{instance.tmpl => instance-card.tmpl} | 2 +- web/templates/instances.frag | 3 --- web/templates/resource-chart.tmpl | 6 +----- 12 files changed, 14 insertions(+), 18 deletions(-) rename app/routes/{instance.go => config.go} (67%) rename web/html/{instance.html => config.html} (96%) create mode 100644 web/html/instances.frag rename web/scripts/{instance.js => config.js} (100%) rename web/templates/{instance.tmpl => instance-card.tmpl} (97%) delete mode 100644 web/templates/instances.frag diff --git a/app/app.go b/app/app.go index 732f314..26bc5c9 100644 --- a/app/app.go +++ b/app/app.go @@ -29,7 +29,7 @@ func Run() { router.GET("/account.html", routes.HandleGETAccount) router.GET("/", routes.HandleGETIndex) router.GET("/index.html", routes.HandleGETIndex) - router.GET("/instance.html", routes.HandleGETInstance) + router.GET("/config.html", routes.HandleGETConfig) router.GET("/login.html", routes.HandleGETLogin) router.GET("/settings.html", routes.HandleGETSettings) diff --git a/app/common/utils.go b/app/common/utils.go index ae4a0e9..f5eaf76 100644 --- a/app/common/utils.go +++ b/app/common/utils.go @@ -185,7 +185,7 @@ func GetAuth(c *gin.Context) (string, string, string, error) { token, errToken := c.Cookie("PVEAuthCookie") csrf, errCSRF := c.Cookie("CSRFPreventionToken") if errUsername != nil || errAuth != nil || errToken != nil || errCSRF != nil { - return "", "", "", fmt.Errorf("auth: %s, token: %s, csrf: %s", errAuth, errToken, errCSRF) + return "", "", "", fmt.Errorf("error occured getting user cookies: (auth: %s, token: %s, csrf: %s)", errAuth, errToken, errCSRF) } else { return username, token, csrf, nil } diff --git a/app/routes/instance.go b/app/routes/config.go similarity index 67% rename from app/routes/instance.go rename to app/routes/config.go index 401f09c..899f152 100644 --- a/app/routes/instance.go +++ b/app/routes/config.go @@ -7,12 +7,12 @@ import ( "github.com/gin-gonic/gin" ) -func HandleGETInstance(c *gin.Context) { +func HandleGETConfig(c *gin.Context) { _, _, _, err := common.GetAuth(c) if err == nil { - c.HTML(http.StatusOK, "html/instance.html", gin.H{ + c.HTML(http.StatusOK, "html/config.html", gin.H{ "global": common.Global, - "page": "instance", + "page": "config", }) } else { c.Redirect(http.StatusFound, "/login.html") diff --git a/app/routes/index.go b/app/routes/index.go index f644232..c58e3cf 100644 --- a/app/routes/index.go +++ b/app/routes/index.go @@ -115,7 +115,7 @@ func HandleGETInstancesFragment(c *gin.Context) { common.HandleNonFatalError(c, err) } c.Header("Content-Type", "text/plain") - common.TMPL.ExecuteTemplate(c.Writer, "templates/instances.frag", gin.H{ + common.TMPL.ExecuteTemplate(c.Writer, "html/instances.frag", gin.H{ "instances": instances, }) c.Status(http.StatusOK) diff --git a/web/html/instance.html b/web/html/config.html similarity index 96% rename from web/html/instance.html rename to web/html/config.html index c688309..dfad024 100644 --- a/web/html/instance.html +++ b/web/html/config.html @@ -2,7 +2,7 @@ {{template "head" .}} - + diff --git a/web/html/index.html b/web/html/index.html index 1ee8113..48698f4 100644 --- a/web/html/index.html +++ b/web/html/index.html @@ -56,7 +56,7 @@
{{range .instances}} - {{template "instance" .}} + {{template "instance-card" .}} {{end}}
diff --git a/web/html/instances.frag b/web/html/instances.frag new file mode 100644 index 0000000..63f4cd8 --- /dev/null +++ b/web/html/instances.frag @@ -0,0 +1,3 @@ +{{range .instances}} + {{template "instance-card" .}} +{{end}} \ No newline at end of file diff --git a/web/scripts/instance.js b/web/scripts/config.js similarity index 100% rename from web/scripts/instance.js rename to web/scripts/config.js diff --git a/web/scripts/index.js b/web/scripts/index.js index eda9e84..3cf2f6d 100644 --- a/web/scripts/index.js +++ b/web/scripts/index.js @@ -179,7 +179,7 @@ class InstanceCard extends HTMLElement { handleConfigButton () { if (!this.actionLock && this.status === "stopped") { // if the action lock is false, and the node is stopped, then navigate to the config page with the node info in the search query - goToPage("instance.html", { node: this.node.name, type: this.type, vmid: this.vmid }); + goToPage("config.html", { node: this.node.name, type: this.type, vmid: this.vmid }); } } diff --git a/web/templates/instance.tmpl b/web/templates/instance-card.tmpl similarity index 97% rename from web/templates/instance.tmpl rename to web/templates/instance-card.tmpl index db4c437..76d558e 100644 --- a/web/templates/instance.tmpl +++ b/web/templates/instance-card.tmpl @@ -1,4 +1,4 @@ -{{define "instance"}} +{{define "instance-card"}}