mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-07 22:45:46 +01:00
feat: reduce amount of data loaded on acp admin page
get rid of socket call and use ajaxify.data.categories
This commit is contained in:
@@ -11,13 +11,7 @@ define('admin/manage/categories', [
|
|||||||
var sortables;
|
var sortables;
|
||||||
|
|
||||||
Categories.init = function () {
|
Categories.init = function () {
|
||||||
socket.emit('admin.categories.getAll', function (err, payload) {
|
Categories.render(ajaxify.data.categories);
|
||||||
if (err) {
|
|
||||||
return app.alertError(err.message);
|
|
||||||
}
|
|
||||||
|
|
||||||
Categories.render(payload);
|
|
||||||
});
|
|
||||||
|
|
||||||
$('button[data-action="create"]').on('click', Categories.throwCreateModal);
|
$('button[data-action="create"]').on('click', Categories.throwCreateModal);
|
||||||
|
|
||||||
|
|||||||
@@ -43,9 +43,19 @@ categoriesController.get = async function (req, res, next) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
categoriesController.getAll = function (req, res) {
|
categoriesController.getAll = async function (req, res) {
|
||||||
// Categories list will be rendered on client side with recursion, etc.
|
// Categories list will be rendered on client side with recursion, etc.
|
||||||
res.render('admin/manage/categories', {});
|
const cids = await categories.getAllCidsFromSet('categories:cid');
|
||||||
|
const fields = [
|
||||||
|
'cid', 'name', 'level', 'icon', 'parentCid', 'disabled', 'link',
|
||||||
|
'color', 'bgColor', 'backgroundImage', 'imageClass',
|
||||||
|
];
|
||||||
|
const categoriesData = await categories.getCategoriesFields(cids, fields);
|
||||||
|
const result = await plugins.fireHook('filter:admin.categories.get', { categories: categoriesData, fields: fields });
|
||||||
|
const tree = categories.getTree(result.categories, 0);
|
||||||
|
res.render('admin/manage/categories', {
|
||||||
|
categories: tree,
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
categoriesController.getAnalytics = async function (req, res) {
|
categoriesController.getAnalytics = async function (req, res) {
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const winston = require('winston');
|
||||||
|
|
||||||
const groups = require('../../groups');
|
const groups = require('../../groups');
|
||||||
const user = require('../../user');
|
const user = require('../../user');
|
||||||
const categories = require('../../categories');
|
const categories = require('../../categories');
|
||||||
@@ -18,9 +20,14 @@ Categories.create = async function (socket, data) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Categories.getAll = async function () {
|
Categories.getAll = async function () {
|
||||||
|
winston.warn('[deprecated] admin.categories.getAll deprecated, data is returned in the api route');
|
||||||
const cids = await categories.getAllCidsFromSet('categories:cid');
|
const cids = await categories.getAllCidsFromSet('categories:cid');
|
||||||
const categoriesData = await categories.getCategoriesData(cids);
|
const fields = [
|
||||||
const result = await plugins.fireHook('filter:admin.categories.get', { categories: categoriesData });
|
'cid', 'name', 'level', 'icon', 'parentCid', 'disabled', 'link',
|
||||||
|
'color', 'bgColor', 'backgroundImage', 'imageClass',
|
||||||
|
];
|
||||||
|
const categoriesData = await categories.getCategoriesFields(cids, fields);
|
||||||
|
const result = await plugins.fireHook('filter:admin.categories.get', { categories: categoriesData, fields: fields });
|
||||||
return categories.getTree(result.categories, 0);
|
return categories.getTree(result.categories, 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user