Databind based on game keys instead of full game
This commit is contained in:
parent
c8a11bee7f
commit
b50b7e4d61
3 changed files with 17 additions and 12 deletions
|
@ -3,18 +3,18 @@
|
||||||
|
|
||||||
<Row>
|
<Row>
|
||||||
<Col Span="8">
|
<Col Span="8">
|
||||||
<Statistic Title="Available" Value="Game.Keys.Count - AllocatedKeys" Style="text-align: center;" />
|
<Statistic Title="Available" Value="Keys.Count - AllocatedKeys" Style="text-align: center;" />
|
||||||
</Col>
|
</Col>
|
||||||
<Col Span="8">
|
<Col Span="8">
|
||||||
<Statistic Title="Allocated" Value="AllocatedKeys" Style="text-align: center;" />
|
<Statistic Title="Allocated" Value="AllocatedKeys" Style="text-align: center;" />
|
||||||
</Col>
|
</Col>
|
||||||
<Col Span="8">
|
<Col Span="8">
|
||||||
<Statistic Title="Total" Value="Game.Keys.Count" Style="text-align: center;" />
|
<Statistic Title="Total" Value="Keys.Count" Style="text-align: center;" />
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
|
|
||||||
<Modal Title="View Keys" Visible="ViewModalVisible" Maximizable="false" DefaultMaximized="true" OnCancel="() => ViewModalVisible = false" OnOk="() => ViewModalVisible = false">
|
<Modal Title="View Keys" Visible="ViewModalVisible" Maximizable="false" DefaultMaximized="true" OnCancel="() => ViewModalVisible = false" OnOk="() => ViewModalVisible = false">
|
||||||
<Table TItem="Key" DataSource="@Game.Keys" Bordered>
|
<Table TItem="Key" DataSource="@Keys" Bordered>
|
||||||
<PropertyColumn Property="k => k.Value">
|
<PropertyColumn Property="k => k.Value">
|
||||||
<InputPassword @bind-Value="@context.Value" />
|
<InputPassword @bind-Value="@context.Value" />
|
||||||
</PropertyColumn>
|
</PropertyColumn>
|
||||||
|
@ -56,7 +56,9 @@
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
[Parameter] public Game Game { get; set; }
|
[Parameter] public Guid GameId { get; set; }
|
||||||
|
[Parameter] public ICollection<Key> Keys { get; set; }
|
||||||
|
[Parameter] public EventCallback<ICollection<Key>> KeysChanged { get; set; }
|
||||||
|
|
||||||
int AllocatedKeys;
|
int AllocatedKeys;
|
||||||
|
|
||||||
|
@ -71,17 +73,17 @@
|
||||||
{
|
{
|
||||||
AutomaticLayout = true,
|
AutomaticLayout = true,
|
||||||
Language = "text",
|
Language = "text",
|
||||||
Value = String.Join('\n', Game.Keys.Select(k => k.Value)),
|
Value = String.Join('\n', Keys.Select(k => k.Value)),
|
||||||
Theme = "vs-dark",
|
Theme = "vs-dark",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override async Task OnInitializedAsync()
|
protected override async Task OnInitializedAsync()
|
||||||
{
|
{
|
||||||
if (Game.Keys == null)
|
if (Keys == null)
|
||||||
Game.Keys = new List<Key>();
|
Keys = new List<Key>();
|
||||||
|
|
||||||
AllocatedKeys = Game.Keys.Count(k => k.IsAllocated());
|
AllocatedKeys = Keys.Count(k => k.IsAllocated());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Edit()
|
public void Edit()
|
||||||
|
@ -106,8 +108,8 @@
|
||||||
var value = await Editor.GetValue();
|
var value = await Editor.GetValue();
|
||||||
var keys = value.Split("\n").Select(k => k.Trim()).Where(k => !String.IsNullOrWhiteSpace(k));
|
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 keysDeleted = Keys.Where(k => !keys.Contains(k.Value));
|
||||||
var keysAdded = keys.Where(k => !Game.Keys.Any(gk => gk.Value == k));
|
var keysAdded = keys.Where(k => !Keys.Any(gk => gk.Value == k));
|
||||||
|
|
||||||
foreach (var key in keysDeleted)
|
foreach (var key in keysDeleted)
|
||||||
KeyService.Delete(key);
|
KeyService.Delete(key);
|
||||||
|
@ -115,7 +117,7 @@
|
||||||
foreach (var key in keysAdded)
|
foreach (var key in keysAdded)
|
||||||
await KeyService.Add(new Key()
|
await KeyService.Add(new Key()
|
||||||
{
|
{
|
||||||
Game = Game,
|
GameId = GameId,
|
||||||
Value = key
|
Value = key
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,10 @@ namespace LANCommander.Data.Models
|
||||||
{
|
{
|
||||||
[MaxLength(255)]
|
[MaxLength(255)]
|
||||||
public string Value { get; set; }
|
public string Value { get; set; }
|
||||||
|
public Guid GameId { get; set; }
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
|
[ForeignKey(nameof(GameId))]
|
||||||
|
[InverseProperty("Keys")]
|
||||||
public virtual Game Game { get; set; }
|
public virtual Game Game { get; set; }
|
||||||
public KeyAllocationMethod AllocationMethod { get; set; }
|
public KeyAllocationMethod AllocationMethod { get; set; }
|
||||||
[MaxLength(17)]
|
[MaxLength(17)]
|
||||||
|
|
|
@ -100,7 +100,7 @@
|
||||||
<Button OnClick="() => KeysEditor.View()" Type="@ButtonType.Primary">View</Button>
|
<Button OnClick="() => KeysEditor.View()" Type="@ButtonType.Primary">View</Button>
|
||||||
</Extra>
|
</Extra>
|
||||||
<Body>
|
<Body>
|
||||||
<KeysEditor @ref="KeysEditor" Game="Game" />
|
<KeysEditor @ref="KeysEditor" @bind-Keys="Game.Keys" GameId="Game.Id" />
|
||||||
</Body>
|
</Body>
|
||||||
</Card>
|
</Card>
|
||||||
</SpaceItem>
|
</SpaceItem>
|
||||||
|
|
Loading…
Add table
Reference in a new issue