97 lines
3.1 KiB
Plaintext
97 lines
3.1 KiB
Plaintext
@page "/config"
|
|
@inject AccessQueuePlayground.Services.IAccessQueueManager QueueManager
|
|
@using BlazorBootstrap
|
|
|
|
<h3>Access Queue Configuration</h3>
|
|
|
|
<EditForm Model="config" OnValidSubmit="HandleValidSubmit">
|
|
<DataAnnotationsValidator />
|
|
<ValidationSummary />
|
|
<div class="mb-3">
|
|
<label for="capacityLimit">Capacity Limit</label>
|
|
<TextInput Id="capacityLimit" @bind-Value="config.CapacityLimit" Type="TextInputType.Number" />
|
|
@if (!isCapacityLimitValid)
|
|
{
|
|
<div class="text-danger">Please enter a positive integer.</div>
|
|
}
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="activitySeconds">Activity Seconds</label>
|
|
<TextInput Id="activitySeconds" @bind-Value="config.ActivitySeconds" Type="TextInputType.Number" />
|
|
@if (!isActivitySecondsValid)
|
|
{
|
|
<div class="text-danger">Please enter a positive integer.</div>
|
|
}
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="expirationSeconds">Expiration Seconds</label>
|
|
<TextInput Id="expirationSeconds" @bind-Value="config.ExpirationSeconds" Type="TextInputType.Number" />
|
|
@if (!isExpirationSecondsValid)
|
|
{
|
|
<div class="text-danger">Please enter a positive integer.</div>
|
|
}
|
|
</div>
|
|
<div class="mb-3">
|
|
<Switch Id="rollingExpiration" @bind-Value="config.RollingExpiration" Label="Rolling Expiration" />
|
|
</div>
|
|
<Button Type="ButtonType.Submit" Color="ButtonColor.Primary">Save</Button>
|
|
@if (successMessage != null)
|
|
{
|
|
<Alert Color="AlertColor.Success" Class="mt-3">@successMessage</Alert>
|
|
}
|
|
</EditForm>
|
|
|
|
@code {
|
|
private ConfigModel config = new();
|
|
private bool isCapacityLimitValid = true;
|
|
private bool isActivitySecondsValid = true;
|
|
private bool isExpirationSecondsValid = true;
|
|
private string? successMessage;
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
var current = QueueManager.GetConfig();
|
|
config = new ConfigModel
|
|
{
|
|
ActivitySeconds = (current.ActivitySeconds ?? 0).ToString(),
|
|
CapacityLimit = (current.CapacityLimit ?? 0).ToString(),
|
|
ExpirationSeconds = (current.ExpirationSeconds ?? 0).ToString(),
|
|
RollingExpiration = current.RollingExpiration ?? false
|
|
};
|
|
ValidateInputs();
|
|
}
|
|
|
|
private bool IsFormValid => isCapacityLimitValid && isActivitySecondsValid && isExpirationSecondsValid;
|
|
|
|
private void ValidateInputs()
|
|
{
|
|
isCapacityLimitValid = int.TryParse(config.CapacityLimit, out var cap) && cap > 0;
|
|
isActivitySecondsValid = int.TryParse(config.ActivitySeconds, out var act) && act > 0;
|
|
isExpirationSecondsValid = int.TryParse(config.ExpirationSeconds, out var exp) && exp > 0;
|
|
}
|
|
|
|
private async Task HandleValidSubmit()
|
|
{
|
|
successMessage = null;
|
|
ValidateInputs();
|
|
if (!IsFormValid)
|
|
return;
|
|
await Task.Run(() => QueueManager.UpdateConfig(new ()
|
|
{
|
|
ActivitySeconds = int.Parse(config.ActivitySeconds),
|
|
CapacityLimit = int.Parse(config.CapacityLimit),
|
|
ExpirationSeconds = int.Parse(config.ExpirationSeconds),
|
|
RollingExpiration = config.RollingExpiration
|
|
}));
|
|
successMessage = "Configuration updated successfully.";
|
|
}
|
|
|
|
public class ConfigModel
|
|
{
|
|
public string CapacityLimit { get; set; } = "";
|
|
public string ActivitySeconds { get; set; } = "";
|
|
public string ExpirationSeconds { get; set; } = "";
|
|
public bool RollingExpiration { get; set; }
|
|
}
|
|
}
|