reorganized Raid pages

This commit is contained in:
Sarah Faey 2022-11-16 22:23:53 +01:00
parent f40903851e
commit d0ff8251a2
16 changed files with 174 additions and 53 deletions

View file

@ -0,0 +1,71 @@
@using Lieb.Data
@using Lieb.Models
@using Lieb.Models.GuildWars2.Raid
@using SharedClasses.SharedModels
<p>
<label>
Discord Messages:
</label>
<button type=button @onclick="() => AddDiscordMessageClicked()">Add message</button>
<table>
<tr>
<th>Server</th>
<th>Channel</th>
</tr>
@foreach( DiscordRaidMessage message in _raid.DiscordRaidMessages)
{
bool disableEdit = message.DiscordRaidMessageId != 0;
<tr>
<td>
<InputSelect @bind-Value="message.DiscordGuildId" disabled="@disableEdit">
@foreach(DiscordServer item in _discordServers)
{
<option value="@item.Id">@item.Name</option>
}
</InputSelect>
</td>
<td>
<InputSelect @bind-Value="message.DiscordChannelId" disabled="@disableEdit">
@if(message.DiscordGuildId > 0)
{
List<DiscordChannel> channels = _discordServers.Where(s => s.Id == message.DiscordGuildId).FirstOrDefault(new DiscordServer()).Channels;
@foreach(DiscordChannel item in channels)
{
<option value="@item.Id">@item.Name</option>
}
}
</InputSelect>
</td>
<td><button type=button @onclick="() => DeleteMessageClicked(message)">Delete</button></td>
</tr>
}
</table>
</p>
@code {
[Parameter]
public Raid _raid { get; set; }
[Parameter]
public List<DiscordServer> _discordServers {get; set; }
[Parameter]
public List<DiscordRaidMessage> _messagesToDelete {get; set; }
async Task AddDiscordMessageClicked()
{
_raid.DiscordRaidMessages.Add(new DiscordRaidMessage());
}
async Task DeleteMessageClicked(DiscordRaidMessage message)
{
if(message.DiscordRaidMessageId != 0)
{
_messagesToDelete.Add(message);
}
_raid.DiscordRaidMessages.Remove(message);
}
}

View file

@ -0,0 +1,288 @@
@page "/raidedit"
@page "/raidedit/{raidId}"
@using Lieb.Data
@using Lieb.Models
@using Lieb.Models.GuildWars2.Raid
@using System.ComponentModel.DataAnnotations
@using System.Security.Claims
@using SharedClasses.SharedModels
@inject RaidService RaidService
@inject UserService UserService
@inject DiscordService DiscordService
@inject TimeZoneService TimeZoneService
@inject NavigationManager NavigationManager
@inject AuthenticationStateProvider AuthenticationStateProvider
@inject IJSRuntime JsRuntime
<h3>Create Raid</h3>
<AuthorizeView Policy="@Constants.Roles.RaidLead.Name" Context="authorizationContext">
<EditForm Model="@_raid" OnValidSubmit="@HandleValidSubmit">
<DataAnnotationsValidator />
@{
bool _isEdit = _raid.RaidId != 0;
}
<p>
<label>
Title:
<InputText @bind-Value="_raid.Title" />
</label>
</p>
<p>
<label>
Description:
<InputTextArea rows="8" style="width: 400px;" @bind-Value="_raid.Description" />
</label>
</p>
<p>
<label>
Raid Type:
<InputSelect @bind-Value="_raid.RaidType" disabled="@_isEdit">
<option value="@RaidType.Planned">Planned</option>
<option value="@RaidType.RandomWithBoons">Random with boons covered</option>
<option value="@RaidType.RandomClasses">Random classes</option>
<option value="@RaidType.RandomEliteSpecialization">Random elite specializations</option>
</InputSelect>
</label>
</p>
<p>
<label>
Date:
<InputDate @bind-Value="_raidDate" />
</label>
</p>
<p>
<label>
Start Time:
<input type="time" @bind="_startTime" />
</label>
</p>
<p>
<label>
End Time:
<input type="time" @bind="_endTime" />
</label>
</p>
<p>
<label>
Required Role:
<InputSelect @bind-Value="_raid.RequiredRole">
<option value="">Not Locked</option>
@foreach(LiebRole role in UserService.GetLiebRoles())
{
if (role.Type != RoleType.SystemRole)
{
<option value="@role.RoleName">@role.RoleName</option>
}
}
</InputSelect>
</label>
</p>
<p>
<label>
Free for all date:
<InputDate @bind-Value="_freeForAllDate" />
</label>
</p>
<p>
<label>
Free for all time:
<input type="time" @bind="_freeForAllTime" />
</label>
</p>
<p>
<label>
Organizer:
<InputText @bind-Value="_raid.Organizer" />
</label>
</p>
<p>
<label>
Guild:
<InputText @bind-Value="_raid.Guild" />
</label>
</p>
<p>
<label>
Voice chat:
<InputText @bind-Value="_raid.VoiceChat" />
</label>
</p>
@if(_raid.RaidType == RaidType.Planned)
{
<p>
<label>
Roles:
</label>
<button type=button @onclick="() => AddRoleClicked()">Add role</button>
<table>
<tr>
<th>Spots</th>
<th>Role name</th>
<th>Description</th>
</tr>
@foreach( RaidRole role in _raid.Roles)
{
bool disableEdit = _raid.SignUps.Where(s => s.RaidRoleId == role.RaidRoleId).Any();
<tr>
<td><InputNumber @bind-Value="role.Spots" disabled="@disableEdit" /></td>
<td><InputText @bind-Value="role.Name" disabled="@disableEdit" /></td>
<td><InputText @bind-Value="role.Description" disabled="@disableEdit" /></td>
@if(!disableEdit)
{
<td><button type=button @onclick="() => DeleteRoleClicked(role)">Delete</button></td>
}
</tr>
}
</table>
</p>
}
<DiscordMessageEdit _raid=@_raid _discordServers=@_discordServers _messagesToDelete=@_messagesToDelete ></DiscordMessageEdit>
<ReminderEdit _raid=@_raid _discordServers=@_discordServers _remindersToDelete=@_remindersToDelete ></ReminderEdit>
<ValidationSummary />
<label class="validation-message" >@_errorMessage</label>
<button type="submit">Submit</button>
</EditForm>
<br/>
<button type=button @onclick="() => DeleteRaidClicked()">Delete Raid</button>
</AuthorizeView>
@code {
[Parameter]
public string raidId { get; set; }
public Raid _raid;
private LiebUser _user;
private string _errorMessage = string.Empty;
private DateTimeOffset _raidDate = DateTime.Now.Date;
private DateTimeOffset _startTime;
private DateTimeOffset _endTime;
private DateTimeOffset _freeForAllDate = DateTime.Now.Date;
private DateTimeOffset _freeForAllTime;
private List<RaidRole> _rolesToDelete = new List<RaidRole>();
private List<RaidReminder> _remindersToDelete = new List<RaidReminder>();
private List<DiscordRaidMessage> _messagesToDelete = new List<DiscordRaidMessage>();
private List<DiscordServer> _discordServers = new List<DiscordServer>();
protected override async Task OnInitializedAsync()
{
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
if (authState != null)
{
ulong discordId = ulong.Parse(authState.User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value);
_user = UserService.GetLiebUser(discordId);
}
if(_user == null)
{
NavigationManager.NavigateTo("");
}
if(!string.IsNullOrEmpty(raidId) && int.TryParse(raidId, out int parsedId))
{
_raid = RaidService.GetRaid(parsedId);
if (_raid.RaidOwnerId == _user.Id
|| _user.RoleAssignments.Max(a => a.LiebRole.Level) >= Constants.RaidEditPowerLevel)
{
_startTime = await TimeZoneService.GetLocalDateTime(_raid.StartTimeUTC);
_endTime = await TimeZoneService.GetLocalDateTime(_raid.EndTimeUTC);
_raidDate = _startTime.Date;
_freeForAllTime = await TimeZoneService.GetLocalDateTime(_raid.FreeForAllTimeUTC);
_freeForAllDate = _freeForAllTime.Date;
}
else
{
_raid = new Raid();
}
}
else
{
_raid = new Raid();
}
_discordServers = await DiscordService.GetServers();
}
async Task AddRoleClicked()
{
_raid.Roles.Add(new RaidRole());
}
async Task DeleteRoleClicked(RaidRole role)
{
if(role.RaidRoleId != 0)
{
_rolesToDelete.Add(role);
}
_raid.Roles.Remove(role);
}
async Task DeleteRaidClicked()
{
bool confirmed = await JsRuntime.InvokeAsync<bool>("confirm", "Are you sure you want to delete the raid?");
if (confirmed)
{
await RaidService.DeleteRaid(_raid.RaidId);
NavigationManager.NavigateTo("raidoverview");
}
}
private async Task HandleValidSubmit()
{
if(_raid.RaidType != RaidType.Planned)
{
if(!_raid.Roles.Where(r => r.IsRandomSignUpRole).Any())
{
_raid.Roles.Add(RaidService.CreateRandomSignUpRole(_raid.RaidType));
}
foreach(RaidRole role in _raid.Roles.Where(r => !r.IsRandomSignUpRole))
{
_rolesToDelete.Add(role);
}
}
if(_raid.Roles.Count == 0)
{
_errorMessage = "Roles are needed for a raid.";
return;
}
_raid.StartTimeUTC = await TimeZoneService.GetUTCDateTime(_raidDate.Date + _startTime.TimeOfDay);
if(_startTime.TimeOfDay <= _endTime.TimeOfDay)
{
_raid.EndTimeUTC = await TimeZoneService.GetUTCDateTime(_raidDate.Date + _endTime.TimeOfDay);
}
else
{
_raid.EndTimeUTC = await TimeZoneService.GetUTCDateTime(_raidDate.Date.AddDays(1) + _endTime.TimeOfDay);
}
_raid.FreeForAllTimeUTC = await TimeZoneService.GetUTCDateTime(_freeForAllDate.Date + _freeForAllTime.TimeOfDay);
if (_raid.RaidOwnerId == 0)
{
_raid.RaidOwnerId = _user.Id;
}
await RaidService.AddOrEditRaid(_raid, _rolesToDelete, _remindersToDelete, _messagesToDelete);
NavigationManager.NavigateTo("raidoverview");
}
}

View file

@ -0,0 +1,2 @@
body {
}

View file

@ -0,0 +1,299 @@
@page "/raidtemplateedit"
@page "/raidtemplateedit/{raidId}"
@using Lieb.Data
@using Lieb.Models
@using Lieb.Models.GuildWars2.Raid
@using System.ComponentModel.DataAnnotations
@using System.Security.Claims
@inject RaidTemplateService RaidTemplateService
@inject UserService UserService
@inject TimeZoneService TimeZoneService
@inject NavigationManager NavigationManager
@inject AuthenticationStateProvider AuthenticationStateProvider
@inject IJSRuntime JsRuntime
<h3>CreateRaid</h3>
<AuthorizeView Policy="@Constants.Roles.RaidLead.Name" Context="authorizationContext">
<EditForm Model="@_template" OnValidSubmit="@HandleValidSubmit">
<DataAnnotationsValidator />
@{
bool _isEdit = _template.RaidTemplateId != 0;
}
<p>
<label>
Title:
<InputText @bind-Value="_template.Title" />
</label>
</p>
<p>
<label>
Description:
<InputTextArea @bind-Value="_template.Description" />
</label>
</p>
<p>
<label>
Raid Type:
<InputSelect @bind-Value="_template.RaidType" disabled="@_isEdit">
<option value="@RaidType.Planned">Planned</option>
<option value="@RaidType.RandomWithBoons">Random with boons covered</option>
<option value="@RaidType.RandomClasses">Random classes</option>
<option value="@RaidType.RandomEliteSpecialization">Random elite specializations</option>
</InputSelect>
</label>
</p>
<p>
<label>
Date:
<InputDate @bind-Value="_raidDate" />
</label>
</p>
<p>
<label>
Start Time:
<input type="time" @bind="_startTime" />
</label>
</p>
<p>
<label>
End Time:
<input type="time" @bind="_endTime" />
</label>
</p>
<p>
<label>
Time Zone:
<InputSelect @bind-Value="_template.RequiredRole">
<option value="@_template.TimeZone">@_template.TimeZone</option>
@if(_userTimeZone != @_template.TimeZone)
{
<option value="@_userTimeZone">@_userTimeZone</option>
}
</InputSelect>
</label>
</p>
<p>
<label>
Required Role:
<InputSelect @bind-Value="_template.RequiredRole">
<option value="">Not Locked</option>
@foreach(LiebRole role in UserService.GetLiebRoles())
{
if (role.Type != RoleType.SystemRole)
{
<option value="@role.RoleName">@role.RoleName</option>
}
}
</InputSelect>
</label>
</p>
<p>
<label>
Free for all date:
<InputDate @bind-Value="_freeForAllDate" />
</label>
</p>
<p>
<label>
Free for all time:
<input type="time" @bind="_freeForAllTime" />
</label>
</p>
<p>
<label>
Organizer:
<InputText @bind-Value="_template.Organizer" />
</label>
</p>
<p>
<label>
Guild:
<InputText @bind-Value="_template.Guild" />
</label>
</p>
<p>
<label>
Voice chat:
<InputText @bind-Value="_template.VoiceChat" />
</label>
</p>
<p>
<label>
Interval in Days:
<InputNumber @bind-Value="_template.Interval" />
</label>
</p>
<p>
<label>
Create Days Before:
<InputNumber @bind-Value="_template.CreateDaysBefore" />
</label>
</p>
@if(_template.RaidType == RaidType.Planned)
{
<p>
<label>
Roles:
</label>
<button type=button @onclick="() => AddRoleClicked()">Add role</button>
<table>
<tr>
<th>Spots</th>
<th>Role name</th>
<th>Description</th>
</tr>
@foreach( RaidRole role in _template.Roles)
{
<tr>
<td><InputNumber @bind-Value="role.Spots" /></td>
<td><InputText @bind-Value="role.Name" /></td>
<td><InputText @bind-Value="role.Description" /></td>
<td><button type=button @onclick="() => DeleteRoleClicked(role)">Delete</button></td>
</tr>
}
</table>
</p>
}
<ValidationSummary />
<label class="validation-message" >@_errorMessage</label>
<button type="submit">Submit</button>
</EditForm>
<br/>
<button type=button @onclick="() => DeleteRaidClicked()">Delete Raid</button>
</AuthorizeView>
@code {
[Parameter]
public string raidId { get; set; }
public RaidTemplate _template;
private LiebUser _user;
private string _errorMessage = string.Empty;
private DateTimeOffset _raidDate = DateTime.Now.Date;
private DateTimeOffset _startTime;
private DateTimeOffset _endTime;
private DateTimeOffset _freeForAllDate = DateTime.Now.Date;
private DateTimeOffset _freeForAllTime;
private string _userTimeZone = string.Empty;
private List<RaidRole> _rolesToDelete = new List<RaidRole>();
protected override async Task OnInitializedAsync()
{
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
if (authState != null)
{
ulong discordId = ulong.Parse(authState.User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value);
_user = UserService.GetLiebUser(discordId);
}
if(_user == null)
{
NavigationManager.NavigateTo("");
}
if(!string.IsNullOrEmpty(raidId) && int.TryParse(raidId, out int parsedId))
{
_template = RaidTemplateService.GetTemplate(parsedId);
if (_template != null && (_template.RaidOwnerId == _user.Id
|| _user.RoleAssignments.Max(a => a.LiebRole.Level) >= Constants.RaidEditPowerLevel))
{
_startTime = _template.StartTime;
_endTime = _template.EndTime;
_raidDate = _startTime.Date;
_freeForAllTime = _template.FreeForAllTime;
_freeForAllDate = _freeForAllTime.Date;
}
else
{
_template = new RaidTemplate();
}
}
else
{
_template = new RaidTemplate();
}
_userTimeZone = await TimeZoneService.GetUserTimeZone();
}
async Task AddRoleClicked()
{
_template.Roles.Add(new RaidRole());
}
async Task DeleteRoleClicked(RaidRole role)
{
if(role.RaidRoleId != 0)
{
_rolesToDelete.Add(role);
}
_template.Roles.Remove(role);
}
async Task DeleteRaidClicked()
{
bool confirmed = await JsRuntime.InvokeAsync<bool>("confirm", "Are you sure you want to delete the raid?");
if (confirmed)
{
await RaidTemplateService.DeleteTemplate(_template.RaidTemplateId);
NavigationManager.NavigateTo("raidtemplateoverview");
}
}
private async Task HandleValidSubmit()
{
if(_template.RaidType != RaidType.Planned)
{
_template.Roles.Clear();
_template.Roles.Add(new RaidRole()
{
Spots = 10,
Name = "Random",
Description = _template.RaidType.ToString()
});
}
if(_template.Roles.Count == 0)
{
_errorMessage = "Roles are needed for a raid.";
return;
}
_template.TimeZone = await TimeZoneService.GetUserTimeZone();
_template.StartTime =_raidDate.Date + _startTime.TimeOfDay;
if(_startTime.TimeOfDay > _endTime.TimeOfDay)
{
_template.EndTime = _raidDate.Date + _endTime.TimeOfDay;
}
else
{
_template.EndTime = _raidDate.Date.AddDays(1) + _endTime.TimeOfDay;
}
_template.FreeForAllTime = _freeForAllDate.Date + _freeForAllTime.TimeOfDay;
if (_template.RaidOwnerId == 0)
{
_template.RaidOwnerId = _user.Id;
}
await RaidTemplateService.AddOrEditTemplate(_template, _rolesToDelete, new List<RaidReminder>());
NavigationManager.NavigateTo("raidtemplateoverview");
}
}

View file

@ -0,0 +1,100 @@
@using Lieb.Data
@using Lieb.Models
@using Lieb.Models.GuildWars2.Raid
@using SharedClasses.SharedModels
<p>
<label>
Raid Reminders:
</label>
<button type=button @onclick="() => AddReminderClicked()">Add reminder</button>
<table>
<tr>
<th>Time</th>
<th>Type</th>
@if(_raid.Reminders.Where(r => r.Type == RaidReminder.ReminderType.Channel).Any())
{
<th>Server</th>
<th>Channel</th>
}
else
{
<th></th>
<th></th>
}
<th>Message</th>
</tr>
@foreach( RaidReminder reminder in _raid.Reminders)
{
bool hidden = reminder.Type == RaidReminder.ReminderType.User;
<tr>
<td>
TODO: Time
</td>
<td>
<InputSelect @bind-Value="reminder.Type">
@foreach(RaidReminder.ReminderType type in Enum.GetValues(typeof(RaidReminder.ReminderType)))
{
<option value="@type">@type.ToString()</option>
}
</InputSelect>
</td>
<td>
<InputSelect @bind-Value="reminder.DiscordServerId" hidden="@hidden">
@foreach(DiscordServer item in _discordServers)
{
<option value="@item.Id">@item.Name</option>
}
</InputSelect>
</td>
<td>
<InputSelect @bind-Value="reminder.DiscordChannelId" hidden="@hidden">
@if(reminder.DiscordServerId > 0)
{
List<DiscordChannel> channels = _discordServers.Where(s => s.Id == reminder.DiscordServerId).FirstOrDefault(new DiscordServer()).Channels;
@foreach(DiscordChannel item in channels)
{
<option value="@item.Id">@item.Name</option>
}
}
</InputSelect>
</td>
<td>
<InputText @bind-Value="reminder.Message" />
</td>
<td><button type=button @onclick="() => DeleteReminderClicked(reminder)">Delete</button></td>
</tr>
}
</table>
</p>
@code {
[Parameter]
public Raid _raid { get; set; }
[Parameter]
public List<DiscordServer> _discordServers {get; set; }
[Parameter]
public List<RaidReminder> _remindersToDelete {get; set; }
async Task AddReminderClicked()
{
_raid.Reminders.Add(new RaidReminder()
{
RaidId = _raid.RaidId,
Type = RaidReminder.ReminderType.User
});
}
async Task DeleteReminderClicked(RaidReminder reminder)
{
if(reminder.RaidReminderId != 0)
{
_remindersToDelete.Add(reminder);
}
_raid.Reminders.Remove(reminder);
}
}