Node.js based forum software built for the modern web
redis - added mget and multi, finished initial topics listview on home page, finished get topics method calls
psychobunnya16f72e11c5e
diff --git a/public/templates/header.tpl b/public/templates/header.tplindex 9b3fa01468..8d6f9fa6b4 100644--- a/public/templates/header.tpl+++ b/public/templates/header.tpl@@ -42,7 +42,7 @@height: 350px;left: 0px;bottom: 0px;- opacity: 0.8;+ background: white;}#post_window input {@@ -68,15 +68,40 @@}#post_window .post-title-container {+ opacity: 0.8;height: 50px;}#post_window .post-content-container {+ opacity: 0.8;background: #000;width: 100%;height: 300px;}++ .topic-container {+ list-style-type: none;+ padding: 0;+ margin: 0;+ border: 1px solid #eee;+ margin-top: 50px;+ }+ .topic-container li.topic-row:nth-child(odd) {+ background-color:#fdfdfd;+ }+ .topic-container li.topic-row:nth-child(even) {+ background-color:#fff;+ }+ .topic-container li.topic-row {+ cursor: pointer;+ border-bottom: 1px solid #eee;+ padding: 10px;++ }+ .topic-container li.topic-row:hover {+ background-color: #eee;+ }</style></head>diff --git a/public/templates/home.tpl b/public/templates/home.tplindex ae29dc4787..35b4880009 100644--- a/public/templates/home.tpl+++ b/public/templates/home.tpl@@ -1,5 +1,12 @@<button id="new_post" class="btn btn-primary btn-large">New Post</button>-+<ul class="topic-container">+<!-- BEGIN topics -->+<li class="topic-row">+ <h4>{topics.title}</h4>+ <p>Posted on {topics.timestamp} by user {topics.uid}. {topics.post_count} replies.</p>+</li>+<!-- END topics -->+</ul><script type="text/javascript">var new_post = document.getElementById('new_post');new_post.onclick = function() {@@ -7,7 +14,7 @@ new_post.onclick = function() {}jQuery('document').ready(function() {-+});diff --git a/src/redis.js b/src/redis.jsindex 1582fb0f03..0c2a6d2e04 100644--- a/src/redis.js+++ b/src/redis.js@@ -33,6 +33,16 @@});};+ RedisDB.mget = function(keys, callback, error_handler) {+ db.mget(keys, function(error, data) {+ return_handler(error, data, callback, error_handler);+ });+ };++ RedisDB.multi = function() {+ return db.multi();+ }+RedisDB.del = function(key, callback) {db.del(key);}diff --git a/src/templates.js b/src/templates.jsindex 73766a33c0..9c909aceec 100644--- a/src/templates.js+++ b/src/templates.js@@ -62,7 +62,7 @@ var fs = require('fs');for (var d in data) {if (data.hasOwnProperty(d)) {- if (data[d] instanceof String) {+ if (data[d] instanceof String || data[d] === null) {continue;} else if (data[d].constructor == Array) {namespace += d;diff --git a/src/topics.js b/src/topics.jsindex 96f5ce8d4b..7af7f2eee8 100644--- a/src/topics.js+++ b/src/topics.js@@ -12,23 +12,74 @@ var RDB = require('./redis.js'),// *tid:1:uid// *tid:1:posts (array of pid)// *tid:1:timestamp- // *uid:1:topics+ // *uid:1:tozpics// *topic:slug:how-to-eat-chicken:tid- Topics.get_by_category = function(category, start, end) {+ Topics.get_by_category = function(callback, category, start, end) {}- Topics.get = function(start, end) {+ Topics.generate_forum_body = function(callback, start, end) {+ var forum_body = global.templates['home'];+++ Topics.get(function(data) {+ console.log({'topics': data});+ forum_body = forum_body.parse({'topics': data});+ callback(forum_body);+ }, start, end);+ };++ Topics.get = function(callback, start, end) {if (start == null) start = 0;if (end == null) end = start + 10;- RDB.lrange('topics:tid', start, end, function() {- global.socket.emit+ RDB.lrange('topics:tid', start, end, function(tids) {+ var title = [],+ uid = [],+ timestamp = [],+ posts = [];++ for (var i=0, ii=tids.length; i<ii; i++) {+ title.push('tid:' + tids[i] + ':title');+ uid.push('tid:' + tids[i] + ':uid');+ timestamp.push('tid:' + tids[i] + ':timestamp');+ posts.push('tid:' + tids[i] + ':posts');+ }+ /*RDB.mget(topic, function(topic_data) {+ callback(topic_data);+ });*/++ RDB.multi()+ .mget(title)+ .mget(uid)+ .mget(timestamp)+ .mget(posts)+ .exec(function(err, replies) {+ title = replies[0];+ uid = replies[1];+ timestamp = replies[2];+ posts = replies[3];++ var topics = [];+ for (var i=0, ii=title.length; i<ii; i++) {+ topics.push({+ 'title' : title[i],+ 'uid' : uid[i],+ 'timestamp' : timestamp[i],+ 'posts' : posts[i],+ 'post_count' : 0+ });+ }++ callback(topics);+ });});++}diff --git a/src/webserver.js b/src/webserver.jsindex e88c514b93..eeaad273ee 100644--- a/src/webserver.js+++ b/src/webserver.js@@ -40,11 +40,11 @@ var express = require('express'),// app.use(express.methodOverride());app.get('/', function(req, res) {- //global.modules.topics.get(function() {- // res.send(templates['header'] + templates['home'] + templates['footer']);- //})+ global.modules.topics.generate_forum_body(function(forum_body) {+ res.send(templates['header'] + forum_body + templates['footer']);+ })- res.send(templates['header'] + templates['home'] + templates['footer']);+ //res.send(templates['header'] + templates['home'] + templates['footer']);});app.get('/login', function(req, res) {