main
vue 61 lines 1.79 KB
Raw
1 <template>
2 <div class="grid-auto-fit-250 grid gap-2">
3 <CardKV v-for="item of propsSanitized" :key="item.key">
4 <template #key>
5 {{ item.key }}
6 </template>
7 <template #value>
8 <template v-if="item.key === 'customer_code' && item.val !== '-'">
9 <code class="text-primary cursor-pointer" @click="routeCustomer({ code: item.val }).navigate()">
10 {{ item.val }}
11 <Icon :name="LinkIcon" :size="13" class="relative top-0.5" />
12 </code>
13 </template>
14 <template v-else-if="item.key === 'velociraptor_id'">
15 <AgentVelociraptorIdForm v-model:velociraptor-id="item.val" :agent @updated="emit('updated')" />
16 </template>
17 <template v-else>
18 {{ item.val ?? "-" }}
19 </template>
20 </template>
21 </CardKV>
22 </div>
23 </template>
24
25 <script setup lang="ts">
26 import type { Agent } from "@/types/agents.d"
27 import { computed, toRefs } from "vue"
28 import CardKV from "@/components/common/cards/CardKV.vue"
29 import Icon from "@/components/common/Icon.vue"
30 import { useNavigation } from "@/composables/useNavigation"
31 import { useSettingsStore } from "@/stores/settings"
32 import { formatDate } from "@/utils/format"
33 import AgentVelociraptorIdForm from "./AgentVelociraptorIdForm.vue"
34
35 const props = defineProps<{
36 agent: Agent
37 }>()
38
39 const emit = defineEmits<{
40 (e: "updated"): void
41 }>()
42
43 const { agent } = toRefs(props)
44
45 const LinkIcon = "carbon:launch"
46 const dFormats = useSettingsStore().dateFormat
47 const { routeCustomer } = useNavigation()
48
49 const propsSanitized = computed(() => {
50 const obj = []
51 for (const key in agent.value) {
52 if (["wazuh_last_seen", "velociraptor_last_seen"].includes(key)) {
53 obj.push({ key, val: formatDate(Reflect.get(agent.value, key), dFormats.datetime) || "-" })
54 } else {
55 obj.push({ key, val: Reflect.get(agent.value, key) || "-" })
56 }
57 }
58
59 return obj
60 })
61 </script>