mirror of
https://github.com/CannedNet/CannedNet.git
synced 2026-10-26 23:48:58 -07:00
chore: clean up admin panel
This commit is contained in:
@@ -1,133 +0,0 @@
|
||||
@page "/config/gameconfig"
|
||||
@rendermode InteractiveServer
|
||||
|
||||
<PageTitle>Game Config</PageTitle>
|
||||
|
||||
<h3>Game Config</h3>
|
||||
<p class="text-muted">Edit the gameconfigs.json file that controls various game settings.</p>
|
||||
|
||||
@if (loading)
|
||||
{
|
||||
<div class="spinner-border" role="status"></div>
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(error))
|
||||
{
|
||||
<div class="alert alert-danger">@error</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<ul class="nav nav-tabs mb-3">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link @GetActiveClass("edit")" href="#" @onclick='() => SetTab("edit")' @onclick:preventDefault="true">Raw Editor</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link @GetActiveClass("browse")" href="#" @onclick='() => SetTab("browse")' @onclick:preventDefault="true">Browse</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
@if (activeTab == "edit")
|
||||
{
|
||||
<form>
|
||||
<div class="mb-3">
|
||||
<button type="submit" class="btn btn-success" @onclick="Save" disabled="@saving">
|
||||
@(saving ? "Saving..." : "Save Changes")
|
||||
</button>
|
||||
@if (!string.IsNullOrEmpty(saveMessage))
|
||||
{
|
||||
<span class="ms-2 @(saveMessage.Contains("Error") ? "text-danger" : "text-success")">@saveMessage</span>
|
||||
}
|
||||
</div>
|
||||
<textarea class="form-control font-monospace" rows="30" @bind="jsonContent"></textarea>
|
||||
</form>
|
||||
}
|
||||
else if (activeTab == "browse")
|
||||
{
|
||||
<div class="mb-3">
|
||||
<input type="text" class="form-control" placeholder="Filter keys..." @bind="filterText" @bind:event="oninput" />
|
||||
</div>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-sm table-striped">
|
||||
<thead>
|
||||
<tr><th>Key</th><th>Value</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var entry in configEntries.Where(e => string.IsNullOrEmpty(filterText) || e.Key.Contains(filterText, StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
<tr>
|
||||
<td class="font-monospace small">@entry.Key</td>
|
||||
<td class="small" style="max-width: 400px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;" title="@entry.Value">@entry.Value</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="text-muted small">@configEntries.Count(e => string.IsNullOrEmpty(filterText) || e.Key.Contains(filterText, StringComparison.OrdinalIgnoreCase)) entries</div>
|
||||
}
|
||||
}
|
||||
|
||||
@code {
|
||||
[Inject] private HttpClient Http { get; set; } = default!;
|
||||
|
||||
private bool loading = true;
|
||||
private bool saving;
|
||||
private string? error;
|
||||
private string? saveMessage;
|
||||
private string jsonContent = "";
|
||||
private string activeTab = "browse";
|
||||
private string filterText = "";
|
||||
private List<ConfigEntry> configEntries = new();
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
jsonContent = await Http.GetStringAsync("/admin/api/config/gameconfigs");
|
||||
configEntries = JsonSerializer.Deserialize<List<ConfigEntry>>(jsonContent) ?? new();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
error = $"Failed to load: {ex.Message}";
|
||||
}
|
||||
finally
|
||||
{
|
||||
loading = false;
|
||||
}
|
||||
}
|
||||
|
||||
private string GetActiveClass(string tab) => activeTab == tab ? "active" : "";
|
||||
|
||||
private void SetTab(string tab)
|
||||
{
|
||||
activeTab = tab;
|
||||
}
|
||||
|
||||
private async Task Save()
|
||||
{
|
||||
saving = true;
|
||||
saveMessage = null;
|
||||
try
|
||||
{
|
||||
var content = new StringContent(jsonContent, System.Text.Encoding.UTF8, "application/json");
|
||||
var response = await Http.PutAsync("/admin/api/config/gameconfigs", content);
|
||||
response.EnsureSuccessStatusCode();
|
||||
saveMessage = "Saved successfully!";
|
||||
configEntries = JsonSerializer.Deserialize<List<ConfigEntry>>(jsonContent) ?? new();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
saveMessage = $"Error: {ex.Message}";
|
||||
}
|
||||
finally
|
||||
{
|
||||
saving = false;
|
||||
}
|
||||
}
|
||||
|
||||
private class ConfigEntry
|
||||
{
|
||||
public string Key { get; set; } = "";
|
||||
public string Value { get; set; } = "";
|
||||
public string? EndTime { get; set; }
|
||||
public string? StartTime { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user