Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

  • Loading branch information...
commit 40535749df6ef8ed89f58f7fcd991dc7b8cb39cb 1 parent 3df746a
Daniel Bartlett authored
4 public/css/style.css
@@ -37,4 +37,8 @@ span.post_date {
37 37
38 38 div.post_nickname {
39 39
  40 +}
  41 +
  42 +a.nickname_list {
  43 + margin-right: 10px;
40 44 }
28 server.js
@@ -21,6 +21,21 @@ var users_db = couchdb.database('hub_users');
21 21 lib.ensure_db_exists.call(users_db, function (err, rv) {});
22 22 var nicks_db = couchdb.database('hub_nicks');
23 23 lib.ensure_db_exists.call(nicks_db, function (err, rv) {});
  24 +setTimeout(function () {
  25 + nicks_db.view('nicks/all', function (err, resp) {
  26 + if (err && err.error == 'not_found') {
  27 + nicks_db.save('_design/nicks', {
  28 + all: {
  29 + map: function (doc) {
  30 + emit(undefined, doc.id);
  31 + }
  32 + }
  33 + });
  34 + } else if (err) {
  35 + console.error('Failed to load nicks/all view.');
  36 + }
  37 + });
  38 +}, 500);
24 39
25 40 var handle_new_user_meta = function (type, id, meta, promise) {
26 41 var key = type + '_' + id;
@@ -114,7 +129,18 @@ app.configure(function () {
114 129 });
115 130
116 131 app.get('/', function (req, res) {
117   - res.render('home');
  132 + var nicks = new Array();
  133 + nicks_db.view('nicks/all', function (err, resp) {
  134 + if (err) {
  135 + console.error(err);
  136 + } else {
  137 + for(var i in resp) {
  138 + nicks.push(resp[i].id);
  139 + }
  140 + }
  141 + res.local('nicks', nicks);
  142 + res.render('home');
  143 + });
118 144 });
119 145
120 146 app.get('/logout', function (req, res) {
14 views/home.jade
... ... @@ -1,13 +1,17 @@
1   -- if (everyauth)
2   - - if (everyauth.loggedIn)
3   - - if (!everyauth.user.nickname)
  1 +-if (everyauth)
  2 + -if (everyauth.loggedIn)
  3 + -if (!everyauth.user.nickname)
4 4 p You have no nickname assigned to this login method. Please input your existing or desired nickname.
5 5 form(action='/nickname/set',method='post')
6 6 input(type='text',name='nickname',size='16')
7 7 button(type='submit') Submit
8   - - else
  8 + -else
9 9 h5 What happening?
10 10 form(action='/post/add',method='post')
11 11 textarea(name='body',rows='3',cols='40')
12 12 button(type='submit') Post
13   -
  13 +-if(typeof nicks != 'undefined')
  14 + div
  15 + h4 Users
  16 + -for(var i = 0; i < nicks.length; i++)
  17 + a(class='nickname_list',href='/' + nicks[i])= nicks[i]
2  views/layout.jade
@@ -6,6 +6,8 @@ html(lang="en")
6 6 script(src='http://static.ak.fbcdn.net/connect/en_US/core.js')
7 7 script(type='text/javascript',src='/js/app.js')
8 8 body
  9 + a(href='http://github.com/DanBUK/hub')
  10 + 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')
9 11 div(class='header')
10 12 h2 hub.f-box.org
11 13 a(href='/') Home

0 comments on commit 4053574

Please sign in to comment.
Something went wrong with that request. Please try again.