diff --git a/templates/index.templ b/templates/index.templ
index 11d47a3..a2663f6 100644
--- a/templates/index.templ
+++ b/templates/index.templ
@@ -27,7 +27,7 @@ type DNSRecord struct {
Content string
TTL int
Proxied bool
- IsStatic bool
+ IsStatic bool
CreatedOn string
}
@@ -36,6 +36,38 @@ type UpdateFrequency struct {
Value string
}
+// Helper type for grouped records
+type IPGroup struct {
+ IP string
+ Records []DNSRecord
+}
+
+// Helper function to group records by IP
+func groupRecordsByIP(records []DNSRecord) []IPGroup {
+ groupMap := make(map[string][]DNSRecord)
+ for _, r := range records {
+ groupMap[r.Content] = append(groupMap[r.Content], r)
+ }
+
+ // Stable order of groups
+ ips := make([]string, 0, len(groupMap))
+ for ip := range groupMap {
+ ips = append(ips, ip)
+ }
+ sort.Strings(ips)
+
+ // Convert to slice of IPGroup
+ result := make([]IPGroup, 0, len(ips))
+ for _, ip := range ips {
+ result = append(result, IPGroup{
+ IP: ip,
+ Records: groupMap[ip],
+ })
+ }
+
+ return result
+}
+
templ Index(props IndexProps) {
@Layout(props.Title) {
@@ -73,12 +105,7 @@ templ ConfigWarning() {
Configuration Required
Please configure your Cloudflare API credentials to manage your DNS records.
-
+
Configure Now
@@ -214,30 +241,20 @@ templ DNSRecordsTable(records []DNSRecord, currentIP string) {
No DNS records found
} else {
- // Group records by Content (IP)
- groups := make(map[string][]DNSRecord)
- for _, r := range records {
- groups[r.Content] = append(groups[r.Content], r)
- }
-
- // Stable order of groups
- ips := make([]string, 0, len(groups))
- for ip := range groups {
- ips = append(ips, ip)
- }
- sort.Strings(ips)
-
- for _, ip := range ips {
+ for _, ipGroup := range groupRecordsByIP(records) {
- { ip }
- { fmt.Sprintf("%d record(s)", len(groups[ip])) }
- if ip == currentIP {
+ { ipGroup.IP }
+
+ { fmt.Sprintf("%d record(s)",
+ len(ipGroup.Records)) }
+
+ if ipGroup.IP == currentIP {
Current IP
}
- for _, record := range groups[ip] {
+ for _, record := range ipGroup.Records {
@DNSRecordRow(record, currentIP)
}
}
@@ -286,7 +303,8 @@ templ DNSRecordRow(record DNSRecord, currentIP string) {
>
@@ -328,7 +346,8 @@ templ DNSRecordRow(record DNSRecord, currentIP string) {
method="delete"
action={ templ.URL(fmt.Sprintf("/records/%s", record.ID)) }
x-target="closest tr"
- @ajax:before={ fmt.Sprintf(`confirm('Are you sure you want to delete the record for "%s"?') || $event.preventDefault(); deleteLoading = true`, record.Name) }
+ @ajax:before={ fmt.Sprintf(`confirm('Are you sure you want to delete the record for "%s" ?') ||
+ $event.preventDefault(); deleteLoading=true`, record.Name) }
@ajax:after="deleteLoading = false"
@ajax:error="deleteLoading = false"
@ajax:success="$el.closest('tr').remove()"
@@ -390,4 +409,5 @@ func getStaticToggleTitle(isStatic bool) string {
return "Make dynamic (will auto-update)"
}
return "Make static (won't auto-update)"
- }
+}
+
diff --git a/templates/index_templ.go b/templates/index_templ.go
index 130c187..499acdd 100644
--- a/templates/index_templ.go
+++ b/templates/index_templ.go
@@ -44,6 +44,38 @@ type UpdateFrequency struct {
Value string
}
+// Helper type for grouped records
+type IPGroup struct {
+ IP string
+ Records []DNSRecord
+}
+
+// Helper function to group records by IP
+func groupRecordsByIP(records []DNSRecord) []IPGroup {
+ groupMap := make(map[string][]DNSRecord)
+ for _, r := range records {
+ groupMap[r.Content] = append(groupMap[r.Content], r)
+ }
+
+ // Stable order of groups
+ ips := make([]string, 0, len(groupMap))
+ for ip := range groupMap {
+ ips = append(ips, ip)
+ }
+ sort.Strings(ips)
+
+ // Convert to slice of IPGroup
+ result := make([]IPGroup, 0, len(ips))
+ for _, ip := range ips {
+ result = append(result, IPGroup{
+ IP: ip,
+ Records: groupMap[ip],
+ })
+ }
+
+ return result
+}
+
func Index(props IndexProps) templ.Component {
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
@@ -84,7 +116,7 @@ func Index(props IndexProps) templ.Component {
var templ_7745c5c3_Var3 string
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(props.Title)
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/index.templ`, Line: 45, Col: 23}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/index.templ`, Line: 77, Col: 23}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
if templ_7745c5c3_Err != nil {
@@ -97,7 +129,7 @@ func Index(props IndexProps) templ.Component {
var templ_7745c5c3_Var4 string
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(props.CurrentIP)
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/index.templ`, Line: 48, Col: 69}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/index.templ`, Line: 80, Col: 69}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
if templ_7745c5c3_Err != nil {
@@ -197,7 +229,7 @@ func ConfigStatus(config ConfigData) templ.Component {
var templ_7745c5c3_Var7 string
templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(config.Domain)
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/index.templ`, Line: 120, Col: 51}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/index.templ`, Line: 147, Col: 51}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
if templ_7745c5c3_Err != nil {
@@ -210,7 +242,7 @@ func ConfigStatus(config ConfigData) templ.Component {
var templ_7745c5c3_Var8 string
templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(config.ZoneID)
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/index.templ`, Line: 123, Col: 52}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/index.templ`, Line: 150, Col: 52}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
if templ_7745c5c3_Err != nil {
@@ -223,7 +255,7 @@ func ConfigStatus(config ConfigData) templ.Component {
var templ_7745c5c3_Var9 string
templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(formatUpdateSchedule(config.UpdatePeriod))
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/index.templ`, Line: 127, Col: 54}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/index.templ`, Line: 154, Col: 54}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9))
if templ_7745c5c3_Err != nil {
@@ -305,72 +337,49 @@ func DNSRecordsTable(records []DNSRecord, currentIP string) templ.Component {
return templ_7745c5c3_Err
}
} else {
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, " groups := make(map[string][]DNSRecord) ")
- if templ_7745c5c3_Err != nil {
- return templ_7745c5c3_Err
- }
- for _, r := range records {
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "groups[r.Content] = append(groups[r.Content], r)")
- if templ_7745c5c3_Err != nil {
- return templ_7745c5c3_Err
- }
- }
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, " ips := make([]string, 0, len(groups)) ")
- if templ_7745c5c3_Err != nil {
- return templ_7745c5c3_Err
- }
- for ip := range groups {
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 18, "ips = append(ips, ip)")
- if templ_7745c5c3_Err != nil {
- return templ_7745c5c3_Err
- }
- }
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 19, " sort.Strings(ips) ")
- if templ_7745c5c3_Err != nil {
- return templ_7745c5c3_Err
- }
- for _, ip := range ips {
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 20, "")
+ for _, ipGroup := range groupRecordsByIP(records) {
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, "")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var12 string
- templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(ip)
+ templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(ipGroup.IP)
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/index.templ`, Line: 233, Col: 20}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/index.templ`, Line: 247, Col: 28}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 21, " ")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, " ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var13 string
- templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d record(s)", len(groups[ip])))
+ templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d record(s)",
+ len(ipGroup.Records)))
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/index.templ`, Line: 234, Col: 84}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/index.templ`, Line: 250, Col: 27}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 22, " ")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, " ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- if ip == currentIP {
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 23, "Current IP ")
+ if ipGroup.IP == currentIP {
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 18, "Current IP ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 24, " ")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 19, " ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- for _, record := range groups[ip] {
+ for _, record := range ipGroup.Records {
templ_7745c5c3_Err = DNSRecordRow(record, currentIP).Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
@@ -378,7 +387,7 @@ func DNSRecordsTable(records []DNSRecord, currentIP string) templ.Component {
}
}
}
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 25, " ")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 20, "")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -407,68 +416,68 @@ func DNSRecordRow(record DNSRecord, currentIP string) templ.Component {
templ_7745c5c3_Var14 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 26, "")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var15 string
templ_7745c5c3_Var15, templ_7745c5c3_Err = templ.JoinStringErrs(record.Type)
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/index.templ`, Line: 252, Col: 19}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/index.templ`, Line: 269, Col: 19}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var15))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 27, " ")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 22, " ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var16 string
templ_7745c5c3_Var16, templ_7745c5c3_Err = templ.JoinStringErrs(record.Name)
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/index.templ`, Line: 253, Col: 19}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/index.templ`, Line: 270, Col: 19}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var16))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 28, " ")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 23, " ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var17 string
templ_7745c5c3_Var17, templ_7745c5c3_Err = templ.JoinStringErrs(record.Content)
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/index.templ`, Line: 255, Col: 19}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/index.templ`, Line: 272, Col: 19}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var17))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 29, " ")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 24, " ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if record.Type == "A" && !record.IsStatic {
if record.Content == currentIP {
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 30, "Current IP ")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 25, "Current IP ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
} else {
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 31, "Outdated IP ")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 26, "Outdated IP ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
}
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 32, " ")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 27, " ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if record.TTL == 1 {
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 33, "Auto")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 28, "Auto")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -476,51 +485,52 @@ func DNSRecordRow(record DNSRecord, currentIP string) templ.Component {
var templ_7745c5c3_Var18 string
templ_7745c5c3_Var18, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%ds", record.TTL))
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/index.templ`, Line: 268, Col: 36}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/index.templ`, Line: 285, Col: 36}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var18))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 34, " ")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 29, " ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if record.Proxied {
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 35, " ")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 30, " ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 36, " ")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 31, " ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if record.Type == "A" {
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 37, "")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 39, " ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
} else {
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 45, "- ")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 40, "- ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 46, " ")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 44, "\" @ajax:after=\"deleteLoading = false\" @ajax:error=\"deleteLoading = false\" @ajax:success=\"$el.closest('tr').remove()\" style=\"display: inline;\">