Implemented template crud, db entities, import/export, ptero and pelican import
This commit is contained in:
132
MoonlightServers.Frontend/Admin/Templates/Create.razor
Normal file
132
MoonlightServers.Frontend/Admin/Templates/Create.razor
Normal file
@@ -0,0 +1,132 @@
|
||||
@page "/admin/servers/templates/create"
|
||||
|
||||
@using LucideBlazor
|
||||
@using Moonlight.Frontend.Helpers
|
||||
@using MoonlightServers.Shared
|
||||
@using MoonlightServers.Shared.Admin.Templates
|
||||
@using ShadcnBlazor.Buttons
|
||||
@using ShadcnBlazor.Cards
|
||||
@using ShadcnBlazor.Extras.Forms
|
||||
@using ShadcnBlazor.Extras.Toasts
|
||||
@using ShadcnBlazor.Fields
|
||||
@using ShadcnBlazor.Inputs
|
||||
@using ShadcnBlazor.Tab
|
||||
|
||||
@inject HttpClient HttpClient
|
||||
@inject NavigationManager Navigation
|
||||
@inject ToastService ToastService
|
||||
|
||||
<EnhancedEditForm Model="Request" OnValidSubmit="OnSubmitAsync" Context="formContext">
|
||||
|
||||
<div class="flex flex-row justify-between">
|
||||
<div class="flex flex-col">
|
||||
<h1 class="text-xl font-semibold">Create Template</h1>
|
||||
<div class="text-muted-foreground">
|
||||
Create a new template
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-row gap-x-1.5">
|
||||
<Button Variant="ButtonVariant.Secondary">
|
||||
<Slot>
|
||||
<a href="/admin/servers?tab=templates" @attributes="context">
|
||||
<ChevronLeftIcon/>
|
||||
Back
|
||||
</a>
|
||||
</Slot>
|
||||
</Button>
|
||||
<SubmitButton>
|
||||
<CheckIcon/>
|
||||
Continue
|
||||
</SubmitButton>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<DataAnnotationsValidator/>
|
||||
|
||||
<div class="mt-8">
|
||||
<Card>
|
||||
<CardContent>
|
||||
<FieldGroup>
|
||||
<FormValidationSummary/>
|
||||
|
||||
<FieldSet>
|
||||
<FieldGroup>
|
||||
<div class="grid grid-cols-1 lg:grid-cols-2 xl:grid-cols-3 gap-8">
|
||||
<Field>
|
||||
<FieldLabel for="templateName">Name</FieldLabel>
|
||||
<TextInputField
|
||||
@bind-Value="Request.Name"
|
||||
id="templateName"/>
|
||||
</Field>
|
||||
|
||||
<Field>
|
||||
<FieldLabel for="templateAuthor">Author</FieldLabel>
|
||||
<TextInputField
|
||||
@bind-Value="Request.Author"
|
||||
id="templateAuthor"/>
|
||||
</Field>
|
||||
|
||||
<Field>
|
||||
<FieldLabel for="templateVersion">Version</FieldLabel>
|
||||
<TextInputField
|
||||
@bind-Value="Request.Version"
|
||||
id="templateVersion"/>
|
||||
</Field>
|
||||
|
||||
<Field ClassName="col-span-1 lg:col-span-2 xl:col-span-3">
|
||||
<FieldLabel for="templateDescription">Description</FieldLabel>
|
||||
<TextareaInputField
|
||||
@bind-Value="Request.Description"
|
||||
id="templateDescription"/>
|
||||
</Field>
|
||||
|
||||
<Field>
|
||||
<FieldLabel for="templateDonateUrl">Donate URL</FieldLabel>
|
||||
<TextInputField
|
||||
@bind-Value="Request.DonateUrl"
|
||||
id="templateDonateUrl"/>
|
||||
</Field>
|
||||
|
||||
<Field>
|
||||
<FieldLabel for="templateUpdateUrl">Update URL</FieldLabel>
|
||||
<TextInputField
|
||||
@bind-Value="Request.UpdateUrl"
|
||||
id="templateUpdateUrl"/>
|
||||
</Field>
|
||||
</div>
|
||||
</FieldGroup>
|
||||
</FieldSet>
|
||||
</FieldGroup>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
</EnhancedEditForm>
|
||||
|
||||
@code
|
||||
{
|
||||
private CreateTemplateDto Request = new();
|
||||
|
||||
private async Task<bool> OnSubmitAsync(EditContext context, ValidationMessageStore validationMessageStore)
|
||||
{
|
||||
var response = await HttpClient.PostAsJsonAsync(
|
||||
"/api/admin/servers/templates",
|
||||
Request,
|
||||
SerializationContext.Default.Options
|
||||
);
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
await ProblemDetailsHelper.HandleProblemDetailsAsync(response, Request, validationMessageStore);
|
||||
return false;
|
||||
}
|
||||
|
||||
await ToastService.SuccessAsync(
|
||||
"Template Creation",
|
||||
$"Successfully created template {Request.Name}"
|
||||
);
|
||||
|
||||
Navigation.NavigateTo("/admin/servers?tab=templates");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user