reworked raid details
This commit is contained in:
parent
8afe8af4c5
commit
75b8fd13fc
3 changed files with 148 additions and 104 deletions
|
@ -1,4 +1,5 @@
|
||||||
using Lieb.Models.GuildWars2.Raid;
|
using Lieb.Models;
|
||||||
|
using Lieb.Models.GuildWars2.Raid;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace Lieb.Data
|
namespace Lieb.Data
|
||||||
|
@ -148,7 +149,7 @@ namespace Lieb.Data
|
||||||
|
|
||||||
public async Task SignUp(int raidId, int liebUserId, int guildWars2AccountId, int plannedRoleId, SignUpType signUpType)
|
public async Task SignUp(int raidId, int liebUserId, int guildWars2AccountId, int plannedRoleId, SignUpType signUpType)
|
||||||
{
|
{
|
||||||
if (!IsSignUpAllowed(liebUserId, plannedRoleId, signUpType))
|
if (!await IsRoleSignUpAllowed(raidId, liebUserId, plannedRoleId, signUpType, true, new List<int>()))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -195,7 +196,7 @@ namespace Lieb.Data
|
||||||
|
|
||||||
public async Task ChangeSignUpType(int raidId, int liebUserId, int plannedRoleId, SignUpType signUpType)
|
public async Task ChangeSignUpType(int raidId, int liebUserId, int plannedRoleId, SignUpType signUpType)
|
||||||
{
|
{
|
||||||
if (!IsSignUpAllowed(liebUserId, plannedRoleId, signUpType))
|
if (!await IsRoleSignUpAllowed(raidId, liebUserId, plannedRoleId, signUpType, true, new List<int>()))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -223,7 +224,7 @@ namespace Lieb.Data
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsSignUpAllowed(int liebUserId, int plannedRoleId, SignUpType signUpType)
|
public bool IsRoleSignUpAllowed(int liebUserId, int plannedRoleId, SignUpType signUpType)
|
||||||
{
|
{
|
||||||
if(signUpType == SignUpType.Backup || signUpType == SignUpType.Flex || signUpType == SignUpType.SignedOff)
|
if(signUpType == SignUpType.Backup || signUpType == SignUpType.Flex || signUpType == SignUpType.SignedOff)
|
||||||
{
|
{
|
||||||
|
@ -246,9 +247,14 @@ namespace Lieb.Data
|
||||||
return signUps.Where(s => s.LiebUserId == liebUserId && s.SignUpType == SignUpType.SignedUp).Any();
|
return signUps.Where(s => s.LiebUserId == liebUserId && s.SignUpType == SignUpType.SignedUp).Any();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> IsSignUpAllowed(int raidId, int liebUserId, int plannedRoleId, SignUpType signUpType, bool moveFlexUser, List<int> checkedRoleIds)
|
public bool IsRoleSignUpAllowed(int raidId, int liebUserId, int plannedRoleId, SignUpType signUpType, bool moveFlexUser)
|
||||||
{
|
{
|
||||||
if (IsSignUpAllowed(liebUserId, plannedRoleId, signUpType))
|
return IsRoleSignUpAllowed(raidId, liebUserId, plannedRoleId, signUpType, moveFlexUser, new List<int>()).Result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<bool> IsRoleSignUpAllowed(int raidId, int liebUserId, int plannedRoleId, SignUpType signUpType, bool moveFlexUser, List<int> checkedRoleIds)
|
||||||
|
{
|
||||||
|
if (IsRoleSignUpAllowed(liebUserId, plannedRoleId, signUpType))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (checkedRoleIds == null)
|
if (checkedRoleIds == null)
|
||||||
|
@ -271,7 +277,7 @@ namespace Lieb.Data
|
||||||
foreach (RaidSignUp signUp in raid.SignUps.Where(s => s.LiebUserId == userId && s.SignUpType == SignUpType.Flex))
|
foreach (RaidSignUp signUp in raid.SignUps.Where(s => s.LiebUserId == userId && s.SignUpType == SignUpType.Flex))
|
||||||
{
|
{
|
||||||
if (!checkedRoleIds.Contains(signUp.PlannedRaidRoleId)
|
if (!checkedRoleIds.Contains(signUp.PlannedRaidRoleId)
|
||||||
&& await IsSignUpAllowed(raidId, userId, signUp.PlannedRaidRoleId, SignUpType.SignedUp, moveFlexUser, checkedRoleIds))
|
&& await IsRoleSignUpAllowed(raidId, userId, signUp.PlannedRaidRoleId, SignUpType.SignedUp, moveFlexUser, checkedRoleIds))
|
||||||
{
|
{
|
||||||
if (moveFlexUser)
|
if (moveFlexUser)
|
||||||
{
|
{
|
||||||
|
@ -283,5 +289,52 @@ namespace Lieb.Data
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsRaidSignUpAllowed(int liebUserId, int raidId, out string errorMessage)
|
||||||
|
{
|
||||||
|
errorMessage = string.Empty;
|
||||||
|
using var context = _contextFactory.CreateDbContext();
|
||||||
|
Raid? raid = context.Raids
|
||||||
|
.AsNoTracking()
|
||||||
|
.FirstOrDefault(r => r.RaidId == raidId);
|
||||||
|
if(raid == null)
|
||||||
|
{
|
||||||
|
errorMessage = "Raid not found.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
LiebUser? user = context.LiebUsers
|
||||||
|
.Include(u => u.RoleAssignments)
|
||||||
|
.ThenInclude(a => a.LiebRole)
|
||||||
|
.Include(u => u.GuildWars2Accounts)
|
||||||
|
.ThenInclude(a => a.EquippedBuilds)
|
||||||
|
.AsNoTracking()
|
||||||
|
.FirstOrDefault(r => r.LiebUserId == liebUserId);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
errorMessage = "User not found.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
DateTime freeForAllTime = raid.FreeForAllDate.Date + raid.FreeForAllTime.TimeOfDay;
|
||||||
|
if (!string.IsNullOrEmpty(raid.RequiredRole) && !user.RoleAssignments.Where(a => a.LiebRole.RoleName == raid.RequiredRole).Any() || freeForAllTime > DateTimeOffset.Now)
|
||||||
|
{
|
||||||
|
errorMessage = $"The raid is still locked for {raid.RequiredRole}.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (user.GuildWars2Accounts.Count == 0)
|
||||||
|
{
|
||||||
|
errorMessage = "No Guild Wars 2 account found.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (raid.RaidType != RaidType.Planned && !user.GuildWars2Accounts.Where(a => a.EquippedBuilds.Count > 0).Any())
|
||||||
|
{
|
||||||
|
errorMessage = "No equipped Guild Wars 2 build found.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,82 +40,82 @@
|
||||||
<AuthorizeView Policy="@Constants.Roles.User">
|
<AuthorizeView Policy="@Constants.Roles.User">
|
||||||
<Authorized>
|
<Authorized>
|
||||||
@{
|
@{
|
||||||
ulong discordId = ulong.Parse(@context.User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value);
|
ulong discordId = ulong.Parse(@context.User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value);
|
||||||
LiebUser user = UserService.GetLiebUser(discordId);
|
LiebUser user = UserService.GetLiebUser(discordId);
|
||||||
RaidSignUp userRole = _raid.SignUps.Where(s => s.LiebUserId == user.LiebUserId).FirstOrDefault();
|
RaidSignUp userRole = _raid.SignUps.Where(s => s.LiebUserId == user.LiebUserId).FirstOrDefault();
|
||||||
bool isSignedUp = userRole != null;
|
bool isSignedUp = userRole != null;
|
||||||
DateTime flexTime = _raid.FreeForAllDate.Date + _raid.FreeForAllTime.TimeOfDay;
|
bool isRaidSignUpAllowed = RaidService.IsRaidSignUpAllowed(user.LiebUserId, _raid.RaidId, out string errorMessage);
|
||||||
bool isSignUoAllowed = !_raid.IsRandomized && (user.RoleAssignments.FirstOrDefault(a => a.LiebRole.RoleName == _raid.RequiredRole) != null || flexTime < DateTime.Now);
|
}
|
||||||
isSignUoAllowed = isSignUoAllowed && user.GuildWars2Accounts.Count > 0 && (_raid.RaidType == RaidType.Planned || user.GuildWars2Accounts.FirstOrDefault()?.EquippedBuilds.Count > 0);
|
<label>@errorMessage</label>
|
||||||
|
<table class="table">
|
||||||
|
<tbody>
|
||||||
|
@foreach (var role in _raid.Roles)
|
||||||
|
{
|
||||||
|
RaidSignUp[] signUps = _raid.SignUps.Where(s => s.PlannedRaidRoleId == role.PlannedRaidRoleId).ToArray();
|
||||||
|
int usedSpots = signUps.Where(s => s.SignUpType == SignUpType.SignedUp).Count();
|
||||||
|
|
||||||
<table class="table">
|
<tr>
|
||||||
<tbody>
|
@if (isRaidSignUpAllowed)
|
||||||
@foreach (var role in _raid.Roles)
|
|
||||||
{
|
|
||||||
Models.GuildWars2.Raid.RaidSignUp[] signUps = _raid.SignUps.Where(s => s.PlannedRaidRoleId == role.PlannedRaidRoleId).ToArray();
|
|
||||||
int usedSpots = signUps.Where(s => s.SignUpType == SignUpType.SignedUp).Count();
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
@if (isSignUoAllowed)
|
|
||||||
{
|
|
||||||
@if (@usedSpots < @role.Spots)
|
|
||||||
{
|
|
||||||
<td><button @onclick="() => SignUpClicked(role, user, isSignedUp)">Sign Up</button></td>
|
|
||||||
<td><button @onclick="() => MaybeClicked(role, user, isSignedUp)">Maybe</button></td>
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
<td></td>
|
|
||||||
<td></td>
|
|
||||||
}
|
|
||||||
<td><button @onclick="() => BackupClicked(role, user, isSignedUp)">Backup</button></td>
|
|
||||||
}
|
|
||||||
<td><h5>@role.Name: @role.Description (@usedSpots /@role.Spots)</h5></td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
@foreach (var signUp in signUps)
|
|
||||||
{
|
{
|
||||||
@if(signUp.SignUpType != SignUpType.SignedOff)
|
@if (RaidService.IsRoleSignUpAllowed(_raid.RaidId, user.LiebUserId, role.PlannedRaidRoleId, SignUpType.SignedUp, false))
|
||||||
{
|
{
|
||||||
<tr>
|
<td><button @onclick="() => SignUpClicked(role, user, isSignedUp, SignUpType.SignedUp)">Sign Up</button></td>
|
||||||
@{bool isUser = isSignedUp && userRole.PlannedRaidRole.PlannedRaidRoleId == role.PlannedRaidRoleId && signUp.LiebUserId == user.LiebUserId;}
|
<td><button @onclick="() => SignUpClicked(role, user, isSignedUp, SignUpType.Maybe)">Maybe</button></td>
|
||||||
@if (isSignUoAllowed)
|
}
|
||||||
{
|
else
|
||||||
<td></td>
|
{
|
||||||
<td></td>
|
<td></td>
|
||||||
@if(isUser)
|
<td></td>
|
||||||
{
|
}
|
||||||
<td><button @onclick="() => SignOffClicked(role, user)">Sign Off</button></td>
|
<td><button @onclick="() => SignUpClicked(role, user, isSignedUp, SignUpType.Backup)">Backup</button></td>
|
||||||
}
|
<td><button @onclick="() => SignUpClicked(role, user, isSignedUp, SignUpType.Flex)">Flex</button></td>
|
||||||
else
|
}
|
||||||
{
|
<td><h5>@role.Name: @role.Description (@usedSpots /@role.Spots)</h5></td>
|
||||||
<td></td>
|
</tr>
|
||||||
}
|
|
||||||
}
|
|
||||||
@{string signUpStatus = string.Empty;}
|
|
||||||
@if (signUp.SignUpType != SignUpType.SignedUp) signUpStatus = $" - {signUp.SignUpType}";
|
|
||||||
|
|
||||||
@if (isUser)
|
@foreach (var signUp in signUps)
|
||||||
|
{
|
||||||
|
@if(signUp.SignUpType != SignUpType.SignedOff)
|
||||||
|
{
|
||||||
|
<tr>
|
||||||
|
@{bool isUser = isSignedUp && userRole.PlannedRaidRole.PlannedRaidRoleId == role.PlannedRaidRoleId && signUp.LiebUserId == user.LiebUserId;}
|
||||||
|
@if (isRaidSignUpAllowed)
|
||||||
|
{
|
||||||
|
<td></td>
|
||||||
|
<td></td>
|
||||||
|
<td></td>
|
||||||
|
@if(isUser)
|
||||||
{
|
{
|
||||||
<td>@signUp.LiebUser.Name
|
<td><button @onclick="() => SignOffClicked(role, user)">Sign Off</button></td>
|
||||||
<select value=@signUp.GuildWars2AccountId @onchange="args => ChangeAccount(user, args)">
|
|
||||||
@foreach (var account in user.GuildWars2Accounts)
|
|
||||||
{
|
|
||||||
<option value=@account.GuildWars2AccountId>@account.AccountName</option>
|
|
||||||
}
|
|
||||||
</select> @signUpStatus </td>
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
<td>@signUp.LiebUser.Name (@signUp.GuildWars2Account.AccountName) @signUpStatus</td>
|
<td></td>
|
||||||
}
|
}
|
||||||
</tr>
|
}
|
||||||
}
|
@{string signUpStatus = string.Empty;}
|
||||||
|
@if (signUp.SignUpType != SignUpType.SignedUp) signUpStatus = $" - {signUp.SignUpType}";
|
||||||
|
|
||||||
|
@if (isUser)
|
||||||
|
{
|
||||||
|
<td>@signUp.LiebUser.Name
|
||||||
|
<select value=@signUp.GuildWars2AccountId @onchange="args => ChangeAccount(user, args)">
|
||||||
|
@foreach (var account in user.GuildWars2Accounts)
|
||||||
|
{
|
||||||
|
<option value=@account.GuildWars2AccountId>@account.AccountName</option>
|
||||||
|
}
|
||||||
|
</select> @signUpStatus </td>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<td>@signUp.LiebUser.Name (@signUp.GuildWars2Account.AccountName) @signUpStatus</td>
|
||||||
|
}
|
||||||
|
</tr>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</tbody>
|
}
|
||||||
</table>
|
</tbody>
|
||||||
}
|
</table>
|
||||||
</Authorized>
|
</Authorized>
|
||||||
<NotAuthorized>
|
<NotAuthorized>
|
||||||
<div>
|
<div>
|
||||||
|
@ -165,41 +165,18 @@
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public Raid _raid { get; set; }
|
public Raid _raid { get; set; }
|
||||||
|
|
||||||
async Task SignUpClicked(PlannedRaidRole role, LiebUser liebUser, bool isSignedUp)
|
[Parameter]
|
||||||
{
|
public LiebUser? _user { get; set; }
|
||||||
if(isSignedUp)
|
|
||||||
{
|
|
||||||
await RaidService.ChangeSignUpType(_raid.RaidId, liebUser.LiebUserId, role.PlannedRaidRoleId, SignUpType.SignedUp);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
await RaidService.SignUp(_raid.RaidId, liebUser.LiebUserId, liebUser.GuildWars2Accounts.FirstOrDefault().GuildWars2AccountId, role.PlannedRaidRoleId, SignUpType.SignedUp);
|
|
||||||
}
|
|
||||||
_raid = RaidService.GetRaid(_raid.RaidId);
|
|
||||||
}
|
|
||||||
|
|
||||||
async Task BackupClicked(PlannedRaidRole role, LiebUser liebUser, bool isSignedUp)
|
async Task SignUpClicked(PlannedRaidRole role, LiebUser liebUser, bool isSignedUp, SignUpType signUpType)
|
||||||
{
|
{
|
||||||
if(isSignedUp)
|
if(isSignedUp)
|
||||||
{
|
{
|
||||||
await RaidService.ChangeSignUpType(_raid.RaidId, liebUser.LiebUserId, role.PlannedRaidRoleId, SignUpType.Backup);
|
await RaidService.ChangeSignUpType(_raid.RaidId, liebUser.LiebUserId, role.PlannedRaidRoleId, signUpType);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await RaidService.SignUp(_raid.RaidId, liebUser.LiebUserId, liebUser.GuildWars2Accounts.FirstOrDefault().GuildWars2AccountId, role.PlannedRaidRoleId, SignUpType.Backup);
|
await RaidService.SignUp(_raid.RaidId, liebUser.LiebUserId, liebUser.GuildWars2Accounts.FirstOrDefault().GuildWars2AccountId, role.PlannedRaidRoleId, signUpType);
|
||||||
}
|
|
||||||
_raid = RaidService.GetRaid(_raid.RaidId);
|
|
||||||
}
|
|
||||||
|
|
||||||
async Task MaybeClicked(PlannedRaidRole role, LiebUser liebUser, bool isSignedUp)
|
|
||||||
{
|
|
||||||
if(isSignedUp)
|
|
||||||
{
|
|
||||||
await RaidService.ChangeSignUpType(_raid.RaidId, liebUser.LiebUserId, role.PlannedRaidRoleId, SignUpType.Maybe);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
await RaidService.SignUp(_raid.RaidId, liebUser.LiebUserId, liebUser.GuildWars2Accounts.FirstOrDefault().GuildWars2AccountId, role.PlannedRaidRoleId, SignUpType.Maybe);
|
|
||||||
}
|
}
|
||||||
_raid = RaidService.GetRaid(_raid.RaidId);
|
_raid = RaidService.GetRaid(_raid.RaidId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
@page "/raidoverview"
|
@page "/raidoverview"
|
||||||
@using Lieb.Data
|
@using Lieb.Data
|
||||||
|
@using System.Security.Claims
|
||||||
|
@using Lieb.Models
|
||||||
|
@using Lieb.Models.GuildWars2.Raid
|
||||||
@inject RaidService RaidService
|
@inject RaidService RaidService
|
||||||
|
@inject UserService UserService
|
||||||
|
@inject AuthenticationStateProvider AuthenticationStateProvider
|
||||||
|
|
||||||
|
|
||||||
<h3>RaidOverview</h3>
|
<h3>RaidOverview</h3>
|
||||||
|
@ -15,19 +20,28 @@
|
||||||
</AuthorizeView>
|
</AuthorizeView>
|
||||||
|
|
||||||
|
|
||||||
@foreach (var raid in raids) {
|
@foreach (var raid in _raids) {
|
||||||
<br />
|
<br />
|
||||||
<RaidDetails _raid=@raid />
|
<RaidDetails _raid=@raid _user=@_user/>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@code
|
@code
|
||||||
{
|
{
|
||||||
private List<Models.GuildWars2.Raid.Raid> raids;
|
private List<Raid> _raids;
|
||||||
|
private LiebUser? _user;
|
||||||
|
|
||||||
protected override async Task OnInitializedAsync()
|
protected override async Task OnInitializedAsync()
|
||||||
{
|
{
|
||||||
raids = RaidService.GetRaids();
|
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
||||||
|
|
||||||
|
if (authState.User.Identity.IsAuthenticated)
|
||||||
|
{
|
||||||
|
ulong discordId = ulong.Parse(authState.User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value);
|
||||||
|
_user = UserService.GetLiebUserSmall(discordId);
|
||||||
|
}
|
||||||
|
|
||||||
|
_raids = RaidService.GetRaids();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue