LANCommander/LANCommander.Server/UI/Pages/Redistributables/Index.razor
2026-05-24 18:51:58 -05:00

122 lines
4 KiB
Text

@page "/Redistributables"
@using ManifestType = LANCommander.SDK.Enums.ManifestType
@using LANCommander.Server.UI.Pages.Redistributables.Components
@attribute [Authorize(Roles = RoleService.AdministratorRoleName)]
@inject RedistributableService RedistributableService
@inject ModalService ModalService
@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 Type="@ButtonType.Default" OnClick="OpenImportDialog">Import</Button>
<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 TData="string">
<Flex Gap="FlexGap.Small" Align="FlexAlign.Center" Justify="FlexJustify.End">
<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>
</Flex>
</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>
@code {
bool Loading = true;
int Total;
DataTable<Redistributable> Table;
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 OpenImportDialog()
{
var options = new ImportDialogOptions
{
Hint = "Only LCX files are supported for importing redistributables",
ManifestType = ManifestType.Redistributable,
};
var modalOptions = new ModalOptions
{
Title = "Import Redistributable",
DestroyOnClose = true,
MaskClosable = false,
Footer = null,
};
var modalRef = ModalService.CreateModal<ImportUploadDialog, ImportDialogOptions>(modalOptions, options);
modalRef.OnOk = modalRef.OnCancel = Reload;
}
async Task Reload()
{
Table.ReloadData();
}
}