@using LANCommander.Server.Data.Models @using LANCommander.Server.Extensions @using LANCommander.Server.Models; @using System.IO.Compression; @using System.Collections.ObjectModel @inject ModalService ModalService
@code { [Parameter] public ICollection Actions { get; set; } [Parameter] public EventCallback> ActionsChanged { get; set; } [Parameter] public Guid GameId { get; set; } [Parameter] public Guid ServerId { get; set; } [Parameter] public Guid ArchiveId { get; set; } ObservableCollection SortedActions = new ObservableCollection(); protected override async Task OnInitializedAsync() { if (Actions == null) Actions = new List(); if (SortedActions.Count != Actions.Count) { SortedActions.Clear(); foreach (var action in Actions.OrderBy(a => a.SortOrder)) SortedActions.Add(action); } } private async Task AddAction() { var newAction = new Data.Models.Action() { PrimaryAction = Actions.Count == 0, SortOrder = Actions.Count }; if (GameId != Guid.Empty) newAction.GameId = GameId; if (ServerId != Guid.Empty) newAction.ServerId = ServerId; SortedActions.Add(newAction); await UpdateOrder(); } private async Task RemoveAction(Data.Models.Action action) { SortedActions.Remove(action); await UpdateOrder(); } private async Task MoveUp(Data.Models.Action action) { var index = SortedActions.IndexOf(action); if (index > 0) SortedActions.Move(index, index - 1); await UpdateOrder(); } private async Task MoveDown(Data.Models.Action action) { var index = SortedActions.IndexOf(action); if (index < SortedActions.Count - 1) SortedActions.Move(index, index + 1); await UpdateOrder(); } private async Task UpdateOrder() { foreach (var action in SortedActions) { action.SortOrder = SortedActions.IndexOf(action); } Actions = SortedActions; if (ActionsChanged.HasDelegate) await ActionsChanged.InvokeAsync(Actions); } private void OnPathSelected(string path, Data.Models.Action action) { action.WorkingDirectory = "{InstallDir}"; } }