Merge pull request #395 from Moonlight-Panel/v2_AddNodeLogView
Added node log view
This commit is contained in:
commit
f2aad2ccdf
3 changed files with 88 additions and 0 deletions
|
@ -9,6 +9,9 @@
|
|||
<li class="nav-item">
|
||||
<a class="nav-link text-white @(Index == 2 ? "active" : "")" href="/admin/servers/nodes/view/@(NodeId)/setup">Setup</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-white @(Index == 3 ? "active" : "")" href="/admin/servers/nodes/view/@(NodeId)/logs">Logs</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
|
79
Moonlight/Features/Servers/UI/NodeComponents/NodeLogs.razor
Normal file
79
Moonlight/Features/Servers/UI/NodeComponents/NodeLogs.razor
Normal file
|
@ -0,0 +1,79 @@
|
|||
@using MoonCore.Helpers
|
||||
@using Moonlight.Features.Servers.Entities
|
||||
@using MoonCore.Services
|
||||
@using MoonCoreUI.Services
|
||||
@using Moonlight.Core.Configuration
|
||||
@using Moonlight.Features.Servers.Services
|
||||
|
||||
@inject ConfigService<CoreConfiguration> ConfigService
|
||||
@inject NodeService NodeService
|
||||
@inject ToastService ToastService
|
||||
|
||||
<div class="card card-body mb-5 p-3">
|
||||
<div class="d-flex justify-content-between align-items-center">
|
||||
<div class="fs-3 fw-semibold ms-3">Latest logs of <span class="text-primary">@Node.Name</span></div>
|
||||
<div class="text-end">
|
||||
<div class="input-group">
|
||||
<input @bind="LinesToFetch" type="number" class="form-control" placeholder="Lines to fetch"/>
|
||||
<WButton OnClick="Refresh" CssClasses="btn btn-primary">
|
||||
<i class="bx bx-sm bx-refresh"></i> Refresh
|
||||
</WButton>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<LazyLoader Load="Load">
|
||||
<div class="card card-body p-5 bg-black">
|
||||
@foreach (var line in Lines)
|
||||
{
|
||||
@line
|
||||
<br/>
|
||||
}
|
||||
</div>
|
||||
</LazyLoader>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public ServerNode Node { get; set; }
|
||||
|
||||
private string[] Lines;
|
||||
private int LinesToFetch = 25;
|
||||
|
||||
private async Task Load(LazyLoader lazyLoader)
|
||||
{
|
||||
await lazyLoader.SetText("Fetching current logs");
|
||||
await Refresh();
|
||||
}
|
||||
|
||||
private async Task Refresh()
|
||||
{
|
||||
// Prevent too small and too big values
|
||||
if (LinesToFetch < 0)
|
||||
LinesToFetch = 50;
|
||||
|
||||
if (LinesToFetch > 500)
|
||||
LinesToFetch = 50;
|
||||
|
||||
try
|
||||
{
|
||||
// Fetch and parse log
|
||||
var logs = await NodeService.GetLogs(Node);
|
||||
var logLines = logs.Split("\n");
|
||||
|
||||
// Save required logs
|
||||
Lines = logLines.TakeLast(LinesToFetch).ToArray();
|
||||
|
||||
await ToastService.Success("Refreshed logs successfully");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Warn($"An error occured while fetching logs from node '{Node.Name}'");
|
||||
Logger.Warn(e);
|
||||
|
||||
await ToastService.Danger("An error occured while fetching logs. Please try again later");
|
||||
}
|
||||
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
}
|
|
@ -29,6 +29,9 @@
|
|||
<Route Path="/setup">
|
||||
<NodeSetup Node="Node"/>
|
||||
</Route>
|
||||
<Route Path="/logs">
|
||||
<NodeLogs Node="Node"/>
|
||||
</Route>
|
||||
</SmartRouter>
|
||||
}
|
||||
</LazyLoader>
|
||||
|
@ -65,6 +68,9 @@
|
|||
|
||||
case "/setup":
|
||||
return 2;
|
||||
|
||||
case "/logs":
|
||||
return 3;
|
||||
|
||||
default:
|
||||
return 0;
|
||||
|
|
Loading…
Reference in a new issue