fixed a bug in templates, introduced categories, added default setup script onload, moved home.tpl code over to category, created hierachies

This commit is contained in:
psychobunny
2013-05-06 22:05:42 +00:00
parent 178bc82a55
commit fa64e84dcc
8 changed files with 72 additions and 48 deletions

View File

@@ -1,8 +1,7 @@
var RDB = require('./redis.js'),
utils = require('./utils.js'),
marked = require('marked'),
user = require('./user.js'),
async = require('async');
user = require('./user.js');
(function(Posts) {

View File

@@ -11,12 +11,14 @@ var RDB = require('./redis.js'),
Topics.get = function(callback, start, end) {
Topics.get = function(callback, category_id, start, end) {
if (start == null) start = 0;
if (end == null) end = start + 10;
//build a proper wrapper for this and move it into above function later
var range_var = (category_id) ? 'categories:' + category_id + ':tid' : 'topics:tid';
RDB.lrange('topics:tid', start, end, function(tids) {
RDB.lrange(range_var, start, end, function(tids) {
var title = [],
uid = [],
timestamp = [],
@@ -64,17 +66,17 @@ var RDB = require('./redis.js'),
});
}
callback({'topics': topics});
callback({'category_id': category_id, 'topics': topics});
});
}
);
} else callback([]);
} else callback({'category_id': category_id, 'topics': []});
});
}
Topics.post = function(socket, uid, title, content, category) {
Topics.post = function(socket, uid, title, content, category_id) {
if (uid === 0) {
socket.emit('event:alert', {
@@ -102,8 +104,8 @@ var RDB = require('./redis.js'),
if (category) {
RDB.lpush('topics:' + category + ':tid', tid);
if (category_id) {
RDB.lpush('categories:' + category_id + ':tid', tid);
}
var slug = tid + '/' + utils.slugify(title);

View File

@@ -147,6 +147,10 @@ passport.deserializeUser(function(uid, done) {
res.send(templates['header'] + '<script>templates.ready(function(){ajaxify.go("' + 'topic/' + req.params.topic_id + '");});</script>' + templates['footer']);
});
app.get('/category/:category_id/:slug?', function(req, res) {
res.send(templates['header'] + '<script>templates.ready(function(){ajaxify.go("' + 'category/' + req.params.category_id + '");});</script>' + templates['footer']);
});
app.get('/confirm/:code', function(req, res) {
res.send(templates['header'] + '<script>templates.ready(function(){ajaxify.go("' + 'confirm/' + req.params.code + '");});</script>' + templates['footer']);
});
@@ -155,7 +159,7 @@ passport.deserializeUser(function(uid, done) {
function api_method(req, res) {
switch(req.params.method) {
case 'home' :
global.modules.topics.get(function(data) {
global.modules.categories.get(function(data) {
res.send(JSON.stringify(data));
});
break;
@@ -185,6 +189,12 @@ passport.deserializeUser(function(uid, done) {
res.send(JSON.stringify(data));
}, req.params.id, (req.user) ? req.user.uid : 0);
break;
case 'category' :
global.modules.topics.get(function(data) {
console.log(data);
res.send(JSON.stringify(data));
}, req.params.id);
break;
case 'account' :
get_account_fn(req, res, function(userData) {
res.send(JSON.stringify(userData));

View File

@@ -161,7 +161,7 @@ var SocketIO = require('socket.io').listen(global.server,{log:false}),
});
socket.on('api:topics.post', function(data) {
modules.topics.post(socket, uid, data.title, data.content);
modules.topics.post(socket, uid, data.title, data.content, data.category_id);
});
socket.on('api:posts.reply', function(data) {