Skip to content

Commit

Permalink
Let's auto generate list of current users for homepage.
Browse files Browse the repository at this point in the history
  • Loading branch information
DanBUK committed Jul 17, 2011
1 parent 3df746a commit 4053574
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 6 deletions.
4 changes: 4 additions & 0 deletions public/css/style.css
Expand Up @@ -37,4 +37,8 @@ span.post_date {


div.post_nickname { div.post_nickname {


}

a.nickname_list {
margin-right: 10px;
} }
28 changes: 27 additions & 1 deletion server.js
Expand Up @@ -21,6 +21,21 @@ var users_db = couchdb.database('hub_users');
lib.ensure_db_exists.call(users_db, function (err, rv) {}); lib.ensure_db_exists.call(users_db, function (err, rv) {});
var nicks_db = couchdb.database('hub_nicks'); var nicks_db = couchdb.database('hub_nicks');
lib.ensure_db_exists.call(nicks_db, function (err, rv) {}); 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 handle_new_user_meta = function (type, id, meta, promise) {
var key = type + '_' + id; var key = type + '_' + id;
Expand Down Expand Up @@ -114,7 +129,18 @@ app.configure(function () {
}); });


app.get('/', function (req, res) { 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) { app.get('/logout', function (req, res) {
Expand Down
14 changes: 9 additions & 5 deletions views/home.jade
@@ -1,13 +1,17 @@
- if (everyauth) -if (everyauth)
- if (everyauth.loggedIn) -if (everyauth.loggedIn)
- if (!everyauth.user.nickname) -if (!everyauth.user.nickname)
p You have no nickname assigned to this login method. Please input your existing or desired nickname. p You have no nickname assigned to this login method. Please input your existing or desired nickname.
form(action='/nickname/set',method='post') form(action='/nickname/set',method='post')
input(type='text',name='nickname',size='16') input(type='text',name='nickname',size='16')
button(type='submit') Submit button(type='submit') Submit
- else -else
h5 What happening? h5 What happening?
form(action='/post/add',method='post') form(action='/post/add',method='post')
textarea(name='body',rows='3',cols='40') textarea(name='body',rows='3',cols='40')
button(type='submit') Post 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]
2 changes: 2 additions & 0 deletions views/layout.jade
Expand Up @@ -6,6 +6,8 @@ html(lang="en")
script(src='http://static.ak.fbcdn.net/connect/en_US/core.js') script(src='http://static.ak.fbcdn.net/connect/en_US/core.js')
script(type='text/javascript',src='/js/app.js') script(type='text/javascript',src='/js/app.js')
body 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') div(class='header')
h2 hub.f-box.org h2 hub.f-box.org
a(href='/') Home a(href='/') Home
Expand Down

0 comments on commit 4053574

Please sign in to comment.