Fixed some labelling issues and added support for last month

v1.18.x
Julian Lam 9 years ago
parent 7f9ac3f1fe
commit 6d386dd2ee

@ -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;

@ -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) {

@ -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>

Loading…
Cancel
Save