180 lines
No EOL
6.7 KiB
Text
180 lines
No EOL
6.7 KiB
Text
@page "/gw2accountedit"
|
|
@page "/gw2accountedit/{gw2Id}"
|
|
@using Lieb.Data
|
|
@using Lieb.Models
|
|
@using Lieb.Models.GuildWars2
|
|
@using System.ComponentModel.DataAnnotations
|
|
@using System.Security.Claims
|
|
@inject GuildWars2AccountService GuildWars2AccountService
|
|
@inject GuildWars2BuildService GuildWars2BuildService
|
|
@inject UserService UserService
|
|
@inject NavigationManager NavigationManager
|
|
@inject AuthenticationStateProvider AuthenticationStateProvider
|
|
@inject IJSRuntime JsRuntime
|
|
|
|
<h3>Manage Guild Wars 2 Account</h3>
|
|
|
|
<AuthorizeView Context="authorizationContext">
|
|
<Authorized>
|
|
<EditForm Model="@_account" OnValidSubmit="@HandleValidSubmit">
|
|
<DataAnnotationsValidator />
|
|
|
|
<p>@_saveMessage</p>
|
|
<p>
|
|
<label>
|
|
Account name:
|
|
<InputText @bind-Value="_account.AccountName" />
|
|
</label>
|
|
</p>
|
|
<!--<p>
|
|
<label>
|
|
Api-Key:
|
|
<InputText @bind-Value="_account.ApiKey" />
|
|
</label>
|
|
</p>-->
|
|
|
|
<br />
|
|
<button type="submit">Save</button>
|
|
<ValidationSummary />
|
|
|
|
</EditForm>
|
|
|
|
@if (_account.GuildWars2AccountId != 0)
|
|
{
|
|
<br />
|
|
<label>
|
|
Filter:
|
|
<select @onchange="args => ChangeBuildFilter(args)" >
|
|
<option value="All">All</option>
|
|
@foreach(GuildWars2Class gw2Class in Enum.GetValues(typeof(GuildWars2Class)))
|
|
{
|
|
<option value="@gw2Class">@gw2Class.ToString()</option>
|
|
}
|
|
</select>
|
|
</label>
|
|
<table class="roletable">
|
|
<tr>
|
|
<th>Equipped</th>
|
|
<th>Tank</th>
|
|
<th>Build</th>
|
|
<th>Class</th>
|
|
<th>Elite</th>
|
|
<th>Might</th>
|
|
<th>Heal</th>
|
|
<th>Quick</th>
|
|
<th>Alac</th>
|
|
</tr>
|
|
@foreach (GuildWars2Build build in _buildsToShow.OrderBy(b => b.Class).ThenBy(b => b.EliteSpecialization))
|
|
{
|
|
Equipped? equippedBuild = _account.EquippedBuilds.FirstOrDefault(e => e.GuildWars2BuildId == build.GuildWars2BuildId);
|
|
bool isEquipped = equippedBuild != null;
|
|
bool canTank = false;
|
|
if (isEquipped)
|
|
{
|
|
canTank = equippedBuild.CanTank;
|
|
}
|
|
|
|
<tr>
|
|
<td class="checkboxfield"><input type="checkbox" checked="@isEquipped" @onchange="args => EquippedStatusChanged(build.GuildWars2BuildId, args)" /></td>
|
|
<td class="checkboxfield"><input type="checkbox" checked="@canTank" disabled="@(!isEquipped)" @onchange="args => TankingStatusChanged(build.GuildWars2BuildId, args)" /></td>
|
|
<td>@build.BuildName</td>
|
|
<td>@build.Class.ToString()</td>
|
|
<td>@build.EliteSpecialization.ToString()</td>
|
|
<td class="checkboxfield"><input type="checkbox" checked="@(build.Might > 0)" disabled="disabled" /></td>
|
|
<td class="checkboxfield"><input type="checkbox" checked="@(build.Heal > 0)" disabled="disabled" /></td>
|
|
<td class="checkboxfield"><input type="checkbox" checked="@(build.Quickness > 0)" disabled="disabled" /></td>
|
|
<td class="checkboxfield"><input type="checkbox" checked="@(build.Alacrity > 0)" disabled="disabled" /></td>
|
|
</tr>
|
|
}
|
|
</table>
|
|
|
|
<br/>
|
|
<button type=button @onclick="() => DeleteAccountClicked()">Delete Account</button>
|
|
}
|
|
|
|
</Authorized>
|
|
</AuthorizeView>
|
|
|
|
|
|
@code {
|
|
|
|
[Parameter]
|
|
public string gw2Id { get; set; }
|
|
|
|
public GuildWars2Account _account;
|
|
|
|
private LiebUser _user;
|
|
|
|
private string _saveMessage = string.Empty;
|
|
|
|
private List<GuildWars2Build> _builds;
|
|
|
|
private List<GuildWars2Build> _buildsToShow;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
|
ulong discordId = ulong.Parse(authState.User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value);
|
|
_user = UserService.GetLiebUserGW2AccountOnly(discordId);
|
|
|
|
if(!string.IsNullOrEmpty(gw2Id) && int.TryParse(gw2Id, out int parsedId) && _user.GuildWars2Accounts.Where(a => a.GuildWars2AccountId == parsedId).Any())
|
|
{
|
|
_account = GuildWars2AccountService.GetAccount(parsedId);
|
|
}
|
|
else
|
|
{
|
|
_account = new GuildWars2Account();
|
|
}
|
|
_builds = GuildWars2BuildService.GetBuilds();
|
|
_buildsToShow = _builds;
|
|
}
|
|
|
|
async Task EquippedStatusChanged(int buildId, ChangeEventArgs args)
|
|
{
|
|
bool isEquipped = bool.Parse(args.Value.ToString());
|
|
if(isEquipped)
|
|
{
|
|
await GuildWars2AccountService.AddBuild(_account.GuildWars2AccountId, buildId);
|
|
}
|
|
else
|
|
{
|
|
await GuildWars2AccountService.RemoveBuild(_account.GuildWars2AccountId, buildId);
|
|
}
|
|
_account = GuildWars2AccountService.GetAccount(_account.GuildWars2AccountId);
|
|
}
|
|
|
|
async Task TankingStatusChanged(int buildId, ChangeEventArgs args)
|
|
{
|
|
bool canTank = bool.Parse(args.Value.ToString());
|
|
await GuildWars2AccountService.ChangeTankStatus(_account.GuildWars2AccountId, buildId, canTank);
|
|
}
|
|
|
|
async Task DeleteAccountClicked()
|
|
{
|
|
bool confirmed = await JsRuntime.InvokeAsync<bool>("confirm", "Are you sure you want to delete this Account?\nThis will sign you off in every raid in which you are signed up with this account.");
|
|
if (confirmed)
|
|
{
|
|
await GuildWars2AccountService.DeleteAccount(_account.GuildWars2AccountId);
|
|
NavigationManager.NavigateTo("accountedit");
|
|
}
|
|
}
|
|
|
|
private async Task HandleValidSubmit()
|
|
{
|
|
await GuildWars2AccountService.AddOrEditAccount(_account, _user.Id);
|
|
_account = GuildWars2AccountService.GetAccount(_account.GuildWars2AccountId);
|
|
_saveMessage = "changes saved successfully";
|
|
}
|
|
|
|
private void ChangeBuildFilter( ChangeEventArgs e)
|
|
{
|
|
if(Enum.TryParse<GuildWars2Class>(e.Value?.ToString(),out GuildWars2Class selectedClass))
|
|
{
|
|
_buildsToShow = _builds.Where(b => b.Class == selectedClass).ToList();
|
|
}
|
|
else
|
|
{
|
|
_buildsToShow = _builds;
|
|
}
|
|
}
|
|
} |