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,10 +7,11 @@ 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.waterfall([
function (next) {
async.parallel({ async.parallel({
stats: function (next) { stats: function (next) {
getStats(next); getStats(next);
@ -40,19 +41,21 @@ dashboardController.get = function (req, res, next) {
plugins.fireHook('filter:admin.notices', notices, next); plugins.fireHook('filter:admin.notices', notices, next);
}, },
}, function (err, results) { }, next);
if (err) { },
return next(err); function (results) {
}
res.render('admin/general/dashboard', { res.render('admin/general/dashboard', {
version: nconf.get('version'), version: nconf.get('version'),
notices: results.notices, notices: results.notices,
stats: results.stats, stats: results.stats,
}); });
}); },
], next);
}; };
function getStats(callback) { function getStats(callback) {
async.waterfall([
function (next) {
async.parallel([ async.parallel([
function (next) { function (next) {
getStatsForSet('ip:recent', 'uniqueIPCount', next); getStatsForSet('ip:recent', 'uniqueIPCount', next);
@ -66,17 +69,17 @@ function getStats(callback) {
function (next) { function (next) {
getStatsForSet('topics:tid', 'topicCount', next); getStatsForSet('topics:tid', 'topicCount', next);
}, },
], function (err, results) { ], next);
if (err) { },
return callback(err); function (results, next) {
}
results[0].name = '[[admin/general/dashboard:unique-visitors]]'; results[0].name = '[[admin/general/dashboard:unique-visitors]]';
results[1].name = '[[admin/general/dashboard:users]]'; results[1].name = '[[admin/general/dashboard:users]]';
results[2].name = '[[admin/general/dashboard:posts]]'; results[2].name = '[[admin/general/dashboard:posts]]';
results[3].name = '[[admin/general/dashboard:topics]]'; 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,10 +3,11 @@
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.waterfall([
function (next) {
async.parallel({ async.parallel({
redis: function (next) { redis: function (next) {
if (nconf.get('redis')) { if (nconf.get('redis')) {
@ -24,12 +25,10 @@ databaseController.get = function (req, res, next) {
next(); next();
} }
}, },
}, function (err, results) { }, next);
if (err) { },
return next(err); function (results) {
}
res.render('admin/advanced/database', results); res.render('admin/advanced/database', results);
}); },
], next);
}; };
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.waterfall([
function (next) {
async.parallel({ async.parallel({
'not-found': async.apply(meta.errors.get, true), 'not-found': async.apply(meta.errors.get, true),
analytics: async.apply(analytics.getErrorAnalytics), analytics: async.apply(analytics.getErrorAnalytics),
}, function (err, data) { }, next);
if (err) { },
return next(err); 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) {
return next(err);
}
res.set('Content-Type', 'text/csv').set('Content-Disposition', 'attachment; filename="404.csv"').send(csv); res.set('Content-Type', 'text/csv').set('Content-Disposition', 'attachment; filename="404.csv"').send(csv);
}); },
], next);
}; };
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,6 +14,8 @@ 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.waterfall([
function (next) {
async.parallel({ async.parallel({
eventCount: function (next) { eventCount: function (next) {
db.sortedSetCard('events:time', next); db.sortedSetCard('events:time', next);
@ -22,11 +23,9 @@ eventsController.get = function (req, res, next) {
events: function (next) { events: function (next) {
events.getEvents(start, stop, next); events.getEvents(start, stop, next);
}, },
}, function (err, results) { }, next);
if (err) { },
return next(err); function (results) {
}
var pageCount = Math.max(1, Math.ceil(results.eventCount / itemsPerPage)); var pageCount = Math.max(1, Math.ceil(results.eventCount / itemsPerPage));
res.render('admin/advanced/events', { res.render('admin/advanced/events', {
@ -34,8 +33,7 @@ eventsController.get = function (req, res, next) {
pagination: pagination.create(page, pageCount), pagination: pagination.create(page, pageCount),
next: 20, next: 20,
}); });
}); },
], next);
}; };
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) });
},
], function (err, data) {
if (err) {
return next(err);
}
res.render('admin/manage/groups', { res.render('admin/manage/groups', {
groups: data.groups, groups: groupData,
pagination: data.pagination, pagination: pagination.create(page, pageCount),
yourid: req.uid, yourid: req.uid,
}); });
}); },
], next);
}; };
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) {
return callback(err);
}
group.isOwner = true; group.isOwner = true;
res.render('admin/manage/group', { group: group, 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,12 +27,6 @@ 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: [ plugins.fireHook('filter:homepage.get', { routes: [
{ {
@ -48,19 +41,15 @@ homePageController.get = function (req, res, next) {
route: 'popular', route: 'popular',
name: 'Popular', name: 'Popular',
}, },
].concat(categoryData) }, function (err, data) { ].concat(categoryData) }, next);
if (err) { },
return next(err); 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,17 +1,18 @@
'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');
}); });
@ -20,7 +21,7 @@ languagesController.get = function (req, res, next) {
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,9 +3,11 @@
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.waterfall([
function (next) {
async.parallel({ async.parallel({
compatible: function (next) { compatible: function (next) {
plugins.list(function (err, plugins) { plugins.list(function (err, plugins) {
@ -25,10 +27,9 @@ pluginsController.get = function (req, res, next) {
next(null, plugins); next(null, plugins);
}); });
}, },
}, function (err, payload) { }, next);
if (err) { },
return next(err); function (payload) {
}
var compatiblePkgNames = payload.compatible.map(function (pkgData) { var compatiblePkgNames = payload.compatible.map(function (pkgData) {
return pkgData.name; return pkgData.name;
}); });
@ -50,7 +51,6 @@ pluginsController.get = function (req, res, next) {
return compatiblePkgNames.indexOf(plugin.name) === -1; return compatiblePkgNames.indexOf(plugin.name) === -1;
}), }),
}); });
}); },
], next);
}; };
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);
}
rewardsController.get = function (req, res, next) {
async.waterfall([
function (next) {
require('../../rewards/admin').get(next);
},
function (data) {
res.render('admin/extend/rewards', data); res.render('admin/extend/rewards', data);
}); },
], next);
}; };

@ -36,11 +36,11 @@ 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, { next(null, {
@ -49,19 +49,17 @@ function renderEmail(req, res, next) {
text: text, text: text,
original: original.toString(), original: original.toString(),
}); });
}); },
], next);
}, next); }, next);
}, },
], function (err, emails) { function (emails) {
if (err) {
return next(err);
}
res.render('admin/settings/email', { res.render('admin/settings/email', {
emails: emails, emails: emails,
sendable: emails.filter(function (email) { sendable: emails.filter(function (email) {
return email.path.indexOf('_plaintext') === -1 && email.path.indexOf('partials') === -1; 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,11 +13,11 @@ 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 = {};
@ -41,7 +43,6 @@ soundsController.get = function (req, res, next) {
}); });
res.render('admin/general/sounds', output); res.render('admin/general/sounds', output);
}); },
], next);
}; };
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); function (exists, next) {
}
if (!exists) { if (!exists) {
return next(Error('invalid-data')); return next(Error('invalid-data'));
} }
next();
});
},
function (next) {
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,6 +63,8 @@ usersController.registrationQueue = function (req, res, next) {
var stop = start + itemsPerPage - 1; var stop = start + itemsPerPage - 1;
var invitations; var invitations;
async.waterfall([
function (next) {
async.parallel({ async.parallel({
registrationQueueCount: function (next) { registrationQueueCount: function (next) {
db.sortedSetCard('registration:queue', next); db.sortedSetCard('registration:queue', next);
@ -105,15 +107,15 @@ usersController.registrationQueue = function (req, res, next) {
}, },
], next); ], next);
}, },
}, function (err, data) { }, next);
if (err) { },
return next(err); function (data) {
}
var pageCount = Math.max(1, Math.ceil(data.registrationQueueCount / itemsPerPage)); var pageCount = Math.max(1, Math.ceil(data.registrationQueueCount / itemsPerPage));
data.pagination = pagination.create(page, pageCount); data.pagination = pagination.create(page, pageCount);
data.customHeaders = data.customHeaders.headers; data.customHeaders = data.customHeaders.headers;
res.render('admin/manage/registration', data); res.render('admin/manage/registration', data);
}); },
], next);
}; };
function getUsers(set, section, min, max, req, res, next) { function getUsers(set, section, min, max, req, res, next) {
@ -123,6 +125,8 @@ 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.waterfall([
function (next) {
async.parallel({ async.parallel({
count: function (next) { count: function (next) {
if (byScore) { if (byScore) {
@ -147,11 +151,9 @@ function getUsers(set, section, min, max, req, res, next) {
}, },
], next); ], next);
}, },
}, function (err, results) { }, next);
if (err) { },
return next(err); function (results) {
}
results.users = results.users.filter(function (user) { results.users = results.users.filter(function (user) {
user.email = validator.escape(String(user.email || '')); user.email = validator.escape(String(user.email || ''));
return user && parseInt(user.uid, 10); return user && parseInt(user.uid, 10);
@ -163,7 +165,8 @@ function getUsers(set, section, min, max, req, res, next) {
}; };
data[section] = true; data[section] = true;
render(req, res, data); render(req, res, data);
}); },
], next);
} }
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);
}
widgetsController.get = function (req, res, next) {
async.waterfall([
function (next) {
require('../../widgets/admin').get(next);
},
function (data) {
res.render('admin/extend/widgets', 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