mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
feat: closes #9380, add category filtering and topic tools to tag page
This commit is contained in:
@@ -17,6 +17,7 @@ const tagsController = module.exports;
|
||||
tagsController.getTag = async function (req, res) {
|
||||
const tag = validator.escape(utils.cleanUpTag(req.params.tag, meta.config.maximumTagLength));
|
||||
const page = parseInt(req.query.page, 10) || 1;
|
||||
const cid = Array.isArray(req.query.cid) || !req.query.cid ? req.query.cid : [req.query.cid];
|
||||
|
||||
const templateData = {
|
||||
topics: [],
|
||||
@@ -24,9 +25,11 @@ tagsController.getTag = async function (req, res) {
|
||||
breadcrumbs: helpers.buildBreadcrumbs([{ text: '[[tags:tags]]', url: '/tags' }, { text: tag }]),
|
||||
title: `[[pages:tag, ${tag}]]`,
|
||||
};
|
||||
const [settings, cids] = await Promise.all([
|
||||
const [settings, cids, categoryData, isPrivileged] = await Promise.all([
|
||||
user.getSettings(req.uid),
|
||||
categories.getCidsByPrivilege('categories:cid', req.uid, 'topics:read'),
|
||||
cid || categories.getCidsByPrivilege('categories:cid', req.uid, 'topics:read'),
|
||||
helpers.getSelectedCategory(cid),
|
||||
user.isPrivileged(req.uid),
|
||||
]);
|
||||
const start = Math.max(0, (page - 1) * settings.topicsPerPage);
|
||||
const stop = start + settings.topicsPerPage - 1;
|
||||
@@ -37,6 +40,11 @@ tagsController.getTag = async function (req, res) {
|
||||
]);
|
||||
|
||||
templateData.topics = await topics.getTopics(tids, req.uid);
|
||||
templateData.showSelect = isPrivileged;
|
||||
templateData.showTopicTools = isPrivileged;
|
||||
templateData.allCategoriesUrl = `tags/${tag}${helpers.buildQueryString(req.query, 'cid', '')}`;
|
||||
templateData.selectedCategory = categoryData.selectedCategory;
|
||||
templateData.selectedCids = categoryData.selectedCids;
|
||||
topics.calculateTopicIndices(templateData.topics, start);
|
||||
res.locals.metaTags = [
|
||||
{
|
||||
@@ -50,7 +58,7 @@ tagsController.getTag = async function (req, res) {
|
||||
];
|
||||
|
||||
const pageCount = Math.max(1, Math.ceil(topicCount / settings.topicsPerPage));
|
||||
templateData.pagination = pagination.create(page, pageCount);
|
||||
templateData.pagination = pagination.create(page, pageCount, req.query);
|
||||
helpers.addLinkTags({ url: `tags/${tag}`, res: req.res, tags: templateData.pagination.rel });
|
||||
|
||||
templateData['feeds:disableRSS'] = meta.config['feeds:disableRSS'];
|
||||
|
||||
Reference in New Issue
Block a user