From 8dbc6d512906cb108013d88eacf771ed22db4b1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20B=C3=BClow?= Date: Fri, 23 Feb 2024 18:39:05 +0100 Subject: [PATCH] added submit details page, started refractoring templates --- db/subnets.go | 4 +- utils/stringMagic.go | 14 + web/auth/middleware.go | 7 +- .../components/editableTextField.templ | 39 +++ .../components/editableTextField_templ.go | 116 +++++++ web/templates/components/locationPicker.templ | 6 + web/templates/formatting.templ | 13 + web/templates/formatting_templ.go | 111 +++++++ web/templates/index.templ | 4 +- web/templates/index_templ.go | 4 +- web/templates/login.templ | 4 +- web/templates/login_templ.go | 4 +- web/templates/mainComponents.templ | 6 +- web/templates/mainComponents_templ.go | 6 +- web/templates/profile.templ | 4 +- web/templates/profile_templ.go | 4 +- web/templates/structs.go | 5 + web/templates/subnetDetails.templ | 72 +++++ web/templates/subnetDetails_templ.go | 303 ++++++++++++++++++ web/templates/subnets.templ | 6 +- web/templates/subnets_templ.go | 55 ++-- web/ui/index.go | 2 +- web/ui/login.go | 7 +- web/ui/profile.go | 13 +- web/ui/routes.go | 5 + web/ui/subnetDetails.go | 94 ++++++ web/ui/subnets.go | 10 +- 27 files changed, 839 insertions(+), 79 deletions(-) create mode 100644 utils/stringMagic.go create mode 100644 web/templates/components/editableTextField.templ create mode 100644 web/templates/components/editableTextField_templ.go create mode 100644 web/templates/components/locationPicker.templ create mode 100644 web/templates/subnetDetails.templ create mode 100644 web/templates/subnetDetails_templ.go create mode 100644 web/ui/subnetDetails.go diff --git a/db/subnets.go b/db/subnets.go index b97216d..ecdc7a7 100644 --- a/db/subnets.go +++ b/db/subnets.go @@ -50,8 +50,8 @@ func SubnetsList(filter *Subnet, limit int, offset int, order string) []Subnet { return subnets } -func SubnetByID(id uint) Subnet { +func SubnetByID(id uint) *Subnet { var subnet Subnet conn.First(&subnet, id) - return subnet + return &subnet } diff --git a/utils/stringMagic.go b/utils/stringMagic.go new file mode 100644 index 0000000..d7ec5a2 --- /dev/null +++ b/utils/stringMagic.go @@ -0,0 +1,14 @@ +package utils + +import "fmt" + +// SliceToLines() turns a slice of strings into a LF separated string) +func SliceToLines(slice []string) string { + var result string + + for _, entry := range slice { + result += fmt.Sprint(entry, "\n") + } + + return result +} diff --git a/web/auth/middleware.go b/web/auth/middleware.go index a361e03..a60d2f2 100644 --- a/web/auth/middleware.go +++ b/web/auth/middleware.go @@ -6,7 +6,6 @@ import ( "github.com/gin-contrib/sessions" "github.com/gin-gonic/gin" - "git.jmbit.de/jmb/goipam/utils" "git.jmbit.de/jmb/goipam/web/templates" ) @@ -24,10 +23,10 @@ func AuthMiddleware(requiredLevel int) gin.HandlerFunc { } if accessLevelValue, ok := accessLevel.(int); ok { if accessLevelValue < requiredLevel { - metaContent := utils.GenMetaContent(c) + metaContent := templates.GenMetaContent(c) metaContent.ErrorTitle = "Not Authorized" - metaContent.ErrorText = "You are not authorized to do this Action" - c.HTML(http.StatusUnauthorized, "", templates.Login(metaContent, "Login", nil)) + metaContent.ErrorText += "\nYou are not authorized to do this Action" + c.HTML(http.StatusUnauthorized, "", templates.Login(metaContent, "Login")) c.Abort() return } diff --git a/web/templates/components/editableTextField.templ b/web/templates/components/editableTextField.templ new file mode 100644 index 0000000..3909140 --- /dev/null +++ b/web/templates/components/editableTextField.templ @@ -0,0 +1,39 @@ +package components + +import "fmt" + +//EditableFieldText() gives an Input field to write text into +templ EditableFieldText(target string, label string, content string) { +
+
+ +
+ +
+
+
+} + +//EditableFieldInt() gives an Input field to write text into +templ EditableFieldInt(target string, label string, content int) { +
+
+ +
+ +
+ save +
+
+} + +//EditableField() is a generic component to make a single field editable +templ EditableField(target string, label string, content any) { +
+ +
+ { fmt.Sprint(content) } + edit +
+
+} diff --git a/web/templates/components/editableTextField_templ.go b/web/templates/components/editableTextField_templ.go new file mode 100644 index 0000000..9f79372 --- /dev/null +++ b/web/templates/components/editableTextField_templ.go @@ -0,0 +1,116 @@ +// Code generated by templ - DO NOT EDIT. + +// templ: version: v0.2.543 +package components + +//lint:file-ignore SA4006 This context is only used if a nested component is present. + +import "github.com/a-h/templ" +import "context" +import "io" +import "bytes" + +import "fmt" + +func EditableText(target string, label string, content string) templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var1 := templ.GetChildren(ctx) + if templ_7745c5c3_Var1 == nil { + templ_7745c5c3_Var1 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var3 string + templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(content) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/components/editableTextField.templ`, Line: 7, Col: 11} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} + +func EditableTextEdit(target string, label string, content string) templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var4 := templ.GetChildren(ctx) + if templ_7745c5c3_Var4 == nil { + templ_7745c5c3_Var4 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} diff --git a/web/templates/components/locationPicker.templ b/web/templates/components/locationPicker.templ new file mode 100644 index 0000000..6545262 --- /dev/null +++ b/web/templates/components/locationPicker.templ @@ -0,0 +1,6 @@ +package components + + +templ LocationPicker() { + +} diff --git a/web/templates/formatting.templ b/web/templates/formatting.templ index 6c4fa56..e69096b 100644 --- a/web/templates/formatting.templ +++ b/web/templates/formatting.templ @@ -10,3 +10,16 @@ templ columns(columns ...templ.Component) { } } + +templ formField(label string, inputType string, name string, value string) { +
+ + +
+} + +templ formFieldStatic(label string, inputType string, name string, value string) { +
+ { value } +
+} diff --git a/web/templates/formatting_templ.go b/web/templates/formatting_templ.go index c2f38dc..922acf2 100644 --- a/web/templates/formatting_templ.go +++ b/web/templates/formatting_templ.go @@ -52,3 +52,114 @@ func columns(columns ...templ.Component) templ.Component { return templ_7745c5c3_Err }) } + +func formField(label string, inputType string, name string, value string) templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var2 := templ.GetChildren(ctx) + if templ_7745c5c3_Var2 == nil { + templ_7745c5c3_Var2 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} + +func formFieldStatic(label string, inputType string, name string, value string) templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var4 := templ.GetChildren(ctx) + if templ_7745c5c3_Var4 == nil { + templ_7745c5c3_Var4 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var6 string + templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(value) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/formatting.templ`, Line: 22, Col: 48} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} diff --git a/web/templates/index.templ b/web/templates/index.templ index 1adce32..8f44720 100644 --- a/web/templates/index.templ +++ b/web/templates/index.templ @@ -2,8 +2,8 @@ package templates import "fmt" -templ Index(metaContent MetaContent, counters IndexCounts, err error) { - @wrapBase(metaContent, "GoIPAM", err) { +templ Index(metaContent MetaContent, counters IndexCounts) { + @wrapBase(metaContent, "GoIPAM") {
@indexStats(counters) diff --git a/web/templates/index_templ.go b/web/templates/index_templ.go index 5efe405..9175d87 100644 --- a/web/templates/index_templ.go +++ b/web/templates/index_templ.go @@ -12,7 +12,7 @@ import "bytes" import "fmt" -func Index(metaContent MetaContent, counters IndexCounts, err error) templ.Component { +func Index(metaContent MetaContent, counters IndexCounts) templ.Component { return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) if !templ_7745c5c3_IsBuffer { @@ -48,7 +48,7 @@ func Index(metaContent MetaContent, counters IndexCounts, err error) templ.Compo } return templ_7745c5c3_Err }) - templ_7745c5c3_Err = wrapBase(metaContent, "GoIPAM", err).Render(templ.WithChildren(ctx, templ_7745c5c3_Var2), templ_7745c5c3_Buffer) + templ_7745c5c3_Err = wrapBase(metaContent, "GoIPAM").Render(templ.WithChildren(ctx, templ_7745c5c3_Var2), templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/web/templates/login.templ b/web/templates/login.templ index 5042078..7fcfac6 100644 --- a/web/templates/login.templ +++ b/web/templates/login.templ @@ -1,7 +1,7 @@ package templates -templ Login(metaContent MetaContent, title string, err error) { - @wrapBase(metaContent, title, err) { +templ Login(metaContent MetaContent, title string) { + @wrapBase(metaContent, title) {
diff --git a/web/templates/login_templ.go b/web/templates/login_templ.go index db2b11b..36af401 100644 --- a/web/templates/login_templ.go +++ b/web/templates/login_templ.go @@ -10,7 +10,7 @@ import "context" import "io" import "bytes" -func Login(metaContent MetaContent, title string, err error) templ.Component { +func Login(metaContent MetaContent, title string) templ.Component { return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) if !templ_7745c5c3_IsBuffer { @@ -46,7 +46,7 @@ func Login(metaContent MetaContent, title string, err error) templ.Component { } return templ_7745c5c3_Err }) - templ_7745c5c3_Err = wrapBase(metaContent, title, err).Render(templ.WithChildren(ctx, templ_7745c5c3_Var2), templ_7745c5c3_Buffer) + templ_7745c5c3_Err = wrapBase(metaContent, title).Render(templ.WithChildren(ctx, templ_7745c5c3_Var2), templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/web/templates/mainComponents.templ b/web/templates/mainComponents.templ index e71cde0..1514396 100644 --- a/web/templates/mainComponents.templ +++ b/web/templates/mainComponents.templ @@ -93,14 +93,14 @@ templ ErrorMessage(title string, content string) { } // wrapBase handles the basics of HTML -templ wrapBase(metaContent MetaContent, title string, err error) { +templ wrapBase(metaContent MetaContent, title string) { @head(title) @navbar(metaContent.IsLoggedIn) - if err != nil { - @ErrorMessage("Error", err.Error()) + if metaContent.ErrorText != "" { + @ErrorMessage(metaContent.ErrorTitle, metaContent.ErrorText) } { children... } @footer(metaContent.Timestamp) diff --git a/web/templates/mainComponents_templ.go b/web/templates/mainComponents_templ.go index 8073192..dbc7a86 100644 --- a/web/templates/mainComponents_templ.go +++ b/web/templates/mainComponents_templ.go @@ -198,7 +198,7 @@ func ErrorMessage(title string, content string) templ.Component { } // wrapBase handles the basics of HTML -func wrapBase(metaContent MetaContent, title string, err error) templ.Component { +func wrapBase(metaContent MetaContent, title string) templ.Component { return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) if !templ_7745c5c3_IsBuffer { @@ -227,8 +227,8 @@ func wrapBase(metaContent MetaContent, title string, err error) templ.Component if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - if err != nil { - templ_7745c5c3_Err = ErrorMessage("Error", err.Error()).Render(ctx, templ_7745c5c3_Buffer) + if metaContent.ErrorText != "" { + templ_7745c5c3_Err = ErrorMessage(metaContent.ErrorTitle, metaContent.ErrorText).Render(ctx, templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/web/templates/profile.templ b/web/templates/profile.templ index b762255..41f70bf 100644 --- a/web/templates/profile.templ +++ b/web/templates/profile.templ @@ -3,8 +3,8 @@ package templates import "git.jmbit.de/jmb/goipam/db" -templ ProfilePage(metaContent MetaContent, title string, user *db.User, err error) { - @wrapBase(metaContent, title, err) { +templ ProfilePage(metaContent MetaContent, title string, user *db.User) { + @wrapBase(metaContent, title) { @profileMain(user) } } diff --git a/web/templates/profile_templ.go b/web/templates/profile_templ.go index c546aec..497befc 100644 --- a/web/templates/profile_templ.go +++ b/web/templates/profile_templ.go @@ -12,7 +12,7 @@ import "bytes" import "git.jmbit.de/jmb/goipam/db" -func ProfilePage(metaContent MetaContent, title string, user *db.User, err error) templ.Component { +func ProfilePage(metaContent MetaContent, title string, user *db.User) templ.Component { return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) if !templ_7745c5c3_IsBuffer { @@ -40,7 +40,7 @@ func ProfilePage(metaContent MetaContent, title string, user *db.User, err error } return templ_7745c5c3_Err }) - templ_7745c5c3_Err = wrapBase(metaContent, title, err).Render(templ.WithChildren(ctx, templ_7745c5c3_Var2), templ_7745c5c3_Buffer) + templ_7745c5c3_Err = wrapBase(metaContent, title).Render(templ.WithChildren(ctx, templ_7745c5c3_Var2), templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/web/templates/structs.go b/web/templates/structs.go index 4128319..afb317f 100644 --- a/web/templates/structs.go +++ b/web/templates/structs.go @@ -6,6 +6,8 @@ import ( "github.com/gin-contrib/sessions" "github.com/gin-gonic/gin" + + "git.jmbit.de/jmb/goipam/utils" ) type IndexCounts struct { @@ -31,6 +33,7 @@ func GenMetaContent(c *gin.Context) MetaContent { sessionUserName := session.Get("username") sessionIsLoggedIn := session.Get("isLoggedIn") sessionIsAdmin := session.Get("isAdmin") + errorText := utils.SliceToLines(c.Errors.Errors()) var username string var isLoggedIn bool var isAdmin bool @@ -57,5 +60,7 @@ func GenMetaContent(c *gin.Context) MetaContent { IsLoggedIn: isLoggedIn, IsAdmin: isAdmin, Timestamp: fmt.Sprintf("%d", time.Now().Year()), + ErrorText: errorText, + ErrorTitle: "Error", } } diff --git a/web/templates/subnetDetails.templ b/web/templates/subnetDetails.templ new file mode 100644 index 0000000..f31691c --- /dev/null +++ b/web/templates/subnetDetails.templ @@ -0,0 +1,72 @@ + +package templates + +import "git.jmbit.de/jmb/goipam/db" +import "fmt" + +templ SubnetDetails(metaContent MetaContent, title string, subnet *db.Subnet) { + @wrapBase(metaContent, title) { + @subnetMain(subnet) + } +} + +templ subnetMain(subnet *db.Subnet) { +
+
+ @SubnetStatic(subnet) +
+
+} + +templ SubnetStatic(subnet *db.Subnet) { +
+
+ { subnet.Name } +
+
+ { subnet.DisplayName } +
+
+ { fmt.Sprint(subnet.VLAN) } +
+
+ { subnet.IPv4Net } +
+
+ { subnet.IPv6Net } +
+ +
+ { fmt.Sprint(subnet.VLAN) } +
+ +
+} + +templ SubnetForm(subnet *db.Subnet) { +
+ @formField("Name", "text", "name", subnet.Name) + @formField("Display Name", "text", "display-name", subnet.DisplayName) + @formField("VLAN", "number", "vlan", fmt.Sprint(subnet.VLAN)) + @formField("IPv4 Network Address", "text", "ipv4", subnet.IPv4Net) + @formField("IPv6 Network Address", "text", "ipv6", subnet.IPv6Net) + + @formField("Comment", "text", "comment", subnet.Comment) + + +
+} + + diff --git a/web/templates/subnetDetails_templ.go b/web/templates/subnetDetails_templ.go new file mode 100644 index 0000000..c20b048 --- /dev/null +++ b/web/templates/subnetDetails_templ.go @@ -0,0 +1,303 @@ +// Code generated by templ - DO NOT EDIT. + +// templ: version: v0.2.543 +package templates + +//lint:file-ignore SA4006 This context is only used if a nested component is present. + +import "github.com/a-h/templ" +import "context" +import "io" +import "bytes" + +import "git.jmbit.de/jmb/goipam/db" +import "fmt" + +func SubnetDetails(metaContent MetaContent, title string, subnet *db.Subnet) templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var1 := templ.GetChildren(ctx) + if templ_7745c5c3_Var1 == nil { + templ_7745c5c3_Var1 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Var2 := templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + templ_7745c5c3_Err = subnetMain(subnet).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = io.Copy(templ_7745c5c3_W, templ_7745c5c3_Buffer) + } + return templ_7745c5c3_Err + }) + templ_7745c5c3_Err = wrapBase(metaContent, title).Render(templ.WithChildren(ctx, templ_7745c5c3_Var2), templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} + +func subnetMain(subnet *db.Subnet) templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var3 := templ.GetChildren(ctx) + if templ_7745c5c3_Var3 == nil { + templ_7745c5c3_Var3 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = SubnetStatic(subnet).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} + +func SubnetStatic(subnet *db.Subnet) templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var4 := templ.GetChildren(ctx) + if templ_7745c5c3_Var4 == nil { + templ_7745c5c3_Var4 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var5 string + templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(subnet.Name) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/subnetDetails.templ`, Line: 23, Col: 57} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var6 string + templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(subnet.DisplayName) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/subnetDetails.templ`, Line: 26, Col: 65} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var7 string + templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprint(subnet.VLAN)) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/subnetDetails.templ`, Line: 29, Col: 62} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var8 string + templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(subnet.IPv4Net) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/subnetDetails.templ`, Line: 32, Col: 69} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var9 string + templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(subnet.IPv6Net) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/subnetDetails.templ`, Line: 35, Col: 69} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var12 string + templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprint(subnet.VLAN)) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/subnetDetails.templ`, Line: 44, Col: 65} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} + +func SubnetForm(subnet *db.Subnet) templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var13 := templ.GetChildren(ctx) + if templ_7745c5c3_Var13 == nil { + templ_7745c5c3_Var13 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = formField("Name", "text", "name", subnet.Name).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = formField("Display Name", "text", "display-name", subnet.DisplayName).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = formField("VLAN", "number", "vlan", fmt.Sprint(subnet.VLAN)).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = formField("IPv4 Network Address", "text", "ipv4", subnet.IPv4Net).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = formField("IPv6 Network Address", "text", "ipv6", subnet.IPv6Net).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = formField("Comment", "text", "comment", subnet.Comment).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} diff --git a/web/templates/subnets.templ b/web/templates/subnets.templ index 1920275..41a71df 100644 --- a/web/templates/subnets.templ +++ b/web/templates/subnets.templ @@ -3,8 +3,8 @@ package templates import "git.jmbit.de/jmb/goipam/db" import "fmt" -templ SubnetsPage(metaContent MetaContent, subnets []db.Subnet, err error) { - @wrapBase(metaContent, "Subnets", err) { +templ SubnetsPage(metaContent MetaContent, subnets []db.Subnet) { + @wrapBase(metaContent, "Subnets") {
@subnetsTable(subnets) @@ -20,7 +20,6 @@ templ subnetsTable(subnets []db.Subnet) { - @@ -39,7 +38,6 @@ templ subnetsTable(subnets []db.Subnet) { templ subnetsTableRows(subnets []db.Subnet) { for _, subnet := range subnets { - diff --git a/web/templates/subnets_templ.go b/web/templates/subnets_templ.go index 3cbd6ef..0b75585 100644 --- a/web/templates/subnets_templ.go +++ b/web/templates/subnets_templ.go @@ -13,7 +13,7 @@ import "bytes" import "git.jmbit.de/jmb/goipam/db" import "fmt" -func SubnetsPage(metaContent MetaContent, subnets []db.Subnet, err error) templ.Component { +func SubnetsPage(metaContent MetaContent, subnets []db.Subnet) templ.Component { return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) if !templ_7745c5c3_IsBuffer { @@ -49,7 +49,7 @@ func SubnetsPage(metaContent MetaContent, subnets []db.Subnet, err error) templ. } return templ_7745c5c3_Err }) - templ_7745c5c3_Err = wrapBase(metaContent, "Subnets", err).Render(templ.WithChildren(ctx, templ_7745c5c3_Var2), templ_7745c5c3_Buffer) + templ_7745c5c3_Err = wrapBase(metaContent, "Subnets").Render(templ.WithChildren(ctx, templ_7745c5c3_Var2), templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -73,7 +73,7 @@ func subnetsTable(subnets []db.Subnet) templ.Component { templ_7745c5c3_Var3 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

Subnets

ID Name Display Name VLAN
{ fmt.Sprint(subnet.ID) } { subnet.Name } { subnet.DisplayName } { fmt.Sprint(subnet.VLAN) }
IDNameDisplay NameVLANIPv4IPv6LocationComment
") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

Subnets

NameDisplay NameVLANIPv4IPv6LocationComment
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -111,9 +111,9 @@ func subnetsTableRows(subnets []db.Subnet) templ.Component { return templ_7745c5c3_Err } var templ_7745c5c3_Var5 string - templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprint(subnet.ID)) + templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(subnet.Name) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/subnets.templ`, Line: 41, Col: 30} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/subnets.templ`, Line: 40, Col: 20} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5)) if templ_7745c5c3_Err != nil { @@ -124,9 +124,9 @@ func subnetsTableRows(subnets []db.Subnet) templ.Component { return templ_7745c5c3_Err } var templ_7745c5c3_Var6 string - templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(subnet.Name) + templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(subnet.DisplayName) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/subnets.templ`, Line: 42, Col: 20} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/subnets.templ`, Line: 41, Col: 27} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6)) if templ_7745c5c3_Err != nil { @@ -137,9 +137,9 @@ func subnetsTableRows(subnets []db.Subnet) templ.Component { return templ_7745c5c3_Err } var templ_7745c5c3_Var7 string - templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(subnet.DisplayName) + templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprint(subnet.VLAN)) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/subnets.templ`, Line: 43, Col: 27} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/subnets.templ`, Line: 42, Col: 32} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7)) if templ_7745c5c3_Err != nil { @@ -150,9 +150,9 @@ func subnetsTableRows(subnets []db.Subnet) templ.Component { return templ_7745c5c3_Err } var templ_7745c5c3_Var8 string - templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprint(subnet.VLAN)) + templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(subnet.IPv4Net) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/subnets.templ`, Line: 44, Col: 32} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/subnets.templ`, Line: 43, Col: 23} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8)) if templ_7745c5c3_Err != nil { @@ -163,27 +163,14 @@ func subnetsTableRows(subnets []db.Subnet) templ.Component { return templ_7745c5c3_Err } var templ_7745c5c3_Var9 string - templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(subnet.IPv4Net) + templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(subnet.IPv6Net) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/subnets.templ`, Line: 45, Col: 23} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/subnets.templ`, Line: 44, Col: 23} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - var templ_7745c5c3_Var10 string - templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(subnet.IPv6Net) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/subnets.templ`, Line: 46, Col: 23} - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10)) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("