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

76 lines
2.6 KiB
Text
Raw Permalink Normal View History

@inject GameService GameService
<Flex Vertical Gap="FlexGap.Large">
<Table TItem="SavePath" DataSource="@SavePaths" 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">
2025-03-13 20:54:31 -05:00
<FilePicker @bind-Value="context.WorkingDirectory" Disabled="@(context.Type == SavePathType.Registry)" ArchiveId="@ArchiveId" AllowDirectories Title="Select Working Directory" />
</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 Guid GameId { get; set; }
[Parameter] public Guid ArchiveId { get; set; }
ICollection<SavePath> SavePaths = new List<SavePath>();
protected override async Task OnInitializedAsync()
{
2025-02-09 15:08:47 -06:00
var game = await GameService.Include(g => g.SavePaths).GetAsync(GameId);
2025-02-09 15:08:47 -06:00
if (game.SavePaths != null)
SavePaths = game.SavePaths;
}
async Task AddPath()
{
SavePaths.Add(new SavePath()
{
GameId = GameId,
WorkingDirectory = "{InstallDir}"
});
}
async Task RemovePath(SavePath path)
{
SavePaths.Remove(path);
}
public async Task Save()
{
2025-02-09 15:08:47 -06:00
var game = await GameService.Include(g => g.SavePaths).GetAsync(GameId);
game.SavePaths = SavePaths;
await GameService.UpdateAsync(game);
}
}