diff --git a/Moonlight/Shared/Views/Admin/Settings.razor b/Moonlight/Shared/Views/Admin/Settings.razor new file mode 100644 index 00000000..3090b850 --- /dev/null +++ b/Moonlight/Shared/Views/Admin/Settings.razor @@ -0,0 +1,95 @@ +@page "/admin/settings" +@using Moonlight.App.Services + +@inject ConfigService ConfigService + +@if (ModelToShow == null) +{ +

Nope

+} +else +{ +
+
+ @{ + string title; + + if (Path.Length == 0) + title = "Configuration"; + else + title = string.Join( + " > ", + Path.Select(x => + x.EndsWith("Data") ? Formatter.ReplaceEnd(x, "Data", "") : x)); + } + +

@(title)

+
+
+
+
+ @{ + var props = ModelToShow + .GetType() + .GetProperties() + .Where(x => x.PropertyType.Assembly.FullName!.Contains("Moonlight") && x.PropertyType.IsClass) + .ToArray(); + } + + @foreach (var prop in props) + { +
+ +
+ } +
+
+ +
+
+
+
+} + +@code +{ + [Parameter] + [SupplyParameterFromQuery] + public string? Section { get; set; } = ""; + + private object? ModelToShow = new(); + private string[] Path = Array.Empty(); + + protected override async Task OnParametersSetAsync() + { + if (Section != null && Section.StartsWith("/")) + Section = Section.TrimStart('/'); + + Path = Section != null ? Section.Split("/") : Array.Empty(); + + ModelToShow = Resolve(ConfigService.Get(), Path, 0); + + await InvokeAsync(StateHasChanged); + } + + private object? Resolve(object model, string[] path, int index) + { + if (path.Length == 0) + return model; + + if (path.Length == index) + return model; + + var prop = model + .GetType() + .GetProperties() + .FirstOrDefault(x => x.PropertyType.Assembly.FullName!.Contains("Moonlight") && x.PropertyType.IsClass && x.Name == path[index]); + + if (prop == null) + return null; + + return Resolve(prop.GetValue(model)!, path, index + 1); + } +} \ No newline at end of file