show categories in unread as tree

v1.18.x
barisusakli 8 years ago
parent a72ccfb067
commit f46755759a

@ -292,7 +292,7 @@ var privileges = require('./privileges');
for (i; i < len; ++i) { for (i; i < len; ++i) {
category = categories[i]; category = categories[i];
if (!category.hasOwnProperty('parentCid')) { if (!category.hasOwnProperty('parentCid') || category.parentCid === null) {
category.parentCid = 0; category.parentCid = 0;
} }

@ -100,12 +100,13 @@ function getWatchedCategories(uid, selectedCid, callback) {
privileges.categories.filterCids('read', cids, uid, next); privileges.categories.filterCids('read', cids, uid, next);
}, },
function (cids, 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) { function (categoryData, next) {
categoryData = categoryData.filter(function(category) { categoryData = categoryData.filter(function(category) {
return category && !category.link; return category && !category.link;
}); });
var selectedCategory; var selectedCategory;
categoryData.forEach(function(category) { categoryData.forEach(function(category) {
category.selected = parseInt(category.cid, 10) === parseInt(selectedCid, 10); category.selected = parseInt(category.cid, 10) === parseInt(selectedCid, 10);
@ -113,11 +114,27 @@ function getWatchedCategories(uid, selectedCid, callback) {
selectedCategory = category; 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); ], callback);
} }
function recursive(category, categoriesData, level) {
category.level = level;
categoriesData.push(category);
category.children.forEach(function(child) {
recursive(child, categoriesData, '&nbsp;&nbsp;&nbsp;&nbsp;' + level);
});
}
unreadController.unreadTotal = function(req, res, next) { unreadController.unreadTotal = function(req, res, next) {
var filter = req.params.filter || ''; var filter = req.params.filter || '';

Loading…
Cancel
Save