Files
systemrevivalserver/Services/Admin/Pages/Assets/Index.cshtml
T
2025-12-25 15:36:03 -05:00

209 lines
11 KiB
Plaintext

@page "/admin/assets"
@model Assets.IndexModel
@using Server.Data.Entities
@{
ViewData["Title"] = "CDN Assets";
}
<div class="space-y-6">
<!-- Header -->
<div class="flex items-center justify-between">
<div>
<h1 class="text-3xl font-bold text-white">CDN Assets</h1>
<p class="text-gray-400 mt-1">Browse and manage client assets</p>
</div>
<a href="/admin/assets/edit" class="btn btn-primary flex items-center gap-2">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"/>
</svg>
Add Asset
</a>
</div>
<!-- Filters -->
<div class="card p-4">
<form method="get" class="flex flex-wrap items-end gap-4">
<div class="flex-1 min-w-[200px]">
<label class="label">Search</label>
<input type="text" name="search" value="@Model.Search" class="input" placeholder="Search by path..." />
</div>
<div class="w-40">
<label class="label">Type</label>
<select name="type" class="input">
<option value="">All Types</option>
@foreach (var t in Enum.GetValues<ClientAssetType>())
{
<option value="@t" selected="@(Model.TypeFilter == t)">@t</option>
}
</select>
</div>
<button type="submit" class="btn btn-secondary">Filter</button>
<a href="/admin/assets" class="btn btn-secondary">Clear</a>
</form>
</div>
<!-- Stats -->
<div class="grid grid-cols-2 md:grid-cols-4 gap-4">
<div class="card p-4">
<p class="text-2xl font-bold text-white">@Model.TotalCount</p>
<p class="text-sm text-gray-400">Total Assets</p>
</div>
<div class="card p-4">
<p class="text-2xl font-bold text-indigo-400">@Model.TextureCount</p>
<p class="text-sm text-gray-400">Textures</p>
</div>
<div class="card p-4">
<p class="text-2xl font-bold text-green-400">@Model.SceneCount</p>
<p class="text-sm text-gray-400">Scenes</p>
</div>
<div class="card p-4">
<p class="text-2xl font-bold text-yellow-400">@Model.ScriptCount</p>
<p class="text-sm text-gray-400">Scripts</p>
</div>
</div>
<!-- Assets Grid -->
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4">
@foreach (var asset in Model.Assets)
{
<div class="card overflow-hidden group">
<!-- Preview -->
<div class="h-32 bg-gray-900 flex items-center justify-center relative">
@if (asset.AssetType == ClientAssetType.Texture)
{
<img src="@Html.Raw(Model.CdnBaseUrl)/downloads/@asset.DownloadPath"
alt="@asset.FilePath"
class="max-h-full max-w-full object-contain"
onerror="this.parentElement.innerHTML='<div class=\'text-gray-600 text-center\'><svg class=\'w-12 h-12 mx-auto\' fill=\'none\' stroke=\'currentColor\' viewBox=\'0 0 24 24\'><path stroke-linecap=\'round\' stroke-linejoin=\'round\' stroke-width=\'2\' d=\'M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z\'/></svg><p class=\'text-xs mt-1\'>Failed to load</p></div>'" />
}
else
{
<div class="text-gray-600 text-center">
@switch (asset.AssetType)
{
case ClientAssetType.Scene:
<svg class="w-12 h-12 mx-auto text-green-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"/>
</svg>
break;
case ClientAssetType.Script:
<svg class="w-12 h-12 mx-auto text-yellow-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 20l4-16m4 4l4 4-4 4M6 16l-4-4 4-4"/>
</svg>
break;
case ClientAssetType.Audio:
<svg class="w-12 h-12 mx-auto text-purple-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 19V6l12-3v13M9 19c0 1.105-1.343 2-3 2s-3-.895-3-2 1.343-2 3-2 3 .895 3 2zm12-3c0 1.105-1.343 2-3 2s-3-.895-3-2 1.343-2 3-2 3 .895 3 2zM9 10l12-3"/>
</svg>
break;
default:
<svg class="w-12 h-12 mx-auto" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/>
</svg>
break;
}
<p class="text-xs mt-1">@asset.AssetType</p>
</div>
}
<!-- Type badge -->
<div class="absolute top-2 right-2">
<span class="badge @(asset.AssetType == ClientAssetType.Texture ? "badge-rare" : asset.AssetType == ClientAssetType.Scene ? "badge-uncommon" : "badge-common")">
@asset.AssetType
</span>
</div>
</div>
<!-- Info -->
<div class="p-3">
<p class="text-sm text-white font-medium truncate" title="@asset.FilePath">
@System.IO.Path.GetFileName(asset.FilePath)
</p>
<p class="text-xs text-gray-500 truncate" title="@asset.FilePath">
@asset.FilePath
</p>
<div class="flex items-center justify-between mt-2 text-xs text-gray-400">
<span>v@asset.Version</span>
<span>@FormatFileSize(asset.FileSize)</span>
</div>
<div class="flex items-center gap-1 mt-2">
@if (asset.IsRequired)
{
<span class="text-xs text-yellow-400">Required</span>
}
@if (!asset.IsEnabled)
{
<span class="text-xs text-red-400">Disabled</span>
}
</div>
</div>
<!-- Actions (hidden until hover) -->
<div class="border-t border-gray-700 p-2 flex justify-end gap-2 opacity-0 group-hover:opacity-100 transition-opacity">
<a href="@Html.Raw(Model.CdnBaseUrl)/downloads/@asset.DownloadPath" target="_blank" class="p-1.5 hover:bg-gray-700 rounded text-gray-400" title="Download">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"/>
</svg>
</a>
<button type="button" onclick="copyToClipboard('@asset.FilePath')" class="p-1.5 hover:bg-gray-700 rounded text-gray-400" title="Copy Path">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"/>
</svg>
</button>
</div>
</div>
}
@if (!Model.Assets.Any())
{
<div class="col-span-full card p-12 text-center">
<svg class="w-16 h-16 mx-auto text-gray-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"/>
</svg>
<p class="text-gray-400 mt-4">No assets found.</p>
</div>
}
</div>
<!-- Pagination -->
@if (Model.TotalPages > 1)
{
<div class="flex items-center justify-between">
<p class="text-sm text-gray-400">
Showing @((Model.CurrentPage - 1) * Model.PageSize + 1)-@Math.Min(Model.CurrentPage * Model.PageSize, Model.TotalCount) of @Model.TotalCount
</p>
<div class="flex items-center gap-2">
@if (Model.CurrentPage > 1)
{
<a href="@Model.GetPageUrl(Model.CurrentPage - 1)" class="btn btn-secondary">← Prev</a>
}
<span class="text-gray-400 px-2">@Model.CurrentPage / @Model.TotalPages</span>
@if (Model.CurrentPage < Model.TotalPages)
{
<a href="@Model.GetPageUrl(Model.CurrentPage + 1)" class="btn btn-secondary">Next →</a>
}
</div>
</div>
}
</div>
@functions {
string FormatFileSize(long bytes)
{
if (bytes < 1024) return $"{bytes} B";
if (bytes < 1024 * 1024) return $"{bytes / 1024.0:F1} KB";
return $"{bytes / (1024.0 * 1024.0):F1} MB";
}
}
@section Scripts {
<script>
function copyToClipboard(text) {
navigator.clipboard.writeText(text).then(() => {
// Show a quick toast or just change cursor briefly
console.log('Copied:', text);
});
}
</script>
}