v1.18.x
Barış Soner Uşaklı 7 years ago
parent 8a499e09ed
commit d8dc79e3c7

@ -117,7 +117,7 @@ define('admin/general/dashboard', ['semver', 'Chart', 'translator', 'benchpress'
updateRegisteredGraph(data.onlineRegisteredCount, data.onlineGuestCount); updateRegisteredGraph(data.onlineRegisteredCount, data.onlineGuestCount);
updatePresenceGraph(data.users); updatePresenceGraph(data.users);
updateTopicsGraph(data.topics); updateTopicsGraph(data.topTenTopics);
$('#active-users').translateHtml(html); $('#active-users').translateHtml(html);
}; };
@ -444,39 +444,36 @@ define('admin/general/dashboard', ['semver', 'Chart', 'translator', 'benchpress'
} }
function updateTopicsGraph(topics) { function updateTopicsGraph(topics) {
if (!Object.keys(topics).length) { if (!topics.length) {
topics = { 0: { topics = [{
title: 'No users browsing', title: 'No users browsing',
value: 1, count: 1,
} }; }];
} }
var tids = Object.keys(topics);
graphs.topics.data.labels = []; graphs.topics.data.labels = [];
graphs.topics.data.datasets[0].data = []; graphs.topics.data.datasets[0].data = [];
graphs.topics.data.datasets[0].backgroundColor = []; graphs.topics.data.datasets[0].backgroundColor = [];
graphs.topics.data.datasets[0].hoverBackgroundColor = []; graphs.topics.data.datasets[0].hoverBackgroundColor = [];
for (var i = 0, ii = tids.length; i < ii; i += 1) { topics.forEach(function (topic, i) {
graphs.topics.data.labels.push(topics[tids[i]].title); graphs.topics.data.labels.push(topic.title);
graphs.topics.data.datasets[0].data.push(topics[tids[i]].value); graphs.topics.data.datasets[0].data.push(topic.count);
graphs.topics.data.datasets[0].backgroundColor.push(topicColors[i]); graphs.topics.data.datasets[0].backgroundColor.push(topicColors[i]);
graphs.topics.data.datasets[0].hoverBackgroundColor.push(lighten(topicColors[i], 10)); graphs.topics.data.datasets[0].hoverBackgroundColor.push(lighten(topicColors[i], 10));
} });
function buildTopicsLegend() { function buildTopicsLegend() {
var legend = $('#topics-legend').html(''); var legend = $('#topics-legend').html('');
for (var i = 0, ii = tids.length; i < ii; i += 1) { topics.forEach(function (topic, i) {
var topic = topics[tids[i]]; var label = topic.count === '0' ? topic.title : '<a title="' + topic.title + '"href="' + RELATIVE_PATH + '/topic/' + topic.tid + '" target="_blank"> ' + topic.title + '</a>';
var label = topic.value === '0' ? topic.title : '<a title="' + topic.title + '"href="' + RELATIVE_PATH + '/topic/' + tids[i] + '" target="_blank"> ' + topic.title + '</a>';
legend.append('<li>' + legend.append('<li>' +
'<div style="background-color: ' + topicColors[i] + ';"></div>' + '<div style="background-color: ' + topicColors[i] + ';"></div>' +
'<span>' + label + '</span>' + '<span>' + label + '</span>' +
'</li>'); '</li>');
} });
} }
buildTopicsLegend(); buildTopicsLegend();

@ -89,7 +89,7 @@ SocketRooms.getAll = function (socket, data, callback) {
var topTenTopics = []; var topTenTopics = [];
Object.keys(totals.topics).forEach(function (tid) { Object.keys(totals.topics).forEach(function (tid) {
topTenTopics.push({ tid: tid, count: totals.topics[tid].count }); topTenTopics.push({ tid: tid, count: totals.topics[tid].count || 0 });
}); });
topTenTopics = topTenTopics.sort(function (a, b) { topTenTopics = topTenTopics.sort(function (a, b) {
@ -105,13 +105,11 @@ SocketRooms.getAll = function (socket, data, callback) {
topics.getTopicsFields(topTenTids, ['title'], next); topics.getTopicsFields(topTenTids, ['title'], next);
}, },
function (titles, next) { function (titles, next) {
totals.topics = {}; totals.topTenTopics = topTenTopics.map(function (topic, index) {
topTenTopics.forEach(function (topic, index) { topic.title = titles[index].title;
totals.topics[topic.tid] = { return topic;
value: topic.count || 0,
title: String(titles[index].title),
};
}); });
next(null, totals); next(null, totals);
}, },
], callback); ], callback);

Loading…
Cancel
Save