style changes

v1.18.x
Barış Soner Uşaklı 8 years ago
parent 78005d6124
commit 0f234601f1

@ -1,12 +1,9 @@
'use strict'; 'use strict';
var appearanceController = {}; var appearanceController = module.exports;
appearanceController.get = function (req, res) { appearanceController.get = function (req, res) {
var term = req.params.term ? req.params.term : 'themes'; var term = req.params.term ? req.params.term : 'themes';
res.render('admin/appearance/' + term, {}); res.render('admin/appearance/' + term, {});
}; };
module.exports = appearanceController;

@ -1,6 +1,6 @@
'use strict'; 'use strict';
var cacheController = {}; var cacheController = module.exports;
cacheController.get = function (req, res) { cacheController.get = function (req, res) {
var postCache = require('../../posts/cache'); var postCache = require('../../posts/cache');
@ -37,6 +37,3 @@ cacheController.get = function (req, res) {
}, },
}); });
}; };
module.exports = cacheController;

@ -7,76 +7,79 @@ var db = require('../../database');
var meta = require('../../meta'); var meta = require('../../meta');
var plugins = require('../../plugins'); var plugins = require('../../plugins');
var dashboardController = {}; var dashboardController = module.exports;
dashboardController.get = function (req, res, next) { dashboardController.get = function (req, res, next) {
async.parallel({ async.waterfall([
stats: function (next) { function (next) {
getStats(next); async.parallel({
}, stats: function (next) {
notices: function (next) { getStats(next);
var notices = [
{
done: !meta.reloadRequired,
doneText: '[[admin/general/dashboard:restart-not-required]]',
notDoneText: '[[admin/general/dashboard:restart-required]]',
},
{
done: plugins.hasListeners('filter:search.query'),
doneText: '[[admin/general/dashboard:search-plugin-installed]]',
notDoneText: '[[admin/general/dashboard:search-plugin-not-installed]]',
tooltip: '[[admin/general/dashboard:search-plugin-tooltip]]',
link: '/admin/extend/plugins',
}, },
]; notices: function (next) {
var notices = [
{
done: !meta.reloadRequired,
doneText: '[[admin/general/dashboard:restart-not-required]]',
notDoneText: '[[admin/general/dashboard:restart-required]]',
},
{
done: plugins.hasListeners('filter:search.query'),
doneText: '[[admin/general/dashboard:search-plugin-installed]]',
notDoneText: '[[admin/general/dashboard:search-plugin-not-installed]]',
tooltip: '[[admin/general/dashboard:search-plugin-tooltip]]',
link: '/admin/extend/plugins',
},
];
if (global.env !== 'production') { if (global.env !== 'production') {
notices.push({ notices.push({
done: false, done: false,
notDoneText: '[[admin/general/dashboard:running-in-development]]', notDoneText: '[[admin/general/dashboard:running-in-development]]',
}); });
} }
plugins.fireHook('filter:admin.notices', notices, next); plugins.fireHook('filter:admin.notices', notices, next);
},
}, next);
}, },
}, function (err, results) { function (results) {
if (err) { res.render('admin/general/dashboard', {
return next(err); version: nconf.get('version'),
} notices: results.notices,
res.render('admin/general/dashboard', { stats: results.stats,
version: nconf.get('version'), });
notices: results.notices, },
stats: results.stats, ], next);
});
});
}; };
function getStats(callback) { function getStats(callback) {
async.parallel([ async.waterfall([
function (next) { function (next) {
getStatsForSet('ip:recent', 'uniqueIPCount', next); async.parallel([
}, function (next) {
function (next) { getStatsForSet('ip:recent', 'uniqueIPCount', next);
getStatsForSet('users:joindate', 'userCount', next); },
}, function (next) {
function (next) { getStatsForSet('users:joindate', 'userCount', next);
getStatsForSet('posts:pid', 'postCount', next); },
}, function (next) {
function (next) { getStatsForSet('posts:pid', 'postCount', next);
getStatsForSet('topics:tid', 'topicCount', next); },
function (next) {
getStatsForSet('topics:tid', 'topicCount', next);
},
], next);
}, },
], function (err, results) { function (results, next) {
if (err) { results[0].name = '[[admin/general/dashboard:unique-visitors]]';
return callback(err); results[1].name = '[[admin/general/dashboard:users]]';
} results[2].name = '[[admin/general/dashboard:posts]]';
results[0].name = '[[admin/general/dashboard:unique-visitors]]'; results[3].name = '[[admin/general/dashboard:topics]]';
results[1].name = '[[admin/general/dashboard:users]]';
results[2].name = '[[admin/general/dashboard:posts]]';
results[3].name = '[[admin/general/dashboard:topics]]';
callback(null, results); next(null, results);
}); },
], callback);
} }
function getStatsForSet(set, field, callback) { function getStatsForSet(set, field, callback) {
@ -108,5 +111,3 @@ function getGlobalField(field, callback) {
callback(err, parseInt(count, 10) || 0); callback(err, parseInt(count, 10) || 0);
}); });
} }
module.exports = dashboardController;

@ -3,33 +3,32 @@
var async = require('async'); var async = require('async');
var nconf = require('nconf'); var nconf = require('nconf');
var databaseController = {}; var databaseController = module.exports;
databaseController.get = function (req, res, next) { databaseController.get = function (req, res, next) {
async.parallel({ async.waterfall([
redis: function (next) { function (next) {
if (nconf.get('redis')) { async.parallel({
var rdb = require('../../database/redis'); redis: function (next) {
rdb.info(rdb.client, next); if (nconf.get('redis')) {
} else { var rdb = require('../../database/redis');
next(); rdb.info(rdb.client, next);
} } else {
next();
}
},
mongo: function (next) {
if (nconf.get('mongo')) {
var mdb = require('../../database/mongo');
mdb.info(mdb.client, next);
} else {
next();
}
},
}, next);
}, },
mongo: function (next) { function (results) {
if (nconf.get('mongo')) { res.render('admin/advanced/database', results);
var mdb = require('../../database/mongo');
mdb.info(mdb.client, next);
} else {
next();
}
}, },
}, function (err, results) { ], next);
if (err) {
return next(err);
}
res.render('admin/advanced/database', results);
});
}; };
module.exports = databaseController;

@ -6,33 +6,28 @@ var json2csv = require('json-2-csv').json2csv;
var meta = require('../../meta'); var meta = require('../../meta');
var analytics = require('../../analytics'); var analytics = require('../../analytics');
var errorsController = {}; var errorsController = module.exports;
errorsController.get = function (req, res, next) { errorsController.get = function (req, res, next) {
async.parallel({ async.waterfall([
'not-found': async.apply(meta.errors.get, true), function (next) {
analytics: async.apply(analytics.getErrorAnalytics), async.parallel({
}, function (err, data) { 'not-found': async.apply(meta.errors.get, true),
if (err) { analytics: async.apply(analytics.getErrorAnalytics),
return next(err); }, next);
} },
function (data) {
res.render('admin/advanced/errors', data); res.render('admin/advanced/errors', data);
}); },
], next);
}; };
errorsController.export = function (req, res, next) { errorsController.export = function (req, res, next) {
async.waterfall([ async.waterfall([
async.apply(meta.errors.get, false), async.apply(meta.errors.get, false),
async.apply(json2csv), async.apply(json2csv),
], function (err, csv) { function (csv) {
if (err) { res.set('Content-Type', 'text/csv').set('Content-Disposition', 'attachment; filename="404.csv"').send(csv);
return next(err); },
} ], next);
res.set('Content-Type', 'text/csv').set('Content-Disposition', 'attachment; filename="404.csv"').send(csv);
});
}; };
module.exports = errorsController;

@ -6,8 +6,7 @@ var db = require('../../database');
var events = require('../../events'); var events = require('../../events');
var pagination = require('../../pagination'); var pagination = require('../../pagination');
var eventsController = {}; var eventsController = module.exports;
eventsController.get = function (req, res, next) { eventsController.get = function (req, res, next) {
var page = parseInt(req.query.page, 10) || 1; var page = parseInt(req.query.page, 10) || 1;
@ -15,27 +14,26 @@ eventsController.get = function (req, res, next) {
var start = (page - 1) * itemsPerPage; var start = (page - 1) * itemsPerPage;
var stop = start + itemsPerPage - 1; var stop = start + itemsPerPage - 1;
async.parallel({ async.waterfall([
eventCount: function (next) { function (next) {
db.sortedSetCard('events:time', next); async.parallel({
eventCount: function (next) {
db.sortedSetCard('events:time', next);
},
events: function (next) {
events.getEvents(start, stop, next);
},
}, next);
}, },
events: function (next) { function (results) {
events.getEvents(start, stop, next); var pageCount = Math.max(1, Math.ceil(results.eventCount / itemsPerPage));
res.render('admin/advanced/events', {
events: results.events,
pagination: pagination.create(page, pageCount),
next: 20,
});
}, },
}, function (err, results) { ], next);
if (err) {
return next(err);
}
var pageCount = Math.max(1, Math.ceil(results.eventCount / itemsPerPage));
res.render('admin/advanced/events', {
events: results.events,
pagination: pagination.create(page, pageCount),
next: 20,
});
});
}; };
module.exports = eventsController;

@ -7,7 +7,7 @@ var groups = require('../../groups');
var meta = require('../../meta'); var meta = require('../../meta');
var pagination = require('../../pagination'); var pagination = require('../../pagination');
var groupsController = {}; var groupsController = module.exports;
groupsController.list = function (req, res, next) { groupsController.list = function (req, res, next) {
var page = parseInt(req.query.page, 10) || 1; var page = parseInt(req.query.page, 10) || 1;
@ -30,20 +30,14 @@ groupsController.list = function (req, res, next) {
groupNames = groupNames.slice(start, stop + 1); groupNames = groupNames.slice(start, stop + 1);
groups.getGroupsData(groupNames, next); groups.getGroupsData(groupNames, next);
}, },
function (groupData, next) { function (groupData) {
next(null, { groups: groupData, pagination: pagination.create(page, pageCount) }); res.render('admin/manage/groups', {
groups: groupData,
pagination: pagination.create(page, pageCount),
yourid: req.uid,
});
}, },
], function (err, data) { ], next);
if (err) {
return next(err);
}
res.render('admin/manage/groups', {
groups: data.groups,
pagination: data.pagination,
yourid: req.uid,
});
});
}; };
groupsController.get = function (req, res, callback) { groupsController.get = function (req, res, callback) {
@ -58,13 +52,12 @@ groupsController.get = function (req, res, callback) {
} }
groups.get(groupName, { uid: req.uid, truncateUserList: true, userListCount: 20 }, next); groups.get(groupName, { uid: req.uid, truncateUserList: true, userListCount: 20 }, next);
}, },
], function (err, group) { function (group) {
if (err) { group.isOwner = true;
return callback(err); res.render('admin/manage/group', {
} group: group,
group.isOwner = true; allowPrivateGroups: parseInt(meta.config.allowPrivateGroups, 10) === 1,
res.render('admin/manage/group', { group: group, allowPrivateGroups: parseInt(meta.config.allowPrivateGroups, 10) === 1 }); });
}); },
], callback);
}; };
module.exports = groupsController;

@ -7,8 +7,7 @@ var categories = require('../../categories');
var privileges = require('../../privileges'); var privileges = require('../../privileges');
var plugins = require('../../plugins'); var plugins = require('../../plugins');
var homePageController = {}; var homePageController = module.exports;
homePageController.get = function (req, res, next) { homePageController.get = function (req, res, next) {
async.waterfall([ async.waterfall([
@ -28,39 +27,29 @@ homePageController.get = function (req, res, next) {
name: 'Category: ' + category.name, name: 'Category: ' + category.name,
}; };
}); });
next(null, categoryData);
},
], function (err, categoryData) {
if (err || !categoryData) {
categoryData = [];
}
plugins.fireHook('filter:homepage.get', { routes: [
{
route: 'categories',
name: 'Categories',
},
{
route: 'recent',
name: 'Recent',
},
{
route: 'popular',
name: 'Popular',
},
].concat(categoryData) }, function (err, data) {
if (err) {
return next(err);
}
plugins.fireHook('filter:homepage.get', { routes: [
{
route: 'categories',
name: 'Categories',
},
{
route: 'recent',
name: 'Recent',
},
{
route: 'popular',
name: 'Popular',
},
].concat(categoryData) }, next);
},
function (data) {
data.routes.push({ data.routes.push({
route: '', route: '',
name: 'Custom', name: 'Custom',
}); });
res.render('admin/general/homepage', data); res.render('admin/general/homepage', data);
}); },
}); ], next);
}; };
module.exports = homePageController;

@ -1,26 +1,27 @@
'use strict'; 'use strict';
var async = require('async');
var languages = require('../../languages'); var languages = require('../../languages');
var meta = require('../../meta'); var meta = require('../../meta');
var languagesController = {}; var languagesController = module.exports;
languagesController.get = function (req, res, next) { languagesController.get = function (req, res, next) {
languages.list(function (err, languages) { async.waterfall([
if (err) { function (next) {
return next(err); languages.list(next);
} },
function (languages) {
languages.forEach(function (language) { languages.forEach(function (language) {
language.selected = language.code === (meta.config.defaultLang || 'en-GB'); language.selected = language.code === (meta.config.defaultLang || 'en-GB');
}); });
res.render('admin/general/languages', { res.render('admin/general/languages', {
languages: languages, languages: languages,
autoDetectLang: parseInt(meta.config.autoDetectLang, 10) === 1, autoDetectLang: parseInt(meta.config.autoDetectLang, 10) === 1,
}); });
}); },
], next);
}; };
module.exports = languagesController;

@ -1,9 +1,7 @@
'use strict'; 'use strict';
var loggerController = {}; var loggerController = module.exports;
loggerController.get = function (req, res) { loggerController.get = function (req, res) {
res.render('admin/development/logger', {}); res.render('admin/development/logger', {});
}; };
module.exports = loggerController;

@ -1,21 +1,23 @@
'use strict'; 'use strict';
var async = require('async');
var validator = require('validator'); var validator = require('validator');
var meta = require('../../meta');
var meta = require('../../meta');
var logsController = {}; var logsController = module.exports;
logsController.get = function (req, res, next) { logsController.get = function (req, res, next) {
meta.logs.get(function (err, logs) { async.waterfall([
if (err) { function (next) {
return next(err); meta.logs.get(next);
} },
function (logs) {
res.render('admin/advanced/logs', { res.render('admin/advanced/logs', {
data: validator.escape(logs), data: validator.escape(logs),
}); });
}); },
], next);
}; };

@ -3,54 +3,54 @@
var async = require('async'); var async = require('async');
var plugins = require('../../plugins'); var plugins = require('../../plugins');
var pluginsController = {}; var pluginsController = module.exports;
pluginsController.get = function (req, res, next) { pluginsController.get = function (req, res, next) {
async.parallel({ async.waterfall([
compatible: function (next) { function (next) {
plugins.list(function (err, plugins) { async.parallel({
if (err || !Array.isArray(plugins)) { compatible: function (next) {
plugins = []; plugins.list(function (err, plugins) {
} if (err || !Array.isArray(plugins)) {
plugins = [];
}
next(null, plugins); next(null, plugins);
}); });
},
all: function (next) {
plugins.list(false, function (err, plugins) {
if (err || !Array.isArray(plugins)) {
plugins = [];
}
next(null, plugins);
});
},
}, next);
}, },
all: function (next) { function (payload) {
plugins.list(false, function (err, plugins) { var compatiblePkgNames = payload.compatible.map(function (pkgData) {
if (err || !Array.isArray(plugins)) { return pkgData.name;
plugins = []; });
}
next(null, plugins); res.render('admin/extend/plugins', {
installed: payload.compatible.filter(function (plugin) {
return plugin.installed;
}),
upgradeCount: payload.compatible.reduce(function (count, current) {
if (current.installed && current.outdated) {
count += 1;
}
return count;
}, 0),
download: payload.compatible.filter(function (plugin) {
return !plugin.installed;
}),
incompatible: payload.all.filter(function (plugin) {
return compatiblePkgNames.indexOf(plugin.name) === -1;
}),
}); });
}, },
}, function (err, payload) { ], next);
if (err) {
return next(err);
}
var compatiblePkgNames = payload.compatible.map(function (pkgData) {
return pkgData.name;
});
res.render('admin/extend/plugins', {
installed: payload.compatible.filter(function (plugin) {
return plugin.installed;
}),
upgradeCount: payload.compatible.reduce(function (count, current) {
if (current.installed && current.outdated) {
count += 1;
}
return count;
}, 0),
download: payload.compatible.filter(function (plugin) {
return !plugin.installed;
}),
incompatible: payload.all.filter(function (plugin) {
return compatiblePkgNames.indexOf(plugin.name) === -1;
}),
});
});
}; };
module.exports = pluginsController;

@ -1,15 +1,18 @@
'use strict'; 'use strict';
var rewardsController = {}; var async = require('async');
rewardsController.get = function (req, res, next) { var rewardsController = module.exports;
require('../../rewards/admin').get(function (err, data) {
if (err) {
return next(err);
}
res.render('admin/extend/rewards', data); rewardsController.get = function (req, res, next) {
}); async.waterfall([
function (next) {
require('../../rewards/admin').get(next);
},
function (data) {
res.render('admin/extend/rewards', data);
},
], next);
}; };

@ -36,32 +36,30 @@ function renderEmail(req, res, next) {
async.map(emails, function (email, next) { async.map(emails, function (email, next) {
var path = email.replace(emailsPath, '').substr(1).replace('.tpl', ''); var path = email.replace(emailsPath, '').substr(1).replace('.tpl', '');
fs.readFile(email, function (err, original) { async.waterfall([
if (err) { function (next) {
return next(err); fs.readFile(email, next);
} },
function (original, next) {
var text = meta.config['email:custom:' + path] ? meta.config['email:custom:' + path] : original.toString();
var text = meta.config['email:custom:' + path] ? meta.config['email:custom:' + path] : original.toString(); next(null, {
path: path,
next(null, { fullpath: email,
path: path, text: text,
fullpath: email, original: original.toString(),
text: text, });
original: original.toString(), },
}); ], next);
});
}, next); }, next);
}, },
], function (err, emails) { function (emails) {
if (err) { res.render('admin/settings/email', {
return next(err); emails: emails,
} sendable: emails.filter(function (email) {
return email.path.indexOf('_plaintext') === -1 && email.path.indexOf('partials') === -1;
res.render('admin/settings/email', { }),
emails: emails, });
sendable: emails.filter(function (email) { },
return email.path.indexOf('_plaintext') === -1 && email.path.indexOf('partials') === -1; ], next);
}),
});
});
} }

@ -1,9 +1,11 @@
'use strict'; 'use strict';
var async = require('async');
var plugins = require('../../plugins'); var plugins = require('../../plugins');
var meta = require('../../meta'); var meta = require('../../meta');
var soundsController = {}; var soundsController = module.exports;
soundsController.get = function (req, res, next) { soundsController.get = function (req, res, next) {
var types = [ var types = [
@ -11,37 +13,36 @@ soundsController.get = function (req, res, next) {
'chat-incoming', 'chat-incoming',
'chat-outgoing', 'chat-outgoing',
]; ];
meta.configs.getFields(types, function (err, settings) { async.waterfall([
if (err) { function (next) {
return next(err); meta.configs.getFields(types, next);
} },
function (settings) {
settings = settings || {}; settings = settings || {};
var output = {}; var output = {};
types.forEach(function (type) {
var soundpacks = plugins.soundpacks.map(function (pack) {
var sounds = Object.keys(pack.sounds).map(function (soundName) {
var value = pack.name + ' | ' + soundName;
return {
name: soundName,
value: value,
selected: value === settings[type],
};
});
types.forEach(function (type) {
var soundpacks = plugins.soundpacks.map(function (pack) {
var sounds = Object.keys(pack.sounds).map(function (soundName) {
var value = pack.name + ' | ' + soundName;
return { return {
name: soundName, name: pack.name,
value: value, sounds: sounds,
selected: value === settings[type],
}; };
}); });
return { output[type + '-sound'] = soundpacks;
name: pack.name,
sounds: sounds,
};
}); });
output[type + '-sound'] = soundpacks; res.render('admin/general/sounds', output);
}); },
], next);
res.render('admin/general/sounds', output);
});
}; };
module.exports = soundsController;

@ -1,18 +1,18 @@
'use strict'; 'use strict';
var async = require('async');
var topics = require('../../topics'); var topics = require('../../topics');
var tagsController = {}; var tagsController = module.exports;
tagsController.get = function (req, res, next) { tagsController.get = function (req, res, next) {
topics.getTags(0, 199, function (err, tags) { async.waterfall([
if (err) { function (next) {
return next(err); topics.getTags(0, 199, next);
} },
function (tags) {
res.render('admin/manage/tags', { tags: tags }); res.render('admin/manage/tags', { tags: tags });
}); },
], next);
}; };
module.exports = tagsController;

@ -6,28 +6,23 @@ var async = require('async');
var file = require('../../file'); var file = require('../../file');
var themesController = {}; var themesController = module.exports;
var defaultScreenshotPath = path.join(__dirname, '../../../public/images/themes/default.png'); var defaultScreenshotPath = path.join(__dirname, '../../../public/images/themes/default.png');
themesController.get = function (req, res, next) { themesController.get = function (req, res, next) {
var themeDir = path.join(__dirname, '../../../node_modules', req.params.theme); var themeDir = path.join(__dirname, '../../../node_modules', req.params.theme);
var themeConfigPath = path.join(themeDir, 'theme.json'); var themeConfigPath = path.join(themeDir, 'theme.json');
var screenshotPath;
async.waterfall([ async.waterfall([
function (next) { function (next) {
file.exists(themeConfigPath, function (err, exists) { file.exists(themeConfigPath, next);
if (err) {
return next(err);
}
if (!exists) {
return next(Error('invalid-data'));
}
next();
});
}, },
function (next) { function (exists, next) {
if (!exists) {
return next(Error('invalid-data'));
}
fs.readFile(themeConfigPath, next); fs.readFile(themeConfigPath, next);
}, },
function (themeConfig, next) { function (themeConfig, next) {
@ -38,16 +33,13 @@ themesController.get = function (req, res, next) {
next(e); next(e);
} }
}, },
function (screenshotPath, next) { function (_screenshotPath, next) {
file.exists(screenshotPath, function (err, exists) { screenshotPath = _screenshotPath;
if (err) { file.exists(screenshotPath, next);
return next(err); },
} function (exists) {
res.sendFile(exists ? screenshotPath : defaultScreenshotPath);
res.sendFile(exists ? screenshotPath : defaultScreenshotPath);
});
}, },
], next); ], next);
}; };
module.exports = themesController;

@ -10,7 +10,7 @@ var pagination = require('../../pagination');
var events = require('../../events'); var events = require('../../events');
var plugins = require('../../plugins'); var plugins = require('../../plugins');
var usersController = {}; var usersController = module.exports;
var userFields = ['uid', 'username', 'userslug', 'email', 'postcount', 'joindate', 'banned', var userFields = ['uid', 'username', 'userslug', 'email', 'postcount', 'joindate', 'banned',
'reputation', 'picture', 'flags', 'lastonline', 'email:confirmed']; 'reputation', 'picture', 'flags', 'lastonline', 'email:confirmed'];
@ -63,57 +63,59 @@ usersController.registrationQueue = function (req, res, next) {
var stop = start + itemsPerPage - 1; var stop = start + itemsPerPage - 1;
var invitations; var invitations;
async.parallel({ async.waterfall([
registrationQueueCount: function (next) { function (next) {
db.sortedSetCard('registration:queue', next); async.parallel({
}, registrationQueueCount: function (next) {
users: function (next) { db.sortedSetCard('registration:queue', next);
user.getRegistrationQueue(start, stop, next);
},
customHeaders: function (next) {
plugins.fireHook('filter:admin.registrationQueue.customHeaders', { headers: [] }, next);
},
invites: function (next) {
async.waterfall([
function (next) {
user.getAllInvites(next);
}, },
function (_invitations, next) { users: function (next) {
invitations = _invitations; user.getRegistrationQueue(start, stop, next);
async.map(invitations, function (invites, next) {
user.getUserField(invites.uid, 'username', next);
}, next);
}, },
function (usernames, next) { customHeaders: function (next) {
invitations.forEach(function (invites, index) { plugins.fireHook('filter:admin.registrationQueue.customHeaders', { headers: [] }, next);
invites.username = usernames[index];
});
async.map(invitations, function (invites, next) {
async.map(invites.invitations, user.getUsernameByEmail, next);
}, next);
}, },
function (usernames, next) { invites: function (next) {
invitations.forEach(function (invites, index) { async.waterfall([
invites.invitations = invites.invitations.map(function (email, i) { function (next) {
return { user.getAllInvites(next);
email: email, },
username: usernames[index][i] === '[[global:guest]]' ? '' : usernames[index][i], function (_invitations, next) {
}; invitations = _invitations;
}); async.map(invitations, function (invites, next) {
}); user.getUserField(invites.uid, 'username', next);
next(null, invitations); }, next);
},
function (usernames, next) {
invitations.forEach(function (invites, index) {
invites.username = usernames[index];
});
async.map(invitations, function (invites, next) {
async.map(invites.invitations, user.getUsernameByEmail, next);
}, next);
},
function (usernames, next) {
invitations.forEach(function (invites, index) {
invites.invitations = invites.invitations.map(function (email, i) {
return {
email: email,
username: usernames[index][i] === '[[global:guest]]' ? '' : usernames[index][i],
};
});
});
next(null, invitations);
},
], next);
}, },
], next); }, next);
}, },
}, function (err, data) { function (data) {
if (err) { var pageCount = Math.max(1, Math.ceil(data.registrationQueueCount / itemsPerPage));
return next(err); data.pagination = pagination.create(page, pageCount);
} data.customHeaders = data.customHeaders.headers;
var pageCount = Math.max(1, Math.ceil(data.registrationQueueCount / itemsPerPage)); res.render('admin/manage/registration', data);
data.pagination = pagination.create(page, pageCount); },
data.customHeaders = data.customHeaders.headers; ], next);
res.render('admin/manage/registration', data);
});
}; };
function getUsers(set, section, min, max, req, res, next) { function getUsers(set, section, min, max, req, res, next) {
@ -123,47 +125,48 @@ function getUsers(set, section, min, max, req, res, next) {
var stop = start + resultsPerPage - 1; var stop = start + resultsPerPage - 1;
var byScore = min !== undefined && max !== undefined; var byScore = min !== undefined && max !== undefined;
async.parallel({ async.waterfall([
count: function (next) { function (next) {
if (byScore) { async.parallel({
db.sortedSetCount(set, min, max, next); count: function (next) {
} else if (set === 'users:banned' || set === 'users:notvalidated') {
db.sortedSetCard(set, next);
} else {
db.getObjectField('global', 'userCount', next);
}
},
users: function (next) {
async.waterfall([
function (next) {
if (byScore) { if (byScore) {
db.getSortedSetRevRangeByScore(set, start, resultsPerPage, max, min, next); db.sortedSetCount(set, min, max, next);
} else if (set === 'users:banned' || set === 'users:notvalidated') {
db.sortedSetCard(set, next);
} else { } else {
user.getUidsFromSet(set, start, stop, next); db.getObjectField('global', 'userCount', next);
} }
}, },
function (uids, next) { users: function (next) {
user.getUsersWithFields(uids, userFields, req.uid, next); async.waterfall([
function (next) {
if (byScore) {
db.getSortedSetRevRangeByScore(set, start, resultsPerPage, max, min, next);
} else {
user.getUidsFromSet(set, start, stop, next);
}
},
function (uids, next) {
user.getUsersWithFields(uids, userFields, req.uid, next);
},
], next);
}, },
], next); }, next);
}, },
}, function (err, results) { function (results) {
if (err) { results.users = results.users.filter(function (user) {
return next(err); user.email = validator.escape(String(user.email || ''));
} return user && parseInt(user.uid, 10);
});
results.users = results.users.filter(function (user) { var data = {
user.email = validator.escape(String(user.email || '')); users: results.users,
return user && parseInt(user.uid, 10); page: page,
}); pageCount: Math.max(1, Math.ceil(results.count / resultsPerPage)),
var data = { };
users: results.users, data[section] = true;
page: page, render(req, res, data);
pageCount: Math.max(1, Math.ceil(results.count / resultsPerPage)), },
}; ], next);
data[section] = true;
render(req, res, data);
});
} }
function render(req, res, data) { function render(req, res, data) {
@ -185,15 +188,14 @@ usersController.getCSV = function (req, res, next) {
uid: req.user.uid, uid: req.user.uid,
ip: req.ip, ip: req.ip,
}); });
async.waterfall([
user.getUsersCSV(function (err, data) { function (next) {
if (err) { user.getUsersCSV(next);
return next(err); },
} function (data) {
res.attachment('users.csv'); res.attachment('users.csv');
res.setHeader('Content-Type', 'text/csv'); res.setHeader('Content-Type', 'text/csv');
res.end(data); res.end(data);
}); },
], next);
}; };
module.exports = usersController;

@ -1,16 +1,16 @@
'use strict'; 'use strict';
var widgetsController = {}; var async = require('async');
widgetsController.get = function (req, res, next) { var widgetsController = module.exports;
require('../../widgets/admin').get(function (err, data) {
if (err) {
return next(err);
}
res.render('admin/extend/widgets', data); widgetsController.get = function (req, res, next) {
}); async.waterfall([
function (next) {
require('../../widgets/admin').get(next);
},
function (data) {
res.render('admin/extend/widgets', data);
},
], next);
}; };
module.exports = widgetsController;

@ -150,6 +150,9 @@ topicsController.get = function (req, res, callback) {
if (req.uid) { if (req.uid) {
topicData.rssFeedUrl += '?uid=' + req.uid + '&token=' + rssToken; topicData.rssFeedUrl += '?uid=' + req.uid + '&token=' + rssToken;
} }
addTags(topicData, req, res);
topicData.postIndex = req.params.post_index; topicData.postIndex = req.params.post_index;
topicData.pagination = pagination.create(currentPage, pageCount, req.query); topicData.pagination = pagination.create(currentPage, pageCount, req.query);
topicData.pagination.rel.forEach(function (rel) { topicData.pagination.rel.forEach(function (rel) {
@ -163,8 +166,6 @@ topicsController.get = function (req, res, callback) {
req.session.tids_viewed[tid] = Date.now(); req.session.tids_viewed[tid] = Date.now();
} }
addTags(topicData, req, res);
if (req.uid) { if (req.uid) {
topics.markAsRead([tid], req.uid, function (err, markedRead) { topics.markAsRead([tid], req.uid, function (err, markedRead) {
if (err) { if (err) {

Loading…
Cancel
Save