Created some request models. Started building create star form together
This commit is contained in:
@@ -20,7 +20,7 @@
|
||||
<ItemGroup>
|
||||
<Folder Include="Helpers\"/>
|
||||
<Folder Include="Interfaces\"/>
|
||||
<Folder Include="UI\Components\"/>
|
||||
<Folder Include="UI\Views\Admin\All\" />
|
||||
<Folder Include="wwwroot\"/>
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
using MoonCore.Blazor.Tailwind.Forms;
|
||||
using MoonCore.Blazor.Tailwind.Forms.Components;
|
||||
using Moonlight.Client;
|
||||
|
||||
FormComponentRepository.Set<bool, SwitchComponent>();
|
||||
|
||||
var startup = new Startup();
|
||||
|
||||
await startup.Run(args, [
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=fallback');
|
||||
@import url('https://fonts.googleapis.com/css2?family=Source+Code+Pro:ital,wght@0,200..900;1,200..900&display=swap');
|
||||
@import url("https://cdn.jsdelivr.net/npm/lucide-static@0.460.0/font/lucide.css");
|
||||
0
MoonlightServers.Frontend/Styles/build.sh
Normal file → Executable file
0
MoonlightServers.Frontend/Styles/build.sh
Normal file → Executable file
@@ -2,7 +2,6 @@
|
||||
@import "tailwindcss/components";
|
||||
|
||||
@import "additions/animations.css";
|
||||
@import "additions/fonts.css";
|
||||
@import "additions/buttons.css";
|
||||
@import "additions/cards.css";
|
||||
@import "additions/progress.css";
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
@using MoonCore.Blazor.Tailwind.Forms
|
||||
@using MoonlightServers.Shared.Enums
|
||||
|
||||
@typeparam TPropertyType where TPropertyType : class, MoonlightServers.Shared.Interfaces.IStarVariable
|
||||
@inherits BaseFormComponent<List<TPropertyType>>
|
||||
|
||||
<div class="flex justify-end mb-5">
|
||||
<button type="button" @onclick="AddVariable" class="btn btn-primary">Add variable</button>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
@foreach (var variable in Binder.Value)
|
||||
{
|
||||
<div class="col-span-1 card p-0">
|
||||
<div class="card-body grid grid-cols-2 gap-2">
|
||||
|
||||
<div class="col-span-1">
|
||||
<label class="block text-sm font-medium leading-6 text-white">Name</label>
|
||||
<input @bind="variable.Name" type="text" class="form-input w-full"/>
|
||||
</div>
|
||||
|
||||
<div class="col-span-1">
|
||||
<label class="block text-sm font-medium leading-6 text-white">Description</label>
|
||||
<input @bind="variable.Description" type="text" class="form-input w-full"/>
|
||||
</div>
|
||||
|
||||
<div class="col-span-1">
|
||||
<label class="block text-sm font-medium leading-6 text-white">Key</label>
|
||||
<input @bind="variable.Key" type="text" class="form-input w-full"/>
|
||||
</div>
|
||||
|
||||
<div class="col-span-1">
|
||||
<label class="block text-sm font-medium leading-6 text-white">Default Value</label>
|
||||
<input @bind="variable.DefaultValue" type="text" class="form-input w-full"/>
|
||||
</div>
|
||||
|
||||
<div class="col-span-1">
|
||||
<label class="block text-sm font-medium leading-6 text-white">Allow Viewing</label>
|
||||
<Switch @bind-Value="variable.AllowViewing" />
|
||||
</div>
|
||||
|
||||
<div class="col-span-1">
|
||||
<label class="block text-sm font-medium leading-6 text-white">Allow Editing</label>
|
||||
<Switch @bind-Value="variable.AllowEditing" />
|
||||
</div>
|
||||
|
||||
<div class="col-span-1">
|
||||
<label class="block text-sm font-medium leading-6 text-white">Type</label>
|
||||
<select @bind="variable.Type" class="form-select w-full">
|
||||
@foreach (var val in Enum.GetValues<StarVariableType>())
|
||||
{
|
||||
<option value="@val">@val</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="col-span-1">
|
||||
<label class="block text-sm font-medium leading-6 text-white">Filter</label>
|
||||
<input @bind="variable.Filter" type="text" class="form-input w-full"/>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
|
||||
<div class="flex justify-end mx-2">
|
||||
<button @onclick="() => DeleteVariable(variable)" class="btn btn-danger">
|
||||
<i class="icon-trash mr-2"></i>
|
||||
Remove
|
||||
</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
private async Task AddVariable()
|
||||
{
|
||||
Binder.Value.Add(Activator.CreateInstance<TPropertyType>());
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
private async Task DeleteVariable(TPropertyType variable)
|
||||
{
|
||||
Binder.Value.Remove(variable);
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
}
|
||||
38
MoonlightServers.Frontend/UI/Components/Forms/Switch.razor
Normal file
38
MoonlightServers.Frontend/UI/Components/Forms/Switch.razor
Normal file
@@ -0,0 +1,38 @@
|
||||
@using System.Diagnostics.CodeAnalysis
|
||||
@using Microsoft.AspNetCore.Components
|
||||
|
||||
@* TODO: Extract to mooncore? *@
|
||||
|
||||
@inherits InputBase<bool>
|
||||
|
||||
<div class="flex items-center">
|
||||
<div class="form-switch">
|
||||
<input @bind="CurrentValue" type="checkbox" id="@("switch-" + GetHashCode())" class="sr-only">
|
||||
<label class="bg-gray-700" for="switch-@(GetHashCode())">
|
||||
<span class="bg-white shadow-sm" aria-hidden="true"></span>
|
||||
<span class="sr-only">Switch label</span>
|
||||
</label>
|
||||
</div>
|
||||
<div class="text-sm text-gray-500 italic ml-2">
|
||||
@if (CurrentValue)
|
||||
{
|
||||
<span>On</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span>
|
||||
Off
|
||||
</span>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
protected override bool TryParseValueFromString(string? value, out bool result, [NotNullWhen(false)] out string? validationErrorMessage)
|
||||
{
|
||||
validationErrorMessage = null;
|
||||
result = string.Equals(value, "true", StringComparison.OrdinalIgnoreCase);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,2 +1,6 @@
|
||||
@page "/admin/servers"
|
||||
|
||||
@using MoonCore.Blazor.Tailwind.Components
|
||||
|
||||
<NavTabs Index="0" Names="@UiConstants.AdminNavNames" Links="@UiConstants.AdminNavLinks"/>
|
||||
|
||||
|
||||
@@ -4,17 +4,19 @@
|
||||
@using MoonCore.Blazor.Tailwind.Forms
|
||||
@using MoonCore.Blazor.Tailwind.Toasts
|
||||
@using MoonCore.Helpers
|
||||
@using MoonlightServers.Frontend.UI.Components.Forms
|
||||
@using MoonlightServers.Shared.Http.Requests.Admin.Stars
|
||||
@using MoonlightServers.Shared.Http.Requests.Admin.StarVariables
|
||||
|
||||
@inject HttpApiClient ApiClient
|
||||
@inject NavigationManager Navigation
|
||||
@inject ToastService ToastService
|
||||
|
||||
<PageHeader Title="Create Star">
|
||||
<WButton OnClick="_ => GoBack()" CssClasses="btn btn-secondary">
|
||||
<button @onclick="GoBack" class="btn btn-secondary">
|
||||
<i class="icon-chevron-left mr-1"></i>
|
||||
Back
|
||||
</WButton>
|
||||
</button>
|
||||
<WButton OnClick="_ => Form.Submit()" CssClasses="btn btn-primary">
|
||||
<i class="icon-check mr-1"></i>
|
||||
Create
|
||||
@@ -40,7 +42,46 @@
|
||||
|
||||
private void OnConfigure(FormConfiguration<CreateStarRequest> configuration)
|
||||
{
|
||||
var generalPage = configuration.WithPage("General");
|
||||
|
||||
generalPage.WithField(x => x.Name);
|
||||
generalPage.WithField(x => x.Author);
|
||||
generalPage.WithField(x => x.DonateUrl);
|
||||
generalPage.WithField(x => x.UpdateUrl);
|
||||
|
||||
var startStopStatusPage = configuration.WithPage("Start, Stop & Status");
|
||||
|
||||
startStopStatusPage.WithField(x => x.StartupCommand);
|
||||
startStopStatusPage.WithField(x => x.StopCommand);
|
||||
startStopStatusPage.WithField(x => x.OnlineDetection);
|
||||
|
||||
var installationPage = configuration.WithPage("Installation");
|
||||
|
||||
installationPage.WithField(x => x.InstallShell);
|
||||
installationPage.WithField(x => x.InstallDockerImage);
|
||||
|
||||
installationPage.WithField(x => x.InstallScript, fieldConfiguration =>
|
||||
{
|
||||
fieldConfiguration.Columns = 6;
|
||||
});
|
||||
|
||||
var parseConfigurationPage = configuration.WithPage("Parse configuration");
|
||||
|
||||
parseConfigurationPage.WithField(x => x.ParseConfiguration);
|
||||
|
||||
var variablesPage = configuration.WithPage("Variables");
|
||||
|
||||
variablesPage.WithField(x => x.Variables, fieldConfiguration =>
|
||||
{
|
||||
fieldConfiguration.Columns = 6;
|
||||
fieldConfiguration.Label = "";
|
||||
})
|
||||
.WithComponent<StarVariableComponent<CreateStarVariableRequest>>();
|
||||
|
||||
var miscPage = configuration.WithPage("Miscellaneous");
|
||||
|
||||
miscPage.WithField(x => x.AllowDockerImageChange);
|
||||
miscPage.WithField(x => x.RequiredAllocations);
|
||||
}
|
||||
|
||||
private async Task OnSubmit()
|
||||
|
||||
@@ -5,9 +5,14 @@
|
||||
@using MoonCore.Models
|
||||
@using MoonCore.Blazor.Tailwind.DataTable
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.Stars
|
||||
@using MoonCore.Blazor.Tailwind.Components
|
||||
|
||||
@inject HttpApiClient ApiClient
|
||||
|
||||
<div class="mb-3">
|
||||
<NavTabs Index="3" Names="@UiConstants.AdminNavNames" Links="@UiConstants.AdminNavLinks"/>
|
||||
</div>
|
||||
|
||||
<MinimalCrud TItem="StarDetailResponse" OnConfigure="OnConfigure">
|
||||
<ChildContent>
|
||||
<DataColumn TItem="StarDetailResponse" Field="@(x => x.Id)" Title="Id" IsSortable="true"/>
|
||||
|
||||
6
MoonlightServers.Frontend/UI/_Imports.razor
Normal file
6
MoonlightServers.Frontend/UI/_Imports.razor
Normal file
@@ -0,0 +1,6 @@
|
||||
@using System.Net.Http
|
||||
@using Microsoft.AspNetCore.Authorization
|
||||
@using Microsoft.AspNetCore.Components.Forms
|
||||
@using Microsoft.AspNetCore.Components.Routing
|
||||
@using Microsoft.AspNetCore.Components.Web
|
||||
@using Microsoft.JSInterop
|
||||
7
MoonlightServers.Frontend/UiConstants.cs
Normal file
7
MoonlightServers.Frontend/UiConstants.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace MoonlightServers.Frontend;
|
||||
|
||||
public static class UiConstants
|
||||
{
|
||||
public static readonly string[] AdminNavNames = ["Overview", "Servers", "Nodes", "Stars", "Manager"];
|
||||
public static readonly string[] AdminNavLinks = ["/admin/servers", "/admin/servers/all", "/admin/servers/nodes", "/admin/servers/stars", "/admin/servers/manager"];
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using MoonlightServers.Shared.Enums;
|
||||
using MoonlightServers.Shared.Interfaces;
|
||||
|
||||
namespace MoonlightServers.Shared.Http.Requests.Admin.StarVariables;
|
||||
|
||||
public class CreateStarVariableRequest : IStarVariable
|
||||
{
|
||||
[Required(ErrorMessage = "You need to specify a variable name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
[Required(ErrorMessage = "You need to specify a variable description", AllowEmptyStrings = true)]
|
||||
public string Description { get; set; } = "";
|
||||
|
||||
[Required(ErrorMessage = "You need to specify a variable key")]
|
||||
public string Key { get; set; }
|
||||
|
||||
[Required(ErrorMessage = "You need to specify a variable default value", AllowEmptyStrings = true)]
|
||||
public string DefaultValue { get; set; } = "";
|
||||
|
||||
public bool AllowViewing { get; set; }
|
||||
public bool AllowEditing { get; set; }
|
||||
|
||||
public StarVariableType Type { get; set; } = StarVariableType.Text;
|
||||
public string? Filter { get; set; } = null;
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using MoonlightServers.Shared.Http.Requests.Admin.StarVariables;
|
||||
|
||||
namespace MoonlightServers.Shared.Http.Requests.Admin.Stars;
|
||||
|
||||
@@ -42,4 +43,6 @@ public class CreateStarRequest
|
||||
|
||||
[Required(ErrorMessage = "You need to provide parse configuration")]
|
||||
public string ParseConfiguration { get; set; } = "[]";
|
||||
|
||||
public List<CreateStarVariableRequest> Variables { get; set; } = new();
|
||||
}
|
||||
20
MoonlightServers.Shared/Interfaces/IStarVariable.cs
Normal file
20
MoonlightServers.Shared/Interfaces/IStarVariable.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using MoonlightServers.Shared.Enums;
|
||||
|
||||
namespace MoonlightServers.Shared.Interfaces;
|
||||
|
||||
public interface IStarVariable // For a common abstraction between create and update model to use in a shared form component
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
public string Description { get; set; }
|
||||
|
||||
public string Key { get; set; }
|
||||
|
||||
public string DefaultValue { get; set; }
|
||||
|
||||
public bool AllowViewing { get; set; }
|
||||
public bool AllowEditing { get; set; }
|
||||
|
||||
public StarVariableType Type { get; set; }
|
||||
public string? Filter { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user