define(function() { var Admin = {}; Admin.init = function() { ajaxify.register_events(['meta.rooms.getAll']); app.enterRoom('admin'); socket.emit('meta.rooms.getAll', Admin.updateRoomUsage); socket.on('event:meta.rooms.update', Admin.updateRoomUsage); $('#logout-link').on('click', function() { $.post(RELATIVE_PATH + '/logout', { _csrf: $('#csrf_token').val() }, function() { window.location.href = RELATIVE_PATH + '/'; }); }); $.get('https://api.github.com/repos/designcreateplay/NodeBB/tags', function(releases) { var version = $('#version').html(), latestVersion = releases[0].name.slice(1), checkEl = $('.version-check'); checkEl.html($('.version-check').html().replace('', 'v' + latestVersion)); // Alter box colour accordingly if (latestVersion === version) { checkEl.removeClass('alert-info').addClass('alert-success'); checkEl.append('

You are up-to-date

'); } else if (latestVersion > version) { checkEl.removeClass('alert-info').addClass('alert-danger'); checkEl.append('

A new version (v' + latestVersion + ') has been released. Consider upgrading your NodeBB.

'); } }); $('.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) { function getUserCountIn(room) { var count = 0; for(var user in data[room]) { ++count; } return count; } var active_users = $('#active_users').html(''), total = 0; if(!active_users.length) { return; } var sortedData = []; for (var room in data) { if (room !== '') { sortedData.push({room: room, count: data[room].length}); total += data[room].length; } } sortedData.sort(function(a, b) { return parseInt(b.count, 10) - parseInt(a.count, 10); }); var usersHtml = ''; for(var i=0; i " + sortedData[i].count + " active user" + (sortedData[i].count > 1 ? "s" : "") + ""; } active_users.html(usersHtml); $('#connections').html(total); }; return Admin; });