Skip to content

Node.js based forum software built for the modern web

small refactor plus breadcrumbs for all ur pages

psychobunnyae2be687b80a
diff --git a/public/templates/category.tpl b/public/templates/category.tpl
index 513070c198..5abee5a796 100644
--- a/public/templates/category.tpl
+++ b/public/templates/category.tpl
@@ -1,3 +1,11 @@
+<div class="container">
+ <ul class="breadcrumb">
+ <li><a href="/">Home</a><span class="divider">/</span></li>
+ <li class="active">{category_name}</li>
+ <div id="category_active_users"></div>
+ </ul>
+</div>
+
<button id="new_post" class="btn btn-primary btn-large {show_topic_button}">New Topic</button>
<ul class="topic-container">
<!-- BEGIN topics -->
diff --git a/public/templates/topic.tpl b/public/templates/topic.tpl
index 25c48d99ac..8408e8fb2a 100644
--- a/public/templates/topic.tpl
+++ b/public/templates/topic.tpl
@@ -1,6 +1,7 @@
<div class="container">
<ul class="breadcrumb">
- <li><a href="/">Home</a> <span class="divider">/</span></li>
+ <li><a href="/">Home</a><span class="divider">/</span></li>
+ <li><a href="/category/{category_slug}">{category_name}</a><span class="divider">/</span></li>
<li class="active">{topic_name}</li>
<div id="thread_active_users"></div>
</ul>
diff --git a/src/categories.js b/src/categories.js
index 545538d377..5173e64955 100644
--- a/src/categories.js
+++ b/src/categories.js
@@ -25,60 +25,66 @@ var RDB = require('./redis.js'),
});
};
-
+ Categories.edit = function(data, callback) {
+ // just a reminder to self that name + slugs are stored into topics data as well.
+ };
Categories.get = function(callback) {
RDB.lrange('categories:cid', 0, -1, function(cids) {
- var name = [],
- description = [],
- icon = [],
- blockclass = [],
- slug = [];
+ Categories.get_category(cids, callback);
+ });
+ }
- for (var i=0, ii=cids.length; i<ii; i++) {
- name.push('cid:' + cids[i] + ':name');
- description.push('cid:' + cids[i] + ':description');
- icon.push('cid:' + cids[i] + ':icon');
- blockclass.push('cid:' + cids[i] + ':blockclass');
- slug.push('cid:' + cids[i] + ':slug');
- }
+ Categories.get_category = function(cids, callback) {
+ var name = [],
+ description = [],
+ icon = [],
+ blockclass = [],
+ slug = [];
- if (cids.length > 0) {
- RDB.multi()
- .mget(name)
- .mget(description)
- .mget(icon)
- .mget(blockclass)
- .mget(slug)
- .exec(function(err, replies) {
- name = replies[0];
- description = replies[1];
- icon = replies[2];
- blockclass = replies[3];
- slug = replies[4];
-
- var categories = [];
- for (var i=0, ii=cids.length; i<ii; i++) {
- categories.push({
- 'name' : name[i],
- 'cid' : cids[i],
- 'slug' : slug[i],
- 'description' : description[i],
- 'blockclass' : blockclass[i],
- 'icon' : icon[i],
- /*'topics' : [0,1], later
- 'latest_post' : {
- 'uid' : 1,
- 'pid' : 1,
- timestamp and shit
- }*/
- });
- }
+ for (var i=0, ii=cids.length; i<ii; i++) {
+ name.push('cid:' + cids[i] + ':name');
+ description.push('cid:' + cids[i] + ':description');
+ icon.push('cid:' + cids[i] + ':icon');
+ blockclass.push('cid:' + cids[i] + ':blockclass');
+ slug.push('cid:' + cids[i] + ':slug');
+ }
- callback({'categories': categories});
- });
- } else callback({'categories' : []});
- });
- }
+ if (cids.length > 0) {
+ RDB.multi()
+ .mget(name)
+ .mget(description)
+ .mget(icon)
+ .mget(blockclass)
+ .mget(slug)
+ .exec(function(err, replies) {
+ name = replies[0];
+ description = replies[1];
+ icon = replies[2];
+ blockclass = replies[3];
+ slug = replies[4];
+
+ var categories = [];
+ for (var i=0, ii=cids.length; i<ii; i++) {
+ categories.push({
+ 'name' : name[i],
+ 'cid' : cids[i],
+ 'slug' : slug[i],
+ 'description' : description[i],
+ 'blockclass' : blockclass[i],
+ 'icon' : icon[i],
+ /*'topics' : [0,1], later
+ 'latest_post' : {
+ 'uid' : 1,
+ 'pid' : 1,
+ timestamp and shit
+ }*/
+ });
+ }
+
+ callback({'categories': categories});
+ });
+ } else callback({'categories' : []});
+ };
}(exports));
\ No newline at end of file
diff --git a/src/posts.js b/src/posts.js
index c437f57bc1..7538cad7ca 100644
--- a/src/posts.js
+++ b/src/posts.js
@@ -33,12 +33,14 @@ var RDB = require('./redis.js'),
'user_rep' : user_data[uid].reputation || 0,
'gravatar' : user_data[uid].picture,
'fav_star_class' : vote_data[pid] ? 'icon-star' : 'icon-star-empty',
- 'display_moderator_tools' : uid === current_user ? 'show' : 'hide'
+ 'display_moderator_tools' : uid == current_user ? 'show' : 'hide'
});
}
callback({
'topic_name':thread_data.topic_name,
+ 'category_name':thread_data.category_name,
+ 'category_slug':thread_data.category_slug,
'locked': parseInt(thread_data.locked) || 0,
'topic_id': tid,
'posts': posts
@@ -58,10 +60,6 @@ var RDB = require('./redis.js'),
pid.push(pids[i]);
}
- RDB.get('tid:' + tid + ':title', function(topic_name) {
- thread_data = {topic_name: topic_name};
- generateThread();
- });
Posts.getFavouritesByPostIDs(pids, current_user, function(fav_data) {
vote_data = fav_data;
@@ -76,6 +74,8 @@ var RDB = require('./redis.js'),
.mget(post_rep)
.get('tid:' + tid + ':title')
.get('tid:' + tid + ':locked')
+ .get('tid:' + tid + ':category_name')
+ .get('tid:' + tid + ':category_slug')
.exec(function(err, replies) {
post_data = {
pid: pids,
@@ -87,7 +87,9 @@ var RDB = require('./redis.js'),
thread_data = {
topic_name: replies[4],
- locked: replies[5]
+ locked: replies[5],
+ category_name: replies[6],
+ category_slug: replies[7]
};
user.getMultipleUserFields(post_data.uid, ['username','reputation','picture'], function(user_details){
diff --git a/src/topics.js b/src/topics.js
index be6bf06e32..e43b32e67d 100644
--- a/src/topics.js
+++ b/src/topics.js
@@ -1,7 +1,8 @@
var RDB = require('./redis.js'),
posts = require('./posts.js'),
utils = require('./utils.js'),
- user = require('./user.js');
+ user = require('./user.js')
+ categories = require('./categories.js');
(function(Topics) {
@@ -33,54 +34,75 @@ var RDB = require('./redis.js'),
postcount.push('tid:' + tids[i] + ':postcount');
}
+ var multi = RDB.multi()
+ .get('cid:' + category_id + ':name');
+
if (tids.length > 0) {
- RDB.multi()
+ multi
.mget(title)
.mget(uid)
.mget(timestamp)
.mget(slug)
.mget(postcount)
- .exec(function(err, replies) {
-
- title = replies[0];
- uid = replies[1];
- timestamp = replies[2];
- slug = replies[3];
- postcount = replies[4];
-
-
+ }
+
+
+ multi.exec(function(err, replies) {
+ category_name = replies[0];
+ var topics = [];
+
+ if (tids.length > 0) {
+ title = replies[1];
+ uid = replies[2];
+ timestamp = replies[3];
+ slug = replies[4];
+ postcount = replies[5];
+
+
+
+
+ user.get_usernames_by_uids(uid, function(userNames) {
- user.get_usernames_by_uids(uid, function(userNames) {
- var topics = [];
+ for (var i=0, ii=title.length; i<ii; i++) {
- for (var i=0, ii=title.length; i<ii; i++) {
-
- topics.push({
- 'title' : title[i],
- 'uid' : uid[i],
- 'username': userNames[i],
- 'timestamp' : timestamp[i],
- 'relativeTime': utils.relativeTime(timestamp[i]),
- 'slug' : slug[i],
- 'post_count' : postcount[i]
- });
- }
-
- callback({
- 'show_topic_button' : category_id ? 'show' : 'hidden',
- 'category_id': category_id,
- 'topics': topics
+ topics.push({
+ 'title' : title[i],
+ 'uid' : uid[i],
+ 'username': userNames[i],
+ 'timestamp' : timestamp[i],
+ 'relativeTime': utils.relativeTime(timestamp[i]),
+ 'slug' : slug[i],
+ 'post_count' : postcount[i]
});
+ }
+
+ callback({
+ 'category_name' : category_id ? category_name : 'Recent',
+ 'show_topic_button' : category_id ? 'show' : 'hidden',
+ 'category_id': category_id,
+ 'topics': topics
});
+
+ });
+ }
+ else {
+ callback({
+ 'category_name' : category_id ? category_name : 'Recent',
+ 'show_topic_button' : category_id ? 'show' : 'hidden',
+ 'category_id': category_id,
+ 'topics': []
+ });
+ }
+
-
- }
- );
- } else callback({'category_id': category_id, 'topics': []});
+
+ });
+ //} else callback({'category_id': category_id, 'topics': []});
});
}
Topics.post = function(socket, uid, title, content, category_id) {
+ if (!category_id) throw new Error('Attempted to post without a category_id');
if (uid === 0) {
socket.emit('event:alert', {
@@ -103,7 +125,7 @@ var RDB = require('./redis.js'),
RDB.lpush('topics:tid', tid);
} else {
// need to add some unique key sent by client so we can update this with the real uid later
- RDB.lpush('topics:queued:tid', tid);
+ RDB.lpush('topics:queued:tid', tid);
}
@@ -138,6 +160,14 @@ var RDB = require('./redis.js'),
type: 'notify',
timeout: 2000
});
+
+
+ // in future it may be possible to add topics to several categories, so leaving the door open here.
+ categories.get_category([category_id], function(data) {
+ RDB.set('tid:' + tid + ':category_name', data.categories[0].name);
+ RDB.set('tid:' + tid + ':category_slug', data.categories[0].slug);
+ });
+
});