LANCommander/LANCommander.Server/UI/Pages/Games/Components/SavePathEditor.razor

69 lines
2.5 KiB
Text

@using LANCommander.SDK.Enums
@using LANCommander.Server.Extensions;
<Flex Vertical Gap="FlexGap.Large">
<Table TItem="SavePath" DataSource="@Value" HidePagination="true" Responsive>
<PropertyColumn Property="p => p.Type">
<Select @bind-Value="context.Type" TItem="SavePathType" TItemValue="SavePathType" DataSource="Enum.GetValues<SavePathType>()">
<LabelTemplate Context="Value">@Value.GetDisplayName()</LabelTemplate>
<ItemTemplate Context="Value">@Value.GetDisplayName()</ItemTemplate>
</Select>
</PropertyColumn>
<PropertyColumn Property="p => p.Path">
@if (context.Type == SavePathType.Registry)
{
<InputRegistry @bind-Value="context.Path" />
}
else
{
<FilePicker @bind-Value="context.Path" ArchiveId="@ArchiveId" AllowDirectories="true" />
}
</PropertyColumn>
<PropertyColumn Property="p => p.WorkingDirectory" Title="Working Directory">
<Input @bind-Value="context.WorkingDirectory" Disabled="@(context.Type == SavePathType.Registry)" />
</PropertyColumn>
<PropertyColumn Property="p => p.IsRegex" Title="Regex">
<Checkbox @bind-Checked="context.IsRegex" Disabled="@(context.Type == SavePathType.Registry)" />
</PropertyColumn>
<ActionColumn>
<Flex Gap="FlexGap.Small" Justify="FlexJustify.End">
<Button OnClick="() => RemovePath(context)" Type="@ButtonType.Text" Danger Icon="@IconType.Outline.Close" />
</Flex>
</ActionColumn>
</Table>
<Flex Justify="FlexJustify.End">
<Button OnClick="AddPath" Type="@ButtonType.Primary">Add Path</Button>
</Flex>
</Flex>
@code {
[Parameter] public ICollection<SavePath> Value { get; set; } = new List<SavePath>();
[Parameter] public EventCallback<ICollection<SavePath>> ValueChanged { get; set; }
[Parameter] public Guid GameId { get; set; }
[Parameter] public Guid ArchiveId { get; set; }
protected override async Task OnInitializedAsync()
{
if (Value == null)
Value = new List<SavePath>();
}
private async Task AddPath()
{
if (Value == null)
Value = new List<SavePath>();
Value.Add(new SavePath()
{
GameId = GameId,
WorkingDirectory = "{InstallDir}"
});
}
private async Task RemovePath(SavePath path)
{
Value.Remove(path);
}
}