Rename Value property for action editor. Fix actions adding/removing. Move to only show file browser if archive exists
This commit is contained in:
parent
b3b4d0dad6
commit
a746dddbe7
2 changed files with 40 additions and 44 deletions
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
<Space Direction="DirectionVHType.Vertical" Size="@("large")" Style="width: 100%">
|
<Space Direction="DirectionVHType.Vertical" Size="@("large")" Style="width: 100%">
|
||||||
<SpaceItem>
|
<SpaceItem>
|
||||||
<Table TItem="Data.Models.Action" DataSource="@OrderedActions" HidePagination="true" Style="border: 1px solid #f0f0f0">
|
<Table TItem="Data.Models.Action" DataSource="@Actions" HidePagination="true" Style="border: 1px solid #f0f0f0">
|
||||||
<PropertyColumn Property="a => a.Name">
|
<PropertyColumn Property="a => a.Name">
|
||||||
<Input Type="text" @bind-Value="context.Name" />
|
<Input Type="text" @bind-Value="context.Name" />
|
||||||
</PropertyColumn>
|
</PropertyColumn>
|
||||||
|
@ -15,9 +15,11 @@
|
||||||
<SpaceItem Style="flex-grow: 1">
|
<SpaceItem Style="flex-grow: 1">
|
||||||
<Input Type="text" @bind-Value="context.Path" />
|
<Input Type="text" @bind-Value="context.Path" />
|
||||||
</SpaceItem>
|
</SpaceItem>
|
||||||
|
@if (ArchiveId != Guid.Empty) {
|
||||||
<SpaceItem>
|
<SpaceItem>
|
||||||
<Button OnClick="() => BrowseForActionPath(context)" Type="@ButtonType.Primary" Icon="@IconType.Outline.FolderOpen" />
|
<Button OnClick="() => BrowseForActionPath(context)" Type="@ButtonType.Primary" Icon="@IconType.Outline.FolderOpen" />
|
||||||
</SpaceItem>
|
</SpaceItem>
|
||||||
|
}
|
||||||
</Space>
|
</Space>
|
||||||
</PropertyColumn>
|
</PropertyColumn>
|
||||||
<PropertyColumn Property="a => a.Arguments">
|
<PropertyColumn Property="a => a.Arguments">
|
||||||
|
@ -54,58 +56,46 @@
|
||||||
</Space>
|
</Space>
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
[Parameter] public ICollection<Data.Models.Action> Value { get; set; }
|
[Parameter] public ICollection<Data.Models.Action> Actions { get; set; }
|
||||||
[Parameter] public EventCallback<ICollection<Data.Models.Action>> ValueChanged { get; set; }
|
[Parameter] public EventCallback<ICollection<Data.Models.Action>> ActionsChanged { get; set; }
|
||||||
|
|
||||||
|
[Parameter] public Guid GameId { get; set; }
|
||||||
[Parameter] public Guid ArchiveId { get; set; }
|
[Parameter] public Guid ArchiveId { get; set; }
|
||||||
|
|
||||||
private List<Data.Models.Action> OrderedActions { get; set; }
|
|
||||||
|
|
||||||
protected override async Task OnInitializedAsync()
|
protected override async Task OnInitializedAsync()
|
||||||
{
|
{
|
||||||
if (Value == null)
|
if (Actions == null)
|
||||||
Value = new List<Data.Models.Action>();
|
Actions = new List<Data.Models.Action>();
|
||||||
|
|
||||||
OrderedActions = Value.OrderBy(a => a.SortOrder).ToList();
|
|
||||||
|
|
||||||
await FixSortOrder();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task AddAction()
|
private async Task AddAction()
|
||||||
{
|
{
|
||||||
if (OrderedActions == null)
|
if (Actions == null)
|
||||||
OrderedActions = new List<Data.Models.Action>();
|
Actions = new List<Data.Models.Action>();
|
||||||
|
|
||||||
OrderedActions.Add(new Data.Models.Action()
|
Actions.Add(new Data.Models.Action()
|
||||||
{
|
{
|
||||||
PrimaryAction = OrderedActions.Count == 0,
|
PrimaryAction = Actions.Count == 0,
|
||||||
SortOrder = OrderedActions.Count
|
SortOrder = Actions.Count,
|
||||||
|
GameId = GameId
|
||||||
});
|
});
|
||||||
|
|
||||||
await FixSortOrder();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task RemoveAction(Data.Models.Action action)
|
private async Task RemoveAction(Data.Models.Action action)
|
||||||
{
|
{
|
||||||
OrderedActions.Remove(action);
|
Actions.Remove(action);
|
||||||
|
|
||||||
await FixSortOrder();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task MoveUp(Data.Models.Action action)
|
private async Task MoveUp(Data.Models.Action action)
|
||||||
{
|
{
|
||||||
if (action.SortOrder > 0)
|
if (action.SortOrder > 0)
|
||||||
OrderedActions.Move(action, action.SortOrder - 1);
|
Move(action.SortOrder, action.SortOrder - 1);
|
||||||
|
|
||||||
await FixSortOrder();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task MoveDown(Data.Models.Action action)
|
private async Task MoveDown(Data.Models.Action action)
|
||||||
{
|
{
|
||||||
if (action.SortOrder < OrderedActions.Count + 1)
|
if (action.SortOrder < Actions.Count + 1)
|
||||||
OrderedActions.Move(action, action.SortOrder + 1);
|
Move(action.SortOrder, action.SortOrder + 1);
|
||||||
|
|
||||||
await FixSortOrder();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void BrowseForActionPath(Data.Models.Action action)
|
private async void BrowseForActionPath(Data.Models.Action action)
|
||||||
|
@ -145,20 +135,15 @@
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task FixSortOrder()
|
private void Move(int oldIndex, int newIndex)
|
||||||
{
|
{
|
||||||
int i = 0;
|
foreach (var action in Actions)
|
||||||
|
|
||||||
foreach (var action in OrderedActions)
|
|
||||||
{
|
{
|
||||||
action.SortOrder = i;
|
if (action.SortOrder == oldIndex)
|
||||||
|
action.SortOrder = newIndex;
|
||||||
|
|
||||||
i++;
|
if (action.SortOrder == newIndex)
|
||||||
|
action.SortOrder = oldIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
Value = OrderedActions;
|
|
||||||
|
|
||||||
if (ValueChanged.HasDelegate)
|
|
||||||
await ValueChanged.InvokeAsync();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,12 +75,12 @@
|
||||||
</Card>
|
</Card>
|
||||||
</SpaceItem>
|
</SpaceItem>
|
||||||
|
|
||||||
@if (Game.Id != Guid.Empty)
|
@if (Game != null && Game.Id != Guid.Empty)
|
||||||
{
|
{
|
||||||
<SpaceItem>
|
<SpaceItem>
|
||||||
<Card Title="Actions">
|
<Card Title="Actions">
|
||||||
<Body>
|
<Body>
|
||||||
<ActionEditor @bind-Value="Game.Actions" ArchiveId="Game.Archives.OrderByDescending(a => a.CreatedOn).FirstOrDefault().Id" />
|
<ActionEditor @bind-Actions="Game.Actions" GameId="Game.Id" ArchiveId="@LatestArchiveId" />
|
||||||
</Body>
|
</Body>
|
||||||
</Card>
|
</Card>
|
||||||
</SpaceItem>
|
</SpaceItem>
|
||||||
|
@ -141,6 +141,17 @@
|
||||||
private KeysEditor? KeysEditor;
|
private KeysEditor? KeysEditor;
|
||||||
private GameMetadataLookup? GameMetadataLookup;
|
private GameMetadataLookup? GameMetadataLookup;
|
||||||
|
|
||||||
|
private Guid LatestArchiveId
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (Game != null && Game.Archives != null && Game.Archives.Count > 0)
|
||||||
|
return Game.Archives.OrderByDescending(a => a.CreatedOn).FirstOrDefault().Id;
|
||||||
|
else
|
||||||
|
return Guid.Empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private int KeysAvailable { get {
|
private int KeysAvailable { get {
|
||||||
return Game.Keys.Count(k =>
|
return Game.Keys.Count(k =>
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue