mirror of
https://github.com/alexhopeoconnor/dnsmasq-webui.git
synced 2026-10-03 22:12:00 +10:00
Remove the Status column and row-level badges/actions; keep source-level Editable on group headers. Double-click managed rows to edit; commit staged drafts when focus leaves the row via isFocusOutsideElement in the shared scroll-cue module. Hide inactive system-host rows when dnsmasq ignores them and move system-hosts / expand-hosts notes below the content area. Memoize VisibleGroups so BuildGroups runs once per render during search. Move read-ethers metadata to the DHCP section; adjust Hosts page state copy and related effective-config tooltips/builders where needed.
52 lines
2.4 KiB
C#
52 lines
2.4 KiB
C#
using DnsmasqWebUI.Models.Dnsmasq;
|
|
|
|
namespace DnsmasqWebUI.Models.Dnsmasq.PageStates;
|
|
|
|
/// <summary>
|
|
/// Page state for the Hosts specialized page. Derived from DnsmasqServiceStatus to keep Razor markup clean.
|
|
/// </summary>
|
|
public sealed record HostsPageState(
|
|
bool ManagedHostsAvailable,
|
|
string? ManagedHostsUnavailableReason,
|
|
bool SystemHostsActive,
|
|
string? SystemHostsInactiveReason,
|
|
bool ExpandHostsEnabled,
|
|
string? ExpansionDomain)
|
|
{
|
|
public static HostsPageState FromStatus(DnsmasqServiceStatus? status)
|
|
{
|
|
if (status == null)
|
|
{
|
|
return new HostsPageState(
|
|
ManagedHostsAvailable: false,
|
|
ManagedHostsUnavailableReason: "Status not available.",
|
|
SystemHostsActive: false,
|
|
SystemHostsInactiveReason: "Status not available.",
|
|
ExpandHostsEnabled: false,
|
|
ExpansionDomain: null);
|
|
}
|
|
|
|
var managedHostsAvailable = !string.IsNullOrEmpty(status.ManagedHostsFilePath);
|
|
var noHosts = status.NoHosts;
|
|
var systemHostsActive = !noHosts && !string.IsNullOrEmpty(status.SystemHostsPath) && status.SystemHostsPathExists;
|
|
var expandHosts = status.EffectiveConfig?.ExpandHosts ?? false;
|
|
var domain = status.EffectiveConfig?.DomainValues?.FirstOrDefault();
|
|
|
|
return new HostsPageState(
|
|
ManagedHostsAvailable: managedHostsAvailable,
|
|
ManagedHostsUnavailableReason: managedHostsAvailable
|
|
? null
|
|
: "Hosts editing is unavailable: managed hosts path is not configured. Set Dnsmasq:MainConfigPath (and optionally Dnsmasq:ManagedHostsFileName) so the app can create and edit the managed hosts file.",
|
|
SystemHostsActive: systemHostsActive,
|
|
SystemHostsInactiveReason: noHosts
|
|
? "Dnsmasq is ignoring system hosts (no-hosts is enabled), so system hosts rows are hidden from this table."
|
|
: string.IsNullOrEmpty(status.SystemHostsPath)
|
|
? "System hosts path is not configured; system hosts rows are hidden from this table."
|
|
: !status.SystemHostsPathExists
|
|
? $"System hosts file not found ({status.SystemHostsPath}); those rows are hidden from this table."
|
|
: null,
|
|
ExpandHostsEnabled: expandHosts,
|
|
ExpansionDomain: expandHosts ? domain : null);
|
|
}
|
|
}
|