LANCommander/LANCommander.Server/UI/Pages/Settings/Components/ServerEngineEditor.razor
Pat Hartl add770b227 Refactor Settings
Settings for the server are now combined with the settings from the SDK. This introduces a large breaking change and a migration should be created. This refactor utilizes .NET Configuration and the Options pattern. This will allow for the overriding of any setting using envionment variables. It also means that Settings.yml can be used to override any .NET configuration. A SettingsProvider implementation was created, and any updating of settings was changed from SettingsService.SaveSettings() to SettingsProvider.Update(s => { ... })
2025-11-16 12:31:25 -06:00

85 lines
No EOL
3.2 KiB
Text

@using LANCommander.Server.Settings
@using LANCommander.Server.Settings.Enums
@using LANCommander.Server.Settings.Models
@using Microsoft.Extensions.Options
@inject IOptions<Settings> Settings
<Flex Direction="FlexDirection.Vertical" Gap="FlexGap.Large">
@if (!Settings.Value.Server.GameServers.ServerEngines.Any())
{
<Empty Description="@("No Docker hosts have been configured")" />
}
<Collapse>
@foreach (var serverEngine in Settings.Value.Server.GameServers.ServerEngines)
{
@if (serverEngine.Type == ServerEngine.Local)
{
<Panel Header="@serverEngine.Name">
<ExtraTemplate>
<Button Type="ButtonType.Text" Icon="@IconType.Outline.Close" Size="ButtonSize.Small" Danger OnClick="() => Remove(serverEngine)"/>
</ExtraTemplate>
<ChildContent>
<Form Model="serverEngine" Layout="FormLayout.Vertical">
<FormItem Label="Name">
<Input @bind-Value="context.Name" BindOnInput />
</FormItem>
</Form>
</ChildContent>
</Panel>
}
@if (serverEngine.Type == ServerEngine.Docker)
{
<Panel Header="@serverEngine.Name">
<ExtraTemplate>
<Button Type="ButtonType.Text" Icon="@IconType.Outline.Close" Size="ButtonSize.Small" Danger OnClick="() => Remove(serverEngine)"/>
</ExtraTemplate>
<ChildContent>
<Form Model="serverEngine" Layout="FormLayout.Vertical">
<FormItem Label="Name">
<Input @bind-Value="context.Name" BindOnInput />
</FormItem>
<FormItem Label="Address">
<Input @bind-Value="context.Address" />
</FormItem>
</Form>
</ChildContent>
</Panel>
}
}
</Collapse>
<Flex Justify="FlexJustify.Center">
<Button OnClick="Add" Type="ButtonType.Primary">Add Engine</Button>
</Flex>
</Flex>
@code {
[Parameter] public IEnumerable<ServerEngineConfiguration> Values { get; set; }
[Parameter] public EventCallback<IEnumerable<ServerEngineConfiguration>> ValuesChanged { get; set; }
List<ServerEngineConfiguration> ServerEngines = new();
protected override void OnParametersSet()
{
ServerEngines = Values.OrderBy(e => e.Type).ThenBy(e => e.Name).ToList();
}
async Task Add()
{
ServerEngines.Add(new ServerEngineConfiguration());
if (ValuesChanged.HasDelegate)
await ValuesChanged.InvokeAsync(ServerEngines);
}
async Task Remove(ServerEngineConfiguration serverEngine)
{
ServerEngines.Remove(serverEngine);
if (ValuesChanged.HasDelegate)
await ValuesChanged.InvokeAsync(ServerEngines);
}
}