Implemented owner change option in admin ui
This commit is contained in:
29
Moonlight/App/Models/Forms/ServerEditDataModel.cs
Normal file
29
Moonlight/App/Models/Forms/ServerEditDataModel.cs
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using Moonlight.App.Database.Entities;
|
||||||
|
|
||||||
|
namespace Moonlight.App.Models.Forms;
|
||||||
|
|
||||||
|
public class ServerEditDataModel
|
||||||
|
{
|
||||||
|
[Required(ErrorMessage = "You need to enter a name")]
|
||||||
|
[MaxLength(32, ErrorMessage = "The name cannot be longer that 32 characters")]
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
[Required(ErrorMessage = "You need to specify a user")]
|
||||||
|
public User Owner { get; set; }
|
||||||
|
|
||||||
|
[Required(ErrorMessage = "You need to specify the cpu cores")]
|
||||||
|
public int Cpu { get; set; }
|
||||||
|
|
||||||
|
[Required(ErrorMessage = "You need to specify the memory")]
|
||||||
|
public long Memory { get; set; }
|
||||||
|
|
||||||
|
[Required(ErrorMessage = "You need to specify the disk")]
|
||||||
|
public long Disk { get; set; }
|
||||||
|
|
||||||
|
public string OverrideStartup { get; set; }
|
||||||
|
|
||||||
|
public int DockerImageIndex { get; set; }
|
||||||
|
|
||||||
|
public bool IsCleanupException { get; set; }
|
||||||
|
}
|
||||||
@@ -4,12 +4,14 @@
|
|||||||
@using Moonlight.App.Repositories.Servers
|
@using Moonlight.App.Repositories.Servers
|
||||||
@using Moonlight.App.Database.Entities
|
@using Moonlight.App.Database.Entities
|
||||||
@using Microsoft.EntityFrameworkCore
|
@using Microsoft.EntityFrameworkCore
|
||||||
|
@using Moonlight.App.Models.Forms
|
||||||
@using Moonlight.App.Repositories
|
@using Moonlight.App.Repositories
|
||||||
|
@using Mappy.Net
|
||||||
|
|
||||||
@inject SmartTranslateService SmartTranslateService
|
@inject SmartTranslateService SmartTranslateService
|
||||||
@inject ServerRepository ServerRepository
|
@inject ServerRepository ServerRepository
|
||||||
@inject ServerService ServerService
|
|
||||||
@inject ImageRepository ImageRepository
|
@inject ImageRepository ImageRepository
|
||||||
|
@inject Repository<User> UserRepository
|
||||||
|
|
||||||
<OnlyAdmin>
|
<OnlyAdmin>
|
||||||
<LazyLoader @ref="LazyLoader" Load="Load">
|
<LazyLoader @ref="LazyLoader" Load="Load">
|
||||||
@@ -21,143 +23,152 @@
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
<div class="row mb-5">
|
<SmartForm Model="Model" OnValidSubmit="OnValidSubmit">
|
||||||
<div class="card card-body p-10">
|
<div class="row mb-5">
|
||||||
<label class="form-label">
|
<div class="card card-body p-10">
|
||||||
<TL>Identifier</TL>
|
<label class="form-label">
|
||||||
</label>
|
<TL>Identifier</TL>
|
||||||
<div class="input-group mb-5">
|
</label>
|
||||||
<span class="input-group-text">
|
<div class="input-group mb-5">
|
||||||
<i class="bx bx-id-card"></i>
|
<span class="input-group-text">
|
||||||
</span>
|
<i class="bx bx-id-card"></i>
|
||||||
<input @bind="Server.Id" type="number" class="form-control disabled" disabled="">
|
</span>
|
||||||
</div>
|
<input type="number" class="form-control disabled" disabled="" value="@(Server.Id)">
|
||||||
<label class="form-label">
|
</div>
|
||||||
<TL>UuidIdentifier</TL>
|
<label class="form-label">
|
||||||
</label>
|
<TL>UuidIdentifier</TL>
|
||||||
<div class="input-group mb-5">
|
</label>
|
||||||
<span class="input-group-text">
|
<div class="input-group mb-5">
|
||||||
<i class="bx bx-id-card"></i>
|
<span class="input-group-text">
|
||||||
</span>
|
<i class="bx bx-id-card"></i>
|
||||||
<input @bind="Server.Uuid" type="text" class="form-control disabled" disabled="">
|
</span>
|
||||||
</div>
|
<input type="text" class="form-control disabled" disabled="" value="@(Server.Uuid)">
|
||||||
<label class="form-label">
|
</div>
|
||||||
<TL>Server name</TL>
|
<label class="form-label">
|
||||||
</label>
|
<TL>Server name</TL>
|
||||||
<div class="input-group mb-5">
|
</label>
|
||||||
<span class="input-group-text">
|
<div class="input-group mb-5">
|
||||||
<i class="bx bx-purchase-tag-alt"></i>
|
<span class="input-group-text">
|
||||||
</span>
|
<i class="bx bx-purchase-tag-alt"></i>
|
||||||
<input @bind="Server.Name" type="text" class="form-control" placeholder="@(SmartTranslateService.Translate("Server name"))" aria-label="Servername">
|
</span>
|
||||||
|
<InputText @bind-Value="Model.Name" type="text" class="form-control" placeholder="@(SmartTranslateService.Translate("Server name"))"></InputText>
|
||||||
|
</div>
|
||||||
|
<label class="form-label">
|
||||||
|
<TL>Owner</TL>
|
||||||
|
</label>
|
||||||
|
<div class="input-group mb-5">
|
||||||
|
<SmartDropdown T="User"
|
||||||
|
@bind-Value="Model.Owner"
|
||||||
|
Items="Users"
|
||||||
|
DisplayFunc="@(x => x.Email)"
|
||||||
|
SearchProp="@(x => x.Email)">
|
||||||
|
</SmartDropdown>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<div class="row mb-5">
|
||||||
<div class="row mb-5">
|
<div class="card card-body p-10">
|
||||||
<div class="card card-body p-10">
|
<label class="form-label">
|
||||||
<label class="form-label">
|
<TL>Cpu cores</TL>
|
||||||
<TL>Cpu cores</TL>
|
</label>
|
||||||
</label>
|
<div class="input-group mb-5">
|
||||||
<div class="input-group mb-5">
|
<span class="input-group-text">
|
||||||
<span class="input-group-text">
|
<i class="bx bx-chip"></i>
|
||||||
<i class="bx bx-chip"></i>
|
</span>
|
||||||
</span>
|
<InputNumber @bind-Value="Model.Cpu" type="number" class="form-control"></InputNumber>
|
||||||
<input @bind="Server.Cpu" type="number" class="form-control">
|
<span class="input-group-text">
|
||||||
<span class="input-group-text">
|
<TL>CPU Cores (100% = 1 Core)</TL>
|
||||||
<TL>CPU Cores (100% = 1 Core)</TL>
|
</span>
|
||||||
</span>
|
</div>
|
||||||
</div>
|
<label class="form-label">
|
||||||
<label class="form-label">
|
<TL>Memory</TL>
|
||||||
<TL>Memory</TL>
|
</label>
|
||||||
</label>
|
<div class="input-group mb-5">
|
||||||
<div class="input-group mb-5">
|
<span class="input-group-text">
|
||||||
<span class="input-group-text">
|
<i class="bx bx-microchip"></i>
|
||||||
<i class="bx bx-microchip"></i>
|
</span>
|
||||||
</span>
|
<InputNumber @bind-Value="Model.Memory" type="number" class="form-control"></InputNumber>
|
||||||
<input @bind="Server.Memory" type="number" class="form-control">
|
<span class="input-group-text">
|
||||||
<span class="input-group-text">
|
MB
|
||||||
MB
|
</span>
|
||||||
</span>
|
</div>
|
||||||
</div>
|
<label class="form-label">
|
||||||
<label class="form-label">
|
<TL>Disk</TL>
|
||||||
<TL>Disk</TL>
|
</label>
|
||||||
</label>
|
<div class="input-group mb-5">
|
||||||
<div class="input-group mb-5">
|
<span class="input-group-text">
|
||||||
<span class="input-group-text">
|
<i class="bx bx-hdd"></i>
|
||||||
<i class="bx bx-hdd"></i>
|
</span>
|
||||||
</span>
|
<InputNumber @bind-Value="Model.Disk" type="number" class="form-control"></InputNumber>
|
||||||
<input @bind="Server.Disk" type="number" class="form-control">
|
<span class="input-group-text">
|
||||||
<span class="input-group-text">
|
MB
|
||||||
MB
|
</span>
|
||||||
</span>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<div class="row mb-5">
|
||||||
<div class="row mb-5">
|
<div class="card card-body p-10">
|
||||||
<div class="card card-body p-10">
|
<label class="form-label">
|
||||||
<label class="form-label">
|
<TL>Override startup command</TL>
|
||||||
<TL>Override startup command</TL>
|
</label>
|
||||||
</label>
|
<div class="input-group mb-5">
|
||||||
<div class="input-group mb-5">
|
<span class="input-group-text">
|
||||||
<span class="input-group-text">
|
<i class="bx bx-terminal"></i>
|
||||||
<i class="bx bx-terminal"></i>
|
</span>
|
||||||
</span>
|
<InputText @bind-Value="Model.OverrideStartup" type="text" class="form-control" placeholder="@(Server.Image.Startup)"></InputText>
|
||||||
<input @bind="Server.OverrideStartup" type="text" class="form-control" placeholder="@(Server.Image.Startup)">
|
</div>
|
||||||
|
<label class="form-label">
|
||||||
|
<TL>Docker image</TL>
|
||||||
|
</label>
|
||||||
|
<select @bind="Model.DockerImageIndex" class="form-select">
|
||||||
|
@foreach (var image in DockerImages)
|
||||||
|
{
|
||||||
|
<option value="@(DockerImages.IndexOf(image))">@(image.Name)</option>
|
||||||
|
}
|
||||||
|
</select>
|
||||||
|
<label class="form-label">
|
||||||
|
<TL>Cleanup exception</TL>
|
||||||
|
</label>
|
||||||
|
<input @bind="Model.IsCleanupException" class="form-check" type="checkbox"/>
|
||||||
</div>
|
</div>
|
||||||
<label class="form-label">
|
|
||||||
<TL>Docker image</TL>
|
|
||||||
</label>
|
|
||||||
<select @bind="Server.DockerImageIndex" class="form-select">
|
|
||||||
@foreach (var image in DockerImages)
|
|
||||||
{
|
|
||||||
<option value="@(DockerImages.IndexOf(image))">@(image.Name)</option>
|
|
||||||
}
|
|
||||||
</select>
|
|
||||||
<label class="form-label">
|
|
||||||
<TL>Cleanup exception</TL>
|
|
||||||
</label>
|
|
||||||
<input @bind="Server.IsCleanupException" class="form-control" type="checkbox" />
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<div class="row mb-5">
|
||||||
<div class="row mb-5">
|
@foreach (var vars in Server.Variables.Chunk(4))
|
||||||
@foreach (var vars in Server.Variables.Chunk(4))
|
{
|
||||||
{
|
<div class="row mb-3">
|
||||||
<div class="row mb-3">
|
@foreach (var variable in vars)
|
||||||
@foreach (var variable in vars)
|
{
|
||||||
{
|
<div class="col">
|
||||||
<div class="col">
|
<div class="card card-body">
|
||||||
<div class="card card-body">
|
<label class="form-label">
|
||||||
<label class="form-label">
|
<TL>Name</TL>
|
||||||
<TL>Name</TL>
|
</label>
|
||||||
</label>
|
<div class="input-group mb-5">
|
||||||
<div class="input-group mb-5">
|
<input @bind="variable.Key" type="text" class="form-control disabled" disabled="">
|
||||||
<input @bind="variable.Key" type="text" class="form-control disabled" disabled="">
|
</div>
|
||||||
</div>
|
<label class="form-label">
|
||||||
<label class="form-label">
|
<TL>Value</TL>
|
||||||
<TL>Value</TL>
|
</label>
|
||||||
</label>
|
<div class="input-group mb-5">
|
||||||
<div class="input-group mb-5">
|
<input @bind="variable.Value" type="text" class="form-control">
|
||||||
<input @bind="variable.Value" type="text" class="form-control">
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
}
|
||||||
}
|
</div>
|
||||||
</div>
|
}
|
||||||
}
|
</div>
|
||||||
</div>
|
<div class="row">
|
||||||
<div class="row">
|
<div class="card card-body">
|
||||||
<div class="card card-body">
|
<div class="d-flex justify-content-end">
|
||||||
<div class="d-flex justify-content-end">
|
<a href="/admin/servers/images" class="btn btn-danger me-3">
|
||||||
<a href="/admin/servers/images" class="btn btn-danger me-3">
|
<TL>Cancel</TL>
|
||||||
<TL>Cancel</TL>
|
</a>
|
||||||
</a>
|
<button class="btn btn-success" type="submit"><TL>Save</TL></button>
|
||||||
<WButton Text="@(SmartTranslateService.Translate("Save"))"
|
</div>
|
||||||
WorkingText="@(SmartTranslateService.Translate("Saving"))"
|
|
||||||
CssClasses="btn-success"
|
|
||||||
OnClick="Save">
|
|
||||||
</WButton>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</SmartForm>
|
||||||
}
|
}
|
||||||
</LazyLoader>
|
</LazyLoader>
|
||||||
</OnlyAdmin>
|
</OnlyAdmin>
|
||||||
@@ -173,7 +184,11 @@
|
|||||||
private List<DockerImage> DockerImages;
|
private List<DockerImage> DockerImages;
|
||||||
private List<Image> Images;
|
private List<Image> Images;
|
||||||
|
|
||||||
private Task Load(LazyLoader arg)
|
private User[] Users;
|
||||||
|
|
||||||
|
private ServerEditDataModel Model = new();
|
||||||
|
|
||||||
|
private async Task Load(LazyLoader lazyLoader)
|
||||||
{
|
{
|
||||||
Server = ServerRepository
|
Server = ServerRepository
|
||||||
.Get()
|
.Get()
|
||||||
@@ -182,25 +197,34 @@
|
|||||||
|
|
||||||
if (Server != null)
|
if (Server != null)
|
||||||
{
|
{
|
||||||
|
await lazyLoader.SetText("Loading images");
|
||||||
|
|
||||||
Images = ImageRepository
|
Images = ImageRepository
|
||||||
.Get()
|
.Get()
|
||||||
.Include(x => x.Variables)
|
.Include(x => x.Variables)
|
||||||
.Include(x => x.DockerImages)
|
.Include(x => x.DockerImages)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
|
await lazyLoader.SetText("Loading docker images");
|
||||||
|
|
||||||
DockerImages = Images
|
DockerImages = Images
|
||||||
.First(x => x.Id == Server.Image.Id).DockerImages
|
.First(x => x.Id == Server.Image.Id).DockerImages
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
|
||||||
|
|
||||||
return Task.CompletedTask;
|
await lazyLoader.SetText("Loading users");
|
||||||
|
|
||||||
|
Users = UserRepository.Get().ToArray();
|
||||||
|
|
||||||
|
Model = Mapper.Map<ServerEditDataModel>(Server);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task Save()
|
private async Task OnValidSubmit()
|
||||||
{
|
{
|
||||||
ServerRepository.Update(Server!);
|
// Overwrite data using mapper
|
||||||
//await ServerService.Sync(Server!); I dont know if we need this, because wings should resync the data while restarting anyway
|
Server = Mapper.Map(Server, Model);
|
||||||
|
|
||||||
|
ServerRepository.Update(Server!);
|
||||||
await LazyLoader.Reload();
|
await LazyLoader.Reload();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user