continue working on per servver topstats

This commit is contained in:
RaidMax 2019-02-26 21:25:27 -06:00
parent d318a57830
commit c21bf2ebf1
15 changed files with 96 additions and 55 deletions

View File

@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Authorization; using IW4MAdmin.Plugins.Stats.Helpers;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using SharedLibraryCore; using SharedLibraryCore;
@ -13,19 +14,43 @@ namespace IW4MAdmin.Plugins.Stats.Web.Controllers
public class StatsController : BaseController public class StatsController : BaseController
{ {
[HttpGet] [HttpGet]
public async Task<IActionResult> TopPlayersAsync() public IActionResult TopPlayersAsync()
{ {
ViewBag.Title = Utilities.CurrentLocalization.LocalizationIndex.Set["WEBFRONT_STATS_INDEX_TITLE"]; ViewBag.Title = Utilities.CurrentLocalization.LocalizationIndex.Set["WEBFRONT_STATS_INDEX_TITLE"];
ViewBag.Description = Utilities.CurrentLocalization.LocalizationIndex.Set["WEBFRONT_STATS_INDEX_DESC"]; ViewBag.Description = Utilities.CurrentLocalization.LocalizationIndex.Set["WEBFRONT_STATS_INDEX_DESC"];
ViewBag.Servers = Manager.GetServers().Select(_server => new ServerInfo() { Name = _server.Hostname, ID = _server.GetHashCode() }); ViewBag.Servers = Manager.GetServers().Select(_server => new ServerInfo() { Name = _server.Hostname, ID = _server.GetHashCode() });
return View("Index", await Plugin.Manager.GetTopStats(0, 50)); return View("Index");
} }
[HttpGet] [HttpGet]
public async Task<IActionResult> GetTopPlayersAsync(int count, int offset) public async Task<IActionResult> GetTopPlayersAsync(int count, int offset, long? serverId = null)
{ {
return View("_List", await Plugin.Manager.GetTopStats(offset, count)); // this prevents empty results when we really want aggregate
if (serverId == 0)
{
serverId = null;
}
var server = Manager.GetServers().FirstOrDefault(_server => _server.EndPoint == serverId);
if (server != null)
{
serverId = await StatManager.GetIdForServer(server);
}
var results = await Plugin.Manager.GetTopStats(offset, count, serverId);
// this returns an empty result so we know to stale the loader
if (results.Count == 0 && offset > 0)
{
return Ok();
}
else
{
return View("Components/TopPlayers/_List", results);
}
} }
[HttpGet] [HttpGet]
@ -40,7 +65,7 @@ namespace IW4MAdmin.Plugins.Stats.Web.Controllers
where message.ServerId == serverId where message.ServerId == serverId
where message.TimeSent >= whenLower where message.TimeSent >= whenLower
where message.TimeSent <= whenUpper where message.TimeSent <= whenUpper
select new SharedLibraryCore.Dtos.ChatInfo() select new ChatInfo()
{ {
ClientId = message.ClientId, ClientId = message.ClientId,
Message = message.Message, Message = message.Message,

View File

@ -18,6 +18,5 @@ namespace IW4MAdmin.Plugins.Stats.Web.Dtos
public int Deaths { get; set; } public int Deaths { get; set; }
public int RatingChange { get; set; } public int RatingChange { get; set; }
public List<double> PerformanceHistory { get; set; } public List<double> PerformanceHistory { get; set; }
public List<ServerInfo> Servers { get; set; }
} }
} }

View File

@ -82,13 +82,13 @@ namespace IW4MAdmin.Plugins.Stats.Helpers
} }
} }
public async Task<List<TopStatsInfo>> GetTopStats(int start, int count) public async Task<List<TopStatsInfo>> GetTopStats(int start, int count, long? serverId = null)
{ {
using (var context = new DatabaseContext(true)) using (var context = new DatabaseContext(true))
{ {
// setup the query for the clients within the given rating range // setup the query for the clients within the given rating range
var iqClientRatings = (from rating in context.Set<EFRating>() var iqClientRatings = (from rating in context.Set<EFRating>()
.Where(GetRankingFunc()) .Where(GetRankingFunc(serverId))
select new select new
{ {
rating.RatingHistory.ClientId, rating.RatingHistory.ClientId,
@ -113,7 +113,7 @@ namespace IW4MAdmin.Plugins.Stats.Helpers
var iqRatingInfo = from rating in context.Set<EFRating>() var iqRatingInfo = from rating in context.Set<EFRating>()
where clientIds.Contains(rating.RatingHistory.ClientId) where clientIds.Contains(rating.RatingHistory.ClientId)
where rating.ServerId == null where rating.ServerId == serverId
select new select new
{ {
rating.Ranking, rating.Ranking,

View File

@ -26,7 +26,7 @@ namespace IW4MAdmin.Plugins.Stats
public string Author => "RaidMax"; public string Author => "RaidMax";
public static StatManager Manager { get; private set; } public static StatManager Manager { get; private set; }
private IManager ServerManager; public static IManager ServerManager;
public static BaseConfigurationHandler<StatsConfiguration> Config { get; private set; } public static BaseConfigurationHandler<StatsConfiguration> Config { get; private set; }
public async Task OnEventAsync(GameEvent E, Server S) public async Task OnEventAsync(GameEvent E, Server S)

View File

@ -0,0 +1,28 @@
using IW4MAdmin.Plugins.Stats;
using IW4MAdmin.Plugins.Stats.Helpers;
using Microsoft.AspNetCore.Mvc;
using System.Linq;
using System.Threading.Tasks;
namespace Stats.ViewComponents
{
public class TopPlayersViewComponent : ViewComponent
{
public async Task<IViewComponentResult> InvokeAsync(int count, int offset, long? serverId = null)
{
if (serverId == 0)
{
serverId = null;
}
var server = Plugin.ServerManager.GetServers().FirstOrDefault(_server => _server.EndPoint == serverId);
if (server != null)
{
serverId = await StatManager.GetIdForServer(server);
}
return View("_List", await Plugin.Manager.GetTopStats(offset, count, serverId));
}
}
}

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor"> <Project Sdk="Microsoft.NET.Sdk.Razor">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework> <TargetFramework>netcoreapp2.2</TargetFramework>
<RazorCompileOnBuild>false</RazorCompileOnBuild> <RazorCompileOnBuild>true</RazorCompileOnBuild>
<RazorCompiledOnPublish>true</RazorCompiledOnPublish> <RazorCompiledOnPublish>true</RazorCompiledOnPublish>
<ResolvedRazorCompileToolset>RazorSdk</ResolvedRazorCompileToolset> <ResolvedRazorCompileToolset>RazorSdk</ResolvedRazorCompileToolset>
<Configurations>Debug;Release;Prerelease</Configurations> <Configurations>Debug;Release;Prerelease</Configurations>
@ -19,10 +19,6 @@
</ItemGroup> </ItemGroup>
<ItemGroup>
</ItemGroup>
<Target Name="PreBuild" BeforeTargets="PreBuildEvent"> <Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="xcopy /E /K /Y /C /I &quot;$(ProjectDir)wwwroot\images&quot; &quot;$(SolutionDir)WebfrontCore\wwwroot\images&quot;" /> <Exec Command="xcopy /E /K /Y /C /I &quot;$(ProjectDir)wwwroot\images&quot; &quot;$(SolutionDir)WebfrontCore\wwwroot\images&quot;" />
</Target> </Target>

View File

@ -25,6 +25,10 @@
return "0_no-place/menu_div_no_place.png"; return "0_no-place/menu_div_no_place.png";
} }
} }
@if (Model.Count == 0)
{
<div class="p-2 text-center">@SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex.Set["PLUGINS_STATS_TEXT_NOQUALIFY"]</div>
}
@foreach (var stat in Model) @foreach (var stat in Model)
{ {
<div class="row ml-0 mr-0 pt-2 pb-2"> <div class="row ml-0 mr-0 pt-2 pb-2">

View File

@ -1,53 +1,34 @@
@model List<IW4MAdmin.Plugins.Stats.Web.Dtos.TopStatsInfo> <ul class="nav nav-tabs" role="tablist" id="stats_top_players">
<ul class="nav nav-tabs" role="tablist" id="stats_top_players">
<li class="nav-item"> <li class="nav-item">
<a class="nav-link active" href="#server_0" role="tab" data-toggle="tab" aria-selected="true">All Servers</a> <a class="nav-link active top-players-link" href="#server_0" role="tab" data-toggle="tab" aria-selected="true" data-serverid="0">All Servers</a>
</li> </li>
@foreach (var server in ViewBag.Servers) @foreach (var server in ViewBag.Servers)
{ {
<li class="nav-item"> <li class="nav-item ">
<a class="nav-link" href="#server_@server.ID" role="tab" data-toggle="tab" aria-selected="false">@server.Name</a> <a class="nav-link top-players-link" href="#server_@server.ID" role="tab" data-toggle="tab" aria-selected="false" data-serverid="@server.ID">@server.Name</a>
</li> </li>
} }
</ul> </ul>
<div class="tab-content striped border-bottom"> <div class="tab-content striped border-bottom">
<div role="tabpanel" class="tab-pane active" id="server_0"> <div role="tabpanel" class="tab-pane active" id="server_0">
@{ @await Component.InvokeAsync("TopPlayers", new { count = 50, offset = 0 })
if (Model.Count > 0)
{
await Html.PartialAsync("_List", Model);
}
else
{
<div class="p-2 text-center">@SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex.Set["PLUGINS_STATS_TEXT_NOQUALIFY"]</div>
}
}
</div> </div>
@foreach (var server in ViewBag.Servers) @foreach (var server in ViewBag.Servers)
{ {
<div role="tabpanel" class="tab-pane" id="server_@server.ID"> <div role="tabpanel" class="tab-pane" id="server_@server.ID">
@{ @await Component.InvokeAsync("TopPlayers", new { count = 50, offset = 0, serverId = server.ID })
if (Model.Count > 0)
{
await Html.PartialAsync("_List", Model);
}
else
{
<div class="p-2 text-center">@SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex.Set["PLUGINS_STATS_TEXT_NOQUALIFY"]</div>
}
}
</div> </div>
} }
</div> </div>
@section scripts { @section scripts
{
<environment include="Development"> <environment include="Development">
@*<script type="text/javascript" src="~/js/loader.js"></script> <script type="text/javascript" src="~/js/loader.js"></script>
<script type="text/javascript" src="~/js/stats.js"></script>*@ <script type="text/javascript" src="~/js/stats.js"></script>
</environment> </environment>
@*<script>initLoader('/Stats/GetTopPlayersAsync', '#stats_top_players', 50);</script>*@ <script>initLoader('/Stats/GetTopPlayersAsync', '#server_0', 50);</script>
} }

View File

@ -184,7 +184,7 @@ namespace WebfrontCore.Controllers
})); }));
} }
public async Task<IActionResult> GenerateLoginTokenForm() public IActionResult GenerateLoginTokenForm()
{ {
var info = new ActionInfo() var info = new ActionInfo()
{ {

View File

@ -12,7 +12,7 @@
</div> </div>
<div id="server_clientactivity_@Model.ID" class="bg-dark row server-activity pt-2 pb-2"> <div id="server_clientactivity_@Model.ID" class="bg-dark row server-activity pt-2 pb-2">
@Html.Partial("../Server/_ClientActivity", Model) @await Html.PartialAsync("../Server/_ClientActivity", Model)
</div> </div>
<div class="row server-history mb-4"> <div class="row server-history mb-4">

View File

@ -6,6 +6,6 @@
@{ @{
foreach (var penalty in Model) foreach (var penalty in Model)
{ {
Html.RenderPartial("_Penalty", penalty); await Html.RenderPartialAsync("_Penalty", penalty);
} }
} }

View File

@ -6,6 +6,6 @@
@{ @{
foreach (var s in Model) foreach (var s in Model)
{ {
Html.RenderPartial("../Server/_Server", s); await Html.RenderPartialAsync("../Server/_Server", s);
} }
} }

View File

@ -3,7 +3,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework> <TargetFramework>netcoreapp2.2</TargetFramework>
<RuntimeFrameworkVersion>2.2.2</RuntimeFrameworkVersion> <RuntimeFrameworkVersion>2.2.2</RuntimeFrameworkVersion>
<RazorCompileOnBuild>false</RazorCompileOnBuild> <RazorCompileOnBuild>true</RazorCompileOnBuild>
<RazorCompileOnPublish>true</RazorCompileOnPublish> <RazorCompileOnPublish>true</RazorCompileOnPublish>
<PreserveCompilationContext>true</PreserveCompilationContext> <PreserveCompilationContext>true</PreserveCompilationContext>
<TypeScriptToolsVersion>2.6</TypeScriptToolsVersion> <TypeScriptToolsVersion>2.6</TypeScriptToolsVersion>
@ -33,12 +33,20 @@
<Content Remove="bower.json" /> <Content Remove="bower.json" />
<Content Remove="bundleconfig.json" /> <Content Remove="bundleconfig.json" />
<Content Remove="compilerconfig.json" /> <Content Remove="compilerconfig.json" />
<Content Remove="Views\Plugins\Stats\Components\TopPlayers\_List.cshtml" />
<Content Remove="Views\Plugins\Stats\Index.cshtml" />
<Content Remove="Views\Plugins\Stats\_MessageContext.cshtml" />
<Content Remove="Views\Plugins\Stats\_PenaltyInfo.cshtml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="bower.json" /> <None Include="bower.json" />
<None Include="bundleconfig.json" /> <None Include="bundleconfig.json" />
<None Include="compilerconfig.json" /> <None Include="compilerconfig.json" />
<None Include="Views\Plugins\Stats\Components\TopPlayers\_List.cshtml" />
<None Include="Views\Plugins\Stats\Index.cshtml" />
<None Include="Views\Plugins\Stats\_MessageContext.cshtml" />
<None Include="Views\Plugins\Stats\_PenaltyInfo.cshtml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -64,10 +64,6 @@ if ($(loaderResponseId).length === 1) {
$window $window
.off('scroll', ScrollHandler) .off('scroll', ScrollHandler)
.on('scroll', ScrollHandler); .on('scroll', ScrollHandler);
/*$('#load_penalties_button').click(function () {
loadMorePenalties();
});*/
}); });
function ScrollHandler(e) { function ScrollHandler(e) {

View File

@ -72,6 +72,10 @@ $(document).ready(function () {
getStatsChart($(element).attr('id'), $(element).width(), $(element).height()).render(); getStatsChart($(element).attr('id'), $(element).width(), $(element).height()).render();
}); });
}); });
$('.top-players-link').click(function (event) {
initLoader('/Stats/GetTopPlayersAsync?serverId=' + $(this).data('serverid'), $(this).attr('href'), 50);
});
}); });
$(document).on("loaderFinished", function (event, response) { $(document).on("loaderFinished", function (event, response) {