| 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 flex-col gap-4 py-1"> |
| 8 | <div>This will download ALL Sigma queries, are you sure you want to proceed?</div> |
| 9 | |
| 10 | <div class="flex justify-between gap-2"> |
| 11 | <n-button quaternary size="small" @click="closePopup()">Close</n-button> |
| 12 | <n-button :loading type="primary" size="small" @click="downloadQueries()">Yes I'm sure</n-button> |
| 13 | </div> |
| 14 | </div> |
| 15 | </n-popover> |
| 16 | </template> |
| 17 | |
| 18 | <script setup lang="ts"> |
| 19 | import { NButton, NPopover, useMessage } from "naive-ui" |
| 20 | import { ref } from "vue" |
| 21 | import Api from "@/api" |
| 22 | |
| 23 | const emit = defineEmits<{ |
| 24 | (e: "updated"): void |
| 25 | }>() |
| 26 | |
| 27 | const loading = defineModel<boolean | undefined>("loading", { default: false }) |
| 28 | |
| 29 | const show = ref(false) |
| 30 | const lastShow = ref(Date.now()) |
| 31 | const message = useMessage() |
| 32 | |
| 33 | function togglePopup() { |
| 34 | if (Date.now() - lastShow.value > 500) { |
| 35 | show.value = !show.value |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | function closePopup() { |
| 40 | lastShow.value = Date.now() |
| 41 | show.value = false |
| 42 | } |
| 43 | |
| 44 | function downloadQueries() { |
| 45 | loading.value = true |
| 46 | |
| 47 | Api.sigma |
| 48 | .downloadRules() |
| 49 | .then(res => { |
| 50 | if (res.data.success) { |
| 51 | emit("updated") |
| 52 | message.success(res.data?.message || "Sigma queries downloaded successfully") |
| 53 | } else { |
| 54 | message.warning(res.data?.message || "An error occurred. Please try again later.") |
| 55 | } |
| 56 | }) |
| 57 | .catch(err => { |
| 58 | message.error(err.response?.data?.message || "An error occurred. Please try again later.") |
| 59 | }) |
| 60 | .finally(() => { |
| 61 | loading.value = false |
| 62 | }) |
| 63 | } |
| 64 | </script> |