mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-05-06 10:06:31 +02:00
refactor: crossposts.get to return limited category data (name, icon, etc.), fixed up crosspost modal to hide uncategorized and all categories options
This commit is contained in:
@@ -150,6 +150,7 @@
|
|||||||
|
|
||||||
"load-categories": "Loading Categories",
|
"load-categories": "Loading Categories",
|
||||||
"confirm-move": "Move",
|
"confirm-move": "Move",
|
||||||
|
"confirm-crosspost": "Cross-post",
|
||||||
"confirm-fork": "Fork",
|
"confirm-fork": "Fork",
|
||||||
|
|
||||||
"bookmark": "Bookmark",
|
"bookmark": "Bookmark",
|
||||||
@@ -162,6 +163,7 @@
|
|||||||
"loading-more-posts": "Loading More Posts",
|
"loading-more-posts": "Loading More Posts",
|
||||||
"move-topic": "Move Topic",
|
"move-topic": "Move Topic",
|
||||||
"move-topics": "Move Topics",
|
"move-topics": "Move Topics",
|
||||||
|
"crosspost-topic": "Cross-post Topic",
|
||||||
"move-post": "Move Post",
|
"move-post": "Move Post",
|
||||||
"post-moved": "Post moved!",
|
"post-moved": "Post moved!",
|
||||||
"fork-topic": "Fork Topic",
|
"fork-topic": "Fork Topic",
|
||||||
@@ -182,6 +184,7 @@
|
|||||||
"topic-id": "Topic ID",
|
"topic-id": "Topic ID",
|
||||||
"move-posts-instruction": "Click the posts you want to move then enter a topic ID or go to the target topic",
|
"move-posts-instruction": "Click the posts you want to move then enter a topic ID or go to the target topic",
|
||||||
"move-topic-instruction": "Select the target category and then click move",
|
"move-topic-instruction": "Select the target category and then click move",
|
||||||
|
"crosspost-topic-instruction": "Select one or more categories to cross-post to. Topic(s) will be accessible from the original category and all cross-posted categories.",
|
||||||
"change-owner-instruction": "Click the posts you want to assign to another user",
|
"change-owner-instruction": "Click the posts you want to assign to another user",
|
||||||
"manage-editors-instruction": "Manage the users who can edit this post below.",
|
"manage-editors-instruction": "Manage the users who can edit this post below.",
|
||||||
|
|
||||||
|
|||||||
@@ -117,7 +117,9 @@ define('forum/topic/threadTools', [
|
|||||||
});
|
});
|
||||||
|
|
||||||
topicContainer.on('click', '[component="topic/crosspost"]', () => {
|
topicContainer.on('click', '[component="topic/crosspost"]', () => {
|
||||||
console.log('tbd');
|
require(['forum/topic/crosspost'], (crosspost) => {
|
||||||
|
crosspost.init(tid, ajaxify.data.cid);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
topicContainer.on('click', '[component="topic/delete/posts"]', function () {
|
topicContainer.on('click', '[component="topic/delete/posts"]', function () {
|
||||||
|
|||||||
@@ -77,6 +77,7 @@ define('categorySearch', ['alerts', 'bootstrap', 'api'], function (alerts, boots
|
|||||||
states: options.states,
|
states: options.states,
|
||||||
showLinks: options.showLinks,
|
showLinks: options.showLinks,
|
||||||
localOnly: options.localOnly,
|
localOnly: options.localOnly,
|
||||||
|
hideUncategorized: options.hideUncategorized,
|
||||||
}, function (err, { categories }) {
|
}, function (err, { categories }) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return alerts.error(err);
|
return alerts.error(err);
|
||||||
@@ -94,6 +95,7 @@ define('categorySearch', ['alerts', 'bootstrap', 'api'], function (alerts, boots
|
|||||||
categoryItems: categories.slice(0, 200),
|
categoryItems: categories.slice(0, 200),
|
||||||
selectedCategory: ajaxify.data.selectedCategory,
|
selectedCategory: ajaxify.data.selectedCategory,
|
||||||
allCategoriesUrl: ajaxify.data.allCategoriesUrl,
|
allCategoriesUrl: ajaxify.data.allCategoriesUrl,
|
||||||
|
hideAll: options.hideAll,
|
||||||
}, function (html) {
|
}, function (html) {
|
||||||
el.find('[component="category/list"]')
|
el.find('[component="category/list"]')
|
||||||
.html(html.find('[component="category/list"]').html());
|
.html(html.find('[component="category/list"]').html());
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ const messaging = require('../messaging');
|
|||||||
const privileges = require('../privileges');
|
const privileges = require('../privileges');
|
||||||
const meta = require('../meta');
|
const meta = require('../meta');
|
||||||
const plugins = require('../plugins');
|
const plugins = require('../plugins');
|
||||||
|
const utils = require('../utils');
|
||||||
|
|
||||||
const controllersHelpers = require('../controllers/helpers');
|
const controllersHelpers = require('../controllers/helpers');
|
||||||
|
|
||||||
@@ -29,9 +30,12 @@ searchApi.categories = async (caller, data) => {
|
|||||||
({ cids, matchedCids } = await findMatchedCids(caller.uid, data));
|
({ cids, matchedCids } = await findMatchedCids(caller.uid, data));
|
||||||
} else {
|
} else {
|
||||||
cids = await loadCids(caller.uid, data.parentCid);
|
cids = await loadCids(caller.uid, data.parentCid);
|
||||||
if (meta.config.activitypubEnabled) {
|
if (!data.hideUncategorized && meta.config.activitypubEnabled) {
|
||||||
cids.unshift(-1);
|
cids.unshift(-1);
|
||||||
}
|
}
|
||||||
|
if (data.localOnly) {
|
||||||
|
cids = cids.filter(cid => utils.isNumber(cid));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const visibleCategories = await controllersHelpers.getVisibleCategories({
|
const visibleCategories = await controllersHelpers.getVisibleCategories({
|
||||||
|
|||||||
@@ -123,8 +123,9 @@ topicsController.get = async function getTopic(req, res, next) {
|
|||||||
p => parseInt(p.index, 10) === parseInt(Math.max(0, postIndex - 1), 10)
|
p => parseInt(p.index, 10) === parseInt(Math.max(0, postIndex - 1), 10)
|
||||||
);
|
);
|
||||||
|
|
||||||
const [author] = await Promise.all([
|
const [author, crossposts] = await Promise.all([
|
||||||
user.getUserFields(topicData.uid, ['username', 'userslug']),
|
user.getUserFields(topicData.uid, ['username', 'userslug']),
|
||||||
|
topics.crossposts.get(topicData.tid),
|
||||||
buildBreadcrumbs(topicData),
|
buildBreadcrumbs(topicData),
|
||||||
addOldCategory(topicData, userPrivileges),
|
addOldCategory(topicData, userPrivileges),
|
||||||
addTags(topicData, req, res, currentPage, postAtIndex),
|
addTags(topicData, req, res, currentPage, postAtIndex),
|
||||||
@@ -134,6 +135,7 @@ topicsController.get = async function getTopic(req, res, next) {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
topicData.author = author;
|
topicData.author = author;
|
||||||
|
topicData.crossposts = crossposts;
|
||||||
topicData.pagination = pagination.create(currentPage, pageCount, req.query);
|
topicData.pagination = pagination.create(currentPage, pageCount, req.query);
|
||||||
topicData.pagination.rel.forEach((rel) => {
|
topicData.pagination.rel.forEach((rel) => {
|
||||||
rel.href = `${url}/topic/${topicData.slug}${rel.href}`;
|
rel.href = `${url}/topic/${topicData.slug}${rel.href}`;
|
||||||
|
|||||||
@@ -12,8 +12,20 @@ const Crossposts = module.exports;
|
|||||||
Crossposts.get = async function (tid) {
|
Crossposts.get = async function (tid) {
|
||||||
const crosspostIds = await db.getSortedSetMembers(`tid:${tid}:crossposts`);
|
const crosspostIds = await db.getSortedSetMembers(`tid:${tid}:crossposts`);
|
||||||
let crossposts = await db.getObjects(crosspostIds.map(id => `crosspost:${id}`));
|
let crossposts = await db.getObjects(crosspostIds.map(id => `crosspost:${id}`));
|
||||||
|
const cids = crossposts.reduce((cids, crossposts) => {
|
||||||
|
cids.add(crossposts.cid);
|
||||||
|
return cids;
|
||||||
|
}, new Set());
|
||||||
|
let categoriesData = await categories.getCategoriesFields(
|
||||||
|
cids, ['cid', 'name', 'icon', 'bgColor', 'color', 'slug']
|
||||||
|
);
|
||||||
|
categoriesData = categoriesData.reduce((map, category) => {
|
||||||
|
map.set(parseInt(category.cid, 10), category);
|
||||||
|
return map;
|
||||||
|
}, new Map());
|
||||||
crossposts = crossposts.map((crosspost, idx) => {
|
crossposts = crossposts.map((crosspost, idx) => {
|
||||||
crosspost.id = crosspostIds[idx];
|
crosspost.id = crosspostIds[idx];
|
||||||
|
crosspost.category = categoriesData.get(parseInt(crosspost.cid, 10));
|
||||||
return crosspost;
|
return crosspost;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
15
src/views/modals/crosspost-topic.tpl
Normal file
15
src/views/modals/crosspost-topic.tpl
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<div class="card tool-modal shadow">
|
||||||
|
<h5 class="card-header">
|
||||||
|
[[topic:crosspost-topic]]
|
||||||
|
</h5>
|
||||||
|
<div class="card-body">
|
||||||
|
<p>
|
||||||
|
[[topic:crosspost-topic-instruction]]
|
||||||
|
</p>
|
||||||
|
<!-- IMPORT partials/category/filter-dropdown-right.tpl -->
|
||||||
|
</div>
|
||||||
|
<div class="card-footer text-end">
|
||||||
|
<button type="button" class="btn btn-sm btn-outline-secondary" id="crosspost_topic_cancel">[[global:buttons.close]]</button>
|
||||||
|
<button type="button" class="btn btn-sm btn-primary" id="crosspost_thread_commit" disabled>[[topic:confirm-crosspost]]</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -16,12 +16,14 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ul component="category/list" class="list-unstyled mb-0 text-sm category-dropdown-menu ghost-scrollbar" role="menu">
|
<ul component="category/list" class="list-unstyled mb-0 text-sm category-dropdown-menu ghost-scrollbar" role="menu">
|
||||||
|
{{{ if !hideAll }}}
|
||||||
<li role="presentation" class="category" data-cid="all">
|
<li role="presentation" class="category" data-cid="all">
|
||||||
<a class="dropdown-item rounded-1 d-flex align-items-center gap-2" role="menuitem" href="{{{ if allCategoriesUrl }}}{config.relative_path}/{allCategoriesUrl}{{{ else }}}#{{{ end }}}">
|
<a class="dropdown-item rounded-1 d-flex align-items-center gap-2" role="menuitem" href="{{{ if allCategoriesUrl }}}{config.relative_path}/{allCategoriesUrl}{{{ else }}}#{{{ end }}}">
|
||||||
<div class="flex-grow-1">[[unread:all-categories]]</div>
|
<div class="flex-grow-1">[[unread:all-categories]]</div>
|
||||||
<i component="category/select/icon" class="flex-shrink-0 fa fa-fw fa-check {{{if selectedCategory}}}invisible{{{end}}}"></i>
|
<i component="category/select/icon" class="flex-shrink-0 fa fa-fw fa-check {{{if selectedCategory}}}invisible{{{end}}}"></i>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
{{{ end }}}
|
||||||
{{{each categoryItems}}}
|
{{{each categoryItems}}}
|
||||||
<li role="presentation" class="category {{{ if ./disabledClass }}}disabled{{{ end }}}" data-cid="{./cid}" data-parent-cid="{./parentCid}" data-name="{./name}">
|
<li role="presentation" class="category {{{ if ./disabledClass }}}disabled{{{ end }}}" data-cid="{./cid}" data-parent-cid="{./parentCid}" data-name="{./name}">
|
||||||
<a class="dropdown-item rounded-1 d-flex align-items-center gap-2 {{{ if ./disabledClass }}}disabled{{{ end }}}" role="menuitem" href="#">
|
<a class="dropdown-item rounded-1 d-flex align-items-center gap-2 {{{ if ./disabledClass }}}disabled{{{ end }}}" role="menuitem" href="#">
|
||||||
|
|||||||
Reference in New Issue
Block a user