mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-07-14 21:22:46 +02:00
adding 'load more topics' button to topic admin
This commit is contained in:
@@ -57,10 +57,7 @@ var user = require('./../user.js'),
|
||||
}
|
||||
break;
|
||||
case 'topics':
|
||||
topics.getAllTopics(function(topics) {
|
||||
topics.sort(function(a, b) {
|
||||
return b.timestamp - a.timestamp;
|
||||
});
|
||||
topics.getAllTopics(10, null, function(topics) {
|
||||
res.json({
|
||||
topics: topics
|
||||
});
|
||||
|
||||
@@ -184,9 +184,33 @@ marked.setOptions({
|
||||
});
|
||||
}
|
||||
|
||||
Topics.getAllTopics = function(callback) {
|
||||
Topics.getAllTopics = function(limit, after, callback) {
|
||||
RDB.smembers('topics:tid', function(err, tids) {
|
||||
var topics = [];
|
||||
var topics = [],
|
||||
numTids, x;
|
||||
|
||||
// Sort into ascending order
|
||||
tids.sort(function(a, b) { return a - b; });
|
||||
|
||||
// Eliminate everything after the "after" tid
|
||||
if (after) {
|
||||
for(x=0,numTids=tids.length;x<numTids;x++) {
|
||||
if (tids[x] >= after) {
|
||||
tids = tids.slice(0, x);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (limit) {
|
||||
if (limit > 0 && limit < tids.length) {
|
||||
tids = tids.slice(tids.length - limit);
|
||||
}
|
||||
}
|
||||
|
||||
// Sort into descending order
|
||||
tids.sort(function(a, b) { return b - a; });
|
||||
|
||||
async.each(tids, function(tid, next) {
|
||||
Topics.get_topic(tid, 0, function(topicData) {
|
||||
topics.push(topicData);
|
||||
|
||||
@@ -121,7 +121,6 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
|
||||
});
|
||||
|
||||
// BEGIN: API calls (todo: organize)
|
||||
// julian: :^)
|
||||
|
||||
socket.on('api:updateHeader', function(data) {
|
||||
if(uid) {
|
||||
@@ -391,6 +390,12 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('api:admin.topics.getMore', function(data) {
|
||||
topics.getAllTopics(data.limit, data.after, function(topics) {
|
||||
socket.emit('api:admin.topics.getMore', JSON.stringify(topics));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}(SocketIO));
|
||||
|
||||
Reference in New Issue
Block a user