136 lines
5.4 KiB
Text
136 lines
5.4 KiB
Text
@using System.Collections.ObjectModel
|
|
@using LANCommander.SDK.Enums
|
|
@inject ServerConsoleService ServerConsoleService
|
|
@inject IMessageService MessageService
|
|
@inject ILogger<ServerConsoleEditor> Logger
|
|
|
|
<Flex Direction="FlexDirection.Vertical" Gap="FlexGap.Large">
|
|
@if (_consoles == null || _consoles.Count == 0)
|
|
{
|
|
<Empty />
|
|
}
|
|
|
|
@foreach (var console in _consoles)
|
|
{
|
|
@if (console.Type == ServerConsoleType.RCON)
|
|
{
|
|
<Card Size="CardSize.Small" Title="@console.Name">
|
|
<Extra>
|
|
<Button Icon="@IconType.Outline.Close" Type="@ButtonType.Text" Danger OnClick="() => Remove(console)" />
|
|
</Extra>
|
|
<Body>
|
|
<Form Layout="@FormLayout.Vertical" Model="@console">
|
|
<GridRow Gutter="16">
|
|
<GridCol Span="8">
|
|
<FormItem Label="Type">
|
|
<Select @bind-Value="context.Type" TItem="ServerConsoleType" TItemValue="ServerConsoleType" DataSource="Enum.GetValues<ServerConsoleType>()">
|
|
<LabelTemplate Context="Value">@Value.GetDisplayName()</LabelTemplate>
|
|
<ItemTemplate Context="Value">@Value.GetDisplayName()</ItemTemplate>
|
|
</Select>
|
|
</FormItem>
|
|
<FormItem Label="Name">
|
|
<Input @bind-Value="context.Name" BindOnInput />
|
|
</FormItem>
|
|
</GridCol>
|
|
|
|
<GridCol Span="16">
|
|
<FormItem Label="Server">
|
|
<InputGroup Compact>
|
|
<Input @bind-Value="context.Host" Placeholder="Host" />
|
|
<Input @bind-Value="context.Port" Placeholder="Port" Style="width: 25%" />
|
|
</InputGroup>
|
|
</FormItem>
|
|
<FormItem Label="Password">
|
|
<InputPassword @bind-Value="context.Password" Placeholder="Password" />
|
|
</FormItem>
|
|
</GridCol>
|
|
</GridRow>
|
|
</Form>
|
|
</Body>
|
|
</Card>
|
|
}
|
|
else if (console.Type == ServerConsoleType.LogFile)
|
|
{
|
|
<Card Size="CardSize.Small" Title="@console.Name">
|
|
<Extra>
|
|
<Button Icon="@IconType.Outline.Close" Type="@ButtonType.Text" Danger OnClick="() => Remove(console)" />
|
|
</Extra>
|
|
<Body>
|
|
<Form Layout="@FormLayout.Vertical" Model="@console">
|
|
<GridRow Gutter="16">
|
|
<GridCol Span="8">
|
|
<FormItem Label="Type">
|
|
<Select @bind-Value="context.Type" TItem="ServerConsoleType" TItemValue="ServerConsoleType" DataSource="Enum.GetValues<ServerConsoleType>()">
|
|
<LabelTemplate Context="Value">@Value.GetDisplayName()</LabelTemplate>
|
|
<ItemTemplate Context="Value">@Value.GetDisplayName()</ItemTemplate>
|
|
</Select>
|
|
</FormItem>
|
|
<FormItem Label="Name">
|
|
<Input Type="InputType.Text" @bind-Value="context.Name" />
|
|
</FormItem>
|
|
</GridCol>
|
|
<GridCol Span="16">
|
|
<FormItem Label="Path">
|
|
<Input Type="InputType.Text" @bind-Value="context.Path" />
|
|
</FormItem>
|
|
</GridCol>
|
|
</GridRow>
|
|
</Form>
|
|
</Body>
|
|
</Card>
|
|
}
|
|
}
|
|
|
|
<Flex Justify="FlexJustify.End">
|
|
<Button OnClick="Add" Type="@ButtonType.Primary">Add Console</Button>
|
|
</Flex>
|
|
</Flex>
|
|
|
|
@code {
|
|
[Parameter] public Guid ServerId { get; set; }
|
|
|
|
ObservableCollection<ServerConsole> _consoles = new();
|
|
|
|
protected override async Task OnInitializedAsync() => await LoadConsoles();
|
|
|
|
async Task LoadConsoles()
|
|
{
|
|
_consoles = new ObservableCollection<ServerConsole>(await ServerConsoleService.GetAsync(c => c.ServerId == ServerId));
|
|
}
|
|
|
|
public async Task Save()
|
|
{
|
|
try
|
|
{
|
|
foreach (var console in _consoles)
|
|
{
|
|
if (console.Id == Guid.Empty)
|
|
await ServerConsoleService.AddAsync(console);
|
|
else
|
|
await ServerConsoleService.UpdateAsync(console);
|
|
}
|
|
|
|
await LoadConsoles();
|
|
|
|
MessageService.Success("Consoles updated!");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageService.Error("Could not update consoles!");
|
|
Logger.LogError(ex, "Could not update consoles!");
|
|
}
|
|
}
|
|
|
|
private void Add()
|
|
{
|
|
_consoles.Add(new ServerConsole
|
|
{
|
|
ServerId = ServerId,
|
|
});
|
|
}
|
|
|
|
private void Remove(ServerConsole console)
|
|
{
|
|
_consoles.Remove(console);
|
|
}
|
|
}
|