mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-06 05:55:48 +01:00
nested categories on search
This commit is contained in:
@@ -80,9 +80,11 @@ define('forum/search', ['search', 'autocomplete'], function(searchModule, autoco
|
||||
$('#posted-by-user').val(params.by);
|
||||
}
|
||||
|
||||
loadCategories(function() {
|
||||
if (params.categories) {
|
||||
$('#posted-in-categories').val(params.categories);
|
||||
}
|
||||
});
|
||||
|
||||
if (params.searchChildren) {
|
||||
$('#search-children').prop('checked', true);
|
||||
@@ -112,6 +114,38 @@ define('forum/search', ['search', 'autocomplete'], function(searchModule, autoco
|
||||
}
|
||||
}
|
||||
|
||||
function loadCategories(callback) {
|
||||
var listEl = $('#posted-in-categories');
|
||||
|
||||
socket.emit('categories.getCategoriesByPrivilege', 'read', function(err, categories) {
|
||||
if (err) {
|
||||
return app.alertError(err.message);
|
||||
}
|
||||
|
||||
categories = categories.filter(function(category) {
|
||||
return !category.link && !parseInt(category.parentCid, 10);
|
||||
});
|
||||
|
||||
categories.forEach(function(category) {
|
||||
recursive(category, listEl, '');
|
||||
});
|
||||
listEl.attr('size', listEl.find('option').length);
|
||||
callback();
|
||||
});
|
||||
}
|
||||
|
||||
function recursive(category, listEl, level) {
|
||||
if (category.link) {
|
||||
return;
|
||||
}
|
||||
var bullet = level ? '• ' : '';
|
||||
$('<option value="' + category.cid + '">' + level + bullet + category.name + '</option>').appendTo(listEl);
|
||||
|
||||
category.children.forEach(function(child) {
|
||||
recursive(child, listEl, ' ' + level);
|
||||
});
|
||||
}
|
||||
|
||||
function highlightMatches(searchQuery) {
|
||||
if (!searchQuery) {
|
||||
return;
|
||||
|
||||
@@ -15,17 +15,6 @@ searchController.search = function(req, res, next) {
|
||||
return next();
|
||||
}
|
||||
|
||||
var breadcrumbs = helpers.buildBreadcrumbs([{text: '[[global:search]]'}]);
|
||||
|
||||
categories.getCategoriesByPrivilege('categories:cid', req.uid, 'read', function(err, categories) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
categories = categories.filter(function(category) {
|
||||
return category && !category.link;
|
||||
});
|
||||
|
||||
req.params.term = validator.escape(req.params.term);
|
||||
var page = Math.max(1, parseInt(req.query.page, 10)) || 1;
|
||||
if (req.query.categories && !Array.isArray(req.query.categories)) {
|
||||
@@ -56,8 +45,7 @@ searchController.search = function(req, res, next) {
|
||||
results.pagination = pagination.create(page, results.pageCount, req.query);
|
||||
results.showAsPosts = !req.query.showAs || req.query.showAs === 'posts';
|
||||
results.showAsTopics = req.query.showAs === 'topics';
|
||||
results.breadcrumbs = breadcrumbs;
|
||||
results.categories = categories;
|
||||
results.breadcrumbs = helpers.buildBreadcrumbs([{text: '[[global:search]]'}]);
|
||||
results.expandSearch = !req.params.term;
|
||||
|
||||
plugins.fireHook('filter:search.build', {data: data, results: results}, function(err, data) {
|
||||
@@ -67,8 +55,6 @@ searchController.search = function(req, res, next) {
|
||||
res.render('search', data.results);
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
module.exports = searchController;
|
||||
|
||||
Reference in New Issue
Block a user