Work on index page

This commit is contained in:
calzoneman 2014-01-20 17:52:36 -06:00
parent 24fcce3f87
commit 7307c9c82e
3 changed files with 71 additions and 1 deletions

View file

@ -255,6 +255,49 @@ Server.prototype.unloadChannel = function (chan) {
chan.dead = true; chan.dead = true;
}; };
Server.prototype.packChannelList = function (publicOnly) {
var channels = this.channels.filter(function (c) {
if (!publicOnly) {
return true;
}
return c.opts.show_public && !c.opts.password;
});
return channels.map(this.packChannel.bind(this));
};
Server.prototype.packChannel = function (c) {
var data = {
name: c.name,
pagetitle: c.opts.pagetitle,
mediatitle: c.playlist.current ? c.playlist.current.media.title : "-",
usercount: c.users.length,
voteskip_eligible: c.calcVoteskipMax(),
users: [],
chat: Array.prototype.slice.call(c.chatbuffer)
};
for (var i = 0; i < c.users.length; i++) {
if (c.users[i].name !== "") {
var name = c.users[i].name;
var rank = c.users[i].rank;
if (rank >= 255) {
name = "!" + name;
} else if (rank >= 4) {
name = "~" + name;
} else if (rank >= 3) {
name = "&" + name;
} else if (rank >= 2) {
name = "@" + name;
}
data.users.push(name);
}
}
return data;
};
Server.prototype.logHTTP = function (req, status) { Server.prototype.logHTTP = function (req, status) {
if (status === undefined) if (status === undefined)
status = 200; status = 200;

View file

@ -101,9 +101,11 @@ function handleIndex(req, res) {
if (req.cookies.auth) { if (req.cookies.auth) {
loginName = req.cookies.auth.split(':')[0]; loginName = req.cookies.auth.split(':')[0];
} }
sendJade(res, 'index', { sendJade(res, 'index', {
loggedIn: loginName !== false, loggedIn: loginName !== false,
loginName: loginName loginName: loginName,
channels: Server.getServer().packChannelList(true)
}); });
} }

View file

@ -12,5 +12,30 @@ html(lang="en")
ul.nav.navbar-nav ul.nav.navbar-nav
mixin navdefaultlinks("/") mixin navdefaultlinks("/")
mixin navloginlogout("/") mixin navloginlogout("/")
section#mainpage
.container
.col-lg-9.col-md-9
h3 Public Channels
table.table.table-bordered.table-striped
thead
th Channel
th # Connected
th Now Playing
tbody
each chan in channels
tr
td #{chan.pagetitle} (#{chan.name})
td= chan.usercount
td= chan.mediatitle
.col-lg-3.col-md-3
h3 Enter Channel
input#channelname.form-control(type="text", placeholder="Channel Name")
p.text-muted New channels can be registered from the <a href="/account/channels">My Channels</a> page.
include footer include footer
mixin footer() mixin footer()
script(type="text/javascript").
$("#channelname").keydown(function (ev) {
if (ev.keyCode === 13) {
location.href = "/r/" + $("#channelname").val();
}
});