goipam/web/ui/subnetDetails.go

95 lines
1.9 KiB
Go

package ui
import (
"fmt"
"net/http"
"strconv"
"github.com/gin-gonic/gin"
"git.jmbit.de/jmb/goipam/db"
"git.jmbit.de/jmb/goipam/web/templates"
"git.jmbit.de/jmb/goipam/web/templates/components"
)
func getSubnetDetails(c *gin.Context) {
subnetIDint, err := strconv.Atoi(c.Param("id"))
c.Errors = append(c.Errors, &gin.Error{Err: err, Type: gin.ErrorTypeAny})
subnetID := uint(subnetIDint)
subnet := db.SubnetByID(subnetID)
c.HTML(
http.StatusOK,
"",
templates.SubnetDetails(
templates.GenMetaContent(c),
fmt.Sprint("Subnet ", subnet.Name),
subnet,
),
)
}
func getSubnetDetailsField(c *gin.Context) {
subnetIDint, err := strconv.Atoi(c.Param("id"))
c.Errors = append(c.Errors, &gin.Error{Err: err, Type: gin.ErrorTypeAny})
subnetID := uint(subnetIDint)
targetBase := fmt.Sprint("/subnet/details/", subnetID)
subnet := db.SubnetByID(subnetID)
switch c.Param("field") {
case "name":
c.HTML(
200,
"",
components.EditableTextEdit(fmt.Sprint(targetBase, "/name"), "Name", subnet.Name),
)
case "displayname":
c.HTML(
200,
"",
components.EditableTextEdit(
fmt.Sprint(targetBase, "/displayname"),
"Display Name",
subnet.DisplayName,
),
)
case "vlan":
c.HTML(
200,
"",
components.EditableIntEdit(fmt.Sprint(targetBase, "/vlan"), "VLAN ID", subnet.Name),
)
case "ipv4":
c.HTML(
200,
"",
components.EditableTextEdit(
fmt.Sprint(targetBase, "/ipv4"),
"IPv4 Network Address (CIDR)",
subnet.IPv4Net,
),
)
case "ipv6":
c.HTML(
200,
"",
components.EditableTextEdit(
fmt.Sprint(targetBase, "/ipv6"),
"IPv6 Network Address (CIDR)",
subnet.IPv6Net,
),
)
case "comment":
c.HTML(
200,
"",
components.EditableTextEdit(fmt.Sprint(targetBase, "/name"), "Name", subnet.Name),
)
default:
c.Redirect(http.StatusTemporaryRedirect, targetBase)
}
}