From 7307c9c82e9b1a0b238e4c35308cbdc5aa246f28 Mon Sep 17 00:00:00 2001 From: calzoneman Date: Mon, 20 Jan 2014 17:52:36 -0600 Subject: [PATCH] Work on index page --- lib/server.js | 43 +++++++++++++++++++++++++++++++++++++++++++ lib/web/webserver.js | 4 +++- templates/index.jade | 25 +++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 1 deletion(-) diff --git a/lib/server.js b/lib/server.js index 2fa57317..da25ba51 100644 --- a/lib/server.js +++ b/lib/server.js @@ -255,6 +255,49 @@ Server.prototype.unloadChannel = function (chan) { 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) { if (status === undefined) status = 200; diff --git a/lib/web/webserver.js b/lib/web/webserver.js index c64f9ace..74858ce4 100644 --- a/lib/web/webserver.js +++ b/lib/web/webserver.js @@ -101,9 +101,11 @@ function handleIndex(req, res) { if (req.cookies.auth) { loginName = req.cookies.auth.split(':')[0]; } + sendJade(res, 'index', { loggedIn: loginName !== false, - loginName: loginName + loginName: loginName, + channels: Server.getServer().packChannelList(true) }); } diff --git a/templates/index.jade b/templates/index.jade index 09822ef9..56f0ef7c 100644 --- a/templates/index.jade +++ b/templates/index.jade @@ -12,5 +12,30 @@ html(lang="en") ul.nav.navbar-nav mixin navdefaultlinks("/") 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 My Channels page. include footer mixin footer() + script(type="text/javascript"). + $("#channelname").keydown(function (ev) { + if (ev.keyCode === 13) { + location.href = "/r/" + $("#channelname").val(); + } + });