Merge pull request #32 from Moonlight-Panel/ServerDelete
Added server delete. Tweaked setting names
This commit is contained in:
@@ -1,11 +1,9 @@
|
|||||||
using Logging.Net;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Moonlight.App.Database;
|
using Moonlight.App.Database;
|
||||||
using Moonlight.App.Database.Entities;
|
using Moonlight.App.Database.Entities;
|
||||||
using Moonlight.App.Exceptions;
|
using Moonlight.App.Exceptions;
|
||||||
using Moonlight.App.Helpers;
|
using Moonlight.App.Helpers;
|
||||||
using Moonlight.App.Models.Files;
|
using Moonlight.App.Helpers.Files;
|
||||||
using Moonlight.App.Models.Files.Accesses;
|
|
||||||
using Moonlight.App.Models.Misc;
|
using Moonlight.App.Models.Misc;
|
||||||
using Moonlight.App.Models.Wings;
|
using Moonlight.App.Models.Wings;
|
||||||
using Moonlight.App.Models.Wings.Requests;
|
using Moonlight.App.Models.Wings.Requests;
|
||||||
@@ -13,6 +11,7 @@ using Moonlight.App.Models.Wings.Resources;
|
|||||||
using Moonlight.App.Repositories;
|
using Moonlight.App.Repositories;
|
||||||
using Moonlight.App.Repositories.Servers;
|
using Moonlight.App.Repositories.Servers;
|
||||||
using Moonlight.App.Services.LogServices;
|
using Moonlight.App.Services.LogServices;
|
||||||
|
using FileAccess = Moonlight.App.Helpers.Files.FileAccess;
|
||||||
|
|
||||||
namespace Moonlight.App.Services;
|
namespace Moonlight.App.Services;
|
||||||
|
|
||||||
@@ -30,7 +29,6 @@ public class ServerService
|
|||||||
private readonly SecurityLogService SecurityLogService;
|
private readonly SecurityLogService SecurityLogService;
|
||||||
private readonly AuditLogService AuditLogService;
|
private readonly AuditLogService AuditLogService;
|
||||||
private readonly ErrorLogService ErrorLogService;
|
private readonly ErrorLogService ErrorLogService;
|
||||||
private readonly string AppUrl;
|
|
||||||
|
|
||||||
public ServerService(
|
public ServerService(
|
||||||
ServerRepository serverRepository,
|
ServerRepository serverRepository,
|
||||||
@@ -58,8 +56,6 @@ public class ServerService
|
|||||||
SecurityLogService = securityLogService;
|
SecurityLogService = securityLogService;
|
||||||
AuditLogService = auditLogService;
|
AuditLogService = auditLogService;
|
||||||
ErrorLogService = errorLogService;
|
ErrorLogService = errorLogService;
|
||||||
|
|
||||||
AppUrl = ConfigService.GetSection("Moonlight").GetValue<string>("AppUrl");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Server EnsureNodeData(Server s)
|
private Server EnsureNodeData(Server s)
|
||||||
@@ -225,17 +221,17 @@ public class ServerService
|
|||||||
return $"https://{server.Node.Fqdn}:{server.Node.HttpPort}/download/backup?token={token}";
|
return $"https://{server.Node.Fqdn}:{server.Node.HttpPort}/download/backup?token={token}";
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<IFileAccess> CreateFileAccess(Server s, User user) // We need the user to create the launch url
|
public Task<FileAccess> CreateFileAccess(Server s, User user) // We need the user to create the launch url
|
||||||
{
|
{
|
||||||
Server server = EnsureNodeData(s);
|
Server server = EnsureNodeData(s);
|
||||||
|
|
||||||
return Task.FromResult(
|
return Task.FromResult(
|
||||||
(IFileAccess)new WingsFileAccess(
|
(FileAccess)new WingsFileAccess(
|
||||||
WingsApiHelper,
|
WingsApiHelper,
|
||||||
server,
|
|
||||||
user,
|
|
||||||
WingsJwtHelper,
|
WingsJwtHelper,
|
||||||
AppUrl
|
server,
|
||||||
|
ConfigService,
|
||||||
|
user
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -383,4 +379,20 @@ public class ServerService
|
|||||||
throw new Exception("User and owner id do not match");
|
throw new Exception("User and owner id do not match");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task Sync(Server s)
|
||||||
|
{
|
||||||
|
var server = EnsureNodeData(s);
|
||||||
|
|
||||||
|
await WingsApiHelper.Post(server.Node, $"api/servers/{server.Uuid}/sync", null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task Delete(Server s)
|
||||||
|
{
|
||||||
|
var server = EnsureNodeData(s);
|
||||||
|
|
||||||
|
await WingsApiHelper.Delete(server.Node, $"api/servers/{server.Uuid}", null);
|
||||||
|
|
||||||
|
ServerRepository.Delete(s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
@using PteroConsole.NET
|
@using Moonlight.App.Database.Entities
|
||||||
@using Moonlight.App.Database.Entities
|
|
||||||
@using Moonlight.Shared.Components.ServerControl.Settings
|
@using Moonlight.Shared.Components.ServerControl.Settings
|
||||||
@using Microsoft.AspNetCore.Components.Rendering
|
@using Microsoft.AspNetCore.Components.Rendering
|
||||||
|
|
||||||
@@ -53,9 +52,11 @@
|
|||||||
if(Tags.Contains("pythonfile"))
|
if(Tags.Contains("pythonfile"))
|
||||||
Settings.Add("Python file", typeof(PythonFileSetting));
|
Settings.Add("Python file", typeof(PythonFileSetting));
|
||||||
|
|
||||||
Settings.Add("Server rename", typeof(ServerRenameSetting));
|
Settings.Add("Rename", typeof(ServerRenameSetting));
|
||||||
|
|
||||||
Settings.Add("Server reset", typeof(ServerResetSetting));
|
Settings.Add("Reset", typeof(ServerResetSetting));
|
||||||
|
|
||||||
|
Settings.Add("Delete", typeof(ServerDeleteSetting));
|
||||||
|
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
@using Moonlight.App.Database.Entities
|
||||||
|
@using Moonlight.App.Services
|
||||||
|
@using Moonlight.App.Services.Interop
|
||||||
|
|
||||||
|
@inject SmartTranslateService SmartTranslateService
|
||||||
|
@inject AlertService AlertService
|
||||||
|
@inject NavigationManager NavigationManager
|
||||||
|
@inject ServerService ServerService
|
||||||
|
|
||||||
|
<WButton Text="@(SmartTranslateService.Translate("Delete"))"
|
||||||
|
WorkingText="@(SmartTranslateService.Translate("Deleting"))"
|
||||||
|
CssClasses="btn-danger"
|
||||||
|
OnClick="OnClick">
|
||||||
|
</WButton>
|
||||||
|
|
||||||
|
@code
|
||||||
|
{
|
||||||
|
[CascadingParameter]
|
||||||
|
public Server CurrentServer { get; set; }
|
||||||
|
|
||||||
|
private async Task OnClick()
|
||||||
|
{
|
||||||
|
if (await AlertService.ConfirmMath())
|
||||||
|
{
|
||||||
|
await ServerService.Delete(CurrentServer);
|
||||||
|
NavigationManager.NavigateTo("/servers", true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
@inject SmartTranslateService SmartTranslateService
|
@inject SmartTranslateService SmartTranslateService
|
||||||
@inject ServerRepository ServerRepository
|
@inject ServerRepository ServerRepository
|
||||||
|
@inject ServerService ServerService
|
||||||
@inject ImageRepository ImageRepository
|
@inject ImageRepository ImageRepository
|
||||||
|
|
||||||
<OnlyAdmin>
|
<OnlyAdmin>
|
||||||
@@ -197,7 +198,8 @@
|
|||||||
|
|
||||||
private async Task Save()
|
private async Task Save()
|
||||||
{
|
{
|
||||||
ServerRepository.Update(Server);
|
ServerRepository.Update(Server!);
|
||||||
|
//await ServerService.Sync(Server!); I dont know if we need this, because wings should resync the data while restarting anyway
|
||||||
|
|
||||||
await LazyLoader.Reload();
|
await LazyLoader.Reload();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user