mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-09 07:25:46 +01:00
user presence pie chart
This commit is contained in:
@@ -124,13 +124,18 @@ define('forum/admin/general/dashboard', ['semver'], function(semver) {
|
||||
'<div>Connections</div>' +
|
||||
'</div>';
|
||||
|
||||
var idle = data.socketCount - data.users.home + data.users.topics + data.users.category;
|
||||
|
||||
updateRegisteredGraph(data.onlineRegisteredCount, data.onlineGuestCount);
|
||||
updatePresenceGraph(data.users.home, data.users.topics, data.users.category, idle);
|
||||
|
||||
$('#active-users').html(html);
|
||||
};
|
||||
|
||||
var graphs = {
|
||||
traffic: null
|
||||
traffic: null,
|
||||
registered: null,
|
||||
presence: null
|
||||
};
|
||||
|
||||
function getHoursArray() {
|
||||
@@ -148,8 +153,10 @@ define('forum/admin/general/dashboard', ['semver'], function(semver) {
|
||||
function setupGraphs() {
|
||||
var trafficCanvas = document.getElementById('analytics-traffic'),
|
||||
registeredCanvas = document.getElementById('analytics-registered'),
|
||||
presenceCanvas = document.getElementById('analytics-presence'),
|
||||
trafficCtx = trafficCanvas.getContext('2d'),
|
||||
registeredCtx = registeredCanvas.getContext('2d'),
|
||||
presenceCtx = presenceCanvas.getContext('2d'),
|
||||
trafficLabels = getHoursArray();
|
||||
|
||||
var data = {
|
||||
@@ -198,6 +205,33 @@ define('forum/admin/general/dashboard', ['semver'], function(semver) {
|
||||
responsive: true
|
||||
});
|
||||
|
||||
graphs.presence = new Chart(presenceCtx).Doughnut([{
|
||||
value: 1,
|
||||
color:"#F7464A",
|
||||
highlight: "#FF5A5E",
|
||||
label: "On homepage"
|
||||
},
|
||||
{
|
||||
value: 1,
|
||||
color: "#46BFBD",
|
||||
highlight: "#5AD3D1",
|
||||
label: "Reading posts"
|
||||
},
|
||||
{
|
||||
value: 1,
|
||||
color: "#FDB45C",
|
||||
highlight: "#FFC870",
|
||||
label: "Browsing topics"
|
||||
},
|
||||
{
|
||||
value: 1,
|
||||
color: "#949FB1",
|
||||
highlight: "#A8B3C5",
|
||||
label: "Idle"
|
||||
}], {
|
||||
responsive: true
|
||||
});
|
||||
|
||||
setInterval(updateTrafficGraph, 15000);
|
||||
updateTrafficGraph();
|
||||
}
|
||||
@@ -222,5 +256,13 @@ define('forum/admin/general/dashboard', ['semver'], function(semver) {
|
||||
graphs.registered.update();
|
||||
}
|
||||
|
||||
function updatePresenceGraph(homepage, posts, topics, idle) {
|
||||
graphs.presence.segments[0].value = homepage;
|
||||
graphs.presence.segments[1].value = posts;
|
||||
graphs.presence.segments[2].value = topics;
|
||||
graphs.presence.segments[3].value = idle;
|
||||
graphs.presence.update();
|
||||
}
|
||||
|
||||
return Admin;
|
||||
});
|
||||
|
||||
@@ -83,12 +83,28 @@ SocketMeta.rooms.enter = function(socket, data, callback) {
|
||||
};
|
||||
|
||||
SocketMeta.rooms.getAll = function(socket, data, callback) {
|
||||
var userData = {
|
||||
var rooms = websockets.server.sockets.manager.rooms,
|
||||
userData = {
|
||||
onlineGuestCount: websockets.getOnlineAnonCount(),
|
||||
onlineRegisteredCount: websockets.getOnlineUserCount(),
|
||||
socketCount: websockets.getSocketCount()
|
||||
socketCount: websockets.getSocketCount(),
|
||||
users: {
|
||||
home: rooms['/home'] ? rooms['/home'].length : 0,
|
||||
topics: 0,
|
||||
category: 0
|
||||
}
|
||||
};
|
||||
|
||||
for (var room in rooms) {
|
||||
if (rooms.hasOwnProperty(room)) {
|
||||
if (room.match(/^\/topic/)) {
|
||||
userData.users.topics += rooms[room].length
|
||||
} else if (room.match(/^\/category/)) {
|
||||
userData.users.category += rooms[room].length
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
callback(null, userData);
|
||||
};
|
||||
|
||||
|
||||
@@ -66,6 +66,15 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">User Presence</div>
|
||||
<div class="panel-body">
|
||||
<div class="graph-container">
|
||||
<canvas id="analytics-presence"></canvas>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- BEGIN stats -->
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">{stats.name}</div>
|
||||
|
||||
Reference in New Issue
Block a user