mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-16 10:46:14 +01:00
show categories in unread as tree
This commit is contained in:
@@ -292,7 +292,7 @@ var privileges = require('./privileges');
|
||||
|
||||
for (i; i < len; ++i) {
|
||||
category = categories[i];
|
||||
if (!category.hasOwnProperty('parentCid')) {
|
||||
if (!category.hasOwnProperty('parentCid') || category.parentCid === null) {
|
||||
category.parentCid = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -100,12 +100,13 @@ function getWatchedCategories(uid, selectedCid, callback) {
|
||||
privileges.categories.filterCids('read', cids, uid, next);
|
||||
},
|
||||
function (cids, next) {
|
||||
categories.getCategoriesFields(cids, ['cid', 'name', 'slug', 'icon', 'link', 'color', 'bgColor'], next);
|
||||
categories.getCategoriesFields(cids, ['cid', 'name', 'slug', 'icon', 'link', 'color', 'bgColor', 'parentCid'], next);
|
||||
},
|
||||
function (categoryData, next) {
|
||||
categoryData = categoryData.filter(function(category) {
|
||||
return category && !category.link;
|
||||
});
|
||||
|
||||
var selectedCategory;
|
||||
categoryData.forEach(function(category) {
|
||||
category.selected = parseInt(category.cid, 10) === parseInt(selectedCid, 10);
|
||||
@@ -113,11 +114,27 @@ function getWatchedCategories(uid, selectedCid, callback) {
|
||||
selectedCategory = category;
|
||||
}
|
||||
});
|
||||
next(null, {categories: categoryData, selectedCategory: selectedCategory});
|
||||
|
||||
var categoriesData = [];
|
||||
var tree = categories.getTree(categoryData, 0);
|
||||
|
||||
tree.forEach(function(category) {
|
||||
recursive(category, categoriesData, '');
|
||||
});
|
||||
|
||||
next(null, {categories: categoriesData, selectedCategory: selectedCategory});
|
||||
}
|
||||
], callback);
|
||||
}
|
||||
|
||||
function recursive(category, categoriesData, level) {
|
||||
category.level = level;
|
||||
categoriesData.push(category);
|
||||
|
||||
category.children.forEach(function(child) {
|
||||
recursive(child, categoriesData, ' ' + level);
|
||||
});
|
||||
}
|
||||
|
||||
unreadController.unreadTotal = function(req, res, next) {
|
||||
var filter = req.params.filter || '';
|
||||
|
||||
Reference in New Issue
Block a user