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; }
|
||||
}
|
||||
}
|
||||
@@ -30,8 +30,8 @@
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Config</h5>
|
||||
<p class="card-text">Modify server configuration files: NS config, game configs, community board.</p>
|
||||
<a href="config/nameserver" class="btn btn-primary">Manage Config</a>
|
||||
<p class="card-text">Modify server configuration files</p>
|
||||
<a href="config/communityboard" class="btn btn-primary">Manage Config</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
@page "/settings"
|
||||
@attribute [Authorize]
|
||||
@rendermode InteractiveServer
|
||||
@inject AdminConfigService AdminConfig
|
||||
@inject NavigationManager Navigation
|
||||
|
||||
<PageTitle>Admin Settings</PageTitle>
|
||||
|
||||
<h3>Admin Settings</h3>
|
||||
|
||||
@if (saved)
|
||||
{
|
||||
<div class="alert alert-success alert-dismissible fade show" role="alert">
|
||||
Settings saved. New sessions will use the updated URLs.
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (error)
|
||||
{
|
||||
<div class="alert alert-danger alert-dismissible fade show" role="alert">
|
||||
@errorMessage
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="card mb-4">
|
||||
<div class="card-body">
|
||||
<p class="text-muted">
|
||||
These settings control where the admin panel connects to the CannedNet server API.
|
||||
If you accidentally change this to the wrong server, please manually change the URL in <code>admin_config.json</code>.
|
||||
</p>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="serverUrl" class="form-label">Server Base URL</label>
|
||||
<input type="url" class="form-control" id="serverUrl" @bind="edit.ServerBaseUrl" />
|
||||
</div>
|
||||
|
||||
<button class="btn btn-primary" @onclick="Save" disabled="@saving">
|
||||
@(saving ? "Saving..." : "Save Settings")
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private AdminConfigService.AdminConfigData edit = new();
|
||||
private bool saving;
|
||||
private bool saved;
|
||||
private bool error;
|
||||
private string errorMessage = "";
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
edit = new AdminConfigService.AdminConfigData
|
||||
{
|
||||
ServerBaseUrl = AdminConfig.ServerBaseUrl
|
||||
};
|
||||
}
|
||||
|
||||
private async Task Save()
|
||||
{
|
||||
saving = true;
|
||||
saved = false;
|
||||
error = false;
|
||||
errorMessage = "";
|
||||
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(edit.ServerBaseUrl))
|
||||
{
|
||||
error = true;
|
||||
errorMessage = "Server Base URL cannot be empty.";
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Uri.TryCreate(edit.ServerBaseUrl, UriKind.Absolute, out _))
|
||||
{
|
||||
error = true;
|
||||
errorMessage = "Server Base URL is not a valid absolute URL.";
|
||||
return;
|
||||
}
|
||||
|
||||
AdminConfig.Save(edit);
|
||||
saved = true;
|
||||
}
|
||||
finally
|
||||
{
|
||||
saving = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
@page "/setup"
|
||||
@rendermode InteractiveServer
|
||||
@inject AdminConfigService AdminConfig
|
||||
@inject NavigationManager Navigation
|
||||
|
||||
<PageTitle>First-Time Setup</PageTitle>
|
||||
|
||||
@if (!AdminConfig.IsConfigured)
|
||||
{
|
||||
<div class="row justify-content-center mt-5">
|
||||
<div class="col-md-6">
|
||||
<div class="card">
|
||||
<div class="card-header"><h4 class="mb-0">First-Time Setup</h4></div>
|
||||
<div class="card-body">
|
||||
<p class="text-muted">
|
||||
Welcome to the CannedNet Admin Panel. Before you can log in, please configure the
|
||||
connection to your CannedNet server.
|
||||
</p>
|
||||
|
||||
@if (saved)
|
||||
{
|
||||
<div class="alert alert-success">Settings saved! Redirecting to login...</div>
|
||||
}
|
||||
|
||||
@if (error)
|
||||
{
|
||||
<div class="alert alert-danger">@errorMessage</div>
|
||||
}
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="serverUrl" class="form-label">Server Base URL</label>
|
||||
<input type="url" class="form-control" id="serverUrl" @bind="edit.ServerBaseUrl" placeholder="http://localhost:5000" />
|
||||
</div>
|
||||
|
||||
<button class="btn btn-primary" @onclick="Save" disabled="@saving">
|
||||
@(saving ? "Saving..." : "Save & Continue")
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="row justify-content-center mt-5">
|
||||
<div class="col-md-4">
|
||||
<div class="card">
|
||||
<div class="card-body text-center">
|
||||
<p>Already configured. <a href="/login">Go to login</a>.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@code {
|
||||
private AdminConfigService.AdminConfigData edit = new();
|
||||
private bool saving;
|
||||
private bool saved;
|
||||
private bool error;
|
||||
private string errorMessage = "";
|
||||
|
||||
private async Task Save()
|
||||
{
|
||||
saving = true;
|
||||
saved = false;
|
||||
error = false;
|
||||
errorMessage = "";
|
||||
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(edit.ServerBaseUrl))
|
||||
{
|
||||
error = true;
|
||||
errorMessage = "Server Base URL is required.";
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Uri.TryCreate(edit.ServerBaseUrl, UriKind.Absolute, out _))
|
||||
{
|
||||
error = true;
|
||||
errorMessage = "Server Base URL is not a valid absolute URL.";
|
||||
return;
|
||||
}
|
||||
|
||||
AdminConfig.Save(edit);
|
||||
saved = true;
|
||||
await Task.Delay(1000);
|
||||
Navigation.NavigateTo("/login", forceLoad: true);
|
||||
}
|
||||
finally
|
||||
{
|
||||
saving = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user