Updated the usage of mooncore components
This commit is contained in:
@@ -1,24 +1,20 @@
|
||||
@page "/admin/servers/stars/create"
|
||||
|
||||
@using Microsoft.AspNetCore.Components.Authorization
|
||||
@using MoonCore.Blazor.Tailwind.Components
|
||||
@using MoonCore.Blazor.Tailwind.Forms
|
||||
@using MoonCore.Blazor.Tailwind.Toasts
|
||||
@using MoonCore.Helpers
|
||||
@using Moonlight.Client.Services
|
||||
@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
|
||||
@inject IdentityService IdentityService
|
||||
|
||||
<PageHeader Title="Create Star">
|
||||
<button @onclick="GoBack" class="btn btn-secondary">
|
||||
<a href="/admin/servers/stars" class="btn btn-secondary">
|
||||
<i class="icon-chevron-left mr-1"></i>
|
||||
Back
|
||||
</button>
|
||||
</a>
|
||||
<WButton OnClick="_ => Form.Submit()" CssClasses="btn btn-primary">
|
||||
<i class="icon-check mr-1"></i>
|
||||
Create
|
||||
@@ -27,42 +23,43 @@
|
||||
|
||||
<div class="mt-5">
|
||||
<HandleForm @ref="Form" Model="Request" OnValidSubmit="OnSubmit">
|
||||
<GeneratedForm TForm="CreateStarRequest" Model="Request" OnConfigure="OnConfigure"/>
|
||||
<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">Author</label>
|
||||
<div class="mt-2">
|
||||
<input @bind="Request.Author" type="text" autocomplete="off" class="form-input w-full">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</HandleForm>
|
||||
</div>
|
||||
|
||||
@code
|
||||
|
||||
{
|
||||
[CascadingParameter] public Task<AuthenticationState> AuthState { get; set; }
|
||||
|
||||
private HandleForm Form;
|
||||
private CreateStarRequest Request;
|
||||
|
||||
protected override void OnInitialized()
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
Request = new();
|
||||
}
|
||||
|
||||
private void OnConfigure(FormConfiguration<CreateStarRequest> configuration)
|
||||
{
|
||||
configuration.WithField(x => x.Name);
|
||||
|
||||
configuration.WithField(x => x.Author, fieldConfiguration =>
|
||||
{
|
||||
fieldConfiguration.DefaultValue = IdentityService.Email;
|
||||
});
|
||||
var authState = await AuthState;
|
||||
Request.Author = authState.User.Claims.First(x => x.Type == "email").Value;
|
||||
}
|
||||
|
||||
private async Task OnSubmit()
|
||||
{
|
||||
await ApiClient.Post("api/admin/servers/stars", Request);
|
||||
|
||||
await ToastService.Success("Successfully created Star");
|
||||
await GoBack();
|
||||
}
|
||||
|
||||
private Task GoBack()
|
||||
{
|
||||
Navigation.NavigateTo(ComponentHelper.GetRouteOfComponent<Index>()!);
|
||||
return Task.CompletedTask;
|
||||
await ToastService.Success("Successfully created star");
|
||||
Navigation.NavigateTo("/admin/servers/stars");
|
||||
}
|
||||
}
|
||||
@@ -1,84 +1,110 @@
|
||||
@page "/admin/servers/stars"
|
||||
|
||||
@using MoonCore.Blazor.Tailwind.MinimalCrud
|
||||
@using MoonCore.Blazor.Tailwind.Alerts
|
||||
@using MoonCore.Helpers
|
||||
@using MoonCore.Models
|
||||
@using MoonCore.Blazor.Tailwind.DataTable
|
||||
@using MoonlightServers.Shared.Http.Responses.Admin.Stars
|
||||
@using MoonCore.Blazor.Tailwind.Components
|
||||
@using MoonCore.Blazor.Tailwind.Dt
|
||||
@using MoonCore.Blazor.Tailwind.Services
|
||||
@using MoonCore.Blazor.Tailwind.Toasts
|
||||
@using MoonCore.Exceptions
|
||||
@using Moonlight.Client.Services
|
||||
|
||||
@inject HttpApiClient ApiClient
|
||||
@inject DownloadService DownloadService
|
||||
@inject ToastService ToastService
|
||||
@inject AlertService AlertService
|
||||
|
||||
<div class="mb-3">
|
||||
<NavTabs Index="3" Names="@UiConstants.AdminNavNames" Links="@UiConstants.AdminNavLinks"/>
|
||||
</div>
|
||||
|
||||
<MinimalCrud @ref="Crud" TItem="StarDetailResponse" OnConfigure="OnConfigure">
|
||||
<ChildContent>
|
||||
<DataColumn TItem="StarDetailResponse" Field="@(x => x.Id)" Title="Id" IsSortable="true" />
|
||||
<DataColumn TItem="StarDetailResponse" Field="@(x => x.Name)" Title="Name" IsSortable="true">
|
||||
<Template>
|
||||
@{
|
||||
var url = ComponentHelper.GetRouteOfComponent<Update>(context.Id)!;
|
||||
}
|
||||
|
||||
<a class="text-primary-500" href="@url">@context.Name</a>
|
||||
</Template>
|
||||
</DataColumn>
|
||||
<DataColumn TItem="StarDetailResponse" Field="@(x => x.Version)" Title="Version" IsSortable="true"/>
|
||||
<DataColumn TItem="StarDetailResponse" Field="@(x => x.Author)" Title="Author"/>
|
||||
</ChildContent>
|
||||
<Actions>
|
||||
<div class="mb-5">
|
||||
<PageHeader Title="Nodes">
|
||||
<InputFile id="import-file" hidden="" multiple OnChange="OnImportFiles"/>
|
||||
<label for="import-file" class="btn btn-tertiary cursor-pointer">
|
||||
<i class="icon-file-up mr-2"></i>
|
||||
Import
|
||||
</label>
|
||||
</Actions>
|
||||
<ItemActions>
|
||||
@if (!string.IsNullOrEmpty(context.DonateUrl))
|
||||
{
|
||||
<a href="@context.DonateUrl" target="_blank" class="text-red-500 mr-3">
|
||||
<i class="icon-heart align-middle"></i>
|
||||
<span class="align-middle">Donate</span>
|
||||
</a>
|
||||
}
|
||||
|
||||
@if (!string.IsNullOrEmpty(context.UpdateUrl))
|
||||
{
|
||||
<a href="#" @onclick:preventDefault class="text-tertiary-500 mr-3">
|
||||
<i class="icon-refresh-cw align-middle"></i>
|
||||
<span class="align-middle">Update</span>
|
||||
</a>
|
||||
}
|
||||
|
||||
<a href="#" @onclick="() => Export(context)" @onclick:preventDefault class="text-success-500 mr-3">
|
||||
<i class="icon-download align-middle"></i>
|
||||
<span class="align-middle">Export</span>
|
||||
|
||||
<a href="/admin/servers/nodes/create" class="btn btn-primary">
|
||||
Create
|
||||
</a>
|
||||
</ItemActions>
|
||||
</MinimalCrud>
|
||||
</PageHeader>
|
||||
</div>
|
||||
|
||||
<DataTable @ref="Table" TItem="StarDetailResponse" LoadItemsPaginatedAsync="LoadData">
|
||||
<Configuration>
|
||||
<DataTableColumn TItem="StarDetailResponse" Field="@(x => x.Id)" Name="Id" />
|
||||
<DataTableColumn TItem="StarDetailResponse" Field="@(x => x.Name)" Name="Name">
|
||||
<ColumnTemplate>
|
||||
<a class="text-primary-500" href="/admin/servers/stars/update/@(context.Id)">
|
||||
@context.Name
|
||||
</a>
|
||||
</ColumnTemplate>
|
||||
</DataTableColumn>
|
||||
<DataTableColumn TItem="StarDetailResponse" Field="@(x => x.Version)" Name="Version" />
|
||||
<DataTableColumn TItem="StarDetailResponse" Field="@(x => x.Author)" Name="Author" />
|
||||
<DataTableColumn TItem="StarDetailResponse">
|
||||
<ColumnTemplate>
|
||||
<div class="flex justify-end">
|
||||
@if (!string.IsNullOrEmpty(context.DonateUrl))
|
||||
{
|
||||
<a href="@context.DonateUrl" target="_blank" class="text-red-500 mr-3">
|
||||
<i class="icon-heart align-middle"></i>
|
||||
<span class="align-middle">Donate</span>
|
||||
</a>
|
||||
}
|
||||
|
||||
@if (!string.IsNullOrEmpty(context.UpdateUrl))
|
||||
{
|
||||
<a href="#" @onclick:preventDefault class="text-tertiary-500 mr-3">
|
||||
<i class="icon-refresh-cw align-middle"></i>
|
||||
<span class="align-middle">Update</span>
|
||||
</a>
|
||||
}
|
||||
|
||||
<a href="#" @onclick="() => Export(context)" @onclick:preventDefault class="text-success-500 mr-3">
|
||||
<i class="icon-download align-middle"></i>
|
||||
<span class="align-middle">Export</span>
|
||||
</a>
|
||||
|
||||
<a href="/admin/servers/stars/update/@(context.Id)" class="text-primary-500 mr-2 sm:mr-3">
|
||||
<i class="icon-pencil text-base"></i>
|
||||
</a>
|
||||
|
||||
<a href="#" @onclick="() => Delete(context)" @onclick:preventDefault
|
||||
class="text-danger-500">
|
||||
<i class="icon-trash text-base"></i>
|
||||
</a>
|
||||
</div>
|
||||
</ColumnTemplate>
|
||||
</DataTableColumn>
|
||||
</Configuration>
|
||||
</DataTable>
|
||||
|
||||
@code
|
||||
{
|
||||
private MinimalCrud<StarDetailResponse> Crud;
|
||||
|
||||
private void OnConfigure(MinimalCrudOptions<StarDetailResponse> options)
|
||||
private DataTable<StarDetailResponse> Table;
|
||||
|
||||
private async Task<IPagedData<StarDetailResponse>> LoadData(PaginationOptions options)
|
||||
=> await ApiClient.GetJson<PagedData<StarDetailResponse>>($"api/admin/servers/stars?page={options.Page}&pageSize={options.PerPage}");
|
||||
|
||||
private async Task Delete(StarDetailResponse detailResponse)
|
||||
{
|
||||
options.Title = "Stars";
|
||||
options.ItemLoader = async (page, pageSize) =>
|
||||
await ApiClient.GetJson<PagedData<StarDetailResponse>>($"api/admin/servers/stars?page={page}&pageSize={pageSize}");
|
||||
await AlertService.ConfirmDanger(
|
||||
"Star deletion",
|
||||
$"Do you really want to delete the star '{detailResponse.Name}'",
|
||||
async () =>
|
||||
{
|
||||
await ApiClient.Delete($"api/admin/servers/stars/{detailResponse.Id}");
|
||||
await ToastService.Success("Successfully deleted star");
|
||||
|
||||
options.CreateUrl = ComponentHelper.GetRouteOfComponent<Create>();
|
||||
options.UpdateUrl = item => ComponentHelper.GetRouteOfComponent<Update>(item.Id)!;
|
||||
options.DeleteFunction = async item => await ApiClient.Delete($"api/admin/servers/stars/{item.Id}");
|
||||
await Table.Refresh();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
private async Task Export(StarDetailResponse star)
|
||||
{
|
||||
var json = await ApiClient.GetString($"api/admin/servers/stars/{star.Id}/export");
|
||||
@@ -124,7 +150,7 @@
|
||||
await ToastService.Danger($"Failed to import '{file.Name}': {e.Title}");
|
||||
}
|
||||
}
|
||||
|
||||
await Crud.Refresh(isSilent: false, bypassCache: true);
|
||||
|
||||
await Table.Refresh();
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
@page "/admin/servers/stars/update/{Id:int}"
|
||||
|
||||
@using MoonCore.Blazor.Tailwind.Components
|
||||
@using MoonCore.Blazor.Tailwind.Forms
|
||||
@using MoonCore.Blazor.Tailwind.Toasts
|
||||
@using MoonCore.Helpers
|
||||
@using MoonlightServers.Shared.Http.Requests.Admin.Stars
|
||||
@@ -14,10 +13,10 @@
|
||||
|
||||
<LazyLoader Load="Load">
|
||||
<PageHeader Title="Update Star">
|
||||
<button @onclick="GoBack" type="button" class="btn btn-secondary">
|
||||
<a href="/admin/servers/stars" class="btn btn-secondary">
|
||||
<i class="icon-chevron-left mr-1"></i>
|
||||
Back
|
||||
</button>
|
||||
</a>
|
||||
<WButton OnClick="_ => Form.Submit()" CssClasses="btn btn-primary">
|
||||
<i class="icon-check mr-1"></i>
|
||||
Update
|
||||
@@ -75,52 +74,11 @@
|
||||
Request = Mapper.Map<UpdateStarRequest>(Detail);
|
||||
}
|
||||
|
||||
private void OnConfigure(FormConfiguration<UpdateStarRequest> configuration)
|
||||
{
|
||||
var generalPage = configuration.WithPage("General");
|
||||
|
||||
generalPage.WithField(x => x.Name);
|
||||
generalPage.WithField(x => x.Version);
|
||||
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");
|
||||
|
||||
var miscPage = configuration.WithPage("Miscellaneous");
|
||||
|
||||
miscPage.WithField(x => x.AllowDockerImageChange);
|
||||
miscPage.WithField(x => x.RequiredAllocations);
|
||||
}
|
||||
|
||||
private async Task OnSubmit()
|
||||
{
|
||||
await ApiClient.Patch($"api/admin/servers/stars/{Id}", Request);
|
||||
|
||||
await ToastService.Success("Successfully updated Star");
|
||||
GoBack();
|
||||
Navigation.NavigateTo("/admin/servers/stars");
|
||||
}
|
||||
|
||||
private void GoBack()
|
||||
=> Navigation.NavigateTo(ComponentHelper.GetRouteOfComponent<Index>()!);
|
||||
}
|
||||
Reference in New Issue
Block a user