Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support batch publish/unpublish posts #6123

Merged
merged 4 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 52 additions & 3 deletions ui/console-src/modules/contents/posts/PostList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,52 @@ const handleDeleteInBatch = async () => {
});
};

watch(selectedPostNames, (newValue) => {
checkedAll.value = newValue.length === posts.value?.length;
});
const handlePublishInBatch = async () => {
Dialog.info({
title: t("core.post.operations.publish_in_batch.title"),
description: t("core.post.operations.publish_in_batch.description"),
confirmText: t("core.common.buttons.confirm"),
cancelText: t("core.common.buttons.cancel"),
onConfirm: async () => {
for (const i in selectedPostNames.value) {
const name = selectedPostNames.value[i];
await consoleApiClient.content.post.publishPost({ name });
}

await refetch();
selectedPostNames.value = [];

Toast.success(t("core.common.toast.publish_success"));
},
});
};

const handleCancelPublishInBatch = async () => {
Dialog.warning({
title: t("core.post.operations.cancel_publish_in_batch.title"),
description: t("core.post.operations.cancel_publish_in_batch.description"),
confirmText: t("core.common.buttons.confirm"),
cancelText: t("core.common.buttons.cancel"),
onConfirm: async () => {
for (const i in selectedPostNames.value) {
const name = selectedPostNames.value[i];
await consoleApiClient.content.post.unpublishPost({ name });
}

await refetch();
selectedPostNames.value = [];

Toast.success(t("core.common.toast.cancel_publish_success"));
},
});
};

watch(
() => selectedPostNames.value,
(newValue) => {
checkedAll.value = newValue.length === posts.value?.length;
}
);
</script>
<template>
<PostSettingModal
Expand Down Expand Up @@ -349,6 +392,12 @@ watch(selectedPostNames, (newValue) => {
<div class="flex w-full flex-1 items-center sm:w-auto">
<SearchInput v-if="!selectedPostNames.length" v-model="keyword" />
<VSpace v-else>
<VButton @click="handlePublishInBatch">
{{ $t("core.common.buttons.publish") }}
</VButton>
<VButton @click="handleCancelPublishInBatch">
{{ $t("core.common.buttons.cancel_publish") }}
</VButton>
<VButton type="danger" @click="handleDeleteInBatch">
{{ $t("core.common.buttons.delete") }}
</VButton>
Expand Down
10 changes: 10 additions & 0 deletions ui/src/locales/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,16 @@ core:
description: >-
This operation will move the posts to the recycle bin, and it can be
restored from the recycle bin later.
publish_in_batch:
title: Publish posts
description: >-
Batch publish posts, the selected posts will be set to published
status
cancel_publish_in_batch:
title: Cancel publish posts
description: >-
Batch cancel publish posts, the selected posts will be set to
unpublished status
filters:
status:
items:
Expand Down
6 changes: 6 additions & 0 deletions ui/src/locales/zh-CN.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ core:
delete_in_batch:
title: 删除所选文章
description: 该操作会将文章放入回收站,后续可以从回收站恢复。
publish_in_batch:
title: 发布文章
description: 批量发布文章,所选文章会被设置为发布状态
cancel_publish_in_batch:
title: 取消发布文章
description: 批量取消发布文章,所选文章会被设置为未发布状态
filters:
status:
items:
Expand Down
6 changes: 6 additions & 0 deletions ui/src/locales/zh-TW.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ core:
delete_in_batch:
title: 刪除所選文章
description: 該操作會將文章放入回收站,後續可以從回收站恢復。
publish_in_batch:
title: 發布文章
description: 批量發佈文章,所選文章會被設置為發佈狀態
cancel_publish_in_batch:
title: 取消發佈文章
description: 批量取消發佈文章,所選文章會被設置為未發布狀態
filters:
status:
items:
Expand Down