mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-05-21 08:42:27 +00:00
Add users page
This commit is contained in:
parent
7cc3a613e7
commit
b4440659a6
5 changed files with 113 additions and 0 deletions
|
@ -12,6 +12,8 @@ public static class StatisticsHelper
|
||||||
|
|
||||||
public static async Task<int> SlotCount() => await database.Slots.CountAsync();
|
public static async Task<int> SlotCount() => await database.Slots.CountAsync();
|
||||||
|
|
||||||
|
public static async Task<int> UserCount() => await database.Users.CountAsync();
|
||||||
|
|
||||||
public static async Task<int> MMPicksCount() => await database.Slots.CountAsync(s => s.TeamPick);
|
public static async Task<int> MMPicksCount() => await database.Slots.CountAsync(s => s.TeamPick);
|
||||||
|
|
||||||
public static async Task<int> PhotoCount() => await database.Photos.CountAsync();
|
public static async Task<int> PhotoCount() => await database.Photos.CountAsync();
|
||||||
|
|
|
@ -13,6 +13,7 @@ public class BaseLayout : PageModel
|
||||||
public readonly List<PageNavigationItem> NavigationItems = new()
|
public readonly List<PageNavigationItem> NavigationItems = new()
|
||||||
{
|
{
|
||||||
new PageNavigationItem("Home", "/", "home"),
|
new PageNavigationItem("Home", "/", "home"),
|
||||||
|
new PageNavigationItem("Users", "/users/0", "user friends"),
|
||||||
new PageNavigationItem("Photos", "/photos/0", "camera"),
|
new PageNavigationItem("Photos", "/photos/0", "camera"),
|
||||||
new PageNavigationItem("Levels", "/slots/0", "certificate"),
|
new PageNavigationItem("Levels", "/slots/0", "certificate"),
|
||||||
};
|
};
|
||||||
|
|
33
ProjectLighthouse/Pages/Partials/UserCardPartial.cshtml
Normal file
33
ProjectLighthouse/Pages/Partials/UserCardPartial.cshtml
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
@using LBPUnion.ProjectLighthouse.Types.Settings
|
||||||
|
@model LBPUnion.ProjectLighthouse.Types.User
|
||||||
|
|
||||||
|
@{
|
||||||
|
bool showLink = (bool?)ViewData["ShowLink"] ?? false;
|
||||||
|
}
|
||||||
|
|
||||||
|
<div class="ui grid">
|
||||||
|
<div class="eight wide column">
|
||||||
|
@if (showLink)
|
||||||
|
{
|
||||||
|
<h2 style="margin-bottom: 2px;">
|
||||||
|
<a href="~/user/@Model.UserId">@Model.Username</a>
|
||||||
|
</h2>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<h1 style="margin-bottom: 2px;">
|
||||||
|
@Model.Username
|
||||||
|
</h1>
|
||||||
|
}
|
||||||
|
<p>
|
||||||
|
<i>@Model.Status</i>
|
||||||
|
</p>
|
||||||
|
<div class="statsUnderTitle">
|
||||||
|
<i class="pink heart icon" title="Hearts"></i> <span>@Model.Hearts</span>
|
||||||
|
<i class="blue comment icon" title="Comments"></i> <span>@Model.Comments</span>
|
||||||
|
<i class="green upload icon" title="Uploaded Levels"></i><span>@Model.UsedSlots / @ServerSettings.Instance.EntitledSlots</span>
|
||||||
|
<i class="purple camera icon" title="Uploaded Photos"></i><span>@Model.PhotosByMe</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
32
ProjectLighthouse/Pages/UsersPage.cshtml
Normal file
32
ProjectLighthouse/Pages/UsersPage.cshtml
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
@page "/users/{pageNumber:int}"
|
||||||
|
@using LBPUnion.ProjectLighthouse.Types
|
||||||
|
@model LBPUnion.ProjectLighthouse.Pages.UsersPage
|
||||||
|
|
||||||
|
@{
|
||||||
|
Layout = "Layouts/BaseLayout";
|
||||||
|
Model.Title = "Users";
|
||||||
|
}
|
||||||
|
|
||||||
|
<p>There are @Model.UserCount total users.</p>
|
||||||
|
|
||||||
|
@foreach (User user in Model.Users)
|
||||||
|
{
|
||||||
|
<div class="ui segment">
|
||||||
|
@await Html.PartialAsync("Partials/UserCardPartial", user, new ViewDataDictionary(ViewData)
|
||||||
|
{
|
||||||
|
{
|
||||||
|
"ShowLink", true
|
||||||
|
},
|
||||||
|
})
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
@if (Model.PageNumber != 0)
|
||||||
|
{
|
||||||
|
<a href="/users/@(Model.PageNumber - 1)">Previous Page</a>
|
||||||
|
}
|
||||||
|
@(Model.PageNumber + 1) / @(Model.PageAmount)
|
||||||
|
@if (Model.PageNumber < Model.PageAmount - 1)
|
||||||
|
{
|
||||||
|
<a href="/users/@(Model.PageNumber + 1)">Next Page</a>
|
||||||
|
}
|
45
ProjectLighthouse/Pages/UsersPage.cshtml.cs
Normal file
45
ProjectLighthouse/Pages/UsersPage.cshtml.cs
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using JetBrains.Annotations;
|
||||||
|
using LBPUnion.ProjectLighthouse.Helpers;
|
||||||
|
using LBPUnion.ProjectLighthouse.Pages.Layouts;
|
||||||
|
using LBPUnion.ProjectLighthouse.Types;
|
||||||
|
using LBPUnion.ProjectLighthouse.Types.Settings;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace LBPUnion.ProjectLighthouse.Pages;
|
||||||
|
|
||||||
|
public class UsersPage : BaseLayout
|
||||||
|
{
|
||||||
|
public int PageAmount;
|
||||||
|
|
||||||
|
public int PageNumber;
|
||||||
|
|
||||||
|
public int UserCount;
|
||||||
|
|
||||||
|
public List<User> Users;
|
||||||
|
|
||||||
|
public UsersPage([NotNull] Database database) : base(database)
|
||||||
|
{}
|
||||||
|
|
||||||
|
public async Task<IActionResult> OnGet([FromRoute] int pageNumber)
|
||||||
|
{
|
||||||
|
this.UserCount = await StatisticsHelper.UserCount();
|
||||||
|
|
||||||
|
this.PageNumber = pageNumber;
|
||||||
|
this.PageAmount = (int)Math.Ceiling((double)this.UserCount / ServerStatics.PageSize);
|
||||||
|
|
||||||
|
if (this.PageNumber < 0 || this.PageNumber >= this.PageAmount) return this.Redirect($"/users/{Math.Clamp(this.PageNumber, 0, this.PageAmount - 1)}");
|
||||||
|
|
||||||
|
this.Users = await this.Database.Users.OrderByDescending
|
||||||
|
(p => p.UserId)
|
||||||
|
.Skip(pageNumber * ServerStatics.PageSize)
|
||||||
|
.Take(ServerStatics.PageSize)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
return this.Page();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue