feat: async/await admin/controllers
parent
216eba6847
commit
72590b3462
@ -1,52 +1,31 @@
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
const groups = require('../../groups');
|
||||
const categories = require('../../categories');
|
||||
const privileges = require('../../privileges');
|
||||
|
||||
var groups = require('../../groups');
|
||||
var categories = require('../../categories');
|
||||
var privileges = require('../../privileges');
|
||||
const AdminsMods = module.exports;
|
||||
|
||||
var AdminsMods = module.exports;
|
||||
AdminsMods.get = async function (req, res) {
|
||||
const [admins, globalMods, categories] = await Promise.all([
|
||||
groups.get('administrators', { uid: req.uid }),
|
||||
groups.get('Global Moderators', { uid: req.uid }),
|
||||
getModeratorsOfCategories(req.uid),
|
||||
]);
|
||||
|
||||
AdminsMods.get = function (req, res, next) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
async.parallel({
|
||||
admins: function (next) {
|
||||
groups.get('administrators', { uid: req.uid }, next);
|
||||
},
|
||||
globalMods: function (next) {
|
||||
groups.get('Global Moderators', { uid: req.uid }, next);
|
||||
},
|
||||
categories: function (next) {
|
||||
getModeratorsOfCategories(req.uid, next);
|
||||
},
|
||||
}, next);
|
||||
},
|
||||
function (results) {
|
||||
results.allPrivileges = privileges.userPrivilegeList;
|
||||
res.render('admin/manage/admins-mods', results);
|
||||
},
|
||||
], next);
|
||||
res.render('admin/manage/admins-mods', {
|
||||
admins: admins,
|
||||
globalMods: globalMods,
|
||||
categories: categories,
|
||||
allPrivileges: privileges.userPrivilegeList,
|
||||
});
|
||||
};
|
||||
|
||||
function getModeratorsOfCategories(uid, callback) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
categories.buildForSelect(uid, 'find', next);
|
||||
},
|
||||
function (categoryData, next) {
|
||||
async.map(categoryData, function (category, next) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
categories.getModerators(category.cid, next);
|
||||
},
|
||||
function (moderators, next) {
|
||||
category.moderators = moderators;
|
||||
next(null, category);
|
||||
},
|
||||
], next);
|
||||
}, next);
|
||||
},
|
||||
], callback);
|
||||
async function getModeratorsOfCategories(uid) {
|
||||
const categoryData = await categories.buildForSelect(uid, 'find');
|
||||
const moderators = await Promise.all(categoryData.map(c => categories.getModerators(c.cid)));
|
||||
categoryData.forEach((c, index) => {
|
||||
c.moderators = moderators[index];
|
||||
});
|
||||
return categoryData;
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
var appearanceController = module.exports;
|
||||
const appearanceController = module.exports;
|
||||
|
||||
appearanceController.get = function (req, res) {
|
||||
var term = req.params.term ? req.params.term : 'themes';
|
||||
const term = req.params.term ? req.params.term : 'themes';
|
||||
|
||||
res.render('admin/appearance/' + term, {});
|
||||
};
|
||||
|
@ -1,22 +1,18 @@
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
var meta = require('../../meta');
|
||||
var analytics = require('../../analytics');
|
||||
const meta = require('../../meta');
|
||||
const analytics = require('../../analytics');
|
||||
|
||||
var blacklistController = module.exports;
|
||||
const blacklistController = module.exports;
|
||||
|
||||
blacklistController.get = function (req, res, next) {
|
||||
async.parallel({
|
||||
rules: async.apply(meta.blacklist.get),
|
||||
analytics: async.apply(analytics.getBlacklistAnalytics),
|
||||
}, function (err, data) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
res.render('admin/manage/ip-blacklist', Object.assign(data, {
|
||||
title: '[[pages:ip-blacklist]]',
|
||||
}));
|
||||
blacklistController.get = async function (req, res) {
|
||||
const [rules, analyticsData] = await Promise.all([
|
||||
meta.blacklist.get(),
|
||||
analytics.getBlacklistAnalytics(),
|
||||
]);
|
||||
res.render('admin/manage/ip-blacklist', {
|
||||
title: '[[pages:ip-blacklist]]',
|
||||
rules: rules,
|
||||
analytics: analyticsData,
|
||||
});
|
||||
};
|
||||
|
@ -1,84 +1,66 @@
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
const categories = require('../../categories');
|
||||
const analytics = require('../../analytics');
|
||||
const plugins = require('../../plugins');
|
||||
const translator = require('../../translator');
|
||||
|
||||
var categories = require('../../categories');
|
||||
var analytics = require('../../analytics');
|
||||
var plugins = require('../../plugins');
|
||||
var translator = require('../../translator');
|
||||
const categoriesController = module.exports;
|
||||
|
||||
var categoriesController = module.exports;
|
||||
categoriesController.get = async function (req, res, next) {
|
||||
const [categoryData, parent, allCategories] = await Promise.all([
|
||||
categories.getCategories([req.params.category_id], req.uid),
|
||||
categories.getParents([req.params.category_id]),
|
||||
getAllCategories(req.uid),
|
||||
]);
|
||||
|
||||
categoriesController.get = function (req, res, callback) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
async.parallel({
|
||||
category: async.apply(categories.getCategories, [req.params.category_id], req.uid),
|
||||
parent: async.apply(categories.getParents, [req.params.category_id]),
|
||||
allCategories: function (next) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
categories.getAllCidsFromSet('categories:cid', next);
|
||||
},
|
||||
function (cids, next) {
|
||||
categories.getCategories(cids, req.uid, next);
|
||||
},
|
||||
function (categoryData, next) {
|
||||
categoryData = categories.getTree(categoryData);
|
||||
categories.buildForSelectCategories(categoryData, next);
|
||||
},
|
||||
], next);
|
||||
},
|
||||
}, next);
|
||||
},
|
||||
function (data, next) {
|
||||
var category = data.category[0];
|
||||
const category = categoryData[0];
|
||||
if (!category) {
|
||||
return next();
|
||||
}
|
||||
|
||||
if (!category) {
|
||||
return callback();
|
||||
}
|
||||
category.parent = data.parent[0];
|
||||
data.allCategories.forEach(function (category) {
|
||||
if (category) {
|
||||
category.selected = parseInt(category.cid, 10) === parseInt(req.params.category_id, 10);
|
||||
}
|
||||
});
|
||||
category.parent = parent[0];
|
||||
allCategories.forEach(function (category) {
|
||||
if (category) {
|
||||
category.selected = parseInt(category.cid, 10) === parseInt(req.params.category_id, 10);
|
||||
}
|
||||
});
|
||||
|
||||
plugins.fireHook('filter:admin.category.get', {
|
||||
req: req,
|
||||
res: res,
|
||||
category: category,
|
||||
customClasses: [],
|
||||
allCategories: data.allCategories,
|
||||
}, next);
|
||||
},
|
||||
function (data) {
|
||||
data.category.name = translator.escape(String(data.category.name));
|
||||
const data = await plugins.fireHook('filter:admin.category.get', {
|
||||
req: req,
|
||||
res: res,
|
||||
category: category,
|
||||
customClasses: [],
|
||||
allCategories: allCategories,
|
||||
});
|
||||
data.category.name = translator.escape(String(data.category.name));
|
||||
|
||||
res.render('admin/manage/category', {
|
||||
category: data.category,
|
||||
allCategories: data.allCategories,
|
||||
customClasses: data.customClasses,
|
||||
});
|
||||
},
|
||||
], callback);
|
||||
res.render('admin/manage/category', {
|
||||
category: data.category,
|
||||
allCategories: data.allCategories,
|
||||
customClasses: data.customClasses,
|
||||
});
|
||||
};
|
||||
|
||||
async function getAllCategories(uid) {
|
||||
const cids = await categories.getAllCidsFromSet('categories:cid');
|
||||
const categoryData = await categories.getCategories(cids, uid);
|
||||
const tree = categories.getTree(categoryData);
|
||||
return await categories.buildForSelectCategories(tree);
|
||||
}
|
||||
|
||||
categoriesController.getAll = function (req, res) {
|
||||
// Categories list will be rendered on client side with recursion, etc.
|
||||
res.render('admin/manage/categories', {});
|
||||
};
|
||||
|
||||
categoriesController.getAnalytics = function (req, res, next) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
async.parallel({
|
||||
name: async.apply(categories.getCategoryField, req.params.category_id, 'name'),
|
||||
analytics: async.apply(analytics.getCategoryAnalytics, req.params.category_id),
|
||||
}, next);
|
||||
},
|
||||
function (data) {
|
||||
res.render('admin/manage/category-analytics', data);
|
||||
},
|
||||
], next);
|
||||
categoriesController.getAnalytics = async function (req, res) {
|
||||
const [name, analyticsData] = await Promise.all([
|
||||
categories.getCategoryField(req.params.category_id, 'name'),
|
||||
analytics.getCategoryAnalytics(req.params.category_id),
|
||||
]);
|
||||
res.render('admin/manage/category-analytics', {
|
||||
name: name,
|
||||
analytics: analyticsData,
|
||||
});
|
||||
};
|
||||
|
Loading…
Reference in New Issue