rename instance to config,

simplify resource-chart code
This commit is contained in:
2025-04-02 20:39:38 +00:00
parent add58d849e
commit bd0387976f
12 changed files with 14 additions and 18 deletions

View File

@@ -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)

View File

@@ -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
}

View File

@@ -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")

View File

@@ -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)

View File

@@ -2,7 +2,7 @@
<html lang="en">
<head>
{{template "head" .}}
<script src="scripts/instance.js" type="module"></script>
<script src="scripts/config.js" type="module"></script>
<script src="scripts/draggable.js" type="module"></script>
<script src="modules/Sortable.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sortablejs@latest/Sortable.min.js"></script>

View File

@@ -56,7 +56,7 @@
</div>
<div id="instance-container">
{{range .instances}}
{{template "instance" .}}
{{template "instance-card" .}}
{{end}}
</div>
</div>

3
web/html/instances.frag Normal file
View File

@@ -0,0 +1,3 @@
{{range .instances}}
{{template "instance-card" .}}
{{end}}

View File

@@ -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 });
}
}

View File

@@ -1,4 +1,4 @@
{{define "instance"}}
{{define "instance-card"}}
<instance-card data-type="{{.Type}}" data-status="{{.Status}}" data-vmid="{{.VMID}}" data-name="{{.Name}}" data-node="{{.Node}}" data-nodestatus="{{.NodeStatus}}">
<template shadowrootmode="open">
<link rel="stylesheet" href="modules/w3.css">

View File

@@ -1,3 +0,0 @@
{{range .instances}}
{{template "instance" .}}
{{end}}

View File

@@ -35,11 +35,7 @@
<progress value="{{.Used}}" max="{{.Max}}"></progress>
<p id="caption">
<span>{{.Name}}</span>
{{if eq .Type "list"}}
<span>{{.Avail}} {{.Prefix}}{{.Unit}} Avaliable</span>
{{else}}
<span>{{printf "%.2f" .Avail}} {{.Prefix}}{{.Unit}} Avaliable</span>
{{end}}
<span>{{printf "%g" .Avail}} {{.Prefix}}{{.Unit}} Avaliable</span>
</p>
</div>
</template>