2024-08-12 00:15:16 -05:00
|
|
|
@using LANCommander.SDK.Enums
|
|
|
|
|
@using LANCommander.Server.Extensions;
|
2024-08-04 18:44:33 -05:00
|
|
|
@using LANCommander.Server.Models;
|
2024-11-22 02:04:04 -06:00
|
|
|
@using LANCommander.Server.UI.Components;
|
2023-11-28 20:48:03 -06:00
|
|
|
@inherits FeedbackComponent<ScriptEditorOptions, Script>
|
|
|
|
|
@inject ScriptService ScriptService
|
|
|
|
|
@inject ModalService ModalService
|
|
|
|
|
@inject IMessageService MessageService
|
2024-01-04 18:23:54 -06:00
|
|
|
@inject ILogger<ScriptEditorDialog> Logger
|
2023-11-28 20:48:03 -06:00
|
|
|
|
2024-11-22 02:04:04 -06:00
|
|
|
<ScriptTextEditor
|
|
|
|
|
@bind-Script="@Script"
|
|
|
|
|
ArchiveId="@Options.ArchiveId"
|
|
|
|
|
AllowedTypes="@Options.AllowedTypes"
|
|
|
|
|
OnSave="Save" />
|
2023-11-28 20:48:03 -06:00
|
|
|
|
2024-03-11 17:38:29 -05:00
|
|
|
@code {
|
2023-11-28 20:48:03 -06:00
|
|
|
Guid Id = Guid.NewGuid();
|
|
|
|
|
|
2024-11-22 02:04:04 -06:00
|
|
|
Script Script;
|
2023-11-28 20:48:03 -06:00
|
|
|
|
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
|
|
|
{
|
|
|
|
|
if (Options.ScriptId != Guid.Empty)
|
2024-11-12 18:32:46 -06:00
|
|
|
Script = await ScriptService.GetAsync(Options.ScriptId);
|
2023-11-30 19:08:20 -06:00
|
|
|
else if (Options.GameId != Guid.Empty)
|
|
|
|
|
Script = new Script()
|
2024-11-22 02:04:04 -06:00
|
|
|
{
|
|
|
|
|
GameId = Options.GameId
|
|
|
|
|
};
|
2023-11-30 19:08:20 -06:00
|
|
|
else if (Options.RedistributableId != Guid.Empty)
|
|
|
|
|
Script = new Script()
|
2024-11-22 02:04:04 -06:00
|
|
|
{
|
|
|
|
|
RedistributableId = Options.RedistributableId
|
|
|
|
|
};
|
2023-12-20 17:53:52 -06:00
|
|
|
else if (Options.ServerId != Guid.Empty)
|
|
|
|
|
Script = new Script()
|
2023-12-05 19:10:34 -06:00
|
|
|
{
|
2024-11-22 02:04:04 -06:00
|
|
|
ServerId = Options.ServerId
|
|
|
|
|
};
|
2023-12-05 19:10:34 -06:00
|
|
|
}
|
|
|
|
|
|
2023-11-28 20:48:03 -06:00
|
|
|
public override async Task OnFeedbackOkAsync(ModalClosingEventArgs args)
|
|
|
|
|
{
|
2024-03-11 17:38:29 -05:00
|
|
|
var success = await Save();
|
2023-11-28 20:48:03 -06:00
|
|
|
|
2024-03-11 17:38:29 -05:00
|
|
|
if (success)
|
|
|
|
|
await base.OkCancelRefWithResult!.OnOk(Script);
|
|
|
|
|
else
|
|
|
|
|
args.Reject();
|
2023-11-28 20:48:03 -06:00
|
|
|
}
|
|
|
|
|
|
2024-11-22 02:04:04 -06:00
|
|
|
async Task<bool> Save()
|
2023-11-28 20:48:03 -06:00
|
|
|
{
|
2024-11-22 02:04:04 -06:00
|
|
|
try
|
2023-11-28 20:48:03 -06:00
|
|
|
{
|
2024-11-22 02:04:04 -06:00
|
|
|
if (Script.Id == Guid.Empty)
|
|
|
|
|
Script = await ScriptService.AddAsync(Script);
|
|
|
|
|
else
|
|
|
|
|
Script = await ScriptService.UpdateAsync(Script);
|
2023-11-28 20:48:03 -06:00
|
|
|
|
2024-11-22 02:04:04 -06:00
|
|
|
MessageService.Success("Script saved!");
|
2023-11-28 20:48:03 -06:00
|
|
|
|
2024-11-22 02:04:04 -06:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
2023-11-30 19:12:25 -06:00
|
|
|
{
|
2024-11-22 02:04:04 -06:00
|
|
|
MessageService.Error("Script could not be saved!");
|
|
|
|
|
Logger.LogError(ex, "Script could not be saved!");
|
2023-11-28 20:48:03 -06:00
|
|
|
|
2024-03-11 17:38:29 -05:00
|
|
|
return false;
|
2024-11-22 02:04:04 -06:00
|
|
|
}
|
2023-11-28 20:48:03 -06:00
|
|
|
}
|
|
|
|
|
}
|