LANCommander/LANCommander.Server/UI/Pages/Servers/Components/ServerHttpPathEditor.razor

76 lines
2.6 KiB
Text

@using LANCommander.Server.Data.Models
@using LANCommander.Server.Extensions;
@inject NavigationManager NavigationManager
<Flex Vertical Gap="FlexGap.Large">
<Table TItem="ServerHttpPath" DataSource="@Values" HidePagination="true" Responsive>
<PropertyColumn Property="p => p.LocalPath" Title="Local Path">
<FilePicker @bind-Value="context.LocalPath" AllowDirectories Title="Select Local Path" Root="@WorkingDirectory" />
</PropertyColumn>
<PropertyColumn Property="p => p.Path">
<Input Type="InputType.Text" @bind-Value="context.Path" />
</PropertyColumn>
<ActionColumn>
<Space Style="display: flex; justify-content: end">
@if (context != null && context.Id != Guid.Empty)
{
<SpaceItem>
<a class="ant-btn ant-btn-text ant-btn-icon-only" href="@NavigationManager.ToAbsoluteUri($"Server/{ServerId}/{context.Path.TrimStart('/')}")" target="_blank">
<Icon Type="@IconType.Outline.Eye" />
</a>
</SpaceItem>
}
<SpaceItem>
<Button OnClick="() => Remove(context)" Type="@ButtonType.Text" Danger Icon="@IconType.Outline.Close" />
</SpaceItem>
</Space>
</ActionColumn>
</Table>
<Flex Justify="FlexJustify.End">
<Button OnClick="Add" Type="@ButtonType.Primary">Add Path</Button>
</Flex>
</Flex>
@code {
[Parameter] public ICollection<ServerHttpPath> Values { get; set; }
[Parameter] public EventCallback<ICollection<ServerHttpPath>> ValuesChanged { get; set; }
[Parameter] public Guid ServerId { get; set; }
[Parameter] public string WorkingDirectory { get; set; }
protected override async Task OnInitializedAsync()
{
if (Values == null)
Values = new List<ServerHttpPath>();
if (ValuesChanged.HasDelegate)
await ValuesChanged.InvokeAsync(Values);
StateHasChanged();
}
private async Task Add()
{
if (Values == null)
Values = new List<ServerHttpPath>();
Values.Add(new ServerHttpPath
{
ServerId = ServerId
});
if (ValuesChanged.HasDelegate)
await ValuesChanged.InvokeAsync(Values);
StateHasChanged();
}
private async Task Remove(ServerHttpPath httpPath)
{
Values.Remove(httpPath);
if (ValuesChanged.HasDelegate)
await ValuesChanged.InvokeAsync(Values);
StateHasChanged();
}
}