Created some request models. Started building create star form together
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
@using MoonCore.Blazor.Tailwind.Forms
|
||||
@using MoonlightServers.Shared.Enums
|
||||
|
||||
@typeparam TPropertyType where TPropertyType : class, MoonlightServers.Shared.Interfaces.IStarVariable
|
||||
@inherits BaseFormComponent<List<TPropertyType>>
|
||||
|
||||
<div class="flex justify-end mb-5">
|
||||
<button type="button" @onclick="AddVariable" class="btn btn-primary">Add variable</button>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
@foreach (var variable in Binder.Value)
|
||||
{
|
||||
<div class="col-span-1 card p-0">
|
||||
<div class="card-body grid grid-cols-2 gap-2">
|
||||
|
||||
<div class="col-span-1">
|
||||
<label class="block text-sm font-medium leading-6 text-white">Name</label>
|
||||
<input @bind="variable.Name" type="text" class="form-input w-full"/>
|
||||
</div>
|
||||
|
||||
<div class="col-span-1">
|
||||
<label class="block text-sm font-medium leading-6 text-white">Description</label>
|
||||
<input @bind="variable.Description" type="text" class="form-input w-full"/>
|
||||
</div>
|
||||
|
||||
<div class="col-span-1">
|
||||
<label class="block text-sm font-medium leading-6 text-white">Key</label>
|
||||
<input @bind="variable.Key" type="text" class="form-input w-full"/>
|
||||
</div>
|
||||
|
||||
<div class="col-span-1">
|
||||
<label class="block text-sm font-medium leading-6 text-white">Default Value</label>
|
||||
<input @bind="variable.DefaultValue" type="text" class="form-input w-full"/>
|
||||
</div>
|
||||
|
||||
<div class="col-span-1">
|
||||
<label class="block text-sm font-medium leading-6 text-white">Allow Viewing</label>
|
||||
<Switch @bind-Value="variable.AllowViewing" />
|
||||
</div>
|
||||
|
||||
<div class="col-span-1">
|
||||
<label class="block text-sm font-medium leading-6 text-white">Allow Editing</label>
|
||||
<Switch @bind-Value="variable.AllowEditing" />
|
||||
</div>
|
||||
|
||||
<div class="col-span-1">
|
||||
<label class="block text-sm font-medium leading-6 text-white">Type</label>
|
||||
<select @bind="variable.Type" class="form-select w-full">
|
||||
@foreach (var val in Enum.GetValues<StarVariableType>())
|
||||
{
|
||||
<option value="@val">@val</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="col-span-1">
|
||||
<label class="block text-sm font-medium leading-6 text-white">Filter</label>
|
||||
<input @bind="variable.Filter" type="text" class="form-input w-full"/>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
|
||||
<div class="flex justify-end mx-2">
|
||||
<button @onclick="() => DeleteVariable(variable)" class="btn btn-danger">
|
||||
<i class="icon-trash mr-2"></i>
|
||||
Remove
|
||||
</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
private async Task AddVariable()
|
||||
{
|
||||
Binder.Value.Add(Activator.CreateInstance<TPropertyType>());
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
private async Task DeleteVariable(TPropertyType variable)
|
||||
{
|
||||
Binder.Value.Remove(variable);
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
}
|
||||
38
MoonlightServers.Frontend/UI/Components/Forms/Switch.razor
Normal file
38
MoonlightServers.Frontend/UI/Components/Forms/Switch.razor
Normal file
@@ -0,0 +1,38 @@
|
||||
@using System.Diagnostics.CodeAnalysis
|
||||
@using Microsoft.AspNetCore.Components
|
||||
|
||||
@* TODO: Extract to mooncore? *@
|
||||
|
||||
@inherits InputBase<bool>
|
||||
|
||||
<div class="flex items-center">
|
||||
<div class="form-switch">
|
||||
<input @bind="CurrentValue" type="checkbox" id="@("switch-" + GetHashCode())" class="sr-only">
|
||||
<label class="bg-gray-700" for="switch-@(GetHashCode())">
|
||||
<span class="bg-white shadow-sm" aria-hidden="true"></span>
|
||||
<span class="sr-only">Switch label</span>
|
||||
</label>
|
||||
</div>
|
||||
<div class="text-sm text-gray-500 italic ml-2">
|
||||
@if (CurrentValue)
|
||||
{
|
||||
<span>On</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span>
|
||||
Off
|
||||
</span>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
protected override bool TryParseValueFromString(string? value, out bool result, [NotNullWhen(false)] out string? validationErrorMessage)
|
||||
{
|
||||
validationErrorMessage = null;
|
||||
result = string.Equals(value, "true", StringComparison.OrdinalIgnoreCase);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user