104 lines
3.1 KiB
Plaintext
104 lines
3.1 KiB
Plaintext
@using Moonlight.Frontend.Helpers
|
|
@using MoonlightServers.Shared
|
|
@using MoonlightServers.Shared.Admin.Templates
|
|
@using ShadcnBlazor.Dialogs
|
|
@using ShadcnBlazor.Buttons
|
|
@using ShadcnBlazor.Extras.Forms
|
|
@using ShadcnBlazor.Extras.Toasts
|
|
@using ShadcnBlazor.Fields
|
|
@using ShadcnBlazor.Inputs
|
|
|
|
@inherits ShadcnBlazor.Extras.Dialogs.DialogBase
|
|
|
|
@inject HttpClient HttpClient
|
|
@inject ToastService ToastService
|
|
|
|
<DialogHeader>
|
|
<DialogTitle>Create Variable</DialogTitle>
|
|
<DialogDescription>
|
|
Create a new variable
|
|
</DialogDescription>
|
|
</DialogHeader>
|
|
<EnhancedEditForm @ref="Form" Model="Model" OnValidSubmit="OnValidSubmitAsync">
|
|
<FieldGroup>
|
|
<DataAnnotationsValidator/>
|
|
<FormValidationSummary/>
|
|
|
|
<FieldSet>
|
|
<Field>
|
|
<FieldLabel for="variableDisplayName">Display Name</FieldLabel>
|
|
<TextInputField
|
|
@bind-Value="Model.DisplayName"
|
|
id="variableDisplayName"/>
|
|
</Field>
|
|
|
|
<Field>
|
|
<FieldLabel for="variableDescription">Description</FieldLabel>
|
|
<TextareaInputField
|
|
@bind-Value="Model.Description"
|
|
id="variableDescription"/>
|
|
</Field>
|
|
|
|
<Field>
|
|
<FieldLabel for="variableKey">Key</FieldLabel>
|
|
<TextInputField
|
|
@bind-Value="Model.EnvName"
|
|
id="variableKey"/>
|
|
</Field>
|
|
|
|
<Field>
|
|
<FieldLabel for="variableDefaultValue">Default Value</FieldLabel>
|
|
<TextInputField
|
|
@bind-Value="Model.DefaultValue"
|
|
id="variableDefaultValue"/>
|
|
</Field>
|
|
</FieldSet>
|
|
</FieldGroup>
|
|
</EnhancedEditForm>
|
|
<DialogFooter>
|
|
<DialogClose>
|
|
<Slot>
|
|
<Button Type="button" Variant="ButtonVariant.Outline" @attributes="context">
|
|
Cancel
|
|
</Button>
|
|
</Slot>
|
|
</DialogClose>
|
|
<Button @onclick="() => Form.SubmitAsync()" Type="button">
|
|
Save
|
|
</Button>
|
|
</DialogFooter>
|
|
|
|
@code
|
|
{
|
|
[Parameter] public DetailedTemplateDto Template { get; set; }
|
|
[Parameter] public Func<Task> OnSubmit { get; set; }
|
|
|
|
private CreateVariableDto Model = new();
|
|
private EnhancedEditForm Form;
|
|
|
|
private async Task<bool> OnValidSubmitAsync(EditContext editContext, ValidationMessageStore validationMessageStore)
|
|
{
|
|
var response = await HttpClient.PostAsJsonAsync(
|
|
$"api/admin/servers/templates/{Template.Id}/variables",
|
|
Model,
|
|
SerializationContext.Default.Options
|
|
);
|
|
|
|
if (!response.IsSuccessStatusCode)
|
|
{
|
|
await ProblemDetailsHelper.HandleProblemDetailsAsync(response, Model, validationMessageStore);
|
|
return false;
|
|
}
|
|
|
|
await OnSubmit.Invoke();
|
|
|
|
await ToastService.SuccessAsync(
|
|
"Variable Creation",
|
|
$"Successfully created variable {Model.DisplayName}"
|
|
);
|
|
|
|
await CloseAsync();
|
|
return true;
|
|
}
|
|
}
|