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,27 +25,20 @@ var ajaxify = {};
|
|||||||
var tpl_url = (url === '') ? 'home' : url;
|
var tpl_url = (url === '') ? 'home' : url;
|
||||||
|
|
||||||
if (templates[tpl_url]) {
|
if (templates[tpl_url]) {
|
||||||
if (current_state === null || current_state != url) {
|
window.history.pushState({}, url, "/" + url);
|
||||||
current_state = url;
|
|
||||||
|
|
||||||
window.history.pushState({}, url, "/" + url);
|
jQuery('#content, #footer').fadeOut(100);
|
||||||
|
|
||||||
|
load_template(function() {
|
||||||
|
exec_body_scripts(content);
|
||||||
|
|
||||||
jQuery('#content, #footer').fadeOut(150, function() {
|
ajaxify.enable();
|
||||||
//content.innerHTML = templates[tpl_url];
|
if (callback) {
|
||||||
load_template(function() {
|
callback();
|
||||||
exec_body_scripts(content);
|
}
|
||||||
|
|
||||||
ajaxify.enable();
|
|
||||||
if (callback) {
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
|
|
||||||
jQuery('#content, #footer').fadeIn(200);
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
jQuery('#content, #footer').fadeIn(200);
|
||||||
|
});
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
<button id="new_post" class="btn btn-primary btn-large">New Post</button>
|
<button id="new_post" class="btn btn-primary btn-large">New Post</button>
|
||||||
<ul class="topic-container">
|
<ul class="topic-container">
|
||||||
<!-- BEGIN topics -->
|
<!-- BEGIN topics -->
|
||||||
<li class="topic-row">
|
<a href="topics/{topics.slug}"><li class="topic-row">
|
||||||
<h4>{topics.title}</h4>
|
<h4>{topics.title}</h4>
|
||||||
<p>Posted on {topics.timestamp} by user {topics.uid}. {topics.post_count} replies.</p>
|
<p>Posted on {topics.timestamp} by user {topics.uid}. {topics.post_count} posts.</p>
|
||||||
</li>
|
</li></a>
|
||||||
<!-- END topics -->
|
<!-- END topics -->
|
||||||
</ul>
|
</ul>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
|||||||
0
public/templates/topic.tpl
Normal file
0
public/templates/topic.tpl
Normal file
@@ -31,7 +31,7 @@ var RDB = require('./redis.js');
|
|||||||
|
|
||||||
// User Details - move this out later
|
// User Details - move this out later
|
||||||
RDB.lpush('uid:' + uid + ':posts', pid);
|
RDB.lpush('uid:' + uid + ':posts', pid);
|
||||||
|
|
||||||
if (callback) callback(pid);
|
if (callback) callback(pid);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -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) {
|
Topics.generate_forum_body = function(callback, start, end) {
|
||||||
var forum_body = global.templates['home'];
|
var forum_body = global.templates['home'];
|
||||||
|
|
||||||
@@ -31,6 +42,10 @@ var RDB = require('./redis.js'),
|
|||||||
}, start, end);
|
}, start, end);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Topics.get_postIDs_by_topicID = function(topicID, start, end) {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
Topics.get = function(callback, start, end) {
|
Topics.get = function(callback, start, end) {
|
||||||
if (start == null) start = 0;
|
if (start == null) start = 0;
|
||||||
if (end == null) end = start + 10;
|
if (end == null) end = start + 10;
|
||||||
@@ -40,29 +55,30 @@ var RDB = require('./redis.js'),
|
|||||||
var title = [],
|
var title = [],
|
||||||
uid = [],
|
uid = [],
|
||||||
timestamp = [],
|
timestamp = [],
|
||||||
posts = [];
|
slug = [],
|
||||||
|
postcount = [];
|
||||||
|
|
||||||
for (var i=0, ii=tids.length; i<ii; i++) {
|
for (var i=0, ii=tids.length; i<ii; i++) {
|
||||||
title.push('tid:' + tids[i] + ':title');
|
title.push('tid:' + tids[i] + ':title');
|
||||||
uid.push('tid:' + tids[i] + ':uid');
|
uid.push('tid:' + tids[i] + ':uid');
|
||||||
timestamp.push('tid:' + tids[i] + ':timestamp');
|
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) {
|
if (tids.length > 0) {
|
||||||
RDB.multi()
|
RDB.multi()
|
||||||
.mget(title)
|
.mget(title)
|
||||||
.mget(uid)
|
.mget(uid)
|
||||||
.mget(timestamp)
|
.mget(timestamp)
|
||||||
.mget(posts)
|
.mget(slug)
|
||||||
|
.mget(postcount)
|
||||||
.exec(function(err, replies) {
|
.exec(function(err, replies) {
|
||||||
title = replies[0];
|
title = replies[0];
|
||||||
uid = replies[1];
|
uid = replies[1];
|
||||||
timestamp = replies[2];
|
timestamp = replies[2];
|
||||||
posts = replies[3];
|
slug = replies[3];
|
||||||
|
postcount = replies[4];
|
||||||
|
|
||||||
var topics = [];
|
var topics = [];
|
||||||
for (var i=0, ii=title.length; i<ii; i++) {
|
for (var i=0, ii=title.length; i<ii; i++) {
|
||||||
@@ -70,8 +86,8 @@ var RDB = require('./redis.js'),
|
|||||||
'title' : title[i],
|
'title' : title[i],
|
||||||
'uid' : uid[i],
|
'uid' : uid[i],
|
||||||
'timestamp' : timestamp[i],
|
'timestamp' : timestamp[i],
|
||||||
'posts' : posts[i],
|
'slug' : slug[i],
|
||||||
'post_count' : 0
|
'post_count' : postcount[i]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,6 +115,7 @@ var RDB = require('./redis.js'),
|
|||||||
|
|
||||||
RDB.incr('global:next_topic_id', function(tid) {
|
RDB.incr('global:next_topic_id', function(tid) {
|
||||||
// Global Topics
|
// Global Topics
|
||||||
|
if (global.uid == null) global.uid = 0;
|
||||||
if (global.uid !== null) {
|
if (global.uid !== null) {
|
||||||
RDB.lpush('topics:tid', tid);
|
RDB.lpush('topics:tid', tid);
|
||||||
} else {
|
} else {
|
||||||
@@ -112,20 +129,25 @@ var RDB = require('./redis.js'),
|
|||||||
RDB.lpush('topics:' + category + ':tid', tid);
|
RDB.lpush('topics:' + category + ':tid', tid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var slug = tid + '/' + slugify(title);
|
||||||
|
|
||||||
// Topic Info
|
// Topic Info
|
||||||
RDB.set('tid:' + tid + ':title', title);
|
RDB.set('tid:' + tid + ':title', title);
|
||||||
RDB.set('tid:' + tid + ':uid', global.uid);
|
RDB.set('tid:' + tid + ':uid', global.uid);
|
||||||
|
RDB.set('tid:' + tid + ':slug', slug);
|
||||||
RDB.set('tid:' + tid + ':timestamp', new Date().getTime());
|
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
|
||||||
posts.create(content, function(pid) {
|
posts.create(content, function(pid) {
|
||||||
RDB.lpush('tid:' + tid + ':posts', pid);
|
RDB.lpush('tid:' + tid + ':posts', pid);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// User Details - move this out later
|
// User Details - move this out later
|
||||||
RDB.lpush('uid:' + uid + ':topics', tid);
|
RDB.lpush('uid:' + global.uid + ':topics', tid);
|
||||||
|
|
||||||
|
|
||||||
global.socket.emit('event:alert', {
|
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) {
|
app.get('/api/:method', function(req, res) {
|
||||||
switch(req.params.method) {
|
switch(req.params.method) {
|
||||||
case 'home' :
|
case 'home' :
|
||||||
|
|||||||
Reference in New Issue
Block a user