Keys list and edit pages

This commit is contained in:
Pat Hartl 2023-02-11 21:40:45 -06:00
parent 4655e75da5
commit 2b2eb2cf75
5 changed files with 132 additions and 0 deletions

View file

@ -20,6 +20,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BlazorMonaco" Version="3.0.0" />
<PackageReference Include="ByteSize" Version="2.1.1" />
<PackageReference Include="IGDB" Version="2.3.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.12" />

View file

@ -0,0 +1,65 @@
@page "/Games/{id:guid}/Keys/Edit"
@inject GameService GameService
@inject KeyService KeyService
@inject NavigationManager NavigationManager
<MudGrid>
<MudItem xs="12">
<MudPaper Class="pa-4">
<StandaloneCodeEditor @ref="Editor" Id="editor" ConstructionOptions="EditorConstructionOptions" />
</MudPaper>
</MudItem>
</MudGrid>
<style>
.monaco-editor-container {
height: 600px;
}
</style>
<MudFab Color="Color.Primary" OnClick="Save" StartIcon="@Icons.Material.Filled.Save" Style="position: fixed; right: 32px; bottom: 32px;" />
@code {
[Parameter] public Guid Id { get; set; }
private Game Game { get; set; }
private StandaloneCodeEditor Editor;
private StandaloneEditorConstructionOptions EditorConstructionOptions(StandaloneCodeEditor editor)
{
return new StandaloneEditorConstructionOptions
{
AutomaticLayout = true,
Language = "text",
Value = String.Join('\n', Game.Keys.Select(k => k.Value)),
Theme = "vs-dark",
};
}
protected override async Task OnInitializedAsync()
{
Game = await GameService.Get(Id);
}
private async Task Save()
{
var value = await Editor.GetValue();
var keys = value.Split("\n").Select(k => k.Trim()).Where(k => !String.IsNullOrWhiteSpace(k));
var keysDeleted = Game.Keys.Where(k => !keys.Contains(k.Value));
var keysAdded = keys.Where(k => !Game.Keys.Any(gk => gk.Value == k));
foreach (var key in keysDeleted)
KeyService.Delete(key);
foreach (var key in keysAdded)
await KeyService.Add(new Key()
{
Game = Game,
Value = key
});
NavigationManager.NavigateTo($"/Games/{Game.Id}/Keys");
}
}

View file

@ -0,0 +1,61 @@
@page "/Games/{id:guid}/Keys"
@inject GameService GameService
@inject KeyService KeyService
<MudTable Items="@Keys" Hover="true" Elevation="0">
<ToolBarContent>
<MudText Typo="Typo.h6">Keys</MudText>
<MudSpacer />
<MudButton Color="Color.Primary" Variant="Variant.Filled" Href="@($"/Games/{Id}/Keys/Edit")">Edit</MudButton>
</ToolBarContent>
<HeaderContent>
<MudTh>Key</MudTh>
<MudTh>Allocation Method</MudTh>
<MudTh>Claimed By</MudTh>
<MudTh>Claimed On</MudTh>
<MudTh></MudTh>
</HeaderContent>
<RowTemplate>
<MudTd>@context.Value</MudTd>
<MudTd>@context.AllocationMethod</MudTd>
<MudTd>
@switch (context.AllocationMethod)
{
case KeyAllocationMethod.MacAddress:
<text>@context.ClaimedByMacAddress</text>
break;
case KeyAllocationMethod.UserAccount:
<text>@context.ClaimedByUser?.UserName</text>
break;
}
</MudTd>
<MudTd>@context.ClaimedOn</MudTd>
<MudTd>
@if ((context.AllocationMethod == KeyAllocationMethod.MacAddress && !String.IsNullOrWhiteSpace(context.ClaimedByMacAddress)) || (context.AllocationMethod == KeyAllocationMethod.UserAccount && context.ClaimedByUser != null))
{
<MudButton OnClick="() => Release(context)">Release</MudButton>
}
</MudTd>
</RowTemplate>
</MudTable>
@code {
[Parameter] public Guid Id { get; set; }
private ICollection<Key> Keys { get; set; }
protected override async Task OnInitializedAsync()
{
var game = await GameService.Get(Id);
Keys = game.Keys;
}
private async Task Release(Key key)
{
key = await KeyService.Release(key);
}
}

View file

@ -22,5 +22,8 @@
<script src="~/_content/MudBlazor/MudBlazor.min.js"></script>
<script src="~/_framework/blazor.server.js"></script>
<script src="~/_content/BlazorMonaco/jsInterop.js"></script>
<script src="~/_content/BlazorMonaco/lib/monaco-editor/min/vs/loader.js"></script>
<script src="~/_content/BlazorMonaco/lib/monaco-editor/min/vs/editor/editor.main.js"></script>
</body>
</html>

View file

@ -5,6 +5,8 @@
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.JSInterop
@using MudBlazor
@using BlazorMonaco
@using BlazorMonaco.Editor
@using LANCommander.Components
@using LANCommander.Shared
@using LANCommander.Services