2024-08-12 00:15:16 -05:00
|
|
|
@using LANCommander.SDK.Enums
|
2024-08-04 18:44:33 -05:00
|
|
|
@using LANCommander.Server.Extensions;
|
|
|
|
|
@using LANCommander.Server.Models
|
|
|
|
|
@using LANCommander.Server.Services
|
2023-03-02 18:50:24 -06:00
|
|
|
@using System.IO.Compression;
|
2023-11-28 20:48:03 -06:00
|
|
|
@using Microsoft.EntityFrameworkCore;
|
2023-03-02 18:50:24 -06:00
|
|
|
@inject ScriptService ScriptService
|
|
|
|
|
@inject ModalService ModalService
|
|
|
|
|
@inject IMessageService MessageService
|
|
|
|
|
|
|
|
|
|
<Space Direction="DirectionVHType.Vertical" Size="@("large")" Style="width: 100%">
|
|
|
|
|
<SpaceItem>
|
2023-09-04 12:52:45 -05:00
|
|
|
<Table TItem="Script" DataSource="@Scripts" HidePagination="true" Responsive>
|
2023-08-02 17:49:47 -05:00
|
|
|
<PropertyColumn Property="s => s.Type">@context.Type.GetDisplayName()</PropertyColumn>
|
2023-03-02 18:50:24 -06:00
|
|
|
<PropertyColumn Property="s => s.CreatedBy">
|
|
|
|
|
@context.CreatedBy?.UserName
|
|
|
|
|
</PropertyColumn>
|
2023-03-03 17:40:24 -06:00
|
|
|
<PropertyColumn Property="s => s.CreatedOn" Format="MM/dd/yyyy hh:mm tt" />
|
2023-03-02 18:50:24 -06:00
|
|
|
<ActionColumn Title="">
|
|
|
|
|
<Space Style="display: flex; justify-content: end">
|
|
|
|
|
<SpaceItem>
|
2023-11-28 20:48:03 -06:00
|
|
|
<Button OnClick="() => Edit(context.Id)" Icon="@IconType.Outline.Edit" Type="@ButtonType.Text" />
|
2023-11-29 17:10:25 -06:00
|
|
|
</SpaceItem>
|
|
|
|
|
<SpaceItem>
|
2023-03-02 18:50:24 -06:00
|
|
|
<Popconfirm OnConfirm="() => Delete(context)" Title="Are you sure you want to delete this script?">
|
|
|
|
|
<Button Icon="@IconType.Outline.Close" Type="@ButtonType.Text" Danger />
|
|
|
|
|
</Popconfirm>
|
|
|
|
|
</SpaceItem>
|
|
|
|
|
</Space>
|
|
|
|
|
</ActionColumn>
|
|
|
|
|
</Table>
|
|
|
|
|
</SpaceItem>
|
|
|
|
|
|
|
|
|
|
<SpaceItem>
|
|
|
|
|
<GridRow Justify="end">
|
|
|
|
|
<GridCol>
|
|
|
|
|
<Button OnClick="() => Edit()" Type="@ButtonType.Primary">Add Script</Button>
|
|
|
|
|
</GridCol>
|
|
|
|
|
</GridRow>
|
|
|
|
|
</SpaceItem>
|
|
|
|
|
</Space>
|
|
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
.monaco-editor-container {
|
|
|
|
|
height: 600px;
|
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
|
2023-10-18 18:11:42 -05:00
|
|
|
@code {
|
2023-03-20 20:46:11 -05:00
|
|
|
[Parameter] public Guid GameId { get; set; }
|
2023-10-18 18:11:42 -05:00
|
|
|
[Parameter] public Guid RedistributableId { get; set; }
|
2023-12-20 17:53:52 -06:00
|
|
|
[Parameter] public Guid ServerId { get; set; }
|
2023-03-20 20:46:11 -05:00
|
|
|
[Parameter] public Guid ArchiveId { get; set; }
|
2023-10-24 18:05:13 -05:00
|
|
|
[Parameter] public IEnumerable<ScriptType> AllowedTypes { get; set; }
|
2023-03-02 18:50:24 -06:00
|
|
|
|
2023-11-28 20:48:03 -06:00
|
|
|
ICollection<Script> Scripts { get; set; } = new List<Script>();
|
2023-03-02 18:50:24 -06:00
|
|
|
|
2023-11-28 20:48:03 -06:00
|
|
|
protected override async Task OnParametersSetAsync()
|
2023-11-30 19:08:20 -06:00
|
|
|
{
|
|
|
|
|
await LoadData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task LoadData()
|
2023-03-02 18:50:24 -06:00
|
|
|
{
|
2023-11-28 20:48:03 -06:00
|
|
|
if (GameId != Guid.Empty)
|
|
|
|
|
Scripts = await ScriptService.Get(s => s.GameId == GameId).ToListAsync();
|
|
|
|
|
else if (RedistributableId != Guid.Empty)
|
|
|
|
|
Scripts = await ScriptService.Get(s => s.RedistributableId == RedistributableId).ToListAsync();
|
2023-12-20 17:53:52 -06:00
|
|
|
else if (ServerId != Guid.Empty)
|
|
|
|
|
Scripts = await ScriptService.Get(s => s.ServerId == ServerId).ToListAsync();
|
2023-11-30 19:08:20 -06:00
|
|
|
|
|
|
|
|
await InvokeAsync(StateHasChanged);
|
2023-03-02 18:50:24 -06:00
|
|
|
}
|
|
|
|
|
|
2023-11-28 20:48:03 -06:00
|
|
|
private async void Edit(Guid? scriptId = null)
|
2023-03-02 18:50:24 -06:00
|
|
|
{
|
|
|
|
|
var modalOptions = new ModalOptions()
|
2023-09-21 19:00:12 -05:00
|
|
|
{
|
2023-11-28 20:48:03 -06:00
|
|
|
Title = scriptId == null ? "Add Script" : "Edit Script",
|
2023-09-21 19:00:12 -05:00
|
|
|
Maximizable = false,
|
|
|
|
|
DefaultMaximized = true,
|
|
|
|
|
Closable = true,
|
2023-11-28 20:48:03 -06:00
|
|
|
OkText = "Save"
|
2023-09-21 19:00:12 -05:00
|
|
|
};
|
2023-03-02 18:50:24 -06:00
|
|
|
|
2023-11-28 20:48:03 -06:00
|
|
|
var options = new ScriptEditorOptions()
|
2023-09-21 19:00:12 -05:00
|
|
|
{
|
2023-11-28 20:48:03 -06:00
|
|
|
ScriptId = scriptId ?? default,
|
|
|
|
|
AllowedTypes = AllowedTypes,
|
2023-09-21 19:00:12 -05:00
|
|
|
ArchiveId = ArchiveId,
|
2023-11-28 20:48:03 -06:00
|
|
|
GameId = GameId,
|
2023-12-20 17:53:52 -06:00
|
|
|
RedistributableId = RedistributableId,
|
|
|
|
|
ServerId = ServerId
|
2023-09-21 19:00:12 -05:00
|
|
|
};
|
2023-03-02 18:50:24 -06:00
|
|
|
|
2023-11-28 20:48:03 -06:00
|
|
|
var modalRef = await ModalService.CreateModalAsync<ScriptEditorDialog, ScriptEditorOptions, Script>(modalOptions, options);
|
2023-03-02 18:50:24 -06:00
|
|
|
|
2023-11-28 20:48:03 -06:00
|
|
|
modalRef.OnOk = async (script) =>
|
2023-03-02 18:50:24 -06:00
|
|
|
{
|
2023-11-30 19:08:20 -06:00
|
|
|
await LoadData();
|
2023-11-28 20:48:03 -06:00
|
|
|
};
|
|
|
|
|
}
|
2023-03-02 18:50:24 -06:00
|
|
|
|
2023-11-28 20:48:03 -06:00
|
|
|
private async void Delete(Script script = null)
|
|
|
|
|
{
|
|
|
|
|
if (script != null)
|
|
|
|
|
await ScriptService.Delete(script);
|
2023-03-02 18:50:24 -06:00
|
|
|
|
2023-11-28 20:48:03 -06:00
|
|
|
await MessageService.Success("Script deleted!");
|
2023-03-02 18:50:24 -06:00
|
|
|
}
|
|
|
|
|
}
|