From 216b72929c44abc9111d03bdb365db5b69200e5f Mon Sep 17 00:00:00 2001
From: Kenny Young <42425095+tabascq@users.noreply.github.com>
Date: Wed, 6 Mar 2019 23:57:53 -0800
Subject: [PATCH] Faster Puzzle Entry (#276)
* Faster Puzzle Entry
Streamlined the Create page to only a few fields and a selection of puzzle types that fills out defaults for many others.
Also streamlined the Edit page to separate properties into basic and advanced buckets, and shorten the overall height so that the Prerequisites section is visible.
* Add Required attribute
---
ServerCore/Pages/Puzzles/Create.cshtml | 83 +-------
ServerCore/Pages/Puzzles/Create.cshtml.cs | 77 +++++--
ServerCore/Pages/Puzzles/Edit.cshtml | 242 +++++++++++-----------
3 files changed, 194 insertions(+), 208 deletions(-)
diff --git a/ServerCore/Pages/Puzzles/Create.cshtml b/ServerCore/Pages/Puzzles/Create.cshtml
index e2ef18ec..fe035c6f 100644
--- a/ServerCore/Pages/Puzzles/Create.cshtml
+++ b/ServerCore/Pages/Puzzles/Create.cshtml
@@ -24,49 +24,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -78,41 +35,9 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
@@ -121,8 +46,6 @@
-
-
@section Scripts {
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}
diff --git a/ServerCore/Pages/Puzzles/Create.cshtml.cs b/ServerCore/Pages/Puzzles/Create.cshtml.cs
index e424de70..e6d8483a 100644
--- a/ServerCore/Pages/Puzzles/Create.cshtml.cs
+++ b/ServerCore/Pages/Puzzles/Create.cshtml.cs
@@ -1,4 +1,5 @@
-using System.Threading.Tasks;
+using System.ComponentModel.DataAnnotations;
+using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
@@ -11,7 +12,7 @@ namespace ServerCore.Pages.Puzzles
public class CreateModel : EventSpecificPageModel
{
[BindProperty]
- public Puzzle Puzzle { get; set; }
+ public MiniPuzzle Puzzle { get; set; }
public CreateModel(PuzzleServerContext serverContext, UserManager userManager) : base(serverContext, userManager)
{
@@ -20,31 +21,83 @@ public CreateModel(PuzzleServerContext serverContext, UserManager
public IActionResult OnGet()
{
// Populate default fields
- Puzzle = new Puzzle();
- Puzzle.IsPuzzle = true;
- Puzzle.SolveValue = 10;
- Puzzle.OrderInGroup = 0;
- Puzzle.MinPrerequisiteCount = 0;
+ Puzzle = new MiniPuzzle();
return Page();
}
public async Task OnPostAsync()
{
- ModelState.Remove("Puzzle.Event");
if (!ModelState.IsValid)
{
return Page();
}
- Puzzle.Event = Event;
+ Puzzle p = new Puzzle();
- _context.Puzzles.Add(Puzzle);
- _context.PuzzleAuthors.Add(new PuzzleAuthors() { Puzzle = Puzzle, Author = LoggedInUser });
+ p.Event = Event;
+ p.Name = Puzzle.Name;
+ p.Group = Puzzle.Group;
+ p.OrderInGroup = Puzzle.OrderInGroup;
+
+ switch (Puzzle.Type)
+ {
+ case PuzzleType.FinalMetaPuzzle:
+ p.IsFinalPuzzle = true;
+ p.IsMetaPuzzle = true;
+ p.IsPuzzle = true;
+ p.SolveValue = 1000;
+ p.MinPrerequisiteCount = 1;
+ break;
+ case PuzzleType.MetaPuzzle:
+ p.IsMetaPuzzle = true;
+ p.IsPuzzle = true;
+ p.SolveValue = 50;
+ p.MinPrerequisiteCount = 1;
+ break;
+ case PuzzleType.CheatCode:
+ p.IsPuzzle = true;
+ p.IsCheatCode = true;
+ p.SolveValue = -1;
+ p.MinPrerequisiteCount = 1;
+ break;
+ case PuzzleType.NormalPuzzle:
+ p.IsPuzzle = true;
+ p.SolveValue = 10;
+ p.MinPrerequisiteCount = 1;
+ break;
+ case PuzzleType.InvisiblePuzzle:
+ p.MinPrerequisiteCount = 1;
+ break;
+ case PuzzleType.StartPuzzle:
+ break;
+ }
+
+ _context.Puzzles.Add(p);
+ _context.PuzzleAuthors.Add(new PuzzleAuthors() { Puzzle = p, Author = LoggedInUser });
await _context.SaveChangesAsync();
- return RedirectToPage("./Index");
+ return RedirectToPage("./Edit", new { puzzleId = p.ID });
+ }
+
+ public class MiniPuzzle
+ {
+ [Required]
+ public string Name { get; set; }
+ public string Group { get; set; }
+ public int OrderInGroup { get; set; }
+ public PuzzleType Type { get; set; }
+ }
+
+ public enum PuzzleType
+ {
+ NormalPuzzle,
+ MetaPuzzle,
+ FinalMetaPuzzle,
+ CheatCode,
+ StartPuzzle,
+ InvisiblePuzzle
}
}
}
\ No newline at end of file
diff --git a/ServerCore/Pages/Puzzles/Edit.cshtml b/ServerCore/Pages/Puzzles/Edit.cshtml
index 625e0d1f..28e0eaee 100644
--- a/ServerCore/Pages/Puzzles/Edit.cshtml
+++ b/ServerCore/Pages/Puzzles/Edit.cshtml
@@ -10,125 +10,135 @@
Layout = "_puzzleManagementLayout.cshtml";
}
-