mirror of
https://github.com/alexhopeoconnor/dnsmasq-webui.git
synced 2026-10-22 07:52:08 +10:00
Refactor client settings fields, fix logs overwrite, improve settings modal
- Replace FieldBounds with generic ClientSettingsField<T> abstraction - Add IClientSettingsField, ClientSettingsMinMaxField, ClientSettingsBoolField - Put abstractions in Models/Client/Abstractions namespace - Fields hold values; CoerceValue for clamping on set - ClientSettingsService hydrates fields on load; ToDto for save - Settings modal binds directly to field values, collapsible only for All context - Add LogsPreView with ShouldRender freeze to prevent Blazor overwriting JS-owned logs DOM - Add left margin to static group heading in single-section mode
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
using DnsmasqWebUI.Models.Client.Abstractions;
|
||||
|
||||
namespace DnsmasqWebUI.Models.Client;
|
||||
|
||||
/// <summary>
|
||||
/// Min/max bounded integer field with optional clamping on set.
|
||||
/// </summary>
|
||||
public sealed class ClientSettingsMinMaxField : ClientSettingsField<int>
|
||||
{
|
||||
public int Min { get; }
|
||||
public int Max { get; }
|
||||
public string Unit { get; }
|
||||
public bool AllowClamp { get; }
|
||||
|
||||
public ClientSettingsMinMaxField(string displayName, int min, int max, string unit = "seconds", bool allowClamp = true)
|
||||
: base(displayName)
|
||||
{
|
||||
Min = min;
|
||||
Max = max;
|
||||
Unit = unit;
|
||||
AllowClamp = allowClamp;
|
||||
}
|
||||
|
||||
public override string? Validate(int value)
|
||||
{
|
||||
if (value < Min || value > Max)
|
||||
return $"{DisplayName} must be between {Min} and {Max} {Unit}. You entered {value}.";
|
||||
return null;
|
||||
}
|
||||
|
||||
protected override int CoerceValue(int value) =>
|
||||
AllowClamp ? Math.Clamp(value, Min, Max) : value;
|
||||
}
|
||||
Reference in New Issue
Block a user