From 6bf36a04683094e6654fc679c9c6359844771b9b Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Fri, 28 Feb 2014 16:23:46 -0500 Subject: [PATCH 1/4] if alert is closed dont fire clickfn --- public/src/app.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/public/src/app.js b/public/src/app.js index 9ad598be89..e33a0f545d 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -218,9 +218,10 @@ var socket, $('#' + params.location).prepend(alert.fadeIn('100')); if(typeof params.closefn === 'function') { - alert.find('button').on('click', function () { + alert.find('button').on('click', function() { params.closefn(); fadeOut(); + return false; }); } }); From 7081c7dcc418627362e655449ed15f80264f76a4 Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Fri, 28 Feb 2014 16:50:39 -0500 Subject: [PATCH 2/4] moved ip log to api --- src/routes/api.js | 3 +++ src/webserver.js | 3 --- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/routes/api.js b/src/routes/api.js index 4b326fe565..d7e4419b22 100644 --- a/src/routes/api.js +++ b/src/routes/api.js @@ -30,6 +30,9 @@ var path = require('path'), user.updateLastOnlineTime(req.user.uid); } + // Log IP address + db.sortedSetAdd('ip:recent', +new Date(), req.ip || 'Unknown'); + next(); }); diff --git a/src/webserver.js b/src/webserver.js index b4d5afe7b6..8d340c3dd1 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -289,9 +289,6 @@ process.on('uncaughtException', function(err) { // Disable framing res.setHeader('X-Frame-Options', 'SAMEORIGIN'); - // Log IP address - db.sortedSetAdd('ip:recent', +new Date(), req.ip || 'Unknown'); - next(); }); From e75c303b89bc21d9e775738e1a3cc44f25aafa96 Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Fri, 28 Feb 2014 17:19:42 -0500 Subject: [PATCH 3/4] added unique visitor count to admin dashboard --- public/src/forum/admin/index.js | 11 +++++++++++ public/templates/admin/index.tpl | 25 +++++++++++++++++++++++++ src/routes/api.js | 3 +-- src/socket.io/admin.js | 25 +++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 2 deletions(-) diff --git a/public/src/forum/admin/index.js b/public/src/forum/admin/index.js index 1870884328..7c9f6db3bd 100644 --- a/public/src/forum/admin/index.js +++ b/public/src/forum/admin/index.js @@ -35,6 +35,17 @@ define(function() { $('.restart').on('click', 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) { + uniqueVisitors.find('#' + key).text(data[key]); + } + }); }; Admin.updateRoomUsage = function(err, data) { diff --git a/public/templates/admin/index.tpl b/public/templates/admin/index.tpl index 2d548c459c..3fac2b0917 100644 --- a/public/templates/admin/index.tpl +++ b/public/templates/admin/index.tpl @@ -36,4 +36,29 @@ +
+
+
Unique Visitors
+
+
+
+
+
Day
+
+
+
+
Week
+
+
+
+
Month
+
+
+
+
All Time
+
+
+
+
+
\ No newline at end of file diff --git a/src/routes/api.js b/src/routes/api.js index d7e4419b22..134964d185 100644 --- a/src/routes/api.js +++ b/src/routes/api.js @@ -30,8 +30,7 @@ var path = require('path'), user.updateLastOnlineTime(req.user.uid); } - // Log IP address - db.sortedSetAdd('ip:recent', +new Date(), req.ip || 'Unknown'); + db.sortedSetAdd('ip:recent', Date.now(), req.ip || 'Unknown'); next(); }); diff --git a/src/socket.io/admin.js b/src/socket.io/admin.js index 3d5fd87726..316d77a347 100644 --- a/src/socket.io/admin.js +++ b/src/socket.io/admin.js @@ -9,6 +9,7 @@ var groups = require('../groups'), categories = require('../categories'), CategoryTools = require('../categoryTools'), logger = require('../logger'), + db = require('../database'), admin = { user: require('../admin/user'), categories: require('../admin/categories') @@ -35,6 +36,30 @@ 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); +} + /* Topics */ SocketAdmin.topics = {}; From 84dc012198c74fc58417e674433845947c41c4ac Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Fri, 28 Feb 2014 18:17:17 -0500 Subject: [PATCH 4/4] closes #1142 --- public/src/forum/topic.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/public/src/forum/topic.js b/public/src/forum/topic.js index 84eafc8621..4ab60fe365 100644 --- a/public/src/forum/topic.js +++ b/public/src/forum/topic.js @@ -141,16 +141,16 @@ define(['composer', 'forum/pagination'], function(composer, pagination) { } loadingEl.remove(); - categoriesEl.on('click', function(e) { - var el = $(e.target); + categoriesEl.on('click', 'li[data-cid]', function(e) { + var el = $(this); if (el.is('li')) { - confirmCat.html(e.target.innerHTML); + confirmCat.html(el.html()); confirmDiv.css({display: 'block'}); targetCid = el.attr('data-cid'); - targetCatLabel = e.html(); + targetCatLabel = el.html(); commitEl.prop('disabled', false); } - }, false); + }); commitEl.on('click', function() { if (!commitEl.prop('disabled') && targetCid) {