Skip to content

Commit

Permalink
Add various UI stuff (#1948)
Browse files Browse the repository at this point in the history
* make last post link cover the username as well, makes it easier to click and makes more sense in the context anyway

* show submission votes in subs list and forum topics

* add icon to claim button

* only show "current" on wiki revisions that are actually current

* show links to revision source on wiki page history

* improve page history "from-to" colors, table colors were bad on dark mode

* use button design for page footer

* remove empty line for style

* make the vote counts query robust against edited polls
  • Loading branch information
Masterjun3 authored Aug 18, 2024
1 parent 0a4861b commit 59225ec
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 44 deletions.
11 changes: 11 additions & 0 deletions TASVideos.Common/VoteCounts.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace TASVideos.Common;

public class VoteCounts
{
public int VotesYes { get; init; }
public int VotesMeh { get; init; }
public int VotesNo { get; init; }
public bool UserVotedYes { get; init; }
public bool UserVotedMeh { get; init; }
public bool UserVotedNo { get; init; }
}
21 changes: 18 additions & 3 deletions TASVideos/Extensions/EntityExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using TASVideos.Data.Entity.Awards;
using TASVideos.Common;
using TASVideos.Data.Entity.Awards;
using TASVideos.Data.Entity.Forum;
using TASVideos.Data.Entity.Game;
using TASVideos.Pages.Forum.Posts;
Expand Down Expand Up @@ -345,7 +346,7 @@ public static List<SelectListItem> WithAnyEntry(this IEnumerable<SelectListItem>
return [.. UiDefaults.AnyEntry, .. items];
}

public static IQueryable<Pages.Submissions.IndexModel.SubmissionEntry> ToSubListEntry(this IQueryable<Submission> query)
public static IQueryable<Pages.Submissions.IndexModel.SubmissionEntry> ToSubListEntry(this IQueryable<Submission> query, int? userIdForVotes = null)
{
return query
.Select(s => new Pages.Submissions.IndexModel.SubmissionEntry
Expand All @@ -362,7 +363,21 @@ public static List<SelectListItem> WithAnyEntry(this IEnumerable<SelectListItem>
Status = s.Status,
Judge = s.Judge != null ? s.Judge.UserName : null,
Publisher = s.Publisher != null ? s.Publisher.UserName : null,
IntendedClass = s.IntendedClass != null ? s.IntendedClass.Name : null
IntendedClass = s.IntendedClass != null ? s.IntendedClass.Name : null,
Votes = s.Topic != null && s.Topic.Poll != null
&& s.Topic.Poll.PollOptions.Any(o => o.Text == SiteGlobalConstants.PollOptionYes)
&& s.Topic.Poll.PollOptions.Any(o => o.Text == SiteGlobalConstants.PollOptionsMeh)
&& s.Topic.Poll.PollOptions.Any(o => o.Text == SiteGlobalConstants.PollOptionNo)
? new VoteCounts
{
VotesYes = s.Topic.Poll.PollOptions.Single(o => o.Text == SiteGlobalConstants.PollOptionYes).Votes.Count,
VotesMeh = s.Topic.Poll.PollOptions.Single(o => o.Text == SiteGlobalConstants.PollOptionsMeh).Votes.Count,
VotesNo = s.Topic.Poll.PollOptions.Single(o => o.Text == SiteGlobalConstants.PollOptionNo).Votes.Count,
UserVotedYes = s.Topic.Poll.PollOptions.Single(o => o.Text == SiteGlobalConstants.PollOptionYes).Votes.Any(v => v.UserId == userIdForVotes),
UserVotedMeh = s.Topic.Poll.PollOptions.Single(o => o.Text == SiteGlobalConstants.PollOptionsMeh).Votes.Any(v => v.UserId == userIdForVotes),
UserVotedNo = s.Topic.Poll.PollOptions.Single(o => o.Text == SiteGlobalConstants.PollOptionNo).Votes.Any(v => v.UserId == userIdForVotes),
}
: null,
});
}

Expand Down
4 changes: 2 additions & 2 deletions TASVideos/Pages/Forum/Subforum/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
</a>
}
<a asp-page="/Forum/Topics/Index" asp-route-id="@topic.Id" class="fw-bold">@topic.Topics</a>
<div condition="topic.Votes is not null" class="text-body-tertiary float-end"><partial name="_VoteCounts" model="topic.Votes" /></div>
<div class="ms-2">
@{
var totalPages = (topic.Replies - 1) / ForumConstants.PostsPerPage + 1;
Expand Down Expand Up @@ -77,8 +78,7 @@
@if (topic.LastPost is not null)
{
<timezone-convert asp-for="@topic.LastPost.CreateTimestamp" /> <br />
<profile-link username="@topic.LastPost.PosterName"></profile-link>
<a href="/Forum/Posts/@topic.LastPost.Id" class="fa fa-arrow-circle-right"></a>
<a href="/Forum/Posts/@topic.LastPost.Id">@topic.LastPost.PosterName <i class="fa fa-arrow-circle-right"></i></a>
}
</td>
</tr>
Expand Down
20 changes: 18 additions & 2 deletions TASVideos/Pages/Forum/Subforum/Index.cshtml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using TASVideos.Data.Entity.Forum;
using TASVideos.Common;
using TASVideos.Data.Entity.Forum;

namespace TASVideos.Pages.Forum.Subforum;

Expand Down Expand Up @@ -30,6 +31,8 @@ public async Task<IActionResult> OnGet()
return NotFound();
}

int userIdForVotes = User.GetUserId();

Forum = forum;
Topics = await db.ForumTopics
.ForForum(Id)
Expand All @@ -49,7 +52,17 @@ public async Task<IActionResult> OnGet()
PosterName = fp.Poster!.UserName,
CreateTimestamp = fp.CreateTimestamp
})
.FirstOrDefault()
.FirstOrDefault(),
Votes = ft.Submission != null ? ft.Poll != null ? new VoteCounts
{
VotesYes = ft.Poll.PollOptions.Single(o => o.Text == SiteGlobalConstants.PollOptionYes).Votes.Count,
VotesMeh = ft.Poll.PollOptions.Single(o => o.Text == SiteGlobalConstants.PollOptionsMeh).Votes.Count,
VotesNo = ft.Poll.PollOptions.Single(o => o.Text == SiteGlobalConstants.PollOptionNo).Votes.Count,
UserVotedYes = ft.Poll.PollOptions.Single(o => o.Text == SiteGlobalConstants.PollOptionYes).Votes.Any(v => v.UserId == userIdForVotes),
UserVotedMeh = ft.Poll.PollOptions.Single(o => o.Text == SiteGlobalConstants.PollOptionsMeh).Votes.Any(v => v.UserId == userIdForVotes),
UserVotedNo = ft.Poll.PollOptions.Single(o => o.Text == SiteGlobalConstants.PollOptionNo).Votes.Any(v => v.UserId == userIdForVotes),
}
: null : null,
})
.OrderByDescending(ft => ft.Type)
.ThenByDescending(ft => ft.LastPost!.Id) // The database does not enforce it, but we can assume a topic will always have at least one post
Expand Down Expand Up @@ -81,6 +94,9 @@ public class ForumTopicEntry
[TableIgnore]
public bool IsLocked { get; init; }

[TableIgnore]
public VoteCounts? Votes { get; init; }

[TableIgnore]
public LastPostEntry? LastPost { get; init; }

Expand Down
3 changes: 1 addition & 2 deletions TASVideos/Pages/Forum/_Category.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@
{
<div class="col-4 align-items-center">
<timezone-convert asp-for="@forum.LastPost.Timestamp" /> <br />
<profile-link username="@forum.LastPost.PosterName"></profile-link>
<a href="/Forum/Posts/@forum.LastPost.Id" class="fa fa-arrow-circle-right"></a>
<a href="/Forum/Posts/@forum.LastPost.Id">@forum.LastPost.PosterName <i class="fa fa-arrow-circle-right"></i></a>
</div>
}
</row>
Expand Down
7 changes: 4 additions & 3 deletions TASVideos/Pages/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,17 @@
@{
var (version, sha) = Versioning.GetVersion();
}
&copy; @DateTime.UtcNow.Year - TASVideos <a href="https://github.com/TASVideos/tasvideos/commit/@(sha)">v@(version)</a>
- <a href="/SiteRules">Terms</a> - <a href="/api">API</a>
<a class="btn btn-silver btn-sm mb-2" href="https://github.com/TASVideos/tasvideos/commit/@(sha)">&copy; @DateTime.UtcNow.Year - TASVideos v@(version)</a>
<a class="btn btn-info btn-sm mb-2" href="/SiteRules">Terms</a>
<a class="btn btn-info btn-sm mb-2" href="/api">API</a>
@{
string? path = null;
if (ViewData.GetWikiPage() is null && this.Model is not (Publications.ViewModel or Submissions.ViewModel))
{
path = this.Model.HttpContext.Request.Path.ToString().TrimStart('/');
}
}
<a condition="path is not null" class="btn btn-info btn-sm" asp-page="/Wiki/Referrers" asp-route-path="@path">List referrers</a>
<a condition="path is not null" class="btn btn-info btn-sm mb-2" asp-page="/Wiki/Referrers" asp-route-path="@path">List referrers</a>
</p>
</row>
</footer>
Expand Down
20 changes: 20 additions & 0 deletions TASVideos/Pages/Shared/_VoteCounts.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@model VoteCounts?

<span condition="Model is not null">
@{
int totalCount = Model!.VotesYes + Model.VotesMeh + Model.VotesNo;
if (totalCount == 0)
{
<text>No votes</text>
}
else
{
var support = Math.Ceiling(100 * ((Model.VotesYes + (Model.VotesMeh / 2d)) / totalCount));
<text>@support%</text>
}

if (totalCount != 0){
<text> (<span class="@(Model.UserVotedYes ? "fw-bold" : "")">@Model.VotesYes</span>/<span class="@(Model.UserVotedMeh ? "fw-bold" : "")">@Model.VotesMeh</span>/<span class="@(Model.UserVotedNo ? "fw-bold" : "")">@Model.VotesNo</span>)</text>
}
}
</span>
1 change: 1 addition & 0 deletions TASVideos/Pages/Submissions/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
<br />(Available for judging in @hoursRemaining hours)
</small>
</td>
<td><partial name="_VoteCounts" model="item.Votes" /></td>
</tr>
}
</standard-table>
Expand Down
4 changes: 3 additions & 1 deletion TASVideos/Pages/Submissions/Index.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public async Task OnGet()

Submissions = await db.Submissions
.FilterBy(Search)
.ToSubListEntry()
.ToSubListEntry(User.GetUserId())
.SortedPageOf(Search);
}

Expand All @@ -69,6 +69,8 @@ public class SubmissionEntry : ITimeable, ISubmissionDisplay
[Sortable]
public SubmissionStatus Status { get; init; }

public VoteCounts? Votes { get; init; }

[TableIgnore]
public int Id { get; init; }

Expand Down
4 changes: 2 additions & 2 deletions TASVideos/Pages/Submissions/View.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@
</div>

<div class="btn-toolbar mt-2">
<a condition="@canClaimAsJudge" asp-page="Edit" asp-route-id="@Model.Id" asp-page-handler="ClaimForJudging" class="btn btn-success">Claim</a>
<a condition="@canClaimAsPublisher" asp-page="Edit" asp-route-id="@Model.Id" asp-page-handler="ClaimForPublishing" class="btn btn-success">Claim</a>
<a condition="@canClaimAsJudge" asp-page="Edit" asp-route-id="@Model.Id" asp-page-handler="ClaimForJudging" class="btn btn-success"><i class="fa fa-hand"></i> Claim</a>
<a condition="@canClaimAsPublisher" asp-page="Edit" asp-route-id="@Model.Id" asp-page-handler="ClaimForPublishing" class="btn btn-success"><i class="fa fa-hand"></i> Claim</a>
<edit-link condition="@canEdit" asp-page="Edit" asp-route-id="@Model.Id"></edit-link>
<a permission="CatalogMovies" asp-page="Catalog" asp-route-id="@Model.Id" class="btn btn-info"><i class="fa fa-book"></i> Catalog</a>
<a condition="@canPublish" asp-page="Publish" asp-route-id="@Model.Id" class="btn btn-warning">Publish</a>
Expand Down
23 changes: 4 additions & 19 deletions TASVideos/Pages/Wiki/PageHistory.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,16 @@
}

@functions {
string RowStyles(int revision)
{
if (revision == Model.FromRevision)
{
return "table-info";
}

if (revision == Model.ToRevision)
{
return "table-primary";
}

return "";
}

string DiffBtnStyles(int revision, bool isFrom)
{
if (isFrom && revision == Model.FromRevision)
{
return "btn btn-info btn-sm active";
return "btn btn-info btn-sm bg-warning";
}

if (!isFrom && revision == Model.ToRevision)
{
return "btn btn-info btn-sm active";
return "btn btn-info btn-sm bg-warning";
}

return "btn btn-info btn-sm";
Expand All @@ -55,8 +40,8 @@
{
var revision = revisions[i];
var previousId = i < revisions.Count - 1 ? revisions[i + 1].Revision : (int?)null;
<tr data-revision="@revision.Revision" class="@RowStyles(revision.Revision)">
<td><a href="/@(Model.PageName)[email protected]">@revision.Revision</a></td>
<tr data-revision="@revision.Revision">
<td><a href="/@(Model.PageName)[email protected]">@revision.Revision</a> (<a asp-page="ViewSource" asp-route-path="@Model.Path" asp-route-revision="@revision.Revision">source</a>)</td>
<td><timezone-convert asp-for="@revision.CreateTimestamp" /></td>
<td><profile-link username="@revision.CreateUserName"></profile-link></td>
<td>@revision.MinorEdit</td>
Expand Down
4 changes: 2 additions & 2 deletions TASVideos/Pages/Wiki/ViewSource.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<back-link href="/@Model.WikiPage.PageName" name-override="Back to Page"></back-link>
</top-button-bar>
<div class="mb-2">
Revision @Model.Revision (current) <br />
Last Updated by @(Model.WikiPage.AuthorName ?? "Unknown") <timezone-convert asp-for="@Model.WikiPage.CreateTimestamp" in-line="true" />
Revision @Model.WikiPage.Revision @(Model.WikiPage.IsCurrent() ? "(current)" : "(old)") <br />
Edited by @(Model.WikiPage.AuthorName ?? "Unknown") <timezone-convert asp-for="@Model.WikiPage.CreateTimestamp" in-line="true" />
</div>
<pre>@Model.WikiPage.Markup.ReplaceLineEndings("\n")</pre>
12 changes: 4 additions & 8 deletions TASVideos/wwwroot/js/wiki-page-history.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,17 @@ function diffBtnClicked(from, to) {
function updateTableStyling() {
Array.from(document.querySelectorAll('tbody[data-hasrevisions] tr'))
.forEach(function (elem) {
elem.classList.remove('table-primary');
elem.classList.remove('table-info');
elem.querySelector("button[data-from]").classList.remove("active");
elem.querySelector("button[data-to]").classList.remove("active");
elem.querySelector("button[data-from]").classList.remove("bg-warning");
elem.querySelector("button[data-to]").classList.remove("bg-warning");
});

const cur = document.querySelector(`tr[data-revision="${toRevision}"]`);
if (cur) {
cur.classList.add('table-primary');
cur.querySelector("button[data-to]").classList.add("active");
cur.querySelector("button[data-to]").classList.add("bg-warning");
}

const prev = document.querySelector(`tr[data-revision="${fromRevision}"]`);
if (prev) {
prev.classList.add('table-info');
prev.querySelector("button[data-from]").classList.add("active");
prev.querySelector("button[data-from]").classList.add("bg-warning");
}
}

0 comments on commit 59225ec

Please sign in to comment.