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:
		
							parent
							
								
									f8b235ab24
								
							
						
					
					
						commit
						489fdf4b20
					
				
					 2 changed files with 59 additions and 31 deletions
				
			
		| 
						 | 
					@ -128,6 +128,33 @@ class HostsManagerApp(App):
 | 
				
			||||||
                            classes="default-input",
 | 
					                            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:
 | 
					                    with Vertical(classes="default-section") as comment:
 | 
				
			||||||
                        comment.border_title = "Comment:"
 | 
					                        comment.border_title = "Comment:"
 | 
				
			||||||
                        yield Input(
 | 
					                        yield Input(
 | 
				
			||||||
| 
						 | 
					@ -146,15 +173,6 @@ class HostsManagerApp(App):
 | 
				
			||||||
                            classes="default-checkbox",
 | 
					                            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)
 | 
					                # Edit form (initially hidden)
 | 
				
			||||||
                with Vertical(id="entry-edit-form", classes="entry-form hidden"):
 | 
					                with Vertical(id="entry-edit-form", classes="entry-form hidden"):
 | 
				
			||||||
                    with Vertical(
 | 
					                    with Vertical(
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -132,20 +132,26 @@ class DetailsHandler:
 | 
				
			||||||
    def _update_dns_information(self, entry) -> None:
 | 
					    def _update_dns_information(self, entry) -> None:
 | 
				
			||||||
        """Update DNS information display for the selected entry."""
 | 
					        """Update DNS information display for the selected entry."""
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            # Try to find DNS info widget, but don't fail if not present yet
 | 
					            # Get the three separate DNS input fields
 | 
				
			||||||
            dns_info_input = self.app.query_one("#details-dns-info-input", Input)
 | 
					            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():
 | 
					            if not entry.has_dns_name():
 | 
				
			||||||
                dns_info_input.value = ""
 | 
					                # Clear all DNS fields if no DNS information
 | 
				
			||||||
                dns_info_input.placeholder = "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
 | 
					                return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            # Build DNS information display
 | 
					            # Update DNS Name field
 | 
				
			||||||
            dns_parts = []
 | 
					            dns_name_input.value = entry.dns_name or ""
 | 
				
			||||||
            
 | 
					            dns_name_input.placeholder = "" if entry.dns_name else "No DNS name"
 | 
				
			||||||
            # Always show the DNS name first
 | 
					 | 
				
			||||||
            dns_parts.append(f"DNS: {entry.dns_name}")
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            # Update DNS Status field
 | 
				
			||||||
            if entry.dns_resolution_status:
 | 
					            if entry.dns_resolution_status:
 | 
				
			||||||
                status_text = {
 | 
					                status_text = {
 | 
				
			||||||
                    "not_resolved": "Not resolved",
 | 
					                    "not_resolved": "Not resolved",
 | 
				
			||||||
| 
						 | 
					@ -155,24 +161,28 @@ class DetailsHandler:
 | 
				
			||||||
                    "match": "IP matches DNS",
 | 
					                    "match": "IP matches DNS",
 | 
				
			||||||
                    "mismatch": "IP differs from DNS"
 | 
					                    "mismatch": "IP differs from DNS"
 | 
				
			||||||
                }.get(entry.dns_resolution_status, entry.dns_resolution_status)
 | 
					                }.get(entry.dns_resolution_status, entry.dns_resolution_status)
 | 
				
			||||||
                dns_parts.append(f"Status: {status_text}")
 | 
					 | 
				
			||||||
                
 | 
					                
 | 
				
			||||||
            if entry.resolved_ip:
 | 
					                # Add resolved IP to status if available
 | 
				
			||||||
                dns_parts.append(f"Resolved IP: {entry.resolved_ip}")
 | 
					                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:
 | 
					            if entry.last_resolved:
 | 
				
			||||||
                from datetime import datetime
 | 
					                from datetime import datetime
 | 
				
			||||||
                time_str = entry.last_resolved.strftime("%H:%M:%S")
 | 
					                time_str = entry.last_resolved.strftime("%H:%M:%S")
 | 
				
			||||||
                date_str = entry.last_resolved.strftime("%Y-%m-%d")
 | 
					                date_str = entry.last_resolved.strftime("%Y-%m-%d")
 | 
				
			||||||
                dns_parts.append(f"Last resolved: {date_str} {time_str}")
 | 
					                dns_resolved_input.value = f"{date_str} {time_str}"
 | 
				
			||||||
 | 
					                dns_resolved_input.placeholder = ""
 | 
				
			||||||
            if dns_parts:
 | 
					 | 
				
			||||||
                dns_info_input.value = " | ".join(dns_parts)
 | 
					 | 
				
			||||||
                dns_info_input.placeholder = ""
 | 
					 | 
				
			||||||
            else:
 | 
					            else:
 | 
				
			||||||
                dns_info_input.value = f"DNS: {entry.dns_name}"
 | 
					                dns_resolved_input.value = ""
 | 
				
			||||||
                dns_info_input.placeholder = ""
 | 
					                dns_resolved_input.placeholder = "Not resolved yet"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        except Exception:
 | 
					        except Exception:
 | 
				
			||||||
            # DNS info widget not present yet, silently ignore
 | 
					            # DNS widgets not present yet, silently ignore
 | 
				
			||||||
            pass
 | 
					            pass
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue