adding 'load more topics' button to topic admin

This commit is contained in:
Julian Lam
2013-06-24 13:03:34 -04:00
parent 3ef32ba7fb
commit 89e852f692
5 changed files with 54 additions and 8 deletions

View File

@@ -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
});

View File

@@ -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);

View File

@@ -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));