IW4M-Admin/WebfrontCore/ViewComponents/TopPlayersViewComponent.cs

36 lines
1.2 KiB
C#
Raw Normal View History

using System.Linq;
using System.Threading.Tasks;
using IW4MAdmin.Plugins.Stats;
using IW4MAdmin.Plugins.Stats.Helpers;
using Microsoft.AspNetCore.Mvc;
using Stats.Config;
namespace WebfrontCore.ViewComponents
{
public class TopPlayersViewComponent : ViewComponent
{
2022-01-28 18:28:49 -05:00
private readonly StatsConfiguration _config;
2022-01-28 18:28:49 -05:00
public TopPlayersViewComponent(StatsConfiguration config)
{
2022-01-28 18:28:49 -05:00
_config = config;
}
2022-04-19 19:43:58 -04:00
public async Task<IViewComponentResult> InvokeAsync(int count, int offset, string serverEndpoint = null)
{
2022-04-19 19:43:58 -04:00
var server = Plugin.ServerManager.GetServers()
.FirstOrDefault(server => server.ToString() == serverEndpoint);
2022-04-19 19:43:58 -04:00
var serverId = server is null ? (long?)null : StatManager.GetIdForServer(server);
2022-01-28 18:28:49 -05:00
ViewBag.UseNewStats = _config?.EnableAdvancedMetrics ?? true;
2022-04-19 19:43:58 -04:00
ViewBag.SelectedServerName = server?.Hostname;
return View("~/Views/Client/Statistics/Components/TopPlayers/_List.cshtml",
ViewBag.UseNewStats
? await Plugin.Manager.GetNewTopStats(offset, count, serverId)
: await Plugin.Manager.GetTopStats(offset, count, serverId));
}
}
}