Admin v8
This commit is contained in:
@@ -75,7 +75,7 @@
|
|||||||
<td class="table-cell">
|
<td class="table-cell">
|
||||||
@if (!string.IsNullOrEmpty(item.SpritePath))
|
@if (!string.IsNullOrEmpty(item.SpritePath))
|
||||||
{
|
{
|
||||||
<img src="@Model.CdnBaseUrl/@item.SpritePath"
|
<img src="@Html.Raw(Model.CdnBaseUrl)/@item.SpritePath"
|
||||||
alt="@item.Name"
|
alt="@item.Name"
|
||||||
class="w-10 h-10 object-contain bg-gray-900 rounded border border-gray-700"
|
class="w-10 h-10 object-contain bg-gray-900 rounded border border-gray-700"
|
||||||
onerror="this.style.display='none'" />
|
onerror="this.style.display='none'" />
|
||||||
@@ -158,12 +158,12 @@
|
|||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
@if (Model.CurrentPage > 1)
|
@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>
|
<span class="text-gray-400 px-2">@Model.CurrentPage / @Model.TotalPages</span>
|
||||||
@if (Model.CurrentPage < Model.TotalPages)
|
@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>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -25,6 +25,15 @@ public class IndexModel : AdminPageModel
|
|||||||
public int TotalPages => (int)Math.Ceiling(TotalCount / (double)PageSize);
|
public int TotalPages => (int)Math.Ceiling(TotalCount / (double)PageSize);
|
||||||
public string CdnBaseUrl { get; set; } = "https://assets.aeternalisgames.com";
|
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)
|
public async Task OnGetAsync(string? search, ItemType? type, ItemRarity? rarity, int page = 1)
|
||||||
{
|
{
|
||||||
Search = search;
|
Search = search;
|
||||||
|
|||||||
@@ -122,7 +122,7 @@
|
|||||||
<td class="table-cell">
|
<td class="table-cell">
|
||||||
@if (entry.ItemDefinition != null && !string.IsNullOrEmpty(entry.ItemDefinition.SpritePath))
|
@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"
|
alt="@entry.ItemDefinition.Name"
|
||||||
class="w-8 h-8 object-contain bg-gray-900 rounded border border-gray-700"
|
class="w-8 h-8 object-contain bg-gray-900 rounded border border-gray-700"
|
||||||
onerror="this.style.display='none'" />
|
onerror="this.style.display='none'" />
|
||||||
|
|||||||
@@ -126,6 +126,27 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</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>
|
</div>
|
||||||
|
|
||||||
<!-- Delete Modal -->
|
<!-- Delete Modal -->
|
||||||
|
|||||||
@@ -19,12 +19,26 @@ public class IndexModel : AdminPageModel
|
|||||||
public string? Search { get; set; }
|
public string? Search { get; set; }
|
||||||
public MobType? TypeFilter { get; set; }
|
public MobType? TypeFilter { get; set; }
|
||||||
public MobCategory? CategoryFilter { 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;
|
Search = search;
|
||||||
TypeFilter = type;
|
TypeFilter = type;
|
||||||
CategoryFilter = category;
|
CategoryFilter = category;
|
||||||
|
CurrentPage = Math.Max(1, page);
|
||||||
|
|
||||||
var query = _db.DungeonMobDefinitions.AsQueryable();
|
var query = _db.DungeonMobDefinitions.AsQueryable();
|
||||||
|
|
||||||
@@ -37,8 +51,12 @@ public class IndexModel : AdminPageModel
|
|||||||
if (category.HasValue)
|
if (category.HasValue)
|
||||||
query = query.Where(m => m.Category == category.Value);
|
query = query.Where(m => m.Category == category.Value);
|
||||||
|
|
||||||
|
TotalCount = await query.CountAsync();
|
||||||
|
|
||||||
Mobs = await query
|
Mobs = await query
|
||||||
.OrderBy(m => m.Id)
|
.OrderBy(m => m.Id)
|
||||||
|
.Skip((CurrentPage - 1) * PageSize)
|
||||||
|
.Take(PageSize)
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user