LANCommander/LANCommander.Server/UI/Pages/Games/Components/SavePathEditor.razor
2024-08-12 00:15:16 -05:00

77 lines
2.8 KiB
Text

@using LANCommander.SDK.Enums
@using LANCommander.Server.Extensions;
<Space Direction="DirectionVHType.Vertical" Size="@("large")" Style="width: 100%">
<SpaceItem>
<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>
<Space Style="display: flex; justify-content: end">
<SpaceItem>
<Button OnClick="() => RemovePath(context)" Type="@ButtonType.Text" Danger Icon="@IconType.Outline.Close" />
</SpaceItem>
</Space>
</ActionColumn>
</Table>
</SpaceItem>
<SpaceItem>
<GridRow Justify="end">
<GridCol>
<Button OnClick="AddPath" Type="@ButtonType.Primary">Add Path</Button>
</GridCol>
</GridRow>
</SpaceItem>
</Space>
@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);
}
}