diff --git a/ProjectLighthouse/Pages/Partials/CommentsPartial.cshtml b/ProjectLighthouse/Pages/Partials/CommentsPartial.cshtml index c6114822..348db325 100644 --- a/ProjectLighthouse/Pages/Partials/CommentsPartial.cshtml +++ b/ProjectLighthouse/Pages/Partials/CommentsPartial.cshtml @@ -2,20 +2,7 @@ @using System.Web @using LBPUnion.ProjectLighthouse.Types.Profiles
- -

Comments

+

Comments

@if (Model.Comments.Count == 0 && Model.CommentsEnabled) {

There are no comments.

@@ -26,6 +13,11 @@ Comments are disabled. } + else + { + int count = Model.Comments.Count; +

There @(count == 1 ? "is" : "are") @count comment@(count == 1 ? "" : "s").

+ } @if (Model.CommentsEnabled && Model.User != null) { diff --git a/ProjectLighthouse/Pages/SlotPage.cshtml b/ProjectLighthouse/Pages/SlotPage.cshtml index e668bb08..4e0153bd 100644 --- a/ProjectLighthouse/Pages/SlotPage.cshtml +++ b/ProjectLighthouse/Pages/SlotPage.cshtml @@ -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 @@ }
- +
+ @await Html.PartialAsync("Partials/CommentsPartial") +
+
+
+

Reviews

+ @if (Model.Reviews.Count == 0 && Model.ReviewsEnabled) + { +

There are no reviews.

+ } + else if (!Model.ReviewsEnabled) + { + + Reviews are disabled on this level. + + } + else + { + int count = Model.Reviews.Count; +

There @(count == 1 ? "is" : "are") @count review@(count == 1 ? "" : "s").

+ } +
-@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; + +
+
+ @faceAlt +
+
+

@review.Reviewer.Username

+ @if (review.Labels.Length > 1) + { + @foreach (string reviewLabel in review.Labels) + { +
@reviewLabel.Replace("LABEL_", "")
+ } + } + @if (string.IsNullOrWhiteSpace(review.Text)) + { +

+ This review contains no text. +

+ } + else + { +

@review.Text

+ } +
+
+
+ } +
+
+ @if (Model.User != null && Model.User.IsAdmin) {
-

Admin Settings

+

Admin Options

@if (Model.Slot.TeamPick) { diff --git a/ProjectLighthouse/Pages/SlotPage.cshtml.cs b/ProjectLighthouse/Pages/SlotPage.cshtml.cs index 4d7c780b..893683db 100644 --- a/ProjectLighthouse/Pages/SlotPage.cshtml.cs +++ b/ProjectLighthouse/Pages/SlotPage.cshtml.cs @@ -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 Comments; + public List 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 OnGet([FromRoute] int id) @@ -43,6 +45,20 @@ public class SlotPage : BaseLayout this.Comments = new List(); } + 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(); + } + if (this.User == null) return this.Page(); foreach (Comment c in this.Comments) diff --git a/ProjectLighthouse/StaticFiles/css/styles.css b/ProjectLighthouse/StaticFiles/css/styles.css index b231c52f..a944fcfe 100644 --- a/ProjectLighthouse/StaticFiles/css/styles.css +++ b/ProjectLighthouse/StaticFiles/css/styles.css @@ -91,4 +91,21 @@ div.cardStatsUnderTitle > span { /*#endregion User cards*/ -/*#endregion Cards*/ \ No newline at end of file +/*#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*/ \ No newline at end of file