LANCommander/LANCommander.Server/UI/Pages/Redistributables/Index.razor
2025-05-05 22:43:46 +02:00

100 lines
3.2 KiB
Text

@page "/Redistributables"
@using LANCommander.Server.UI.Pages.Redistributables.Components
@attribute [Authorize(Roles = RoleService.AdministratorRoleName)]
@inject RedistributableService RedistributableService
@inject NavigationManager NavigationManager
@inject IMessageService MessageService
@inject ILogger<Index> Logger
<PageHeader Title="Redistributables" Subtitle="@Total.ToString()" />
<DataTable
@ref="Table"
TItem="Redistributable"
Size="TableSize.Small"
@bind-Total="Total"
Responsive
ColumnPicker
Searchable
SearchProperty="r => r.Name">
<RightToolbar>
<Button OnClick="() => Add()" Type="@ButtonType.Primary">Add Redistributable</Button>
</RightToolbar>
<Columns>
<BoundDataColumn Property="c => c.Name" Sortable DefaultSortOrder="SortDirection.Ascending" />
<BoundDataColumn Property="r => r.Games.Count" Title="Games" Sortable Include="Games" />
<BoundDataColumn Property="r => r.CreatedOn" Title="Created On" Sortable>
<LocalTime Value="context.UpdatedOn" />
</BoundDataColumn>
<BoundDataColumn Property="r => r.CreatedBy != null ? r.CreatedBy.UserName : String.Empty" Title="Created By" Sortable Include="CreatedBy" />
<BoundDataColumn Property="r => r.UpdatedOn" Title="Updated On" Sortable>
<LocalTime Value="context.UpdatedOn" />
</BoundDataColumn>
<BoundDataColumn Property="r => r.UpdatedBy != null ? r.UpdatedBy.UserName : String.Empty" Title="Updated By" Sortable Include="UpdatedBy" />
<DataActions>
<a href="@($"/Redistributables/{context.Id}")" class="ant-btn ant-btn-primary">Edit</a>
<Popconfirm OnConfirm="() => Delete(context)" Title="Are you sure you want to delete this redistributable?">
<Button Type="@ButtonType.Text" Icon="@IconType.Outline.Close" Danger/>
</Popconfirm>
</DataActions>
</Columns>
<PaginationTemplate>
<Pagination
Total="context.Total"
PageSize="context.PageSize"
Current="context.PageIndex"
DefaultPageSize="25"
PageSizeOptions="new [] { 25, 50, 100, 200 }"
ShowSizeChanger
OnChange="context.HandlePageChange" />
</PaginationTemplate>
</DataTable>
<ImportUploadDialog @ref="ImportUploadDialog" />
@code {
bool Loading = true;
int Total;
DataTable<Redistributable> Table;
ImportUploadDialog ImportUploadDialog;
protected override async Task OnInitializedAsync()
{
Loading = false;
}
void Add()
{
NavigationManager.NavigateTo("/Redistributables/Add");
}
async Task Delete(Redistributable redistributable)
{
try
{
Loading = true;
await RedistributableService.DeleteAsync(redistributable);
}
catch (Exception ex)
{
MessageService.Error("Could not delete the redistributable!");
Logger.LogError(ex, "Could not delete the redistributable!");
}
finally
{
Loading = false;
}
await Reload();
}
async Task Reload()
{
Table.ReloadData();
}
}