Skip to content

Commit

Permalink
Faster Puzzle Entry (#276)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
tabascq authored Mar 7, 2019
1 parent c8d91b7 commit 216b729
Show file tree
Hide file tree
Showing 3 changed files with 194 additions and 208 deletions.
83 changes: 3 additions & 80 deletions ServerCore/Pages/Puzzles/Create.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -24,49 +24,6 @@
<input asp-for="Puzzle.Name" class="form-control" />
<span asp-validation-for="Puzzle.Name" class="text-danger"></span>
</div>
<div class="form-group">
<div class="checkbox">
<label>
<input asp-for="Puzzle.IsPuzzle" /> @Html.DisplayNameFor(model => model.Puzzle.IsPuzzle)
</label>
</div>
</div>
<div class="form-group">
<div class="checkbox">
<label>
<input asp-for="Puzzle.IsMetaPuzzle" /> @Html.DisplayNameFor(model => model.Puzzle.IsMetaPuzzle)
</label>
</div>
</div>
<div class="form-group">
<div class="checkbox">
<label>
<input asp-for="Puzzle.IsFinalPuzzle" /> @Html.DisplayNameFor(model => model.Puzzle.IsFinalPuzzle)
</label>
</div>
</div>
<div class="form-group">
<div class="checkbox">
<label>
<input asp-for="Puzzle.IsCheatCode" /> @Html.DisplayNameFor(model => model.Puzzle.IsCheatCode)
</label>
</div>
</div>
<div class="form-group">
<label asp-for="Puzzle.SolveValue" class="control-label"></label>
<input asp-for="Puzzle.SolveValue" class="form-control" />
<span asp-validation-for="Puzzle.SolveValue" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Puzzle.HintCoinsForSolve" class="control-label"></label>
<input asp-for="Puzzle.HintCoinsForSolve" class="form-control" />
<span asp-validation-for="Puzzle.HintCoinsForSolve" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Puzzle.Token" class="control-label"></label>
<input asp-for="Puzzle.Token" class="form-control" />
<span asp-validation-for="Puzzle.Token" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Puzzle.Group" class="control-label"></label>
<input asp-for="Puzzle.Group" class="form-control" />
Expand All @@ -78,41 +35,9 @@
<span asp-validation-for="Puzzle.OrderInGroup" class="text-danger"></span>
</div>
<div class="form-group">
<div class="checkbox">
<label>
<input asp-for="Puzzle.IsGloballyVisiblePrerequisite" /> @Html.DisplayNameFor(model => model.Puzzle.IsGloballyVisiblePrerequisite)
</label>
</div>
</div>
<div class="form-group">
<label asp-for="Puzzle.MinPrerequisiteCount" class="control-label"></label>
<input asp-for="Puzzle.MinPrerequisiteCount" class="form-control" />
<span asp-validation-for="Puzzle.MinPrerequisiteCount" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Puzzle.MinutesToAutomaticallySolve" class="control-label"></label>
<input asp-for="Puzzle.MinutesToAutomaticallySolve" class="form-control" />
<span asp-validation-for="Puzzle.MinutesToAutomaticallySolve" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Puzzle.MinutesOfEventLockout" class="control-label"></label>
<input asp-for="Puzzle.MinutesOfEventLockout" class="form-control" />
<span asp-validation-for="Puzzle.MinutesOfEventLockout" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Puzzle.MaxAnnotationKey" class="control-label"></label>
<input asp-for="Puzzle.MaxAnnotationKey" class="form-control" />
<span asp-validation-for="Puzzle.MaxAnnotationKey" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Puzzle.SupportEmailAlias" class="control-label"></label>
<input asp-for="Puzzle.SupportEmailAlias" class="form-control" />
<span asp-validation-for="Puzzle.SupportEmailAlias" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Puzzle.Description" class="control-label"></label>
<input asp-for="Puzzle.Description" class="form-control" />
<span asp-validation-for="Puzzle.Description" class="text-danger"></span>
<label asp-for="Puzzle.Type" class="control-label"></label>
<select asp-for="Puzzle.Type" asp-items="Html.GetEnumSelectList<CreateModel.PuzzleType>()"></select>
<span asp-validation-for="Puzzle.Type" class="text-danger"></span>
</div>
<div class="form-group">
<input type="submit" value="Create" class="btn btn-default" />
Expand All @@ -121,8 +46,6 @@
</div>
</div>



@section Scripts {
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}
77 changes: 65 additions & 12 deletions ServerCore/Pages/Puzzles/Create.cshtml.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<IdentityUser> userManager) : base(serverContext, userManager)
{
Expand All @@ -20,31 +21,83 @@ public CreateModel(PuzzleServerContext serverContext, UserManager<IdentityUser>
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<IActionResult> 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
}
}
}
Loading

0 comments on commit 216b729

Please sign in to comment.