Admin Panel v6
This commit is contained in:
@@ -0,0 +1,310 @@
|
||||
@page "/admin/items/edit"
|
||||
@model Items.EditModel
|
||||
@using Server.Data.Enums
|
||||
@{
|
||||
ViewData["Title"] = Model.IsNew ? "Create Item" : $"Edit: {Model.Item.Name}";
|
||||
}
|
||||
|
||||
<div class="space-y-6 max-w-5xl">
|
||||
<!-- Header -->
|
||||
<div class="flex items-center gap-4">
|
||||
<a href="/admin/items" class="p-2 hover:bg-gray-800 rounded-lg">
|
||||
<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" : $"ID: {Model.Item.Id}")</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (!string.IsNullOrEmpty(Model.Message))
|
||||
{
|
||||
<div class="p-4 rounded-lg @(Model.IsError ? "bg-red-900/50 border border-red-700 text-red-200" : "bg-green-900/50 border border-green-700 text-green-200")">
|
||||
@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 lg:grid-cols-3 gap-6">
|
||||
<div class="lg:col-span-2">
|
||||
<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 t in Enum.GetValues<ItemType>())
|
||||
{
|
||||
<option value="@t" selected="@(Model.Item.Type == t)">@t</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="lg:col-span-3">
|
||||
<label class="label">Description</label>
|
||||
<textarea name="Item.Description" class="input" rows="2" maxlength="256">@Model.Item.Description</textarea>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="label">Rarity</label>
|
||||
<select name="Item.Rarity" class="input">
|
||||
@foreach (var r in Enum.GetValues<ItemRarity>())
|
||||
{
|
||||
<option value="@r" selected="@(Model.Item.Rarity == r)">@r</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="label">Equipment Slot</label>
|
||||
<select name="Item.EquipSlot" class="input">
|
||||
<option value="">Not Equippable</option>
|
||||
@foreach (var s in Enum.GetValues<DungeonEquipmentSlot>())
|
||||
{
|
||||
<option value="@s" selected="@(Model.Item.EquipSlot == s)">@s</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center gap-6 pt-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" />
|
||||
<span class="text-gray-300">Enabled</span>
|
||||
</label>
|
||||
<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" id="stackableCheck" onchange="toggleMaxStack()" />
|
||||
<span class="text-gray-300">Stackable</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Stacking & Visual -->
|
||||
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
|
||||
<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 space-y-4">
|
||||
<div>
|
||||
<label class="label">Max Stack</label>
|
||||
<input type="number" id="maxStackInput" name="Item.MaxStack" value="@Model.Item.MaxStack" class="input" min="1" max="9999" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<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 space-y-4">
|
||||
<div>
|
||||
<label class="label">Sprite Path (CDN)</label>
|
||||
<input type="text" name="Item.SpritePath" value="@Model.Item.SpritePath" class="input" placeholder="textures/items/sword.png" id="spritePath" oninput="updatePreview()" />
|
||||
</div>
|
||||
<div class="flex items-center gap-4">
|
||||
<div>
|
||||
<label class="label">Preview</label>
|
||||
<div class="w-16 h-16 bg-gray-900 rounded-lg border border-gray-700 flex items-center justify-center overflow-hidden">
|
||||
<img id="spritePreview" src="" class="max-w-full max-h-full object-contain hidden" onerror="this.classList.add('hidden')" onload="this.classList.remove('hidden')" />
|
||||
<svg id="spritePlaceholder" class="w-8 h-8 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>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex-1">
|
||||
<label class="label">Tint Color</label>
|
||||
<div class="flex gap-2">
|
||||
<input type="color" id="tintPicker" value="@(Model.Item.TintColor ?? "#ffffff")" class="w-10 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" oninput="document.getElementById('tintPicker').value=this.value||'#ffffff'" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Requirements -->
|
||||
<div class="card">
|
||||
<div class="p-4 border-b border-gray-700">
|
||||
<h2 class="text-lg font-semibold text-white">Requirements</h2>
|
||||
</div>
|
||||
<div class="p-6 grid grid-cols-2 md:grid-cols-5 gap-4">
|
||||
<div>
|
||||
<label class="label">Level</label>
|
||||
<input type="number" name="Item.RequiredLevel" value="@Model.Item.RequiredLevel" class="input" min="1" />
|
||||
</div>
|
||||
<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>
|
||||
</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 lg:grid-cols-7 gap-4">
|
||||
<div>
|
||||
<label class="label">+ STR</label>
|
||||
<input type="number" name="Item.BonusStrength" value="@Model.Item.BonusStrength" class="input" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">+ INT</label>
|
||||
<input type="number" name="Item.BonusIntelligence" value="@Model.Item.BonusIntelligence" class="input" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">+ WIS</label>
|
||||
<input type="number" name="Item.BonusWisdom" value="@Model.Item.BonusWisdom" class="input" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">+ END</label>
|
||||
<input type="number" name="Item.BonusEndurance" value="@Model.Item.BonusEndurance" class="input" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">+ DEX</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">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 d in Enum.GetValues<DamageType>())
|
||||
{
|
||||
<option value="@d" selected="@(Model.Item.DamageType == d)">@d</option>
|
||||
}
|
||||
</select>
|
||||
</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>
|
||||
</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-4 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 class="flex items-center pt-6">
|
||||
<label class="flex items-center gap-2 cursor-pointer">
|
||||
<input type="checkbox" name="Item.IsTeleportScroll" value="true" checked="@Model.Item.IsTeleportScroll" class="w-4 h-4 rounded border-gray-600 bg-gray-800 text-indigo-600" />
|
||||
<span class="text-gray-300">Teleport Scroll</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Actions -->
|
||||
<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 cdnBase = '@Model.CdnBaseUrl';
|
||||
|
||||
function updatePreview() {
|
||||
const path = document.getElementById('spritePath').value;
|
||||
const img = document.getElementById('spritePreview');
|
||||
const placeholder = document.getElementById('spritePlaceholder');
|
||||
if (path) {
|
||||
img.src = cdnBase + '/' + path;
|
||||
placeholder.classList.add('hidden');
|
||||
} else {
|
||||
img.classList.add('hidden');
|
||||
placeholder.classList.remove('hidden');
|
||||
}
|
||||
}
|
||||
|
||||
function toggleMaxStack() {
|
||||
const cb = document.getElementById('stackableCheck');
|
||||
const input = document.getElementById('maxStackInput');
|
||||
input.disabled = !cb.checked;
|
||||
if (!cb.checked) input.value = 1;
|
||||
}
|
||||
|
||||
// Init
|
||||
updatePreview();
|
||||
toggleMaxStack();
|
||||
</script>
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Server.Data;
|
||||
using Server.Data.Entities;
|
||||
|
||||
namespace VoidScavengers.Services.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)
|
||||
{
|
||||
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
|
||||
{
|
||||
// Defaults for new item
|
||||
Item.IsEnabled = true;
|
||||
Item.RequiredLevel = 1;
|
||||
Item.MaxStack = 1;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostAsync(string? action)
|
||||
{
|
||||
var cdnUrl = Environment.GetEnvironmentVariable("CDN_BASE_URL");
|
||||
if (!string.IsNullOrEmpty(cdnUrl)) CdnBaseUrl = cdnUrl;
|
||||
|
||||
// Handle checkbox binding (unchecked = not sent)
|
||||
Item.IsEnabled = Request.Form.ContainsKey("Item.IsEnabled");
|
||||
Item.Stackable = Request.Form.ContainsKey("Item.Stackable");
|
||||
Item.IsTeleportScroll = Request.Form.ContainsKey("Item.IsTeleportScroll");
|
||||
|
||||
if (string.IsNullOrWhiteSpace(Item.Name))
|
||||
{
|
||||
Message = "Name is required.";
|
||||
IsError = true;
|
||||
return Page();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (action == "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,
|
||||
IsTeleportScroll = Item.IsTeleportScroll,
|
||||
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 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();
|
||||
}
|
||||
|
||||
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.IsTeleportScroll = Item.IsTeleportScroll;
|
||||
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: {ex.Message}";
|
||||
IsError = true;
|
||||
}
|
||||
|
||||
return Page();
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,16 @@
|
||||
@page "/admin/items"
|
||||
@model Items.IndexModel
|
||||
@using Server.Data.Enums
|
||||
@{
|
||||
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 (@Model.ItemCount total)</p>
|
||||
<p class="text-gray-400 mt-1">Manage item definitions</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">
|
||||
@@ -18,7 +20,182 @@
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="card p-8 text-center">
|
||||
<p class="text-gray-400">Full item editor coming in next update...</p>
|
||||
<!-- 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-40">
|
||||
<label class="label">Type</label>
|
||||
<select name="type" class="input">
|
||||
<option value="">All Types</option>
|
||||
@foreach (var t in Enum.GetValues<ItemType>())
|
||||
{
|
||||
<option value="@t" selected="@(Model.TypeFilter == t)">@t</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
<div class="w-40">
|
||||
<label class="label">Rarity</label>
|
||||
<select name="rarity" class="input">
|
||||
<option value="">All Rarities</option>
|
||||
@foreach (var r in Enum.GetValues<ItemRarity>())
|
||||
{
|
||||
<option value="@r" selected="@(Model.RarityFilter == r)">@r</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/50">
|
||||
<tr>
|
||||
<th class="table-header w-16">ID</th>
|
||||
<th class="table-header w-16">Icon</th>
|
||||
<th class="table-header">Name</th>
|
||||
<th class="table-header w-28">Type</th>
|
||||
<th class="table-header w-28">Rarity</th>
|
||||
<th class="table-header w-24">Stack</th>
|
||||
<th class="table-header w-20">Enabled</th>
|
||||
<th class="table-header w-24">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y divide-gray-700">
|
||||
@foreach (var item in Model.Items)
|
||||
{
|
||||
<tr class="hover:bg-gray-700/30">
|
||||
<td class="table-cell font-mono text-gray-500">@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 border border-gray-700"
|
||||
onerror="this.style.display='none'" />
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="w-10 h-10 bg-gray-900 rounded border border-gray-700 flex items-center justify-center text-gray-600">
|
||||
<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="M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4"/>
|
||||
</svg>
|
||||
</div>
|
||||
}
|
||||
</td>
|
||||
<td class="table-cell">
|
||||
<span class="font-medium text-white">@item.Name</span>
|
||||
@if (!string.IsNullOrEmpty(item.Description))
|
||||
{
|
||||
<p class="text-xs text-gray-500 truncate max-w-xs">@item.Description</p>
|
||||
}
|
||||
</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">@item.MaxStack</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="text-gray-500">-</span>
|
||||
}
|
||||
</td>
|
||||
<td class="table-cell">
|
||||
@if (item.IsEnabled)
|
||||
{
|
||||
<span class="w-3 h-3 bg-green-500 rounded-full inline-block" title="Enabled"></span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="w-3 h-3 bg-red-500 rounded-full inline-block" title="Disabled"></span>
|
||||
}
|
||||
</td>
|
||||
<td class="table-cell">
|
||||
<div class="flex items-center gap-1">
|
||||
<a href="/admin/items/edit?id=@item.Id" class="p-1.5 hover:bg-gray-700 rounded" title="Edit">
|
||||
<svg class="w-4 h-4 text-indigo-400" 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="p-1.5 hover:bg-gray-700 rounded" title="Delete">
|
||||
<svg class="w-4 h-4 text-red-400" 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-12">
|
||||
No items found. <a href="/admin/items/edit" class="text-indigo-400 hover:underline">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.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="/admin/items?page=@(Model.CurrentPage - 1)&search=@Model.Search&type=@Model.TypeFilter&rarity=@Model.RarityFilter" 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="/admin/items?page=@(Model.CurrentPage + 1)&search=@Model.Search&type=@Model.TypeFilter&rarity=@Model.RarityFilter" class="btn btn-secondary">Next →</a>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<!-- Delete 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" class="text-white"></span>"?</p>
|
||||
<form 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>
|
||||
</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');
|
||||
}
|
||||
document.addEventListener('keydown', e => { if (e.key === 'Escape') closeDeleteModal(); });
|
||||
</script>
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Server.Data;
|
||||
using Server.Data.Entities;
|
||||
using Server.Data.Enums;
|
||||
|
||||
namespace VoidScavengers.Services.Admin.Pages.Items;
|
||||
|
||||
@@ -12,10 +15,54 @@ public class IndexModel : AdminPageModel
|
||||
_db = db;
|
||||
}
|
||||
|
||||
public int ItemCount { get; set; }
|
||||
public List<DungeonItemDefinition> Items { get; set; } = new();
|
||||
public string? Search { get; set; }
|
||||
public ItemType? TypeFilter { get; set; }
|
||||
public ItemRarity? RarityFilter { get; set; }
|
||||
public int CurrentPage { 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 async Task OnGetAsync()
|
||||
public async Task OnGetAsync(string? search, ItemType? type, ItemRarity? rarity, int page = 1)
|
||||
{
|
||||
ItemCount = await _db.DungeonItemDefinitions.CountAsync();
|
||||
Search = search;
|
||||
TypeFilter = type;
|
||||
RarityFilter = rarity;
|
||||
CurrentPage = Math.Max(1, page);
|
||||
|
||||
var cdnUrl = Environment.GetEnvironmentVariable("CDN_BASE_URL");
|
||||
if (!string.IsNullOrEmpty(cdnUrl)) CdnBaseUrl = cdnUrl;
|
||||
|
||||
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((CurrentPage - 1) * PageSize)
|
||||
.Take(PageSize)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user