Skip to content

Node.js based forum software built for the modern web

feat: closes #14251

Barış Soner Uşaklı6f3d6884e8f7
diff --git a/public/language/en-GB/post-queue.json b/public/language/en-GB/post-queue.json
index 24b33da2e6..13fce2e9ac 100644
--- a/public/language/en-GB/post-queue.json
+++ b/public/language/en-GB/post-queue.json
@@ -10,6 +10,7 @@
"user": "User",
"when": "When",
"category": "Category",
+ "tags": "Tags",
"title": "Title",
"content": "Content",
"posted": "Posted",
@@ -39,5 +40,6 @@
"remove-selected-confirm": "Do you want to remove %1 selected posts?",
"bulk-accept-success": "%1 posts accepted",
"bulk-reject-success": "%1 posts rejected",
- "links-in-this-post": "Links in this post"
+ "links-in-this-post": "Links in this post",
+ "thumbs-in-this-post": "Thumbnails in this post"
}
\ No newline at end of file
diff --git a/public/src/client/post-queue.js b/public/src/client/post-queue.js
index 1a637b6e1b..86b5bed119 100644
--- a/public/src/client/post-queue.js
+++ b/public/src/client/post-queue.js
@@ -2,11 +2,12 @@
define('forum/post-queue', [
- 'categoryFilter', 'categorySelector', 'api', 'alerts', 'translator',
- 'bootbox', 'accounts/moderate', 'accounts/delete',
+ 'categoryFilter', 'categorySelector', 'api', 'alerts',
+ 'translator', 'bootbox', 'accounts/moderate', 'accounts/delete',
+ 'autocomplete', 'uploader',
], function (
categoryFilter, categorySelector, api, alerts, translator,
- bootbox, AccountModerate, AccountsDelete
+ bootbox, AccountModerate, AccountsDelete, autocomplete, uploader
) {
const PostQueue = {};
@@ -17,21 +18,102 @@ define('forum/post-queue', [
privilege: 'moderate',
});
+ createTagsInput();
+
handleActions();
handleBulkActions();
handleContentEdit('[data-action="editContent"]', '.post-content-editable', 'textarea', '.post-content');
handleContentEdit('[data-action="editTitle"]', '.topic-title-editable', 'input', '.topic-title');
- $('.posts-list').on('click', '.topic-category[data-editable]', function (e) {
- handleCategoryChange(this);
- e.stopPropagation();
- e.preventDefault();
- });
-
$('[component="post/content"] img:not(.not-responsive)').addClass('img-fluid');
showLinksInPosts();
};
+ function replaceRelativeUploadPath(url) {
+ return url
+ .replace(new RegExp(`^${config.relative_path}`), '')
+ .replace(new RegExp(`^${config.upload_url}`), '');
+ }
+
+ function getThumbUrls(thumbList) {
+ return thumbList.find('img').map((i, img) => $(img).attr('src')).get();
+ }
+
+ function handleThumbUpload(postEl) {
+ const id = postEl.getAttribute('data-id');
+ const $postEl = $(postEl);
+ const thumbList = $postEl.find('.thumb-list');
+
+ uploader.show({
+ title: '[[topic:composer.thumb-title]]',
+ method: 'put',
+ route: config.relative_path + `/api/topic/thumb/upload`,
+ }, function (url) {
+ const currentThumbs = getThumbUrls(thumbList);
+ currentThumbs.push(url);
+ saveAndUpdateThumbs(id, currentThumbs, thumbList);
+ });
+ }
+
+ function removeThumb(removeBtn) {
+ const postEl = removeBtn.closest('[data-id]');
+ const id = postEl.attr('data-id');
+ removeBtn.parent().remove();
+ const thumbList = postEl.find('.thumb-list');
+ const currentThumbs = getThumbUrls(thumbList);
+ saveAndUpdateThumbs(id, currentThumbs, thumbList);
+ }
+
+ function saveAndUpdateThumbs(id, currentThumbs, thumbList) {
+ api.put(`/posts/queue/${id}`, {
+ // remove relative path and upload url from the thumbs before saving
+ thumbs: currentThumbs.map(replaceRelativeUploadPath),
+ }).then(function () {
+ app.parseAndTranslate('post-queue', 'posts', {
+ posts: [{
+ type: 'topic',
+ data: {
+ thumbs: currentThumbs,
+ },
+ }],
+ }, function (html) {
+ thumbList.html(html.find('.thumb-list').html());
+ });
+ }).catch(alerts.error);
+ }
+
+ function createTagsInput() {
+ ajaxify.data.posts.forEach(function (postData) {
+ const postEl = $(`[data-id="${postData.id}"]`);
+ const tagContainer = postEl.find('.topic-tags-editable');
+ const tagEl = tagContainer.find('input');
+
+ tagEl.tagsinput({
+ tagClass: 'badge rounded-1 fw-normal',
+ confirmKeys: [13, 44],
+ trimValue: true,
+ });
+ const tagsinput = tagContainer.find('.bootstrap-tagsinput');
+ tagsinput.addClass('tag-list');
+ const inputEls = tagsinput.find('input');
+
+ inputEls.each((index, input) => {
+ const $input = $(input);
+ autocomplete.tag($input, function () {
+ const e = jQuery.Event('keypress');
+ e.which = 13;
+ setTimeout(() => input.trigger(e), 100);
+ });
+ });
+ const tags = postData.data.tags || [];
+ if (tags && tags.length) {
+ tags.forEach(function (tag) {
+ tagEl.tagsinput('add', tag);
+ });
+ }
+ });
+ }
+
function showLinksInPosts() {
$('.posts-list [data-id]').each((idx, el) => {
const $el = $(el);
@@ -115,6 +197,50 @@ define('forum/post-queue', [
return false;
}
+ function handleTagChange(postEl) {
+ const id = postEl.getAttribute('data-id');
+ const tagList = postEl.querySelector('.tag-list');
+ const tagEl = postEl.querySelector('.topic-tags-editable');
+
+ tagList.classList.add('hidden');
+ tagEl.classList.remove('hidden');
+
+ const input = tagEl.querySelector('.bootstrap-tagsinput input');
+ if (!input) return;
+
+ input.focus();
+ function focusOut() {
+ setTimeout(() => {
+ if (tagEl.contains(document.activeElement)) {
+ // focus is still inside the tag edit area, do not save yet
+ return;
+ }
+
+ const modifiedTags = $(tagEl).find('.tags').tagsinput('items');
+ api.put(`/posts/queue/${id}`, {
+ tags: modifiedTags,
+ }).then(function () {
+ app.parseAndTranslate('post-queue', 'posts', {
+ posts: [{
+ type: 'topic',
+ data: {
+ tags: modifiedTags,
+ },
+ }],
+ }, function (html) {
+ tagList.innerHTML = html.find('.tag-list').html();
+ tagList.classList.remove('hidden');
+ tagEl.classList.add('hidden');
+ });
+ }).catch(alerts.error)
+ .finally(() => {
+ document.removeEventListener('focusout', focusOut);
+ });
+ }, 100);
+ }
+ document.addEventListener('focusout', focusOut);
+ }
+
function handleActions() {
const listEl = document.querySelector('.posts-list');
if (listEl) {
@@ -130,6 +256,23 @@ define('forum/post-queue', [
break;
}
+ case 'editTags': {
+ const postEl = e.target.closest('[data-id]');
+ handleTagChange(postEl);
+ break;
+ }
+
+ case 'uploadThumb': {
+ const postEl = e.target.closest('[data-id]');
+ handleThumbUpload(postEl);
+ break;
+ }
+
+ case 'removeThumb': {
+ removeThumb($(subselector));
+ break;
+ }
+
case 'ban':
AccountModerate.banAccount(uid, ajaxify.refresh);
break;
diff --git a/src/api/posts.js b/src/api/posts.js
index 683372f6f3..1b323ebbf4 100644
--- a/src/api/posts.js
+++ b/src/api/posts.js
@@ -608,7 +608,7 @@ postsAPI.removeQueuedPost = async (caller, data) => {
};
postsAPI.editQueuedPost = async (caller, data) => {
- if (!data || !data.id || (!data.content && !data.title && !data.cid)) {
+ if (!data || !data.id || (!data.content && !data.title && !data.cid && !data.tags && !data.thumbs)) {
throw new Error('[[error:invalid-data]]');
}
await posts.editQueuedContent(caller.uid, data);
diff --git a/src/posts/queue.js b/src/posts/queue.js
index fe98c3494c..32816e9563 100644
--- a/src/posts/queue.js
+++ b/src/posts/queue.js
@@ -17,6 +17,8 @@ const utils = require('../utils');
const cache = require('../cache');
const socketHelpers = require('../socket.io/helpers');
+const upload_url = nconf.get('relative_path') + nconf.get('upload_url');
+
module.exports = function (Posts) {
Posts.getQueuedPosts = async (filter = {}, options = {}) => {
options = { metadata: true, ...options }; // defaults
@@ -81,6 +83,12 @@ module.exports = function (Posts) {
} else if (postData.data.tid) {
postData.topic = await topics.getTopicFields(postData.data.tid, ['title', 'cid', 'lastposttime']);
}
+ if (Array.isArray(postData.data.thumbs)) {
+ postData.data.thumbs = postData.data.thumbs.map(
+ thumb => thumb.startsWith('http') ? thumb : upload_url + thumb
+ );
+ }
+
postData.category = await categories.getCategoryData(postData.topic.cid);
const result = await plugins.hooks.fire('filter:parse.post', { postData: postData.data });
postData.data.content = result.postData.content;
@@ -377,6 +385,12 @@ module.exports = function (Posts) {
if (editData.cid !== undefined) {
data.data.cid = editData.cid;
}
+ if (editData.tags !== undefined) {
+ data.data.tags = editData.tags;
+ }
+ if (editData.thumbs !== undefined) {
+ data.data.thumbs = editData.thumbs;
+ }
await db.setObjectField(`post:queue:${editData.id}`, 'data', JSON.stringify(data.data));
cache.del('post-queue');
};
diff --git a/src/views/post-queue.tpl b/src/views/post-queue.tpl
index 569bfb68e3..12c3b56df3 100644
--- a/src/views/post-queue.tpl
+++ b/src/views/post-queue.tpl
@@ -80,6 +80,10 @@
<div class="ms-auto dropdown bottom-sheet">
<button href="#" class="btn btn-ghost btn-sm ff-secondary border text-xs dropdown-toggle" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">[[global:actions]]</button>
<ul class="dropdown-menu p-1 text-sm" role="menu">
+ {{{ if ./canAccept }}}
+ <li><a class="dropdown-item rounded-1" data-action="notify"> [[post-queue:notify]]</a></li>
+ <li class="dropdown-divider"></li>
+ {{{ end }}}
{{{ if privileges.view:users:info }}}
<li><a class="dropdown-item rounded-1" href="{config.relative_path}/user/{./user.userslug}/info" role="menuitem">[[user:account-info]]</a></li>
{{{ end }}}
@@ -127,8 +131,13 @@
<span class="small timeago" title={posts.data.timestampISO}></span>
</li>
<li class="card-body border-bottom">
- <div class="text-xs fw-semibold mb-1">
+ <div class="d-flex align-items-center justify-content-between mb-1">
+ <span class="text-xs fw-semibold">
{{{ if posts.data.tid }}}[[post-queue:topic]]{{{ else }}}[[post-queue:title]]{{{ end }}}
+ </span>
+ {{{ if !posts.data.tid }}}
+ <button data-action="editTitle" class="btn btn-ghost btn-sm ff-secondary border text-xs">Edit</button>
+ {{{ end }}}
</div>
<span class="small topic-title text-break">
{{{ if posts.data.tid }}}
@@ -144,23 +153,51 @@
</span>
{{{if !posts.data.tid}}}
<div class="topic-title-editable hidden">
- <input class="form-control" type="text" value="{posts.data.title}"/>
+ <input class="form-control form-control-sm" type="text" value="{posts.data.title}"/>
</div>
{{{end}}}
</li>
+
<li class="card-body border-bottom">
- <div class="text-xs fw-semibold mb-1">
- [[post-queue:category]]
+ <div class="d-flex align-items-center justify-content-between mb-1">
+ <div class="text-xs fw-semibold">
+ [[post-queue:category]]
+ </div>
+ {{{ if posts.data.cid }}}
+ <button data-action="editCategory" class="btn btn-ghost btn-sm ff-secondary border text-xs">Edit</button>
+ {{{ end }}}
</div>
- <div class="topic-category small">
+
+ <div class="topic-category">
<a href="{config.relative_path}/category/{posts.category.slug}">
<div class="category-item d-inline-block">
{buildCategoryIcon(./category, "24px", "rounded-circle")}
- {posts.category.name}
+ <span class="text-sm">{posts.category.name}</span>
</div>
</a>
</div>
</li>
+
+ {{{ if (posts.type == "topic") }}}
+ <li class="card-body border-bottom">
+ <div class="d-flex align-items-center justify-content-between mb-1">
+ <div class="text-xs fw-semibold">
+ [[post-queue:tags]]
+ </div>
+
+ <button data-action="editTags" class="btn btn-ghost btn-sm ff-secondary border text-xs">Edit</button>
+ </div>
+ <div class="tag-list">
+ {{{ each posts.data.tags }}}
+ <a href="{config.relative_path}/tags/{encodeURIComponent(@value)}"><span class="badge border border-gray-300 fw-normal tag">{escape(@value)}</span></a>
+ {{{ end }}}
+ </div>
+ <div class="topic-tags-editable hidden">
+ <input class="form-control form-control-sm tags" type="text" value=""/>
+ </div>
+ </li>
+ {{{ end }}}
+
<li class="card-body">
<div class="row row-cols-2 g-1">
{{{ if ./canAccept }}}
@@ -170,26 +207,6 @@
<div class="col d-grid">
<button class="btn btn-danger btn-sm" data-action="reject"><i class="fa fa-fw fa-times"></i> [[post-queue:reject]]</button>
</div>
- {{{ end }}}
- {{{ if ./canEdit}}}
- {{{ if !posts.data.tid }}}
- <div class="col d-grid">
- <button class="btn btn-light btn-sm" data-action="editTitle"><i class="fa fa-fw fa-edit"></i> [[post-queue:title]]</button>
- </div>
- {{{ end }}}
- <div class="col d-grid">
- <button class="btn btn-light btn-sm" data-action="editContent"><i class="fa fa-fw fa-edit"></i> [[post-queue:content]]</button>
- </div>
- {{{if posts.data.cid}}}
- <div class="col d-grid">
- <button class="btn btn-light btn-sm" data-action="editCategory"><i class="fa fa-fw fa-edit"></i> [[post-queue:category]]</button>
- </div>
- {{{ end }}}
- {{{ end }}}
- {{{ if ./canAccept }}}
- <div class="col d-grid">
- <button class="btn btn-light btn-sm" data-action="notify"><i class="fa fa-fw fa-bell-o"></i> [[post-queue:notify]]</button>
- </div>
{{{ else }}}
<div class="col d-grid">
<button class="btn btn-danger btn-sm" data-action="reject"><i class="fa fa-fw fa-times"></i> [[post-queue:remove]]</button>
@@ -200,7 +217,15 @@
</ul>
</div>
<div class="col-lg-9 d-flex flex-column">
- <div class="post-content mb-auto text-break p-3 pb-0 h-100">{posts.data.content}</div>
+ <div class="d-flex align-items-center justify-content-between mb-1 px-3 pt-3 pb-1">
+ <div class="text-xs fw-semibold">
+ [[post-queue:content]]
+ </div>
+ {{{ if ./canEdit }}}
+ <button data-action="editContent" class="btn btn-ghost btn-sm ff-secondary border text-xs">Edit</button>
+ {{{ end }}}
+ </div>
+ <div class="post-content mb-auto text-break px-3 py-0 h-100">{posts.data.content}</div>
<div class="post-content-editable flex-grow-1 hidden">
<textarea class="form-control w-100 h-100 p-3">{posts.data.rawContent}</textarea>
</div>
@@ -208,6 +233,26 @@
<label class="text-secondary form-text mb-2">[[post-queue:links-in-this-post]]</label>
<ul component="post-queue/link-container/list" class="text-sm"></ul>
</div>
+ {{{ if (posts.type == "topic") }}}
+ <div class="border-top mx-3 py-3">
+ <label class="text-secondary form-text mb-2">[[post-queue:thumbs-in-this-post]]</label>
+ <div class="thumb-list d-flex gap-3 flex-wrap">
+ {{{ each posts.data.thumbs }}}
+ <div class="position-relative">
+ <a class="d-inline-block" href="#">
+ <img class="rounded-1 bg-light" style="width:auto; max-width: 5.33rem; height: 3.33rem; object-fit: contain;" src="{escape(@value)}" />
+ </a>
+ <a href="#" data-action="removeThumb" class="link-danger position-absolute btn top-0 start-100 translate-middle p-1"><i class="fa-solid fa-circle-xmark"></i></button>
+ </div>
+ {{{ end }}}
+ <a class="btn btn-ghost d-inline-block p-0" href="#" data-action="uploadThumb">
+ <div class="d-flex align-items-center justify-content-center" style="width: 3.33rem; max-width: 5.33rem; height: 3.33rem;">
+ <i class="fa-solid fa-upload"></i>
+ </div>
+ </a>
+ </div>
+ </div>
+ {{{ end }}}
</div>
</div>
</div>