mirror of
https://github.com/alexhopeoconnor/dnsmasq-webui.git
synced 2026-10-16 04:31:34 +10:00
- 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
34 lines
971 B
C#
34 lines
971 B
C#
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;
|
|
}
|