| 1 | <template> |
| 2 | <n-spin :show="loading"> |
| 3 | <CardStats |
| 4 | title="SOC Alerts" |
| 5 | :value="total" |
| 6 | :vertical |
| 7 | hovered |
| 8 | class="h-full cursor-pointer" |
| 9 | @click="routeSocAlerts().navigate()" |
| 10 | > |
| 11 | <template #icon> |
| 12 | <CardStatsIcon :icon-name="SOCIcon" boxed :box-size="40"></CardStatsIcon> |
| 13 | </template> |
| 14 | </CardStats> |
| 15 | </n-spin> |
| 16 | </template> |
| 17 | |
| 18 | <script setup lang="ts"> |
| 19 | import type { SocAlert } from "@/types/soc/alert.d" |
| 20 | import { NSpin, useMessage } from "naive-ui" |
| 21 | import { computed, onBeforeMount, ref, toRefs } from "vue" |
| 22 | import Api from "@/api" |
| 23 | import CardStats from "@/components/common/cards/CardStats.vue" |
| 24 | import CardStatsIcon from "@/components/common/cards/CardStatsIcon.vue" |
| 25 | import { useNavigation } from "@/composables/useNavigation" |
| 26 | |
| 27 | const props = defineProps<{ |
| 28 | vertical?: boolean |
| 29 | }>() |
| 30 | const { vertical } = toRefs(props) |
| 31 | |
| 32 | const SOCIcon = "carbon:security" |
| 33 | const { routeSocAlerts } = useNavigation() |
| 34 | const message = useMessage() |
| 35 | const loading = ref(false) |
| 36 | const alerts = ref<SocAlert[]>([]) |
| 37 | |
| 38 | const total = computed<number>(() => { |
| 39 | return alerts.value.length || 0 |
| 40 | }) |
| 41 | |
| 42 | function getData() { |
| 43 | loading.value = true |
| 44 | |
| 45 | Api.soc |
| 46 | .getAlerts() |
| 47 | .then(res => { |
| 48 | if (res.data.success) { |
| 49 | alerts.value = res.data?.alerts || [] |
| 50 | } else { |
| 51 | message.warning(res.data?.message || "An error occurred. Please try again later.") |
| 52 | } |
| 53 | }) |
| 54 | .catch(err => { |
| 55 | message.error(err.response?.data?.message || "An error occurred. Please try again later.") |
| 56 | }) |
| 57 | .finally(() => { |
| 58 | loading.value = false |
| 59 | }) |
| 60 | } |
| 61 | |
| 62 | onBeforeMount(() => { |
| 63 | getData() |
| 64 | }) |
| 65 | </script> |
| 66 | |
| 67 | <style lang="scss" scoped> |
| 68 | .n-spin-container { |
| 69 | :deep() { |
| 70 | .n-spin-content { |
| 71 | height: 100%; |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | </style> |