129 lines
3.9 KiB
Text
129 lines
3.9 KiB
Text
@page "/Metadata/Engines"
|
|
@attribute [Authorize(Roles = RoleService.AdministratorRoleName)]
|
|
@inject EngineService EngineService
|
|
@inject IMessageService MessageService
|
|
@inject ILogger<Index> Logger
|
|
|
|
<PageHeader Title="Engines" />
|
|
|
|
<DataTable
|
|
TItem="Engine"
|
|
@ref="Table"
|
|
Size="@TableSize.Small"
|
|
Searchable
|
|
SearchProperty="e => e.Name">
|
|
<RightToolbar>
|
|
<Button OnClick="() => OpenEdit(null)" Type="@ButtonType.Primary">Add Engine</Button>
|
|
</RightToolbar>
|
|
<Columns>
|
|
<BoundDataColumn Property="e => e.Name" Sortable DefaultSortOrder="SortDirection.Ascending" />
|
|
<BoundDataColumn Property="e => e.Games.Count" Sortable Title="Games" Include="Games" />
|
|
<BoundDataColumn Property="e => e.CreatedOn" Title="Created On" Sortable>
|
|
<LocalTime Value="context.UpdatedOn" />
|
|
</BoundDataColumn>
|
|
<BoundDataColumn Property="e => e.CreatedBy != null ? e.CreatedBy.UserName : String.Empty" Title="Created By" Sortable Include="CreatedBy" />
|
|
<BoundDataColumn Property="e => e.UpdatedOn" Title="Updated On" Sortable>
|
|
<LocalTime Value="context.UpdatedOn" />
|
|
</BoundDataColumn>
|
|
<BoundDataColumn Property="e => e.UpdatedBy != null ? e.UpdatedBy.UserName : String.Empty" Title="Updated By" Sortable Include="UpdatedBy" />
|
|
<DataActions>
|
|
<a href="@($"/Metadata/Engines/{context.Id}")" class="ant-btn ant-btn-primary">Edit</a>
|
|
<Popconfirm OnConfirm="() => Delete(context)" Title="Are you sure you want to delete this engine?">
|
|
<Button Icon="@IconType.Outline.Close" Type="@ButtonType.Text" Danger />
|
|
</Popconfirm>
|
|
</DataActions>
|
|
</Columns>
|
|
</DataTable>
|
|
|
|
<Modal Title="@(EngineContext.Id == Guid.Empty ? "New Engine" : "Edit Engine")"
|
|
@bind-Visible="@EditEngineVisible"
|
|
OnOk="UpdateOrAdd"
|
|
OnCancel="CloseEdit">
|
|
<Form Model="@EngineContext">
|
|
<FormItem Label="Name">
|
|
<Input @bind-Value="@context.Name" AutoFocus />
|
|
</FormItem>
|
|
</Form>
|
|
</Modal>
|
|
|
|
@code {
|
|
IEnumerable<Engine> Engines { get; set; } = new List<Engine>();
|
|
|
|
bool Loading = true;
|
|
|
|
bool EditEngineVisible = false;
|
|
Engine EngineContext = new();
|
|
|
|
DataTable<Engine> Table;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
Loading = false;
|
|
}
|
|
|
|
async Task UpdateOrAdd()
|
|
{
|
|
try
|
|
{
|
|
if (EngineContext.Id == Guid.Empty)
|
|
{
|
|
await EngineService.AddMissingAsync(x => x.Name == EngineContext.Name, EngineContext);
|
|
|
|
MessageService.Success($"{EngineContext.Name} was added!");
|
|
}
|
|
else
|
|
{
|
|
await EngineService.UpdateAsync(EngineContext);
|
|
|
|
MessageService.Success($"{EngineContext.Name} was updated!");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (EngineContext.Id == Guid.Empty)
|
|
MessageService.Error($"Could not add {EngineContext.Name}!");
|
|
else
|
|
MessageService.Error($"Could not update {EngineContext.Name}!");
|
|
|
|
Logger.LogError(ex, "Could not add/update {EngineContext.Name}!");
|
|
}
|
|
|
|
Table.Reload();
|
|
|
|
await CloseEdit();
|
|
}
|
|
|
|
async Task OpenEdit(Engine engine)
|
|
{
|
|
if (engine != null)
|
|
EngineContext = engine;
|
|
|
|
EditEngineVisible = true;
|
|
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
async Task CloseEdit()
|
|
{
|
|
EditEngineVisible = false;
|
|
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
async Task Delete(Engine engine)
|
|
{
|
|
try
|
|
{
|
|
await EngineService.DeleteAsync(engine);
|
|
|
|
MessageService.Success("Engine deleted!");
|
|
|
|
Table.Reload();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageService.Error("Could not delete engine!");
|
|
Logger?.LogError(ex, "Could not delete engine");
|
|
}
|
|
}
|
|
}
|