v1.18.x
Julian Lam 8 years ago
parent 51a85031f7
commit 816809ce3c

@ -5,8 +5,8 @@
"users": "Users",
"posts": "Posts",
"topics": "Topics",
"page-views-last-month": "Last Month",
"page-views-this-month": "This Month",
"page-views-seven": "Last 7 Days",
"page-views-thirty": "Last 30 Days",
"page-views-last-day": "Last 24 hours",
"page-views-custom": "Custom Date Range",
"page-views-custom-start": "Range Start",

@ -295,14 +295,11 @@ define('admin/general/dashboard', ['semver', 'Chart', 'translator'], function (s
adjustPieCharts();
$('[data-action="updateGraph"]:not([data-units="custom"])').on('click', function () {
var until;
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);
var until = new Date();
var amount = $(this).attr('data-amount');
until.setHours(0, 0, 0, 0);
until = until.getTime();
updateTrafficGraph($(this).attr('data-units'), until, amount);
$('[data-action="updateGraph"]').removeClass('active');
$(this).addClass('active');
@ -406,11 +403,11 @@ define('admin/general/dashboard', ['semver', 'Chart', 'translator'], function (s
} else {
graphs.traffic.data.xLabels = utils.getHoursArray();
$('#pageViewsThisMonth').html(data.monthlyPageViews.thisMonth);
$('#pageViewsLastMonth').html(data.monthlyPageViews.lastMonth);
$('#pageViewsThirty').html(data.summary.thirty);
$('#pageViewsSeven').html(data.summary.seven);
$('#pageViewsPastDay').html(data.pastDay);
utils.addCommasToNumbers($('#pageViewsThisMonth'));
utils.addCommasToNumbers($('#pageViewsLastMonth'));
utils.addCommasToNumbers($('#pageViewsThirty'));
utils.addCommasToNumbers($('#pageViewsSeven'));
utils.addCommasToNumbers($('#pageViewsPastDay'));
}

@ -168,21 +168,18 @@ Analytics.getUnwrittenPageviews = function () {
return pageViews;
};
Analytics.getMonthlyPageViews = function (callback) {
var thisMonth = new Date();
var lastMonth = new Date();
thisMonth.setMonth(thisMonth.getMonth(), 1);
thisMonth.setHours(0, 0, 0, 0);
lastMonth.setMonth(thisMonth.getMonth() - 1, 1);
lastMonth.setHours(0, 0, 0, 0);
var values = [thisMonth.getTime(), lastMonth.getTime()];
Analytics.getSummary = function (callback) {
var today = new Date();
today.setHours(0, 0, 0, 0);
db.sortedSetScores('analytics:pageviews:month', values, function (err, scores) {
if (err) {
return callback(err);
}
callback(null, { thisMonth: scores[0] || 0, lastMonth: scores[1] || 0 });
async.parallel({
seven: async.apply(Analytics.getDailyStatsForSet, 'analytics:pageviews', today, 7),
thirty: async.apply(Analytics.getDailyStatsForSet, 'analytics:pageviews', today, 30),
}, function (err, scores) {
callback(null, {
seven: scores.seven.reduce(function (sum, cur) { return sum += cur; }, 0),
thirty: scores.thirty.reduce(function (sum, cur) { return sum += cur; }, 0),
});
});
};

@ -235,8 +235,8 @@ SocketAdmin.analytics.get = function (socket, data, callback) {
analytics.getHourlyStatsForSet('analytics:pageviews', data.until || Date.now(), data.amount, next);
}
},
monthlyPageViews: function (next) {
analytics.getMonthlyPageViews(next);
summary: function (next) {
analytics.getSummary(next);
},
}, function (err, data) {
data.pastDay = data.pageviews.reduce(function (a, b) { return parseInt(a, 10) + parseInt(b, 10); });

@ -13,12 +13,12 @@
<hr/>
<div class="row">
<div class="col-sm-3 hidden-xs text-center pageview-stats">
<div><strong id="pageViewsLastMonth">0</strong></div>
<div><a href="#" class="updatePageviewsGraph" data-action="updateGraph" data-units="days" data-until="last-month">[[admin/general/dashboard:page-views-last-month]]</a></div>
<div><strong id="pageViewsThirty">0</strong></div>
<div><a href="#" class="updatePageviewsGraph" data-action="updateGraph" data-units="days" data-amount="30">[[admin/general/dashboard:page-views-thirty]]</a></div>
</div>
<div class="col-sm-3 text-center pageview-stats">
<div><strong id="pageViewsThisMonth">0</strong></div>
<div><a href="#" class="updatePageviewsGraph" data-action="updateGraph" data-units="days">[[admin/general/dashboard:page-views-this-month]]</a></div>
<div><strong id="pageViewsSeven">0</strong></div>
<div><a href="#" class="updatePageviewsGraph" data-action="updateGraph" data-units="days" data-amount="7">[[admin/general/dashboard:page-views-seven]]</a></div>
</div>
<div class="col-sm-3 hidden-xs text-center pageview-stats">
<div><strong id="pageViewsPastDay">0</strong></div>

Loading…
Cancel
Save