mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 02:55:58 +01:00 
			
		
		
		
	use buildForSelect
This commit is contained in:
		| @@ -24,39 +24,20 @@ categoriesController.get = function (req, res, callback) { | |||||||
| 				ignored: function (next) { | 				ignored: function (next) { | ||||||
| 					user.getIgnoredCategories(userData.uid, next); | 					user.getIgnoredCategories(userData.uid, next); | ||||||
| 				}, | 				}, | ||||||
| 				all: function (next) { | 				categories: function (next) { | ||||||
| 					categories.getCategoriesByPrivilege('cid:0:children', userData.uid, 'find', next); | 					categories.buildForSelect(userData.uid, 'find', next); | ||||||
| 				}, | 				} | ||||||
| 			}, next); | 			}, next); | ||||||
| 		}, | 		}, | ||||||
| 		function (results) { | 		function (results) { | ||||||
| 			flattenArray(results); | 			results.categories.forEach(function (category) { | ||||||
| 			userData.categories = results.all; | 				if (category) { | ||||||
|  | 					category.isIgnored = results.ignored.includes(String(category.cid)); | ||||||
|  | 				} | ||||||
|  | 			}); | ||||||
|  | 			userData.categories = results.categories; | ||||||
| 			userData.title = '[[pages:account/watched_categories, ' + userData.username + ']]'; | 			userData.title = '[[pages:account/watched_categories, ' + userData.username + ']]'; | ||||||
| 			res.render('account/categories', userData); | 			res.render('account/categories', userData); | ||||||
| 		}, | 		}, | ||||||
| 	], callback); | 	], callback); | ||||||
| }; | }; | ||||||
|  |  | ||||||
| function moveChildrenToRoot(child) { |  | ||||||
| 	this.results.all.splice(this.i + this.results.j, 0, child); |  | ||||||
| 	this.results.j = this.results.j + 1; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| function flattenArray(results) { |  | ||||||
| 	for (var i = 0; i < results.all.length; i++) { |  | ||||||
| 		var category = results.all[i]; |  | ||||||
|  |  | ||||||
| 		category.isIgnored = false; |  | ||||||
| 		if (results.ignored.includes(String(category.cid))) { |  | ||||||
| 			category.isIgnored = true; |  | ||||||
| 		} |  | ||||||
|  |  | ||||||
| 		if (!!category.children && !!category.children.length) { |  | ||||||
| 			results.j = 1; |  | ||||||
| 			category.children.forEach(moveChildrenToRoot, { i: i, results: results }); |  | ||||||
| 			category.children = []; |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user