| 1 | <template> |
| 2 | <n-timeline> |
| 3 | <n-timeline-item |
| 4 | v-for="(item, $index) of history" |
| 5 | :key="item.label" |
| 6 | :type="$index === 0 ? 'success' : undefined" |
| 7 | :title="item.label" |
| 8 | :time="item.timeString" |
| 9 | :line-type="$index === history.length - 2 ? 'dashed' : undefined" |
| 10 | /> |
| 11 | </n-timeline> |
| 12 | </template> |
| 13 | |
| 14 | <script setup lang="ts"> |
| 15 | import type { SocAlert } from "@/types/soc/alert.d" |
| 16 | import _toNumber from "lodash/toSafeInteger" |
| 17 | import { NTimeline, NTimelineItem } from "naive-ui" |
| 18 | import { onBeforeMount, ref } from "vue" |
| 19 | import { useSettingsStore } from "@/stores/settings" |
| 20 | import dayjs from "@/utils/dayjs" |
| 21 | |
| 22 | const { alert } = defineProps<{ alert: SocAlert }>() |
| 23 | |
| 24 | const dFormats = useSettingsStore().dateFormat |
| 25 | |
| 26 | const history = ref< |
| 27 | { |
| 28 | timeString: string |
| 29 | label: string |
| 30 | }[] |
| 31 | >([]) |
| 32 | |
| 33 | function formatDate(timestamp: string | number, utc: boolean = true): string { |
| 34 | return dayjs(timestamp).utc(utc).format(dFormats.datetimesec) |
| 35 | } |
| 36 | |
| 37 | onBeforeMount(() => { |
| 38 | history.value.push({ |
| 39 | timeString: formatDate(alert.alert_source_event_time), |
| 40 | label: "Source event" |
| 41 | }) |
| 42 | |
| 43 | if (Object.keys(alert.modification_history).length) { |
| 44 | for (const key in alert.modification_history) { |
| 45 | const item = alert.modification_history[key] |
| 46 | history.value.push({ |
| 47 | timeString: formatDate(_toNumber(key) * 1000, false), |
| 48 | label: `${item?.action ?? ""} [${item?.user ?? ""}]` |
| 49 | }) |
| 50 | } |
| 51 | } |
| 52 | }) |
| 53 | </script> |