Admin System.
This commit is contained in:
+1
-1
@@ -25,7 +25,7 @@ builder.Services.AddControllers();
|
||||
builder.Services.AddRazorPages()
|
||||
.AddRazorPagesOptions(options =>
|
||||
{
|
||||
options.RootDirectory = "/Admin/Pages";
|
||||
options.RootDirectory = "/Services/Admin/Pages";
|
||||
});
|
||||
|
||||
// ---- Session for Admin Auth ----
|
||||
|
||||
@@ -2,7 +2,7 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
|
||||
namespace VoidScavengers.Admin.Pages;
|
||||
namespace VoidScavengers.Services.Admin.Pages;
|
||||
|
||||
/// <summary>
|
||||
/// Base class for all admin pages that require authentication
|
||||
|
||||
@@ -1,210 +1,16 @@
|
||||
@page "/admin/assets"
|
||||
@model VoidScavengers.Admin.Pages.Assets.IndexModel
|
||||
@model Assets.IndexModel
|
||||
@{
|
||||
ViewData["Title"] = "CDN Assets";
|
||||
}
|
||||
|
||||
<div class="space-y-6">
|
||||
<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 assets from your CDN</p>
|
||||
</div>
|
||||
<a href="/admin/assets/sync" class="btn btn-secondary 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="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"/>
|
||||
</svg>
|
||||
Sync from CDN
|
||||
</a>
|
||||
<div>
|
||||
<h1 class="text-3xl font-bold text-white">CDN Assets</h1>
|
||||
<p class="text-gray-400 mt-1">Browse assets (@Model.AssetCount total)</p>
|
||||
</div>
|
||||
|
||||
<!-- CDN Info -->
|
||||
<div class="card p-4">
|
||||
<div class="flex items-center gap-4">
|
||||
<div class="p-3 bg-indigo-600/20 rounded-lg">
|
||||
<svg class="w-6 h-6 text-indigo-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 15a4 4 0 004 4h9a5 5 0 10-.1-9.999 5.002 5.002 0 10-9.78 2.096A4.001 4.001 0 003 15z"/>
|
||||
</svg>
|
||||
</div>
|
||||
<div>
|
||||
<p class="text-sm text-gray-400">CDN Base URL</p>
|
||||
<p class="text-white font-mono">@Model.CdnBaseUrl</p>
|
||||
</div>
|
||||
<div class="ml-auto text-right">
|
||||
<p class="text-sm text-gray-400">Registered Assets</p>
|
||||
<p class="text-2xl font-bold text-white">@Model.AssetCount</p>
|
||||
</div>
|
||||
</div>
|
||||
</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-48">
|
||||
<label class="label">Type</label>
|
||||
<select name="type" class="input">
|
||||
<option value="">All Types</option>
|
||||
<option value="sprite" selected="@(Model.TypeFilter == "sprite")">Sprites</option>
|
||||
<option value="scene" selected="@(Model.TypeFilter == "scene")">Scenes</option>
|
||||
<option value="script" selected="@(Model.TypeFilter == "script")">Scripts</option>
|
||||
<option value="audio" selected="@(Model.TypeFilter == "audio")">Audio</option>
|
||||
</select>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-secondary">Filter</button>
|
||||
<a href="/admin/assets" class="btn btn-secondary">Clear</a>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- Assets Grid -->
|
||||
<div class="grid grid-cols-2 md:grid-cols-4 lg:grid-cols-6 gap-4">
|
||||
@foreach (var asset in Model.Assets)
|
||||
{
|
||||
<div class="card p-3 hover:border-indigo-500 transition-colors cursor-pointer group"
|
||||
onclick="showAssetDetails('@asset.FilePath.Replace("'", "\\'")}')" >
|
||||
<div class="aspect-square bg-gray-900 rounded-lg flex items-center justify-center mb-2 overflow-hidden">
|
||||
@if (asset.AssetType == Server.Data.Entities.ClientAssetType.Texture)
|
||||
{
|
||||
<img src="@Model.CdnBaseUrl/@asset.DownloadPath"
|
||||
alt="@asset.FilePath"
|
||||
class="max-w-full max-h-full object-contain"
|
||||
onerror="this.style.display='none'; this.nextElementSibling.style.display='flex'" />
|
||||
<div class="hidden items-center justify-center text-gray-600">
|
||||
<svg class="w-8 h-8" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"/>
|
||||
</svg>
|
||||
</div>
|
||||
}
|
||||
else if (asset.AssetType == Server.Data.Entities.ClientAssetType.Scene)
|
||||
{
|
||||
<svg class="w-12 h-12 text-purple-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 5a1 1 0 011-1h14a1 1 0 011 1v2a1 1 0 01-1 1H5a1 1 0 01-1-1V5zM4 13a1 1 0 011-1h6a1 1 0 011 1v6a1 1 0 01-1 1H5a1 1 0 01-1-1v-6zM16 13a1 1 0 011-1h2a1 1 0 011 1v6a1 1 0 01-1 1h-2a1 1 0 01-1-1v-6z"/>
|
||||
</svg>
|
||||
}
|
||||
else if (asset.AssetType == Server.Data.Entities.ClientAssetType.Script)
|
||||
{
|
||||
<svg class="w-12 h-12 text-blue-500" 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>
|
||||
}
|
||||
else
|
||||
{
|
||||
<svg class="w-12 h-12 text-gray-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 21h10a2 2 0 002-2V9.414a1 1 0 00-.293-.707l-5.414-5.414A1 1 0 0012.586 3H7a2 2 0 00-2 2v14a2 2 0 002 2z"/>
|
||||
</svg>
|
||||
}
|
||||
</div>
|
||||
<p class="text-xs text-gray-400 truncate" title="@asset.FilePath">@System.IO.Path.GetFileName(asset.FilePath)</p>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (!Model.Assets.Any())
|
||||
{
|
||||
<div class="col-span-full card p-8 text-center">
|
||||
<p class="text-gray-500">No assets found.</p>
|
||||
<p class="text-gray-600 text-sm mt-2">Assets are registered in the client_assets table.</p>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<!-- Pagination -->
|
||||
@if (Model.TotalPages > 1)
|
||||
{
|
||||
<div class="flex items-center justify-between">
|
||||
<p class="text-sm text-gray-400">
|
||||
Showing @((Model.Page - 1) * Model.PageSize + 1) to @Math.Min(Model.Page * Model.PageSize, Model.TotalCount) of @Model.TotalCount assets
|
||||
</p>
|
||||
<div class="flex items-center gap-2">
|
||||
@if (Model.Page > 1)
|
||||
{
|
||||
<a href="/admin/assets?page=@(Model.Page - 1)&search=@Model.Search&type=@Model.TypeFilter" class="btn btn-secondary">Previous</a>
|
||||
}
|
||||
<span class="text-gray-400">Page @Model.Page of @Model.TotalPages</span>
|
||||
@if (Model.Page < Model.TotalPages)
|
||||
{
|
||||
<a href="/admin/assets?page=@(Model.Page + 1)&search=@Model.Search&type=@Model.TypeFilter" class="btn btn-secondary">Next</a>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<!-- Asset Details Modal -->
|
||||
<div id="assetModal" class="fixed inset-0 bg-black/50 hidden items-center justify-center z-50">
|
||||
<div class="bg-gray-800 rounded-xl p-6 max-w-2xl w-full mx-4 border border-gray-700 max-h-[80vh] overflow-auto">
|
||||
<div class="flex items-center justify-between mb-4">
|
||||
<h3 class="text-lg font-semibold text-white">Asset Details</h3>
|
||||
<button onclick="closeAssetModal()" class="text-gray-400 hover:text-white">
|
||||
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
<div id="assetModalContent">
|
||||
<!-- Filled by JS -->
|
||||
</div>
|
||||
<div class="card p-8 text-center">
|
||||
<p class="text-gray-400">Asset browser coming soon...</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@section Scripts {
|
||||
<script>
|
||||
const cdnBaseUrl = '@Model.CdnBaseUrl';
|
||||
|
||||
function showAssetDetails(path) {
|
||||
const modal = document.getElementById('assetModal');
|
||||
const content = document.getElementById('assetModalContent');
|
||||
|
||||
const isImage = /\.(png|jpg|jpeg|webp|gif)$/i.test(path);
|
||||
|
||||
content.innerHTML = `
|
||||
<div class="space-y-4">
|
||||
${isImage ? `
|
||||
<div class="bg-gray-900 rounded-lg p-4 flex items-center justify-center">
|
||||
<img src="${cdnBaseUrl}/${path}" alt="${path}" class="max-w-full max-h-64 object-contain" />
|
||||
</div>
|
||||
` : ''}
|
||||
<div>
|
||||
<p class="text-sm text-gray-400">Path</p>
|
||||
<p class="text-white font-mono text-sm break-all">${path}</p>
|
||||
</div>
|
||||
<div>
|
||||
<p class="text-sm text-gray-400">Full URL</p>
|
||||
<p class="text-indigo-400 font-mono text-sm break-all">
|
||||
<a href="${cdnBaseUrl}/${path}" target="_blank">${cdnBaseUrl}/${path}</a>
|
||||
</p>
|
||||
</div>
|
||||
<div class="flex gap-2">
|
||||
<button onclick="copyToClipboard('${path}')" class="btn btn-secondary flex-1">
|
||||
Copy Path
|
||||
</button>
|
||||
<button onclick="copyToClipboard('${cdnBaseUrl}/${path}')" class="btn btn-secondary flex-1">
|
||||
Copy URL
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
modal.classList.remove('hidden');
|
||||
modal.classList.add('flex');
|
||||
}
|
||||
|
||||
function closeAssetModal() {
|
||||
const modal = document.getElementById('assetModal');
|
||||
modal.classList.add('hidden');
|
||||
modal.classList.remove('flex');
|
||||
}
|
||||
|
||||
function copyToClipboard(text) {
|
||||
navigator.clipboard.writeText(text).then(() => {
|
||||
alert('Copied to clipboard!');
|
||||
});
|
||||
}
|
||||
|
||||
document.addEventListener('keydown', (e) => {
|
||||
if (e.key === 'Escape') closeAssetModal();
|
||||
});
|
||||
</script>
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Server.Data;
|
||||
using Server.Data.Entities;
|
||||
|
||||
namespace VoidScavengers.Admin.Pages.Assets;
|
||||
namespace VoidScavengers.Services.Admin.Pages.Assets;
|
||||
|
||||
public class IndexModel : AdminPageModel
|
||||
{
|
||||
@@ -13,63 +12,10 @@ public class IndexModel : AdminPageModel
|
||||
_db = db;
|
||||
}
|
||||
|
||||
public List<ClientAsset> Assets { get; set; } = new();
|
||||
public string? Search { get; set; }
|
||||
public string? TypeFilter { get; set; }
|
||||
public int Page { get; set; } = 1;
|
||||
public int PageSize { get; set; } = 24;
|
||||
public int TotalCount { get; set; }
|
||||
public int AssetCount { get; set; }
|
||||
public int TotalPages => (int)Math.Ceiling(TotalCount / (double)PageSize);
|
||||
public string CdnBaseUrl { get; set; } = "https://assets.aeternalisgames.com";
|
||||
|
||||
public async Task OnGetAsync(string? search, string? type, int page = 1)
|
||||
public async Task OnGetAsync()
|
||||
{
|
||||
Search = search;
|
||||
TypeFilter = type;
|
||||
Page = Math.Max(1, page);
|
||||
|
||||
// Get CDN URL from environment
|
||||
var cdnUrl = Environment.GetEnvironmentVariable("CDN_BASE_URL");
|
||||
if (!string.IsNullOrEmpty(cdnUrl))
|
||||
{
|
||||
CdnBaseUrl = cdnUrl;
|
||||
}
|
||||
|
||||
AssetCount = await _db.ClientAssets.CountAsync();
|
||||
|
||||
var query = _db.ClientAssets.AsQueryable();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(search))
|
||||
{
|
||||
query = query.Where(a => a.FilePath.Contains(search));
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(type))
|
||||
{
|
||||
switch (type.ToLower())
|
||||
{
|
||||
case "sprite":
|
||||
query = query.Where(a => a.AssetType == ClientAssetType.Texture);
|
||||
break;
|
||||
case "scene":
|
||||
query = query.Where(a => a.AssetType == ClientAssetType.Scene);
|
||||
break;
|
||||
case "script":
|
||||
query = query.Where(a => a.AssetType == ClientAssetType.Script);
|
||||
break;
|
||||
case "audio":
|
||||
query = query.Where(a => a.AssetType == ClientAssetType.Audio);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
TotalCount = await query.CountAsync();
|
||||
|
||||
Assets = await query
|
||||
.OrderBy(a => a.FilePath)
|
||||
.Skip((Page - 1) * PageSize)
|
||||
.Take(PageSize)
|
||||
.ToListAsync();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
@page "/admin"
|
||||
@model VoidScavengers.Admin.Pages.IndexModel
|
||||
@model IndexModel
|
||||
@{
|
||||
ViewData["Title"] = "Dashboard";
|
||||
}
|
||||
@@ -129,18 +129,4 @@
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- CDN Assets -->
|
||||
<div class="card">
|
||||
<div class="p-6 border-b border-gray-700">
|
||||
<h2 class="text-lg font-semibold text-white">CDN Assets</h2>
|
||||
<p class="text-sm text-gray-400 mt-1">@Model.AssetCount assets registered</p>
|
||||
</div>
|
||||
<div class="p-6">
|
||||
<p class="text-gray-400 mb-4">CDN Base URL: <code class="text-indigo-400">@Model.CdnBaseUrl</code></p>
|
||||
<a href="/admin/assets" class="btn btn-secondary">
|
||||
Browse Assets
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Server.Data;
|
||||
|
||||
namespace VoidScavengers.Admin.Pages;
|
||||
namespace VoidScavengers.Services.Admin.Pages;
|
||||
|
||||
public class IndexModel : AdminPageModel
|
||||
{
|
||||
@@ -17,8 +16,6 @@ public class IndexModel : AdminPageModel
|
||||
public int MobCount { get; set; }
|
||||
public int RecipeCount { get; set; }
|
||||
public int PlayerCount { get; set; }
|
||||
public int AssetCount { get; set; }
|
||||
public string CdnBaseUrl { get; set; } = "https://assets.aeternalisgames.com";
|
||||
|
||||
public async Task OnGetAsync()
|
||||
{
|
||||
@@ -26,13 +23,5 @@ public class IndexModel : AdminPageModel
|
||||
MobCount = await _db.DungeonMobDefinitions.CountAsync();
|
||||
RecipeCount = await _db.DungeonCraftingRecipes.CountAsync();
|
||||
PlayerCount = await _db.Accounts.CountAsync();
|
||||
AssetCount = await _db.ClientAssets.CountAsync();
|
||||
|
||||
// Get CDN URL from environment if set
|
||||
var cdnUrl = Environment.GetEnvironmentVariable("CDN_BASE_URL");
|
||||
if (!string.IsNullOrEmpty(cdnUrl))
|
||||
{
|
||||
CdnBaseUrl = cdnUrl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,338 +0,0 @@
|
||||
@page "/admin/items/edit"
|
||||
@model VoidScavengers.Admin.Pages.Items.EditModel
|
||||
@{
|
||||
ViewData["Title"] = Model.IsNew ? "Create Item" : $"Edit: {Model.Item.Name}";
|
||||
}
|
||||
|
||||
<div class="space-y-6 max-w-4xl">
|
||||
<!-- Header -->
|
||||
<div class="flex items-center gap-4">
|
||||
<a href="/admin/items" class="p-2 hover:bg-gray-800 rounded-lg transition-colors">
|
||||
<svg class="w-6 h-6 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 19l-7-7m0 0l7-7m-7 7h18"/>
|
||||
</svg>
|
||||
</a>
|
||||
<div>
|
||||
<h1 class="text-3xl font-bold text-white">@(Model.IsNew ? "Create Item" : "Edit Item")</h1>
|
||||
<p class="text-gray-400 mt-1">@(Model.IsNew ? "Add a new item definition" : $"Editing item #{Model.Item.Id}")</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (!string.IsNullOrEmpty(Model.Message))
|
||||
{
|
||||
<div class="p-4 @(Model.IsError ? "bg-red-900/50 border-red-700 text-red-200" : "bg-green-900/50 border-green-700 text-green-200") border rounded-lg">
|
||||
@Model.Message
|
||||
</div>
|
||||
}
|
||||
|
||||
<form method="post" class="space-y-6">
|
||||
@Html.AntiForgeryToken()
|
||||
<input type="hidden" name="Item.Id" value="@Model.Item.Id" />
|
||||
|
||||
<!-- Basic Info -->
|
||||
<div class="card">
|
||||
<div class="p-4 border-b border-gray-700">
|
||||
<h2 class="text-lg font-semibold text-white">Basic Information</h2>
|
||||
</div>
|
||||
<div class="p-6 grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||
<div>
|
||||
<label class="label">Name *</label>
|
||||
<input type="text" name="Item.Name" value="@Model.Item.Name" class="input" required maxlength="64" />
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="label">Type *</label>
|
||||
<select name="Item.Type" class="input" required>
|
||||
@foreach (var type in Enum.GetValues<Server.Data.Enums.ItemType>())
|
||||
{
|
||||
<option value="@type" selected="@(Model.Item.Type == type)">@type</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="md:col-span-2">
|
||||
<label class="label">Description</label>
|
||||
<textarea name="Item.Description" class="input" rows="3" maxlength="256">@Model.Item.Description</textarea>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="label">Rarity</label>
|
||||
<select name="Item.Rarity" class="input">
|
||||
@foreach (var rarity in Enum.GetValues<Server.Data.Enums.ItemRarity>())
|
||||
{
|
||||
<option value="@rarity" selected="@(Model.Item.Rarity == rarity)">@rarity</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="label">Equipment Slot</label>
|
||||
<select name="Item.EquipSlot" class="input">
|
||||
<option value="">Not Equippable</option>
|
||||
@foreach (var slot in Enum.GetValues<Server.Data.Enums.DungeonEquipmentSlot>())
|
||||
{
|
||||
<option value="@slot" selected="@(Model.Item.EquipSlot == slot)">@slot</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="label">Required Level</label>
|
||||
<input type="number" name="Item.RequiredLevel" value="@Model.Item.RequiredLevel" class="input" min="1" />
|
||||
</div>
|
||||
|
||||
<div class="flex items-center gap-6">
|
||||
<label class="flex items-center gap-2 cursor-pointer">
|
||||
<input type="checkbox" name="Item.IsEnabled" value="true" checked="@Model.Item.IsEnabled" class="w-4 h-4 rounded border-gray-600 bg-gray-800 text-indigo-600 focus:ring-indigo-500" />
|
||||
<span class="text-gray-300">Enabled</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Stacking -->
|
||||
<div class="card">
|
||||
<div class="p-4 border-b border-gray-700">
|
||||
<h2 class="text-lg font-semibold text-white">Stacking</h2>
|
||||
</div>
|
||||
<div class="p-6 grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||
<div class="flex items-center gap-6">
|
||||
<label class="flex items-center gap-2 cursor-pointer">
|
||||
<input type="checkbox" name="Item.Stackable" value="true" checked="@Model.Item.Stackable"
|
||||
class="w-4 h-4 rounded border-gray-600 bg-gray-800 text-indigo-600 focus:ring-indigo-500"
|
||||
onchange="document.getElementById('maxStackInput').disabled = !this.checked" />
|
||||
<span class="text-gray-300">Stackable</span>
|
||||
</label>
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">Max Stack</label>
|
||||
<input type="number" id="maxStackInput" name="Item.MaxStack" value="@Model.Item.MaxStack" class="input" min="1"
|
||||
disabled="@(!Model.Item.Stackable)" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Visual -->
|
||||
<div class="card">
|
||||
<div class="p-4 border-b border-gray-700">
|
||||
<h2 class="text-lg font-semibold text-white">Visual</h2>
|
||||
</div>
|
||||
<div class="p-6 grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||
<div>
|
||||
<label class="label">Sprite Path</label>
|
||||
<div class="flex gap-2">
|
||||
<input type="text" id="spritePath" name="Item.SpritePath" value="@Model.Item.SpritePath" class="input flex-1"
|
||||
placeholder="textures/items/sword.png"
|
||||
oninput="updateSpritePreview()" />
|
||||
<button type="button" onclick="openAssetBrowser()" class="btn btn-secondary">Browse</button>
|
||||
</div>
|
||||
<p class="text-xs text-gray-500 mt-1">Path relative to CDN root</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="label">Preview</label>
|
||||
<div class="w-24 h-24 bg-gray-900 rounded-lg flex items-center justify-center border border-gray-700">
|
||||
<img id="spritePreview"
|
||||
src="@(string.IsNullOrEmpty(Model.Item.SpritePath) ? "" : $"{Model.CdnBaseUrl}/{Model.Item.SpritePath}")"
|
||||
class="max-w-full max-h-full object-contain @(string.IsNullOrEmpty(Model.Item.SpritePath) ? "hidden" : "")"
|
||||
onerror="this.classList.add('hidden'); document.getElementById('spritePreviewPlaceholder').classList.remove('hidden')" />
|
||||
<div id="spritePreviewPlaceholder" class="text-gray-600 @(string.IsNullOrEmpty(Model.Item.SpritePath) ? "" : "hidden")">
|
||||
<svg class="w-12 h-12" 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>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="label">Tint Color</label>
|
||||
<div class="flex gap-2">
|
||||
<input type="color" id="tintColorPicker" value="@(string.IsNullOrEmpty(Model.Item.TintColor) ? "#ffffff" : Model.Item.TintColor)"
|
||||
class="w-12 h-10 rounded border border-gray-700 bg-gray-800 cursor-pointer"
|
||||
oninput="document.getElementById('tintColor').value = this.value" />
|
||||
<input type="text" id="tintColor" name="Item.TintColor" value="@Model.Item.TintColor" class="input flex-1"
|
||||
placeholder="#ffffff" pattern="#[0-9A-Fa-f]{6}"
|
||||
oninput="document.getElementById('tintColorPicker').value = this.value || '#ffffff'" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Stat Requirements -->
|
||||
<div class="card">
|
||||
<div class="p-4 border-b border-gray-700">
|
||||
<h2 class="text-lg font-semibold text-white">Stat Requirements</h2>
|
||||
</div>
|
||||
<div class="p-6 grid grid-cols-2 md:grid-cols-5 gap-4">
|
||||
<div>
|
||||
<label class="label">Strength</label>
|
||||
<input type="number" name="Item.RequiredStrength" value="@Model.Item.RequiredStrength" class="input" min="0" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">Intelligence</label>
|
||||
<input type="number" name="Item.RequiredIntelligence" value="@Model.Item.RequiredIntelligence" class="input" min="0" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">Wisdom</label>
|
||||
<input type="number" name="Item.RequiredWisdom" value="@Model.Item.RequiredWisdom" class="input" min="0" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">Dexterity</label>
|
||||
<input type="number" name="Item.RequiredDexterity" value="@Model.Item.RequiredDexterity" class="input" min="0" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">Level</label>
|
||||
<input type="number" name="Item.RequiredLevel" value="@Model.Item.RequiredLevel" class="input" min="1" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Stat Bonuses -->
|
||||
<div class="card">
|
||||
<div class="p-4 border-b border-gray-700">
|
||||
<h2 class="text-lg font-semibold text-white">Stat Bonuses (When Equipped)</h2>
|
||||
</div>
|
||||
<div class="p-6 grid grid-cols-2 md:grid-cols-4 gap-4">
|
||||
<div>
|
||||
<label class="label">+ Strength</label>
|
||||
<input type="number" name="Item.BonusStrength" value="@Model.Item.BonusStrength" class="input" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">+ Intelligence</label>
|
||||
<input type="number" name="Item.BonusIntelligence" value="@Model.Item.BonusIntelligence" class="input" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">+ Wisdom</label>
|
||||
<input type="number" name="Item.BonusWisdom" value="@Model.Item.BonusWisdom" class="input" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">+ Endurance</label>
|
||||
<input type="number" name="Item.BonusEndurance" value="@Model.Item.BonusEndurance" class="input" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">+ Dexterity</label>
|
||||
<input type="number" name="Item.BonusDexterity" value="@Model.Item.BonusDexterity" class="input" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">+ Health</label>
|
||||
<input type="number" name="Item.BonusHealth" value="@Model.Item.BonusHealth" class="input" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">+ Mana</label>
|
||||
<input type="number" name="Item.BonusMana" value="@Model.Item.BonusMana" class="input" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Combat Stats -->
|
||||
<div class="card">
|
||||
<div class="p-4 border-b border-gray-700">
|
||||
<h2 class="text-lg font-semibold text-white">Combat Stats</h2>
|
||||
</div>
|
||||
<div class="p-6 grid grid-cols-2 md:grid-cols-4 gap-4">
|
||||
<div>
|
||||
<label class="label">Min Damage</label>
|
||||
<input type="number" name="Item.MinDamage" value="@Model.Item.MinDamage" class="input" min="0" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">Max Damage</label>
|
||||
<input type="number" name="Item.MaxDamage" value="@Model.Item.MaxDamage" class="input" min="0" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">Armor</label>
|
||||
<input type="number" name="Item.Armor" value="@Model.Item.Armor" class="input" min="0" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">Magic Resist</label>
|
||||
<input type="number" name="Item.MagicResist" value="@Model.Item.MagicResist" class="input" min="0" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">Attack Range</label>
|
||||
<input type="number" name="Item.AttackRange" value="@Model.Item.AttackRange" class="input" min="0" step="0.1" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">Damage Type</label>
|
||||
<select name="Item.DamageType" class="input">
|
||||
@foreach (var dmgType in Enum.GetValues<Server.Data.Enums.DamageType>())
|
||||
{
|
||||
<option value="@dmgType" selected="@(Model.Item.DamageType == dmgType)">@dmgType</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Consumable Effects -->
|
||||
<div class="card">
|
||||
<div class="p-4 border-b border-gray-700">
|
||||
<h2 class="text-lg font-semibold text-white">Consumable Effects</h2>
|
||||
</div>
|
||||
<div class="p-6 grid grid-cols-2 md:grid-cols-3 gap-4">
|
||||
<div>
|
||||
<label class="label">Heal Amount</label>
|
||||
<input type="number" name="Item.HealAmount" value="@Model.Item.HealAmount" class="input" min="0" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">Mana Restore</label>
|
||||
<input type="number" name="Item.ManaRestore" value="@Model.Item.ManaRestore" class="input" min="0" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">Stamina Restore</label>
|
||||
<input type="number" name="Item.StaminaRestore" value="@Model.Item.StaminaRestore" class="input" min="0" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Submit -->
|
||||
<div class="flex items-center gap-4">
|
||||
<button type="submit" class="btn btn-primary">
|
||||
@(Model.IsNew ? "Create Item" : "Save Changes")
|
||||
</button>
|
||||
<a href="/admin/items" class="btn btn-secondary">Cancel</a>
|
||||
|
||||
@if (!Model.IsNew)
|
||||
{
|
||||
<div class="flex-1"></div>
|
||||
<button type="submit" name="action" value="duplicate" class="btn btn-secondary">
|
||||
Duplicate
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@section Scripts {
|
||||
<script>
|
||||
const cdnBaseUrl = '@Model.CdnBaseUrl';
|
||||
|
||||
function updateSpritePreview() {
|
||||
const path = document.getElementById('spritePath').value;
|
||||
const img = document.getElementById('spritePreview');
|
||||
const placeholder = document.getElementById('spritePreviewPlaceholder');
|
||||
|
||||
if (path) {
|
||||
img.src = cdnBaseUrl + '/' + path;
|
||||
img.classList.remove('hidden');
|
||||
placeholder.classList.add('hidden');
|
||||
img.onerror = function() {
|
||||
this.classList.add('hidden');
|
||||
placeholder.classList.remove('hidden');
|
||||
};
|
||||
} else {
|
||||
img.classList.add('hidden');
|
||||
placeholder.classList.remove('hidden');
|
||||
}
|
||||
}
|
||||
|
||||
function openAssetBrowser() {
|
||||
// Open asset browser in a new window/modal
|
||||
window.open('/admin/assets/browser?select=true&callback=setSpritePath', 'assetBrowser', 'width=800,height=600');
|
||||
}
|
||||
|
||||
// Called by asset browser when an asset is selected
|
||||
function setSpritePath(path) {
|
||||
document.getElementById('spritePath').value = path;
|
||||
updateSpritePreview();
|
||||
}
|
||||
</script>
|
||||
}
|
||||
@@ -1,180 +0,0 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Server.Data;
|
||||
using Server.Data.Entities;
|
||||
|
||||
namespace VoidScavengers.Admin.Pages.Items;
|
||||
|
||||
public class EditModel : AdminPageModel
|
||||
{
|
||||
private readonly GameDbContext _db;
|
||||
|
||||
public EditModel(GameDbContext db)
|
||||
{
|
||||
_db = db;
|
||||
}
|
||||
|
||||
[BindProperty]
|
||||
public DungeonItemDefinition Item { get; set; } = new();
|
||||
|
||||
public bool IsNew => Item.Id == 0;
|
||||
public string? Message { get; set; }
|
||||
public bool IsError { get; set; }
|
||||
public string CdnBaseUrl { get; set; } = "https://assets.aeternalisgames.com";
|
||||
|
||||
public async Task OnGetAsync(int? id)
|
||||
{
|
||||
// Get CDN URL from environment
|
||||
var cdnUrl = Environment.GetEnvironmentVariable("CDN_BASE_URL");
|
||||
if (!string.IsNullOrEmpty(cdnUrl))
|
||||
{
|
||||
CdnBaseUrl = cdnUrl;
|
||||
}
|
||||
|
||||
if (id.HasValue)
|
||||
{
|
||||
var item = await _db.DungeonItemDefinitions.FindAsync(id.Value);
|
||||
if (item != null)
|
||||
{
|
||||
Item = item;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Set defaults for new item
|
||||
Item.IsEnabled = true;
|
||||
Item.RequiredLevel = 1;
|
||||
Item.MaxStack = 1;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostAsync(string? action)
|
||||
{
|
||||
// Get CDN URL from environment
|
||||
var cdnUrl = Environment.GetEnvironmentVariable("CDN_BASE_URL");
|
||||
if (!string.IsNullOrEmpty(cdnUrl))
|
||||
{
|
||||
CdnBaseUrl = cdnUrl;
|
||||
}
|
||||
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
Message = "Please fix the errors below.";
|
||||
IsError = true;
|
||||
return Page();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (action == "duplicate")
|
||||
{
|
||||
// Create a duplicate
|
||||
var newItem = new DungeonItemDefinition
|
||||
{
|
||||
Name = Item.Name + " (Copy)",
|
||||
Description = Item.Description,
|
||||
Type = Item.Type,
|
||||
Rarity = Item.Rarity,
|
||||
EquipSlot = Item.EquipSlot,
|
||||
RequiredStrength = Item.RequiredStrength,
|
||||
RequiredIntelligence = Item.RequiredIntelligence,
|
||||
RequiredWisdom = Item.RequiredWisdom,
|
||||
RequiredDexterity = Item.RequiredDexterity,
|
||||
RequiredLevel = Item.RequiredLevel,
|
||||
BonusStrength = Item.BonusStrength,
|
||||
BonusIntelligence = Item.BonusIntelligence,
|
||||
BonusWisdom = Item.BonusWisdom,
|
||||
BonusEndurance = Item.BonusEndurance,
|
||||
BonusDexterity = Item.BonusDexterity,
|
||||
BonusHealth = Item.BonusHealth,
|
||||
BonusMana = Item.BonusMana,
|
||||
MinDamage = Item.MinDamage,
|
||||
MaxDamage = Item.MaxDamage,
|
||||
AttackRange = Item.AttackRange,
|
||||
DamageType = Item.DamageType,
|
||||
Armor = Item.Armor,
|
||||
MagicResist = Item.MagicResist,
|
||||
HealAmount = Item.HealAmount,
|
||||
ManaRestore = Item.ManaRestore,
|
||||
StaminaRestore = Item.StaminaRestore,
|
||||
Stackable = Item.Stackable,
|
||||
MaxStack = Item.MaxStack,
|
||||
SpritePath = Item.SpritePath,
|
||||
TintColor = Item.TintColor,
|
||||
IsEnabled = Item.IsEnabled
|
||||
};
|
||||
|
||||
_db.DungeonItemDefinitions.Add(newItem);
|
||||
await _db.SaveChangesAsync();
|
||||
|
||||
return RedirectToPage("/Items/Edit", new { id = newItem.Id });
|
||||
}
|
||||
|
||||
if (Item.Id == 0)
|
||||
{
|
||||
// Create new
|
||||
_db.DungeonItemDefinitions.Add(Item);
|
||||
await _db.SaveChangesAsync();
|
||||
|
||||
Message = $"Item '{Item.Name}' created successfully with ID {Item.Id}";
|
||||
return RedirectToPage("/Items/Edit", new { id = Item.Id });
|
||||
}
|
||||
else
|
||||
{
|
||||
// Update existing
|
||||
var existing = await _db.DungeonItemDefinitions.FindAsync(Item.Id);
|
||||
if (existing == null)
|
||||
{
|
||||
Message = "Item not found.";
|
||||
IsError = true;
|
||||
return Page();
|
||||
}
|
||||
|
||||
// Update all properties
|
||||
existing.Name = Item.Name;
|
||||
existing.Description = Item.Description;
|
||||
existing.Type = Item.Type;
|
||||
existing.Rarity = Item.Rarity;
|
||||
existing.EquipSlot = Item.EquipSlot;
|
||||
existing.RequiredStrength = Item.RequiredStrength;
|
||||
existing.RequiredIntelligence = Item.RequiredIntelligence;
|
||||
existing.RequiredWisdom = Item.RequiredWisdom;
|
||||
existing.RequiredDexterity = Item.RequiredDexterity;
|
||||
existing.RequiredLevel = Item.RequiredLevel;
|
||||
existing.BonusStrength = Item.BonusStrength;
|
||||
existing.BonusIntelligence = Item.BonusIntelligence;
|
||||
existing.BonusWisdom = Item.BonusWisdom;
|
||||
existing.BonusEndurance = Item.BonusEndurance;
|
||||
existing.BonusDexterity = Item.BonusDexterity;
|
||||
existing.BonusHealth = Item.BonusHealth;
|
||||
existing.BonusMana = Item.BonusMana;
|
||||
existing.MinDamage = Item.MinDamage;
|
||||
existing.MaxDamage = Item.MaxDamage;
|
||||
existing.AttackRange = Item.AttackRange;
|
||||
existing.DamageType = Item.DamageType;
|
||||
existing.Armor = Item.Armor;
|
||||
existing.MagicResist = Item.MagicResist;
|
||||
existing.HealAmount = Item.HealAmount;
|
||||
existing.ManaRestore = Item.ManaRestore;
|
||||
existing.StaminaRestore = Item.StaminaRestore;
|
||||
existing.Stackable = Item.Stackable;
|
||||
existing.MaxStack = Item.MaxStack;
|
||||
existing.SpritePath = Item.SpritePath;
|
||||
existing.TintColor = Item.TintColor;
|
||||
existing.IsEnabled = Item.IsEnabled;
|
||||
|
||||
await _db.SaveChangesAsync();
|
||||
|
||||
Item = existing;
|
||||
Message = "Changes saved successfully.";
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Message = $"Error saving item: {ex.Message}";
|
||||
IsError = true;
|
||||
}
|
||||
|
||||
return Page();
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,14 @@
|
||||
@page "/admin/items"
|
||||
@model VoidScavengers.Admin.Pages.Items.IndexModel
|
||||
@model Items.IndexModel
|
||||
@{
|
||||
ViewData["Title"] = "Items";
|
||||
}
|
||||
|
||||
<div class="space-y-6">
|
||||
<!-- Header -->
|
||||
<div class="flex items-center justify-between">
|
||||
<div>
|
||||
<h1 class="text-3xl font-bold text-white">Items</h1>
|
||||
<p class="text-gray-400 mt-1">Manage item definitions</p>
|
||||
<p class="text-gray-400 mt-1">Manage item definitions (@Model.ItemCount total)</p>
|
||||
</div>
|
||||
<a href="/admin/items/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">
|
||||
@@ -19,196 +18,7 @@
|
||||
</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 name..." />
|
||||
</div>
|
||||
<div class="w-48">
|
||||
<label class="label">Type</label>
|
||||
<select name="type" class="input">
|
||||
<option value="">All Types</option>
|
||||
@foreach (var type in Enum.GetValues<Server.Data.Enums.ItemType>())
|
||||
{
|
||||
<option value="@type" selected="@(Model.TypeFilter == type)">@type</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
<div class="w-48">
|
||||
<label class="label">Rarity</label>
|
||||
<select name="rarity" class="input">
|
||||
<option value="">All Rarities</option>
|
||||
@foreach (var rarity in Enum.GetValues<Server.Data.Enums.ItemRarity>())
|
||||
{
|
||||
<option value="@rarity" selected="@(Model.RarityFilter == rarity)">@rarity</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-secondary">Filter</button>
|
||||
<a href="/admin/items" class="btn btn-secondary">Clear</a>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- Items Table -->
|
||||
<div class="card overflow-hidden">
|
||||
<table class="w-full">
|
||||
<thead class="bg-gray-900">
|
||||
<tr>
|
||||
<th class="table-header">ID</th>
|
||||
<th class="table-header">Icon</th>
|
||||
<th class="table-header">Name</th>
|
||||
<th class="table-header">Type</th>
|
||||
<th class="table-header">Rarity</th>
|
||||
<th class="table-header">Stackable</th>
|
||||
<th class="table-header">Enabled</th>
|
||||
<th class="table-header">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y divide-gray-700">
|
||||
@foreach (var item in Model.Items)
|
||||
{
|
||||
<tr class="hover:bg-gray-700/50">
|
||||
<td class="table-cell font-mono text-gray-400">@item.Id</td>
|
||||
<td class="table-cell">
|
||||
@if (!string.IsNullOrEmpty(item.SpritePath))
|
||||
{
|
||||
<img src="@Model.CdnBaseUrl/@item.SpritePath"
|
||||
alt="@item.Name"
|
||||
class="w-10 h-10 object-contain bg-gray-900 rounded"
|
||||
onerror="this.style.display='none'" />
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="w-10 h-10 bg-gray-900 rounded flex items-center justify-center text-gray-600">
|
||||
<svg class="w-6 h-6" 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>
|
||||
</div>
|
||||
}
|
||||
</td>
|
||||
<td class="table-cell font-medium text-white">@item.Name</td>
|
||||
<td class="table-cell">@item.Type</td>
|
||||
<td class="table-cell">
|
||||
<span class="badge badge-@item.Rarity.ToString().ToLower()">@item.Rarity</span>
|
||||
</td>
|
||||
<td class="table-cell">
|
||||
@if (item.Stackable)
|
||||
{
|
||||
<span class="text-green-400">Yes (@item.MaxStack)</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="text-gray-500">No</span>
|
||||
}
|
||||
</td>
|
||||
<td class="table-cell">
|
||||
@if (item.IsEnabled)
|
||||
{
|
||||
<span class="inline-flex items-center gap-1 text-green-400">
|
||||
<svg class="w-4 h-4" fill="currentColor" viewBox="0 0 20 20">
|
||||
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" clip-rule="evenodd"/>
|
||||
</svg>
|
||||
Yes
|
||||
</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="inline-flex items-center gap-1 text-red-400">
|
||||
<svg class="w-4 h-4" fill="currentColor" viewBox="0 0 20 20">
|
||||
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z" clip-rule="evenodd"/>
|
||||
</svg>
|
||||
No
|
||||
</span>
|
||||
}
|
||||
</td>
|
||||
<td class="table-cell">
|
||||
<div class="flex items-center gap-2">
|
||||
<a href="/admin/items/edit?id=@item.Id" class="text-indigo-400 hover:text-indigo-300" title="Edit">
|
||||
<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="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"/>
|
||||
</svg>
|
||||
</a>
|
||||
<button type="button"
|
||||
onclick="confirmDelete(@item.Id, '@item.Name.Replace("'", "\\'")}')"
|
||||
class="text-red-400 hover:text-red-300"
|
||||
title="Delete">
|
||||
<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="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"/>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
|
||||
@if (!Model.Items.Any())
|
||||
{
|
||||
<tr>
|
||||
<td colspan="8" class="table-cell text-center text-gray-500 py-8">
|
||||
No items found.
|
||||
<a href="/admin/items/edit" class="text-indigo-400 hover:text-indigo-300">Create one?</a>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- Pagination -->
|
||||
@if (Model.TotalPages > 1)
|
||||
{
|
||||
<div class="flex items-center justify-between">
|
||||
<p class="text-sm text-gray-400">
|
||||
Showing @((Model.Page - 1) * Model.PageSize + 1) to @Math.Min(Model.Page * Model.PageSize, Model.TotalCount) of @Model.TotalCount items
|
||||
</p>
|
||||
<div class="flex items-center gap-2">
|
||||
@if (Model.Page > 1)
|
||||
{
|
||||
<a href="/admin/items?page=@(Model.Page - 1)&search=@Model.Search&type=@Model.TypeFilter&rarity=@Model.RarityFilter" class="btn btn-secondary">Previous</a>
|
||||
}
|
||||
<span class="text-gray-400">Page @Model.Page of @Model.TotalPages</span>
|
||||
@if (Model.Page < Model.TotalPages)
|
||||
{
|
||||
<a href="/admin/items?page=@(Model.Page + 1)&search=@Model.Search&type=@Model.TypeFilter&rarity=@Model.RarityFilter" class="btn btn-secondary">Next</a>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<!-- Delete confirmation modal -->
|
||||
<div id="deleteModal" class="fixed inset-0 bg-black/50 hidden items-center justify-center z-50">
|
||||
<div class="bg-gray-800 rounded-xl p-6 max-w-md w-full mx-4 border border-gray-700">
|
||||
<h3 class="text-lg font-semibold text-white mb-2">Delete Item</h3>
|
||||
<p class="text-gray-400 mb-4">Are you sure you want to delete "<span id="deleteItemName"></span>"? This action cannot be undone.</p>
|
||||
<form id="deleteForm" method="post" asp-page-handler="Delete" class="flex justify-end gap-3">
|
||||
@Html.AntiForgeryToken()
|
||||
<input type="hidden" name="id" id="deleteItemId" />
|
||||
<button type="button" onclick="closeDeleteModal()" class="btn btn-secondary">Cancel</button>
|
||||
<button type="submit" class="btn btn-danger">Delete</button>
|
||||
</form>
|
||||
<div class="card p-8 text-center">
|
||||
<p class="text-gray-400">Full item editor coming in next update...</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@section Scripts {
|
||||
<script>
|
||||
function confirmDelete(id, name) {
|
||||
document.getElementById('deleteItemId').value = id;
|
||||
document.getElementById('deleteItemName').textContent = name;
|
||||
document.getElementById('deleteModal').classList.remove('hidden');
|
||||
document.getElementById('deleteModal').classList.add('flex');
|
||||
}
|
||||
|
||||
function closeDeleteModal() {
|
||||
document.getElementById('deleteModal').classList.add('hidden');
|
||||
document.getElementById('deleteModal').classList.remove('flex');
|
||||
}
|
||||
|
||||
// Close modal on escape key
|
||||
document.addEventListener('keydown', (e) => {
|
||||
if (e.key === 'Escape') closeDeleteModal();
|
||||
});
|
||||
</script>
|
||||
}
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Server.Data;
|
||||
using Server.Data.Entities;
|
||||
using Server.Data.Enums;
|
||||
|
||||
namespace VoidScavengers.Admin.Pages.Items;
|
||||
namespace VoidScavengers.Services.Admin.Pages.Items;
|
||||
|
||||
public class IndexModel : AdminPageModel
|
||||
{
|
||||
@@ -15,64 +12,10 @@ public class IndexModel : AdminPageModel
|
||||
_db = db;
|
||||
}
|
||||
|
||||
public List<DungeonItemDefinition> Items { get; set; } = new();
|
||||
public string? Search { get; set; }
|
||||
public ItemType? TypeFilter { get; set; }
|
||||
public ItemRarity? RarityFilter { get; set; }
|
||||
public int Page { get; set; } = 1;
|
||||
public int PageSize { get; set; } = 20;
|
||||
public int TotalCount { get; set; }
|
||||
public int TotalPages => (int)Math.Ceiling(TotalCount / (double)PageSize);
|
||||
public string CdnBaseUrl { get; set; } = "https://assets.aeternalisgames.com";
|
||||
public int ItemCount { get; set; }
|
||||
|
||||
public async Task OnGetAsync(string? search, ItemType? type, ItemRarity? rarity, int page = 1)
|
||||
public async Task OnGetAsync()
|
||||
{
|
||||
Search = search;
|
||||
TypeFilter = type;
|
||||
RarityFilter = rarity;
|
||||
Page = Math.Max(1, page);
|
||||
|
||||
var query = _db.DungeonItemDefinitions.AsQueryable();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(search))
|
||||
{
|
||||
query = query.Where(i => i.Name.Contains(search) || i.Description.Contains(search));
|
||||
}
|
||||
|
||||
if (type.HasValue)
|
||||
{
|
||||
query = query.Where(i => i.Type == type.Value);
|
||||
}
|
||||
|
||||
if (rarity.HasValue)
|
||||
{
|
||||
query = query.Where(i => i.Rarity == rarity.Value);
|
||||
}
|
||||
|
||||
TotalCount = await query.CountAsync();
|
||||
|
||||
Items = await query
|
||||
.OrderBy(i => i.Id)
|
||||
.Skip((Page - 1) * PageSize)
|
||||
.Take(PageSize)
|
||||
.ToListAsync();
|
||||
|
||||
// Get CDN URL from environment if set
|
||||
var cdnUrl = Environment.GetEnvironmentVariable("CDN_BASE_URL");
|
||||
if (!string.IsNullOrEmpty(cdnUrl))
|
||||
{
|
||||
CdnBaseUrl = cdnUrl;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostDeleteAsync(int id)
|
||||
{
|
||||
var item = await _db.DungeonItemDefinitions.FindAsync(id);
|
||||
if (item != null)
|
||||
{
|
||||
_db.DungeonItemDefinitions.Remove(item);
|
||||
await _db.SaveChangesAsync();
|
||||
}
|
||||
return RedirectToPage();
|
||||
ItemCount = await _db.DungeonItemDefinitions.CountAsync();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
@page "/admin/login"
|
||||
@model VoidScavengers.Admin.Pages.LoginModel
|
||||
@model LoginModel
|
||||
@{
|
||||
Layout = null;
|
||||
ViewData["Title"] = "Login";
|
||||
|
||||
@@ -4,7 +4,7 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Server.Data;
|
||||
using Server.Services.Auth;
|
||||
|
||||
namespace VoidScavengers.Admin.Pages;
|
||||
namespace VoidScavengers.Services.Admin.Pages;
|
||||
|
||||
public class LoginModel : PageModel
|
||||
{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
@page "/admin/logout"
|
||||
@model VoidScavengers.Admin.Pages.LogoutModel
|
||||
@model LogoutModel
|
||||
@{
|
||||
// This page just redirects after clearing session
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
|
||||
namespace VoidScavengers.Admin.Pages;
|
||||
namespace VoidScavengers.Services.Admin.Pages;
|
||||
|
||||
public class LogoutModel : PageModel
|
||||
{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
@page "/admin/mobs"
|
||||
@model VoidScavengers.Admin.Pages.Mobs.IndexModel
|
||||
@model Mobs.IndexModel
|
||||
@{
|
||||
ViewData["Title"] = "Mobs";
|
||||
}
|
||||
@@ -8,7 +8,7 @@
|
||||
<div class="flex items-center justify-between">
|
||||
<div>
|
||||
<h1 class="text-3xl font-bold text-white">Mobs</h1>
|
||||
<p class="text-gray-400 mt-1">Manage mob definitions</p>
|
||||
<p class="text-gray-400 mt-1">Manage mob definitions (@Model.MobCount total)</p>
|
||||
</div>
|
||||
<a href="/admin/mobs/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">
|
||||
@@ -19,7 +19,6 @@
|
||||
</div>
|
||||
|
||||
<div class="card p-8 text-center">
|
||||
<p class="text-gray-400">@Model.MobCount mobs defined</p>
|
||||
<p class="text-gray-500 mt-2">Full mob editor coming soon...</p>
|
||||
<p class="text-gray-400">Mob editor coming soon...</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Server.Data;
|
||||
|
||||
namespace VoidScavengers.Admin.Pages.Mobs;
|
||||
namespace VoidScavengers.Services.Admin.Pages.Mobs;
|
||||
|
||||
public class IndexModel : AdminPageModel
|
||||
{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
@page "/admin/players"
|
||||
@model VoidScavengers.Admin.Pages.Players.IndexModel
|
||||
@model Players.IndexModel
|
||||
@{
|
||||
ViewData["Title"] = "Players";
|
||||
}
|
||||
@@ -7,11 +7,10 @@
|
||||
<div class="space-y-6">
|
||||
<div>
|
||||
<h1 class="text-3xl font-bold text-white">Players</h1>
|
||||
<p class="text-gray-400 mt-1">Manage player accounts</p>
|
||||
<p class="text-gray-400 mt-1">Manage player accounts (@Model.PlayerCount total)</p>
|
||||
</div>
|
||||
|
||||
<div class="card p-8 text-center">
|
||||
<p class="text-gray-400">@Model.PlayerCount registered accounts</p>
|
||||
<p class="text-gray-500 mt-2">Full player management coming soon...</p>
|
||||
<p class="text-gray-400">Player management coming soon...</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Server.Data;
|
||||
|
||||
namespace VoidScavengers.Admin.Pages.Players;
|
||||
namespace VoidScavengers.Services.Admin.Pages.Players;
|
||||
|
||||
public class IndexModel : AdminPageModel
|
||||
{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
@page "/admin/recipes"
|
||||
@model VoidScavengers.Admin.Pages.Recipes.IndexModel
|
||||
@model Recipes.IndexModel
|
||||
@{
|
||||
ViewData["Title"] = "Recipes";
|
||||
}
|
||||
@@ -8,7 +8,7 @@
|
||||
<div class="flex items-center justify-between">
|
||||
<div>
|
||||
<h1 class="text-3xl font-bold text-white">Recipes</h1>
|
||||
<p class="text-gray-400 mt-1">Manage crafting recipes</p>
|
||||
<p class="text-gray-400 mt-1">Manage crafting recipes (@Model.RecipeCount total)</p>
|
||||
</div>
|
||||
<a href="/admin/recipes/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">
|
||||
@@ -19,7 +19,6 @@
|
||||
</div>
|
||||
|
||||
<div class="card p-8 text-center">
|
||||
<p class="text-gray-400">@Model.RecipeCount recipes defined</p>
|
||||
<p class="text-gray-500 mt-2">Full recipe editor coming soon...</p>
|
||||
<p class="text-gray-400">Recipe editor coming soon...</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Server.Data;
|
||||
|
||||
namespace VoidScavengers.Admin.Pages.Recipes;
|
||||
namespace VoidScavengers.Services.Admin.Pages.Recipes;
|
||||
|
||||
public class IndexModel : AdminPageModel
|
||||
{
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
@namespace VoidScavengers.Admin.Pages
|
||||
@namespace VoidScavengers.Services.Admin.Pages
|
||||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
||||
|
||||
Reference in New Issue
Block a user