77 lines
2.6 KiB
Plaintext
77 lines
2.6 KiB
Plaintext
@using MoonCore.Blazor.FlyonUi.Components
|
|
@using MoonlightServers.Shared.Enums
|
|
@using MoonlightServers.Shared.Models
|
|
|
|
@inherits MoonCore.Blazor.FlyonUi.Modals.Components.BaseModal
|
|
|
|
<h1 class="mb-5 font-semibold text-xl">Add a new parse configuration</h1>
|
|
|
|
<HandleForm @ref="HandleForm" Model="Form" OnValidSubmit="OnValidSubmit">
|
|
<div class="grid grid-cols-2 gap-x-2 gap-y-4">
|
|
<div class="col-span-1">
|
|
<label class="block text-sm font-medium leading-6 text-base-content">File</label>
|
|
<input @bind="Form.File" type="text" class="input w-full"/>
|
|
</div>
|
|
|
|
<div class="col-span-1">
|
|
<label class="block text-sm font-medium leading-6 text-base-content">Type</label>
|
|
<select @bind="Form.Parser" class="select w-full">
|
|
@foreach (var val in Enum.GetValues<FileParsers>())
|
|
{
|
|
<option value="@val">@val</option>
|
|
}
|
|
</select>
|
|
</div>
|
|
|
|
<div class="col-span-2">
|
|
<button type="button" @onclick="AddEntry" class="btn btn-primary w-full">Add entry</button>
|
|
</div>
|
|
|
|
@foreach (var entry in Form.Entries)
|
|
{
|
|
<div class="col-span-2">
|
|
<div class="flex flex-row">
|
|
<input @bind="entry.Key" placeholder="Key" class="input placeholder-base-content/50 grow rounded-r-none"/>
|
|
<input @bind="entry.Value" placeholder="Value" class="input placeholder-base-content/50 grow rounded-none"/>
|
|
<button type="button" @onclick="() => RemoveEntry(entry)" class="btn btn-error grow-0 rounded-l-none">
|
|
<i class="icon-x"></i>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
}
|
|
</div>
|
|
</HandleForm>
|
|
|
|
<div class="mt-5 flex space-x-2">
|
|
<WButton OnClick="_ => Hide()" CssClasses="btn btn-secondary grow">Cancel</WButton>
|
|
<WButton OnClick="_ => Submit()" CssClasses="btn btn-primary grow">Create</WButton>
|
|
</div>
|
|
|
|
@code
|
|
{
|
|
[Parameter] public Func<ParseConfiguration, Task> OnSubmit { get; set; }
|
|
|
|
private ParseConfiguration Form = new();
|
|
private HandleForm HandleForm;
|
|
|
|
private async Task OnValidSubmit()
|
|
{
|
|
await OnSubmit.Invoke(Form);
|
|
await Hide();
|
|
}
|
|
|
|
private Task Submit() => HandleForm.Submit();
|
|
|
|
private async Task AddEntry()
|
|
{
|
|
Form.Entries.Add(new());
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
private async Task RemoveEntry(ParseConfiguration.ParseConfigurationEntry entry)
|
|
{
|
|
Form.Entries.Remove(entry);
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
}
|