mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-30 16:58:38 +00:00
Add reviews to slot page (#264)
* Reviews are now in a working state probably * Apply karma ordering suggestion Co-authored-by: Josh <josh@slendy.pw> Co-authored-by: Josh <josh@slendy.pw>
This commit is contained in:
parent
8ef8c204a1
commit
69d18786a3
4 changed files with 120 additions and 21 deletions
|
@ -2,20 +2,7 @@
|
|||
@using System.Web
|
||||
@using LBPUnion.ProjectLighthouse.Types.Profiles
|
||||
<div class="ui yellow segment" id="comments">
|
||||
<style>
|
||||
.comment {
|
||||
width: 100%;
|
||||
display: inline-block;
|
||||
text-align: left;
|
||||
}
|
||||
.voting {
|
||||
text-align: center;
|
||||
display: inline-block;
|
||||
float: left;
|
||||
margin-right: 0.5em;
|
||||
}
|
||||
</style>
|
||||
<h1>Comments</h1>
|
||||
<h2>Comments</h2>
|
||||
@if (Model.Comments.Count == 0 && Model.CommentsEnabled)
|
||||
{
|
||||
<p>There are no comments.</p>
|
||||
|
@ -26,6 +13,11 @@
|
|||
<i>Comments are disabled.</i>
|
||||
</b>
|
||||
}
|
||||
else
|
||||
{
|
||||
int count = Model.Comments.Count;
|
||||
<p>There @(count == 1 ? "is" : "are") @count comment@(count == 1 ? "" : "s").</p>
|
||||
}
|
||||
|
||||
@if (Model.CommentsEnabled && Model.User != null)
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
@page "/slot/{id:int}"
|
||||
@using System.Web
|
||||
@using LBPUnion.ProjectLighthouse.Helpers.Extensions
|
||||
@using LBPUnion.ProjectLighthouse.Types.Reviews
|
||||
@using LBPUnion.ProjectLighthouse.Types.Settings
|
||||
@model LBPUnion.ProjectLighthouse.Pages.SlotPage
|
||||
|
||||
@{
|
||||
|
@ -9,6 +11,8 @@
|
|||
|
||||
Model.Title = Model.Slot.Name;
|
||||
Model.Description = Model.Slot.Description;
|
||||
|
||||
bool isMobile = this.Request.IsMobile();
|
||||
}
|
||||
|
||||
@await Html.PartialAsync("Partials/SlotCardPartial", Model.Slot, new ViewDataDictionary(ViewData)
|
||||
|
@ -54,14 +58,84 @@
|
|||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="eight wide column">
|
||||
@await Html.PartialAsync("Partials/CommentsPartial")
|
||||
</div>
|
||||
<div class="eight wide column">
|
||||
<div class="ui purple segment">
|
||||
<h2>Reviews</h2>
|
||||
@if (Model.Reviews.Count == 0 && Model.ReviewsEnabled)
|
||||
{
|
||||
<p>There are no reviews.</p>
|
||||
}
|
||||
else if (!Model.ReviewsEnabled)
|
||||
{
|
||||
<b>
|
||||
<i>Reviews are disabled on this level.</i>
|
||||
</b>
|
||||
}
|
||||
else
|
||||
{
|
||||
int count = Model.Reviews.Count;
|
||||
<p>There @(count == 1 ? "is" : "are") @count review@(count == 1 ? "" : "s").</p>
|
||||
}
|
||||
<div class="ui divider"></div>
|
||||
|
||||
@await Html.PartialAsync("Partials/CommentsPartial")
|
||||
@foreach (Review review in Model.Reviews)
|
||||
{
|
||||
string faceHash = review.Thumb switch {
|
||||
-1 => review.Reviewer.BooHash,
|
||||
0 => review.Reviewer.MehHash,
|
||||
1 => review.Reviewer.YayHash,
|
||||
|
||||
_ => throw new ArgumentOutOfRangeException(),
|
||||
};
|
||||
|
||||
string faceAlt = review.Thumb switch {
|
||||
-1 => "Boo!",
|
||||
0 => "Meh.",
|
||||
1 => "Yay!",
|
||||
|
||||
_ => throw new ArgumentOutOfRangeException(),
|
||||
};
|
||||
|
||||
int size = isMobile ? 50 : 100;
|
||||
|
||||
<div class="card">
|
||||
<div>
|
||||
<img class="cardIcon slotCardIcon" src="@ServerSettings.Instance.ExternalUrl/gameAssets/@faceHash" alt="@faceAlt" title="@faceAlt" style="min-width: @(size)px; width: @(size)px; height: @(size)px">
|
||||
</div>
|
||||
<div class="cardStats">
|
||||
<h3 style="margin-bottom: 5px;">@review.Reviewer.Username</h3>
|
||||
@if (review.Labels.Length > 1)
|
||||
{
|
||||
@foreach (string reviewLabel in review.Labels)
|
||||
{
|
||||
<div class="ui blue label">@reviewLabel.Replace("LABEL_", "")</div>
|
||||
}
|
||||
}
|
||||
@if (string.IsNullOrWhiteSpace(review.Text))
|
||||
{
|
||||
<p>
|
||||
<i>This review contains no text.</i>
|
||||
</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<p>@review.Text</p>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<br>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (Model.User != null && Model.User.IsAdmin)
|
||||
{
|
||||
<div class="ui yellow segment">
|
||||
<h2>Admin Settings</h2>
|
||||
<h2>Admin Options</h2>
|
||||
|
||||
@if (Model.Slot.TeamPick)
|
||||
{
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using JetBrains.Annotations;
|
||||
using LBPUnion.ProjectLighthouse.Pages.Layouts;
|
||||
using LBPUnion.ProjectLighthouse.Types;
|
||||
using LBPUnion.ProjectLighthouse.Types.Levels;
|
||||
using LBPUnion.ProjectLighthouse.Types.Profiles;
|
||||
using LBPUnion.ProjectLighthouse.Types.Reviews;
|
||||
using LBPUnion.ProjectLighthouse.Types.Settings;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
@ -16,11 +16,13 @@ namespace LBPUnion.ProjectLighthouse.Pages;
|
|||
public class SlotPage : BaseLayout
|
||||
{
|
||||
public List<Comment> Comments;
|
||||
public List<Review> Reviews;
|
||||
|
||||
public bool CommentsEnabled = ServerSettings.Instance.LevelCommentsEnabled;
|
||||
public readonly bool CommentsEnabled = ServerSettings.Instance.LevelCommentsEnabled;
|
||||
public readonly bool ReviewsEnabled = ServerSettings.Instance.LevelReviewsEnabled;
|
||||
|
||||
public Slot Slot;
|
||||
public SlotPage([NotNull] Database database) : base(database)
|
||||
public SlotPage(Database database) : base(database)
|
||||
{}
|
||||
|
||||
public async Task<IActionResult> OnGet([FromRoute] int id)
|
||||
|
@ -43,6 +45,20 @@ public class SlotPage : BaseLayout
|
|||
this.Comments = new List<Comment>();
|
||||
}
|
||||
|
||||
if (this.ReviewsEnabled)
|
||||
{
|
||||
this.Reviews = await this.Database.Reviews.Include(r => r.Reviewer)
|
||||
.OrderByDescending(r => r.ThumbsUp - r.ThumbsDown)
|
||||
.ThenByDescending(r => r.Timestamp)
|
||||
.Where(r => r.SlotId == id)
|
||||
.Take(50)
|
||||
.ToListAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Reviews = new List<Review>();
|
||||
}
|
||||
|
||||
if (this.User == null) return this.Page();
|
||||
|
||||
foreach (Comment c in this.Comments)
|
||||
|
|
|
@ -91,4 +91,21 @@ div.cardStatsUnderTitle > span {
|
|||
|
||||
/*#endregion User cards*/
|
||||
|
||||
/*#endregion Cards*/
|
||||
/*#endregion Cards*/
|
||||
|
||||
/*#region Comments*/
|
||||
|
||||
.comment {
|
||||
width: 100%;
|
||||
display: inline-block;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.voting {
|
||||
text-align: center;
|
||||
display: inline-block;
|
||||
float: left;
|
||||
margin-right: 0.5em;
|
||||
}
|
||||
|
||||
/*#endregion Comments*/
|
Loading…
Add table
Add a link
Reference in a new issue