dev: automated commit - 2025-10-07 13:25:55
This commit is contained in:
parent
bc63f389f0
commit
9d6ca04834
2 changed files with 136 additions and 105 deletions
|
|
@ -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) {
|
||||
<div class="container">
|
||||
|
|
@ -73,12 +105,7 @@ templ ConfigWarning() {
|
|||
<div class="alert alert-warning config-warning">
|
||||
<h4>Configuration Required</h4>
|
||||
<p>Please configure your Cloudflare API credentials to manage your DNS records.</p>
|
||||
<a
|
||||
href="/config"
|
||||
x-target="contact"
|
||||
@ajax:success="$dispatch('dialog:open')"
|
||||
class="btn btn-primary"
|
||||
>
|
||||
<a href="/config" x-target="contact" @ajax:success="$dispatch('dialog:open')" class="btn btn-primary">
|
||||
Configure Now
|
||||
</a>
|
||||
</div>
|
||||
|
|
@ -214,30 +241,20 @@ templ DNSRecordsTable(records []DNSRecord, currentIP string) {
|
|||
<td colspan="7" class="text-center">No DNS records found</td>
|
||||
</tr>
|
||||
} 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) {
|
||||
<tr class="table-secondary">
|
||||
<td colspan="7">
|
||||
<strong>{ ip }</strong>
|
||||
<span class="ms-2 text-muted">{ fmt.Sprintf("%d record(s)", len(groups[ip])) }</span>
|
||||
if ip == currentIP {
|
||||
<strong>{ ipGroup.IP }</strong>
|
||||
<span class="ms-2 text-muted">
|
||||
{ fmt.Sprintf("%d record(s)",
|
||||
len(ipGroup.Records)) }
|
||||
</span>
|
||||
if ipGroup.IP == currentIP {
|
||||
<span class="badge bg-success ms-2">Current IP</span>
|
||||
}
|
||||
</td>
|
||||
</tr>
|
||||
for _, record := range groups[ip] {
|
||||
for _, record := range ipGroup.Records {
|
||||
@DNSRecordRow(record, currentIP)
|
||||
}
|
||||
}
|
||||
|
|
@ -286,7 +303,8 @@ templ DNSRecordRow(record DNSRecord, currentIP string) {
|
|||
>
|
||||
<button
|
||||
type="submit"
|
||||
class={ "btn btn-sm", templ.KV("btn-outline-secondary", !record.IsStatic), templ.KV("btn-secondary", record.IsStatic) }
|
||||
class={ "btn btn-sm" , templ.KV("btn-outline-secondary",
|
||||
!record.IsStatic), templ.KV("btn-secondary", record.IsStatic) }
|
||||
:disabled="editLoading || deleteLoading || toggleLoading"
|
||||
title={ getStaticToggleTitle(record.IsStatic) }
|
||||
>
|
||||
|
|
@ -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)"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue