Starting updating mooncore dependency usage
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
@page "/admin/api"
|
||||
|
||||
@*
|
||||
@using MoonCore.Attributes
|
||||
@using MoonCore.Helpers
|
||||
@using MoonCore.Models
|
||||
@@ -108,4 +108,4 @@
|
||||
configuration.WithField(x => x.ExpiresAt);
|
||||
};
|
||||
}
|
||||
}
|
||||
}*@
|
||||
69
Moonlight.Client/UI/Views/Admin/Users/Create.razor
Normal file
69
Moonlight.Client/UI/Views/Admin/Users/Create.razor
Normal file
@@ -0,0 +1,69 @@
|
||||
@page "/admin/users/create"
|
||||
|
||||
@using MoonCore.Helpers
|
||||
@using Moonlight.Shared.Http.Requests.Admin.Users
|
||||
|
||||
@inject HttpApiClient ApiClient
|
||||
@inject NavigationManager Navigation
|
||||
@inject ToastService ToastService
|
||||
|
||||
<PageHeader Title="Create User">
|
||||
<a href="/admin/users" class="btn btn-secondary">
|
||||
<i class="icon-chevron-left mr-1"></i>
|
||||
Back
|
||||
</a>
|
||||
<WButton OnClick="_ => Form.Submit()" CssClasses="btn btn-primary">
|
||||
<i class="icon-check mr-1"></i>
|
||||
Create
|
||||
</WButton>
|
||||
</PageHeader>
|
||||
|
||||
<div class="mt-5">
|
||||
<HandleForm @ref="Form" Model="Request" OnValidSubmit="OnSubmit">
|
||||
<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.Username" 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.Email" type="email" 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.Password" type="password" 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.PermissionsJson" type="text" autocomplete="off" class="form-input w-full">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</HandleForm>
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
private HandleForm Form;
|
||||
private CreateUserRequest Request;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
Request = new();
|
||||
}
|
||||
|
||||
private async Task OnSubmit()
|
||||
{
|
||||
await ApiClient.Post("api/users", Request);
|
||||
|
||||
await ToastService.Success("Successfully created User");
|
||||
Navigation.NavigateTo("/admin/users");
|
||||
}
|
||||
}
|
||||
@@ -1,71 +1,55 @@
|
||||
@page "/admin/users"
|
||||
@page "/admin/users"
|
||||
|
||||
@using MoonCore.Attributes
|
||||
@using MoonCore.Blazor.Tailwind.Forms.Components
|
||||
@using MoonCore.Helpers
|
||||
@using MoonCore.Models
|
||||
@using Moonlight.Shared.Http.Requests.Admin.Users
|
||||
@using MoonCore.Blazor.Tailwind.Dt
|
||||
@using Moonlight.Shared.Http.Responses.Admin.Users
|
||||
|
||||
@attribute [RequirePermission("admin.users.read")]
|
||||
@inject HttpApiClient ApiClient
|
||||
@inject AlertService AlertService
|
||||
@inject ToastService ToastService
|
||||
|
||||
@inject HttpApiClient HttpApiClient
|
||||
<PageHeader Title="Users" />
|
||||
|
||||
<Crud TItem="UserDetailResponse"
|
||||
TCreateForm="CreateUserRequest"
|
||||
TUpdateForm="UpdateUserRequest"
|
||||
OnConfigure="OnConfigure">
|
||||
<View>
|
||||
<Column TItem="UserDetailResponse" Field="@(x => x.Id)" Title="Id" />
|
||||
<Column TItem="UserDetailResponse" Field="@(x => x.Username)" Title="Username" />
|
||||
<Column TItem="UserDetailResponse" Field="@(x => x.Email)" Title="Email" />
|
||||
</View>
|
||||
</Crud>
|
||||
<DataTable @ref="Table" TItem="UserDetailResponse" PageSize="15" LoadItemsPaginatedAsync="LoadData">
|
||||
<DataTableColumn TItem="UserDetailResponse" Field="@(x => x.Id)" Name="Id" />
|
||||
<DataTableColumn TItem="UserDetailResponse" Field="@(x => x.Username)" Name="Username" />
|
||||
<DataTableColumn TItem="UserDetailResponse" Field="@(x => x.Email)" Name="Email" />
|
||||
<DataTableColumn TItem="UserDetailResponse">
|
||||
<ColumnTemplate>
|
||||
<div class="flex justify-end">
|
||||
<a href="/admin/users/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>
|
||||
</DataTable>
|
||||
|
||||
@code
|
||||
{
|
||||
private void OnConfigure(CrudOptions<UserDetailResponse, CreateUserRequest, UpdateUserRequest> crudOptions)
|
||||
private DataTable<UserDetailResponse> Table;
|
||||
|
||||
private async Task<IPagedData<UserDetailResponse>> LoadData(PaginationOptions options)
|
||||
=> await ApiClient.GetJson<PagedData<UserDetailResponse>>($"api/admin/users?page={options.Page}&pageSize={options.PerPage}");
|
||||
|
||||
private async Task Delete(UserDetailResponse detailResponse)
|
||||
{
|
||||
crudOptions.ItemName = "User";
|
||||
|
||||
crudOptions.ItemLoader = async (page, pageSize)
|
||||
=> await HttpApiClient.GetJson<PagedData<UserDetailResponse>>($"api/admin/users?page={page}&pageSize={pageSize}");
|
||||
await AlertService.ConfirmDanger(
|
||||
"User deletion",
|
||||
$"Do you really want to delete the user '{detailResponse.Username}'",
|
||||
async () =>
|
||||
{
|
||||
await ApiClient.Delete($"api/admin/users/{detailResponse.Id}");
|
||||
await ToastService.Success("Successfully deleted user");
|
||||
|
||||
crudOptions.SingleItemLoader = async id
|
||||
=> await HttpApiClient.GetJson<UserDetailResponse>($"api/admin/users/{id}");
|
||||
|
||||
crudOptions.QueryIdentifier = response => response.Id.ToString();
|
||||
|
||||
crudOptions.OnCreate = async request
|
||||
=> await HttpApiClient.Post("api/admin/users", request);
|
||||
|
||||
crudOptions.OnUpdate = async (item, request)
|
||||
=> await HttpApiClient.Patch($"api/admin/users/{item.Id}", request);
|
||||
|
||||
crudOptions.OnDelete = async item
|
||||
=> await HttpApiClient.Delete($"api/admin/users/{item.Id}");
|
||||
|
||||
crudOptions.OnConfigureCreate = configuration =>
|
||||
{
|
||||
configuration.WithField(x => x.Username);
|
||||
configuration.WithField(x => x.Email);
|
||||
configuration.WithField(x => x.Password)
|
||||
.WithComponent<StringComponent>(component => component.Type = "password");
|
||||
|
||||
configuration.WithField(x => x.PermissionsJson)
|
||||
.WithComponent<TagComponent>();
|
||||
};
|
||||
|
||||
crudOptions.OnConfigureUpdate = (_, configuration) =>
|
||||
{
|
||||
configuration.WithField(x => x.Username);
|
||||
configuration.WithField(x => x.Email);
|
||||
|
||||
configuration.WithField(x => x.Password, fieldConfiguration =>
|
||||
{
|
||||
fieldConfiguration.Description = "Optional. Specify if you want to change this accounts password";
|
||||
})
|
||||
.WithComponent<StringComponent>(component => component.Type = "password");
|
||||
};
|
||||
await Table.Refresh();
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
69
Moonlight.Client/UI/Views/Admin/Users/Update.razor
Normal file
69
Moonlight.Client/UI/Views/Admin/Users/Update.razor
Normal file
@@ -0,0 +1,69 @@
|
||||
@page "/users/update/{Id:int}"
|
||||
|
||||
@using MoonCore.Helpers
|
||||
@using Moonlight.Shared.Http.Requests.Admin.Users
|
||||
@using Moonlight.Shared.Http.Responses.Admin.Users
|
||||
|
||||
@inject HttpApiClient ApiClient
|
||||
@inject NavigationManager Navigation
|
||||
@inject ToastService ToastService
|
||||
|
||||
<LazyLoader Load="Load">
|
||||
<PageHeader Title="Update User">
|
||||
<a href="/admin/users" class="btn btn-secondary">
|
||||
<i class="icon-chevron-left mr-1"></i>
|
||||
Back
|
||||
</a>
|
||||
<WButton OnClick="_ => Form.Submit()" CssClasses="btn btn-primary">
|
||||
<i class="icon-check mr-1"></i>
|
||||
Update
|
||||
</WButton>
|
||||
</PageHeader>
|
||||
|
||||
<div class="mt-5">
|
||||
<HandleForm @ref="Form" Model="Request" OnValidSubmit="OnSubmit">
|
||||
<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.Username" 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.Email" type="email" 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.Password" type="password" autocomplete="off" class="form-input w-full">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</HandleForm>
|
||||
</div>
|
||||
</LazyLoader>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public int Id { get; set; }
|
||||
|
||||
private HandleForm Form;
|
||||
private UpdateUserRequest Request;
|
||||
|
||||
private async Task Load(LazyLoader _)
|
||||
{
|
||||
var detail = await ApiClient.GetJson<UserDetailResponse>($"api/users/{Id}");
|
||||
Request = Mapper.Map<UpdateUserRequest>(detail);
|
||||
}
|
||||
|
||||
private async Task OnSubmit()
|
||||
{
|
||||
await ApiClient.Patch($"api/admin/users/{Id}", Request);
|
||||
|
||||
await ToastService.Success("Successfully updated User");
|
||||
Navigation.NavigateTo("/admin/users");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user