mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-12 08:55:47 +01:00
remove more parseints
This commit is contained in:
@@ -89,12 +89,10 @@ function modifyCategory(category) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (category.hasOwnProperty('post_count')) {
|
if (category.hasOwnProperty('post_count')) {
|
||||||
category.post_count = category.post_count || 0;
|
|
||||||
category.totalPostCount = category.post_count;
|
category.totalPostCount = category.post_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (category.hasOwnProperty('topic_count')) {
|
if (category.hasOwnProperty('topic_count')) {
|
||||||
category.topic_count = category.topic_count || 0;
|
|
||||||
category.totalTopicCount = category.topic_count;
|
category.totalTopicCount = category.topic_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ Categories.getCategories = function (cids, uid, callback) {
|
|||||||
category.children = results.children[i];
|
category.children = results.children[i];
|
||||||
category.parent = results.parents[i] || undefined;
|
category.parent = results.parents[i] || undefined;
|
||||||
category.tagWhitelist = results.tagWhitelist[i];
|
category.tagWhitelist = results.tagWhitelist[i];
|
||||||
category['unread-class'] = (parseInt(category.topic_count, 10) === 0 || (results.hasRead[i] && uid !== 0)) ? '' : 'unread';
|
category['unread-class'] = (category.topic_count === 0 || (results.hasRead[i] && uid !== 0)) ? '' : 'unread';
|
||||||
calculateTopicPostCount(category);
|
calculateTopicPostCount(category);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -168,8 +168,8 @@ function calculateTopicPostCount(category) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var postCount = parseInt(category.post_count, 10) || 0;
|
var postCount = category.post_count;
|
||||||
var topicCount = parseInt(category.topic_count, 10) || 0;
|
var topicCount = category.topic_count;
|
||||||
if (!Array.isArray(category.children) || !category.children.length) {
|
if (!Array.isArray(category.children) || !category.children.length) {
|
||||||
category.totalPostCount = postCount;
|
category.totalPostCount = postCount;
|
||||||
category.totalTopicCount = topicCount;
|
category.totalTopicCount = topicCount;
|
||||||
@@ -196,21 +196,17 @@ Categories.getParents = function (cids, callback) {
|
|||||||
function (_categoriesData, next) {
|
function (_categoriesData, next) {
|
||||||
categoriesData = _categoriesData;
|
categoriesData = _categoriesData;
|
||||||
|
|
||||||
parentCids = categoriesData.filter(function (category) {
|
parentCids = categoriesData.filter(c => c && c.parentCid).map(c => c.parentCid);
|
||||||
return category && category.hasOwnProperty('parentCid') && parseInt(category.parentCid, 10);
|
|
||||||
}).map(function (category) {
|
|
||||||
return parseInt(category.parentCid, 10);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!parentCids.length) {
|
if (!parentCids.length) {
|
||||||
return callback(null, cids.map(function () { return null; }));
|
return callback(null, cids.map(() => null));
|
||||||
}
|
}
|
||||||
|
|
||||||
Categories.getCategoriesData(parentCids, next);
|
Categories.getCategoriesData(parentCids, next);
|
||||||
},
|
},
|
||||||
function (parentData, next) {
|
function (parentData, next) {
|
||||||
parentData = categoriesData.map(function (category) {
|
parentData = categoriesData.map(function (category) {
|
||||||
return parentData[parentCids.indexOf(parseInt(category.parentCid, 10))];
|
return parentData[parentCids.indexOf(category.parentCid)];
|
||||||
});
|
});
|
||||||
next(null, parentData);
|
next(null, parentData);
|
||||||
},
|
},
|
||||||
@@ -253,16 +249,14 @@ function getChildrenRecursive(category, uid, callback) {
|
|||||||
children = children.filter(Boolean);
|
children = children.filter(Boolean);
|
||||||
category.children = children;
|
category.children = children;
|
||||||
|
|
||||||
var cids = children.map(function (child) {
|
var cids = children.map(child => child.cid);
|
||||||
return child.cid;
|
|
||||||
});
|
|
||||||
|
|
||||||
Categories.hasReadCategories(cids, uid, next);
|
Categories.hasReadCategories(cids, uid, next);
|
||||||
},
|
},
|
||||||
function (hasRead, next) {
|
function (hasRead, next) {
|
||||||
hasRead.forEach(function (read, i) {
|
hasRead.forEach(function (read, i) {
|
||||||
var child = category.children[i];
|
var child = category.children[i];
|
||||||
child['unread-class'] = (parseInt(child.topic_count, 10) === 0 || (read && uid !== 0)) ? '' : 'unread';
|
child['unread-class'] = (child.topic_count === 0 || (read && uid !== 0)) ? '' : 'unread';
|
||||||
});
|
});
|
||||||
|
|
||||||
next();
|
next();
|
||||||
@@ -304,7 +298,7 @@ Categories.getTree = function (categories, parentCid) {
|
|||||||
category.parentCid = 0;
|
category.parentCid = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parseInt(category.parentCid, 10) === parseInt(parentCid, 10)) {
|
if (category.parentCid === parentCid) {
|
||||||
tree.push(category);
|
tree.push(category);
|
||||||
category.children = Categories.getTree(categories, category.cid);
|
category.children = Categories.getTree(categories, category.cid);
|
||||||
}
|
}
|
||||||
@@ -341,9 +335,7 @@ Categories.buildForSelectCategories = function (categories, callback) {
|
|||||||
|
|
||||||
var categoriesData = [];
|
var categoriesData = [];
|
||||||
|
|
||||||
categories = categories.filter(function (category) {
|
categories = categories.filter(category => category && !category.parentCid);
|
||||||
return category && !parseInt(category.parentCid, 10);
|
|
||||||
});
|
|
||||||
|
|
||||||
categories.forEach(function (category) {
|
categories.forEach(function (category) {
|
||||||
recursive(category, categoriesData, '', 0);
|
recursive(category, categoriesData, '', 0);
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ categoryController.get = function (req, res, callback) {
|
|||||||
|
|
||||||
settings = results.userSettings;
|
settings = results.userSettings;
|
||||||
|
|
||||||
var topicCount = parseInt(results.categoryData.topic_count, 10);
|
var topicCount = results.categoryData.topic_count;
|
||||||
pageCount = Math.max(1, Math.ceil(topicCount / settings.topicsPerPage));
|
pageCount = Math.max(1, Math.ceil(topicCount / settings.topicsPerPage));
|
||||||
|
|
||||||
if (topicIndex < 0 || topicIndex > Math.max(topicCount - 1, 0)) {
|
if (topicIndex < 0 || topicIndex > Math.max(topicCount - 1, 0)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user