111 lines
3.6 KiB
Text
111 lines
3.6 KiB
Text
@page "/Metadata/Collections"
|
|
@attribute [Authorize(Roles = RoleService.AdministratorRoleName)]
|
|
@inject CollectionService CollectionService
|
|
@inject IMessageService MessageService
|
|
@inject ILogger<Index> Logger
|
|
|
|
<PageHeader Title="Collections" />
|
|
|
|
<DataTable
|
|
TItem="Collection"
|
|
@ref="Table"
|
|
Size="@TableSize.Small"
|
|
Searchable
|
|
SearchProperty="c => c.Name">
|
|
<RightToolbar>
|
|
<Button OnClick="OpenAdd" Type="@ButtonType.Primary">Add Collection</Button>
|
|
</RightToolbar>
|
|
<Columns>
|
|
<BoundDataColumn Property="c => c.Name" Sortable DefaultSortOrder="SortDirection.Ascending" />
|
|
<BoundDataColumn Property="c => c.Games.Count" Sortable Title="Games" Include="Games" />
|
|
<BoundDataColumn Property="c => c.CreatedOn" Title="Created On" Sortable>
|
|
<LocalTime Value="context.UpdatedOn" />
|
|
</BoundDataColumn>
|
|
<BoundDataColumn Property="c => c.CreatedBy != null ? c.CreatedBy.UserName : String.Empty" Title="Created By" Sortable Include="CreatedBy" />
|
|
<BoundDataColumn Property="c => c.UpdatedOn" Title="Updated On" Sortable>
|
|
<LocalTime Value="context.UpdatedOn" />
|
|
</BoundDataColumn>
|
|
<BoundDataColumn Property="c => c.UpdatedBy != null ? c.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="@($"/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>
|
|
</Flex>
|
|
</DataActions>
|
|
</Columns>
|
|
</DataTable>
|
|
|
|
<Modal Title="Add Collection" OnOk="Add" OnCancel="CloseAdd" @bind-Visible="AddCollectionVisible">
|
|
<Form Model="@CollectionContext">
|
|
<FormItem Label="Name">
|
|
<Input @bind-Value="@context.Name" AutoFocus />
|
|
</FormItem>
|
|
</Form>
|
|
</Modal>
|
|
|
|
@code {
|
|
IEnumerable<Collection> Collections { get; set; } = new List<Collection>();
|
|
|
|
bool Visibility = false;
|
|
|
|
string Url;
|
|
|
|
bool AddCollectionVisible;
|
|
Collection CollectionContext = new();
|
|
|
|
DataTable<Collection> Table;
|
|
|
|
async Task OpenAdd()
|
|
{
|
|
CollectionContext = new Collection();
|
|
|
|
AddCollectionVisible = true;
|
|
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
async Task CloseAdd()
|
|
{
|
|
AddCollectionVisible = false;
|
|
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
async Task Add()
|
|
{
|
|
try
|
|
{
|
|
await CollectionService.AddMissingAsync(x => x.Name == CollectionContext.Name, CollectionContext);
|
|
|
|
MessageService.Success($"{CollectionContext.Name} was added!");
|
|
|
|
await Table.ReloadAsync();
|
|
|
|
await CloseAdd();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageService.Error($"Could not add {CollectionContext.Name}!");
|
|
Logger.LogError(ex, $"Could not add {CollectionContext.Name}!");
|
|
}
|
|
}
|
|
|
|
async Task Delete(Collection collection)
|
|
{
|
|
try
|
|
{
|
|
await CollectionService.DeleteAsync(collection);
|
|
|
|
await Table.ReloadAsync();
|
|
|
|
MessageService.Success("Collection deleted!");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageService.Error("Could not delete collection!");
|
|
Logger?.LogError(ex, "Could not delete collection");
|
|
}
|
|
}
|
|
}
|