mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 12:05:57 +01:00
started working on threadss, implemented slug url, fixed crashing bug during post creation
This commit is contained in:
@@ -25,13 +25,10 @@ var ajaxify = {};
|
||||
var tpl_url = (url === '') ? 'home' : url;
|
||||
|
||||
if (templates[tpl_url]) {
|
||||
if (current_state === null || current_state != url) {
|
||||
current_state = url;
|
||||
|
||||
window.history.pushState({}, url, "/" + url);
|
||||
|
||||
jQuery('#content, #footer').fadeOut(150, function() {
|
||||
//content.innerHTML = templates[tpl_url];
|
||||
jQuery('#content, #footer').fadeOut(100);
|
||||
|
||||
load_template(function() {
|
||||
exec_body_scripts(content);
|
||||
|
||||
@@ -43,10 +40,6 @@ var ajaxify = {};
|
||||
jQuery('#content, #footer').fadeIn(200);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
<button id="new_post" class="btn btn-primary btn-large">New Post</button>
|
||||
<ul class="topic-container">
|
||||
<!-- BEGIN topics -->
|
||||
<li class="topic-row">
|
||||
<a href="topics/{topics.slug}"><li class="topic-row">
|
||||
<h4>{topics.title}</h4>
|
||||
<p>Posted on {topics.timestamp} by user {topics.uid}. {topics.post_count} replies.</p>
|
||||
</li>
|
||||
<p>Posted on {topics.timestamp} by user {topics.uid}. {topics.post_count} posts.</p>
|
||||
</li></a>
|
||||
<!-- END topics -->
|
||||
</ul>
|
||||
<script type="text/javascript">
|
||||
|
||||
0
public/templates/topic.tpl
Normal file
0
public/templates/topic.tpl
Normal file
@@ -21,6 +21,17 @@ var RDB = require('./redis.js'),
|
||||
|
||||
}
|
||||
|
||||
|
||||
Topics.generate_topic_body = function(callback, tid, start, end) {
|
||||
if (start == null) start = 0;
|
||||
if (end == null) end = start + 10;
|
||||
|
||||
RDB.lrange('tid:' + tid + ':posts', start, end, function(tids) {
|
||||
callback(tids);
|
||||
});
|
||||
};
|
||||
|
||||
// this needs to move into forum.js
|
||||
Topics.generate_forum_body = function(callback, start, end) {
|
||||
var forum_body = global.templates['home'];
|
||||
|
||||
@@ -31,6 +42,10 @@ var RDB = require('./redis.js'),
|
||||
}, start, end);
|
||||
};
|
||||
|
||||
Topics.get_postIDs_by_topicID = function(topicID, start, end) {
|
||||
|
||||
};
|
||||
|
||||
Topics.get = function(callback, start, end) {
|
||||
if (start == null) start = 0;
|
||||
if (end == null) end = start + 10;
|
||||
@@ -40,29 +55,30 @@ var RDB = require('./redis.js'),
|
||||
var title = [],
|
||||
uid = [],
|
||||
timestamp = [],
|
||||
posts = [];
|
||||
slug = [],
|
||||
postcount = [];
|
||||
|
||||
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');
|
||||
slug.push('tid:' + tids[i] + ':slug');
|
||||
postcount.push('tid:' + tids[i] + ':postcount');
|
||||
}
|
||||
/*RDB.mget(topic, function(topic_data) {
|
||||
callback(topic_data);
|
||||
});*/
|
||||
|
||||
if (tids.length > 0) {
|
||||
RDB.multi()
|
||||
.mget(title)
|
||||
.mget(uid)
|
||||
.mget(timestamp)
|
||||
.mget(posts)
|
||||
.mget(slug)
|
||||
.mget(postcount)
|
||||
.exec(function(err, replies) {
|
||||
title = replies[0];
|
||||
uid = replies[1];
|
||||
timestamp = replies[2];
|
||||
posts = replies[3];
|
||||
slug = replies[3];
|
||||
postcount = replies[4];
|
||||
|
||||
var topics = [];
|
||||
for (var i=0, ii=title.length; i<ii; i++) {
|
||||
@@ -70,8 +86,8 @@ var RDB = require('./redis.js'),
|
||||
'title' : title[i],
|
||||
'uid' : uid[i],
|
||||
'timestamp' : timestamp[i],
|
||||
'posts' : posts[i],
|
||||
'post_count' : 0
|
||||
'slug' : slug[i],
|
||||
'post_count' : postcount[i]
|
||||
});
|
||||
}
|
||||
|
||||
@@ -99,6 +115,7 @@ var RDB = require('./redis.js'),
|
||||
|
||||
RDB.incr('global:next_topic_id', function(tid) {
|
||||
// Global Topics
|
||||
if (global.uid == null) global.uid = 0;
|
||||
if (global.uid !== null) {
|
||||
RDB.lpush('topics:tid', tid);
|
||||
} else {
|
||||
@@ -112,20 +129,25 @@ var RDB = require('./redis.js'),
|
||||
RDB.lpush('topics:' + category + ':tid', tid);
|
||||
}
|
||||
|
||||
var slug = tid + '/' + slugify(title);
|
||||
|
||||
// Topic Info
|
||||
RDB.set('tid:' + tid + ':title', title);
|
||||
RDB.set('tid:' + tid + ':uid', global.uid);
|
||||
RDB.set('tid:' + tid + ':slug', slug);
|
||||
RDB.set('tid:' + tid + ':timestamp', new Date().getTime());
|
||||
RDB.incr('tid:' + tid + ':postcount');
|
||||
|
||||
RDB.set('topic:slug:' + tid + '/' + slugify(title) + ':tid', tid);
|
||||
RDB.set('topic:slug:' + slug + ':tid', tid);
|
||||
|
||||
// Posts
|
||||
posts.create(content, function(pid) {
|
||||
RDB.lpush('tid:' + tid + ':posts', pid);
|
||||
});
|
||||
|
||||
|
||||
// User Details - move this out later
|
||||
RDB.lpush('uid:' + uid + ':topics', tid);
|
||||
RDB.lpush('uid:' + global.uid + ':topics', tid);
|
||||
|
||||
|
||||
global.socket.emit('event:alert', {
|
||||
|
||||
@@ -60,6 +60,19 @@ var express = require('express'),
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
app.get('/topics/:topic_id', function(req, res) {
|
||||
global.modules.topics.generate_topic_body(function(topic_body) {
|
||||
res.send(templates['header'] + topic_body + templates['footer']);
|
||||
}, req.params.topic_id)
|
||||
});
|
||||
app.get('/topics/:topic_id/:slug', function(req, res) {
|
||||
global.modules.topics.generate_topic_body(function(topic_body) {
|
||||
res.send(templates['header'] + topic_body + templates['footer']);
|
||||
}, req.params.topic_id)
|
||||
});
|
||||
|
||||
app.get('/api/:method', function(req, res) {
|
||||
switch(req.params.method) {
|
||||
case 'home' :
|
||||
|
||||
Reference in New Issue
Block a user