Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions EventManager.Tests/AdminPages/ChallengesPageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public async Task PageIsEditableWhenProjectsAreEnabled()
}

[TestMethod]
public async Task ModelFiltersProjectsForOptInChallenges()
public async Task ModelHasProjectsAndChallenges()
{
{
var alice = new Participant("alice@example.org") { Status = ParticipantStatus.CheckedIn };
Expand All @@ -51,8 +51,8 @@ public async Task ModelFiltersProjectsForOptInChallenges()
new Project("c", "xxx", "Middle", "Middle long", "https://example.org", "idC") { Team = { carol }, Challenges = ["First"] }
);
Db.ChallengeSetters.Add(
new("First", 0, true),
new("Second", 1, false),
new("First", 0, true),
new("Awarder", 2, true) { Awards = { new(0, "Top", "a") } }
);
await Db.CommitAsync();
Expand All @@ -61,18 +61,16 @@ public async Task ModelFiltersProjectsForOptInChallenges()
var page = GetPage();
var admin = await GetAdminAsync();
var model = await page.GetModelAsync(admin);
var typedModel = Assert.IsInstanceOfType<IReadOnlyCollection<ChallengesPage.ChallengeSetterAndProjects>>(model);

// and they're sorted case-insensitive with awards first!
Assert.HasCount(3, typedModel);
Assert.AreEqual("First", typedModel.ElementAt(0).ChallengeSetter.Name, StringComparer.Ordinal);
Assert.AreSequenceEqual(["xxx", "Zzz"], typedModel.ElementAt(0).Projects.Select(p => p.Key.Title), StringComparer.Ordinal);
Assert.AreEqual("Second", typedModel.ElementAt(1).ChallengeSetter.Name, StringComparer.Ordinal);
Assert.AreSequenceEqual(["Aaa", "xxx", "Zzz"], typedModel.ElementAt(1).Projects.Select(p => p.Key.Title), StringComparer.Ordinal);
Assert.AreEqual("Awarder", typedModel.ElementAt(2).ChallengeSetter.Name, StringComparer.Ordinal);
Assert.AreSequenceEqual(["Zzz", "Aaa"], typedModel.ElementAt(2).Projects.Select(p => p.Key.Title), StringComparer.Ordinal);
Assert.AreSequenceEqual(["Awarder Top"], typedModel.ElementAt(2).Projects.ElementAt(0).Value, StringComparer.Ordinal);
Assert.IsEmpty(typedModel.ElementAt(2).Projects.ElementAt(1).Value);
var typedModel = Assert.IsInstanceOfType<ChallengesPage.Model>(model);

// and the challenges are sorted case-insensitive with awards first!
Assert.HasCount(3, typedModel.ChallengeSetters);
Assert.AreEqual("First", typedModel.ChallengeSetters.ElementAt(0).Name, StringComparer.Ordinal);
Assert.AreEqual("Second", typedModel.ChallengeSetters.ElementAt(1).Name, StringComparer.Ordinal);
Assert.AreEqual("Awarder", typedModel.ChallengeSetters.ElementAt(2).Name, StringComparer.Ordinal);

Assert.HasCount(3, typedModel.ProjectsById);
Assert.AreEqual(typedModel.ProjectsById.First().Key, typedModel.ProjectsById.First().Value.Id);
}

[TestMethod]
Expand Down
36 changes: 17 additions & 19 deletions EventManager.Tests/EndToEndTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -752,35 +752,33 @@ await system.ExecuteRequestAndAssertSuccessAsync(
Assert.AreEqual("FriendFinder", project.Title);
Assert.AreSequenceEqual(["alice@example.org", "bob@example.org"], project.Team.Select(m => m.EmailAddress), SequenceOrder.InAnyOrder);
// but as the event is not over its awards are not visible.
Assert.IsEmpty(gallery.Awards);
Assert.IsFalse(gallery.ShowAwards);

// The organizers can however view the awards in the challenges list.
var adminChallengesPage = await system.ExecuteRequestAndAssertSuccessAsync(adminStorage, "/Admin/Challenges");
var challengesAndProjects = Assert.IsInstanceOfType<IReadOnlyCollection<ChallengesPage.ChallengeSetterAndProjects>>(adminChallengesPage.Model);
Assert.HasCount(3, challengesAndProjects);
Assert.AreEqual("Overall", challengesAndProjects.ElementAt(0).ChallengeSetter.Name, StringComparer.Ordinal);
Assert.HasCount(1, challengesAndProjects.ElementAt(0).Projects);
Assert.HasCount(1, challengesAndProjects.ElementAt(0).ChallengeSetter.Awards);
Assert.AreEqual("Top", challengesAndProjects.ElementAt(0).ChallengeSetter.Awards.Single().Name);
Assert.AreEqual(challengesAndProjects.ElementAt(0).Projects.Single().Key.Id, challengesAndProjects.ElementAt(0).ChallengeSetter.Awards.Single().ProjectId, StringComparer.Ordinal);
Assert.AreEqual("Some Company", challengesAndProjects.ElementAt(1).ChallengeSetter.Name, StringComparer.Ordinal);
Assert.HasCount(1, challengesAndProjects.ElementAt(1).Projects);
Assert.HasCount(1, challengesAndProjects.ElementAt(1).ChallengeSetter.Awards);
Assert.AreEqual("1st place", challengesAndProjects.ElementAt(1).ChallengeSetter.Awards.Single().Name);
Assert.AreEqual(challengesAndProjects.ElementAt(1).Projects.Single().Key.Id, challengesAndProjects.ElementAt(0).ChallengeSetter.Awards.Single().ProjectId, StringComparer.Ordinal);
Assert.AreEqual("Yet Another Company", challengesAndProjects.ElementAt(2).ChallengeSetter.Name, StringComparer.Ordinal);
Assert.HasCount(1, challengesAndProjects.ElementAt(2).Projects);
Assert.HasCount(0, challengesAndProjects.ElementAt(2).ChallengeSetter.Awards);
var challengesAndProjects = Assert.IsInstanceOfType<ChallengesPage.Model>(adminChallengesPage.Model);
Assert.HasCount(1, challengesAndProjects.ProjectsById);
Assert.AreEqual("FriendFinder", challengesAndProjects.ProjectsById.First().Value.Title);
Assert.HasCount(3, challengesAndProjects.ChallengeSetters);
Assert.AreEqual("Overall", challengesAndProjects.ChallengeSetters.ElementAt(0).Name, StringComparer.Ordinal);
Assert.HasCount(1, challengesAndProjects.ChallengeSetters.ElementAt(0).Awards);
Assert.AreEqual("Top", challengesAndProjects.ChallengeSetters.ElementAt(0).Awards.ElementAt(0).Name);
Assert.AreEqual(overallProjects.Single().Id, challengesAndProjects.ChallengeSetters.ElementAt(0).Awards.ElementAt(0).ProjectId);
Assert.AreEqual("Some Company", challengesAndProjects.ChallengeSetters.ElementAt(1).Name, StringComparer.Ordinal);
Assert.HasCount(1, challengesAndProjects.ChallengeSetters.ElementAt(1).Awards);
Assert.AreEqual("1st place", challengesAndProjects.ChallengeSetters.ElementAt(1).Awards.ElementAt(0).Name);
Assert.AreEqual(overallProjects.Single().Id, challengesAndProjects.ChallengeSetters.ElementAt(1).Awards.ElementAt(0).ProjectId);
Assert.AreEqual("Yet Another Company", challengesAndProjects.ChallengeSetters.ElementAt(2).Name, StringComparer.Ordinal);
Assert.HasCount(0, challengesAndProjects.ChallengeSetters.ElementAt(2).Awards);

// The event ends.
await system.ExecuteRequestAndAssertSuccessAsync(adminStorage, "/Admin/End/EndJudging");

// The project now has awards in the gallery, in the right order.
// The project now has awards in the gallery.
var endGallery = await system.ExecuteRequestAsync<OperationResult.Projects>([], "/Projects");
var endProject = Assert.ContainsSingle(endGallery.Contents);
Assert.AreEqual("FriendFinder", endProject.Title);
Assert.HasCount(1, endGallery.Awards);
Assert.AreSequenceEqual(["Overall Top", "Some Company 1st place"], endGallery.Awards[endProject], StringComparer.Ordinal);
Assert.IsTrue(endGallery.ShowAwards);

// The challenges list and projects gallery URL are case-insensitive.
await system.ExecuteRequestAsync<OperationResult.Projects>([], "/pRoJeCts");
Expand Down
139 changes: 90 additions & 49 deletions EventManager.Web/Views/Admin/Challenges.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@model PageModel<IReadOnlyCollection<ChallengesPage.ChallengeSetterAndProjects>, Admin>
@model PageModel<ChallengesPage.Model, Admin>

<section>
<p>
Expand All @@ -21,7 +21,7 @@
then by order of the awards within each challenge setter, again with the first being most important within that challenge.
You can drag-and-drop challenge setters to reorder them.
</p>
@if (Model.Data.Count == 0)
@if (Model.Data.ChallengeSetters.Count == 0)
{
<p>
You will also be able to see how many projects have been submitted for each challenge on this page.
Expand All @@ -34,7 +34,7 @@
</p>
}
@{
var existing = Model.Data.Select(p => new ChallengesPage.ChallengeSetterDefinition(p.ChallengeSetter.Name, p.ChallengeSetter.IsChallengeOptIn));
var existing = Model.Data.ChallengeSetters.Select(c => new ChallengesPage.ChallengeSetterDefinition(c.Name, c.IsChallengeOptIn));
}
<form action="/Admin/Challenges/Edit">
<x-repeated-input label="Challenge setters"
Expand All @@ -56,14 +56,13 @@
</form>
</section>

@if (Model.Data.Count > 0)
@if (Model.Data.ChallengeSetters.Count > 0)
{
<section>
<h2>Login links</h2>
<p>
Copy login links for challenge setters here.
</p>

<script>
async function setClipboardLink(relativeLink, btn) {
const fullLink = window.location.origin + relativeLink;
Expand All @@ -73,73 +72,115 @@
btn.textContent = "Copied!";
}
</script>
@foreach (var setterAndProjects in Model.Data)
@foreach (var setter in Model.Data.ChallengeSetters)
{
var linkOp = Authenticator.AddAuthentication(Model.Config.AuthenticationSecret!, Operation.CreatePageView<ChallengeSetter>(), setterAndProjects.ChallengeSetter.Name);
var linkOp = Authenticator.AddAuthentication(Model.Config.AuthenticationSecret!, Operation.CreatePageView<ChallengeSetter>(), setter.Name);
var link = JsonSerializer.Serialize(linkOp.RelativeUri.ToString());
<fieldset role="group">
<p>@setterAndProjects.ChallengeSetter.Name</p>
<p>@setter.Name</p>
<button onclick="setClipboardLink(@link, this)">Copy login link</button>
</fieldset>
}
</section>

<section>
<h2>Projects per challenge</h2>
<p>
These are the projects that have been submitted for each challenge, with awards in parentheses.
</p>
<p>
Percentages may sum up to more than 100% since projects can participate in more than one challenge.
</p>
@if (Model.Config.EventStatus < EventStatus.Finished)
{
<p>
<em>Awards are not public yet as the event has not finished!</em>
</p>
}
@foreach (var setterAndProjects in Model.Data)
{
var percent = setterAndProjects.Projects.Count * 100 / Model.Data.Count;
<p>
<strong>@setterAndProjects.ChallengeSetter.Name</strong>: @setterAndProjects.Projects.Count (@percent%)
</p>
<ul>
@foreach (var projectAndAwards in setterAndProjects.Projects)
{
<li>
<p>
@projectAndAwards.Key.Title
@if (projectAndAwards.Value.Count > 0)
{
<strong>(@string.Join(", ", projectAndAwards.Value)</strong>
}
</p>
</li>
}
</ul>
}
</section>

<section>
<h2>Challenges preview</h2>
<p>
You can preview all challenges here, even if they are not yet visible to participants.
</p>
<details>
<summary>Preview (click to expand)</summary>
@foreach (var setterAndProjects in Model.Data)
@foreach (var setter in Model.Data.ChallengeSetters)
{
<h3>@setterAndProjects.ChallengeSetter.Name</h3>
@if (setterAndProjects.ChallengeSetter.Description is null)
<h3>@setter.Name</h3>
@if (setter.Description is null)
{
<p><em>Not set yet.</em></p>
}
else
{
@Html.Raw(Markdown.ToHtml(setterAndProjects.ChallengeSetter.Description))
@Html.Raw(Markdown.ToHtml(setter.Description))
}
}
</details>
</section>

@if (Model.Data.ProjectsById.Any(p => p.Value.Challenges.Length > 0))
{
<section>
<h2>Projects per opt-in challenge</h2>
<p>
These are the projects that have been submitted for each challenge.
Percentages may sum up to more than 100% since projects can participate in more than one challenge.
</p>
<details>
<summary>View (click to expand)</summary>
@foreach (var setter in Model.Data.ChallengeSetters)
{
@if (setter.IsChallengeOptIn)
{
var projects = Model.Data.ProjectsById.Values.Where(p => p.Challenges.Contains(setter.Name)).ToArray();
var percent = projects.Length * 100 / Model.Data.ProjectsById.Count;
<p>
<strong>@setter.Name</strong>: @projects.Length projects (@percent%)
</p>
@if (projects.Length > 0)
{
<ul>
@foreach (var project in projects)
{
<li>@project.Title</li>
}
</ul>
}
}
}
</details>
</section>
}

<section>
<h2>Awards</h2>
@if (Model.Data.ChallengeSetters.All(c => c.Awards.Count == 0))
{
<p>
No awards have been given yet.
</p>
}
else
{
<p>
The following awards have been given.
@if (Model.Config.EventStatus < EventStatus.Finished)
{
<strong>They are not public yet as the event has not finished!</strong>
}
</p>

<ul>
@foreach (var setter in Model.Data.ChallengeSetters)
{
if (setter.Awards.Count > 0)
{
<li>
@setter.Name:
<ul>
@foreach (var award in setter.Awards.OrderBy(a => a.Order))
{
if (Model.Data.ProjectsById.TryGetValue(award.ProjectId, out var project))
{
<li><em>@award.Name</em>: @project.Title</li>
}
else
{
<li><em>@award.Name to a project that no longer exists</em></li>
}
}
</ul>
</li>
}
}
</ul>
}
</section>
}
Loading