Files
NodeBB/public/src/forum/admin/index.js

127 lines
3.3 KiB
JavaScript
Raw Normal View History

2014-03-12 16:15:39 -04:00
"use strict";
/*global define, ajaxify, app, socket, RELATIVE_PATH*/
define('forum/admin/index', function() {
var Admin = {};
Admin.init = function() {
app.enterRoom('admin');
socket.emit('meta.rooms.getAll', Admin.updateRoomUsage);
socket.removeListener('event:meta.rooms.update', Admin.updateRoomUsage);
2014-01-13 12:01:42 -05:00
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 + '/';
});
2014-02-19 15:24:39 -05:00
});
2014-06-01 11:57:44 -04:00
$.get('https://api.github.com/repos/NodeBB/NodeBB/tags', function(releases) {
2014-02-19 15:24:39 -05:00
var version = $('#version').html(),
latestVersion = releases[0].name.slice(1),
checkEl = $('.version-check');
checkEl.html($('.version-check').html().replace('<i class="fa fa-spinner fa-spin"></i>', 'v' + latestVersion));
// Alter box colour accordingly
if (latestVersion === version) {
checkEl.removeClass('alert-info').addClass('alert-success');
checkEl.append('<p>You are <strong>up-to-date</strong> <i class="fa fa-check"></i></p>');
} else if (latestVersion > version) {
checkEl.removeClass('alert-info').addClass('alert-danger');
checkEl.append('<p>A new version (v' + latestVersion + ') has been released. Consider upgrading your NodeBB.</p>');
}
});
2014-02-22 03:11:13 -05:00
$('.restart').on('click', function() {
2014-08-25 10:46:48 -04:00
bootbox.confirm('Are you sure you wish to restart NodeBB?', function(confirm) {
if (confirm) {
app.alert({
timeout: 5000,
title: 'Restarting... <i class="fa fa-spin fa-refresh"></i>',
message: 'NodeBB is restarting.',
type: 'info'
});
$(window).one('action:reconnected', function() {
app.alertSuccess('NodeBB has successfully restarted.');
});
socket.emit('admin.restart');
}
});
});
$('.reload').on('click', function() {
2014-06-02 16:58:38 -04:00
app.alert({
2014-08-25 10:46:48 -04:00
alert_id: 'instance_reload',
title: 'Reloading... <i class="fa fa-spin fa-refresh"></i>',
2014-06-02 16:58:38 -04:00
message: 'NodeBB is restarting.',
2014-08-25 10:46:48 -04:00
type: 'info',
timeout: 5000
2014-06-02 16:58:38 -04:00
});
2014-08-25 10:46:48 -04:00
socket.emit('admin.reload', function(err) {
if (!err) {
app.alertSuccess('NodeBB has successfully reloaded.');
} else {
app.alert({
alert_id: 'instance_reload',
title: '[[global:alert.error]]',
message: err.message,
type: 'danger'
});
}
2014-06-02 16:58:38 -04:00
});
2014-02-22 03:11:13 -05:00
});
};
2014-01-16 16:26:47 -05:00
Admin.updateRoomUsage = function(err, data) {
2014-01-26 21:32:53 -05:00
2014-01-19 14:42:47 -05:00
function getUserCountIn(room) {
var count = 0;
for(var user in data[room]) {
2014-03-12 16:15:39 -04:00
if (data[room].hasOwnProperty(user)) {
++count;
}
2014-01-19 14:42:47 -05:00
}
return count;
}
2014-01-26 21:32:53 -05:00
var active_users = $('#active_users').html(''),
2014-01-13 12:01:42 -05:00
total = 0;
2014-01-18 21:57:06 -05:00
if(!active_users.length) {
return;
}
2014-01-26 21:32:53 -05:00
var sortedData = [];
2014-01-13 12:01:42 -05:00
for (var room in data) {
if (room !== '') {
2014-01-26 21:32:53 -05:00
sortedData.push({room: room, count: data[room].length});
total += data[room].length;
2014-01-13 12:01:42 -05:00
}
}
2014-01-26 21:32:53 -05:00
sortedData.sort(function(a, b) {
return parseInt(b.count, 10) - parseInt(a.count, 10);
});
var usersHtml = '';
for(var i=0; i<sortedData.length; ++i) {
usersHtml += "<div class='alert alert-success'><strong>" + sortedData[i].room + "</strong> " +
sortedData[i].count + " active user" + (sortedData[i].count > 1 ? "s" : "") + "</div>";
}
2014-01-18 21:57:06 -05:00
active_users.html(usersHtml);
2014-01-26 21:32:53 -05:00
$('#connections').html(total);
2014-01-13 12:01:42 -05:00
};
return Admin;
});