| 1 | <template> |
| 2 | <div class="configured-sources-list"> |
| 3 | <div v-if="showToolbar" class="mb-3 flex items-center justify-end gap-2"> |
| 4 | <div class="info flex grow gap-5"> |
| 5 | <n-popover overlap placement="bottom-start"> |
| 6 | <template #trigger> |
| 7 | <div class="bg-default rounded-lg"> |
| 8 | <n-button size="small" class="cursor-help!"> |
| 9 | <template #icon> |
| 10 | <Icon :name="InfoIcon" /> |
| 11 | </template> |
| 12 | </n-button> |
| 13 | </div> |
| 14 | </template> |
| 15 | <div class="flex flex-col gap-2"> |
| 16 | <div class="box"> |
| 17 | Total: |
| 18 | <code>{{ totalConfiguredSources }}</code> |
| 19 | </div> |
| 20 | </div> |
| 21 | </n-popover> |
| 22 | </div> |
| 23 | <div class="actions flex items-center gap-2"> |
| 24 | <NewConfiguredSourceButton |
| 25 | :disabled-sources="configuredSourcesList" |
| 26 | @success="getConfiguredSources()" |
| 27 | /> |
| 28 | </div> |
| 29 | </div> |
| 30 | <n-spin :show="loading" class="min-h-32"> |
| 31 | <div v-if="configuredSourcesList.length" class="list grid-auto-fill-250 grid gap-4"> |
| 32 | <ConfiguredSourceItem |
| 33 | v-for="source of configuredSourcesList" |
| 34 | :key="source" |
| 35 | :source |
| 36 | class="item-appear item-appear-bottom item-appear-005" |
| 37 | @deleted="getConfiguredSources()" |
| 38 | /> |
| 39 | </div> |
| 40 | <template v-else> |
| 41 | <n-empty v-if="!loading" description="No items found" class="h-48 justify-center" /> |
| 42 | </template> |
| 43 | </n-spin> |
| 44 | </div> |
| 45 | </template> |
| 46 | |
| 47 | <script setup lang="ts"> |
| 48 | import type { SourceName } from "@/types/incidentManagement/sources.d" |
| 49 | import { NButton, NEmpty, NPopover, NSpin, useMessage } from "naive-ui" |
| 50 | import { computed, onBeforeMount, ref } from "vue" |
| 51 | import Api from "@/api" |
| 52 | import Icon from "@/components/common/Icon.vue" |
| 53 | import ConfiguredSourceItem from "./ConfiguredSourceItem.vue" |
| 54 | import NewConfiguredSourceButton from "./NewConfiguredSourceButton.vue" |
| 55 | |
| 56 | const { showToolbar = true } = defineProps<{ showToolbar?: boolean }>() |
| 57 | |
| 58 | const emit = defineEmits<{ |
| 59 | ( |
| 60 | e: "mounted", |
| 61 | value: { |
| 62 | reload: () => void |
| 63 | } |
| 64 | ): void |
| 65 | (e: "loaded", value: number): void |
| 66 | }>() |
| 67 | |
| 68 | const InfoIcon = "carbon:information" |
| 69 | const message = useMessage() |
| 70 | const loading = ref(false) |
| 71 | const configuredSourcesList = ref<SourceName[]>([]) |
| 72 | const totalConfiguredSources = computed(() => configuredSourcesList.value.length) |
| 73 | |
| 74 | function getConfiguredSources() { |
| 75 | loading.value = true |
| 76 | |
| 77 | Api.incidentManagement.sources |
| 78 | .getConfiguredSources() |
| 79 | .then(res => { |
| 80 | if (res.data.success) { |
| 81 | configuredSourcesList.value = res.data?.sources || [] |
| 82 | } else { |
| 83 | message.warning(res.data?.message || "An error occurred. Please try again later.") |
| 84 | } |
| 85 | }) |
| 86 | .catch(err => { |
| 87 | message.error(err.response?.data?.message || "An error occurred. Please try again later.") |
| 88 | }) |
| 89 | .finally(() => { |
| 90 | loading.value = false |
| 91 | emit("loaded", configuredSourcesList.value.length) |
| 92 | }) |
| 93 | } |
| 94 | |
| 95 | onBeforeMount(() => { |
| 96 | getConfiguredSources() |
| 97 | |
| 98 | emit("mounted", { |
| 99 | reload: getConfiguredSources |
| 100 | }) |
| 101 | }) |
| 102 | </script> |