Created
April 16, 2012 19:28
-
-
Save mikevalstar/2400931 to your computer and use it in GitHub Desktop.
Coding with Node.js Part 4 - section 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Includes | |
| var crypto = require('crypto'); | |
| function hashString(value) { | |
| hash = crypto.createHash('sha1'); | |
| hash.update(value); | |
| return hash.digest('hex'); | |
| } | |
| var AdminPages = module.exports = function AdminPages(){}; | |
| AdminPages.prototype = { | |
| db: null | |
| , initPages: function(app, db){ | |
| this.db = db; | |
| var self = this; | |
| /* ... */ | |
| // post related | |
| app.get ('/Admin/PostList', function(req, res) { self.pagePostList(req, res); } ); | |
| /* ... */ | |
| } | |
| /* ... */ | |
| /* Blog post related */ | |
| , pagePostList: function(req, res){ // List of blog posts | |
| if( !this._checkLogin(req, res) ) return; | |
| var blogpost = this.db.model('blogPost'); | |
| var query = blogpost.find().sort("posted", -1).limit(1000).exec(function(err, docs){ | |
| res.render('admin/postlist', { | |
| title: 'Post Listing', | |
| posts: docs, | |
| showFullNav: false | |
| }); | |
| }); | |
| } | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| h2 Admin - Post Listing | |
| table.aPostList | |
| thead | |
| tr | |
| th Post ID | |
| th Title | |
| th Int/Ext | |
| th Posted | |
| tbody | |
| - posts.forEach(function(item){ | |
| tr | |
| td= item.sid | |
| td: a(href="/Admin/Post/" + item.sid)= item.title | |
| td | |
| - if(item.ext_link != ""){ | |
| | External | |
| - }else{ | |
| | Internal | |
| - } | |
| td: time= item.posted | |
| - }) | |
| a(href="/Admin/NewPost") Create a new post |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment