133 lines
4.3 KiB
Text
133 lines
4.3 KiB
Text
@inject KeyService KeyService
|
|
@inject IMessageService MessageService
|
|
|
|
@if (Keys != null)
|
|
{
|
|
<Flex Vertical Gap="FlexGap.Small">
|
|
<GridRow>
|
|
<GridCol Span="8">
|
|
<Statistic Title="Available" Value="Keys.Count - AllocatedKeys" Style="text-align: center;" />
|
|
</GridCol>
|
|
<GridCol Span="8">
|
|
<Statistic Title="Allocated" Value="AllocatedKeys" Style="text-align: center;" />
|
|
</GridCol>
|
|
<GridCol Span="8">
|
|
<Statistic Title="Total" Value="Keys.Count" Style="text-align: center;" />
|
|
</GridCol>
|
|
</GridRow>
|
|
|
|
<DataTable
|
|
@ref="Table"
|
|
TItem="Key"
|
|
Responsive
|
|
Query="k => k.GameId == GameId">
|
|
<RightToolbar>
|
|
<Button Type="@ButtonType.Default" OnClick="() => Edit()">Edit</Button>
|
|
<Button Type="@ButtonType.Primary" OnClick="() => Save()">Save</Button>
|
|
</RightToolbar>
|
|
<Columns>
|
|
<BoundDataColumn Property="k => k.Value">
|
|
<InputPassword @bind-Value="@context.Value"/>
|
|
</BoundDataColumn>
|
|
<BoundDataColumn Property="k => k.AllocationMethod" Title="Allocation Method"/>
|
|
<DataColumn TData="string" Title="Claimed By" Include="ClaimedByUser">
|
|
@switch (context.AllocationMethod)
|
|
{
|
|
case KeyAllocationMethod.MacAddress:
|
|
<text>@context.ClaimedByMacAddress</text>
|
|
break;
|
|
|
|
case KeyAllocationMethod.UserAccount:
|
|
<text>@context.ClaimedByUser?.UserName</text>
|
|
break;
|
|
}
|
|
</DataColumn>
|
|
<BoundDataColumn Property="k => k.ClaimedOn" Format="MM/dd/yyyy hh:mm tt" Title="Claimed On" Sortable />
|
|
<DataActions>
|
|
@if (context.IsAllocated())
|
|
{
|
|
<Button OnClick="() => Release(context)">Release</Button>
|
|
}
|
|
</DataActions>
|
|
</Columns>
|
|
</DataTable>
|
|
</Flex>
|
|
|
|
<Modal Title="Edit Keys" Visible="EditModalVisible" Maximizable="false" DefaultMaximized="true" OnCancel="() => EditModalVisible = false" OnOk="Save">
|
|
<StandaloneCodeEditor @ref="Editor" Id="editor" ConstructionOptions="EditorConstructionOptions" />
|
|
</Modal>
|
|
}
|
|
|
|
<style>
|
|
.monaco-editor-container {
|
|
height: 600px;
|
|
}
|
|
</style>
|
|
|
|
@code {
|
|
[Parameter] public Guid GameId { get; set; }
|
|
|
|
ICollection<Key> Keys = new List<Key>();
|
|
int AllocatedKeys;
|
|
|
|
bool EditModalVisible = false;
|
|
|
|
DataTable<Key> Table;
|
|
StandaloneCodeEditor? Editor;
|
|
|
|
StandaloneEditorConstructionOptions EditorConstructionOptions(StandaloneCodeEditor editor)
|
|
{
|
|
return new StandaloneEditorConstructionOptions
|
|
{
|
|
AutomaticLayout = true,
|
|
Language = "text",
|
|
Value = String.Join('\n', Keys.Select(k => k.Value)),
|
|
Theme = "vs-dark",
|
|
};
|
|
}
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
if (Keys == null)
|
|
Keys = new List<Key>();
|
|
|
|
Keys = await KeyService.GetAsync(k => k.GameId == GameId);
|
|
|
|
AllocatedKeys = Keys.Count(k => k.IsAllocated());
|
|
}
|
|
|
|
void Edit()
|
|
{
|
|
EditModalVisible = true;
|
|
}
|
|
|
|
async Task Release(Key key)
|
|
{
|
|
await KeyService.ReleaseAsync(key);
|
|
|
|
await MessageService.Success("Key was unallocated!");
|
|
}
|
|
|
|
async Task Save()
|
|
{
|
|
var value = await Editor.GetValue();
|
|
var keys = value.Split("\n").Select(k => k.Trim()).Where(k => !String.IsNullOrWhiteSpace(k)).ToList();
|
|
|
|
var keysDeleted = Keys.Where(k => !keys.Contains(k.Value)).ToList();
|
|
var keysAdded = keys.Where(k => !Keys.Any(gk => gk.Value == k)).ToList();
|
|
|
|
foreach (var key in keysDeleted)
|
|
KeyService.DeleteAsync(key);
|
|
|
|
foreach (var key in keysAdded)
|
|
await KeyService.AddAsync(new Key()
|
|
{
|
|
GameId = GameId,
|
|
Value = key
|
|
});
|
|
|
|
EditModalVisible = false;
|
|
|
|
MessageService.Success("Keys updated!");
|
|
}
|
|
}
|