mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-05 21:45:47 +01:00
Fixed some labelling issues and added support for last month
This commit is contained in:
@@ -12,7 +12,10 @@ define('admin/general/dashboard', ['semver'], function(semver) {
|
|||||||
rooms: {},
|
rooms: {},
|
||||||
traffic: {}
|
traffic: {}
|
||||||
},
|
},
|
||||||
currentGraph = 'hours';
|
currentGraph = {
|
||||||
|
units: 'hours',
|
||||||
|
until: undefined
|
||||||
|
};
|
||||||
|
|
||||||
var DEFAULTS = {
|
var DEFAULTS = {
|
||||||
roomInterval: 10000,
|
roomInterval: 10000,
|
||||||
@@ -157,8 +160,8 @@ define('admin/general/dashboard', ['semver'], function(semver) {
|
|||||||
return labels.reverse();
|
return labels.reverse();
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDaysArray() {
|
function getDaysArray(from) {
|
||||||
var currentDay = new Date().getTime(),
|
var currentDay = new Date(from || Date.now()).getTime(),
|
||||||
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
|
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
|
||||||
labels = [],
|
labels = [],
|
||||||
tmpDate;
|
tmpDate;
|
||||||
@@ -280,8 +283,15 @@ define('admin/general/dashboard', ['semver'], function(semver) {
|
|||||||
adjustPieCharts();
|
adjustPieCharts();
|
||||||
|
|
||||||
$('[data-action="updateGraph"]').on('click', function() {
|
$('[data-action="updateGraph"]').on('click', function() {
|
||||||
updateTrafficGraph($(this).attr('data-units'));
|
var until = undefined;
|
||||||
})
|
switch($(this).attr('data-until')) {
|
||||||
|
case 'last-month':
|
||||||
|
var lastMonth = new Date();
|
||||||
|
lastMonth.setDate(lastMonth.getDate()-30);
|
||||||
|
until = lastMonth.getTime();
|
||||||
|
}
|
||||||
|
updateTrafficGraph($(this).attr('data-units'), until);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function adjustPieCharts() {
|
function adjustPieCharts() {
|
||||||
@@ -296,20 +306,20 @@ define('admin/general/dashboard', ['semver'], function(semver) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateTrafficGraph(units) {
|
function updateTrafficGraph(units, until) {
|
||||||
if (!app.isFocused) {
|
if (!app.isFocused) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
units = units || currentGraph;
|
|
||||||
|
|
||||||
socket.emit('admin.analytics.get', {
|
socket.emit('admin.analytics.get', {
|
||||||
graph: 'traffic',
|
graph: 'traffic',
|
||||||
units: units
|
units: units || 'hours',
|
||||||
|
until: until
|
||||||
}, function (err, data) {
|
}, function (err, data) {
|
||||||
if (JSON.stringify(graphData.traffic) === JSON.stringify(data)) {
|
if (JSON.stringify(graphData.traffic) === JSON.stringify(data)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
console.log(data);
|
||||||
|
|
||||||
graphData.traffic = data;
|
graphData.traffic = data;
|
||||||
|
|
||||||
@@ -319,7 +329,7 @@ define('admin/general/dashboard', ['semver'], function(semver) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (units === 'days') {
|
if (units === 'days') {
|
||||||
graphs.traffic.scale.xLabels = getDaysArray();
|
graphs.traffic.scale.xLabels = getDaysArray(until);
|
||||||
} else {
|
} else {
|
||||||
graphs.traffic.scale.xLabels = getHoursArray();
|
graphs.traffic.scale.xLabels = getHoursArray();
|
||||||
}
|
}
|
||||||
@@ -337,7 +347,8 @@ define('admin/general/dashboard', ['semver'], function(semver) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
graphs.traffic.update();
|
graphs.traffic.update();
|
||||||
currentGraph = units;
|
currentGraph.units = units;
|
||||||
|
currentGraph.until = until;
|
||||||
|
|
||||||
$('#pageViewsThisMonth').html(data.monthlyPageViews.thisMonth);
|
$('#pageViewsThisMonth').html(data.monthlyPageViews.thisMonth);
|
||||||
$('#pageViewsLastMonth').html(data.monthlyPageViews.lastMonth);
|
$('#pageViewsLastMonth').html(data.monthlyPageViews.lastMonth);
|
||||||
@@ -483,7 +494,9 @@ define('admin/general/dashboard', ['semver'], function(semver) {
|
|||||||
}
|
}
|
||||||
}, realtime ? DEFAULTS.realtimeInterval : DEFAULTS.roomInterval);
|
}, realtime ? DEFAULTS.realtimeInterval : DEFAULTS.roomInterval);
|
||||||
|
|
||||||
intervals.graphs = setInterval(updateTrafficGraph, realtime ? DEFAULTS.realtimeInterval : DEFAULTS.graphInterval);
|
intervals.graphs = setInterval(function() {
|
||||||
|
updateTrafficGraph(currentGraph.units, currentGraph.until);
|
||||||
|
}, realtime ? DEFAULTS.realtimeInterval : DEFAULTS.graphInterval);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Admin;
|
return Admin;
|
||||||
|
|||||||
@@ -218,16 +218,16 @@ SocketAdmin.analytics.get = function(socket, data, callback) {
|
|||||||
async.parallel({
|
async.parallel({
|
||||||
uniqueVisitors: function(next) {
|
uniqueVisitors: function(next) {
|
||||||
if (data.units === 'days') {
|
if (data.units === 'days') {
|
||||||
getDailyStatsForSet('analytics:uniquevisitors', Date.now(), data.amount, next);
|
getDailyStatsForSet('analytics:uniquevisitors', data.until || Date.now(), data.amount, next);
|
||||||
} else {
|
} else {
|
||||||
getHourlyStatsForSet('analytics:uniquevisitors', Date.now(), data.amount, next);
|
getHourlyStatsForSet('analytics:uniquevisitors', data.until || Date.now(), data.amount, next);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
pageviews: function(next) {
|
pageviews: function(next) {
|
||||||
if (data.units === 'days') {
|
if (data.units === 'days') {
|
||||||
getDailyStatsForSet('analytics:pageviews', Date.now(), data.amount, next);
|
getDailyStatsForSet('analytics:pageviews', data.until || Date.now(), data.amount, next);
|
||||||
} else {
|
} else {
|
||||||
getHourlyStatsForSet('analytics:pageviews', Date.now(), data.amount, next);
|
getHourlyStatsForSet('analytics:pageviews', data.until || Date.now(), data.amount, next);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
monthlyPageViews: function(next) {
|
monthlyPageViews: function(next) {
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
<hr/>
|
<hr/>
|
||||||
<div class="text-center pull-left monthly-pageviews">
|
<div class="text-center pull-left monthly-pageviews">
|
||||||
<div><strong id="pageViewsLastMonth"></strong></div>
|
<div><strong id="pageViewsLastMonth"></strong></div>
|
||||||
<div>Page views Last Month</div>
|
<div><a href="#" data-action="updateGraph" data-units="days" data-until="last-month">Page views Last Month</a></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="text-center pull-left monthly-pageviews">
|
<div class="text-center pull-left monthly-pageviews">
|
||||||
<div><strong id="pageViewsThisMonth"></strong></div>
|
<div><strong id="pageViewsThisMonth"></strong></div>
|
||||||
|
|||||||
Reference in New Issue
Block a user