IW4M-Admin/WebfrontCore/wwwroot/js/server.js

100 lines
3.2 KiB
JavaScript
Raw Permalink Normal View History

function getPlayerHistoryChart(playerHistory, i, width, color, maxClients) {
2018-02-21 20:29:23 -05:00
///////////////////////////////////////
// thanks to canvasjs :(
playerHistory.forEach(function (item, i) {
playerHistory[i].x = new Date(playerHistory[i].x);
});
return new CanvasJS.Chart(`server_history_${i}`, {
backgroundColor: '#191919',
2018-02-21 20:29:23 -05:00
height: 100,
width: width,
animationEnabled: true,
toolTip: {
contentFormatter: function (e) {
const date = moment.utc(e.entries[0].dataPoint.x);
return date.local().format('h:mm A') + " - " + e.entries[0].dataPoint.y + " players";
2018-02-21 20:29:23 -05:00
}
},
axisX: {
interval: 1,
gridThickness: 0,
lineThickness: 0,
tickThickness: 0,
margin: 0,
valueFormatString: " "
2018-02-21 20:29:23 -05:00
},
axisY: {
gridThickness: 0,
lineThickness: 0,
tickThickness: 0,
minimum: 0,
maximum: maxClients + 1,
2018-02-21 20:29:23 -05:00
margin: 0,
valueFormatString: " ",
labelMaxWidth: 0
2018-02-21 20:29:23 -05:00
},
legend: {
maxWidth: 0,
maxHeight: 0,
dockInsidePlotArea: true
2018-02-21 20:29:23 -05:00
},
data: [{
showInLegend: false,
type: "splineArea",
color: color,
2018-02-21 20:29:23 -05:00
markerSize: 0,
dataPoints: playerHistory
2018-02-21 20:29:23 -05:00
}]
});
//////////////////////////////////////
}
var charts = {};
$(window).resize(function () {
$('.server-history-row').each(function (index) {
let serverId = $(this).data('serverid');
charts[serverId].options.width = $('.server-header').first().width();
charts[serverId].render();
2018-02-21 20:29:23 -05:00
});
});
2018-02-21 20:29:23 -05:00
function refreshClientActivity() {
$('.server-history-row').each(function (index) {
let serverId = $(this).data("serverid");
$.get({
url: "/server/clientactivity/" + serverId,
cache: false
})
2018-02-21 20:29:23 -05:00
.done(function (response) {
2019-08-04 18:06:07 -04:00
const clientCount = $(response).find('a').length;
$('#server_header_' + serverId + ' .server-clientcount').text(clientCount);
2018-02-21 20:29:23 -05:00
$('#server_clientactivity_' + serverId).html(response);
})
.fail(function (jqxhr, textStatus, error) {
$('#server_clientactivity_' + serverId).html('');
2018-02-21 20:29:23 -05:00
});
});
}
2019-07-19 15:54:39 -04:00
$(document).ready(function () {
$('.server-join-button').click(function (e) {
$(this).children('.server-header-ip-address').show();
});
$('.server-history-row').each(function (index, element) {
let clientHistory = $(this).data('clienthistory');
let serverId = $(this).data('serverid');
let maxClients = parseInt($('#server_header_' + serverId + ' .server-maxclients').text());
let primaryColor = $('title').css('background-color');
let color = $(this).data('online') === 'True' ? primaryColor : '#ff6060';
let width = $('.server-header').first().width();
let historyChart = getPlayerHistoryChart(clientHistory, serverId, width, color, maxClients);
historyChart.render();
charts[serverId] = historyChart;
});
2019-07-19 15:54:39 -04:00
});
setInterval(refreshClientActivity, 2000);