diff --git a/db/subnets.go b/db/subnets.go index 1a133de..b97216d 100644 --- a/db/subnets.go +++ b/db/subnets.go @@ -20,13 +20,6 @@ func (subnet *Subnet) Delete() error { } -func (subnet *Subnet) Get() *Subnet { - if err := conn.First(subnet).Error; err != nil { - return nil - } - return subnet - -} func CountSubnets() int { var count int64 err := conn.Model(&Subnet{}).Count(&count) @@ -38,6 +31,7 @@ func CountSubnets() int { return int(count) } +// Location() allows accessing the associated Location from the Subnet object func (subnet *Subnet) Location() Location { var location Location @@ -55,3 +49,9 @@ func SubnetsList(filter *Subnet, limit int, offset int, order string) []Subnet { return subnets } + +func SubnetByID(id uint) Subnet { + var subnet Subnet + conn.First(&subnet, id) + return subnet +} diff --git a/utils/metacontent.go b/utils/metacontent.go deleted file mode 100644 index 2b941d5..0000000 --- a/utils/metacontent.go +++ /dev/null @@ -1,54 +0,0 @@ -package utils - -import ( - "fmt" - "time" - - "github.com/gin-contrib/sessions" - "github.com/gin-gonic/gin" -) - -type MetaContent struct { - Username string - IsLoggedIn bool - IsAdmin bool - Timestamp string - ErrorTitle string - ErrorText string -} - -// MetaContent collects all the values needed to render the templates that aren't specific to the view -// and combines them into a structure expected by the template -func GenMetaContent(c *gin.Context) MetaContent { - session := sessions.Default(c) - sessionUserName := session.Get("username") - sessionIsLoggedIn := session.Get("isLoggedIn") - sessionIsAdmin := session.Get("isAdmin") - var username string - var isLoggedIn bool - var isAdmin bool - - // Validate Types - if sessionUserName != nil { - username, _ = sessionUserName.(string) - } else { - username = "" - } - if sessionIsLoggedIn != nil { - isLoggedIn, _ = sessionIsLoggedIn.(bool) - } else { - isLoggedIn = false - } - if sessionIsAdmin != nil { - isAdmin, _ = sessionIsAdmin.(bool) - } else { - isAdmin = false - } - - return MetaContent{ - Username: username, - IsLoggedIn: isLoggedIn, - IsAdmin: isAdmin, - Timestamp: fmt.Sprintf("%d", time.Now().Year()), - } -} diff --git a/web/templates/index.templ b/web/templates/index.templ index 5f72ba2..1adce32 100644 --- a/web/templates/index.templ +++ b/web/templates/index.templ @@ -1,9 +1,8 @@ package templates import "fmt" -import "git.jmbit.de/jmb/goipam/utils" -templ Index(metaContent utils.MetaContent, counters IndexCounts, err error) { +templ Index(metaContent MetaContent, counters IndexCounts, err error) { @wrapBase(metaContent, "GoIPAM", err) {
diff --git a/web/templates/index_templ.go b/web/templates/index_templ.go index e117034..5efe405 100644 --- a/web/templates/index_templ.go +++ b/web/templates/index_templ.go @@ -11,9 +11,8 @@ import "io" import "bytes" import "fmt" -import "git.jmbit.de/jmb/goipam/utils" -func Index(metaContent utils.MetaContent, counters IndexCounts, err error) templ.Component { +func Index(metaContent MetaContent, counters IndexCounts, err error) 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 { @@ -80,7 +79,7 @@ func indexStats(counters IndexCounts) templ.Component { var templ_7745c5c3_Var4 string templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprint(counters.SubnetCount)) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/index.templ`, Line: 20, Col: 55} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/index.templ`, Line: 19, Col: 55} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4)) if templ_7745c5c3_Err != nil { @@ -93,7 +92,7 @@ func indexStats(counters IndexCounts) templ.Component { var templ_7745c5c3_Var5 string templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprint(counters.AddressCount)) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/index.templ`, Line: 26, Col: 56} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/index.templ`, Line: 25, Col: 56} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5)) if templ_7745c5c3_Err != nil { @@ -106,7 +105,7 @@ func indexStats(counters IndexCounts) templ.Component { var templ_7745c5c3_Var6 string templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprint(counters.DeviceCount)) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/index.templ`, Line: 32, Col: 55} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/index.templ`, Line: 31, Col: 55} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6)) if templ_7745c5c3_Err != nil { @@ -119,7 +118,7 @@ func indexStats(counters IndexCounts) templ.Component { var templ_7745c5c3_Var7 string templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprint(counters.LocationCount)) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/index.templ`, Line: 38, Col: 57} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/index.templ`, Line: 37, Col: 57} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7)) if templ_7745c5c3_Err != nil { diff --git a/web/templates/login.templ b/web/templates/login.templ index f723c4c..5042078 100644 --- a/web/templates/login.templ +++ b/web/templates/login.templ @@ -1,8 +1,6 @@ package templates -import "git.jmbit.de/jmb/goipam/utils" - -templ Login(metaContent utils.MetaContent, title string, err error) { +templ Login(metaContent MetaContent, title string, err error) { @wrapBase(metaContent, title, err) {
diff --git a/web/templates/login_templ.go b/web/templates/login_templ.go index 5cdf69f..db2b11b 100644 --- a/web/templates/login_templ.go +++ b/web/templates/login_templ.go @@ -10,9 +10,7 @@ import "context" import "io" import "bytes" -import "git.jmbit.de/jmb/goipam/utils" - -func Login(metaContent utils.MetaContent, title string, err error) templ.Component { +func Login(metaContent MetaContent, title string, err error) 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 { diff --git a/web/templates/mainComponents.templ b/web/templates/mainComponents.templ index 3ed5f7a..e71cde0 100644 --- a/web/templates/mainComponents.templ +++ b/web/templates/mainComponents.templ @@ -1,7 +1,5 @@ package templates -import "git.jmbit.de/jmb/goipam/utils" - templ head(title string) { @@ -95,7 +93,7 @@ templ ErrorMessage(title string, content string) { } // wrapBase handles the basics of HTML -templ wrapBase(metaContent utils.MetaContent, title string, err error) { +templ wrapBase(metaContent MetaContent, title string, err error) { @head(title) diff --git a/web/templates/mainComponents_templ.go b/web/templates/mainComponents_templ.go index c16caf1..8073192 100644 --- a/web/templates/mainComponents_templ.go +++ b/web/templates/mainComponents_templ.go @@ -10,8 +10,6 @@ import "context" import "io" import "bytes" -import "git.jmbit.de/jmb/goipam/utils" - func head(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) @@ -32,7 +30,7 @@ func head(title string) templ.Component { var templ_7745c5c3_Var2 string templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(title) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/mainComponents.templ`, Line: 10, Col: 16} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/mainComponents.templ`, Line: 8, Col: 16} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2)) if templ_7745c5c3_Err != nil { @@ -69,7 +67,7 @@ func footer(timestamp string) templ.Component { var templ_7745c5c3_Var4 string templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(timestamp) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/mainComponents.templ`, Line: 18, Col: 100} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/mainComponents.templ`, Line: 16, Col: 100} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4)) if templ_7745c5c3_Err != nil { @@ -169,7 +167,7 @@ func ErrorMessage(title string, content string) templ.Component { var templ_7745c5c3_Var8 string templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(title) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/mainComponents.templ`, Line: 80, Col: 13} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/mainComponents.templ`, Line: 78, Col: 13} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8)) if templ_7745c5c3_Err != nil { @@ -182,7 +180,7 @@ func ErrorMessage(title string, content string) templ.Component { var templ_7745c5c3_Var9 string templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(content) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/mainComponents.templ`, Line: 91, Col: 12} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/mainComponents.templ`, Line: 89, Col: 12} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9)) if templ_7745c5c3_Err != nil { @@ -200,7 +198,7 @@ func ErrorMessage(title string, content string) templ.Component { } // wrapBase handles the basics of HTML -func wrapBase(metaContent utils.MetaContent, title string, err error) templ.Component { +func wrapBase(metaContent MetaContent, title string, err error) 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 { diff --git a/web/templates/profile.templ b/web/templates/profile.templ index e1a1c23..b762255 100644 --- a/web/templates/profile.templ +++ b/web/templates/profile.templ @@ -2,9 +2,8 @@ package templates import "git.jmbit.de/jmb/goipam/db" -import "git.jmbit.de/jmb/goipam/utils" -templ ProfilePage(metaContent utils.MetaContent, title string, user *db.User, err error) { +templ ProfilePage(metaContent MetaContent, title string, user *db.User, err error) { @wrapBase(metaContent, title, err) { @profileMain(user) } diff --git a/web/templates/profile_templ.go b/web/templates/profile_templ.go index 33ffd2f..c546aec 100644 --- a/web/templates/profile_templ.go +++ b/web/templates/profile_templ.go @@ -11,9 +11,8 @@ import "io" import "bytes" import "git.jmbit.de/jmb/goipam/db" -import "git.jmbit.de/jmb/goipam/utils" -func ProfilePage(metaContent utils.MetaContent, title string, user *db.User, err error) templ.Component { +func ProfilePage(metaContent MetaContent, title string, user *db.User, err error) 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 { @@ -104,7 +103,7 @@ func ProfileStatic(user *db.User) templ.Component { var templ_7745c5c3_Var5 string templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(user.Name) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/profile.templ`, Line: 23, Col: 52} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/profile.templ`, Line: 22, Col: 52} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5)) if templ_7745c5c3_Err != nil { @@ -117,7 +116,7 @@ func ProfileStatic(user *db.User) templ.Component { var templ_7745c5c3_Var6 string templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(user.DisplayName) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/profile.templ`, Line: 26, Col: 63} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/profile.templ`, Line: 25, Col: 63} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6)) if templ_7745c5c3_Err != nil { @@ -130,7 +129,7 @@ func ProfileStatic(user *db.User) templ.Component { var templ_7745c5c3_Var7 string templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(user.Email) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/profile.templ`, Line: 29, Col: 50} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/profile.templ`, Line: 28, Col: 50} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7)) if templ_7745c5c3_Err != nil { @@ -167,7 +166,7 @@ func ProfileForm(user *db.User) templ.Component { var templ_7745c5c3_Var9 string templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(user.Name) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/profile.templ`, Line: 40, Col: 52} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/profile.templ`, Line: 39, Col: 52} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9)) if templ_7745c5c3_Err != nil { diff --git a/web/templates/structs.go b/web/templates/structs.go index 8f730ad..4128319 100644 --- a/web/templates/structs.go +++ b/web/templates/structs.go @@ -1,8 +1,61 @@ package templates +import ( + "fmt" + "time" + + "github.com/gin-contrib/sessions" + "github.com/gin-gonic/gin" +) + type IndexCounts struct { SubnetCount int AddressCount int DeviceCount int LocationCount int } + +type MetaContent struct { + Username string + IsLoggedIn bool + IsAdmin bool + Timestamp string + ErrorTitle string + ErrorText string +} + +// MetaContent collects all the values needed to render the templates that aren't specific to the view +// and combines them into a structure expected by the template +func GenMetaContent(c *gin.Context) MetaContent { + session := sessions.Default(c) + sessionUserName := session.Get("username") + sessionIsLoggedIn := session.Get("isLoggedIn") + sessionIsAdmin := session.Get("isAdmin") + var username string + var isLoggedIn bool + var isAdmin bool + + // Validate Types + if sessionUserName != nil { + username, _ = sessionUserName.(string) + } else { + username = "" + } + if sessionIsLoggedIn != nil { + isLoggedIn, _ = sessionIsLoggedIn.(bool) + } else { + isLoggedIn = false + } + if sessionIsAdmin != nil { + isAdmin, _ = sessionIsAdmin.(bool) + } else { + isAdmin = false + } + + return MetaContent{ + Username: username, + IsLoggedIn: isLoggedIn, + IsAdmin: isAdmin, + Timestamp: fmt.Sprintf("%d", time.Now().Year()), + } +} diff --git a/web/templates/subnets.templ b/web/templates/subnets.templ index c5b81f9..1920275 100644 --- a/web/templates/subnets.templ +++ b/web/templates/subnets.templ @@ -1,10 +1,9 @@ package templates -import "git.jmbit.de/jmb/goipam/utils" import "git.jmbit.de/jmb/goipam/db" import "fmt" -templ SubnetsPage(metaContent utils.MetaContent, subnets []db.Subnet, err error) { +templ SubnetsPage(metaContent MetaContent, subnets []db.Subnet, err error) { @wrapBase(metaContent, "Subnets", err) {
diff --git a/web/templates/subnets_templ.go b/web/templates/subnets_templ.go index edafb20..3cbd6ef 100644 --- a/web/templates/subnets_templ.go +++ b/web/templates/subnets_templ.go @@ -10,11 +10,10 @@ import "context" import "io" import "bytes" -import "git.jmbit.de/jmb/goipam/utils" import "git.jmbit.de/jmb/goipam/db" import "fmt" -func SubnetsPage(metaContent utils.MetaContent, subnets []db.Subnet, err error) templ.Component { +func SubnetsPage(metaContent MetaContent, subnets []db.Subnet, err error) 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 { @@ -114,7 +113,7 @@ func subnetsTableRows(subnets []db.Subnet) templ.Component { var templ_7745c5c3_Var5 string templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprint(subnet.ID)) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/subnets.templ`, Line: 42, Col: 30} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/subnets.templ`, Line: 41, Col: 30} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5)) if templ_7745c5c3_Err != nil { @@ -127,7 +126,7 @@ func subnetsTableRows(subnets []db.Subnet) templ.Component { var templ_7745c5c3_Var6 string templ_7745c5c3_Var6, 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: 43, Col: 20} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/subnets.templ`, Line: 42, Col: 20} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6)) if templ_7745c5c3_Err != nil { @@ -140,7 +139,7 @@ func subnetsTableRows(subnets []db.Subnet) templ.Component { var templ_7745c5c3_Var7 string templ_7745c5c3_Var7, 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: 44, Col: 27} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/subnets.templ`, Line: 43, Col: 27} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7)) if templ_7745c5c3_Err != nil { @@ -153,7 +152,7 @@ func subnetsTableRows(subnets []db.Subnet) templ.Component { var templ_7745c5c3_Var8 string templ_7745c5c3_Var8, 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: 45, Col: 32} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/subnets.templ`, Line: 44, Col: 32} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8)) if templ_7745c5c3_Err != nil { @@ -166,7 +165,7 @@ func subnetsTableRows(subnets []db.Subnet) templ.Component { var templ_7745c5c3_Var9 string templ_7745c5c3_Var9, 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: 46, Col: 23} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/subnets.templ`, Line: 45, Col: 23} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9)) if templ_7745c5c3_Err != nil { @@ -179,7 +178,7 @@ func subnetsTableRows(subnets []db.Subnet) templ.Component { 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: 47, Col: 23} + 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 { @@ -200,7 +199,7 @@ func subnetsTableRows(subnets []db.Subnet) templ.Component { var templ_7745c5c3_Var11 string templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(subnet.Location().Name) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/subnets.templ`, Line: 48, Col: 98} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/subnets.templ`, Line: 47, Col: 98} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11)) if templ_7745c5c3_Err != nil { @@ -213,7 +212,7 @@ func subnetsTableRows(subnets []db.Subnet) templ.Component { var templ_7745c5c3_Var12 string templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(subnet.Comment) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/subnets.templ`, Line: 49, Col: 23} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `web/templates/subnets.templ`, Line: 48, Col: 23} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12)) if templ_7745c5c3_Err != nil { diff --git a/web/ui/index.go b/web/ui/index.go index 5011370..b5edd6f 100644 --- a/web/ui/index.go +++ b/web/ui/index.go @@ -6,7 +6,6 @@ import ( "github.com/gin-gonic/gin" "git.jmbit.de/jmb/goipam/db" - "git.jmbit.de/jmb/goipam/utils" "git.jmbit.de/jmb/goipam/web/templates" ) @@ -18,7 +17,7 @@ func index(c *gin.Context) { LocationCount: db.CountLocations(), } - c.HTML(http.StatusOK, "", templates.Index(utils.GenMetaContent(c), counters, nil)) + c.HTML(http.StatusOK, "", templates.Index(templates.GenMetaContent(c), counters, nil)) } func getEmpty(c *gin.Context) { diff --git a/web/ui/login.go b/web/ui/login.go index 2966892..1ac454f 100644 --- a/web/ui/login.go +++ b/web/ui/login.go @@ -7,13 +7,12 @@ import ( "github.com/gin-contrib/sessions" "github.com/gin-gonic/gin" - "git.jmbit.de/jmb/goipam/utils" "git.jmbit.de/jmb/goipam/web/auth" "git.jmbit.de/jmb/goipam/web/templates" ) func getLogin(c *gin.Context) { - c.HTML(http.StatusOK, "", templates.Login(utils.GenMetaContent(c), "Login", nil)) + c.HTML(http.StatusOK, "", templates.Login(templates.GenMetaContent(c), "Login", nil)) } func postLogin(c *gin.Context) { @@ -22,7 +21,7 @@ func postLogin(c *gin.Context) { password := c.PostForm("password") err := auth.CheckPassword(username, password, session) if err != nil { - metaContent := utils.GenMetaContent(c) + metaContent := templates.GenMetaContent(c) metaContent.ErrorTitle = "Error" metaContent.ErrorText = err.Error() c.HTML(http.StatusUnauthorized, "", templates.Login(metaContent, "Login", err)) diff --git a/web/ui/profile.go b/web/ui/profile.go index 61a5bbc..5894b18 100644 --- a/web/ui/profile.go +++ b/web/ui/profile.go @@ -22,17 +22,17 @@ func getProfile(c *gin.Context) { c.HTML( http.StatusInternalServerError, "", - templates.ProfilePage(utils.GenMetaContent(c), "User Profile", &user, err), + templates.ProfilePage(templates.GenMetaContent(c), "User Profile", &user, err, ) } c.HTML( http.StatusOK, "", - templates.ProfilePage(utils.GenMetaContent(c), "User Profile", &user, nil), + templates.ProfilePage(templates.GenMetaContent(c), "User Profile", &user, nil), ) } else { - c.HTML(http.StatusNotFound, "", templates.ProfilePage(utils.GenMetaContent(c), "User Profile", &user, nil)) + c.HTML(http.StatusNotFound, "", templates.ProfilePage(templates.GenMetaContent(c), "User Profile", &user, nil)) } } diff --git a/web/ui/subnets.go b/web/ui/subnets.go index d150c17..3735e32 100644 --- a/web/ui/subnets.go +++ b/web/ui/subnets.go @@ -2,21 +2,23 @@ package ui import ( "net/http" + "strconv" "github.com/gin-gonic/gin" "git.jmbit.de/jmb/goipam/db" - "git.jmbit.de/jmb/goipam/utils" "git.jmbit.de/jmb/goipam/web/templates" ) func getSubnetsPage(c *gin.Context) { subnets := db.SubnetsList(&db.Subnet{}, -1, -1, "") - c.HTML(http.StatusOK, "", templates.SubnetsPage(utils.GenMetaContent(c), subnets, nil)) + c.HTML(http.StatusOK, "", templates.SubnetsPage(templates.GenMetaContent(c), subnets, nil)) } func getSubnetDetails(c *gin.Context) { - subnetID := c.Param("id") - subnet := &db.Subnet{ID: subnetID}.Get() + subnetID, err := strconv.Atoi(c.Param("id")) + c.Errors = append(c.Errors, &gin.Error{Err: err, Type: gin.ErrorTypeAny}) + + subnet := db.SubnetByID(subnetID) }