Fix scripts not saving
This commit is contained in:
parent
7c67b7535c
commit
521d6222b0
1 changed files with 29 additions and 9 deletions
|
@ -6,7 +6,15 @@
|
||||||
@inject ModalService ModalService
|
@inject ModalService ModalService
|
||||||
@inject IMessageService MessageService
|
@inject IMessageService MessageService
|
||||||
|
|
||||||
<Modal Visible="ModalVisible" OnOk="Save" OnCancel="() => ModalVisible = false" Title="@(Script == null ? "Add Script" : "Edit Script")" OkText="@("Save")" Maximizable="false" DefaultMaximized="true">
|
@{
|
||||||
|
RenderFragment Footer =
|
||||||
|
@<Template>
|
||||||
|
<Button OnClick="Save" Disabled="@(String.IsNullOrWhiteSpace(Script.Name))" Type="@ButtonType.Primary">Save</Button>
|
||||||
|
<Button OnClick="() => ModalVisible = false">Close</Button>
|
||||||
|
</Template>;
|
||||||
|
}
|
||||||
|
|
||||||
|
<Modal Visible="ModalVisible" Footer="@Footer" Title="@(Script == null ? "Add Script" : "Edit Script")" OkText="@("Save")" Maximizable="false" DefaultMaximized="true" Closable="true">
|
||||||
<Form Model="@Script" Layout="@FormLayout.Vertical">
|
<Form Model="@Script" Layout="@FormLayout.Vertical">
|
||||||
<FormItem>
|
<FormItem>
|
||||||
@foreach (var group in Snippets.Select(s => s.Group).Distinct())
|
@foreach (var group in Snippets.Select(s => s.Group).Distinct())
|
||||||
|
@ -36,16 +44,20 @@
|
||||||
<StandaloneCodeEditor @ref="Editor" Id="editor" ConstructionOptions="EditorConstructionOptions" />
|
<StandaloneCodeEditor @ref="Editor" Id="editor" ConstructionOptions="EditorConstructionOptions" />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
|
|
||||||
|
<FormItem Label="Name">
|
||||||
|
<Input @bind-Value="@context.Name" />
|
||||||
|
</FormItem>
|
||||||
|
|
||||||
<FormItem Label="Type">
|
<FormItem Label="Type">
|
||||||
<Select @bind-Value="Script.Type" TItem="ScriptType" TItemValue="ScriptType" DataSource="Enum.GetValues<ScriptType>()" />
|
<Select @bind-Value="context.Type" TItem="ScriptType" TItemValue="ScriptType" DataSource="Enum.GetValues<ScriptType>()" />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
|
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<Checkbox @bind-Checked="Script.RequiresAdmin">Requires Admin</Checkbox>
|
<Checkbox @bind-Checked="context.RequiresAdmin">Requires Admin</Checkbox>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
|
|
||||||
<FormItem Label="Description">
|
<FormItem Label="Description">
|
||||||
<TextArea @bind-Value="Script.Description" MaxLength=500 ShowCount />
|
<TextArea @bind-Value="context.Description" MaxLength=500 ShowCount />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
</Form>
|
</Form>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
@ -95,7 +107,7 @@
|
||||||
bool ModalVisible = false;
|
bool ModalVisible = false;
|
||||||
|
|
||||||
IEnumerable<Snippet> Snippets { get; set; }
|
IEnumerable<Snippet> Snippets { get; set; }
|
||||||
StandaloneCodeEditor Editor;
|
StandaloneCodeEditor? Editor;
|
||||||
|
|
||||||
private StandaloneEditorConstructionOptions EditorConstructionOptions(StandaloneCodeEditor editor)
|
private StandaloneEditorConstructionOptions EditorConstructionOptions(StandaloneCodeEditor editor)
|
||||||
{
|
{
|
||||||
|
@ -121,12 +133,15 @@
|
||||||
|
|
||||||
private async void Edit(Script script = null)
|
private async void Edit(Script script = null)
|
||||||
{
|
{
|
||||||
if (Script == null)
|
if (script == null)
|
||||||
Script = new Script();
|
Script = new Script()
|
||||||
|
{
|
||||||
|
GameId = Game.Id
|
||||||
|
};
|
||||||
else
|
else
|
||||||
Script = script;
|
Script = script;
|
||||||
|
|
||||||
if (Editor != null)
|
if (Editor != null && Script != null)
|
||||||
await Editor.SetValue(Script.Contents);
|
await Editor.SetValue(Script.Contents);
|
||||||
|
|
||||||
ModalVisible = true;
|
ModalVisible = true;
|
||||||
|
@ -144,7 +159,12 @@
|
||||||
{
|
{
|
||||||
var value = await Editor.GetValue();
|
var value = await Editor.GetValue();
|
||||||
|
|
||||||
await ScriptService.Update(Script);
|
Script.Contents = value;
|
||||||
|
|
||||||
|
if (Script.Id == Guid.Empty)
|
||||||
|
Script = await ScriptService.Add(Script);
|
||||||
|
else
|
||||||
|
Script = await ScriptService.Update(Script);
|
||||||
|
|
||||||
await MessageService.Success("Script saved!");
|
await MessageService.Success("Script saved!");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue