main
vue 76 lines 2.08 KB
Raw
1 <template>
2 <n-popover v-model:show="show" trigger="manual" to="body" content-class="px-0" @clickoutside="closePopup()">
3 <template #trigger>
4 <slot :loading :toggle-popup />
5 </template>
6
7 <div class="flex max-w-80 min-w-72 flex-col gap-2 py-1">
8 <div>Choose the level to load:</div>
9
10 <n-checkbox-group v-model:value="ruleLevels" class="flex gap-4" :disabled="loading">
11 <n-checkbox value="high" label="High" />
12 <n-checkbox value="critical" label="Critical" />
13 </n-checkbox-group>
14
15 <p class="text-right">* It may take several minutes</p>
16
17 <div class="flex justify-between gap-2">
18 <n-button quaternary size="small" @click="closePopup()">Close</n-button>
19 <n-button :disabled="!isValid" :loading type="primary" size="small" @click="uploadQueries()">
20 Upload
21 </n-button>
22 </div>
23 </div>
24 </n-popover>
25 </template>
26
27 <script setup lang="ts">
28 import type { SigmaRuleLevels } from "@/types/sigma.d"
29 import { NButton, NCheckbox, NCheckboxGroup, NPopover, useMessage } from "naive-ui"
30 import { computed, ref } from "vue"
31 import Api from "@/api"
32
33 const emit = defineEmits<{
34 (e: "updated"): void
35 }>()
36
37 const loading = defineModel<boolean | undefined>("loading", { default: false })
38
39 const show = ref(false)
40 const lastShow = ref(Date.now())
41 const message = useMessage()
42 const ruleLevels = ref<SigmaRuleLevels[]>([])
43 const isValid = computed(() => !!ruleLevels.value.length)
44
45 function togglePopup() {
46 if (Date.now() - lastShow.value > 500) {
47 show.value = !show.value
48 }
49 }
50
51 function closePopup() {
52 lastShow.value = Date.now()
53 show.value = false
54 }
55
56 function uploadQueries() {
57 loading.value = true
58
59 Api.sigma
60 .uploadRules(ruleLevels.value)
61 .then(res => {
62 if (res.data.success) {
63 emit("updated")
64 message.success(res.data?.message || "Successfully uploaded the Sigma queries to the database")
65 } else {
66 message.warning(res.data?.message || "An error occurred. Please try again later.")
67 }
68 })
69 .catch(err => {
70 message.error(err.response?.data?.message || "An error occurred. Please try again later.")
71 })
72 .finally(() => {
73 loading.value = false
74 })
75 }
76 </script>