Merge pull request #113 from RaidMax/enhancement/issue-112-toggle-automated-penalties-webfront

allow toggle of automated penalties display on the webfront
This commit is contained in:
RaidMax 2020-02-12 13:16:11 -06:00 committed by GitHub
commit 68490bde57
9 changed files with 134 additions and 36 deletions

View File

@ -1,4 +1,5 @@
using Jint; using Jint;
using Microsoft.CSharp.RuntimeBinder;
using SharedLibraryCore; using SharedLibraryCore;
using SharedLibraryCore.Database.Models; using SharedLibraryCore.Database.Models;
using SharedLibraryCore.Interfaces; using SharedLibraryCore.Interfaces;
@ -100,19 +101,20 @@ namespace IW4MAdmin.Application.Misc
Name = pluginObject.name; Name = pluginObject.name;
Version = (float)pluginObject.version; Version = (float)pluginObject.version;
await OnLoadAsync(manager);
try try
{ {
if (pluginObject.isParser) if (pluginObject.isParser)
{ {
await OnLoadAsync(manager);
IEventParser eventParser = (IEventParser)_scriptEngine.GetValue("eventParser").ToObject(); IEventParser eventParser = (IEventParser)_scriptEngine.GetValue("eventParser").ToObject();
IRConParser rconParser = (IRConParser)_scriptEngine.GetValue("rconParser").ToObject(); IRConParser rconParser = (IRConParser)_scriptEngine.GetValue("rconParser").ToObject();
manager.AdditionalEventParsers.Add(eventParser); manager.AdditionalEventParsers.Add(eventParser);
manager.AdditionalRConParsers.Add(rconParser); manager.AdditionalRConParsers.Add(rconParser);
} }
} }
catch { }
catch (RuntimeBinderException) { }
if (!firstRun) if (!firstRun)
{ {

View File

@ -62,12 +62,13 @@ namespace SharedLibraryCore.Services
throw new NotImplementedException(); throw new NotImplementedException();
} }
public async Task<IList<PenaltyInfo>> GetRecentPenalties(int count, int offset, EFPenalty.PenaltyType showOnly = EFPenalty.PenaltyType.Any) public async Task<IList<PenaltyInfo>> GetRecentPenalties(int count, int offset, EFPenalty.PenaltyType showOnly = EFPenalty.PenaltyType.Any, bool ignoreAutomated = true)
{ {
using (var context = new DatabaseContext(true)) using (var context = new DatabaseContext(true))
{ {
var iqPenalties = context.Penalties var iqPenalties = context.Penalties
.Where(p => showOnly == EFPenalty.PenaltyType.Any ? p.Type != EFPenalty.PenaltyType.Any : p.Type == showOnly) .Where(p => showOnly == EFPenalty.PenaltyType.Any ? p.Type != EFPenalty.PenaltyType.Any : p.Type == showOnly)
.Where(_penalty => ignoreAutomated ? _penalty.PunisherId != 1 : true)
.OrderByDescending(p => p.When) .OrderByDescending(p => p.When)
.Skip(offset) .Skip(offset)
.Take(count) .Take(count)

View File

@ -18,21 +18,23 @@ namespace WebfrontCore.Controllers
} }
public IActionResult List(PenaltyType showOnly = PenaltyType.Any) public IActionResult List(PenaltyType showOnly = PenaltyType.Any, bool hideAutomatedPenalties = true)
{ {
ViewBag.Description = "List of all the recent penalties (bans, kicks, warnings) on IW4MAdmin"; ViewBag.Description = "List of all the recent penalties (bans, kicks, warnings) on IW4MAdmin";
ViewBag.Title = Localization["WEBFRONT_PENALTY_TITLE"]; ViewBag.Title = Localization["WEBFRONT_PENALTY_TITLE"];
ViewBag.Keywords = "IW4MAdmin, penalties, ban, kick, warns"; ViewBag.Keywords = "IW4MAdmin, penalties, ban, kick, warns";
ViewBag.HideAutomatedPenalties = hideAutomatedPenalties;
return View(showOnly); return View(showOnly);
} }
public async Task<IActionResult> ListAsync(int offset = 0, PenaltyType showOnly = PenaltyType.Any) public async Task<IActionResult> ListAsync(int offset = 0, PenaltyType showOnly = PenaltyType.Any, bool hideAutomatedPenalties = true)
{ {
return await Task.FromResult(View("_List", new ViewModels.PenaltyFilterInfo() return await Task.FromResult(View("_List", new ViewModels.PenaltyFilterInfo()
{ {
Offset = offset, Offset = offset,
ShowOnly = showOnly ShowOnly = showOnly,
IgnoreAutomated = hideAutomatedPenalties
})); }));
} }

View File

@ -9,9 +9,9 @@ namespace WebfrontCore.ViewComponents
{ {
private const int PENALTY_COUNT = 15; private const int PENALTY_COUNT = 15;
public async Task<IViewComponentResult> InvokeAsync(int offset, EFPenalty.PenaltyType showOnly) public async Task<IViewComponentResult> InvokeAsync(int offset, EFPenalty.PenaltyType showOnly, bool ignoreAutomated)
{ {
var penalties = await Program.Manager.GetPenaltyService().GetRecentPenalties(PENALTY_COUNT, offset, showOnly); var penalties = await Program.Manager.GetPenaltyService().GetRecentPenalties(PENALTY_COUNT, offset, showOnly, ignoreAutomated);
penalties = User.Identity.IsAuthenticated ? penalties : penalties.Where(p => !p.Sensitive).ToList(); penalties = User.Identity.IsAuthenticated ? penalties : penalties.Where(p => !p.Sensitive).ToList();
return View("_List", penalties); return View("_List", penalties);

View File

@ -2,9 +2,24 @@
namespace WebfrontCore.ViewModels namespace WebfrontCore.ViewModels
{ {
/// <summary>
/// helper class to determine the filters to apply to penalties
/// </summary>
public class PenaltyFilterInfo public class PenaltyFilterInfo
{ {
/// <summary>
/// number of items offset from the start of the list
/// </summary>
public int Offset { get; set; } public int Offset { get; set; }
/// <summary>
/// show only a certain type of penalty
/// </summary>
public PenaltyType ShowOnly { get; set; } public PenaltyType ShowOnly { get; set; }
/// <summary>
/// ignore penalties that are automated
/// </summary>
public bool IgnoreAutomated { get; set; }
} }
} }

View File

@ -4,35 +4,54 @@
} }
<h4 class="pb-3 text-center">@ViewBag.Title</h4> <h4 class="pb-3 text-center">@ViewBag.Title</h4>
<div class="row"> <div class="row">
<select class="form-control bg-dark text-muted" id="penalty_filter_selection"> <div class="d-block d-md-flex w-100 pb-2">
@{ <select class="form-control bg-dark text-muted" id="penalty_filter_selection">
foreach (var penaltyType in Enum.GetValues(typeof(SharedLibraryCore.Database.Models.EFPenalty.PenaltyType))) @{
{ foreach (var penaltyType in Enum.GetValues(typeof(SharedLibraryCore.Database.Models.EFPenalty.PenaltyType)))
if ((SharedLibraryCore.Database.Models.EFPenalty.PenaltyType)penaltyType == SharedLibraryCore.Database.Models.EFPenalty.PenaltyType.Any)
{ {
if (Model == SharedLibraryCore.Database.Models.EFPenalty.PenaltyType.Any) if ((SharedLibraryCore.Database.Models.EFPenalty.PenaltyType)penaltyType == SharedLibraryCore.Database.Models.EFPenalty.PenaltyType.Any)
{ {
<option value="@Convert.ToInt32(penaltyType)" selected="selected" )>@loc["WEBFRONT_PENALTY_TEMPLATE_SHOW"] @penaltyType.ToString()</option> if (Model == SharedLibraryCore.Database.Models.EFPenalty.PenaltyType.Any)
{
<option value="@Convert.ToInt32(penaltyType)" selected="selected" )>@loc["WEBFRONT_PENALTY_TEMPLATE_SHOW"] @penaltyType.ToString()</option>
}
else
{
<option value="@Convert.ToInt32(penaltyType)" )>@loc["WEBFRONT_PENALTY_TEMPLATE_SHOW"] @penaltyType.ToString()</option>
}
} }
else else
{ {
<option value="@Convert.ToInt32(penaltyType)" )>@loc["WEBFRONT_PENALTY_TEMPLATE_SHOW"] @penaltyType.ToString()</option> if ((SharedLibraryCore.Database.Models.EFPenalty.PenaltyType)penaltyType == Model)
} {
} <option value="@Convert.ToInt32(penaltyType)" selected="selected">@loc["WEBFRONT_PENALTY_TEMPLATE_SHOWONLY"] @penaltyType.ToString()s</option>
else }
{ else
if ((SharedLibraryCore.Database.Models.EFPenalty.PenaltyType)penaltyType == Model) {
{ <option value="@Convert.ToInt32(penaltyType)" )>@loc["WEBFRONT_PENALTY_TEMPLATE_SHOWONLY"] @penaltyType.ToString()s</option>
<option value="@Convert.ToInt32(penaltyType)" selected="selected">@loc["WEBFRONT_PENALTY_TEMPLATE_SHOWONLY"] @penaltyType.ToString()s</option> }
}
else
{
<option value="@Convert.ToInt32(penaltyType)" )>@loc["WEBFRONT_PENALTY_TEMPLATE_SHOWONLY"] @penaltyType.ToString()s</option>
} }
} }
} }
} </select>
</select> <div class="pl-md-2 pr-md-2 pt-2 pt-md-0">
<label class="toggle-switch">
@if (ViewBag.HideAutomatedPenalties)
{
<input type="checkbox" id="hide_automated_penalties_checkbox" checked="checked" />
}
else
{
<input type="checkbox" id="hide_automated_penalties_checkbox" />
}
<span class="toggle-switch-slider"></span>
</label>
</div>
<div class="align-self-center">
<span class="text-light text-nowrap">@loc["WEBFRONT_PENALTY_HIDE_AUTOMATED"]</span>
</div>
</div>
</div> </div>
<div class="row"> <div class="row">
<table class="table table-striped"> <table class="table table-striped">
@ -49,7 +68,8 @@
@await Component.InvokeAsync("PenaltyList", new WebfrontCore.ViewModels.PenaltyFilterInfo() @await Component.InvokeAsync("PenaltyList", new WebfrontCore.ViewModels.PenaltyFilterInfo()
{ {
Offset = 0, Offset = 0,
ShowOnly = Model ShowOnly = Model,
IgnoreAutomated = ViewBag.HideAutomatedPenalties
}) })
</tbody> </tbody>
</table> </table>

View File

@ -4,4 +4,4 @@
@model WebfrontCore.ViewModels.PenaltyFilterInfo @model WebfrontCore.ViewModels.PenaltyFilterInfo
@await Component.InvokeAsync("PenaltyList", new { offset = Model.Offset, showOnly = Model.ShowOnly }) @await Component.InvokeAsync("PenaltyList", new { offset = Model.Offset, showOnly = Model.ShowOnly, ignoreAutomated = Model.IgnoreAutomated })

View File

@ -112,7 +112,7 @@ form *, select {
border-left: none !important; border-left: none !important;
border-right: none !important; border-right: none !important;
border-bottom: none !important; border-bottom: none !important;
border-top: 2px solid $blue !important; border-top: 1px solid $text-muted;
} }
.oi-fix-navbar { .oi-fix-navbar {
@ -341,3 +341,53 @@ title {
color: #ff0000; color: #ff0000;
} }
} }
.toggle-switch input {
opacity: 0;
width: 0;
height: 0;
margin:0;
padding: 0;
}
label.toggle-switch {
margin: 0;
}
.toggle-switch {
position: relative;
height: calc(1.5em + 0.75rem + 2px);
width: 6rem;
border: 1px solid $text-muted;
}
.toggle-switch-slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: $dark;
-webkit-transition: .4s;
transition: .4s;
}
.toggle-switch-slider:before {
position: absolute;
content: "";
height: calc(1.5em + 0.75rem);
width: 3em;
background-color: $light;
-webkit-transition: 0.25s;
transition: 0.25s;
}
input:checked + .toggle-switch-slider {
background-color: $primary;
}
input:checked + .toggle-switch-slider:before {
-webkit-transform: translateX(3em);
-ms-transform: translateX(3em);
transform: translateX(3em);
}

View File

@ -23,7 +23,11 @@ function loadMorePenalties() {
showLoader(); showLoader();
isLoading = true; isLoading = true;
$.get('/Penalty/ListAsync', { offset: offset, showOnly : $('#penalty_filter_selection').val() }) $.get('/Penalty/ListAsync', {
offset: offset,
showOnly: $('#penalty_filter_selection').val(),
hideAutomatedPenalties: document.getElementById('hide_automated_penalties_checkbox').checked
})
.done(function (response) { .done(function (response) {
$('#penalty_table').append(response); $('#penalty_table').append(response);
if (response.trim().length === 0) { if (response.trim().length === 0) {
@ -40,9 +44,13 @@ function loadMorePenalties() {
} }
if ($('#penalty_table').length === 1) { if ($('#penalty_table').length === 1) {
$('#penalty_filter_selection').change(function() { $('#penalty_filter_selection').change(function () {
location = location.href.split('?')[0] + "?showOnly=" + $('#penalty_filter_selection').val(); location = location.href.split('?')[0] + "?showOnly=" + $('#penalty_filter_selection').val() + '&hideAutomatedPenalties=' + document.getElementById('hide_automated_penalties_checkbox').checked;
});
$('#hide_automated_penalties_checkbox').click(function () {
location = location.href.split('?')[0] + "?showOnly=" + $('#penalty_filter_selection').val() + '&hideAutomatedPenalties=' + document.getElementById('hide_automated_penalties_checkbox').checked;
}); });
/* /*