mirror of
https://github.com/chylex/Minecraft-Phantom-Panel.git
synced 2025-05-02 03:34:06 +02:00
58 lines
2.0 KiB
Plaintext
58 lines
2.0 KiB
Plaintext
@using Phantom.Web.Services.Instances
|
|
@using Phantom.Common.Data.Web.Users
|
|
@using Phantom.Common.Data.Replies
|
|
@inherits Phantom.Web.Components.PhantomComponent
|
|
@inject InstanceManager InstanceManager
|
|
|
|
<Form Model="form" OnSubmit="ExecuteCommand">
|
|
<label for="command-input" class="form-label">Instance Name</label>
|
|
<div class="input-group flex-nowrap">
|
|
<span class="input-group-text" style="padding-top: 0.3rem;">/</span>
|
|
<input id="command-input" class="form-control" type="text" placeholder="command" @bind="form.Command" @bind:event="oninput" disabled="@(Disabled || form.SubmitModel.IsSubmitting)" @ref="commandInputElement" />
|
|
<FormButtonSubmit Label="Execute" class="btn btn-primary" disabled="@(Disabled || string.IsNullOrWhiteSpace(form.Command))" />
|
|
</div>
|
|
<FormSubmitError />
|
|
</Form>
|
|
|
|
@code {
|
|
|
|
[Parameter, EditorRequired]
|
|
public Guid AgentGuid { get; set; }
|
|
|
|
[Parameter, EditorRequired]
|
|
public Guid InstanceGuid { get; set; }
|
|
|
|
[Parameter]
|
|
public bool Disabled { get; set; }
|
|
|
|
private readonly SendCommandFormModel form = new ();
|
|
|
|
private sealed class SendCommandFormModel : FormModel {
|
|
public string Command { get; set; } = string.Empty;
|
|
}
|
|
|
|
private ElementReference commandInputElement;
|
|
|
|
private async Task ExecuteCommand(EditContext context) {
|
|
await form.SubmitModel.StartSubmitting();
|
|
|
|
var loggedInUserGuid = await GetUserGuid();
|
|
if (loggedInUserGuid == null || !await CheckPermission(Permission.ControlInstances)) {
|
|
form.SubmitModel.StopSubmitting("You do not have permission to execute commands.");
|
|
return;
|
|
}
|
|
|
|
var result = await InstanceManager.SendCommandToInstance(loggedInUserGuid.Value, AgentGuid, InstanceGuid, form.Command, CancellationToken);
|
|
if (result.Is(SendCommandToInstanceResult.Success)) {
|
|
form.Command = string.Empty;
|
|
form.SubmitModel.StopSubmitting();
|
|
}
|
|
else {
|
|
form.SubmitModel.StopSubmitting(result.ToSentence(Messages.ToSentence));
|
|
}
|
|
|
|
await commandInputElement.FocusAsync(preventScroll: true);
|
|
}
|
|
|
|
}
|