mirror of
https://github.com/chylex/Minecraft-Phantom-Panel.git
synced 2025-05-28 16:34:05 +02:00
Add option to create instances with Minecraft snapshots
This commit is contained in:
parent
98ec0e001c
commit
59cf71e3e1
Common/Phantom.Common.Data/Minecraft
Server
Phantom.Server.Web.Bootstrap/src
Phantom.Server.Web.Components/Forms
Phantom.Server.Web
@ -11,10 +11,9 @@ public enum MinecraftVersionType : ushort {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class MinecraftVersionTypes {
|
public static class MinecraftVersionTypes {
|
||||||
public static readonly ImmutableHashSet<MinecraftVersionType> All = ImmutableHashSet.Create(
|
public static readonly ImmutableArray<MinecraftVersionType> WithServerJars = ImmutableArray.Create(
|
||||||
MinecraftVersionType.Release,
|
MinecraftVersionType.Release,
|
||||||
MinecraftVersionType.Snapshot,
|
MinecraftVersionType.Snapshot
|
||||||
MinecraftVersionType.Other
|
|
||||||
);
|
);
|
||||||
|
|
||||||
public static MinecraftVersionType FromString(string? type) {
|
public static MinecraftVersionType FromString(string? type) {
|
||||||
@ -26,4 +25,14 @@ public static class MinecraftVersionTypes {
|
|||||||
_ => MinecraftVersionType.Other
|
_ => MinecraftVersionType.Other
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string ToNiceNamePlural(this MinecraftVersionType type) {
|
||||||
|
return type switch {
|
||||||
|
MinecraftVersionType.Release => "Releases",
|
||||||
|
MinecraftVersionType.Snapshot => "Snapshots",
|
||||||
|
MinecraftVersionType.OldBeta => "Beta",
|
||||||
|
MinecraftVersionType.OldAlpha => "Alpha",
|
||||||
|
_ => "Unknown"
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,12 @@ $link-color: $success;
|
|||||||
|
|
||||||
$btn-disabled-opacity: 0.7;
|
$btn-disabled-opacity: 0.7;
|
||||||
|
|
||||||
|
$dropdown-link-color: $gray-700;
|
||||||
|
$dropdown-link-hover-color: $gray-700;
|
||||||
|
$dropdown-link-active-color: $gray-700;
|
||||||
|
$dropdown-link-hover-bg: mix($gray-200, $gray-300, 75%);
|
||||||
|
$dropdown-link-active-bg: mix($gray-200, $gray-300, 75%);
|
||||||
|
|
||||||
@import "./components";
|
@import "./components";
|
||||||
|
|
||||||
.spinner-border-sm {
|
.spinner-border-sm {
|
||||||
|
@ -3,9 +3,21 @@
|
|||||||
@inherits FormInputBase<TValue>
|
@inherits FormInputBase<TValue>
|
||||||
|
|
||||||
<FormLabel Id="@Id" Label="@Label" LabelFragment="@LabelFragment" />
|
<FormLabel Id="@Id" Label="@Label" LabelFragment="@LabelFragment" />
|
||||||
<InputSelect Value="@Value" ValueChanged="@ValueChanged" ValueExpression="@ValueExpression" AdditionalAttributes="@GetAttributes("form-select")">
|
|
||||||
@ChildContent
|
@if (GroupContent == null) {
|
||||||
</InputSelect>
|
<InputSelect Value="@Value" ValueChanged="@ValueChanged" ValueExpression="@ValueExpression" AdditionalAttributes="@GetAttributes("form-select")">
|
||||||
|
@ChildContent
|
||||||
|
</InputSelect>
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
<div class="input-group">
|
||||||
|
<InputSelect Value="@Value" ValueChanged="@ValueChanged" ValueExpression="@ValueExpression" AdditionalAttributes="@GetAttributes("form-select")">
|
||||||
|
@ChildContent
|
||||||
|
</InputSelect>
|
||||||
|
@GroupContent
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
<FormValidationMessage For="@ValueExpression" />
|
<FormValidationMessage For="@ValueExpression" />
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
@ -14,4 +26,7 @@
|
|||||||
[DisallowNull]
|
[DisallowNull]
|
||||||
public RenderFragment? ChildContent { get; set; }
|
public RenderFragment? ChildContent { get; set; }
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public RenderFragment? GroupContent { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
@page "/instances/create"
|
@page "/instances/create"
|
||||||
|
@using Phantom.Common.Data.Minecraft
|
||||||
@using Phantom.Common.Minecraft
|
@using Phantom.Common.Minecraft
|
||||||
@using Phantom.Server.Services.Agents
|
@using Phantom.Server.Services.Agents
|
||||||
@using Phantom.Server.Services.Audit
|
@using Phantom.Server.Services.Audit
|
||||||
@ -7,7 +8,6 @@
|
|||||||
@using System.Collections.Immutable
|
@using System.Collections.Immutable
|
||||||
@using System.ComponentModel.DataAnnotations
|
@using System.ComponentModel.DataAnnotations
|
||||||
@using System.Diagnostics.CodeAnalysis
|
@using System.Diagnostics.CodeAnalysis
|
||||||
@using Phantom.Common.Data.Minecraft
|
|
||||||
@using Phantom.Common.Data.Java
|
@using Phantom.Common.Data.Java
|
||||||
@using Phantom.Common.Data
|
@using Phantom.Common.Data
|
||||||
@using Phantom.Common.Data.Instance
|
@using Phantom.Common.Data.Instance
|
||||||
@ -21,6 +21,7 @@
|
|||||||
<h1>New Instance</h1>
|
<h1>New Instance</h1>
|
||||||
|
|
||||||
<Form Model="form" OnSubmit="Submit">
|
<Form Model="form" OnSubmit="Submit">
|
||||||
|
@{ var selectedAgent = form.SelectedAgent; }
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-xl-7 mb-3">
|
<div class="col-xl-7 mb-3">
|
||||||
<FormSelectInput Id="instance-agent" Label="Agent" @bind-Value="form.SelectedAgentGuid">
|
<FormSelectInput Id="instance-agent" Label="Agent" @bind-Value="form.SelectedAgentGuid">
|
||||||
@ -51,15 +52,27 @@
|
|||||||
</FormSelectInput>
|
</FormSelectInput>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-sm-6 col-xl-2 mb-3">
|
<div class="col-sm-6 col-xl-3 mb-3">
|
||||||
<FormSelectInput Id="instance-minecraft-version" Label="Minecraft Version" @bind-Value="form.MinecraftVersion">
|
<FormSelectInput Id="instance-minecraft-version" Label="Minecraft Version" @bind-Value="form.MinecraftVersion">
|
||||||
@foreach (var version in availableMinecraftVersions) {
|
<ChildContent>
|
||||||
<option value="@version.Id">@version.Id</option>
|
@foreach (var version in availableMinecraftVersions) {
|
||||||
}
|
<option value="@version.Id">@version.Id</option>
|
||||||
|
}
|
||||||
|
</ChildContent>
|
||||||
|
<GroupContent>
|
||||||
|
<button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">@minecraftVersionType.ToNiceNamePlural()</button>
|
||||||
|
<ul class="dropdown-menu dropdown-menu-end">
|
||||||
|
@foreach (var versionType in MinecraftVersionTypes.WithServerJars) {
|
||||||
|
<li>
|
||||||
|
<button class="dropdown-item" @onclick="() => SetMinecraftVersionType(versionType)">@versionType.ToNiceNamePlural()</button>
|
||||||
|
</li>
|
||||||
|
}
|
||||||
|
</ul>
|
||||||
|
</GroupContent>
|
||||||
</FormSelectInput>
|
</FormSelectInput>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-xl-4 mb-3">
|
<div class="col-xl-3 mb-3">
|
||||||
<FormSelectInput Id="instance-java-runtime" Label="Java Runtime" @bind-Value="form.JavaRuntimeGuid" disabled="@(form.JavaRuntimesForSelectedAgent.IsEmpty)">
|
<FormSelectInput Id="instance-java-runtime" Label="Java Runtime" @bind-Value="form.JavaRuntimeGuid" disabled="@(form.JavaRuntimesForSelectedAgent.IsEmpty)">
|
||||||
<option value="" selected>Select Java runtime...</option>
|
<option value="" selected>Select Java runtime...</option>
|
||||||
@foreach (var (guid, runtime) in form.JavaRuntimesForSelectedAgent) {
|
@foreach (var (guid, runtime) in form.JavaRuntimesForSelectedAgent) {
|
||||||
@ -69,59 +82,59 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
@{
|
@{
|
||||||
var selectedAgent = form.SelectedAgent;
|
|
||||||
|
|
||||||
string? allowedServerPorts = selectedAgent?.Agent.AllowedServerPorts?.ToString();
|
string? allowedServerPorts = selectedAgent?.Agent.AllowedServerPorts?.ToString();
|
||||||
string? allowedRconPorts = selectedAgent?.Agent.AllowedRconPorts?.ToString();
|
string? allowedRconPorts = selectedAgent?.Agent.AllowedRconPorts?.ToString();
|
||||||
|
|
||||||
RenderFragment serverPortLabel;
|
|
||||||
RenderFragment rconPortLabel;
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(allowedServerPorts)) {
|
|
||||||
serverPortLabel = @<text>Server Port</text>;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
serverPortLabel = @<text>Server Port <sup title="Allowed: @allowedServerPorts">[?]</sup></text>;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(allowedRconPorts)) {
|
|
||||||
rconPortLabel = @<text>Rcon Port</text>;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
rconPortLabel = @<text>Rcon Port <sup title="Allowed: @allowedRconPorts">[?]</sup></text>;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
<div class="col-sm-6 col-xl-2 mb-3">
|
<div class="col-sm-6 col-xl-2 mb-3">
|
||||||
<FormNumberInput Id="instance-server-port" LabelFragment="@serverPortLabel" @bind-Value="form.ServerPort" min="0" max="65535" />
|
<FormNumberInput Id="instance-server-port" @bind-Value="form.ServerPort" min="0" max="65535">
|
||||||
|
<LabelFragment>
|
||||||
|
@if (string.IsNullOrEmpty(allowedServerPorts)) {
|
||||||
|
<text>Server Port</text>
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
<text>Server Port <sup title="Allowed: @allowedServerPorts">[?]</sup></text>
|
||||||
|
}
|
||||||
|
</LabelFragment>
|
||||||
|
</FormNumberInput>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-sm-6 col-xl-2 mb-3">
|
<div class="col-sm-6 col-xl-2 mb-3">
|
||||||
<FormNumberInput Id="instance-rcon-port" LabelFragment="@rconPortLabel" @bind-Value="form.RconPort" min="0" max="65535" />
|
<FormNumberInput Id="instance-rcon-port" @bind-Value="form.RconPort" min="0" max="65535">
|
||||||
|
<LabelFragment>
|
||||||
|
@if (string.IsNullOrEmpty(allowedRconPorts)) {
|
||||||
|
<text>Rcon Port</text>
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
<text>Rcon Port <sup title="Allowed: @allowedRconPorts">[?]</sup></text>
|
||||||
|
}
|
||||||
|
</LabelFragment>
|
||||||
|
</FormNumberInput>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-xl-12 mb-3">
|
<div class="col-xl-12 mb-3">
|
||||||
@{
|
@{ ushort maximumMemoryUnits = form.MaximumMemoryUnits; }
|
||||||
ushort maximumMemoryUnits = form.MaximumMemoryUnits;
|
<FormNumberInput Id="instance-memory" Type="FormNumberInputType.Range" DebounceMillis="0" DisableTwoWayBinding="true" @bind-Value="form.MemoryUnits" min="2" max="@maximumMemoryUnits" disabled="@(maximumMemoryUnits == 0)">
|
||||||
RenderFragment ramLabel;
|
<LabelFragment>
|
||||||
if (maximumMemoryUnits == 0) {
|
@if (maximumMemoryUnits == 0) {
|
||||||
ramLabel = @<text>RAM</text>;
|
<text>RAM</text>
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ramLabel = @<text>RAM • <code>@(form.MemoryAllocation?.InMegabytes ?? 0) / @(selectedAgent?.AvailableMemory.InMegabytes) MB</code></text>;
|
<text>RAM • <code>@(form.MemoryAllocation?.InMegabytes ?? 0) / @(selectedAgent?.AvailableMemory.InMegabytes) MB</code></text>
|
||||||
}
|
}
|
||||||
}
|
</LabelFragment>
|
||||||
<FormNumberInput Id="instance-memory" LabelFragment="@ramLabel" Type="FormNumberInputType.Range" DebounceMillis="0" DisableTwoWayBinding="true" @bind-Value="form.MemoryUnits" min="2" max="@maximumMemoryUnits" disabled="@(maximumMemoryUnits == 0)" />
|
</FormNumberInput>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
@{
|
<FormTextInput Id="instance-jvm-arguments" Type="FormTextInputType.Textarea" @bind-Value="form.JvmArguments" rows="4">
|
||||||
RenderFragment jvmArgumentsLabel = @<text>JVM Arguments <span class="text-black-50">(one per line)</span></text>;
|
<LabelFragment>
|
||||||
}
|
JVM Arguments <span class="text-black-50">(one per line)</span>
|
||||||
<FormTextInput Id="instance-jvm-arguments" LabelFragment="@jvmArgumentsLabel" Type="FormTextInputType.Textarea" @bind-Value="form.JvmArguments" rows="4" />
|
</LabelFragment>
|
||||||
|
</FormTextInput>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -132,6 +145,8 @@
|
|||||||
@code {
|
@code {
|
||||||
|
|
||||||
private CreateInstanceFormModel form = null!;
|
private CreateInstanceFormModel form = null!;
|
||||||
|
|
||||||
|
private MinecraftVersionType minecraftVersionType = MinecraftVersionType.Release;
|
||||||
private ImmutableArray<MinecraftVersion> availableMinecraftVersions = ImmutableArray<MinecraftVersion>.Empty;
|
private ImmutableArray<MinecraftVersion> availableMinecraftVersions = ImmutableArray<MinecraftVersion>.Empty;
|
||||||
|
|
||||||
private bool IsSubmittable => form.SelectedAgentGuid != null && !form.EditContext.GetValidationMessages(form.EditContext.Field(nameof(CreateInstanceFormModel.SelectedAgentGuid))).Any();
|
private bool IsSubmittable => form.SelectedAgentGuid != null && !form.EditContext.GetValidationMessages(form.EditContext.Field(nameof(CreateInstanceFormModel.SelectedAgentGuid))).Any();
|
||||||
@ -248,11 +263,17 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected override async Task OnInitializedAsync() {
|
protected override async Task OnInitializedAsync() {
|
||||||
|
await SetMinecraftVersionType(minecraftVersionType);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task SetMinecraftVersionType(MinecraftVersionType type) {
|
||||||
|
minecraftVersionType = type;
|
||||||
|
|
||||||
var allMinecraftVersions = await MinecraftVersions.GetVersions(CancellationToken.None);
|
var allMinecraftVersions = await MinecraftVersions.GetVersions(CancellationToken.None);
|
||||||
availableMinecraftVersions = allMinecraftVersions.Where(static version => version.Type == MinecraftVersionType.Release).ToImmutableArray();
|
availableMinecraftVersions = allMinecraftVersions.Where(version => version.Type == type).ToImmutableArray();
|
||||||
|
|
||||||
if (!availableMinecraftVersions.IsEmpty) {
|
if (!availableMinecraftVersions.IsEmpty) {
|
||||||
form.MinecraftVersion = allMinecraftVersions[0].Id;
|
form.MinecraftVersion = availableMinecraftVersions[0].Id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user