Skip to content

Node.js based forum software built for the modern web

Fixed some labelling issues and added support for last month

Julian Lam6d386dd2ee98
diff --git a/public/src/admin/general/dashboard.js b/public/src/admin/general/dashboard.js
index e4ed52d39c..3b9134b10c 100644
--- a/public/src/admin/general/dashboard.js
+++ b/public/src/admin/general/dashboard.js
@@ -12,7 +12,10 @@ define('admin/general/dashboard', ['semver'], function(semver) {
rooms: {},
traffic: {}
},
- currentGraph = 'hours';
+ currentGraph = {
+ units: 'hours',
+ until: undefined
+ };
var DEFAULTS = {
roomInterval: 10000,
@@ -157,8 +160,8 @@ define('admin/general/dashboard', ['semver'], function(semver) {
return labels.reverse();
}
- function getDaysArray() {
- var currentDay = new Date().getTime(),
+ function getDaysArray(from) {
+ var currentDay = new Date(from || Date.now()).getTime(),
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
labels = [],
tmpDate;
@@ -280,8 +283,15 @@ define('admin/general/dashboard', ['semver'], function(semver) {
adjustPieCharts();
$('[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() {
@@ -296,20 +306,20 @@ define('admin/general/dashboard', ['semver'], function(semver) {
});
}
- function updateTrafficGraph(units) {
+ function updateTrafficGraph(units, until) {
if (!app.isFocused) {
return;
}
- units = units || currentGraph;
-
socket.emit('admin.analytics.get', {
graph: 'traffic',
- units: units
+ units: units || 'hours',
+ until: until
}, function (err, data) {
if (JSON.stringify(graphData.traffic) === JSON.stringify(data)) {
return;
}
+ console.log(data);
graphData.traffic = data;
@@ -319,7 +329,7 @@ define('admin/general/dashboard', ['semver'], function(semver) {
}
if (units === 'days') {
- graphs.traffic.scale.xLabels = getDaysArray();
+ graphs.traffic.scale.xLabels = getDaysArray(until);
} else {
graphs.traffic.scale.xLabels = getHoursArray();
}
@@ -337,7 +347,8 @@ define('admin/general/dashboard', ['semver'], function(semver) {
}
graphs.traffic.update();
- currentGraph = units;
+ currentGraph.units = units;
+ currentGraph.until = until;
$('#pageViewsThisMonth').html(data.monthlyPageViews.thisMonth);
$('#pageViewsLastMonth').html(data.monthlyPageViews.lastMonth);
@@ -483,7 +494,9 @@ define('admin/general/dashboard', ['semver'], function(semver) {
}
}, 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;
diff --git a/src/socket.io/admin.js b/src/socket.io/admin.js
index df00925dad..95af8c7122 100644
--- a/src/socket.io/admin.js
+++ b/src/socket.io/admin.js
@@ -218,16 +218,16 @@ SocketAdmin.analytics.get = function(socket, data, callback) {
async.parallel({
uniqueVisitors: function(next) {
if (data.units === 'days') {
- getDailyStatsForSet('analytics:uniquevisitors', Date.now(), data.amount, next);
+ getDailyStatsForSet('analytics:uniquevisitors', data.until || Date.now(), data.amount, next);
} else {
- getHourlyStatsForSet('analytics:uniquevisitors', Date.now(), data.amount, next);
+ getHourlyStatsForSet('analytics:uniquevisitors', data.until || Date.now(), data.amount, next);
}
},
pageviews: function(next) {
if (data.units === 'days') {
- getDailyStatsForSet('analytics:pageviews', Date.now(), data.amount, next);
+ getDailyStatsForSet('analytics:pageviews', data.until || Date.now(), data.amount, next);
} else {
- getHourlyStatsForSet('analytics:pageviews', Date.now(), data.amount, next);
+ getHourlyStatsForSet('analytics:pageviews', data.until || Date.now(), data.amount, next);
}
},
monthlyPageViews: function(next) {
diff --git a/src/views/admin/general/dashboard.tpl b/src/views/admin/general/dashboard.tpl
index 153dd643be..6ea841352a 100644
--- a/src/views/admin/general/dashboard.tpl
+++ b/src/views/admin/general/dashboard.tpl
@@ -13,7 +13,7 @@
<hr/>
<div class="text-center pull-left monthly-pageviews">
<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 class="text-center pull-left monthly-pageviews">
<div><strong id="pageViewsThisMonth"></strong></div>