Skip to content

Node.js based forum software built for the modern web

forgot to commit category files

psychobunny97c1819dc4c9
diff --git a/public/templates/category.tpl b/public/templates/category.tpl
new file mode 100644
index 0000000000..4fb3c46bc8
--- /dev/null
+++ b/public/templates/category.tpl
@@ -0,0 +1,15 @@
+<button id="new_post" class="btn btn-primary btn-large">New Topic</button>
+<ul class="topic-container">
+<!-- BEGIN topics -->
+<a href="../../topic/{topics.slug}"><li class="topic-row">
+ <h4>{topics.title}</h4>
+ <p>Posted {topics.relativeTime} ago by <span class="username">{topics.username}</span>. {topics.post_count} posts.</p>
+</li></a>
+<!-- END topics -->
+</ul>
+<script type="text/javascript">
+var new_post = document.getElementById('new_post');
+new_post.onclick = function() {
+ app.open_post_window('topic', {category_id});
+}
+</script>
\ No newline at end of file
diff --git a/src/categories.js b/src/categories.js
new file mode 100644
index 0000000000..830bdae6a4
--- /dev/null
+++ b/src/categories.js
@@ -0,0 +1,72 @@
+var RDB = require('./redis.js'),
+ posts = require('./posts.js'),
+ utils = require('./utils.js'),
+ user = require('./user.js');
+
+(function(Categories) {
+
+
+ // An admin-only function. Seeing how we have no control panel yet ima leave this right here. sit pretty, you
+ Categories.create = function(data, callback) {
+ RDB.incr('global:next_category_id', function(cid) {
+ var slug = cid + '/' + utils.slugify(data.name);
+ RDB.rpush('categories:cid', cid);
+
+ // Topic Info
+ RDB.set('cid:' + cid + ':name', data.name);
+ RDB.set('cid:' + cid + ':description', data.description);
+ RDB.set('cid:' + cid + ':slug', slug);
+
+ RDB.set('category:slug:' + slug + ':cid', cid);
+
+ if (callback) callback({'status': 1});
+ });
+ };
+
+
+
+ Categories.get = function(callback) {
+ RDB.lrange('categories:cid', 0, -1, function(cids) {
+ var name = [],
+ description = [],
+ slug = [];
+
+ for (var i=0, ii=cids.length; i<ii; i++) {
+ name.push('cid:' + cids[i] + ':name');
+ description.push('cid:' + cids[i] + ':description');
+ slug.push('cid:' + cids[i] + ':slug');
+ }
+
+ if (cids.length > 0) {
+ RDB.multi()
+ .mget(name)
+ .mget(description)
+ .mget(slug)
+ .exec(function(err, replies) {
+ name = replies[0];
+ description = replies[1];
+ slug = replies[2];
+
+ 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],
+ /*'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