mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-03-04 03:21:18 +01:00
add pagination to flags page
This commit is contained in:
@@ -13,7 +13,7 @@ eventsController.get = function(req, res, next) {
|
||||
|
||||
var page = parseInt(req.query.page, 10) || 1;
|
||||
var itemsPerPage = 20;
|
||||
var start = (page - 1) * 20;
|
||||
var start = (page - 1) * itemsPerPage;
|
||||
var stop = start + itemsPerPage - 1;
|
||||
|
||||
async.parallel({
|
||||
|
||||
@@ -4,19 +4,23 @@ var async = require('async');
|
||||
var posts = require('../../posts');
|
||||
var user = require('../../user');
|
||||
var analytics = require('../../analytics');
|
||||
var pagination = require('../../pagination');
|
||||
|
||||
var flagsController = {};
|
||||
|
||||
flagsController.get = function(req, res, next) {
|
||||
var sortBy = req.query.sortBy || 'count';
|
||||
var byUsername = req.query.byUsername || '';
|
||||
var start = 0;
|
||||
var stop = 19;
|
||||
|
||||
var page = parseInt(req.query.page, 10) || 1;
|
||||
var itemsPerPage = 20;
|
||||
var start = (page - 1) * itemsPerPage;
|
||||
var stop = start + itemsPerPage - 1;
|
||||
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
async.parallel({
|
||||
posts: function(next) {
|
||||
flagData: function(next) {
|
||||
if (byUsername) {
|
||||
posts.getUserFlags(byUsername, sortBy, req.uid, start, stop, next);
|
||||
} else {
|
||||
@@ -27,7 +31,9 @@ flagsController.get = function(req, res, next) {
|
||||
analytics: function(next) {
|
||||
analytics.getDailyStatsForSet('analytics:flags', Date.now(), 30, next);
|
||||
},
|
||||
assignees: async.apply(user.getAdminsandGlobalMods)
|
||||
assignees: function(next) {
|
||||
user.getAdminsandGlobalMods(next);
|
||||
}
|
||||
}, next);
|
||||
}
|
||||
], function (err, results) {
|
||||
@@ -49,12 +55,15 @@ flagsController.get = function(req, res, next) {
|
||||
return userObj;
|
||||
});
|
||||
|
||||
var pageCount = Math.max(1, Math.ceil(results.flagData.count / itemsPerPage));
|
||||
|
||||
var data = {
|
||||
posts: results.posts,
|
||||
posts: results.flagData.posts,
|
||||
assignees: results.assignees,
|
||||
analytics: results.analytics,
|
||||
next: stop + 1,
|
||||
byUsername: byUsername,
|
||||
pagination: pagination.create(page, pageCount, req.query),
|
||||
title: '[[pages:flagged-posts]]'
|
||||
};
|
||||
res.render('admin/manage/flags', data);
|
||||
|
||||
@@ -154,12 +154,48 @@ module.exports = function(Posts) {
|
||||
};
|
||||
|
||||
Posts.getFlags = function(set, uid, start, stop, callback) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
db.getSortedSetRevRange(set, start, stop, next);
|
||||
async.parallel({
|
||||
count: function(next) {
|
||||
db.sortedSetCard(set, next);
|
||||
},
|
||||
function (pids, next) {
|
||||
getFlaggedPostsWithReasons(pids, uid, next);
|
||||
posts: function(next) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
db.getSortedSetRevRange(set, start, stop, next);
|
||||
},
|
||||
function (pids, next) {
|
||||
getFlaggedPostsWithReasons(pids, uid, next);
|
||||
}
|
||||
], next);
|
||||
}
|
||||
}, callback);
|
||||
};
|
||||
|
||||
Posts.getUserFlags = function(byUsername, sortBy, callerUID, start, stop, callback) {
|
||||
var count = 0;
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
user.getUidByUsername(byUsername, next);
|
||||
},
|
||||
function(uid, next) {
|
||||
if (!uid) {
|
||||
return next(null, []);
|
||||
}
|
||||
|
||||
db.getSortedSetRevRange('uid:' + uid + ':flag:pids', 0, -1, next);
|
||||
},
|
||||
function(pids, next) {
|
||||
count = pids.length;
|
||||
getFlaggedPostsWithReasons(pids, callerUID, next);
|
||||
},
|
||||
function(posts, next) {
|
||||
if (sortBy === 'count') {
|
||||
posts.sort(function(a, b) {
|
||||
return b.flags - a.flags;
|
||||
});
|
||||
}
|
||||
|
||||
next(null, {posts: posts.slice(start, stop === -1 ? undefined : stop + 1), count: count});
|
||||
}
|
||||
], callback);
|
||||
};
|
||||
@@ -242,32 +278,6 @@ module.exports = function(Posts) {
|
||||
], callback);
|
||||
}
|
||||
|
||||
Posts.getUserFlags = function(byUsername, sortBy, callerUID, start, stop, callback) {
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
user.getUidByUsername(byUsername, next);
|
||||
},
|
||||
function(uid, next) {
|
||||
if (!uid) {
|
||||
return next(null, []);
|
||||
}
|
||||
db.getSortedSetRevRange('uid:' + uid + ':flag:pids', 0, -1, next);
|
||||
},
|
||||
function(pids, next) {
|
||||
getFlaggedPostsWithReasons(pids, callerUID, next);
|
||||
},
|
||||
function(posts, next) {
|
||||
if (sortBy === 'count') {
|
||||
posts.sort(function(a, b) {
|
||||
return b.flags - a.flags;
|
||||
});
|
||||
}
|
||||
|
||||
next(null, posts.slice(start, stop));
|
||||
}
|
||||
], callback);
|
||||
};
|
||||
|
||||
Posts.updateFlagData = function(uid, pid, flagObj, callback) {
|
||||
// Retrieve existing flag data to compare for history-saving purposes
|
||||
var changes = [];
|
||||
|
||||
@@ -136,37 +136,6 @@ module.exports = function(SocketPosts) {
|
||||
], callback);
|
||||
};
|
||||
|
||||
SocketPosts.getMoreFlags = function(socket, data, callback) {
|
||||
if (!data || !parseInt(data.after, 10)) {
|
||||
return callback('[[error:invalid-data]]');
|
||||
}
|
||||
var sortBy = data.sortBy || 'count';
|
||||
var byUsername = data.byUsername || '';
|
||||
var start = parseInt(data.after, 10);
|
||||
var stop = start + 19;
|
||||
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
user.isAdminOrGlobalMod(socket.uid, next);
|
||||
},
|
||||
function (isAdminOrGlobalModerator, next) {
|
||||
if (!isAdminOrGlobalModerator) {
|
||||
return next(new Error('[[no-privileges]]'));
|
||||
}
|
||||
|
||||
if (byUsername) {
|
||||
posts.getUserFlags(byUsername, sortBy, socket.uid, start, stop, next);
|
||||
} else {
|
||||
var set = sortBy === 'count' ? 'posts:flags:count' : 'posts:flagged';
|
||||
posts.getFlags(set, socket.uid, start, stop, next);
|
||||
}
|
||||
},
|
||||
function (posts, next) {
|
||||
next(null, {posts: posts, next: stop + 1});
|
||||
}
|
||||
], callback);
|
||||
};
|
||||
|
||||
SocketPosts.updateFlag = function(socket, data, callback) {
|
||||
if (!data || !(data.pid && data.data)) {
|
||||
return callback('[[error:invalid-data]]');
|
||||
|
||||
@@ -269,8 +269,10 @@ var utils = require('../public/src/utils');
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
User.getUsersData(results.admins.concat(results.mods), callback);
|
||||
var uids = results.admins.concat(results.mods).filter(function(uid, index, array) {
|
||||
return uid && array.indexOf(uid) === index;
|
||||
});
|
||||
User.getUsersData(uids, callback);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -167,6 +167,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<!-- END posts -->
|
||||
<!-- IMPORT partials/paginator.tpl -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user