List loaded channels on ACP

This commit is contained in:
calzoneman 2013-03-23 13:29:47 -05:00
parent c0fc363f1b
commit 05fd0f26a8
4 changed files with 15 additions and 84 deletions

View File

@ -13,7 +13,8 @@ var Rank = require('./rank.js');
var InfoGetter = require('./get-info.js');
var Media = require('./media.js').Media;
var ChatCommand = require('./chatcommand.js');
var io = require('./server.js').io;
var Server = require('./server.js');
var io = Server.io;
var Channel = function(name) {
console.log("Opening channel " + name);

22
user.js
View File

@ -224,27 +224,21 @@ User.prototype.initCallbacks = function() {
// Handle administration
User.prototype.handleAdm = function(data) {
if(data.cmd == "listloadedchannels") {
if(data.cmd == "listchannels") {
var chans = [];
for(var chan in Server.channels) {
var users = [];
for(var i = 0; i < Server.channels[chan].users.length; i++) {
users.push(Server.channels[chan].users[i].name);
}
var nowplaying = "-";
if(Server.channels[chan].currentMedia != null)
nowplaying = Server.channels[chan].currentMedia.title;
chans.push({
chan: chan,
users: users
name: chan,
usercount: Server.channels[chan].users.length,
nowplaying: nowplaying
});
}
this.socket.emit('adm', {
cmd: "listloadedchannels",
chans: chans
});
}
else if(data.cmd == "listchannels") {
this.socket.emit('adm', {
cmd: "listchannels",
chans: Database.listChannels()
chans: chans
});
}
else if(data.cmd == "listusers") {

View File

@ -53,24 +53,13 @@
</div>
<div class="row" style="margin-top: 20px;">
<div class="span6">
<h3>Channel List</h3>
<h3>Loaded Channels</h3>
<table id="chanlist" class="table table-bordered table-striped">
<thead>
<tr>
<th>id</th>
<th>Channel Name</th>
</tr>
</thead>
</table>
</div>
<div class="span6">
<h3 id="channelh3">Channel: </h3>
<input type="text" placeholder="New Rank">
<table id="chanranks" class="table table-bordered table-striped">
<thead>
<tr>
<th>Username</th>
<th>Rank</th>
<th>Connected Users</th>
<th>Currently Playing</th>
</tr>
</thead>
</table>

View File

@ -28,8 +28,6 @@ function initCallbacks() {
console.log(data);
if(data.cmd == "listchannels")
handleChannelList(data);
if(data.cmd == "listchannelranks")
handleChannelRanks(data);
});
socket.on('login', function(data) {
@ -42,15 +40,9 @@ function initCallbacks() {
$('#logoutform').css('display', '');
$('#loginform').css('display', 'none');
}
socket.emit('adm', {
cmd: "listloadedchannels"
});
socket.emit('adm', {
cmd: "listchannels"
});
socket.emit('adm', {
cmd: "listusers"
});
});
}
@ -59,54 +51,9 @@ function handleChannelList(data) {
$($('#chanlist').children()[1]).remove();
for(var i = 0; i < data.chans.length; i++) {
var row = $('<tr/>').appendTo($('#chanlist'));
var id = $('<td/>').appendTo(row).text(data.chans[i].id);
var name = $('<td/>').appendTo(row).text(data.chans[i].name);
var manage = $('<button/>').addClass("btn pull-right").appendTo(name)
.text('Manage Ranks');
var cname = data.chans[i].name;
manage.click(function() {
manageChannelRanks(this);
}.bind(cname));
}
}
function manageChannelRanks(name) {
manageChannel = name;
$('#channelh3').text('Channel: ' + name);
socket.emit('adm', {
cmd: "listchannelranks",
chan: name
});
}
function handleChannelRanks(data) {
if($('#chanranks').children.length > 1)
$($('#chanranks').children()[1]).remove();
for(var i = 0; i < data.ranks.length; i++) {
var row = $('<tr/>').appendTo($('#chanranks'));
var id = $('<td/>').appendTo(row).text(data.ranks[i].name);
var rank = $('<td/>').appendTo(row);
var rtxt = $('<span/>').appendTo(rank).text(data.ranks[i].rank);
var edit = $('<button/>').addClass("btn pull-right").appendTo(rank)
.text('Edit');
edit.click(function() {
var txt = rtxt.text();
rtxt.text('');
var textbox = $('<input/>').attr('type', 'text').attr('value', txt)
.insertBefore(edit, rank);
textbox.focus();
textbox.blur(function() {
rtxt.text(textbox.val());
socket.emit('adm', {
cmd: "updatechanrank",
chan: manageChannel,
user: id.text(),
rank: parseInt(textbox.val())
});
textbox.remove();
});
});
var usercount = $('<td/>').appendTo(row).text(data.chans[i].usercount);
var nowplaying = $('<td/>').appendTo(row).text(data.chans[i].nowplaying);
}
}