Compare commits
No commits in common. "7cb1f0a34c3497b970ac9c2b007b28f43aad0a76" and "aa8e4942119faaa492b3b6b9d8b9fd98691126f6" have entirely different histories.
7cb1f0a34c
...
aa8e494211
|
@ -9,7 +9,7 @@
|
|||
<ValidationSummary />
|
||||
<div class="mb-3">
|
||||
<label for="capacityLimit">Capacity Limit</label>
|
||||
<TextInput Id="capacityLimit" @bind-Value="config.CapacityLimit" Type="TextInputType.Number" />
|
||||
<TextInput Id="capacityLimit" Value="@capacityLimitInput" ValueChanged="@((string? v) => capacityLimitInput = v)" ValueExpression="@(() => capacityLimitInput)" Type="TextInputType.Number" OnInput="e => OnInputChanged(e, nameof(config.CapacityLimit))" />
|
||||
@if (!isCapacityLimitValid)
|
||||
{
|
||||
<div class="text-danger">Please enter a positive integer.</div>
|
||||
|
@ -17,7 +17,7 @@
|
|||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="activitySeconds">Activity Seconds</label>
|
||||
<TextInput Id="activitySeconds" @bind-Value="config.ActivitySeconds" Type="TextInputType.Number" />
|
||||
<TextInput Id="activitySeconds" Value="@activitySecondsInput" ValueChanged="@((string? v) => activitySecondsInput = v)" ValueExpression="@(() => activitySecondsInput)" Type="TextInputType.Number" OnInput="e => OnInputChanged(e, nameof(config.ActivitySeconds))" />
|
||||
@if (!isActivitySecondsValid)
|
||||
{
|
||||
<div class="text-danger">Please enter a positive integer.</div>
|
||||
|
@ -25,16 +25,16 @@
|
|||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="expirationSeconds">Expiration Seconds</label>
|
||||
<TextInput Id="expirationSeconds" @bind-Value="config.ExpirationSeconds" Type="TextInputType.Number" />
|
||||
<TextInput Id="expirationSeconds" Value="@expirationSecondsInput" ValueChanged="@((string? v) => expirationSecondsInput = v)" ValueExpression="@(() => expirationSecondsInput)" Type="TextInputType.Number" OnInput="e => OnInputChanged(e, nameof(config.ExpirationSeconds))" />
|
||||
@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" />
|
||||
<Switch Id="rollingExpiration" @bind-Checked="rollingExpirationSwitch" Label="Rolling Expiration" />
|
||||
</div>
|
||||
<Button Type="ButtonType.Submit" Color="ButtonColor.Primary">Save</Button>
|
||||
<Button Type="ButtonType.Submit" Color="ButtonColor.Primary" Disabled="@(!IsFormValid)">Save</Button>
|
||||
@if (successMessage != null)
|
||||
{
|
||||
<Alert Color="AlertColor.Success" Class="mt-3">@successMessage</Alert>
|
||||
|
@ -42,7 +42,11 @@
|
|||
</EditForm>
|
||||
|
||||
@code {
|
||||
private ConfigModel config = new();
|
||||
private AccessQueueService.Models.AccessQueueConfig config = new();
|
||||
private string? capacityLimitInput;
|
||||
private string? activitySecondsInput;
|
||||
private string? expirationSecondsInput;
|
||||
private bool rollingExpirationSwitch;
|
||||
private bool isCapacityLimitValid = true;
|
||||
private bool isActivitySecondsValid = true;
|
||||
private bool isExpirationSecondsValid = true;
|
||||
|
@ -51,13 +55,11 @@
|
|||
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
|
||||
};
|
||||
config = current.Clone();
|
||||
capacityLimitInput = config.CapacityLimit?.ToString();
|
||||
activitySecondsInput = config.ActivitySeconds?.ToString();
|
||||
expirationSecondsInput = config.ExpirationSeconds?.ToString();
|
||||
rollingExpirationSwitch = config.RollingExpiration ?? true;
|
||||
ValidateInputs();
|
||||
}
|
||||
|
||||
|
@ -65,32 +67,38 @@
|
|||
|
||||
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;
|
||||
isCapacityLimitValid = int.TryParse(capacityLimitInput, out var cap) && cap > 0;
|
||||
isActivitySecondsValid = int.TryParse(activitySecondsInput, out var act) && act > 0;
|
||||
isExpirationSecondsValid = int.TryParse(expirationSecondsInput, 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
|
||||
}));
|
||||
config.CapacityLimit = int.Parse(capacityLimitInput!);
|
||||
config.ActivitySeconds = int.Parse(activitySecondsInput!);
|
||||
config.ExpirationSeconds = int.Parse(expirationSecondsInput!);
|
||||
config.RollingExpiration = rollingExpirationSwitch;
|
||||
await Task.Run(() => QueueManager.UpdateConfig(config));
|
||||
successMessage = "Configuration updated successfully.";
|
||||
}
|
||||
|
||||
public class ConfigModel
|
||||
private void OnInputChanged(ChangeEventArgs e, string field)
|
||||
{
|
||||
public string CapacityLimit { get; set; } = "";
|
||||
public string ActivitySeconds { get; set; } = "";
|
||||
public string ExpirationSeconds { get; set; } = "";
|
||||
public bool RollingExpiration { get; set; }
|
||||
switch (field)
|
||||
{
|
||||
case nameof(config.CapacityLimit):
|
||||
capacityLimitInput = e.Value?.ToString();
|
||||
break;
|
||||
case nameof(config.ActivitySeconds):
|
||||
activitySecondsInput = e.Value?.ToString();
|
||||
break;
|
||||
case nameof(config.ExpirationSeconds):
|
||||
expirationSecondsInput = e.Value?.ToString();
|
||||
break;
|
||||
}
|
||||
ValidateInputs();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,14 +18,13 @@
|
|||
</p>
|
||||
}
|
||||
<p>
|
||||
<Button Color="ButtonColor.Success" @onclick="() => AddUser(true)">Add Active User</Button>
|
||||
<Button Color="ButtonColor.Success" Outline @onclick="() => AddUser(false)">Add Inctive User</Button>
|
||||
<Button Color="ButtonColor.Success" @onclick="AddUser">Add User</Button>
|
||||
<Button Color="ButtonColor.Danger" @onclick="RevokeAllAccess">Revoke All</Button>
|
||||
<Button Color="ButtonColor.Warning" @onclick="Reset">Reset Data</Button>
|
||||
</p>
|
||||
@if (Status != null)
|
||||
{
|
||||
<h4>Users with access</h4>
|
||||
<h2>Users with access</h2>
|
||||
<Grid TItem="User" Data="Status.AccessUsers" Class="table table-bordered mt-3" AllowSorting>
|
||||
<GridColumns>
|
||||
<GridColumn TItem="User" HeaderText="Id" PropertyName="Id" SortKeySelector="item => item.Id">
|
||||
|
@ -46,7 +45,7 @@
|
|||
</GridColumn>
|
||||
</GridColumns>
|
||||
</Grid>
|
||||
<h4>Users in queue</h4>
|
||||
<h2>Users in queue</h2>
|
||||
<Grid TItem="User" Data="Status.QueuedUsers" Class="table table-bordered mt-3">
|
||||
<GridColumns>
|
||||
<GridColumn TItem="User" HeaderText="Id" PropertyName="Id">
|
||||
|
@ -67,7 +66,7 @@
|
|||
</GridColumn>
|
||||
</GridColumns>
|
||||
</Grid>
|
||||
<h4>Inactive users</h4>
|
||||
<h2>Inactive users</h2>
|
||||
<Grid TItem="User" Data="Status.InactiveUsers" Class="table table-bordered mt-3" AllowSorting>
|
||||
<GridColumns>
|
||||
<GridColumn TItem="User" HeaderText="Id" PropertyName="Id" SortKeySelector="item => item.Id">
|
||||
|
@ -101,9 +100,9 @@
|
|||
});
|
||||
}
|
||||
|
||||
public void AddUser(bool isActive)
|
||||
public void AddUser()
|
||||
{
|
||||
Manager.AddUser(isActive);
|
||||
Manager.AddUser();
|
||||
Status = Manager.GetStatus();
|
||||
}
|
||||
|
||||
|
|
|
@ -36,13 +36,13 @@ namespace AccessQueuePlayground.Services
|
|||
_accessService.UpdateConfiguration(config);
|
||||
}
|
||||
|
||||
public Guid AddUser(bool isActive)
|
||||
public Guid AddUser()
|
||||
{
|
||||
var id = Guid.NewGuid();
|
||||
_users[id] = new User
|
||||
{
|
||||
Id = id,
|
||||
Active = isActive,
|
||||
Active = false,
|
||||
};
|
||||
return id;
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace AccessQueuePlayground.Services
|
|||
public void UpdateConfig(AccessQueueConfig config);
|
||||
public Task RecalculateStatus();
|
||||
public AccessQueueStatus GetStatus();
|
||||
public Guid AddUser(bool isActive);
|
||||
public Guid AddUser();
|
||||
public void SetUserActive(Guid userId, bool isActive);
|
||||
public void RevokeAccess(Guid userId);
|
||||
public void RevokeAllAccess();
|
||||
|
|
Loading…
Reference in New Issue