Skip to content
Browse files

Added the lastest stuff to nodrr's github

  • Loading branch information...
1 parent f38f25b commit e195c97299860441523388a29b8a5be727a94301 Travis Glines committed Apr 29, 2011
Showing with 109 additions and 7 deletions.
  1. +2 −0 app.js
  2. +11 −3 controllers/home.js
  3. +13 −0 controllers/nod.js
  4. +15 −0 controllers/user.js
  5. +3 −0 fb_creds.js
  6. +25 −0 global_funcs.js
  7. +1 −0 models/nod.js
  8. +5 −2 public/css/style.css
  9. 0 public/favicon.ico
  10. +13 −1 views/home.jade
  11. +6 −1 views/layout.jade
  12. +15 −0 views/user.jade
View
2 app.js
@@ -91,6 +91,8 @@ require('./global_funcs.js');
require('./controllers/home.js');
require('./controllers/auth.js');
require('./controllers/edit.js');
+require('./controllers/nod.js');
+require('./controllers/user.js');
//Only listen on $ node app.js
if (!module.parent) {
View
14 controllers/home.js
@@ -1,7 +1,15 @@
app.get('/', function(req, res){
loadAccount(req,function(account){
- res.local('account', account);
- res.local('title', 'Nodrr');
- res.render('home');
+ var nods_per_page = 25;
+ Nod.find({},{}, {sort: [['date','descending']], limit: nods_per_page},function(err,nods){
+ res.local('nods', nods);
+ res.local('account', account);
+ res.local('title', 'Nodrr');
+ try{
+ res.render('home');
+ }
+ catch(err){
+ }
+ });
});
});
View
13 controllers/nod.js
@@ -0,0 +1,13 @@
+app.post('/nod', function(req, res){
+ loadAccount(req,function(account){
+ if(account && account.username){
+ var n = new Nod();
+ n.username = account.username;
+ n.text = req.body.nod;
+ n.date = new Date();
+ n.save(function(err){
+ res.redirect('/');
+ });
+ }
+ });
+});
View
15 controllers/user.js
@@ -0,0 +1,15 @@
+app.get('/:username', function(req, res){
+ loadAccount(req,function(account){
+ Account.findOne({username:req.params.username},function(err,user){
+ var search_regex = new RegExp('@'+req.params.username,'i');
+ var nods_per_page = 25;
+ Nod.find({ $or : [{username:req.params.username},{text:search_regex}] },{}, {sort: [['date','descending']], limit: nods_per_page},function(err,nods){
+ res.local('user', user);
+ res.local('nods', nods);
+ res.local('account', account);
+ res.local('title', 'Nodrr - '+req.params.username);
+ res.render('user');
+ });
+ });
+ });
+});
View
3 fb_creds.js
@@ -0,0 +1,3 @@
+fbId = "78346873242";
+fbSecret = "7fwfef8sdf8uwef8wef7";
+fbCallbackAddress = 'http://www.nodrr.com/auth/facebook';
View
25 global_funcs.js
@@ -0,0 +1,25 @@
+howLongAgo = function(d1){
+ var d2 = new Date();
+ var diff = d2 - d1;
+ var sec_diff = Math.floor(diff/1000);
+ var min_diff = Math.floor(diff/1000/60);
+ var hrs_diff = Math.floor(diff/1000/60/60);
+ var days_diff = Math.floor(diff/1000/60/60/24);
+
+ if(sec_diff==1)
+ return sec_diff + ' second';
+ else if(sec_diff<60)
+ return sec_diff + ' seconds';
+ else if(min_diff==1)
+ return min_diff + ' minute';
+ else if(min_diff<60)
+ return min_diff + ' minutes';
+ else if(hrs_diff==1)
+ return hrs_diff + ' hour';
+ else if(hrs_diff<24)
+ return hrs_diff + ' hours';
+ else if(days_diff==1)
+ return days_diff + ' day';
+ else
+ return days_diff + ' days';
+}
View
1 models/nod.js
@@ -1,4 +1,5 @@
var NodSchema = new Schema({
+ username: String,
text: String,
date: Date
});
View
7 public/css/style.css
@@ -5,17 +5,20 @@ html,body{
}
div.center{
- width:1000px;
+ width:640px;
margin-left: auto;
margin-right: auto;
position:relative;
}
h1{
- color:#B9C949;
font-family: Helvetica, sans-serif;
font-weight:bold;
font-size:40px;
padding-top:10px;
padding-bottom:10px;
}
+
+div.center a{
+ color:#B9C949;
+}
View
0 public/favicon.ico
No changes.
View
14 views/home.jade
@@ -1 +1,13 @@
-h2 Body stuff here
+-if(account && account.username)
+ h2(style='font-weight:bold;padding-bottom:5px;') Whats going on?
+ form(action='/nod',method='post')
+ textarea(name='nod',style='width:550px;')
+ input(type='submit',value='Nod',style='background-color:#000000;border:solid;border-color:#666666;border-width:1px;color:#E3E3E3;padding:5px;font-weight:bold;cursor:pointer;position:relative;top:-15px;margin-left:5px;')
+
+div(style='width:600px;')
+ -for(var i=0;i<nods.length;i++)
+ div(style='background-color:#000000;padding:10px;margin-top:5px;border:solid;border-color:#666666;border-width:1px;')
+ div
+ a(href='/'+nods[i].username,style='padding-right:10px;')=nods[i].username
+ span=nods[i].text
+ div(style='color:#999999;font-size:12px;')=howLongAgo(nods[i].date)+' ago'
View
7 views/layout.jade
@@ -10,12 +10,17 @@ html(lang="en")
body
div.center
-if(account && account.username)
- div(style='float:right;')=account.username
+ div(style='float:right;margin-top:20px;position:relative;left:-60px;')
+ a(href='/'+account.username,style='margin-right:20px;')=account.username
+ a(href='/logout') Logout
-else if(!account)
div#facebook_login(style='position:relative;float:right;width:200px;padding-top:10px;')
div#fb-login.fb_button(style='float:left; background-position: left -188px')
a.fb_button_medium(href='/auth/facebook')
span#fb_login_text.fb_button_text Connect with Facebook
+ h2
+ span Check out my startup (also using node.js) @
+ a(href='http://www.exipe.com',style='color:#B9C949;') Exipe.com
h1
a(href='/',style='color:#B9C949;') Nodrr
div
View
15 views/user.jade
@@ -0,0 +1,15 @@
+h2(style='font-weight:bold;font-size:20px;text-align:center;')='@'+user.username
+
+-if(account && account.username && account.username == user.username)
+ h2(style='font-weight:bold;padding-bottom:5px;') Whats going on?
+ form(action='/nod',method='post')
+ textarea(name='nod',style='width:550px;')
+ input(type='submit',value='Nod',style='background-color:#000000;border:solid;border-color:#666666;border-width:1px;color:#E3E3E3;padding:5px;font-weight:bold;cursor:pointer;position:relative;top:-15px;margin-left:5px;')
+
+div(style='width:600px;')
+ -for(var i=0;i<nods.length;i++)
+ div(style='background-color:#000000;padding:10px;margin-top:5px;border:solid;border-color:#666666;border-width:1px;')
+ div
+ a(href='/'+nods[i].username,style='padding-right:10px;')=nods[i].username
+ span=nods[i].text
+ div(style='color:#999999;font-size:12px;')=howLongAgo(nods[i].date)+' ago'

0 comments on commit e195c97

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