ff-admin/src/components/admin/settings/template/TemplateListItem.vue

89 lines
3.2 KiB
Vue
Raw Normal View History

2024-12-22 10:29:31 +01:00
<template>
<div class="flex flex-col h-fit w-full border border-primary rounded-md">
<div class="bg-primary p-2 text-white flex flex-row justify-between items-center">
<p>{{ template.template }}</p>
2024-12-24 10:24:35 +01:00
<div class="flex flex-row justify-end w-24">
2024-12-22 10:29:31 +01:00
<RouterLink
v-if="can('update', 'settings', 'template')"
:to="{ name: 'admin-settings-template-edit', params: { id: template.id } }"
>
<PencilIcon class="w-5 h-5 p-1 box-content cursor-pointer" />
2024-12-24 10:24:35 +01:00
</RouterLink>
<button v-if="status == null" class="!p-0 !h-fit !w-fit" title="duplizieren" @click="cloneElement">
<DocumentDuplicateIcon class="w-5 h-5 p-1 box-content pointer-events-none" />
</button>
<Spinner v-else-if="status == 'loading'" class="my-auto" />
<SuccessCheckmark v-else-if="status?.status == 'success'" />
<FailureXMark v-else-if="status?.status == 'failed'" />
2024-12-22 10:29:31 +01:00
<div v-if="can('delete', 'settings', 'template')" @click="openDeleteModal">
<TrashIcon class="w-5 h-5 p-1 box-content cursor-pointer" />
</div>
</div>
</div>
<div class="flex flex-col p-2">
<div class="flex flex-row gap-2">
<p class="min-w-16">Beschreibung:</p>
<p class="grow overflow-hidden">{{ template.description }}</p>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import { defineComponent, defineAsyncComponent, markRaw, type PropType } from "vue";
import { mapState, mapActions } from "pinia";
2024-12-24 10:24:35 +01:00
import { PencilIcon, TrashIcon, DocumentDuplicateIcon } from "@heroicons/vue/24/outline";
2024-12-22 10:29:31 +01:00
import { useAbilityStore } from "@/stores/ability";
import { useModalStore } from "@/stores/modal";
import type { TemplateViewModel } from "../../../../viewmodels/admin/template.models";
2024-12-24 10:24:35 +01:00
import { useTemplateStore } from "@/stores/admin/template";
import Spinner from "@/components/Spinner.vue";
import SuccessCheckmark from "@/components/SuccessCheckmark.vue";
import FailureXMark from "@/components/FailureXMark.vue";
2024-12-22 10:29:31 +01:00
</script>
<script lang="ts">
export default defineComponent({
props: {
template: { type: Object as PropType<TemplateViewModel>, default: {} },
},
2024-12-24 10:24:35 +01:00
data() {
return {
status: null as null | "loading" | { status: "success" | "failed"; reason?: string },
timeout: undefined as any,
};
},
2024-12-22 10:29:31 +01:00
computed: {
...mapState(useAbilityStore, ["can"]),
},
2024-12-24 10:24:35 +01:00
beforeUnmount() {
try {
clearTimeout(this.timeout);
} catch (error) {}
},
2024-12-22 10:29:31 +01:00
methods: {
...mapActions(useModalStore, ["openModal"]),
2024-12-24 10:24:35 +01:00
...mapActions(useTemplateStore,["cloneTemplate"]),
2024-12-22 10:29:31 +01:00
openDeleteModal() {
this.openModal(
markRaw(defineAsyncComponent(() => import("@/components/admin/settings/template/DeleteTemplateModal.vue"))),
this.template.id
);
},
2024-12-24 10:24:35 +01:00
cloneElement(){
this.cloneTemplate(this.template.id)
.then((res) => {
this.status = { status: "success" };
this.timeout = setTimeout(() => {
this.status = null;
this.$router.push({ name: "admin-settings-template-edit", params: { id: res.data } });
}, 2000);
})
.catch(() => {
this.status = { status: "failed" };
});
}
2024-12-22 10:29:31 +01:00
},
});
</script>