191 lines
No EOL
6.6 KiB
Text
191 lines
No EOL
6.6 KiB
Text
@page "/Servers/{id:guid}"
|
|
@page "/Servers/{id:guid}/{panel}"
|
|
@page "/Servers/{id:guid}/{panel}/{logId:guid}"
|
|
@page "/Servers/Add"
|
|
@using LANCommander.Pages.Servers.Components
|
|
@inject GameService GameService
|
|
@inject ServerService ServerService
|
|
@inject ServerProcessService ServerProcessService
|
|
@inject IMessageService MessageService
|
|
@inject NavigationManager NavigationManager
|
|
|
|
<Layout Class="site-layout-background" Style="padding: 24px 0;">
|
|
<Sider Class="site-layout-background" Width="200">
|
|
<Menu Mode="@MenuMode.Inline" Style="height: 100%;">
|
|
<MenuItem RouterLink="@($"/Servers/{Server.Id}/General")">General</MenuItem>
|
|
|
|
@if (Server != null && Server.Id != Guid.Empty)
|
|
{
|
|
<SubMenu Key="sub1" Title="Console">
|
|
@foreach (var log in Server.ServerConsoles)
|
|
{
|
|
<MenuItem Key="@log.Id.ToString()" RouterLink="@($"/Servers/{Server.Id}/Console/{log.Id}")">@log.Name</MenuItem>
|
|
}
|
|
</SubMenu>
|
|
<MenuItem RouterLink="@($"/Servers/{Server.Id}/Files")">Files</MenuItem>
|
|
}
|
|
</Menu>
|
|
</Sider>
|
|
|
|
<Content>
|
|
<PageHeader>
|
|
<PageHeaderTitle>@Panel</PageHeaderTitle>
|
|
<PageHeaderExtra>
|
|
@if (Server.Id != Guid.Empty)
|
|
{
|
|
<ServerControl ServerId="Id" />
|
|
}
|
|
</PageHeaderExtra>
|
|
</PageHeader>
|
|
|
|
|
|
<div class="site-layout-content">
|
|
@if (Panel == "General" || String.IsNullOrWhiteSpace(Panel))
|
|
{
|
|
<Form Model="@Server" Layout="@FormLayout.Vertical">
|
|
<FormItem Label="Name">
|
|
<Input @bind-Value="@context.Name" />
|
|
</FormItem>
|
|
<FormItem Label="Game">
|
|
<Select TItem="Game"
|
|
TItemValue="Guid"
|
|
DataSource="@Games.OrderBy(g => String.IsNullOrWhiteSpace(g.SortTitle) ? g.Title : g.SortTitle)"
|
|
@bind-Value="@GameId"
|
|
LabelName="Title"
|
|
ValueName="Id"
|
|
Placeholder="Select a Game"
|
|
DefaultActiveFirstOption="false"
|
|
EnableSearch>
|
|
<ItemTemplate Context="game">
|
|
<Image Src="@GetIcon(game)" Height="32" Width="32" Preview="false"></Image>
|
|
@game.Title
|
|
</ItemTemplate>
|
|
</Select>
|
|
</FormItem>
|
|
<FormItem Label="Path">
|
|
<Input @bind-Value="@context.Path" />
|
|
</FormItem>
|
|
<FormItem Label="Arguments">
|
|
<Input @bind-Value="@context.Arguments" />
|
|
</FormItem>
|
|
<FormItem Label="Working Directory">
|
|
<Input @bind-Value="@context.WorkingDirectory" />
|
|
</FormItem>
|
|
<FormItem>
|
|
<LabelTemplate>
|
|
Use Shell Execute
|
|
<Tooltip Title="This option specifies whether you would like to run the server using the shell. Some servers may require this as they will have a UI or won't output logs to stdout">
|
|
<Icon Type="@IconType.Outline.QuestionCircle" Theme="@IconThemeType.Outline" />
|
|
</Tooltip>
|
|
</LabelTemplate>
|
|
<ChildContent>
|
|
<Switch @bind-Checked="context.UseShellExecute" />
|
|
</ChildContent>
|
|
</FormItem>
|
|
<FormItem Label="Autostart">
|
|
<Switch @bind-Checked="context.Autostart" />
|
|
</FormItem>
|
|
@if (context.Autostart)
|
|
{
|
|
<FormItem Label="Autostart Delay">
|
|
<AntDesign.Input @bind-Value="context.AutostartDelay" Placeholder="0">
|
|
<Suffix>Seconds</Suffix>
|
|
</AntDesign.Input>
|
|
</FormItem>
|
|
}
|
|
|
|
<FormItem>
|
|
<ServerConsoleEditor @bind-Value="Server.ServerConsoles" ServerId="Id" />
|
|
</FormItem>
|
|
|
|
<FormItem>
|
|
<Button Type="@ButtonType.Primary" OnClick="Save" Icon="@IconType.Fill.Save">Save</Button>
|
|
</FormItem>
|
|
</Form>
|
|
}
|
|
|
|
@if (Panel == "Console")
|
|
{
|
|
<Console ServerId="@Server.Id" ServerConsoleId="@LogId" />
|
|
}
|
|
|
|
@if (Panel == "Files")
|
|
{
|
|
<TextEditor WorkingDirectory="@Server.WorkingDirectory" />
|
|
}
|
|
</div>
|
|
</Content>
|
|
</Layout>
|
|
|
|
<style>
|
|
.site-layout-background {
|
|
background: #fff;
|
|
}
|
|
|
|
.site-layout-content {
|
|
padding: 0 24px;
|
|
}
|
|
|
|
.ant-layout-content > .ant-page-header-heading {
|
|
padding-top: 0;
|
|
}
|
|
</style>
|
|
|
|
@code {
|
|
[Parameter] public Guid Id { get; set; }
|
|
[Parameter] public string Panel { get; set; }
|
|
[Parameter] public Guid LogId { get; set; }
|
|
|
|
IEnumerable<Game> Games = new List<Game>();
|
|
|
|
Server Server;
|
|
Guid GameId;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
if (Id == Guid.Empty)
|
|
Server = new Server();
|
|
else
|
|
Server = await ServerService.Get(Id);
|
|
|
|
if (String.IsNullOrWhiteSpace(Server.WorkingDirectory))
|
|
Server.WorkingDirectory = "C:\\";
|
|
|
|
if (Server.GameId.HasValue)
|
|
GameId = Server.GameId.Value;
|
|
|
|
Games = GameService.Get().ToList();
|
|
}
|
|
|
|
private async Task Save()
|
|
{
|
|
try
|
|
{
|
|
Server.GameId = GameId;
|
|
|
|
if (Server.Id != Guid.Empty)
|
|
{
|
|
Server = await ServerService.Update(Server);
|
|
|
|
await MessageService.Success("Server updated!");
|
|
}
|
|
else
|
|
{
|
|
Server = await ServerService.Add(Server);
|
|
|
|
await MessageService.Success("Server added!");
|
|
|
|
NavigationManager.NavigateTo($"/Servers/{Server.Id}");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
await MessageService.Error("Could not save!");
|
|
}
|
|
}
|
|
|
|
private string GetIcon(Game game)
|
|
{
|
|
return $"/api/Games/{game?.Id}/Icon.png";
|
|
}
|
|
} |