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

Updated teams layout to include members & removed members page #256

Merged
merged 14 commits into from
Feb 28, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion ServerCore/Pages/Puzzles/SubmitFeedback.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace ServerCore.Pages.Puzzles
{
// [Authorize(Policy = "PlayerIsOnTeam, PlayerCanSeePuzzle")] // TODO: These auth checks not working currently.
[Authorize(Policy = "PlayerIsOnTeam, PlayerCanSeePuzzle")] // TODO: These auth checks not working currently.
jenetlan marked this conversation as resolved.
Show resolved Hide resolved
public class SubmitFeedbackModel : EventSpecificPageModel
{
public SubmitFeedbackModel(PuzzleServerContext serverContext, UserManager<IdentityUser> userManager) : base(serverContext, userManager)
Expand Down
2 changes: 1 addition & 1 deletion ServerCore/Pages/Teams/AddMember.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<h2>@Html.DisplayFor(model => model.Team.Name): Add member</h2>

<div>
<a asp-page="./Members" asp-route-teamId="@Model.Team.ID">Cancel</a>
<a asp-page="./Details" asp-route-teamId="@Model.Team.ID">Cancel</a>
</div>

<h4>Select a user to add to this team:</h4>
Expand Down
68 changes: 8 additions & 60 deletions ServerCore/Pages/Teams/AddMember.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@

namespace ServerCore.Pages.Teams
{
// TODO: Uncomment when auth can read teamId from the route
//[Authorize("IsEventAdminOrPlayerOnTeam")]
[Authorize("IsEventAdmin")]
public class AddMemberModel : EventSpecificPageModel
{
public Team Team { get; set; }
Expand All @@ -34,48 +33,18 @@ public async Task<IActionResult> OnGetAsync(int teamId)
return NotFound("Could not find team with ID '" + teamId + "'. Check to make sure you're accessing this page in the context of a team.");
}

if (EventRole == EventRole.play)
{
// Get all users that want to be on this team
Users = await (from application in _context.TeamApplications
where application.Team == Team &&
!((from teamMember in _context.TeamMembers
where teamMember.Member == application.Player &&
teamMember.Team.Event == Event
select teamMember).Any())
select new Tuple<PuzzleUser, int>(application.Player, application.ID)).ToListAsync();
}
else
{
Debug.Assert(EventRole == EventRole.admin);

// Admins can add anyone
Users = await (from user in _context.PuzzleUsers
where !((from teamMember in _context.TeamMembers
where teamMember.Team.Event == Event
where teamMember.Member == user
select teamMember).Any())
select new Tuple<PuzzleUser, int>(user, -1)).ToListAsync();
}
Users = await (from user in _context.PuzzleUsers
where !((from teamMember in _context.TeamMembers
where teamMember.Team.Event == Event
where teamMember.Member == user
select teamMember).Any())
select new Tuple<PuzzleUser, int>(user, -1)).ToListAsync();

return Page();
}

public async Task<IActionResult> OnGetAddMemberAsync(int teamId, int userId, int applicationId)
{
if (applicationId == -1)
{
if (EventRole != EventRole.admin)
{
return Forbid();
}
}

if (EventRole == EventRole.play && !Event.IsTeamMembershipChangeActive)
{
return NotFound("Team membership change is not currently active.");
}

Team team = await _context.Teams.FirstOrDefaultAsync(m => m.ID == teamId);
if (team == null)
{
Expand Down Expand Up @@ -111,27 +80,6 @@ public async Task<IActionResult> OnGetAddMemberAsync(int teamId, int userId, int
Member.Team = team;
Member.Member = user;

if (applicationId != -1)
{
TeamApplication application = await (from app in _context.TeamApplications
where app.ID == applicationId
select app).FirstOrDefaultAsync();
if (application == null)
{
return NotFound("Could not find application");
}

if (application.Player.ID != userId)
{
return NotFound("Mismatched player and application");
}

if (application.Team != team)
{
return Forbid();
}
}

// Remove any applications the user might have started for this event
var allApplications = from app in _context.TeamApplications
where app.Player == user &&
Expand All @@ -141,7 +89,7 @@ public async Task<IActionResult> OnGetAddMemberAsync(int teamId, int userId, int

_context.TeamMembers.Add(Member);
await _context.SaveChangesAsync();
return RedirectToPage("./Members", new { teamId = teamId });
return RedirectToPage("./Details", new { teamId = teamId });
}
}
}
253 changes: 206 additions & 47 deletions ServerCore/Pages/Teams/Details.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,58 +4,217 @@
@{
ViewData["Title"] = "Team Details";
//Needs route data - ViewData["AdminRoute"] = "/Teams/Details";
//Needs route data - ViewData["AuthorRoute"] = "/Teams/Status";
//Needs route data - ViewData["AuthorRoute"] = "/Teams/Details";
//Needs route data - ViewData["PlayRoute"] = "/Teams/Details";
Layout = "_teamLayout.cshtml";
}
@using Microsoft.AspNetCore.Http.Extensions @* for GetEncodedUrl *@

<h2>@Html.DisplayFor(model => model.Team.Name): Details</h2>
<!--TODO: Consider moving if other pages use this format-->
<style>
.column {
float: left;
width: 50%;
}

<div>
@if (Model.EventRole != ModelBases.EventRole.author)
{
<div>
<a asp-page="./Edit" asp-route-teamId="@Model.Team.ID">Edit</a> |
<a asp-page="./Delete" asp-route-teamId="@Model.Team.ID">Delete</a>
</div>
/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}
</style>

<h2>@Html.DisplayFor(model => model.Team.Name) Team</h2>

@if (Model.EventRole != ModelBases.EventRole.author)
{
<div>
<a asp-page="./Edit" asp-route-teamId="@Model.Team.ID">Edit team details</a> |
<a asp-page="./Delete" asp-route-teamId="@Model.Team.ID">Delete team</a>
</div>
}

<div>
<hr />
<dl class="dl-horizontal">
<dt>
@Html.DisplayNameFor(model => model.Team.Name)
</dt>
<dd>
@Html.DisplayFor(model => model.Team.Name)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Team.RoomID)
</dt>
<dd>
@Html.DisplayFor(model => model.Team.RoomID)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Team.CustomRoom)
</dt>
<dd>
@Html.DisplayFor(model => model.Team.CustomRoom)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Team.PrimaryContactEmail)
</dt>
<dd>
@Html.DisplayFor(model => model.Team.PrimaryContactEmail)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Team.PrimaryPhoneNumber)
</dt>
<dd>
@Html.DisplayFor(model => model.Team.PrimaryPhoneNumber)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Team.SecondaryPhoneNumber)
</dt>
<dd>
@Html.DisplayFor(model => model.Team.SecondaryPhoneNumber)
</dd>
</dl>

<div class="row">
<div class="column">
<h3>Details</h3>
<dl class="dl-horizontal">
<dt>
@Html.DisplayNameFor(model => model.Team.Name)
</dt>
<dd>
@Html.DisplayFor(model => model.Team.Name)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Team.RoomID)
</dt>
<dd>
@Html.DisplayFor(model => model.Team.RoomID)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Team.CustomRoom)
</dt>
<dd>
@Html.DisplayFor(model => model.Team.CustomRoom)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Team.PrimaryContactEmail)
</dt>
<dd>
@Html.DisplayFor(model => model.Team.PrimaryContactEmail)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Team.PrimaryPhoneNumber)
</dt>
<dd>
@Html.DisplayFor(model => model.Team.PrimaryPhoneNumber)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Team.SecondaryPhoneNumber)
</dt>
<dd>
@Html.DisplayFor(model => model.Team.SecondaryPhoneNumber)
</dd>
</dl>
</div>
<div class="column">
<div>
<h3>Members (@(Model.Members.Count))</h3>
@{ bool canAdd = Model.EventRole == ModelBases.EventRole.admin; }

@if (!Model.Event.IsTeamMembershipChangeActive)
{
<div class="alert alert-danger" role="alert">
This event is not currently open for membership changes.
</div>
}
else if (Model.Members.Count >= Model.Event.MaxTeamSize)
{
<div class="alert alert-danger" role="alert">
This team is full.
</div>
}
else
{
canAdd = true;
}

</div>
<table class="table">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.Members[0].Member.Name)
</th>
<th>
@Html.DisplayNameFor(model => model.Members[0].Member.Email)
</th>
<th>
@Html.DisplayNameFor(model => model.Members[0].Member.EmployeeAlias)
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.Members)
{
<tr>
<td>
@if (Model.LoggedInUser.IsGlobalAdmin)
{
<a asp-area="Identity" asp-page="/Account/Edit" asp-route-userId="@item.Member.ID" asp-route-returnUrl="@Request.GetEncodedUrl()">@Html.DisplayFor(modelItem => item.Member.Name)</a>
}
else
{
@Html.DisplayFor(modelItem => item.Member.Name)
}
</td>
<td>
@Html.DisplayFor(modelItem => item.Member.Email)
</td>
<td>
@if (item.Member.EmployeeAlias == null)
{
<p>N/A</p>
}
@Html.DisplayFor(modelItem => item.Member.EmployeeAlias)
jenetlan marked this conversation as resolved.
Show resolved Hide resolved
</td>
@if (canAdd)
jenetlan marked this conversation as resolved.
Show resolved Hide resolved
{
if (Model.EventRole == ModelBases.EventRole.play && Model.Members.Count == 1)
{
<td>
(Can't remove last member)
</td>
}
else
{
<td>
<a asp-page-handler="RemoveMember" asp-route-teamId="@Model.Team.ID" asp-route-teamMemberId="@item.ID" onclick="return confirm('Are you sure you want to remove @item.Member.Name from @Model.Team.Name?')">Remove</a>
</td>
}
}
</tr>
}
</tbody>
</table>
@if (canAdd)
{

<h3>Pending requests (@(Model.Users.Count))</h3>
<div>
<a asp-page="./Apply" asp-route-eventRole="play" asp-route-teamId="@Model.Team.ID">Application link (copy me and email me!)</a>
@if (Model.EventRole == ModelBases.EventRole.admin)
{
<a asp-page="./AddMember" asp-route-teamId="@Model.Team.ID"> | Add a different user</a>
}
</div>

<table class="table">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.Users[0].Item1.Name)
</th>
<th>
@Html.DisplayNameFor(model => model.Users[0].Item1.Email)
</th>
<th>
@Html.DisplayNameFor(model => model.Users[0].Item1.EmployeeAlias)
</th>
<th>
Add player to team
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.Users)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Item1.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Item1.Email)
</td>
<td>
@if (item.Item1.EmployeeAlias == null)
{
<p>N/A</p>
}
@Html.DisplayFor(modelItem => item.Item1.EmployeeAlias)
</td>
<td>
<a asp-page-handler="AddMember" asp-route-teamId="@Model.Team.ID" asp-route-userId="@item.Item1.ID" asp-route-applicationId="@item.Item2">Add</a>
</td>
</tr>
}
</tbody>
</table>
}
</div>
</div>
</div>
Loading