Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feedback pages improvements #183

Merged
merged 4 commits into from
Jan 24, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion ServerCore/DataModel/Feedback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class Feedback
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int ID { get; set; }
public Puzzle Puzzle { get; set; }
public User Submitter {get; set;}
public PuzzleUser Submitter {get; set;}
jenetlan marked this conversation as resolved.
Show resolved Hide resolved
public DateTime SubmissionTime { get; set; }
public string WrittenFeedback { get; set; }
public int Difficulty { get; set; }
Expand Down
20 changes: 19 additions & 1 deletion ServerCore/Pages/Puzzles/Feedback.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,29 @@
ViewData["PlayRoute"] = "../Puzzles/SubmitFeedback";
ViewData["RoutingPuzzleId"] = ViewContext.RouteData.Values["puzzleId"];
Layout = "_puzzleManagementLayout.cshtml";
var id = ViewContext.RouteData.Values["id"];

var sumFun = 0.0;
var sumDiff = 0.0;
var count = 0;
foreach (var item in Model.Feedbacks) {
sumFun += item.Fun;
sumDiff += item.Difficulty;
count++;
}
sumFun /= count;
sumDiff /= count;
}
sprx97 marked this conversation as resolved.
Show resolved Hide resolved

<h2>@Html.DisplayFor(model => model.Puzzle.Name): Feedback</h2>

<div>
<h3><b>Avg Fun Rating:</b> @sumFun</h3>
sprx97 marked this conversation as resolved.
Show resolved Hide resolved
<br>
<h3><b>Avg Difficulty Rating:</b> @sumDiff</h3>
</div>

<br>

<table class="table">
<thead>
<tr>
Expand Down
2 changes: 1 addition & 1 deletion ServerCore/Pages/Puzzles/Feedback.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public FeedbackModel(PuzzleServerContext serverContext, UserManager<IdentityUser
/// </summary>
public async Task<IActionResult> OnGetAsync(int puzzleId)
{
Feedbacks = await _context.Feedback.Where((f) => f.Puzzle.ID == puzzleId).ToListAsync();
Feedbacks = await _context.Feedback.Where((f) => f.Puzzle.ID == puzzleId).Include("Submitter").ToListAsync();
Puzzle = await _context.Puzzles.Where((p) => p.ID == puzzleId).FirstOrDefaultAsync();

if (Puzzle == null)
Expand Down
4 changes: 2 additions & 2 deletions ServerCore/Pages/Puzzles/SubmitFeedback.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</div>
<div class="form-group">
<label asp-for="Feedback.Difficulty" class="control-label"></label>
<input asp-for="Feedback.Difficulty" type="range" min="0" max="10" value="5" step="1" class="slider" id="difficultySlider">
<input asp-for="Feedback.Difficulty" type="range" min="0" max="10" step="1" class="slider" id="difficultySlider">
sprx97 marked this conversation as resolved.
Show resolved Hide resolved
<label id="difficultyLabel">NULL</label>
<script>
var diffslider = document.getElementById("difficultySlider");
Expand All @@ -41,7 +41,7 @@
</div>
<div class="form-group">
<label asp-for="Feedback.Fun" class="control-label"></label>
<input asp-for="Feedback.Fun" type="range" min="0" max="10" value="5" step="1" class="slider" id="funSlider">
<input asp-for="Feedback.Fun" type="range" min="0" max="10" step="1" class="slider" id="funSlider">
<label id="funLabel">NULL</label>
<script>
var funslider = document.getElementById("funSlider");
Expand Down
45 changes: 37 additions & 8 deletions ServerCore/Pages/Puzzles/SubmitFeedback.cshtml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
Expand All @@ -9,6 +10,7 @@

namespace ServerCore.Pages.Puzzles
{
// [Authorize(Policy = "PlayerIsOnTeam, PlayerCanSeePuzzle")] // TODO: These auth checks not working currently.
public class SubmitFeedbackModel : EventSpecificPageModel
{
public SubmitFeedbackModel(PuzzleServerContext serverContext, UserManager<IdentityUser> userManager) : base(serverContext, userManager)
Expand All @@ -31,6 +33,15 @@ public async Task<IActionResult> OnGetAsync(int puzzleId)
return NotFound();
}

// Seed existing feedback page
Feedback = await _context.Feedback.Where((f) => f.Puzzle.ID == puzzleId && f.Submitter == LoggedInUser).FirstOrDefaultAsync();
if (Feedback == null)
{
Feedback = new Feedback();
Feedback.Fun = 5;
Feedback.Difficulty = 5;
}

return Page();
}

Expand All @@ -44,15 +55,33 @@ public async Task<IActionResult> OnPostAsync(int puzzleId)
return Page();
}

Feedback.Puzzle = await _context.Puzzles.Where(m => m.ID == puzzleId).FirstOrDefaultAsync();

if (Feedback.Puzzle == null)
{
return NotFound();
}
Feedback editableFeedback = await _context.Feedback.Where((f) => f.Puzzle.ID == puzzleId && f.Submitter == LoggedInUser).FirstOrDefaultAsync();
if (editableFeedback == null)
{
Feedback.SubmissionTime = DateTime.UtcNow;
Feedback.Submitter = LoggedInUser;
Feedback.Puzzle = await _context.Puzzles.Where(m => m.ID == puzzleId).FirstOrDefaultAsync();
if (Feedback.Puzzle == null)
{
return NotFound();
sprx97 marked this conversation as resolved.
Show resolved Hide resolved
}
_context.Feedback.Add(Feedback);
}
else
{
editableFeedback.SubmissionTime = DateTime.UtcNow;
editableFeedback.Submitter = LoggedInUser;
editableFeedback.Difficulty = Feedback.Difficulty;
editableFeedback.Fun = Feedback.Fun;
editableFeedback.WrittenFeedback = Feedback.WrittenFeedback;
editableFeedback.Puzzle = await _context.Puzzles.Where(m => m.ID == puzzleId).FirstOrDefaultAsync();
if (editableFeedback.Puzzle == null)
{
return NotFound();
sprx97 marked this conversation as resolved.
Show resolved Hide resolved
}
_context.Attach(editableFeedback).State = EntityState.Modified;
}

Feedback.SubmissionTime = DateTime.UtcNow;
_context.Feedback.Add(Feedback);
await _context.SaveChangesAsync();

return RedirectToPage("/Teams/Play");
Expand Down