continue working on per servver topstats
This commit is contained in:
parent
d318a57830
commit
c21bf2ebf1
@ -1,4 +1,5 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using IW4MAdmin.Plugins.Stats.Helpers;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SharedLibraryCore;
|
||||
@ -13,19 +14,43 @@ namespace IW4MAdmin.Plugins.Stats.Web.Controllers
|
||||
public class StatsController : BaseController
|
||||
{
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> TopPlayersAsync()
|
||||
public IActionResult TopPlayersAsync()
|
||||
{
|
||||
ViewBag.Title = Utilities.CurrentLocalization.LocalizationIndex.Set["WEBFRONT_STATS_INDEX_TITLE"];
|
||||
ViewBag.Description = Utilities.CurrentLocalization.LocalizationIndex.Set["WEBFRONT_STATS_INDEX_DESC"];
|
||||
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]
|
||||
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]
|
||||
@ -40,7 +65,7 @@ namespace IW4MAdmin.Plugins.Stats.Web.Controllers
|
||||
where message.ServerId == serverId
|
||||
where message.TimeSent >= whenLower
|
||||
where message.TimeSent <= whenUpper
|
||||
select new SharedLibraryCore.Dtos.ChatInfo()
|
||||
select new ChatInfo()
|
||||
{
|
||||
ClientId = message.ClientId,
|
||||
Message = message.Message,
|
||||
|
@ -18,6 +18,5 @@ namespace IW4MAdmin.Plugins.Stats.Web.Dtos
|
||||
public int Deaths { get; set; }
|
||||
public int RatingChange { get; set; }
|
||||
public List<double> PerformanceHistory { get; set; }
|
||||
public List<ServerInfo> Servers { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -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))
|
||||
{
|
||||
// setup the query for the clients within the given rating range
|
||||
var iqClientRatings = (from rating in context.Set<EFRating>()
|
||||
.Where(GetRankingFunc())
|
||||
.Where(GetRankingFunc(serverId))
|
||||
select new
|
||||
{
|
||||
rating.RatingHistory.ClientId,
|
||||
@ -113,7 +113,7 @@ namespace IW4MAdmin.Plugins.Stats.Helpers
|
||||
|
||||
var iqRatingInfo = from rating in context.Set<EFRating>()
|
||||
where clientIds.Contains(rating.RatingHistory.ClientId)
|
||||
where rating.ServerId == null
|
||||
where rating.ServerId == serverId
|
||||
select new
|
||||
{
|
||||
rating.Ranking,
|
||||
|
@ -26,7 +26,7 @@ namespace IW4MAdmin.Plugins.Stats
|
||||
public string Author => "RaidMax";
|
||||
|
||||
public static StatManager Manager { get; private set; }
|
||||
private IManager ServerManager;
|
||||
public static IManager ServerManager;
|
||||
public static BaseConfigurationHandler<StatsConfiguration> Config { get; private set; }
|
||||
|
||||
public async Task OnEventAsync(GameEvent E, Server S)
|
||||
|
28
Plugins/Stats/ViewComponents/TopPlayersViewComponent.cs
Normal file
28
Plugins/Stats/ViewComponents/TopPlayersViewComponent.cs
Normal 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));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Razor">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.2</TargetFramework>
|
||||
<RazorCompileOnBuild>false</RazorCompileOnBuild>
|
||||
<RazorCompileOnBuild>true</RazorCompileOnBuild>
|
||||
<RazorCompiledOnPublish>true</RazorCompiledOnPublish>
|
||||
<ResolvedRazorCompileToolset>RazorSdk</ResolvedRazorCompileToolset>
|
||||
<Configurations>Debug;Release;Prerelease</Configurations>
|
||||
@ -19,10 +19,6 @@
|
||||
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
|
||||
<Exec Command="xcopy /E /K /Y /C /I "$(ProjectDir)wwwroot\images" "$(SolutionDir)WebfrontCore\wwwroot\images"" />
|
||||
</Target>
|
||||
|
@ -25,6 +25,10 @@
|
||||
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)
|
||||
{
|
||||
<div class="row ml-0 mr-0 pt-2 pb-2">
|
@ -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">
|
||||
<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>
|
||||
|
||||
@foreach (var server in ViewBag.Servers)
|
||||
{
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="#server_@server.ID" role="tab" data-toggle="tab" aria-selected="false">@server.Name</a>
|
||||
<li class="nav-item ">
|
||||
<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>
|
||||
}
|
||||
</ul>
|
||||
|
||||
<div class="tab-content striped border-bottom">
|
||||
<div role="tabpanel" class="tab-pane active" id="server_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>
|
||||
}
|
||||
}
|
||||
@await Component.InvokeAsync("TopPlayers", new { count = 50, offset = 0 })
|
||||
</div>
|
||||
|
||||
@foreach (var server in ViewBag.Servers)
|
||||
{
|
||||
<div role="tabpanel" class="tab-pane" id="server_@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>
|
||||
}
|
||||
}
|
||||
@await Component.InvokeAsync("TopPlayers", new { count = 50, offset = 0, serverId = server.ID })
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@section scripts {
|
||||
@section scripts
|
||||
{
|
||||
<environment include="Development">
|
||||
@*<script type="text/javascript" src="~/js/loader.js"></script>
|
||||
<script type="text/javascript" src="~/js/stats.js"></script>*@
|
||||
<script type="text/javascript" src="~/js/loader.js"></script>
|
||||
<script type="text/javascript" src="~/js/stats.js"></script>
|
||||
</environment>
|
||||
@*<script>initLoader('/Stats/GetTopPlayersAsync', '#stats_top_players', 50);</script>*@
|
||||
<script>initLoader('/Stats/GetTopPlayersAsync', '#server_0', 50);</script>
|
||||
}
|
||||
|
@ -184,7 +184,7 @@ namespace WebfrontCore.Controllers
|
||||
}));
|
||||
}
|
||||
|
||||
public async Task<IActionResult> GenerateLoginTokenForm()
|
||||
public IActionResult GenerateLoginTokenForm()
|
||||
{
|
||||
var info = new ActionInfo()
|
||||
{
|
||||
|
@ -12,7 +12,7 @@
|
||||
</div>
|
||||
|
||||
<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 class="row server-history mb-4">
|
||||
|
@ -6,6 +6,6 @@
|
||||
@{
|
||||
foreach (var penalty in Model)
|
||||
{
|
||||
Html.RenderPartial("_Penalty", penalty);
|
||||
await Html.RenderPartialAsync("_Penalty", penalty);
|
||||
}
|
||||
}
|
@ -6,6 +6,6 @@
|
||||
@{
|
||||
foreach (var s in Model)
|
||||
{
|
||||
Html.RenderPartial("../Server/_Server", s);
|
||||
await Html.RenderPartialAsync("../Server/_Server", s);
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.2</TargetFramework>
|
||||
<RuntimeFrameworkVersion>2.2.2</RuntimeFrameworkVersion>
|
||||
<RazorCompileOnBuild>false</RazorCompileOnBuild>
|
||||
<RazorCompileOnBuild>true</RazorCompileOnBuild>
|
||||
<RazorCompileOnPublish>true</RazorCompileOnPublish>
|
||||
<PreserveCompilationContext>true</PreserveCompilationContext>
|
||||
<TypeScriptToolsVersion>2.6</TypeScriptToolsVersion>
|
||||
@ -33,12 +33,20 @@
|
||||
<Content Remove="bower.json" />
|
||||
<Content Remove="bundleconfig.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>
|
||||
<None Include="bower.json" />
|
||||
<None Include="bundleconfig.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>
|
||||
|
@ -64,10 +64,6 @@ if ($(loaderResponseId).length === 1) {
|
||||
$window
|
||||
.off('scroll', ScrollHandler)
|
||||
.on('scroll', ScrollHandler);
|
||||
|
||||
/*$('#load_penalties_button').click(function () {
|
||||
loadMorePenalties();
|
||||
});*/
|
||||
});
|
||||
|
||||
function ScrollHandler(e) {
|
||||
|
@ -72,6 +72,10 @@ $(document).ready(function () {
|
||||
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) {
|
||||
|
Loading…
Reference in New Issue
Block a user