Admin v9
This commit is contained in:
@@ -1,16 +1,208 @@
|
||||
@page "/admin/assets"
|
||||
@model Assets.IndexModel
|
||||
@using Server.Data.Entities
|
||||
@{
|
||||
ViewData["Title"] = "CDN Assets";
|
||||
}
|
||||
|
||||
<div class="space-y-6">
|
||||
<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>
|
||||
<!-- 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>
|
||||
|
||||
<div class="card p-8 text-center">
|
||||
<p class="text-gray-400">Asset browser coming soon...</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 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>
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Server.Data;
|
||||
using Server.Data.Entities;
|
||||
|
||||
namespace VoidScavengers.Services.Admin.Pages.Assets;
|
||||
|
||||
@@ -12,10 +14,61 @@ public class IndexModel : AdminPageModel
|
||||
_db = db;
|
||||
}
|
||||
|
||||
public int AssetCount { get; set; }
|
||||
public List<ClientAsset> Assets { get; set; } = new();
|
||||
|
||||
[FromQuery(Name = "search")]
|
||||
public string? Search { get; set; }
|
||||
|
||||
[FromQuery(Name = "type")]
|
||||
public ClientAssetType? TypeFilter { get; set; }
|
||||
|
||||
[FromQuery(Name = "page")]
|
||||
public int CurrentPage { get; set; } = 1;
|
||||
|
||||
public int PageSize { get; set; } = 24;
|
||||
public int TotalCount { get; set; }
|
||||
public int TotalPages => (int)Math.Ceiling(TotalCount / (double)PageSize);
|
||||
|
||||
public int TextureCount { get; set; }
|
||||
public int SceneCount { get; set; }
|
||||
public int ScriptCount { get; set; }
|
||||
|
||||
public string CdnBaseUrl { get; set; } = "https://assets.aeternalisgames.com";
|
||||
|
||||
public string GetPageUrl(int page)
|
||||
{
|
||||
var parts = new List<string> { $"page={page}" };
|
||||
if (!string.IsNullOrEmpty(Search)) parts.Add($"search={Uri.EscapeDataString(Search)}");
|
||||
if (TypeFilter.HasValue) parts.Add($"type={TypeFilter}");
|
||||
return "/admin/assets?" + string.Join("&", parts);
|
||||
}
|
||||
|
||||
public async Task OnGetAsync()
|
||||
{
|
||||
AssetCount = await _db.ClientAssets.CountAsync();
|
||||
if (CurrentPage < 1) CurrentPage = 1;
|
||||
|
||||
var cdnUrl = Environment.GetEnvironmentVariable("CDN_BASE_URL");
|
||||
if (!string.IsNullOrEmpty(cdnUrl)) CdnBaseUrl = cdnUrl;
|
||||
|
||||
// Stats
|
||||
TextureCount = await _db.ClientAssets.CountAsync(a => a.AssetType == ClientAssetType.Texture);
|
||||
SceneCount = await _db.ClientAssets.CountAsync(a => a.AssetType == ClientAssetType.Scene);
|
||||
ScriptCount = await _db.ClientAssets.CountAsync(a => a.AssetType == ClientAssetType.Script);
|
||||
|
||||
var query = _db.ClientAssets.AsQueryable();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(Search))
|
||||
query = query.Where(a => a.FilePath.Contains(Search));
|
||||
|
||||
if (TypeFilter.HasValue)
|
||||
query = query.Where(a => a.AssetType == TypeFilter.Value);
|
||||
|
||||
TotalCount = await query.CountAsync();
|
||||
|
||||
Assets = await query
|
||||
.OrderByDescending(a => a.UpdatedAt)
|
||||
.Skip((CurrentPage - 1) * PageSize)
|
||||
.Take(PageSize)
|
||||
.ToListAsync();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,10 +16,19 @@ public class IndexModel : AdminPageModel
|
||||
}
|
||||
|
||||
public List<DungeonItemDefinition> Items { get; set; } = new();
|
||||
|
||||
[FromQuery(Name = "search")]
|
||||
public string? Search { get; set; }
|
||||
|
||||
[FromQuery(Name = "type")]
|
||||
public ItemType? TypeFilter { get; set; }
|
||||
|
||||
[FromQuery(Name = "rarity")]
|
||||
public ItemRarity? RarityFilter { get; set; }
|
||||
|
||||
[FromQuery(Name = "page")]
|
||||
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);
|
||||
@@ -34,26 +43,23 @@ public class IndexModel : AdminPageModel
|
||||
return "/admin/items?" + string.Join("&", parts);
|
||||
}
|
||||
|
||||
public async Task OnGetAsync(string? search, ItemType? type, ItemRarity? rarity, int page = 1)
|
||||
public async Task OnGetAsync()
|
||||
{
|
||||
Search = search;
|
||||
TypeFilter = type;
|
||||
RarityFilter = rarity;
|
||||
CurrentPage = Math.Max(1, page);
|
||||
if (CurrentPage < 1) CurrentPage = 1;
|
||||
|
||||
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 (!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 (TypeFilter.HasValue)
|
||||
query = query.Where(i => i.Type == TypeFilter.Value);
|
||||
|
||||
if (rarity.HasValue)
|
||||
query = query.Where(i => i.Rarity == rarity.Value);
|
||||
if (RarityFilter.HasValue)
|
||||
query = query.Where(i => i.Rarity == RarityFilter.Value);
|
||||
|
||||
TotalCount = await query.CountAsync();
|
||||
|
||||
|
||||
@@ -16,10 +16,19 @@ public class IndexModel : AdminPageModel
|
||||
}
|
||||
|
||||
public List<DungeonMobDefinition> Mobs { get; set; } = new();
|
||||
|
||||
[FromQuery(Name = "search")]
|
||||
public string? Search { get; set; }
|
||||
|
||||
[FromQuery(Name = "type")]
|
||||
public MobType? TypeFilter { get; set; }
|
||||
|
||||
[FromQuery(Name = "category")]
|
||||
public MobCategory? CategoryFilter { get; set; }
|
||||
|
||||
[FromQuery(Name = "page")]
|
||||
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);
|
||||
@@ -33,23 +42,20 @@ public class IndexModel : AdminPageModel
|
||||
return "/admin/mobs?" + string.Join("&", parts);
|
||||
}
|
||||
|
||||
public async Task OnGetAsync(string? search, MobType? type, MobCategory? category, int page = 1)
|
||||
public async Task OnGetAsync()
|
||||
{
|
||||
Search = search;
|
||||
TypeFilter = type;
|
||||
CategoryFilter = category;
|
||||
CurrentPage = Math.Max(1, page);
|
||||
if (CurrentPage < 1) CurrentPage = 1;
|
||||
|
||||
var query = _db.DungeonMobDefinitions.AsQueryable();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(search))
|
||||
query = query.Where(m => m.Name.Contains(search) || m.Description.Contains(search));
|
||||
if (!string.IsNullOrWhiteSpace(Search))
|
||||
query = query.Where(m => m.Name.Contains(Search) || m.Description.Contains(Search));
|
||||
|
||||
if (type.HasValue)
|
||||
query = query.Where(m => m.Type == type.Value);
|
||||
if (TypeFilter.HasValue)
|
||||
query = query.Where(m => m.Type == TypeFilter.Value);
|
||||
|
||||
if (category.HasValue)
|
||||
query = query.Where(m => m.Category == category.Value);
|
||||
if (CategoryFilter.HasValue)
|
||||
query = query.Where(m => m.Category == CategoryFilter.Value);
|
||||
|
||||
TotalCount = await query.CountAsync();
|
||||
|
||||
@@ -65,7 +71,6 @@ public class IndexModel : AdminPageModel
|
||||
var mob = await _db.DungeonMobDefinitions.FindAsync(id);
|
||||
if (mob != null)
|
||||
{
|
||||
// Also delete loot table mappings
|
||||
var mappings = await _db.DungeonMobLootTables.Where(m => m.MobDefinitionId == id).ToListAsync();
|
||||
_db.DungeonMobLootTables.RemoveRange(mappings);
|
||||
|
||||
|
||||
@@ -0,0 +1,304 @@
|
||||
@page "/admin/recipes/edit"
|
||||
@model Recipes.EditModel
|
||||
@using Server.Data.Entities
|
||||
@{
|
||||
ViewData["Title"] = Model.IsNew ? "Create Recipe" : $"Edit: {Model.Recipe.Name}";
|
||||
}
|
||||
|
||||
<div class="space-y-6 max-w-5xl">
|
||||
<!-- Header -->
|
||||
<div class="flex items-center gap-4">
|
||||
<a href="/admin/recipes" 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 Recipe" : "Edit Recipe")</h1>
|
||||
<p class="text-gray-400 mt-1">@(Model.IsNew ? "Add a new crafting recipe" : $"ID: {Model.Recipe.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="Recipe.Id" value="@Model.Recipe.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">Recipe Name *</label>
|
||||
<input type="text" name="Recipe.Name" value="@Model.Recipe.Name" class="input" required maxlength="64" />
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="label">Crafting Skill</label>
|
||||
<select name="Recipe.SkillType" class="input">
|
||||
@foreach (var s in Enum.GetValues<CraftingSkillType>())
|
||||
{
|
||||
<option value="@s" selected="@(Model.Recipe.SkillType == s)">@s</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="lg:col-span-3">
|
||||
<label class="label">Description</label>
|
||||
<textarea name="Recipe.Description" class="input" rows="2" maxlength="256">@Model.Recipe.Description</textarea>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="label">Required Level</label>
|
||||
<input type="number" name="Recipe.RequiredLevel" value="@Model.Recipe.RequiredLevel" class="input" min="1" max="100" />
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="label">Tier</label>
|
||||
<input type="number" name="Recipe.Tier" value="@Model.Recipe.Tier" class="input" min="1" />
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="label">Base XP</label>
|
||||
<input type="number" name="Recipe.BaseXp" value="@Model.Recipe.BaseXp" class="input" min="0" />
|
||||
</div>
|
||||
|
||||
<div class="flex items-center gap-6 pt-6">
|
||||
<label class="flex items-center gap-2 cursor-pointer">
|
||||
<input type="checkbox" name="Recipe.IsEnabled" value="true" checked="@Model.Recipe.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="Recipe.IsBaseRecipe" value="true" checked="@Model.Recipe.IsBaseRecipe" class="w-4 h-4 rounded border-gray-600 bg-gray-800 text-indigo-600" />
|
||||
<span class="text-gray-300">Base Recipe (known by all)</span>
|
||||
</label>
|
||||
<label class="flex items-center gap-2 cursor-pointer">
|
||||
<input type="checkbox" name="Recipe.HasStatRolls" value="true" checked="@Model.Recipe.HasStatRolls" class="w-4 h-4 rounded border-gray-600 bg-gray-800 text-indigo-600" />
|
||||
<span class="text-gray-300">Has Stat Rolls</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Output Item -->
|
||||
<div class="card">
|
||||
<div class="p-4 border-b border-gray-700">
|
||||
<h2 class="text-lg font-semibold text-white">Output</h2>
|
||||
</div>
|
||||
<div class="p-6 grid grid-cols-1 md:grid-cols-3 gap-6">
|
||||
<div class="md:col-span-2">
|
||||
<label class="label">Output Item *</label>
|
||||
<select name="Recipe.OutputItemDefinitionId" class="input" required>
|
||||
<option value="">Select output item...</option>
|
||||
@foreach (var item in Model.AllItems)
|
||||
{
|
||||
<option value="@item.Id" selected="@(Model.Recipe.OutputItemDefinitionId == item.Id)">
|
||||
@item.Name (@item.Type - @item.Rarity)
|
||||
</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">Output Quantity</label>
|
||||
<input type="number" name="Recipe.OutputQuantity" value="@Model.Recipe.OutputQuantity" class="input" min="1" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Save Recipe First -->
|
||||
<div class="flex items-center gap-4">
|
||||
<button type="submit" class="btn btn-primary">@(Model.IsNew ? "Create Recipe" : "Save Changes")</button>
|
||||
<a href="/admin/recipes" class="btn btn-secondary">Cancel</a>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<!-- Ingredients Section -->
|
||||
@if (!Model.IsNew)
|
||||
{
|
||||
<div class="card">
|
||||
<div class="p-4 border-b border-gray-700 flex items-center justify-between">
|
||||
<h2 class="text-lg font-semibold text-white">Ingredients (@Model.Ingredients.Count)</h2>
|
||||
<button type="button" onclick="showAddIngredientModal()" class="btn btn-primary text-sm">+ Add Ingredient</button>
|
||||
</div>
|
||||
|
||||
<!-- Visual Recipe Layout -->
|
||||
<div class="p-6">
|
||||
<div class="flex items-center gap-8 justify-center flex-wrap">
|
||||
<!-- Ingredients Grid (4x4) -->
|
||||
<div class="grid grid-cols-4 gap-1 bg-gray-900 p-2 rounded-lg">
|
||||
@for (int i = 0; i < 16; i++)
|
||||
{
|
||||
var ingredient = Model.Ingredients.FirstOrDefault(ing => ing.SlotOrder == i);
|
||||
<div class="w-14 h-14 bg-gray-800 rounded border border-gray-700 flex items-center justify-center relative group">
|
||||
@if (ingredient != null)
|
||||
{
|
||||
@if (ingredient.ItemDefinition != null && !string.IsNullOrEmpty(ingredient.ItemDefinition.SpritePath))
|
||||
{
|
||||
<img src="@Html.Raw(Model.CdnBaseUrl)/@ingredient.ItemDefinition.SpritePath"
|
||||
class="w-10 h-10 object-contain"
|
||||
onerror="this.style.display='none'" />
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="text-xs text-gray-400">@ingredient.ItemDefinition?.Name?.Substring(0, Math.Min(3, ingredient.ItemDefinition?.Name?.Length ?? 0))</span>
|
||||
}
|
||||
@if (ingredient.Quantity > 1)
|
||||
{
|
||||
<span class="absolute bottom-0 right-0 bg-indigo-600 text-white text-xs px-1 rounded">@ingredient.Quantity</span>
|
||||
}
|
||||
|
||||
<!-- Remove button on hover -->
|
||||
<form method="post" asp-page-handler="RemoveIngredient" class="absolute -top-2 -right-2 hidden group-hover:block">
|
||||
@Html.AntiForgeryToken()
|
||||
<input type="hidden" name="ingredientId" value="@ingredient.Id" />
|
||||
<input type="hidden" name="recipeId" value="@Model.Recipe.Id" />
|
||||
<button type="submit" class="w-5 h-5 bg-red-600 rounded-full text-white text-xs flex items-center justify-center hover:bg-red-700">×</button>
|
||||
</form>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="text-gray-700 text-xs">@i</span>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<!-- Arrow -->
|
||||
<div class="text-4xl text-gray-600">→</div>
|
||||
|
||||
<!-- Output -->
|
||||
<div class="w-20 h-20 bg-gray-800 rounded-lg border-2 border-indigo-600 flex items-center justify-center relative">
|
||||
@if (Model.Recipe.OutputItem != null && !string.IsNullOrEmpty(Model.Recipe.OutputItem.SpritePath))
|
||||
{
|
||||
<img src="@Html.Raw(Model.CdnBaseUrl)/@Model.Recipe.OutputItem.SpritePath"
|
||||
class="w-14 h-14 object-contain" />
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="text-gray-400 text-xs text-center">@Model.Recipe.OutputItem?.Name</span>
|
||||
}
|
||||
@if (Model.Recipe.OutputQuantity > 1)
|
||||
{
|
||||
<span class="absolute bottom-1 right-1 bg-indigo-600 text-white text-xs px-1 rounded">@Model.Recipe.OutputQuantity</span>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Ingredients List -->
|
||||
<div class="border-t border-gray-700">
|
||||
<table class="w-full">
|
||||
<thead class="bg-gray-900/50">
|
||||
<tr>
|
||||
<th class="table-header w-12">Slot</th>
|
||||
<th class="table-header w-16">Icon</th>
|
||||
<th class="table-header">Item</th>
|
||||
<th class="table-header w-24">Quantity</th>
|
||||
<th class="table-header w-20">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y divide-gray-700">
|
||||
@foreach (var ing in Model.Ingredients.OrderBy(i => i.SlotOrder))
|
||||
{
|
||||
<tr class="hover:bg-gray-700/30">
|
||||
<td class="table-cell text-gray-500">@ing.SlotOrder</td>
|
||||
<td class="table-cell">
|
||||
@if (ing.ItemDefinition != null && !string.IsNullOrEmpty(ing.ItemDefinition.SpritePath))
|
||||
{
|
||||
<img src="@Html.Raw(Model.CdnBaseUrl)/@ing.ItemDefinition.SpritePath"
|
||||
class="w-8 h-8 object-contain bg-gray-900 rounded" />
|
||||
}
|
||||
</td>
|
||||
<td class="table-cell">
|
||||
<span class="text-white">@ing.ItemDefinition?.Name</span>
|
||||
<span class="text-xs text-gray-500 ml-2">(ID: @ing.ItemDefinitionId)</span>
|
||||
</td>
|
||||
<td class="table-cell text-gray-400">@ing.Quantity</td>
|
||||
<td class="table-cell">
|
||||
<form method="post" asp-page-handler="RemoveIngredient" class="inline">
|
||||
@Html.AntiForgeryToken()
|
||||
<input type="hidden" name="ingredientId" value="@ing.Id" />
|
||||
<input type="hidden" name="recipeId" value="@Model.Recipe.Id" />
|
||||
<button type="submit" class="p-1.5 hover:bg-gray-700 rounded text-red-400" onclick="return confirm('Remove?')">
|
||||
<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="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>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
@if (!Model.Ingredients.Any())
|
||||
{
|
||||
<tr>
|
||||
<td colspan="5" class="table-cell text-center text-gray-500 py-8">
|
||||
No ingredients yet. Add items to create the recipe.
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Add Ingredient Modal -->
|
||||
<div id="addIngredientModal" 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-lg w-full mx-4 border border-gray-700">
|
||||
<h3 class="text-lg font-semibold text-white mb-4">Add Ingredient</h3>
|
||||
<form method="post" asp-page-handler="AddIngredient" class="space-y-4">
|
||||
@Html.AntiForgeryToken()
|
||||
<input type="hidden" name="recipeId" value="@Model.Recipe.Id" />
|
||||
|
||||
<div>
|
||||
<label class="label">Item *</label>
|
||||
<select name="itemId" class="input" required>
|
||||
<option value="">Select an item...</option>
|
||||
@foreach (var item in Model.AllItems)
|
||||
{
|
||||
<option value="@item.Id">@item.Name (@item.Type)</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label class="label">Slot (0-15)</label>
|
||||
<input type="number" name="slotOrder" value="@Model.Ingredients.Count" class="input" min="0" max="15" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">Quantity</label>
|
||||
<input type="number" name="quantity" value="1" class="input" min="1" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex justify-end gap-3 pt-4">
|
||||
<button type="button" onclick="closeAddIngredientModal()" class="btn btn-secondary">Cancel</button>
|
||||
<button type="submit" class="btn btn-primary">Add Ingredient</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@section Scripts {
|
||||
<script>
|
||||
function showAddIngredientModal() {
|
||||
document.getElementById('addIngredientModal').classList.remove('hidden');
|
||||
document.getElementById('addIngredientModal').classList.add('flex');
|
||||
}
|
||||
function closeAddIngredientModal() {
|
||||
document.getElementById('addIngredientModal').classList.add('hidden');
|
||||
document.getElementById('addIngredientModal').classList.remove('flex');
|
||||
}
|
||||
document.addEventListener('keydown', e => { if (e.key === 'Escape') closeAddIngredientModal(); });
|
||||
</script>
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Server.Data;
|
||||
using Server.Data.Entities;
|
||||
|
||||
namespace VoidScavengers.Services.Admin.Pages.Recipes;
|
||||
|
||||
public class EditModel : AdminPageModel
|
||||
{
|
||||
private readonly GameDbContext _db;
|
||||
|
||||
public EditModel(GameDbContext db)
|
||||
{
|
||||
_db = db;
|
||||
}
|
||||
|
||||
[BindProperty]
|
||||
public DungeonCraftingRecipe Recipe { get; set; } = new();
|
||||
|
||||
public List<DungeonCraftingRecipeIngredient> Ingredients { get; set; } = new();
|
||||
public List<DungeonItemDefinition> AllItems { get; set; } = new();
|
||||
|
||||
public bool IsNew => Recipe.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;
|
||||
|
||||
AllItems = await _db.DungeonItemDefinitions
|
||||
.Where(i => i.IsEnabled)
|
||||
.OrderBy(i => i.Type)
|
||||
.ThenBy(i => i.Name)
|
||||
.ToListAsync();
|
||||
|
||||
if (id.HasValue)
|
||||
{
|
||||
var recipe = await _db.DungeonCraftingRecipes
|
||||
.Include(r => r.OutputItem)
|
||||
.FirstOrDefaultAsync(r => r.Id == id.Value);
|
||||
|
||||
if (recipe != null)
|
||||
{
|
||||
Recipe = recipe;
|
||||
Ingredients = await _db.DungeonCraftingRecipeIngredients
|
||||
.Include(i => i.ItemDefinition)
|
||||
.Where(i => i.RecipeId == id.Value)
|
||||
.OrderBy(i => i.SlotOrder)
|
||||
.ToListAsync();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Recipe.IsEnabled = true;
|
||||
Recipe.RequiredLevel = 1;
|
||||
Recipe.Tier = 1;
|
||||
Recipe.OutputQuantity = 1;
|
||||
Recipe.BaseXp = 25;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostAsync()
|
||||
{
|
||||
var cdnUrl = Environment.GetEnvironmentVariable("CDN_BASE_URL");
|
||||
if (!string.IsNullOrEmpty(cdnUrl)) CdnBaseUrl = cdnUrl;
|
||||
|
||||
AllItems = await _db.DungeonItemDefinitions.Where(i => i.IsEnabled).OrderBy(i => i.Name).ToListAsync();
|
||||
|
||||
Recipe.IsEnabled = Request.Form.ContainsKey("Recipe.IsEnabled");
|
||||
Recipe.IsBaseRecipe = Request.Form.ContainsKey("Recipe.IsBaseRecipe");
|
||||
Recipe.HasStatRolls = Request.Form.ContainsKey("Recipe.HasStatRolls");
|
||||
|
||||
if (string.IsNullOrWhiteSpace(Recipe.Name))
|
||||
{
|
||||
Message = "Name is required.";
|
||||
IsError = true;
|
||||
return Page();
|
||||
}
|
||||
|
||||
if (Recipe.OutputItemDefinitionId == 0)
|
||||
{
|
||||
Message = "Output item is required.";
|
||||
IsError = true;
|
||||
return Page();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (Recipe.Id == 0)
|
||||
{
|
||||
_db.DungeonCraftingRecipes.Add(Recipe);
|
||||
await _db.SaveChangesAsync();
|
||||
Message = $"Recipe '{Recipe.Name}' created. Now add ingredients below.";
|
||||
return RedirectToPage("/Recipes/Edit", new { id = Recipe.Id });
|
||||
}
|
||||
else
|
||||
{
|
||||
var existing = await _db.DungeonCraftingRecipes.FindAsync(Recipe.Id);
|
||||
if (existing == null)
|
||||
{
|
||||
Message = "Recipe not found.";
|
||||
IsError = true;
|
||||
return Page();
|
||||
}
|
||||
|
||||
existing.Name = Recipe.Name;
|
||||
existing.Description = Recipe.Description;
|
||||
existing.SkillType = Recipe.SkillType;
|
||||
existing.RequiredLevel = Recipe.RequiredLevel;
|
||||
existing.OutputItemDefinitionId = Recipe.OutputItemDefinitionId;
|
||||
existing.OutputQuantity = Recipe.OutputQuantity;
|
||||
existing.Tier = Recipe.Tier;
|
||||
existing.BaseXp = Recipe.BaseXp;
|
||||
existing.IsBaseRecipe = Recipe.IsBaseRecipe;
|
||||
existing.HasStatRolls = Recipe.HasStatRolls;
|
||||
existing.IsEnabled = Recipe.IsEnabled;
|
||||
|
||||
await _db.SaveChangesAsync();
|
||||
|
||||
Recipe = await _db.DungeonCraftingRecipes
|
||||
.Include(r => r.OutputItem)
|
||||
.FirstAsync(r => r.Id == existing.Id);
|
||||
|
||||
Ingredients = await _db.DungeonCraftingRecipeIngredients
|
||||
.Include(i => i.ItemDefinition)
|
||||
.Where(i => i.RecipeId == Recipe.Id)
|
||||
.OrderBy(i => i.SlotOrder)
|
||||
.ToListAsync();
|
||||
|
||||
Message = "Changes saved successfully.";
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Message = $"Error: {ex.Message}";
|
||||
IsError = true;
|
||||
}
|
||||
|
||||
return Page();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostAddIngredientAsync(int recipeId, int itemId, int slotOrder, int quantity)
|
||||
{
|
||||
var ingredient = new DungeonCraftingRecipeIngredient
|
||||
{
|
||||
RecipeId = recipeId,
|
||||
ItemDefinitionId = itemId,
|
||||
SlotOrder = slotOrder,
|
||||
Quantity = quantity
|
||||
};
|
||||
|
||||
_db.DungeonCraftingRecipeIngredients.Add(ingredient);
|
||||
await _db.SaveChangesAsync();
|
||||
|
||||
return RedirectToPage("/Recipes/Edit", new { id = recipeId });
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostRemoveIngredientAsync(int ingredientId, int recipeId)
|
||||
{
|
||||
var ingredient = await _db.DungeonCraftingRecipeIngredients.FindAsync(ingredientId);
|
||||
if (ingredient != null)
|
||||
{
|
||||
_db.DungeonCraftingRecipeIngredients.Remove(ingredient);
|
||||
await _db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
return RedirectToPage("/Recipes/Edit", new { id = recipeId });
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,16 @@
|
||||
@page "/admin/recipes"
|
||||
@model Recipes.IndexModel
|
||||
@using Server.Data.Entities
|
||||
@{
|
||||
ViewData["Title"] = "Recipes";
|
||||
}
|
||||
|
||||
<div class="space-y-6">
|
||||
<!-- Header -->
|
||||
<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 (@Model.RecipeCount total)</p>
|
||||
<h1 class="text-3xl font-bold text-white">Crafting Recipes</h1>
|
||||
<p class="text-gray-400 mt-1">Manage crafting recipes</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">
|
||||
@@ -18,7 +20,195 @@
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="card p-8 text-center">
|
||||
<p class="text-gray-400">Recipe editor coming soon...</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">Skill</label>
|
||||
<select name="skill" class="input">
|
||||
<option value="">All Skills</option>
|
||||
@foreach (var s in Enum.GetValues<CraftingSkillType>())
|
||||
{
|
||||
<option value="@s" selected="@(Model.SkillFilter == s)">@s</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-secondary">Filter</button>
|
||||
<a href="/admin/recipes" class="btn btn-secondary">Clear</a>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- Recipes 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">Recipe</th>
|
||||
<th class="table-header">Output</th>
|
||||
<th class="table-header w-28">Skill</th>
|
||||
<th class="table-header w-20">Lvl</th>
|
||||
<th class="table-header w-24">Ingredients</th>
|
||||
<th class="table-header w-20">Base</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 recipe in Model.Recipes)
|
||||
{
|
||||
<tr class="hover:bg-gray-700/30">
|
||||
<td class="table-cell font-mono text-gray-500">@recipe.Id</td>
|
||||
<td class="table-cell">
|
||||
<span class="font-medium text-white">@recipe.Name</span>
|
||||
@if (!string.IsNullOrEmpty(recipe.Description))
|
||||
{
|
||||
<p class="text-xs text-gray-500 truncate max-w-xs">@recipe.Description</p>
|
||||
}
|
||||
</td>
|
||||
<td class="table-cell">
|
||||
@if (recipe.OutputItem != null)
|
||||
{
|
||||
<div class="flex items-center gap-2">
|
||||
@if (!string.IsNullOrEmpty(recipe.OutputItem.SpritePath))
|
||||
{
|
||||
<img src="@Html.Raw(Model.CdnBaseUrl)/@recipe.OutputItem.SpritePath"
|
||||
class="w-8 h-8 object-contain bg-gray-900 rounded"
|
||||
onerror="this.style.display='none'" />
|
||||
}
|
||||
<div>
|
||||
<span class="text-gray-300">@recipe.OutputItem.Name</span>
|
||||
@if (recipe.OutputQuantity > 1)
|
||||
{
|
||||
<span class="text-gray-500">x@recipe.OutputQuantity</span>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="text-red-400">Missing Item #@recipe.OutputItemDefinitionId</span>
|
||||
}
|
||||
</td>
|
||||
<td class="table-cell">
|
||||
<span class="badge @GetSkillBadgeClass(recipe.SkillType)">@recipe.SkillType</span>
|
||||
</td>
|
||||
<td class="table-cell text-gray-400">@recipe.RequiredLevel</td>
|
||||
<td class="table-cell">
|
||||
<span class="badge badge-common">@recipe.Ingredients.Count</span>
|
||||
</td>
|
||||
<td class="table-cell">
|
||||
@if (recipe.IsBaseRecipe)
|
||||
{
|
||||
<span class="text-green-400">✓</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="text-gray-600">-</span>
|
||||
}
|
||||
</td>
|
||||
<td class="table-cell">
|
||||
@if (recipe.IsEnabled)
|
||||
{
|
||||
<span class="w-3 h-3 bg-green-500 rounded-full inline-block"></span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="w-3 h-3 bg-red-500 rounded-full inline-block"></span>
|
||||
}
|
||||
</td>
|
||||
<td class="table-cell">
|
||||
<div class="flex items-center gap-1">
|
||||
<a href="/admin/recipes/edit?id=@recipe.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(@recipe.Id, '@recipe.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.Recipes.Any())
|
||||
{
|
||||
<tr>
|
||||
<td colspan="9" class="table-cell text-center text-gray-500 py-12">
|
||||
No recipes found. <a href="/admin/recipes/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="@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>
|
||||
|
||||
<!-- 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 Recipe</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>
|
||||
|
||||
@functions {
|
||||
string GetSkillBadgeClass(CraftingSkillType skill) => skill switch
|
||||
{
|
||||
CraftingSkillType.Smithing => "badge-common",
|
||||
CraftingSkillType.Fletching => "badge-uncommon",
|
||||
CraftingSkillType.Jewelry => "badge-rare",
|
||||
CraftingSkillType.Alchemy => "badge-epic",
|
||||
CraftingSkillType.Academic => "badge-legendary",
|
||||
_ => "badge-common"
|
||||
};
|
||||
}
|
||||
|
||||
@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,7 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Server.Data;
|
||||
using Server.Data.Entities;
|
||||
|
||||
namespace VoidScavengers.Services.Admin.Pages.Recipes;
|
||||
|
||||
@@ -12,10 +14,71 @@ public class IndexModel : AdminPageModel
|
||||
_db = db;
|
||||
}
|
||||
|
||||
public int RecipeCount { get; set; }
|
||||
public List<DungeonCraftingRecipe> Recipes { get; set; } = new();
|
||||
|
||||
[FromQuery(Name = "search")]
|
||||
public string? Search { get; set; }
|
||||
|
||||
[FromQuery(Name = "skill")]
|
||||
public CraftingSkillType? SkillFilter { get; set; }
|
||||
|
||||
[FromQuery(Name = "page")]
|
||||
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 string GetPageUrl(int page)
|
||||
{
|
||||
var parts = new List<string> { $"page={page}" };
|
||||
if (!string.IsNullOrEmpty(Search)) parts.Add($"search={Uri.EscapeDataString(Search)}");
|
||||
if (SkillFilter.HasValue) parts.Add($"skill={SkillFilter}");
|
||||
return "/admin/recipes?" + string.Join("&", parts);
|
||||
}
|
||||
|
||||
public async Task OnGetAsync()
|
||||
{
|
||||
RecipeCount = await _db.DungeonCraftingRecipes.CountAsync();
|
||||
if (CurrentPage < 1) CurrentPage = 1;
|
||||
|
||||
var cdnUrl = Environment.GetEnvironmentVariable("CDN_BASE_URL");
|
||||
if (!string.IsNullOrEmpty(cdnUrl)) CdnBaseUrl = cdnUrl;
|
||||
|
||||
var query = _db.DungeonCraftingRecipes
|
||||
.Include(r => r.OutputItem)
|
||||
.Include(r => r.Ingredients)
|
||||
.AsQueryable();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(Search))
|
||||
query = query.Where(r => r.Name.Contains(Search) || r.Description.Contains(Search));
|
||||
|
||||
if (SkillFilter.HasValue)
|
||||
query = query.Where(r => r.SkillType == SkillFilter.Value);
|
||||
|
||||
TotalCount = await query.CountAsync();
|
||||
|
||||
Recipes = await query
|
||||
.OrderBy(r => r.SkillType)
|
||||
.ThenBy(r => r.RequiredLevel)
|
||||
.ThenBy(r => r.Id)
|
||||
.Skip((CurrentPage - 1) * PageSize)
|
||||
.Take(PageSize)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostDeleteAsync(int id)
|
||||
{
|
||||
var recipe = await _db.DungeonCraftingRecipes
|
||||
.Include(r => r.Ingredients)
|
||||
.FirstOrDefaultAsync(r => r.Id == id);
|
||||
|
||||
if (recipe != null)
|
||||
{
|
||||
_db.DungeonCraftingRecipeIngredients.RemoveRange(recipe.Ingredients);
|
||||
_db.DungeonCraftingRecipes.Remove(recipe);
|
||||
await _db.SaveChangesAsync();
|
||||
}
|
||||
return RedirectToPage();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user