mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
fix: returned data
This commit is contained in:
@@ -350,7 +350,13 @@ Categories.buildForSelectCategories = function (categories) {
|
||||
categories = categories.filter(category => category && !category.parentCid);
|
||||
|
||||
categories.forEach(category => recursive(category, categoriesData, '', 0));
|
||||
return categoriesData;
|
||||
const pickFields = [
|
||||
'name', 'level', 'disabledClass', 'icon', 'value', 'text',
|
||||
'cid', 'parentCid', 'color', 'bgColor', 'backgroundImage', 'imageClass',
|
||||
'disabled', 'depth',
|
||||
];
|
||||
|
||||
return categoriesData.map(category => _.pick(category, pickFields));
|
||||
};
|
||||
|
||||
Categories.async = require('../promisify')(Categories);
|
||||
|
||||
@@ -4,7 +4,6 @@ const nconf = require('nconf');
|
||||
const validator = require('validator');
|
||||
const winston = require('winston');
|
||||
const querystring = require('querystring');
|
||||
const _ = require('lodash');
|
||||
|
||||
const user = require('../user');
|
||||
const privileges = require('../privileges');
|
||||
@@ -12,7 +11,6 @@ const categories = require('../categories');
|
||||
const plugins = require('../plugins');
|
||||
const meta = require('../meta');
|
||||
const middleware = require('../middleware');
|
||||
const utils = require('../utils');
|
||||
|
||||
const helpers = module.exports;
|
||||
|
||||
@@ -233,11 +231,13 @@ async function getCategoryData(cids, uid, selectedCid) {
|
||||
let categoryData = await categories.getCategoriesFields(cids, categoryFields);
|
||||
categoryData = categoryData.filter(category => category && !category.link);
|
||||
|
||||
categories.getTree(categoryData);
|
||||
const categoriesData = categories.buildForSelectCategories(categoryData);
|
||||
|
||||
let selectedCategory = [];
|
||||
const selectedCids = [];
|
||||
categoryData.forEach(function (category) {
|
||||
categoriesData.forEach(function (category) {
|
||||
category.selected = selectedCid ? selectedCid.includes(String(category.cid)) : false;
|
||||
category.parentCid = category.hasOwnProperty('parentCid') && utils.isNumber(category.parentCid) ? category.parentCid : 0;
|
||||
if (category.selected) {
|
||||
selectedCategory.push(category);
|
||||
selectedCids.push(category.cid);
|
||||
@@ -257,14 +257,8 @@ async function getCategoryData(cids, uid, selectedCid) {
|
||||
selectedCategory = undefined;
|
||||
}
|
||||
|
||||
|
||||
categories.getTree(categoryData);
|
||||
const categoriesData = categories.buildForSelectCategories(categoryData);
|
||||
|
||||
return {
|
||||
categories: categoriesData.map(category => _.pick(category, [
|
||||
'cid', 'name', 'icon', 'color', 'bgColor', 'parentCid', 'backgroundImage', 'imageClass', 'selected', 'level',
|
||||
])),
|
||||
categories: categoriesData,
|
||||
selectedCategory: selectedCategory,
|
||||
selectedCids: selectedCids,
|
||||
};
|
||||
|
||||
@@ -87,11 +87,11 @@ async function buildCategories(uid, searchOnly) {
|
||||
|
||||
const cids = await categories.getCidsByPrivilege('categories:cid', uid, 'read');
|
||||
let categoriesData = await categories.getCategoriesData(cids);
|
||||
categoriesData = categoriesData.filter(category => category && !category.link);
|
||||
categoriesData = categories.getTree(categoriesData);
|
||||
categoriesData = categories.buildForSelectCategories(categoriesData);
|
||||
categoriesData = categoriesData.map(category => ({ value: category.value, text: category.text }));
|
||||
|
||||
categoriesData = categoriesData.filter(category => category && !category.link)
|
||||
.map(category => ({ value: category.value, text: category.text }));
|
||||
return [
|
||||
{ value: 'all', text: '[[unread:all_categories]]' },
|
||||
{ value: 'watched', text: '[[category:watched-categories]]' },
|
||||
|
||||
Reference in New Issue
Block a user