forked from Sarah/Lieb-Website
added poll pages
This commit is contained in:
parent
6d6e720695
commit
1158aff6df
8 changed files with 340 additions and 14 deletions
179
Lieb/Pages/Poll/PollCreate.razor
Normal file
179
Lieb/Pages/Poll/PollCreate.razor
Normal file
|
@ -0,0 +1,179 @@
|
|||
@page "/pollcreate"
|
||||
@using Lieb.Data
|
||||
@using Lieb.Models
|
||||
@using Lieb.Models.Poll
|
||||
@using Lieb.Models.GuildWars2.Raid
|
||||
@using System.ComponentModel.DataAnnotations
|
||||
@using System.Security.Claims
|
||||
@using SharedClasses.SharedModels
|
||||
@inject RaidService RaidService
|
||||
@inject UserService UserService
|
||||
@inject PollService PollService
|
||||
@inject NavigationManager NavigationManager
|
||||
@inject AuthenticationStateProvider AuthenticationStateProvider
|
||||
@inject IJSRuntime JsRuntime
|
||||
|
||||
|
||||
<h3>Create Poll</h3>
|
||||
|
||||
<AuthorizeView Policy="@Constants.Roles.RaidLead.Name" Context="authorizationContext">
|
||||
<EditForm Model="@_poll" OnValidSubmit="@HandleValidSubmit">
|
||||
<DataAnnotationsValidator />
|
||||
<p>
|
||||
<label>
|
||||
Question:
|
||||
<InputText @bind-Value="_poll.Question" />
|
||||
</label>
|
||||
</p>
|
||||
<p>
|
||||
<label>
|
||||
Answer Type:
|
||||
<InputSelect @bind-Value="_poll.AnswerType">
|
||||
<option value="@AnswerType.Buttons">Buttons</option>
|
||||
<option value="@AnswerType.Dropdown">Dropdown</option>
|
||||
</InputSelect>
|
||||
</label>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label>
|
||||
Poll Type:
|
||||
<InputSelect @bind-Value="_pollType">
|
||||
<option value="@POLL_TYPE_RAID">Raid</option>
|
||||
<option value="@POLL_TYPE_GROUP">Group</option>
|
||||
</InputSelect>
|
||||
</label>
|
||||
</p>
|
||||
|
||||
@if(_pollType == POLL_TYPE_RAID)
|
||||
{
|
||||
<p>
|
||||
<label>
|
||||
Raid:
|
||||
<InputSelect @bind-Value="_chosenRaid">
|
||||
@foreach (Raid raid in _raids.OrderByDescending(r => r.StartTimeUTC))
|
||||
{
|
||||
string name = $"{raid.Title} - {raid.StartTimeUTC.DateTime.ToLongDateString()}";
|
||||
<option value="@raid.RaidId">@name</option>
|
||||
}
|
||||
</InputSelect>
|
||||
</label>
|
||||
</p>
|
||||
}
|
||||
else if(_pollType == POLL_TYPE_GROUP)
|
||||
{
|
||||
<p>
|
||||
<label>
|
||||
Raid:
|
||||
<InputSelect @bind-Value="_chosenRole">
|
||||
@foreach (LiebRole group in _availabeGroups)
|
||||
{
|
||||
<option value="@group.LiebRoleId">@group.RoleName</option>
|
||||
}
|
||||
</InputSelect>
|
||||
</label>
|
||||
</p>
|
||||
}
|
||||
|
||||
<p>
|
||||
<label>
|
||||
<InputCheckbox @bind-Value="_poll.AllowCustomAnswer" />
|
||||
Allow custom answers
|
||||
</label>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label>
|
||||
Options:
|
||||
</label>
|
||||
<button type=button @onclick="() => AddOptionClicked()">Add option</button>
|
||||
<table>
|
||||
<tr>
|
||||
<th>Option</th>
|
||||
</tr>
|
||||
@foreach(PollOption option in _poll.Options)
|
||||
{
|
||||
<tr>
|
||||
<td><InputText @bind-Value="option.Name" /></td>
|
||||
<td><button type=button @onclick="() => DeleteOptionClicked(option)">Delete</button></td>
|
||||
</tr>
|
||||
}
|
||||
</table>
|
||||
</p>
|
||||
|
||||
|
||||
<ValidationSummary />
|
||||
<label class="validation-message" >@_errorMessage</label>
|
||||
<button type="submit">Submit</button>
|
||||
|
||||
</EditForm>
|
||||
</AuthorizeView>
|
||||
|
||||
@code {
|
||||
|
||||
public Poll _poll = new Poll();
|
||||
private LiebUser _user;
|
||||
|
||||
private string _errorMessage = string.Empty;
|
||||
|
||||
private List<Raid> _raids = new List<Raid>();
|
||||
private List<LiebRole> _availabeGroups = new List<LiebRole>();
|
||||
|
||||
private const string POLL_TYPE_RAID = "raid";
|
||||
private const string POLL_TYPE_GROUP = "group";
|
||||
private string _pollType = POLL_TYPE_RAID;
|
||||
|
||||
private int _chosenRaid;
|
||||
private int _chosenRole;
|
||||
|
||||
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("");
|
||||
}
|
||||
|
||||
_raids = RaidService.GetRaids();
|
||||
_chosenRaid = _raids.OrderByDescending(r => r.StartTimeUTC).First().RaidId;
|
||||
if(_user.RoleAssignments.Where(r => r.LiebRole.Level >= Constants.Roles.Admin.PowerLevel).Any())
|
||||
{
|
||||
_availabeGroups = UserService.GetLiebRoles().Where(u => u.Type == RoleType.UserDefinedRole).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
_availabeGroups = UserService.GetUserRoles(_user.Id).Where(u => u.Type == RoleType.UserDefinedRole).ToList();
|
||||
}
|
||||
_chosenRole = _availabeGroups.First().LiebRoleId;
|
||||
}
|
||||
|
||||
async Task AddOptionClicked()
|
||||
{
|
||||
_poll.Options.Add(new PollOption());
|
||||
}
|
||||
|
||||
|
||||
async Task DeleteOptionClicked(PollOption option)
|
||||
{
|
||||
_poll.Options.Remove(option);
|
||||
}
|
||||
|
||||
private async Task HandleValidSubmit()
|
||||
{
|
||||
if(_pollType == POLL_TYPE_RAID)
|
||||
{
|
||||
await PollService.CreatePoll(_poll, _chosenRaid);
|
||||
}
|
||||
else if(_pollType == POLL_TYPE_GROUP)
|
||||
{
|
||||
await PollService.CreatePoll(_poll, UserService.GetGroupMembers(_chosenRole).Select(u => u.Id).ToList());
|
||||
}
|
||||
|
||||
NavigationManager.NavigateTo("raidoverview");
|
||||
}
|
||||
}
|
51
Lieb/Pages/Poll/PollDetails.razor
Normal file
51
Lieb/Pages/Poll/PollDetails.razor
Normal file
|
@ -0,0 +1,51 @@
|
|||
@using System.Security.Claims
|
||||
@using Lieb.Data
|
||||
@using Lieb.Models
|
||||
@using Lieb.Models.Poll
|
||||
@using Lieb.Models.GuildWars2.Raid
|
||||
@inject UserService UserService
|
||||
@inject RaidService RaidService
|
||||
@inject TimeZoneService TimeZoneService
|
||||
@inject RaidRandomizerService RaidRandomizerService
|
||||
@inject NavigationManager NavigationManager
|
||||
|
||||
<body>
|
||||
|
||||
<div @onclick="() => _isCollapsed = !_isCollapsed">
|
||||
|
||||
<h5>@_poll.Question</h5>
|
||||
@if(_raid != null)
|
||||
{
|
||||
<p>@_raid.Title - @_raid.StartTimeUTC.DateTime.ToLongDateString()</p>
|
||||
}
|
||||
</div>
|
||||
|
||||
@if (!_isCollapsed)
|
||||
{
|
||||
@foreach(var answer in _poll.Answers.GroupBy(a => a.Answer))
|
||||
{
|
||||
<p>@answer.Key - @answer.Count() </p>
|
||||
}
|
||||
}
|
||||
</body>
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
public Poll _poll { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public LiebUser? _user { get; set; }
|
||||
|
||||
public Raid _raid { get; set; }
|
||||
|
||||
bool _isCollapsed = true;
|
||||
|
||||
protected override async Task OnParametersSetAsync()
|
||||
{
|
||||
if(_poll.RaidId.HasValue)
|
||||
{
|
||||
_raid = RaidService.GetRaid(_poll.RaidId.Value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
12
Lieb/Pages/Poll/PollDetails.razor.css
Normal file
12
Lieb/Pages/Poll/PollDetails.razor.css
Normal file
|
@ -0,0 +1,12 @@
|
|||
body {
|
||||
background-color: rgb(38 38 38);
|
||||
border-radius: 25px;
|
||||
padding: 25px;
|
||||
/*width: 900px;*/
|
||||
width: stretch;
|
||||
color: lightgrey;
|
||||
}
|
||||
|
||||
h5 {
|
||||
color: lightgrey;
|
||||
}
|
47
Lieb/Pages/Poll/PollOverview.razor
Normal file
47
Lieb/Pages/Poll/PollOverview.razor
Normal file
|
@ -0,0 +1,47 @@
|
|||
@page "/polloverview"
|
||||
@using Lieb.Data
|
||||
@using System.Security.Claims
|
||||
@using Lieb.Models
|
||||
@using Lieb.Models.Poll
|
||||
@using Lieb.Models.GuildWars2.Raid
|
||||
@inject PollService PollService
|
||||
@inject UserService UserService
|
||||
@inject AuthenticationStateProvider AuthenticationStateProvider
|
||||
|
||||
|
||||
<h3>Event Overview</h3>
|
||||
|
||||
|
||||
<AuthorizeView Policy="@Constants.Roles.RaidLead.Name">
|
||||
<div class="nav-item px-3">
|
||||
<NavLink class="nav-link" href="pollcreate">
|
||||
<span class="oi oi-plus" aria-hidden="true"></span> Add Event
|
||||
</NavLink>
|
||||
</div>
|
||||
<br />
|
||||
@foreach (var poll in _polls.OrderByDescending(p => p.PollId))
|
||||
{
|
||||
<br />
|
||||
<PollDetails _poll=@poll _user=@_user/>
|
||||
}
|
||||
</AuthorizeView>
|
||||
|
||||
@code
|
||||
{
|
||||
private List<Poll> _polls;
|
||||
|
||||
private LiebUser? _user;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
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.GetLiebUser(discordId);
|
||||
}
|
||||
|
||||
_polls = PollService.GetPolls();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue