-
Notifications
You must be signed in to change notification settings - Fork 32
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
Added ability for admins to release and restrict email mode #214
Changes from 1 commit
7c777f4
d23498f
c89366a
578d7a4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,9 +14,10 @@ public abstract class PuzzleStatePerTeamPageModel : EventSpecificPageModel | |
{ | ||
public SortOrder? Sort { get; set; } | ||
|
||
public PuzzleStatePerTeamPageModel(PuzzleServerContext serverContext, UserManager<IdentityUser> userManager) : base(serverContext, userManager) | ||
{ | ||
} | ||
public PuzzleStatePerTeamPageModel( | ||
PuzzleServerContext serverContext, | ||
UserManager<IdentityUser> userManager) | ||
: base(serverContext, userManager) { } | ||
|
||
public IList<PuzzleStatePerTeam> PuzzleStatePerTeam { get; set; } | ||
|
||
|
@@ -29,7 +30,13 @@ public async Task<IActionResult> InitializeModelAsync(Puzzle puzzle, Team team, | |
return NotFound(); | ||
} | ||
|
||
IQueryable<PuzzleStatePerTeam> statesQ = PuzzleStateHelper.GetFullReadOnlyQuery(_context, Event, puzzle, team, EventRole == EventRole.admin ? null : LoggedInUser); | ||
IQueryable<PuzzleStatePerTeam> statesQ = PuzzleStateHelper.GetFullReadOnlyQuery( | ||
_context, | ||
Event, | ||
puzzle, | ||
team, | ||
EventRole == EventRole.admin ? null : LoggedInUser); | ||
|
||
Sort = sort; | ||
|
||
switch(sort ?? DefaultSort) | ||
|
@@ -86,12 +93,38 @@ public async Task<IActionResult> InitializeModelAsync(Puzzle puzzle, Team team, | |
|
||
public async Task SetUnlockStateAsync(Puzzle puzzle, Team team, bool value) | ||
{ | ||
await PuzzleStateHelper.SetUnlockStateAsync(_context, Event, puzzle, team, value ? (DateTime?)DateTime.UtcNow : null, EventRole == EventRole.admin ? null : LoggedInUser); | ||
await PuzzleStateHelper.SetUnlockStateAsync( | ||
_context, | ||
Event, | ||
puzzle, | ||
team, | ||
value ? (DateTime?)DateTime.UtcNow : null, | ||
EventRole == EventRole.admin ? null : LoggedInUser); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. blank line |
||
} | ||
|
||
public async Task SetSolveStateAsync(Puzzle puzzle, Team team, bool value) | ||
{ | ||
await PuzzleStateHelper.SetSolveStateAsync(_context, Event, puzzle, team, value ? (DateTime?)DateTime.UtcNow : null, EventRole == EventRole.admin ? null : LoggedInUser); | ||
await PuzzleStateHelper.SetSolveStateAsync( | ||
_context, | ||
Event, | ||
puzzle, | ||
team, | ||
value ? (DateTime?)DateTime.UtcNow : null, | ||
EventRole == EventRole.admin ? null : LoggedInUser); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. blank line |
||
} | ||
|
||
public async Task SetEmailModeAsync(Puzzle puzzle, Team team, bool value) | ||
{ | ||
await PuzzleStateHelper.SetEmailOnlyModeAsync( | ||
_context, | ||
Event, | ||
puzzle, | ||
team, | ||
value, | ||
EventRole == EventRole.admin ? null : LoggedInUser); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. blank line |
||
} | ||
|
||
public enum SortOrder | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,9 +21,9 @@ public class MapModel : EventSpecificPageModel | |
|
||
public StateStats[,] StateMap { get; private set; } | ||
|
||
public MapModel(PuzzleServerContext serverContext, UserManager<IdentityUser> userManager) : base(serverContext, userManager) | ||
{ | ||
} | ||
public MapModel(PuzzleServerContext serverContext, | ||
UserManager<IdentityUser> userManager) | ||
: base(serverContext, userManager) { } | ||
|
||
public async Task<IActionResult> OnGetAsync() | ||
{ | ||
|
@@ -32,14 +32,22 @@ public async Task<IActionResult> OnGetAsync() | |
|
||
if (EventRole == EventRole.admin) | ||
{ | ||
puzzles = await _context.Puzzles.Where(p => p.Event == Event).Select(p => new PuzzleStats() { Puzzle = p }).ToListAsync(); | ||
puzzles = await _context.Puzzles.Where(p => p.Event == Event) | ||
.Select(p => new PuzzleStats() { Puzzle = p }) | ||
.ToListAsync(); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. blank line |
||
} | ||
else | ||
{ | ||
puzzles = await UserEventHelper.GetPuzzlesForAuthorAndEvent(_context, Event, LoggedInUser).Select(p => new PuzzleStats() { Puzzle = p }).ToListAsync(); | ||
puzzles = await UserEventHelper.GetPuzzlesForAuthorAndEvent(_context, Event, LoggedInUser) | ||
.Select(p => new PuzzleStats() { Puzzle = p }) | ||
.ToListAsync(); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. blank line |
||
} | ||
|
||
List<TeamStats> teams = await _context.Teams.Where(t => t.Event == Event).Select(t => new TeamStats() { Team = t }).ToListAsync(); | ||
List<TeamStats> teams = await _context.Teams.Where(t => t.Event == Event) | ||
.Select(t => new TeamStats() { Team = t }) | ||
.ToListAsync(); | ||
|
||
// build an ID-based lookup for puzzles and teams | ||
Dictionary<int, PuzzleStats> puzzleLookup = new Dictionary<int, PuzzleStats>(); | ||
|
@@ -49,17 +57,30 @@ public async Task<IActionResult> OnGetAsync() | |
teams.ForEach(t => teamLookup[t.Team.ID] = t); | ||
|
||
// tabulate solve counts and team scores | ||
List<PuzzleStatePerTeam> states = await PuzzleStateHelper.GetSparseQuery(_context, Event, null, null, EventRole == EventRole.admin ? null : LoggedInUser).ToListAsync(); | ||
List<PuzzleStatePerTeam> states = await PuzzleStateHelper.GetSparseQuery( | ||
_context, | ||
Event, | ||
null, | ||
null, | ||
EventRole == EventRole.admin ? null : LoggedInUser).ToListAsync(); | ||
|
||
List<StateStats> stateList = new List<StateStats>(states.Count); | ||
foreach (PuzzleStatePerTeam state in states) | ||
{ | ||
// TODO: Is it more performant to prefilter the states if an author, or is this sufficient? | ||
if (!puzzleLookup.TryGetValue(state.PuzzleID, out PuzzleStats puzzle) || !teamLookup.TryGetValue(state.TeamID, out TeamStats team)) | ||
if (!puzzleLookup.TryGetValue(state.PuzzleID, out PuzzleStats puzzle) || | ||
!teamLookup.TryGetValue(state.TeamID, out TeamStats team)) | ||
{ | ||
continue; | ||
} | ||
|
||
stateList.Add(new StateStats() { Puzzle = puzzle, Team = team, UnlockedTime = state.UnlockedTime, SolvedTime = state.SolvedTime }); | ||
stateList.Add(new StateStats() { | ||
Puzzle = puzzle, | ||
Team = team, | ||
UnlockedTime = state.UnlockedTime, | ||
SolvedTime = state.SolvedTime, | ||
LockedOut = state.IsEmailOnlyMode | ||
}); | ||
|
||
if (state.SolvedTime != null) | ||
{ | ||
|
@@ -75,17 +96,26 @@ public async Task<IActionResult> OnGetAsync() | |
} | ||
|
||
// sort puzzles by solve count, add the sort index to the lookup | ||
puzzles = puzzles.OrderByDescending(p => p.SolveCount).ThenBy(p => p.Puzzle.Name).ToList(); | ||
puzzles = puzzles.OrderByDescending(p => p.SolveCount) | ||
.ThenBy(p => p.Puzzle.Name) | ||
.ToList(); | ||
|
||
for (int i = 0; i < puzzles.Count; i++) | ||
{ | ||
puzzles[i].SortOrder = i; | ||
} | ||
|
||
// sort teams by metameta/score, add the sort index to the lookup | ||
teams = teams.OrderBy(t => t.FinalMetaSolveTime).ThenByDescending(t => t.Score).ThenBy(t => t.Team.Name).ToList(); | ||
teams = teams.OrderBy(t => t.FinalMetaSolveTime) | ||
.ThenByDescending(t => t.Score) | ||
.ThenBy(t => t.Team.Name) | ||
.ToList(); | ||
|
||
for (int i = 0; i < teams.Count; i++) | ||
{ | ||
if (i == 0 || teams[i].FinalMetaSolveTime != teams[i - 1].FinalMetaSolveTime || teams[i].Score != teams[i - 1].Score) | ||
if (i == 0 || | ||
teams[i].FinalMetaSolveTime != teams[i - 1].FinalMetaSolveTime || | ||
teams[i].Score != teams[i - 1].Score) | ||
{ | ||
teams[i].Rank = i + 1; | ||
} | ||
|
@@ -129,20 +159,52 @@ public class StateStats | |
public TeamStats Team { get; set; } | ||
public DateTime? UnlockedTime { get; set; } | ||
public DateTime? SolvedTime { get; set; } | ||
public Boolean LockedOut { get; set; } | ||
|
||
public string DisplayText | ||
{ | ||
get | ||
{ | ||
return SolvedTime != null ? "C" : UnlockedTime != null ? "U" : "L"; | ||
if (LockedOut) | ||
{ | ||
return "E"; | ||
} | ||
|
||
if (SolvedTime != null) | ||
{ | ||
return "C"; | ||
} | ||
|
||
if (UnlockedTime != null) | ||
{ | ||
return "U"; | ||
} | ||
|
||
return "L"; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. blank line |
||
} | ||
} | ||
|
||
public int DisplayHue | ||
{ | ||
get | ||
{ | ||
return SolvedTime != null ? 120 : UnlockedTime != null ? 60 : 0; | ||
if (LockedOut) | ||
{ | ||
return 0; | ||
} | ||
|
||
if (SolvedTime != null) | ||
{ | ||
return 120; | ||
} | ||
|
||
if (UnlockedTime != null) | ||
{ | ||
return 60; | ||
} | ||
|
||
return 0; | ||
} | ||
} | ||
|
||
|
@@ -155,15 +217,14 @@ public int DisplayLightness | |
int minutes = (int)((DateTime.UtcNow - SolvedTime.Value).TotalMinutes); | ||
return 75 - (Math.Min(minutes, 236) >> 2); | ||
} | ||
else if (UnlockedTime != null) | ||
|
||
if (UnlockedTime != null) | ||
{ | ||
int minutes = (int)((DateTime.UtcNow - UnlockedTime.Value).TotalMinutes); | ||
return 75 - (Math.Min(minutes, 236) >> 2); | ||
} | ||
else | ||
{ | ||
return 100; | ||
} | ||
|
||
return 100; | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
blank line