Skip to content

Node.js based forum software built for the modern web

display user post topic stats in admin index

barisusaklie6c9647acf6a
diff --git a/public/src/forum/admin/index.js b/public/src/forum/admin/index.js
index b6f6ed147d..c10706e257 100644
--- a/public/src/forum/admin/index.js
+++ b/public/src/forum/admin/index.js
@@ -50,19 +50,6 @@ define('forum/admin/index', function() {
socket.emit('admin.restart');
});
-
- socket.emit('admin.getVisitorCount', function(err, data) {
- if(err) {
- return app.alertError(err.message);
- }
-
- var uniqueVisitors = $('#unique-visitors');
- for(var key in data) {
- if (data.hasOwnProperty(key)) {
- uniqueVisitors.find('#' + key).text(data[key]);
- }
- }
- });
};
Admin.updateRoomUsage = function(err, data) {
diff --git a/src/controllers/admin.js b/src/controllers/admin.js
index 2d0f22a4cb..21943edb82 100644
--- a/src/controllers/admin.js
+++ b/src/controllers/admin.js
@@ -34,14 +34,70 @@ var adminController = {
};
adminController.home = function(req, res, next) {
- res.render('admin/index', {
- version: pkg.version,
- emailerInstalled: plugins.hasListeners('action:email.send'),
- searchInstalled: plugins.hasListeners('filter:search.query'),
- restartRequired: meta.restartRequired
+ getStats(function(err, stats) {
+ if (err) {
+ return next(err);
+ }
+ res.render('admin/index', {
+ version: pkg.version,
+ emailerInstalled: plugins.hasListeners('action:email.send'),
+ searchInstalled: plugins.hasListeners('filter:search.query'),
+ restartRequired: meta.restartRequired,
+ stats: stats
+ });
});
};
+function getStats(callback) {
+ async.parallel([
+ function(next) {
+ getStatsForSet('ip:recent', next);
+ },
+ function(next) {
+ getStatsForSet('users:joindate', next);
+ },
+ function(next) {
+ getStatsForSet('posts:pid', next);
+ },
+ function(next) {
+ getStatsForSet('topics:tid', next);
+ }
+ ], function(err, results) {
+ if (err) {
+ return callback(err);
+ }
+ results[0].name = 'Unique Visitors';
+ results[1].name = 'Users';
+ results[2].name = 'Posts';
+ results[3].name = 'Topics';
+
+ callback(null, results);
+ });
+}
+
+function getStatsForSet(set, callback) {
+ var terms = {
+ day: 86400000,
+ week: 604800000,
+ month: 2592000000
+ };
+ var now = Date.now();
+ async.parallel({
+ day: function(next) {
+ db.sortedSetCount(set, now - terms.day, now, next);
+ },
+ week: function(next) {
+ db.sortedSetCount(set, now - terms.week, now, next);
+ },
+ month: function(next) {
+ db.sortedSetCount(set, now - terms.month, now, next);
+ },
+ alltime: function(next) {
+ db.sortedSetCount(set, 0, now, next);
+ }
+ }, callback);
+}
+
adminController.categories.active = function(req, res, next) {
filterAndRenderCategories(req, res, next, true);
};
diff --git a/src/socket.io/admin.js b/src/socket.io/admin.js
index 369ba11112..9f6a0be04b 100644
--- a/src/socket.io/admin.js
+++ b/src/socket.io/admin.js
@@ -39,29 +39,6 @@ SocketAdmin.restart = function(socket, data, callback) {
meta.restart();
};
-SocketAdmin.getVisitorCount = function(socket, data, callback) {
- var terms = {
- day: 86400000,
- week: 604800000,
- month: 2592000000
- };
- var now = Date.now();
- async.parallel({
- day: function(next) {
- db.sortedSetCount('ip:recent', now - terms.day, now, next);
- },
- week: function(next) {
- db.sortedSetCount('ip:recent', now - terms.week, now, next);
- },
- month: function(next) {
- db.sortedSetCount('ip:recent', now - terms.month, now, next);
- },
- alltime: function(next) {
- db.sortedSetCount('ip:recent', 0, now, next);
- }
- }, callback);
-};
-
SocketAdmin.fireEvent = function(socket, data, callback) {
index.server.sockets.emit(data.name, data.payload || {});
};