Add version field to star entity. Implemented a lot of the star crud
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
@using MoonCore.Blazor.Tailwind.Modals.Components
|
||||
@using MoonlightServers.Shared.Enums
|
||||
@using MoonCore.Blazor.Tailwind.Components
|
||||
@using MoonlightServers.Shared.Models
|
||||
|
||||
@inherits BaseModal
|
||||
|
||||
<h1 class="mb-5 font-semibold text-xl">Add a new parse configuration</h1>
|
||||
|
||||
<HandleForm @ref="HandleForm" Model="Form" OnValidSubmit="OnValidSubmit">
|
||||
<div class="grid grid-cols-2 gap-x-2 gap-y-4">
|
||||
<div class="col-span-1">
|
||||
<label class="block text-sm font-medium leading-6 text-white">File</label>
|
||||
<input @bind="Form.File" type="text" class="form-input w-full"/>
|
||||
</div>
|
||||
|
||||
<div class="col-span-1">
|
||||
<label class="block text-sm font-medium leading-6 text-white">Type</label>
|
||||
<select @bind="Form.Parser" class="form-select w-full">
|
||||
@foreach (var val in Enum.GetValues<FileParsers>())
|
||||
{
|
||||
<option value="@val">@val</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="col-span-2">
|
||||
<button @onclick="AddEntry" class="btn btn-primary w-full">Add entry</button>
|
||||
</div>
|
||||
|
||||
@foreach (var entry in Form.Entries)
|
||||
{
|
||||
<div class="col-span-2">
|
||||
<div class="flex flex-row">
|
||||
<input @bind="entry.Key" placeholder="Key" class="form-input placeholder-gray-500 grow rounded-r-none"/>
|
||||
<input @bind="entry.Value" placeholder="Value" class="form-input placeholder-gray-500 grow rounded-none"/>
|
||||
<button @onclick="() => RemoveEntry(entry)" class="btn btn-danger grow-0 rounded-l-none">
|
||||
<i class="icon-x"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</HandleForm>
|
||||
|
||||
<div class="mt-5 flex space-x-2">
|
||||
<WButton OnClick="_ => Hide()" CssClasses="btn btn-secondary grow">Cancel</WButton>
|
||||
<WButton OnClick="_ => Submit()" CssClasses="btn btn-primary grow">Create</WButton>
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public Func<ParseConfiguration, Task> OnSubmit { get; set; }
|
||||
|
||||
private ParseConfiguration Form = new();
|
||||
private HandleForm HandleForm;
|
||||
|
||||
private async Task OnValidSubmit()
|
||||
{
|
||||
await OnSubmit.Invoke(Form);
|
||||
await Hide();
|
||||
}
|
||||
|
||||
private Task Submit() => HandleForm.Submit();
|
||||
|
||||
private async Task AddEntry()
|
||||
{
|
||||
Form.Entries.Add(new());
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
private async Task RemoveEntry(ParseConfiguration.ParseConfigurationEntry entry)
|
||||
{
|
||||
Form.Entries.Remove(entry);
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
@using MoonCore.Blazor.Tailwind.Modals.Components
|
||||
@using MoonlightServers.Shared.Enums
|
||||
@using MoonlightServers.Shared.Http.Requests.Admin.StarVariables
|
||||
@using MoonlightServers.Frontend.UI.Components.Forms
|
||||
@using MoonCore.Blazor.Tailwind.Components
|
||||
|
||||
@inherits BaseModal
|
||||
|
||||
<h1 class="mb-5 font-semibold text-xl">Add a new variable</h1>
|
||||
|
||||
<HandleForm @ref="HandleForm" Model="Form" OnValidSubmit="OnValidSubmit">
|
||||
<div class="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="Form.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="Form.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="Form.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="Form.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="Form.AllowViewing"/>
|
||||
</div>
|
||||
|
||||
<div class="col-span-1">
|
||||
<label class="block text-sm font-medium leading-6 text-white">Allow Editing</label>
|
||||
<Switch @bind-Value="Form.AllowEditing"/>
|
||||
</div>
|
||||
|
||||
<div class="col-span-1">
|
||||
<label class="block text-sm font-medium leading-6 text-white">Type</label>
|
||||
<select @bind="Form.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="Form.Filter" type="text" class="form-input w-full"/>
|
||||
</div>
|
||||
</div>
|
||||
</HandleForm>
|
||||
|
||||
<div class="mt-5 flex space-x-2">
|
||||
<WButton OnClick="_ => Hide()" CssClasses="btn btn-secondary grow">Cancel</WButton>
|
||||
<WButton OnClick="_ => Submit()" CssClasses="btn btn-primary grow">Create</WButton>
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public Func<CreateStarVariableRequest, Task> OnSubmit { get; set; }
|
||||
|
||||
private CreateStarVariableRequest Form = new();
|
||||
private HandleForm HandleForm;
|
||||
|
||||
private async Task OnValidSubmit()
|
||||
{
|
||||
await OnSubmit.Invoke(Form);
|
||||
await Hide();
|
||||
}
|
||||
|
||||
private Task Submit() => HandleForm.Submit();
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
@using MoonCore.Blazor.Tailwind.Modals.Components
|
||||
@using MoonlightServers.Shared.Enums
|
||||
@using MoonCore.Blazor.Tailwind.Components
|
||||
@using MoonCore.Helpers
|
||||
@using MoonlightServers.Shared.Models
|
||||
|
||||
@inherits BaseModal
|
||||
|
||||
<h1 class="mb-5 font-semibold text-xl">Update parse configuration</h1>
|
||||
|
||||
<HandleForm @ref="HandleForm" Model="Form" OnValidSubmit="OnValidSubmit">
|
||||
<div class="grid grid-cols-2 gap-x-2 gap-y-4">
|
||||
<div class="col-span-1">
|
||||
<label class="block text-sm font-medium leading-6 text-white">File</label>
|
||||
<input @bind="Form.File" type="text" class="form-input w-full"/>
|
||||
</div>
|
||||
|
||||
<div class="col-span-1">
|
||||
<label class="block text-sm font-medium leading-6 text-white">Type</label>
|
||||
<select @bind="Form.Parser" class="form-select w-full">
|
||||
@foreach (var val in Enum.GetValues<FileParsers>())
|
||||
{
|
||||
<option value="@val">@val</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="col-span-2">
|
||||
<button @onclick="AddEntry" class="btn btn-primary w-full">Add entry</button>
|
||||
</div>
|
||||
|
||||
@foreach (var entry in Form.Entries)
|
||||
{
|
||||
<div class="col-span-2">
|
||||
<div class="flex flex-row">
|
||||
<input @bind="entry.Key" placeholder="Key" class="form-input placeholder-gray-500 grow rounded-r-none"/>
|
||||
<input @bind="entry.Value" placeholder="Value" class="form-input placeholder-gray-500 grow rounded-none"/>
|
||||
<button @onclick="() => RemoveEntry(entry)" class="btn btn-danger grow-0 rounded-l-none">
|
||||
<i class="icon-x"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</HandleForm>
|
||||
|
||||
<div class="mt-5 flex space-x-2">
|
||||
<WButton OnClick="_ => Submit()" CssClasses="btn btn-primary grow">Save changes</WButton>
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public Func<ParseConfiguration, Task> OnSubmit { get; set; }
|
||||
[Parameter] public ParseConfiguration Configuration { get; set; }
|
||||
|
||||
private ParseConfiguration Form;
|
||||
private HandleForm HandleForm;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
// Manual mapping :(
|
||||
Form = Configuration;
|
||||
}
|
||||
|
||||
private async Task OnValidSubmit()
|
||||
{
|
||||
await OnSubmit.Invoke(Form);
|
||||
await Hide();
|
||||
}
|
||||
|
||||
private Task Submit() => HandleForm.Submit();
|
||||
|
||||
private async Task AddEntry()
|
||||
{
|
||||
Form.Entries.Add(new());
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
private async Task RemoveEntry(ParseConfiguration.ParseConfigurationEntry entry)
|
||||
{
|
||||
Form.Entries.Remove(entry);
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
@using MoonCore.Blazor.Tailwind.Modals.Components
|
||||
@using MoonlightServers.Shared.Enums
|
||||
@using MoonlightServers.Shared.Http.Requests.Admin.StarVariables
|
||||
@using MoonlightServers.Frontend.UI.Components.Forms
|
||||
@using MoonCore.Blazor.Tailwind.Components
|
||||
@using MoonCore.Helpers
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.StarVariables
|
||||
|
||||
@inherits BaseModal
|
||||
|
||||
<h1 class="mb-5 font-semibold text-xl">Update variable</h1>
|
||||
|
||||
<HandleForm @ref="HandleForm" Model="Form" OnValidSubmit="OnValidSubmit">
|
||||
<div class="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="Form.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="Form.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="Form.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="Form.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="Form.AllowViewing"/>
|
||||
</div>
|
||||
|
||||
<div class="col-span-1">
|
||||
<label class="block text-sm font-medium leading-6 text-white">Allow Editing</label>
|
||||
<Switch @bind-Value="Form.AllowEditing"/>
|
||||
</div>
|
||||
|
||||
<div class="col-span-1">
|
||||
<label class="block text-sm font-medium leading-6 text-white">Type</label>
|
||||
<select @bind="Form.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="Form.Filter" type="text" class="form-input w-full"/>
|
||||
</div>
|
||||
</div>
|
||||
</HandleForm>
|
||||
|
||||
<div class="mt-5 flex space-x-2">
|
||||
<WButton OnClick="_ => Hide()" CssClasses="btn btn-secondary grow">Cancel</WButton>
|
||||
<WButton OnClick="_ => Submit()" CssClasses="btn btn-primary grow">Update</WButton>
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public Func<UpdateStarVariableRequest, Task> OnSubmit { get; set; }
|
||||
[Parameter] public StarVariableDetailResponse Variable { get; set; }
|
||||
|
||||
private UpdateStarVariableRequest Form;
|
||||
private HandleForm HandleForm;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
Form = Mapper.Map<UpdateStarVariableRequest>(Variable);
|
||||
}
|
||||
|
||||
private async Task OnValidSubmit()
|
||||
{
|
||||
await OnSubmit.Invoke(Form);
|
||||
await Hide();
|
||||
}
|
||||
|
||||
private Task Submit() => HandleForm.Submit();
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
@using MoonlightServers.Shared.Http.Requests.Admin.Stars
|
||||
|
||||
<div>
|
||||
<div class="grid grid-cols-1 gap-x-6 gap-y-8 sm:grid-cols-6">
|
||||
<div class="sm:col-span-2">
|
||||
<label class="block text-sm font-medium leading-6 text-white">Name</label>
|
||||
<div class="mt-2">
|
||||
<input @bind="Request.Name" type="text" autocomplete="off" class="form-input w-full">
|
||||
</div>
|
||||
</div>
|
||||
<div class="sm:col-span-2">
|
||||
<label class="block text-sm font-medium leading-6 text-white">Version</label>
|
||||
<div class="mt-2">
|
||||
<input @bind="Request.Version" type="text" autocomplete="off" class="form-input w-full">
|
||||
</div>
|
||||
</div>
|
||||
<div class="sm:col-span-2">
|
||||
<label class="block text-sm font-medium leading-6 text-white">Author</label>
|
||||
<div class="mt-2">
|
||||
<input @bind="Request.Author" type="text" autocomplete="off" class="form-input w-full">
|
||||
</div>
|
||||
</div>
|
||||
<div class="sm:col-span-2">
|
||||
<label class="block text-sm font-medium leading-6 text-white">Donate Url</label>
|
||||
<div class="mt-2">
|
||||
<input @bind="Request.DonateUrl" type="text" autocomplete="off" class="form-input w-full">
|
||||
</div>
|
||||
</div>
|
||||
<div class="sm:col-span-2">
|
||||
<label class="block text-sm font-medium leading-6 text-white">Update Url</label>
|
||||
<div class="mt-2">
|
||||
<input @bind="Request.UpdateUrl" type="text" autocomplete="off" class="form-input w-full">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public UpdateStarRequest Request { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
@using MoonlightServers.Shared.Http.Requests.Admin.Stars
|
||||
<div>
|
||||
<div class="grid grid-cols-1 gap-x-6 gap-y-8 sm:grid-cols-6">
|
||||
<div class="sm:col-span-3">
|
||||
<label class="block text-sm font-medium leading-6 text-white">Docker Image</label>
|
||||
<div class="mt-2">
|
||||
<input @bind="Request.InstallDockerImage" type="text" autocomplete="off" class="form-input w-full">
|
||||
</div>
|
||||
</div>
|
||||
<div class="sm:col-span-3">
|
||||
<label class="block text-sm font-medium leading-6 text-white">Shell</label>
|
||||
<div class="mt-2">
|
||||
<input @bind="Request.InstallShell" type="text" autocomplete="off" class="form-input w-full">
|
||||
</div>
|
||||
</div>
|
||||
<div class="sm:col-span-6">
|
||||
<label class="block text-sm font-medium leading-6 text-white">Script</label>
|
||||
<div class="mt-2">
|
||||
<textarea @bind="Request.InstallScript" class="form-textarea w-full"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public UpdateStarRequest Request { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
@using System.Text.Json
|
||||
@using MoonCore.Blazor.Tailwind.Alerts
|
||||
@using MoonCore.Blazor.Tailwind.Modals
|
||||
@using MoonCore.Blazor.Tailwind.Toasts
|
||||
@using MoonlightServers.Frontend.UI.Components.Stars.Modals
|
||||
@using MoonlightServers.Shared.Http.Requests.Admin.Stars
|
||||
@using MoonlightServers.Shared.Models
|
||||
|
||||
@inject ILogger<ParseConfigStarUpdate> Logger
|
||||
@inject ModalService ModalService
|
||||
@inject AlertService AlertService
|
||||
@inject ToastService ToastService
|
||||
|
||||
<div class="flex justify-end mb-5">
|
||||
<button type="button" @onclick="AddConfig" class="btn btn-primary">Add parse configuration</button>
|
||||
</div>
|
||||
|
||||
@if (HasParseError)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="grid sm:grid-cols-2 xl:grid-cols-3 gap-4">
|
||||
@foreach (var configuration in Configurations)
|
||||
{
|
||||
<div class="col-span-1 card card-body p-2.5">
|
||||
<div class="flex items-center justify-between">
|
||||
<div class="ml-3">
|
||||
<i class="icon-file-cog text-xl align-middle"></i>
|
||||
<span class="align-middle text-lg">@configuration.File</span>
|
||||
</div>
|
||||
|
||||
<div class="gap-x-2">
|
||||
<button @onclick="() => UpdateConfig(configuration)" class="btn btn-primary">
|
||||
<i class="icon-settings text-base"></i>
|
||||
</button>
|
||||
|
||||
<button @onclick="() => DeleteConfig(configuration)" class="btn btn-danger">
|
||||
<i class="icon-trash text-base"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public UpdateStarRequest Request { get; set; }
|
||||
|
||||
private List<ParseConfiguration> Configurations;
|
||||
private bool HasParseError = false;
|
||||
|
||||
protected override Task OnInitializedAsync()
|
||||
{
|
||||
ReadFromJson();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private async Task AddConfig()
|
||||
{
|
||||
Func<ParseConfiguration, Task> onSubmit = async configuration =>
|
||||
{
|
||||
Configurations.Add(configuration);
|
||||
SaveChanges();
|
||||
|
||||
await InvokeAsync(StateHasChanged);
|
||||
await ToastService.Success("Successfully created parse configuration");
|
||||
};
|
||||
|
||||
await ModalService.Launch<CreateParseConfigModal>(parameters =>
|
||||
{
|
||||
parameters.Add("OnSubmit", onSubmit);
|
||||
}, "max-w-xl");
|
||||
}
|
||||
|
||||
private async Task UpdateConfig(ParseConfiguration configuration)
|
||||
{
|
||||
Func<ParseConfiguration, Task> onSubmit = async _ =>
|
||||
{
|
||||
SaveChanges();
|
||||
|
||||
await InvokeAsync(StateHasChanged);
|
||||
await ToastService.Success("Successfully updated parse configuration");
|
||||
};
|
||||
|
||||
await ModalService.Launch<UpdateParseConfigModal>(parameters =>
|
||||
{
|
||||
parameters.Add("OnSubmit", onSubmit);
|
||||
parameters.Add("Configuration", configuration);
|
||||
}, "max-w-xl");
|
||||
}
|
||||
|
||||
private async Task DeleteConfig(ParseConfiguration configuration)
|
||||
{
|
||||
await AlertService.ConfirmDanger(
|
||||
"Parse configuration deletion",
|
||||
"Do you really want to delete the selected parse configuration",
|
||||
async () =>
|
||||
{
|
||||
Configurations.Remove(configuration);
|
||||
SaveChanges();
|
||||
|
||||
await InvokeAsync(StateHasChanged);
|
||||
await ToastService.Success("Successfully deleted parse configuration");
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private void SaveChanges()
|
||||
{
|
||||
Request.ParseConfiguration = JsonSerializer.Serialize(Configurations);
|
||||
ReadFromJson();
|
||||
}
|
||||
|
||||
private void ReadFromJson()
|
||||
{
|
||||
try
|
||||
{
|
||||
Configurations = JsonSerializer.Deserialize<List<ParseConfiguration>>(Request.ParseConfiguration)
|
||||
?? throw new ArgumentNullException();
|
||||
|
||||
HasParseError = false;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogWarning("An error occured while reading parse configuration: {e}", e);
|
||||
HasParseError = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
@using MoonlightServers.Shared.Http.Requests.Admin.Stars
|
||||
<div>
|
||||
<div class="grid grid-cols-1 gap-x-6 gap-y-8 sm:grid-cols-6">
|
||||
<div class="sm:col-span-4">
|
||||
<label class="block text-sm font-medium leading-6 text-white">Startup Command</label>
|
||||
<div class="mt-2">
|
||||
<input @bind="Request.StartupCommand" type="text" autocomplete="off" class="form-input w-full">
|
||||
</div>
|
||||
</div>
|
||||
<div class="sm:col-span-2">
|
||||
<label class="block text-sm font-medium leading-6 text-white">Stop Command</label>
|
||||
<div class="mt-2">
|
||||
<input @bind="Request.StopCommand" type="text" autocomplete="off" class="form-input w-full">
|
||||
</div>
|
||||
</div>
|
||||
<div class="sm:col-span-2">
|
||||
<label class="block text-sm font-medium leading-6 text-white">Online Detection</label>
|
||||
<div class="mt-2">
|
||||
<input @bind="Request.OnlineDetection" type="text" autocomplete="off" class="form-input w-full">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public UpdateStarRequest Request { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
@using MoonCore.Blazor.Tailwind.Alerts
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.Stars
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.StarVariables
|
||||
@using MoonCore.Blazor.Tailwind.Components
|
||||
@using MoonCore.Blazor.Tailwind.Modals
|
||||
@using MoonCore.Blazor.Tailwind.Toasts
|
||||
@using MoonCore.Helpers
|
||||
@using MoonCore.Models
|
||||
@using MoonlightServers.Frontend.UI.Components.Stars.Modals
|
||||
@using MoonlightServers.Shared.Http.Requests.Admin.StarVariables
|
||||
|
||||
@inject HttpApiClient ApiClient
|
||||
@inject ModalService ModalService
|
||||
@inject AlertService AlertService
|
||||
@inject ToastService ToastService
|
||||
|
||||
<div class="flex justify-end mb-5">
|
||||
<button type="button" @onclick="AddVariable" class="btn btn-primary">Add variable</button>
|
||||
</div>
|
||||
|
||||
<LazyLoader @ref="LazyLoader" Load="Load">
|
||||
<div class="grid sm:grid-cols-2 xl:grid-cols-3 gap-4">
|
||||
@foreach (var variable in Variables)
|
||||
{
|
||||
<div class="col-span-1 card card-body p-2.5">
|
||||
<div class="flex items-center justify-between">
|
||||
<div class="ml-3">
|
||||
<i class="icon-variable text-xl align-middle"></i>
|
||||
<span class="align-middle text-lg">@variable.Name</span>
|
||||
</div>
|
||||
|
||||
<div class="gap-x-2">
|
||||
<button @onclick="() => UpdateVariable(variable)" class="btn btn-primary">
|
||||
<i class="icon-settings text-base"></i>
|
||||
</button>
|
||||
|
||||
<button @onclick="() => DeleteVariable(variable)" class="btn btn-danger">
|
||||
<i class="icon-trash text-base"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</LazyLoader>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public StarDetailResponse Star { get; set; }
|
||||
|
||||
private StarVariableDetailResponse[] Variables;
|
||||
private LazyLoader LazyLoader;
|
||||
|
||||
private async Task Load(LazyLoader arg)
|
||||
{
|
||||
var pagedVariables = await ApiClient.GetJson<PagedData<StarVariableDetailResponse>>(
|
||||
$"api/admin/servers/stars/{Star.Id}/variables?page=0&pageSize=50"
|
||||
);
|
||||
|
||||
Variables = pagedVariables.Items;
|
||||
}
|
||||
|
||||
private async Task AddVariable()
|
||||
{
|
||||
Func<CreateStarVariableRequest, Task> onSubmit = async request =>
|
||||
{
|
||||
await ApiClient.Post($"api/admin/servers/stars/{Star.Id}/variables", request);
|
||||
|
||||
await ToastService.Success("Successfully created variable");
|
||||
await LazyLoader.Reload();
|
||||
};
|
||||
|
||||
await ModalService.Launch<CreateStarVariableModal>(parameters =>
|
||||
{
|
||||
parameters.Add("OnSubmit", onSubmit);
|
||||
}, "max-w-xl");
|
||||
}
|
||||
|
||||
private async Task UpdateVariable(StarVariableDetailResponse variable)
|
||||
{
|
||||
Func<UpdateStarVariableRequest, Task> onSubmit = async request =>
|
||||
{
|
||||
await ApiClient.Patch($"api/admin/servers/stars/{Star.Id}/variables/{variable.Id}", request);
|
||||
|
||||
await ToastService.Success("Successfully updated variable");
|
||||
await LazyLoader.Reload();
|
||||
};
|
||||
|
||||
await ModalService.Launch<UpdateStarVariableModel>(parameters =>
|
||||
{
|
||||
parameters.Add("OnSubmit", onSubmit);
|
||||
parameters.Add("Variable", variable);
|
||||
}, "max-w-xl");
|
||||
}
|
||||
|
||||
private async Task DeleteVariable(StarVariableDetailResponse variable)
|
||||
{
|
||||
await AlertService.ConfirmDanger(
|
||||
"Delete variable",
|
||||
"Do you really want to delete the selected variable? This cannot be undone",
|
||||
async () =>
|
||||
{
|
||||
await ApiClient.Delete($"api/admin/servers/stars/{Star.Id}/variables/{variable.Id}");
|
||||
|
||||
await ToastService.Success("Successfully deleted variable");
|
||||
await LazyLoader.Reload();
|
||||
}
|
||||
);
|
||||
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user