Permalink
Browse files

got pid incrementing again

  • Loading branch information...
thecolorblue committed Apr 7, 2011
1 parent 927f89d commit 432476a9caaf463ba4367efd141f401d74c34708
Showing with 44 additions and 26 deletions.
  1. +15 −10 murray.js
  2. +2 −2 readme.md
  3. +9 −6 resources/admin.js
  4. +5 −0 resources/css.css
  5. +2 −2 server.js
  6. +6 −6 views/index.jade
  7. +5 −0 views/layout.jade
View
@@ -29,7 +29,7 @@ exports.getposts = function(req,res,options,callback){
if(req.cookies.loggedin == 1){
var logged = true;
} else {
- var logged = false;
+ var logged = false ;
}
if(callback != ''){
res.render('index.jade', {posts: posted, logged: logged});
@@ -50,25 +50,30 @@ exports.getposts = function(req,res,options,callback){
*/
exports.createpost = function(req,res,newpost){
var blogpost = req.body;
+ console.log(req.body);
db.open(function(err, db){
db.collection('settings', function(err, collection){
- collection.find({'postcount':'num'}, function(err, cursor){
+ collection.find({}, function(err, cursor){
cursor.toArray(function(err, posted){
- var postnum = posted[0].actual;
- blogpost.pid = postnum + 1;
+ var postnum = posted[0].postcount;
+ console.log(posted[0].postcount);
+ blogpost.pid = ++postnum;
blogpost.date = new Date();
blogpost.user = req.cookies.user;
console.log(blogpost);
db.collection('posts',function(err,collection){
- collection.insert([blogpost],function(err,docs){
- res.send('saved new post');
- collection.update(
- {'postcount':'num'},
- {'postcount':'num','actual':blogpost.pid},
+ collection.insert([blogpost],function(err,docs){
+ db.collection('settings',function(err,collection){
+ collection.update({name:'postcounter'},
+ {$inc:{postcount:1}}, {safe:true},
function(err,docs){
+ console.log(err);
+ console.log(docs);
db.close();
+ res.send('saved new post\n</p><a href="/">Head Back Home</a></p>\n');
}
);
+ });
});
});
});
@@ -92,7 +97,7 @@ exports.login = function(req,res){
{ path: '/', expires: new Date(Date.now() + 900000), httpOnly: true });
res.cookie('user', req.body.name,
{ path: '/', expires: new Date(Date.now() + 900000), httpOnly: true });
- res.send('You logged in!');
+ res.send('You logged in!\n</p><a href="/">Head Back Home</a></p>');
} else {
res.send('sorry, try again');
}
View
@@ -9,11 +9,11 @@ after you enter mongo:
use murray // opens murry db
// create settings
- settings = {postcount:'num',actual:0}
+ settings = {postcount:'num', actual:0}
db.settings.save(settings)
// create first user
// the only thing that is really required is name and pass
- admin = {id:1,name:'admin',pass:'secretpassword','email':'you@yourdomain.com'}
+ admin = {id:1, name:'admin', pass:'secretpassword', 'email':'you@yourdomain.com'}
db.users.save(admin)
View
@@ -2,21 +2,24 @@ $(document).ready(function(){
$('body').append('<div id="toolbar">toolbar</div>');
$('#toolbar').css({'position':'fixed','right':'50px'});
$('#toolbar').append('<ul id="actions"><li id="createpostli"><a href="#" id="createpostlink">create post</a></li></ul>');
- $('#actions').css('position','relative').append('<li><a href="logout">logout</a></li>');
+ $('#actions').css({'position':'relative','list-style-type':'none'}).append('<li><a href="logout">logout</a></li>');
var postformstyle = {
'position':'absolute',
'right':'100px',
'background':'#ddd',
'display':'none',
'padding':'15px'
};
- $('#createpostli').append('<div id="createpostform"><form method="post" action="/create/post"><ul><li>title</li></ul></form></div>');
+ $('#createpostli').append('<div id="createpostform"><form method="post" action="/create/post"><ul></ul></form></div>');
$('#createpostform').css(postformstyle);
- $('#createpostform form ul').append('<li><input type="text" name="title"></input>');
- $('#createpostform form ul').append('<li><input type="text" name="body"></input>');
- $('#createpostform form ul').append('<li><input type="submit" name="submit"></input>');
+ $('#createpostform form ul').append('<li>title</li>');
+ $('#createpostform form ul').append('<li><input type="text" name="title"></input></li>');
+ $('#createpostform form ul').append('<li>Body</li>');
+ $('#createpostform form ul').append('<li><input type="text" name="body"></input></li>');
+ $('#createpostform form ul').append('<li><input type="submit" name="submit"></input></li>');
$('#createpostlink').click(function(){
- $('#createpostform').css('display','block');
+ $('#createpostform').show(700);
+ console.log('opened');
});
});
View
@@ -0,0 +1,5 @@
+.pid {
+position:absolute;
+bottom:-10px;
+right:20px;
+}
View
@@ -40,7 +40,7 @@ app.get('/admin/settings', function(req,res){
app.get('/new', function(req,res){
console.log(req);
- res.render('newpost.jade');
+ res.render('newpost.jade',{posts: '', logged: ''});
});
app.post('/create/post', function(req, res){
murray.isIn(req.cookies,function(){
@@ -54,7 +54,7 @@ app.post('/create/user', function(req,res){
});
app.get('/login', function(req,res){
- res.render('loginform.jade');
+ res.render('loginform.jade',{posts: '', logged: ''});
});
app.post('/login', function(req,res){
murray.login(req,res);
View
@@ -2,10 +2,10 @@ p would you like to login?
<a href='/login' title='login page'>Login</a>
p #{logged}
- each post in posts
- h3(style="display:inline") #{post.title}
- h4(style="display:inline") writen by: #{post.author}
- p #{post.body}
- p #{post.date}
+ div.post(style='position:relative')
+ h3(style="display:inline") #{post.title}
+ h4(style="display:inline") writen by: #{post.user}
+ p #{post.body}
+ p #{post.date}
+ p.pid #{post.pid}
<hr/>
-- if (logged == true)
- script(src='/admin.js',type='text/javascript')
View
@@ -4,6 +4,7 @@ html
title Blog Posts
script(src='/jquery.min.js',type='text/javascript')
link(rel='stylesheet', href='/960.css')
+ link(rel='stylesheet', href='/css.css')
body
div.container_12
div.grid_12
@@ -14,3 +15,7 @@ html
p sidebar
div.grid_12
p footer
+ - if (logged != '')
+ - if (logged == true)
+ script(src='/admin.js',type='text/javascript')
+

0 comments on commit 432476a

Please sign in to comment.