TLC Admin Portal

This commit is contained in:
dingo
2026-01-10 11:20:06 -05:00
parent ecac99ee89
commit c43a334d8b
5 changed files with 284 additions and 45 deletions
+39 -3
View File
@@ -8,7 +8,7 @@
<div class="flex items-center justify-between">
<div>
<h1 class="text-3xl font-bold text-white">Sprite Sheets</h1>
<p class="text-gray-400 mt-1">Manage sprite sheets and animations for mobs</p>
<p class="text-gray-400 mt-1">Manage sprite sheets and animations for mobs (@Model.TotalCount total)</p>
</div>
<a href="/admin/spritesheets/edit" class="btn btn-primary">+ New Sprite Sheet</a>
</div>
@@ -26,6 +26,23 @@
</div>
}
<!-- Search/Filter -->
<div class="card p-4">
<form method="get" class="flex flex-wrap gap-3">
<div class="flex-1 min-w-[200px]">
<input type="text" name="search" value="@Model.Search"
class="input w-full text-sm" placeholder="Search by name or path..." />
</div>
<select name="enabled" class="input text-sm">
<option value="">All Status</option>
<option value="true" selected="@(Model.EnabledFilter == true)">Enabled Only</option>
<option value="false" selected="@(Model.EnabledFilter == false)">Disabled Only</option>
</select>
<button type="submit" class="btn btn-secondary text-sm">Search</button>
<a href="/admin/spritesheets" class="btn btn-ghost text-sm">Clear</a>
</form>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
@foreach (var sheet in Model.SpriteSheets)
{
@@ -33,7 +50,7 @@
<div class="flex items-start justify-between mb-3">
<div>
<h3 class="text-lg font-semibold text-white">@sheet.Name</h3>
<p class="text-sm text-gray-400 font-mono">@sheet.CdnPath</p>
<p class="text-sm text-gray-400 font-mono truncate max-w-[200px]" title="@sheet.CdnPath">@sheet.CdnPath</p>
</div>
@if (sheet.IsEnabled)
{
@@ -45,6 +62,17 @@
}
</div>
<!-- Preview -->
@if (!string.IsNullOrEmpty(sheet.CdnPath))
{
<div class="mb-3 bg-gray-900 rounded p-2 flex justify-center overflow-hidden" style="max-height: 80px;">
<img src="@Model.GetCdnUrl(sheet.CdnPath)"
alt="@sheet.Name"
style="max-height: 76px; image-rendering: pixelated;"
onerror="this.style.display='none'" />
</div>
}
<div class="grid grid-cols-2 gap-2 text-sm mb-3">
<div class="text-gray-400">Sheet Size:</div>
<div class="text-white">@sheet.SheetWidth x @sheet.SheetHeight</div>
@@ -71,7 +99,15 @@
@if (Model.SpriteSheets.Count == 0)
{
<div class="card p-8 text-center text-gray-400">
No sprite sheets found. <a href="/admin/spritesheets/edit" class="text-indigo-400 hover:underline">Create one</a>
@if (!string.IsNullOrEmpty(Model.Search))
{
<span>No sprite sheets found matching "@Model.Search". </span>
}
else
{
<span>No sprite sheets found. </span>
}
<a href="/admin/spritesheets/edit" class="text-indigo-400 hover:underline">Create one</a>
</div>
}
</div>
@@ -8,18 +8,43 @@ namespace Server.Services.Admin.Pages.SpriteSheets;
public class IndexModel : AdminPageModel
{
private readonly GameDbContext _db;
private readonly IConfiguration _config;
public IndexModel(GameDbContext db)
public IndexModel(GameDbContext db, IConfiguration config)
{
_db = db;
_config = config;
}
public List<MobSpriteSheet> SpriteSheets { get; set; } = new();
public string? Search { get; set; }
public bool? EnabledFilter { get; set; }
public int TotalCount { get; set; }
public async Task OnGetAsync()
public async Task OnGetAsync(string? search, bool? enabled)
{
SpriteSheets = await _db.MobSpriteSheets
Search = search;
EnabledFilter = enabled;
var query = _db.MobSpriteSheets
.Include(s => s.Animations)
.AsQueryable();
if (!string.IsNullOrEmpty(search))
{
query = query.Where(s =>
s.Name.Contains(search) ||
(s.CdnPath != null && s.CdnPath.Contains(search)));
}
if (enabled.HasValue)
{
query = query.Where(s => s.IsEnabled == enabled.Value);
}
TotalCount = await query.CountAsync();
SpriteSheets = await query
.OrderBy(s => s.Name)
.ToListAsync();
}
@@ -51,4 +76,17 @@ public class IndexModel : AdminPageModel
}
return RedirectToPage();
}
public string GetCdnUrl(string? path)
{
if (string.IsNullOrEmpty(path)) return "";
var baseUrl = _config["Cdn:BaseUrl"]?.TrimEnd('/') ?? "https://assets.aeternalisgames.com";
if (!baseUrl.EndsWith("/downloads", StringComparison.OrdinalIgnoreCase))
{
baseUrl += "/downloads";
}
return $"{baseUrl}/{path.TrimStart('/')}";
}
}