Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Let's auto generate list of current users for homepage.

  • Loading branch information...
commit 40535749df6ef8ed89f58f7fcd991dc7b8cb39cb 1 parent 3df746a
@DanBUK authored
View
4 public/css/style.css
@@ -37,4 +37,8 @@ span.post_date {
div.post_nickname {
+}
+
+a.nickname_list {
+ margin-right: 10px;
}
View
28 server.js
@@ -21,6 +21,21 @@ var users_db = couchdb.database('hub_users');
lib.ensure_db_exists.call(users_db, function (err, rv) {});
var nicks_db = couchdb.database('hub_nicks');
lib.ensure_db_exists.call(nicks_db, function (err, rv) {});
+setTimeout(function () {
+ nicks_db.view('nicks/all', function (err, resp) {
+ if (err && err.error == 'not_found') {
+ nicks_db.save('_design/nicks', {
+ all: {
+ map: function (doc) {
+ emit(undefined, doc.id);
+ }
+ }
+ });
+ } else if (err) {
+ console.error('Failed to load nicks/all view.');
+ }
+ });
+}, 500);
var handle_new_user_meta = function (type, id, meta, promise) {
var key = type + '_' + id;
@@ -114,7 +129,18 @@ app.configure(function () {
});
app.get('/', function (req, res) {
- res.render('home');
+ var nicks = new Array();
+ nicks_db.view('nicks/all', function (err, resp) {
+ if (err) {
+ console.error(err);
+ } else {
+ for(var i in resp) {
+ nicks.push(resp[i].id);
+ }
+ }
+ res.local('nicks', nicks);
+ res.render('home');
+ });
});
app.get('/logout', function (req, res) {
View
14 views/home.jade
@@ -1,13 +1,17 @@
-- if (everyauth)
- - if (everyauth.loggedIn)
- - if (!everyauth.user.nickname)
+-if (everyauth)
+ -if (everyauth.loggedIn)
+ -if (!everyauth.user.nickname)
p You have no nickname assigned to this login method. Please input your existing or desired nickname.
form(action='/nickname/set',method='post')
input(type='text',name='nickname',size='16')
button(type='submit') Submit
- - else
+ -else
h5 What happening?
form(action='/post/add',method='post')
textarea(name='body',rows='3',cols='40')
button(type='submit') Post
-
+-if(typeof nicks != 'undefined')
+ div
+ h4 Users
+ -for(var i = 0; i < nicks.length; i++)
+ a(class='nickname_list',href='/' + nicks[i])= nicks[i]
View
2  views/layout.jade
@@ -6,6 +6,8 @@ html(lang="en")
script(src='http://static.ak.fbcdn.net/connect/en_US/core.js')
script(type='text/javascript',src='/js/app.js')
body
+ a(href='http://github.com/DanBUK/hub')
+ img(style='position: absolute; top: 0; right: 0; border: 0;',alt='Fork me on GitHub',src='https://gs1.wac.edgecastcdn.net/80460E/assets/img/4c7dc970b89fd04b81c8e221ba88ff99a06c6b61/687474703a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f77686974655f6666666666662e706e67')
div(class='header')
h2 hub.f-box.org
a(href='/') Home
Please sign in to comment.
Something went wrong with that request. Please try again.