305 lines
16 KiB
Plaintext
305 lines
16 KiB
Plaintext
@page "/admin/recipes/edit"
|
||
@model Recipes.EditModel
|
||
@using DataServer.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)/downloads/@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)/downloads/@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)/downloads/@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>
|
||
}
|