LANCommander/LANCommander.Server/UI/Pages/Metadata/Collections/Index.razor

110 lines
3.5 KiB
Text
Raw Permalink Normal View History

@page "/Metadata/Collections"
@attribute [Authorize(Roles = RoleService.AdministratorRoleName)]
@inject CollectionService CollectionService
@inject IMessageService MessageService
2024-07-07 16:33:46 -05:00
@inject ILogger<Index> Logger
2024-12-12 17:35:52 -06:00
<PageHeader Title="Collections" />
<DataTable
TItem="Collection"
@ref="Table"
2025-01-21 18:48:01 -06:00
Size="@TableSize.Small"
Searchable
SearchProperty="c => c.Name">
2024-12-12 17:35:52 -06:00
<RightToolbar>
<Button OnClick="OpenAdd" Type="@ButtonType.Primary">Add Collection</Button>
</RightToolbar>
<Columns>
2025-01-20 01:22:56 -06:00
<BoundDataColumn Property="c => c.Name" Sortable DefaultSortOrder="SortDirection.Ascending" />
<BoundDataColumn Property="c => c.Games.Count" Sortable Title="Games" Include="Games" />
2025-03-17 02:02:17 -05:00
<BoundDataColumn Property="c => c.CreatedOn" Title="Created On" Sortable>
<LocalTime Value="context.UpdatedOn" />
</BoundDataColumn>
2025-01-19 14:50:12 -06:00
<BoundDataColumn Property="c => c.CreatedBy != null ? c.CreatedBy.UserName : String.Empty" Title="Created By" Sortable Include="CreatedBy" />
2025-03-17 02:02:17 -05:00
<BoundDataColumn Property="c => c.UpdatedOn" Title="Updated On" Sortable>
<LocalTime Value="context.UpdatedOn" />
</BoundDataColumn>
2025-01-19 14:50:12 -06:00
<BoundDataColumn Property="c => c.UpdatedBy != null ? c.UpdatedBy.UserName : String.Empty" Title="Updated By" Sortable Include="UpdatedBy" />
<DataActions TData="string">
2024-12-12 17:35:52 -06:00
<a href="@($"/Metadata/Collections/{context.Id}")" class="ant-btn ant-btn-primary">Edit</a>
<Popconfirm OnConfirm="() => Delete(context)" Title="Are you sure you want to delete this collection?">
<Button Icon="@IconType.Outline.Close" Type="@ButtonType.Text" Danger />
</Popconfirm>
</DataActions>
</Columns>
</DataTable>
<Modal Title="Add Collection" OnOk="Add" OnCancel="CloseAdd" @bind-Visible="AddCollectionVisible">
<Form Model="@CollectionContext">
<FormItem Label="Name">
2025-02-23 09:27:34 -06:00
<Input @bind-Value="@context.Name" AutoFocus />
</FormItem>
</Form>
</Modal>
@code {
IEnumerable<Collection> Collections { get; set; } = new List<Collection>();
2024-12-12 17:35:52 -06:00
bool Visibility = false;
2024-12-12 17:35:52 -06:00
string Url;
bool AddCollectionVisible;
2025-01-19 14:50:12 -06:00
Collection CollectionContext = new();
DataTable<Collection> Table;
2024-11-22 02:05:44 -06:00
async Task OpenAdd()
{
CollectionContext = new Collection();
AddCollectionVisible = true;
await InvokeAsync(StateHasChanged);
}
2024-11-22 02:05:44 -06:00
async Task CloseAdd()
{
AddCollectionVisible = false;
await InvokeAsync(StateHasChanged);
}
2024-11-22 02:05:44 -06:00
async Task Add()
{
try
{
await CollectionService.AddMissingAsync(x => x.Name == CollectionContext.Name, CollectionContext);
MessageService.Success($"{CollectionContext.Name} was added!");
2025-12-05 16:28:39 -06:00
await Table.ReloadAsync();
await CloseAdd();
}
catch (Exception ex)
{
MessageService.Error($"Could not add {CollectionContext.Name}!");
2024-07-07 16:33:46 -05:00
Logger.LogError(ex, $"Could not add {CollectionContext.Name}!");
}
}
async Task Delete(Collection collection)
{
try
{
await CollectionService.DeleteAsync(collection);
2025-12-05 16:28:39 -06:00
await Table.ReloadAsync();
MessageService.Success("Collection deleted!");
}
catch (Exception ex)
{
MessageService.Error("Could not delete collection!");
Logger?.LogError(ex, "Could not delete collection");
}
}
}