2025-02-01 02:21:34 -06:00
|
|
|
@inherits FeedbackComponent<ScriptEditorOptions, Script>
|
|
|
|
|
@inject ScriptService ScriptService
|
2023-11-28 20:48:03 -06:00
|
|
|
@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();
|
|
|
|
|
|
2025-02-04 20:58:08 -06:00
|
|
|
Script Script = new();
|
2023-11-28 20:48:03 -06:00
|
|
|
|
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
|
|
|
{
|
2025-02-01 02:21:34 -06:00
|
|
|
if (Options.ScriptId != Guid.Empty)
|
|
|
|
|
Script = await ScriptService.GetAsync(Options.ScriptId);
|
|
|
|
|
else if (Options.GameId != Guid.Empty)
|
|
|
|
|
Script = new Script()
|
|
|
|
|
{
|
|
|
|
|
GameId = Options.GameId
|
|
|
|
|
};
|
|
|
|
|
else if (Options.RedistributableId != Guid.Empty)
|
|
|
|
|
Script = new Script()
|
|
|
|
|
{
|
|
|
|
|
RedistributableId = Options.RedistributableId
|
|
|
|
|
};
|
|
|
|
|
else if (Options.ServerId != Guid.Empty)
|
|
|
|
|
Script = new Script()
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
{
|
2025-02-01 02:21:34 -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
|
|
|
}
|
|
|
|
|
}
|