85 lines
2.7 KiB
Plaintext
85 lines
2.7 KiB
Plaintext
@using Moonlight.Frontend.Infrastructure.Helpers
|
|
@using MoonlightServers.Shared
|
|
@using MoonlightServers.Shared.Admin.Nodes
|
|
@using ShadcnBlazor.Cards
|
|
@using ShadcnBlazor.Extras.Forms
|
|
@using ShadcnBlazor.Extras.Toasts
|
|
@using ShadcnBlazor.Fields
|
|
@using ShadcnBlazor.Inputs
|
|
|
|
@inject HttpClient HttpClient
|
|
@inject ToastService ToastService
|
|
|
|
<EnhancedEditForm Model="Request" OnValidSubmit="OnSubmitAsync" Context="formContext">
|
|
<Card>
|
|
<CardContent>
|
|
<DataAnnotationsValidator/>
|
|
|
|
<FieldGroup>
|
|
<FormValidationSummary/>
|
|
|
|
<FieldSet>
|
|
<FieldGroup>
|
|
<div class="grid grid-cols-1 lg:grid-cols-2 xl:grid-cols-3 gap-8">
|
|
<Field>
|
|
<FieldLabel for="nodeName">Name</FieldLabel>
|
|
<TextInputField
|
|
@bind-Value="Request.Name"
|
|
id="nodeName"/>
|
|
</Field>
|
|
|
|
<Field>
|
|
<FieldLabel for="nodeHttpEndpoint">HTTP Endpoint</FieldLabel>
|
|
<TextInputField
|
|
@bind-Value="Request.HttpEndpointUrl"
|
|
id="nodeHttpEndpoint"
|
|
placeholder="http://example.com:8080"/>
|
|
</Field>
|
|
</div>
|
|
</FieldGroup>
|
|
</FieldSet>
|
|
</FieldGroup>
|
|
</CardContent>
|
|
<CardFooter ClassName="justify-end">
|
|
<SubmitButton>Save changes</SubmitButton>
|
|
</CardFooter>
|
|
</Card>
|
|
</EnhancedEditForm>
|
|
|
|
@code
|
|
{
|
|
[Parameter, EditorRequired] public NodeDto Node { get; set; }
|
|
|
|
private UpdateNodeDto Request;
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
Request = new UpdateNodeDto()
|
|
{
|
|
Name = Node.Name,
|
|
HttpEndpointUrl = Node.HttpEndpointUrl
|
|
};
|
|
}
|
|
|
|
private async Task<bool> OnSubmitAsync(EditContext context, ValidationMessageStore validationMessageStore)
|
|
{
|
|
var response = await HttpClient.PutAsJsonAsync(
|
|
$"/api/admin/servers/nodes/{Node.Id}",
|
|
Request,
|
|
SerializationContext.Default.Options
|
|
);
|
|
|
|
if (!response.IsSuccessStatusCode)
|
|
{
|
|
await ProblemDetailsHelper.HandleProblemDetailsAsync(response, Request, validationMessageStore);
|
|
return false;
|
|
}
|
|
|
|
await ToastService.SuccessAsync(
|
|
"Node Update",
|
|
$"Successfully updated node {Request.Name}"
|
|
);
|
|
|
|
return true;
|
|
}
|
|
} |