add sorting and zscore to scoreboard
This commit is contained in:
parent
16831aaccb
commit
d3962989b5
@ -58,11 +58,11 @@ namespace WebfrontCore.Controllers
|
|||||||
{
|
{
|
||||||
ViewBag.Title = Localization["WEBFRONT_TITLE_SCOREBOARD"];
|
ViewBag.Title = Localization["WEBFRONT_TITLE_SCOREBOARD"];
|
||||||
|
|
||||||
return View(ProjectScoreboard(Manager.GetServers()));
|
return View(ProjectScoreboard(Manager.GetServers(), null, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("[controller]/{id}/scoreboard")]
|
[HttpGet("[controller]/{id}/scoreboard")]
|
||||||
public ActionResult Scoreboard(long id)
|
public ActionResult Scoreboard(long id, [FromQuery]string order = null, [FromQuery] bool down = true)
|
||||||
{
|
{
|
||||||
var server = Manager.GetServers().FirstOrDefault(srv => srv.EndPoint == id);
|
var server = Manager.GetServers().FirstOrDefault(srv => srv.EndPoint == id);
|
||||||
|
|
||||||
@ -71,13 +71,16 @@ namespace WebfrontCore.Controllers
|
|||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
return View("_Scoreboard", ProjectScoreboard(new[] {server}).First());
|
return View("_Scoreboard", ProjectScoreboard(new[] {server}, order, down).First());
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerable<ScoreboardInfo> ProjectScoreboard(IEnumerable<Server> servers)
|
private static IEnumerable<ScoreboardInfo> ProjectScoreboard(IEnumerable<Server> servers, string order,
|
||||||
|
bool down)
|
||||||
{
|
{
|
||||||
return servers.Select(server => new ScoreboardInfo
|
return servers.Select(server => new ScoreboardInfo
|
||||||
{
|
{
|
||||||
|
OrderByKey = order,
|
||||||
|
ShouldOrderDescending = down,
|
||||||
MapName = server.CurrentMap.ToString(),
|
MapName = server.CurrentMap.ToString(),
|
||||||
ServerName = server.Hostname,
|
ServerName = server.Hostname,
|
||||||
ServerId = server.EndPoint,
|
ServerId = server.EndPoint,
|
||||||
@ -96,7 +99,8 @@ namespace WebfrontCore.Controllers
|
|||||||
Kills = clientData.stats?.MatchData?.Kills,
|
Kills = clientData.stats?.MatchData?.Kills,
|
||||||
Deaths = clientData.stats?.MatchData?.Deaths,
|
Deaths = clientData.stats?.MatchData?.Deaths,
|
||||||
ScorePerMinute = clientData.stats?.SessionSPM,
|
ScorePerMinute = clientData.stats?.SessionSPM,
|
||||||
Kdr = clientData.stats?.MatchData?.Kdr
|
Kdr = clientData.stats?.MatchData?.Kdr,
|
||||||
|
ZScore = clientData.stats?.ZScore
|
||||||
})
|
})
|
||||||
.ToList()
|
.ToList()
|
||||||
}).ToList();
|
}).ToList();
|
||||||
|
@ -8,6 +8,8 @@ namespace WebfrontCore.ViewModels
|
|||||||
public string ServerName { get; set; }
|
public string ServerName { get; set; }
|
||||||
public long ServerId { get; set; }
|
public long ServerId { get; set; }
|
||||||
public string MapName { get; set; }
|
public string MapName { get; set; }
|
||||||
|
public string OrderByKey { get; set; }
|
||||||
|
public bool ShouldOrderDescending { get; set; }
|
||||||
public List<ClientScoreboardInfo> ClientInfo { get; set; }
|
public List<ClientScoreboardInfo> ClientInfo { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,5 +23,6 @@ namespace WebfrontCore.ViewModels
|
|||||||
public int? Deaths { get; set; }
|
public int? Deaths { get; set; }
|
||||||
public double? ScorePerMinute { get; set; }
|
public double? ScorePerMinute { get; set; }
|
||||||
public double? Kdr { get; set; }
|
public double? Kdr { get; set; }
|
||||||
|
public double? ZScore { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,41 @@
|
|||||||
@model WebfrontCore.ViewModels.ScoreboardInfo
|
@using WebfrontCore.ViewModels
|
||||||
|
@model WebfrontCore.ViewModels.ScoreboardInfo
|
||||||
@{
|
@{
|
||||||
Layout = null;
|
Layout = null;
|
||||||
|
|
||||||
|
object OrderByFunc(ClientScoreboardInfo item)
|
||||||
|
{
|
||||||
|
var property = typeof(ClientScoreboardInfo).GetProperties().FirstOrDefault(prop =>
|
||||||
|
prop.CanRead && prop.Name.Equals(Model.OrderByKey, StringComparison.InvariantCultureIgnoreCase));
|
||||||
|
|
||||||
|
return property != null ? property.GetValue(item) : item.Score;
|
||||||
|
}
|
||||||
|
|
||||||
|
string GetColumnSortDisplay(string propertyName)
|
||||||
|
{
|
||||||
|
if (propertyName == Model.OrderByKey)
|
||||||
|
{
|
||||||
|
return Model.ShouldOrderDescending ? "<span class=\"oi oi-sort-ascending ml-2 align-middle\"></span>" : "<span class=\"oi oi-sort-descending ml-2 align-middle\"></span>";
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
<table class="table table-striped thead-light bg-dark mb-0 table-responsive-md">
|
<table class="table table-striped thead-light bg-dark mb-0 table-responsive-md table-sort"
|
||||||
|
data-sort-column="@Model.OrderByKey"
|
||||||
|
data-sort-down="@Model.ShouldOrderDescending.ToString().ToLower()">
|
||||||
<tr class="bg-dark border-bottom">
|
<tr class="bg-dark border-bottom">
|
||||||
<th>@ViewBag.Localization["WEBFRONT_SCOREBOARD_TABLE_PLAYER"]</th>
|
<th class="table-sort-column" data-column-name="@nameof(ClientScoreboardInfo.ClientName)">@ViewBag.Localization["WEBFRONT_SCOREBOARD_TABLE_PLAYER"]@Html.Raw(GetColumnSortDisplay(nameof(ClientScoreboardInfo.ClientName)))</th>
|
||||||
<th>@ViewBag.Localization["WEBFRONT_ADV_STATS_SCORE"]</th>
|
<th class="table-sort-column" data-column-name="@nameof(ClientScoreboardInfo.Score)">@ViewBag.Localization["WEBFRONT_ADV_STATS_SCORE"]@Html.Raw(GetColumnSortDisplay(nameof(ClientScoreboardInfo.Score)))</th>
|
||||||
<th>@ViewBag.Localization["WEBFRONT_ADV_STATS_KILLS"]</th>
|
<th class="table-sort-column" data-column-name="@nameof(ClientScoreboardInfo.Kills)">@ViewBag.Localization["WEBFRONT_ADV_STATS_KILLS"]@Html.Raw(GetColumnSortDisplay(nameof(ClientScoreboardInfo.Kills)))</th>
|
||||||
<th>@ViewBag.Localization["WEBFRONT_SCOREBOARD_TABLE_DEATHS"]</th>
|
<th class="table-sort-column" data-column-name="@nameof(ClientScoreboardInfo.Deaths)">@ViewBag.Localization["WEBFRONT_SCOREBOARD_TABLE_DEATHS"]@Html.Raw(GetColumnSortDisplay(nameof(ClientScoreboardInfo.Deaths)))</th>
|
||||||
<th>@ViewBag.Localization["WEBFRONT_SCOREBOARD_TABLE_RATIO"]</th>
|
<th class="table-sort-column" data-column-name="@nameof(ClientScoreboardInfo.Kdr)">@ViewBag.Localization["WEBFRONT_SCOREBOARD_TABLE_RATIO"]@Html.Raw(GetColumnSortDisplay(nameof(ClientScoreboardInfo.Kdr)))</th>
|
||||||
<th>@ViewBag.Localization["WEBFRONT_SCOREBOARD_TABLE_SPM"]</th>
|
<th class="table-sort-column" data-column-name="@nameof(ClientScoreboardInfo.ScorePerMinute)">@ViewBag.Localization["WEBFRONT_SCOREBOARD_TABLE_SPM"]@Html.Raw(GetColumnSortDisplay(nameof(ClientScoreboardInfo.ScorePerMinute)))</th>
|
||||||
<th class="text-right">@ViewBag.Localization["WEBFRONT_SCOREBOARD_TABLE_PING"]</th>
|
<th class="table-sort-column" data-column-name="@nameof(ClientScoreboardInfo.ZScore)">@ViewBag.Localization["WEBFRONT_ADV_STATS_ZSCORE"]@Html.Raw(GetColumnSortDisplay(nameof(ClientScoreboardInfo.ZScore)))</th>
|
||||||
|
<th class="text-right table-sort-column" data-column-name="@nameof(ClientScoreboardInfo.Ping)">@ViewBag.Localization["WEBFRONT_SCOREBOARD_TABLE_PING"]@Html.Raw(GetColumnSortDisplay(nameof(ClientScoreboardInfo.Ping)))</th>
|
||||||
</tr>
|
</tr>
|
||||||
@foreach (var client in Model.ClientInfo.OrderByDescending(c => c.Score))
|
@foreach (var client in Model.ShouldOrderDescending ? Model.ClientInfo.OrderByDescending(OrderByFunc) : Model.ClientInfo.OrderBy(OrderByFunc))
|
||||||
{
|
{
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
@ -26,6 +48,7 @@
|
|||||||
<td>@(client.Deaths ?? 0)</td>
|
<td>@(client.Deaths ?? 0)</td>
|
||||||
<td>@Math.Round(client.Kdr ?? 0, 2)</td>
|
<td>@Math.Round(client.Kdr ?? 0, 2)</td>
|
||||||
<td>@Math.Round(client.ScorePerMinute ?? 0)</td>
|
<td>@Math.Round(client.ScorePerMinute ?? 0)</td>
|
||||||
|
<td>@Math.Round(client.ZScore ?? 0)</td>
|
||||||
<td class="text-right">@client.Ping</td>
|
<td class="text-right">@client.Ping</td>
|
||||||
</tr>
|
</tr>
|
||||||
}
|
}
|
||||||
|
@ -197,7 +197,7 @@ form *, select, button.btn {
|
|||||||
font-size: 1rem;
|
font-size: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.oi {
|
.oi, .table-sort-column {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,14 +2,31 @@
|
|||||||
const serverPanel = $('.scoreboard-container.active');
|
const serverPanel = $('.scoreboard-container.active');
|
||||||
const serverId = $(serverPanel).data('server-id');
|
const serverId = $(serverPanel).data('server-id');
|
||||||
|
|
||||||
$.get(`../Server/${serverId}/Scoreboard`, (response) => {
|
const scoreboardTable = $(serverPanel).children('.table-sort');
|
||||||
|
|
||||||
|
$.get(`../Server/${serverId}/Scoreboard?order=${scoreboardTable.data('sort-column')}&down=${scoreboardTable.data('sort-down')}`, (response) => {
|
||||||
$(serverPanel).html(response);
|
$(serverPanel).html(response);
|
||||||
|
setupDataSorting();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
$(document).ready(() => {
|
$(document).ready(() => {
|
||||||
$(window.location.hash).tab('show');
|
$(window.location.hash).tab('show');
|
||||||
$(`${window.location.hash}_nav`).addClass('active');
|
$(`${window.location.hash}_nav`).addClass('active');
|
||||||
|
|
||||||
|
setupDataSorting();
|
||||||
})
|
})
|
||||||
|
|
||||||
|
function setupDataSorting() {
|
||||||
|
const tableColumn = $('.table-sort-column');
|
||||||
|
$(tableColumn).off('click');
|
||||||
|
$(tableColumn).on('click', function() {
|
||||||
|
const columnName = $(this).data('column-name');
|
||||||
|
const table = $('.table-sort');
|
||||||
|
$(table).data('sort-column', columnName);
|
||||||
|
$(table).data('sort-down', $(table).data('sort-down') !== true);
|
||||||
|
refreshScoreboard();
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
setInterval(refreshScoreboard, 5000);
|
setInterval(refreshScoreboard, 5000);
|
||||||
|
Loading…
Reference in New Issue
Block a user