Enhance DNS information display: separate DNS name, status, and last resolved fields into distinct inputs, and update handling logic for improved clarity and functionality.

This commit is contained in:
Philip Henning 2025-08-18 11:22:07 +02:00
parent f8b235ab24
commit 489fdf4b20
2 changed files with 59 additions and 31 deletions

View file

@ -128,6 +128,33 @@ class HostsManagerApp(App):
classes="default-input",
)
with Vertical(classes="default-section") as dns_name:
dns_name.border_title = "DNS Name"
yield Input(
placeholder="No DNS name",
id="details-dns-name-input",
disabled=True,
classes="default-input",
)
with Vertical(classes="default-section") as dns_status:
dns_status.border_title = "DNS Status"
yield Input(
placeholder="No DNS status",
id="details-dns-status-input",
disabled=True,
classes="default-input",
)
with Vertical(classes="default-section") as dns_resolved:
dns_resolved.border_title = "Last Resolved"
yield Input(
placeholder="Not resolved yet",
id="details-dns-resolved-input",
disabled=True,
classes="default-input",
)
with Vertical(classes="default-section") as comment:
comment.border_title = "Comment:"
yield Input(
@ -146,15 +173,6 @@ class HostsManagerApp(App):
classes="default-checkbox",
)
with Vertical(classes="default-section") as dns_info:
dns_info.border_title = "DNS Information"
yield Input(
placeholder="No DNS information",
id="details-dns-info-input",
disabled=True,
classes="default-input",
)
# Edit form (initially hidden)
with Vertical(id="entry-edit-form", classes="entry-form hidden"):
with Vertical(

View file

@ -132,20 +132,26 @@ class DetailsHandler:
def _update_dns_information(self, entry) -> None:
"""Update DNS information display for the selected entry."""
try:
# Try to find DNS info widget, but don't fail if not present yet
dns_info_input = self.app.query_one("#details-dns-info-input", Input)
# Get the three separate DNS input fields
dns_name_input = self.app.query_one("#details-dns-name-input", Input)
dns_status_input = self.app.query_one("#details-dns-status-input", Input)
dns_resolved_input = self.app.query_one("#details-dns-resolved-input", Input)
if not entry.has_dns_name():
dns_info_input.value = ""
dns_info_input.placeholder = "No DNS information"
# Clear all DNS fields if no DNS information
dns_name_input.value = ""
dns_name_input.placeholder = "No DNS name"
dns_status_input.value = ""
dns_status_input.placeholder = "No DNS status"
dns_resolved_input.value = ""
dns_resolved_input.placeholder = "Not resolved yet"
return
# Build DNS information display
dns_parts = []
# Always show the DNS name first
dns_parts.append(f"DNS: {entry.dns_name}")
# Update DNS Name field
dns_name_input.value = entry.dns_name or ""
dns_name_input.placeholder = "" if entry.dns_name else "No DNS name"
# Update DNS Status field
if entry.dns_resolution_status:
status_text = {
"not_resolved": "Not resolved",
@ -155,24 +161,28 @@ class DetailsHandler:
"match": "IP matches DNS",
"mismatch": "IP differs from DNS"
}.get(entry.dns_resolution_status, entry.dns_resolution_status)
dns_parts.append(f"Status: {status_text}")
if entry.resolved_ip:
dns_parts.append(f"Resolved IP: {entry.resolved_ip}")
# Add resolved IP to status if available
if entry.resolved_ip and entry.dns_resolution_status in ["resolved", "match", "mismatch"]:
status_text += f" ({entry.resolved_ip})"
dns_status_input.value = status_text
dns_status_input.placeholder = ""
else:
dns_status_input.value = ""
dns_status_input.placeholder = "No DNS status"
# Update Last Resolved field
if entry.last_resolved:
from datetime import datetime
time_str = entry.last_resolved.strftime("%H:%M:%S")
date_str = entry.last_resolved.strftime("%Y-%m-%d")
dns_parts.append(f"Last resolved: {date_str} {time_str}")
if dns_parts:
dns_info_input.value = " | ".join(dns_parts)
dns_info_input.placeholder = ""
dns_resolved_input.value = f"{date_str} {time_str}"
dns_resolved_input.placeholder = ""
else:
dns_info_input.value = f"DNS: {entry.dns_name}"
dns_info_input.placeholder = ""
dns_resolved_input.value = ""
dns_resolved_input.placeholder = "Not resolved yet"
except Exception:
# DNS info widget not present yet, silently ignore
# DNS widgets not present yet, silently ignore
pass