feat: closes #9380, add category filtering and topic tools to tag page

v1.18.x
Barış Soner Uşaklı 4 years ago
parent 34b9aaedee
commit 668508cc37

@ -17,6 +17,7 @@ const tagsController = module.exports;
tagsController.getTag = async function (req, res) { tagsController.getTag = async function (req, res) {
const tag = validator.escape(utils.cleanUpTag(req.params.tag, meta.config.maximumTagLength)); const tag = validator.escape(utils.cleanUpTag(req.params.tag, meta.config.maximumTagLength));
const page = parseInt(req.query.page, 10) || 1; 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 = { const templateData = {
topics: [], topics: [],
@ -24,9 +25,11 @@ tagsController.getTag = async function (req, res) {
breadcrumbs: helpers.buildBreadcrumbs([{ text: '[[tags:tags]]', url: '/tags' }, { text: tag }]), breadcrumbs: helpers.buildBreadcrumbs([{ text: '[[tags:tags]]', url: '/tags' }, { text: tag }]),
title: `[[pages:tag, ${tag}]]`, title: `[[pages:tag, ${tag}]]`,
}; };
const [settings, cids] = await Promise.all([ const [settings, cids, categoryData, isPrivileged] = await Promise.all([
user.getSettings(req.uid), 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 start = Math.max(0, (page - 1) * settings.topicsPerPage);
const stop = start + settings.topicsPerPage - 1; 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.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); topics.calculateTopicIndices(templateData.topics, start);
res.locals.metaTags = [ res.locals.metaTags = [
{ {
@ -50,7 +58,7 @@ tagsController.getTag = async function (req, res) {
]; ];
const pageCount = Math.max(1, Math.ceil(topicCount / settings.topicsPerPage)); 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 }); helpers.addLinkTags({ url: `tags/${tag}`, res: req.res, tags: templateData.pagination.rel });
templateData['feeds:disableRSS'] = meta.config['feeds:disableRSS']; templateData['feeds:disableRSS'] = meta.config['feeds:disableRSS'];

Loading…
Cancel
Save