Admin v8
This commit is contained in:
@@ -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,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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user