diff options
author | Rory& <root@rory.gay> | 2024-01-20 08:34:32 +0100 |
---|---|---|
committer | Rory& <root@rory.gay> | 2024-01-20 08:34:32 +0100 |
commit | 43e06f4b1b7ead9f8cc97fe547eb49d51f341486 (patch) | |
tree | b700ba441320e0f3944c398080cadd296f03ef07 /SystemdCtl.Client/Pages/ServiceManage.razor | |
download | SystemdCtl-43e06f4b1b7ead9f8cc97fe547eb49d51f341486.tar.xz |
Initial commit
Diffstat (limited to 'SystemdCtl.Client/Pages/ServiceManage.razor')
-rw-r--r-- | SystemdCtl.Client/Pages/ServiceManage.razor | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/SystemdCtl.Client/Pages/ServiceManage.razor b/SystemdCtl.Client/Pages/ServiceManage.razor new file mode 100644 index 0000000..9a32087 --- /dev/null +++ b/SystemdCtl.Client/Pages/ServiceManage.razor @@ -0,0 +1,66 @@ +@page "/Service/{ServiceName}/Manage" +@using LibSystemdCli.Models +@using LibSystemdCli +@using System.Text.RegularExpressions +@using SystemdCtl.Client.Abstractions +@* @attribute [StreamRendering] *@ +@rendermode InteractiveWebAssembly +@inject NavigationManager NavigationManager + + +<PageTitle>Manage @ServiceName</PageTitle> + +<h1>Manage @ServiceName</h1> + +@* //simple log view *@ +<div class="row"> + <div class="col-12"> + <h3>Logs</h3> + <div class="card"> + <div class="card-body"> + <pre> + @foreach (var line in LogLines) { + <span>@line</span><br/> + } + </pre> + </div> + </div> + </div> +</div> + +@code { + + [Parameter] + public string ServiceName { get; set; } = ""; + + private static bool IsClient => !Environment.CommandLine.Contains("/"); + + private List<string> LogLines { get; set; } = new(); + + protected override async Task OnInitializedAsync() { + Console.WriteLine("OnInitializedAsync"); + await Run(); + } + + private async Task Run() { + if (!IsClient) return; + + LogLines.Clear(); + var Http = new StreamingHttpClient() { BaseAddress = new Uri(NavigationManager.BaseUri) }; + var _items = Http.GetAsyncEnumerableFromJsonAsync<string>($"/api/unit/{ServiceName}/logs"); + await foreach (var item in _items) { + LogLines.Add(item); + if (LogLines.Count > 100) LogLines.RemoveAt(0); + StateHasChanged(); + } + } + + private string Capitalize(string input) { + return input switch { + null => throw new ArgumentNullException(nameof(input)), + "" => throw new ArgumentException($"{nameof(input)} cannot be empty", nameof(input)), + _ => input.First().ToString().ToUpper() + input[1..] + }; + } + +} \ No newline at end of file |