225 lines
9.6 KiB
Text
225 lines
9.6 KiB
Text
@using System.Security.Claims
|
|
@using Lieb.Data
|
|
@using Lieb.Models
|
|
@using Lieb.Models.GuildWars2.Raid
|
|
@inject UserService UserService
|
|
@inject RaidService RaidService
|
|
@inject RaidRandomizerService RaidRandomizerService
|
|
|
|
<body>
|
|
<h5>@_raid.Title</h5>
|
|
|
|
<div>@_raid.Description</div>
|
|
|
|
<div >
|
|
<div class="times">
|
|
<h5>Date</h5>
|
|
<p>@_raid.Date.ToLongDateString()</p>
|
|
</div>
|
|
<div class="times">
|
|
<h5>Time</h5>
|
|
<p>from: @_raid.StartTime.LocalDateTime.ToShortTimeString() to: @_raid.EndTime.LocalDateTime.ToShortTimeString()</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div>
|
|
<div class="details">
|
|
<h5>Organizer</h5>
|
|
<p>@_raid.Organizer</p>
|
|
</div>
|
|
<div class="details">
|
|
<h5>Guild</h5>
|
|
<p>@_raid.Guild</p>
|
|
</div>
|
|
<div class="details">
|
|
<h5>Voice chat</h5>
|
|
<p>@_raid.VoiceChat</p>
|
|
</div>
|
|
</div>
|
|
|
|
<AuthorizeView Policy="@Constants.Roles.User">
|
|
<Authorized>
|
|
@{
|
|
ulong discordId = ulong.Parse(@context.User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value);
|
|
LiebUser user = UserService.GetLiebUser(discordId);
|
|
RaidSignUp userRole = _raid.SignUps.Where(s => s.LiebUserId == user.LiebUserId).FirstOrDefault();
|
|
bool isSignedUp = userRole != null;
|
|
DateTime flexTime = _raid.FreeForAllDate.Date + _raid.FreeForAllTime.TimeOfDay;
|
|
bool isSignUoAllowed = !_raid.IsRandomized && (user.RoleAssignments.FirstOrDefault(a => a.LiebRole.RoleName == _raid.RequiredRole) != null || flexTime < DateTime.Now);
|
|
isSignedUp = isSignedUp && user.GuildWars2Accounts.Count > 0 && (_raid.RaidType == RaidType.Planned || user.GuildWars2Accounts.FirstOrDefault()?.EquippedBuilds.Count > 0);
|
|
|
|
<table class="table">
|
|
<tbody>
|
|
@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)
|
|
{
|
|
<tr>
|
|
@{bool isUser = isSignedUp && userRole.PlannedRaidRole.PlannedRaidRoleId == role.PlannedRaidRoleId && signUp.LiebUserId == user.LiebUserId;}
|
|
@if (isSignUoAllowed)
|
|
{
|
|
<td></td>
|
|
<td></td>
|
|
@if(isUser)
|
|
{
|
|
<td><button @onclick="() => SignOffClicked(role, user)">Sign Off</button></td>
|
|
}
|
|
else
|
|
{
|
|
<td></td>
|
|
}
|
|
}
|
|
@{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>
|
|
}
|
|
</Authorized>
|
|
<NotAuthorized>
|
|
<div>
|
|
<table class="table">
|
|
<tbody>
|
|
@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>
|
|
<td><h5>@role.Name: @role.Description (@usedSpots /@role.Spots)</h5></td>
|
|
</tr>
|
|
@foreach (var signUp in signUps)
|
|
{
|
|
if(signUp.SignUpType != SignUpType.SignedOff)
|
|
{
|
|
string signUpStatus = string.Empty;
|
|
if (signUp.SignUpType != SignUpType.SignedUp) signUpStatus = $" - {signUp.SignUpType}";
|
|
<tr>
|
|
<td>@signUp.LiebUser.Name (@signUp.GuildWars2Account.AccountName) @signUpStatus</td>
|
|
</tr>
|
|
}
|
|
}
|
|
}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</NotAuthorized>
|
|
</AuthorizeView>
|
|
<AuthorizeView Policy="@Constants.Roles.RaidLead">
|
|
<div class="nav-item px-3">
|
|
@{string navLink = $"raidedit/{_raid.RaidId}";}
|
|
<NavLink class="nav-link" href="@navLink">
|
|
<span class="oi oi-plus" aria-hidden="true"></span> Edit
|
|
</NavLink>
|
|
</div>
|
|
@if(_raid.RaidType != RaidType.Planned && !_raid.IsRandomized)
|
|
{
|
|
<button type=button @onclick="() => RandomizeClicked()">Randomize</button>
|
|
}
|
|
</AuthorizeView>
|
|
</body>
|
|
|
|
@code {
|
|
|
|
[Parameter]
|
|
public Raid _raid { get; set; }
|
|
|
|
async Task SignUpClicked(PlannedRaidRole role, LiebUser liebUser, bool isSignedUp)
|
|
{
|
|
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)
|
|
{
|
|
if(isSignedUp)
|
|
{
|
|
await RaidService.ChangeSignUpType(_raid.RaidId, liebUser.LiebUserId, role.PlannedRaidRoleId, SignUpType.Backup);
|
|
}
|
|
else
|
|
{
|
|
await RaidService.SignUp(_raid.RaidId, liebUser.LiebUserId, liebUser.GuildWars2Accounts.FirstOrDefault().GuildWars2AccountId, role.PlannedRaidRoleId, SignUpType.Backup);
|
|
}
|
|
_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);
|
|
}
|
|
|
|
async Task SignOffClicked(PlannedRaidRole role, LiebUser liebUser)
|
|
{
|
|
await RaidService.SignOff(_raid.RaidId, liebUser.LiebUserId, role.PlannedRaidRoleId);
|
|
_raid = RaidService.GetRaid(_raid.RaidId);
|
|
}
|
|
|
|
async Task RandomizeClicked()
|
|
{
|
|
await RaidRandomizerService.RandomizeRaid(_raid.RaidId);
|
|
_raid = RaidService.GetRaid(_raid.RaidId);
|
|
}
|
|
|
|
async Task ChangeAccount(LiebUser liebUser, ChangeEventArgs e)
|
|
{
|
|
int accountId = int.Parse(e.Value.ToString());
|
|
await RaidService.ChangeAccount(_raid.RaidId, liebUser.LiebUserId, accountId);
|
|
_raid = RaidService.GetRaid(_raid.RaidId);
|
|
}
|
|
}
|