| 1 | <template> |
| 2 | <CardEntity embedded hoverable> |
| 3 | <template #headerMain> |
| 4 | {{ contentPack.name }} |
| 5 | </template> |
| 6 | <template #default> |
| 7 | {{ contentPack.description }} |
| 8 | </template> |
| 9 | <template #headerExtra> |
| 10 | <n-button |
| 11 | :loading="loadingProvision" |
| 12 | type="success" |
| 13 | size="small" |
| 14 | secondary |
| 15 | @click="provision(contentPack.name)" |
| 16 | > |
| 17 | <template #icon> |
| 18 | <Icon :name="DeployIcon" /> |
| 19 | </template> |
| 20 | Deploy |
| 21 | </n-button> |
| 22 | </template> |
| 23 | </CardEntity> |
| 24 | </template> |
| 25 | |
| 26 | <script setup lang="ts"> |
| 27 | import type { AvailableContentPack } from "@/types/stackProvisioning.d" |
| 28 | import { NButton, useMessage } from "naive-ui" |
| 29 | import { ref } from "vue" |
| 30 | import Api from "@/api" |
| 31 | import CardEntity from "@/components/common/cards/CardEntity.vue" |
| 32 | import Icon from "@/components/common/Icon.vue" |
| 33 | |
| 34 | const { contentPack } = defineProps<{ contentPack: AvailableContentPack }>() |
| 35 | |
| 36 | const emit = defineEmits<{ |
| 37 | (e: "provisioned"): void |
| 38 | }>() |
| 39 | |
| 40 | const DeployIcon = "mdi:package-variant-closed-check" |
| 41 | const loadingProvision = ref(false) |
| 42 | const message = useMessage() |
| 43 | |
| 44 | function provision(contentPackName: string) { |
| 45 | loadingProvision.value = true |
| 46 | |
| 47 | Api.stackProvisioning |
| 48 | .provisionContentPack(contentPackName) |
| 49 | .then(res => { |
| 50 | if (res.data.success) { |
| 51 | message.success(res.data?.message || "Content Pack Provisioned Successfully") |
| 52 | emit("provisioned") |
| 53 | } else { |
| 54 | message.warning(res.data?.message || "An error occurred. Please try again later.") |
| 55 | } |
| 56 | }) |
| 57 | .catch(err => { |
| 58 | message.error(err.response?.data?.message || "An error occurred. Please try again later.") |
| 59 | }) |
| 60 | .finally(() => { |
| 61 | loadingProvision.value = false |
| 62 | }) |
| 63 | } |
| 64 | </script> |