2023-07-20 08:10:18 +00:00
|
|
|
<script lang="ts" setup>
|
2024-06-26 10:42:50 +00:00
|
|
|
import EntityFieldItems from "@/components/entity-fields/EntityFieldItems.vue";
|
|
|
|
import StatusDotField from "@/components/entity-fields/StatusDotField.vue";
|
|
|
|
import EntityDropdownItems from "@/components/entity/EntityDropdownItems.vue";
|
|
|
|
import { postLabels } from "@/constants/labels";
|
|
|
|
import { usePermission } from "@/utils/permission";
|
|
|
|
import { useEntityFieldItemExtensionPoint } from "@console/composables/use-entity-extension-points";
|
|
|
|
import { useOperationItemExtensionPoint } from "@console/composables/use-operation-extension-points";
|
|
|
|
import type { ListedPost, Post } from "@halo-dev/api-client";
|
|
|
|
import { consoleApiClient } from "@halo-dev/api-client";
|
2023-07-20 08:10:18 +00:00
|
|
|
import {
|
|
|
|
Dialog,
|
|
|
|
Toast,
|
|
|
|
VDropdownDivider,
|
|
|
|
VDropdownItem,
|
|
|
|
VEntity,
|
|
|
|
} from "@halo-dev/components";
|
2024-06-26 10:42:50 +00:00
|
|
|
import type { EntityFieldItem, OperationItem } from "@halo-dev/console-shared";
|
2023-09-01 03:02:12 +00:00
|
|
|
import { useQueryClient } from "@tanstack/vue-query";
|
2023-07-20 08:10:18 +00:00
|
|
|
import type { Ref } from "vue";
|
2024-05-27 08:26:58 +00:00
|
|
|
import { computed, inject, markRaw, ref, toRefs } from "vue";
|
2024-06-26 10:42:50 +00:00
|
|
|
import { useI18n } from "vue-i18n";
|
2023-08-25 09:02:12 +00:00
|
|
|
import { useRouter } from "vue-router";
|
2023-09-01 03:02:12 +00:00
|
|
|
import ContributorsField from "./entity-fields/ContributorsField.vue";
|
|
|
|
import PublishStatusField from "./entity-fields/PublishStatusField.vue";
|
2024-05-24 04:58:51 +00:00
|
|
|
import PublishTimeField from "./entity-fields/PublishTimeField.vue";
|
2024-06-26 10:42:50 +00:00
|
|
|
import TitleField from "./entity-fields/TitleField.vue";
|
|
|
|
import VisibleField from "./entity-fields/VisibleField.vue";
|
2023-07-20 08:10:18 +00:00
|
|
|
|
|
|
|
const { currentUserHasPermission } = usePermission();
|
|
|
|
const { t } = useI18n();
|
|
|
|
const queryClient = useQueryClient();
|
2023-08-25 09:02:12 +00:00
|
|
|
const router = useRouter();
|
2023-07-20 08:10:18 +00:00
|
|
|
|
|
|
|
const props = withDefaults(
|
|
|
|
defineProps<{
|
|
|
|
post: ListedPost;
|
|
|
|
isSelected?: boolean;
|
|
|
|
}>(),
|
|
|
|
{
|
|
|
|
isSelected: false,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2023-08-31 03:36:13 +00:00
|
|
|
const { post } = toRefs(props);
|
|
|
|
|
2023-07-20 08:10:18 +00:00
|
|
|
const emit = defineEmits<{
|
|
|
|
(event: "open-setting-modal", post: Post): void;
|
|
|
|
}>();
|
|
|
|
|
|
|
|
const selectedPostNames = inject<Ref<string[]>>("selectedPostNames", ref([]));
|
|
|
|
|
|
|
|
const handleDelete = async () => {
|
|
|
|
Dialog.warning({
|
|
|
|
title: t("core.post.operations.delete.title"),
|
|
|
|
description: t("core.post.operations.delete.description"),
|
|
|
|
confirmType: "danger",
|
|
|
|
confirmText: t("core.common.buttons.confirm"),
|
|
|
|
cancelText: t("core.common.buttons.cancel"),
|
|
|
|
onConfirm: async () => {
|
2024-06-25 04:31:44 +00:00
|
|
|
await consoleApiClient.content.post.recyclePost({
|
2023-07-20 08:10:18 +00:00
|
|
|
name: props.post.post.metadata.name,
|
|
|
|
});
|
|
|
|
await queryClient.invalidateQueries({ queryKey: ["posts"] });
|
|
|
|
|
|
|
|
Toast.success(t("core.common.toast.delete_success"));
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
2023-08-25 09:02:12 +00:00
|
|
|
|
2023-08-31 10:36:12 +00:00
|
|
|
const { operationItems } = useOperationItemExtensionPoint<ListedPost>(
|
2023-08-25 09:02:12 +00:00
|
|
|
"post:list-item:operation:create",
|
2023-08-31 03:36:13 +00:00
|
|
|
post,
|
2023-08-31 10:36:12 +00:00
|
|
|
computed((): OperationItem<ListedPost>[] => [
|
2024-05-27 08:26:58 +00:00
|
|
|
{
|
|
|
|
priority: 0,
|
|
|
|
component: markRaw(VDropdownItem),
|
|
|
|
label: t("core.common.buttons.publish"),
|
|
|
|
action: async () => {
|
2024-06-25 04:31:44 +00:00
|
|
|
await consoleApiClient.content.post.publishPost({
|
2024-05-27 08:26:58 +00:00
|
|
|
name: props.post.post.metadata.name,
|
|
|
|
});
|
|
|
|
|
|
|
|
Toast.success(t("core.common.toast.publish_success"));
|
|
|
|
|
|
|
|
queryClient.invalidateQueries({
|
|
|
|
queryKey: ["posts"],
|
|
|
|
});
|
|
|
|
},
|
|
|
|
hidden:
|
|
|
|
props.post.post.metadata.labels?.[postLabels.PUBLISHED] == "true" ||
|
|
|
|
props.post.post.metadata.labels?.[postLabels.SCHEDULING_PUBLISH] ==
|
|
|
|
"true",
|
|
|
|
},
|
2023-08-25 09:02:12 +00:00
|
|
|
{
|
|
|
|
priority: 10,
|
|
|
|
component: markRaw(VDropdownItem),
|
|
|
|
label: t("core.common.buttons.edit"),
|
|
|
|
permissions: [],
|
|
|
|
action: () => {
|
|
|
|
router.push({
|
|
|
|
name: "PostEditor",
|
|
|
|
query: { name: props.post.post.metadata.name },
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
priority: 20,
|
|
|
|
component: markRaw(VDropdownItem),
|
|
|
|
label: t("core.common.buttons.setting"),
|
|
|
|
permissions: [],
|
|
|
|
action: () => {
|
|
|
|
emit("open-setting-modal", props.post.post);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
priority: 30,
|
|
|
|
component: markRaw(VDropdownDivider),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
priority: 40,
|
|
|
|
component: markRaw(VDropdownItem),
|
|
|
|
props: {
|
2024-05-27 08:26:58 +00:00
|
|
|
type: "danger",
|
|
|
|
},
|
|
|
|
label: t("core.common.buttons.cancel_publish"),
|
|
|
|
action: async () => {
|
2024-06-25 04:31:44 +00:00
|
|
|
await consoleApiClient.content.post.unpublishPost({
|
2024-05-27 08:26:58 +00:00
|
|
|
name: props.post.post.metadata.name,
|
|
|
|
});
|
|
|
|
|
|
|
|
Toast.success(t("core.common.toast.cancel_publish_success"));
|
|
|
|
|
|
|
|
queryClient.invalidateQueries({
|
|
|
|
queryKey: ["posts"],
|
|
|
|
});
|
|
|
|
},
|
|
|
|
hidden:
|
|
|
|
props.post.post.metadata.labels?.[postLabels.PUBLISHED] !== "true" &&
|
|
|
|
props.post.post.metadata.labels?.[postLabels.SCHEDULING_PUBLISH] !==
|
|
|
|
"true",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
priority: 50,
|
|
|
|
component: markRaw(VDropdownItem),
|
|
|
|
props: {
|
2023-08-25 09:02:12 +00:00
|
|
|
type: "danger",
|
|
|
|
},
|
|
|
|
label: t("core.common.buttons.delete"),
|
|
|
|
permissions: [],
|
|
|
|
action: handleDelete,
|
|
|
|
},
|
2023-08-31 03:36:13 +00:00
|
|
|
])
|
2023-08-25 09:02:12 +00:00
|
|
|
);
|
2023-09-01 03:02:12 +00:00
|
|
|
|
|
|
|
const { startFields, endFields } = useEntityFieldItemExtensionPoint<ListedPost>(
|
|
|
|
"post:list-item:field:create",
|
|
|
|
post,
|
|
|
|
computed((): EntityFieldItem[] => [
|
|
|
|
{
|
|
|
|
priority: 10,
|
|
|
|
position: "start",
|
|
|
|
component: markRaw(TitleField),
|
|
|
|
props: {
|
|
|
|
post: props.post,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
priority: 10,
|
|
|
|
position: "end",
|
|
|
|
component: markRaw(ContributorsField),
|
|
|
|
props: {
|
|
|
|
post: props.post,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
priority: 20,
|
|
|
|
position: "end",
|
|
|
|
component: markRaw(PublishStatusField),
|
|
|
|
props: {
|
|
|
|
post: props.post,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
priority: 30,
|
|
|
|
position: "end",
|
|
|
|
component: markRaw(VisibleField),
|
2024-08-14 06:59:57 +00:00
|
|
|
permissions: ["system:posts:manage"],
|
2023-09-01 03:02:12 +00:00
|
|
|
props: {
|
|
|
|
post: props.post,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
priority: 40,
|
|
|
|
position: "end",
|
|
|
|
component: markRaw(StatusDotField),
|
|
|
|
props: {
|
|
|
|
tooltip: t("core.common.status.deleting"),
|
|
|
|
state: "warning",
|
|
|
|
animate: true,
|
|
|
|
},
|
|
|
|
hidden: !props.post.post.spec.deleted,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
priority: 50,
|
|
|
|
position: "end",
|
2024-05-24 04:58:51 +00:00
|
|
|
component: markRaw(PublishTimeField),
|
2023-09-01 03:02:12 +00:00
|
|
|
props: {
|
2024-05-24 04:58:51 +00:00
|
|
|
post: props.post,
|
2023-09-01 03:02:12 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
])
|
|
|
|
);
|
2023-07-20 08:10:18 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<VEntity :is-selected="isSelected">
|
|
|
|
<template
|
|
|
|
v-if="currentUserHasPermission(['system:posts:manage'])"
|
|
|
|
#checkbox
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
v-model="selectedPostNames"
|
|
|
|
:value="post.post.metadata.name"
|
|
|
|
name="post-checkbox"
|
|
|
|
type="checkbox"
|
|
|
|
/>
|
|
|
|
</template>
|
|
|
|
<template #start>
|
2023-09-01 03:02:12 +00:00
|
|
|
<EntityFieldItems :fields="startFields" />
|
2023-07-20 08:10:18 +00:00
|
|
|
</template>
|
|
|
|
<template #end>
|
2023-09-01 03:02:12 +00:00
|
|
|
<EntityFieldItems :fields="endFields" />
|
2023-07-20 08:10:18 +00:00
|
|
|
</template>
|
|
|
|
<template
|
|
|
|
v-if="currentUserHasPermission(['system:posts:manage'])"
|
|
|
|
#dropdownItems
|
|
|
|
>
|
2023-08-31 10:36:12 +00:00
|
|
|
<EntityDropdownItems :dropdown-items="operationItems" :item="post" />
|
2023-07-20 08:10:18 +00:00
|
|
|
</template>
|
|
|
|
</VEntity>
|
|
|
|
</template>
|