blob: 9a320877b300188368bc1e20d90ce0f99b732d5e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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..]
};
}
}
|