Skip to content

Commit

Permalink
feat: post queue bulk actions closes #10520, fix #10555,
Browse files Browse the repository at this point in the history
  • Loading branch information
barisusakli committed Apr 30, 2022
1 parent 1acbe4c commit 2317511
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 8 deletions.
11 changes: 10 additions & 1 deletion public/language/en-GB/post-queue.json
Expand Up @@ -18,5 +18,14 @@
"remove": "Remove",
"notify": "Notify",
"notify-user": "Notify User",
"confirm-reject": "Do you want to reject this post?"
"confirm-reject": "Do you want to reject this post?",
"bulk-actions": "Bulk Actions",
"accept-all": "Accept All",
"accept-selected": "Accept Selected",
"reject-all": "Reject All",
"reject-all-confirm": "Do you want to reject all posts?",
"reject-selected": "Reject Selected",
"reject-selected-confirm": "Do you want to reject selected posts?",
"bulk-accept-success": "%1 posts accepted",
"bulk-reject-success": "%1 posts rejected"
}
52 changes: 45 additions & 7 deletions public/src/client/post-queue.js
Expand Up @@ -13,6 +13,8 @@ define('forum/post-queue', [
privilege: 'moderate',
});

handleBulkActions();

$('.posts-list').on('click', '[data-action]', async function () {
function getMessage() {
return new Promise((resolve) => {
Expand All @@ -33,17 +35,13 @@ define('forum/post-queue', [
});
});
}
function confirmReject() {
return new Promise((resolve) => {
bootbox.confirm('[[post-queue:confirm-reject]]', resolve);
});
}

const parent = $(this).parents('[data-id]');
const action = $(this).attr('data-action');
const id = parent.attr('data-id');
const listContainer = parent.get(0).parentNode;

if ((!['accept', 'reject', 'notify'].includes(action)) || (action === 'reject' && !await confirmReject())) {
if ((!['accept', 'reject', 'notify'].includes(action)) || (action === 'reject' && !await confirmReject('[[post-queue:confirm-reject]]'))) {
return;
}

Expand All @@ -59,7 +57,11 @@ define('forum/post-queue', [
}

if (listContainer.childElementCount === 0) {
ajaxify.refresh();
if (ajaxify.data.singlePost) {
ajaxify.go('/post-queue' + window.location.search);
} else {
ajaxify.refresh();
}
}
});
return false;
Expand Down Expand Up @@ -102,6 +104,12 @@ define('forum/post-queue', [
$('[component="post/content"] img:not(.not-responsive)').addClass('img-responsive');
};

function confirmReject(msg) {
return new Promise((resolve) => {
bootbox.confirm(msg, resolve);
});
}

function handleContentEdit(displayClass, editableClass, inputSelector) {
$('.posts-list').on('click', displayClass, function () {
const el = $(this);
Expand Down Expand Up @@ -143,5 +151,35 @@ define('forum/post-queue', [
});
}

function handleBulkActions() {
$('[component="post-queue/bulk-actions"]').on('click', '[data-action]', async function () {
const bulkAction = $(this).attr('data-action');
let queueEls = $('.posts-list [data-id]');
if (bulkAction === 'accept-selected' || bulkAction === 'reject-selected') {
queueEls = queueEls.filter(
(i, el) => $(el).find('input[type="checkbox"]').is(':checked')
);
}
const ids = queueEls.map((i, el) => $(el).attr('data-id')).get();
const showConfirm = bulkAction === 'reject-all' || bulkAction === 'reject-selected';
if (!ids.length || (showConfirm && !(await confirmReject(`[[post-queue:${bulkAction}-confirm]]`)))) {
return;
}
const action = bulkAction.split('-')[0];
const promises = ids.map(id => socket.emit('posts.' + action, { id: id }));

Promise.allSettled(promises).then(function (results) {
const fulfilled = results.filter(res => res.status === 'fulfilled').length;
const errors = results.filter(res => res.status === 'rejected');
if (fulfilled) {
alerts.success(`[[post-queue:bulk-${action}-success, ${fulfilled}]]`);
ajaxify.refresh();
}

errors.forEach(res => alerts.error(res.reason));
});
});
}

return PostQueue;
});
1 change: 1 addition & 0 deletions src/controllers/mods.js
Expand Up @@ -194,5 +194,6 @@ modsController.postQueue = async function (req, res, next) {
allCategoriesUrl: `post-queue${helpers.buildQueryString(req.query, 'cid', '')}`,
pagination: pagination.create(page, pageCount),
breadcrumbs: helpers.buildBreadcrumbs(crumbs),
singlePost: !!id,
});
};

2 comments on commit 2317511

@ShlomoCode
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@barisusakli It is not better to indicate in confirm pop up how many posts will be rejected?
I.e. "Do you want to reject 5 selected posts?" And not only notify after: "% 1 posts rejected"

@barisusakli
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ShlomoCode good idea, added here 012860a

Please sign in to comment.