166 lines
5.5 KiB
Text
166 lines
5.5 KiB
Text
@page "/Metadata/Platforms"
|
|
@using Microsoft.EntityFrameworkCore;
|
|
@attribute [Authorize(Roles = "Administrator")]
|
|
@inject PlatformService PlatformService
|
|
@inject NavigationManager NavigationManager
|
|
@inject IMessageService MessageService
|
|
@inject ILogger<Index> Logger
|
|
|
|
<PageHeader Title="Platforms">
|
|
<PageHeaderExtra>
|
|
<Space Direction="DirectionVHType.Horizontal">
|
|
<SpaceItem>
|
|
<Search Placeholder="Search" @bind-Value="Search" BindOnInput DebounceMilliseconds="150" OnChange="() => LoadData()" />
|
|
</SpaceItem>
|
|
<SpaceItem>
|
|
<Button OnClick="() => OpenEdit(null)" Type="@ButtonType.Primary">Add Platform</Button>
|
|
</SpaceItem>
|
|
</Space>
|
|
</PageHeaderExtra>
|
|
</PageHeader>
|
|
|
|
<TableColumnPicker @ref="Picker" Key="Platforms" @bind-Visible="ColumnPickerVisible" />
|
|
|
|
<Table TItem="Platform" DataSource="@Platforms" Loading="@Loading" PageSize="25" Responsive>
|
|
<PropertyColumn Property="c => c.Name" Sortable Hidden="@(Picker.IsColumnHidden("Name"))" />
|
|
<PropertyColumn Property="c => c.CreatedOn" Format="MM/dd/yyyy hh:mm tt" Sortable Hidden="@(Picker.IsColumnHidden("Created On"))" />
|
|
<PropertyColumn Property="c => c.CreatedBy != null ? c.CreatedBy.UserName : String.Empty" Title="Created By" Sortable Hidden="@(Picker.IsColumnHidden("Created By"))" />
|
|
<PropertyColumn Property="c => c.UpdatedOn" Format="MM/dd/yyyy hh:mm tt" Sortable Hidden="@(Picker.IsColumnHidden("Updated On", false))" />
|
|
<PropertyColumn Property="c => c.UpdatedBy != null ? c.UpdatedBy.UserName : String.Empty" Title="Updated By" Sortable Hidden="@(Picker.IsColumnHidden("Updated By"))" />
|
|
<PropertyColumn Property="c => c.Games != null ? c.Games.Count : 0" Title="Games" Sortable Hidden="@(Picker.IsColumnHidden("Games"))" />
|
|
<ActionColumn Title="" Style="text-align: right; white-space: nowrap">
|
|
<TitleTemplate>
|
|
<div style="text-align: right">
|
|
<Button Icon="@IconType.Outline.Edit" Type="@ButtonType.Text" OnClick="() => OpenColumnPicker()" />
|
|
</div>
|
|
</TitleTemplate>
|
|
<ChildContent>
|
|
<Space Direction="DirectionVHType.Horizontal">
|
|
<SpaceItem>
|
|
<Button Icon="@IconType.Outline.Edit" Type="@ButtonType.Text" OnClick="() => OpenEdit(context)" />
|
|
</SpaceItem>
|
|
<SpaceItem>
|
|
<Popconfirm OnConfirm="() => Delete(context)" Title="Are you sure you want to delete this Platform?">
|
|
<Button Icon="@IconType.Outline.Close" Type="@ButtonType.Text" Danger />
|
|
</Popconfirm>
|
|
</SpaceItem>
|
|
</Space>
|
|
</ChildContent>
|
|
</ActionColumn>
|
|
</Table>
|
|
|
|
<Modal Title="@(PlatformContext.Id == Guid.Empty ? "New Platform" : "Edit Platform")"
|
|
@bind-Visible="@EditPlatformVisible"
|
|
OnOk="UpdateOrAdd"
|
|
OnCancel="CloseEdit">
|
|
<Form Model="@PlatformContext">
|
|
<FormItem Label="Name">
|
|
<Input @bind-Value="@context.Name" />
|
|
</FormItem>
|
|
</Form>
|
|
</Modal>
|
|
|
|
@code {
|
|
IEnumerable<Platform> Platforms { get; set; } = new List<Platform>();
|
|
|
|
bool Loading = true;
|
|
|
|
string Search = "";
|
|
|
|
TableColumnPicker Picker;
|
|
bool ColumnPickerVisible = false;
|
|
|
|
bool EditPlatformVisible = false;
|
|
Platform PlatformContext = new Platform();
|
|
|
|
protected override void OnAfterRender(bool firstRender)
|
|
{
|
|
if (firstRender)
|
|
{
|
|
LoadData();
|
|
|
|
Loading = false;
|
|
|
|
StateHasChanged();
|
|
}
|
|
}
|
|
|
|
private async Task LoadData()
|
|
{
|
|
var fuzzySearch = Search.ToLower().Trim();
|
|
|
|
Platforms = await PlatformService.Get(r => r.Name.ToLower().Contains(fuzzySearch)).OrderBy(r => r.Name).ToListAsync();
|
|
}
|
|
|
|
private async Task UpdateOrAdd()
|
|
{
|
|
try
|
|
{
|
|
if (PlatformContext.Id == Guid.Empty)
|
|
{
|
|
await PlatformService.AddMissing(x => x.Name == PlatformContext.Name, PlatformContext);
|
|
|
|
MessageService.Success($"{PlatformContext.Name} was added!");
|
|
}
|
|
else
|
|
{
|
|
await PlatformService.Update(PlatformContext);
|
|
|
|
MessageService.Success($"{PlatformContext.Name} was updated!");
|
|
}
|
|
|
|
await LoadData();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (PlatformContext.Id == Guid.Empty)
|
|
MessageService.Error($"Could not add {PlatformContext.Name}!");
|
|
else
|
|
MessageService.Error($"Could not update {PlatformContext.Name}!");
|
|
|
|
Logger.LogError(ex, $"Could not add/update {PlatformContext.Name}!");
|
|
}
|
|
|
|
await CloseEdit();
|
|
}
|
|
|
|
private async Task OpenEdit(Platform platform)
|
|
{
|
|
if (platform != null)
|
|
PlatformContext = platform;
|
|
|
|
EditPlatformVisible = true;
|
|
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
private async Task CloseEdit()
|
|
{
|
|
EditPlatformVisible = false;
|
|
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
private async Task Delete(Platform Platform)
|
|
{
|
|
Platforms = new List<Platform>();
|
|
|
|
Loading = true;
|
|
|
|
await PlatformService.Delete(Platform);
|
|
|
|
Platforms = await PlatformService.Get(x => true).OrderBy(r => r.Name).ToListAsync();
|
|
|
|
Loading = false;
|
|
}
|
|
|
|
private async Task OpenColumnPicker()
|
|
{
|
|
ColumnPickerVisible = true;
|
|
}
|
|
|
|
private async Task CloseColumnPicker()
|
|
{
|
|
ColumnPickerVisible = false;
|
|
}
|
|
}
|