mirror of https://github.com/calzoneman/sync.git
Add ACP list active channels
This commit is contained in:
parent
359a228d5f
commit
afa17165f7
26
lib/acp.js
26
lib/acp.js
|
@ -14,6 +14,7 @@ var Server = require("./server");
|
|||
var db = require("./database");
|
||||
var util = require("./utilities");
|
||||
var Config = require("./config");
|
||||
var Server = require("./server");
|
||||
|
||||
function handleAnnounce(user, data) {
|
||||
var sv = Server.getServer();
|
||||
|
@ -240,6 +241,29 @@ function handleDeleteChannel(user, data) {
|
|||
});
|
||||
}
|
||||
|
||||
function handleListActiveChannels(user) {
|
||||
user.socket.emit("acp-list-activechannels", Server.getServer().packChannelList(false));
|
||||
}
|
||||
|
||||
function handleForceUnload(user, data) {
|
||||
var name = data.name;
|
||||
if (typeof name !== "string") {
|
||||
return;
|
||||
}
|
||||
|
||||
var sv = Server.getServer();
|
||||
if (!sv.isChannelLoaded(name)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var chan = sv.getChannel(name);
|
||||
var users = Array.prototype.slice.call(chan.users);
|
||||
chan.emit("empty");
|
||||
users.forEach(function (u) {
|
||||
u.kick("Channel shutting down");
|
||||
});
|
||||
}
|
||||
|
||||
function init(user) {
|
||||
var s = user.socket;
|
||||
s.on("acp-announce", handleAnnounce.bind(this, user));
|
||||
|
@ -251,6 +275,8 @@ function init(user) {
|
|||
s.on("acp-reset-password", handleResetPassword.bind(this, user));
|
||||
s.on("acp-list-channels", handleListChannels.bind(this, user));
|
||||
s.on("acp-delete-channel", handleDeleteChannel.bind(this, user));
|
||||
s.on("acp-list-activechannels", handleListActiveChannels.bind(this, user));
|
||||
s.on("acp-force-unload", handleForceUnload.bind(this, user));
|
||||
|
||||
db.listGlobalBans(function (err, bans) {
|
||||
if (err) {
|
||||
|
|
|
@ -195,7 +195,9 @@ Server.prototype.packChannel = function (c) {
|
|||
usercount: c.users.length,
|
||||
voteskip_eligible: c.calcVoteskipMax(),
|
||||
users: [],
|
||||
chat: Array.prototype.slice.call(c.chatbuffer)
|
||||
chat: Array.prototype.slice.call(c.chatbuffer),
|
||||
registered: c.registered,
|
||||
public: c.opts.show_public
|
||||
};
|
||||
|
||||
for (var i = 0; i < c.users.length; i++) {
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
window.socket = io.connect(IO_URL, opts);
|
||||
window.socket.on("connect", function () {
|
||||
window.socket.emit("initACP");
|
||||
window.socket.emit("acp-list-activechannels");
|
||||
});
|
||||
|
||||
window.socket.on("errMessage", function (data) {
|
||||
|
@ -346,6 +347,48 @@ socket.on("acp-delete-channel", function (data) {
|
|||
.remove();
|
||||
});
|
||||
|
||||
/* Active channels */
|
||||
socket.on("acp-list-activechannels", function (channels) {
|
||||
var tbl = $("#acp-loaded-channels table");
|
||||
tbl.find("tbody").remove();
|
||||
|
||||
channels.sort(function (a, b) {
|
||||
if (a.usercount === b.usercount) {
|
||||
var x = a.name.toLowerCase();
|
||||
var y = b.name.toLowerCase();
|
||||
return x === y ? 0 : (x > y ? 1 : -1);
|
||||
}
|
||||
|
||||
return a.usercount > b.usercount ? -1 : 1;
|
||||
});
|
||||
|
||||
channels.forEach(function (c) {
|
||||
var tr = $("<tr/>").appendTo(tbl);
|
||||
var name = $("<td/>").appendTo(tr);
|
||||
$("<a/>").attr("href", "/r/" + c.name)
|
||||
.text(c.pagetitle + " (/r/" + c.name + ")")
|
||||
.appendTo(name);
|
||||
var usercount = $("<td/>").text(c.usercount).appendTo(tr);
|
||||
var nowplaying = $("<td/>").text(c.mediatitle).appendTo(tr);
|
||||
var registered = $("<td/>").text(c.registered).appendTo(tr);
|
||||
var public = $("<td/>").text(c.public).appendTo(tr);
|
||||
var unload = $("<td/>").appendTo(tr);
|
||||
$("<button/>").addClass("btn btn-danger btn-xs").text("Force Unload")
|
||||
.appendTo(unload)
|
||||
.click(function () {
|
||||
if (confirm("Are you sure you want to unload /r/" + c.name + "?")) {
|
||||
socket.emit("acp-force-unload", {
|
||||
name: c.name
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
$("#acp-lchannels-refresh").click(function () {
|
||||
socket.emit("acp-list-activechannels");
|
||||
});
|
||||
|
||||
/* Initialize keyed table sorts */
|
||||
$("table").each(function () {
|
||||
var table = $(this);
|
||||
|
|
Loading…
Reference in New Issue