This commit is contained in:
dingo
2025-12-25 15:06:25 -05:00
parent 30b7d89a70
commit 46adfd5e81
5 changed files with 53 additions and 5 deletions
+3 -3
View File
@@ -75,7 +75,7 @@
<td class="table-cell">
@if (!string.IsNullOrEmpty(item.SpritePath))
{
<img src="@Model.CdnBaseUrl/@item.SpritePath"
<img src="@Html.Raw(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'" />
@@ -158,12 +158,12 @@
<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>
<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="/admin/items?page=@(Model.CurrentPage + 1)&search=@Model.Search&type=@Model.TypeFilter&rarity=@Model.RarityFilter" class="btn btn-secondary">Next →</a>
<a href="@Model.GetPageUrl(Model.CurrentPage + 1)" class="btn btn-secondary">Next →</a>
}
</div>
</div>
@@ -25,6 +25,15 @@ public class IndexModel : AdminPageModel
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 (TypeFilter.HasValue) parts.Add($"type={TypeFilter}");
if (RarityFilter.HasValue) parts.Add($"rarity={RarityFilter}");
return "/admin/items?" + string.Join("&", parts);
}
public async Task OnGetAsync(string? search, ItemType? type, ItemRarity? rarity, int page = 1)
{
Search = search;
+1 -1
View File
@@ -122,7 +122,7 @@
<td class="table-cell">
@if (entry.ItemDefinition != null && !string.IsNullOrEmpty(entry.ItemDefinition.SpritePath))
{
<img src="@Model.CdnBaseUrl/@entry.ItemDefinition.SpritePath"
<img src="@Html.Raw(Model.CdnBaseUrl)/@entry.ItemDefinition.SpritePath"
alt="@entry.ItemDefinition.Name"
class="w-8 h-8 object-contain bg-gray-900 rounded border border-gray-700"
onerror="this.style.display='none'" />
+21
View File
@@ -126,6 +126,27 @@
</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 -->
+19 -1
View File
@@ -19,12 +19,26 @@ public class IndexModel : AdminPageModel
public string? Search { get; set; }
public MobType? TypeFilter { get; set; }
public MobCategory? CategoryFilter { 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 async Task OnGetAsync(string? search, MobType? type, MobCategory? category)
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}");
if (CategoryFilter.HasValue) parts.Add($"category={CategoryFilter}");
return "/admin/mobs?" + string.Join("&", parts);
}
public async Task OnGetAsync(string? search, MobType? type, MobCategory? category, int page = 1)
{
Search = search;
TypeFilter = type;
CategoryFilter = category;
CurrentPage = Math.Max(1, page);
var query = _db.DungeonMobDefinitions.AsQueryable();
@@ -37,8 +51,12 @@ public class IndexModel : AdminPageModel
if (category.HasValue)
query = query.Where(m => m.Category == category.Value);
TotalCount = await query.CountAsync();
Mobs = await query
.OrderBy(m => m.Id)
.Skip((CurrentPage - 1) * PageSize)
.Take(PageSize)
.ToListAsync();
}