| 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 min-w-52 flex-col justify-center gap-2 py-1"> |
| 8 | <div class="flex items-center gap-2"> |
| 9 | <n-button :loading type="success" @click="updateActive(true)">Activates all Sigma queries</n-button> |
| 10 | <n-button :loading @click="updateActive(false)">Deactivates all Sigma queries</n-button> |
| 11 | </div> |
| 12 | |
| 13 | <p class="text-right">* It may take several minutes</p> |
| 14 | |
| 15 | <div class="flex justify-between gap-2"> |
| 16 | <n-button quaternary size="small" @click="closePopup()">Close</n-button> |
| 17 | </div> |
| 18 | </div> |
| 19 | </n-popover> |
| 20 | </template> |
| 21 | |
| 22 | <script setup lang="ts"> |
| 23 | import { NButton, NPopover, useMessage } from "naive-ui" |
| 24 | import { ref } from "vue" |
| 25 | import Api from "@/api" |
| 26 | |
| 27 | const emit = defineEmits<{ |
| 28 | (e: "updated"): void |
| 29 | }>() |
| 30 | |
| 31 | const loading = defineModel<boolean | undefined>("loading", { default: false }) |
| 32 | |
| 33 | const show = ref(false) |
| 34 | const lastShow = ref(Date.now()) |
| 35 | const message = useMessage() |
| 36 | |
| 37 | function togglePopup() { |
| 38 | if (Date.now() - lastShow.value > 500) { |
| 39 | show.value = !show.value |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | function closePopup() { |
| 44 | lastShow.value = Date.now() |
| 45 | show.value = false |
| 46 | } |
| 47 | |
| 48 | function updateActive(active: boolean) { |
| 49 | loading.value = true |
| 50 | |
| 51 | const methods = active ? "activateAllQueries" : "deactivateAllQueries" |
| 52 | |
| 53 | Api.sigma[methods]() |
| 54 | .then(res => { |
| 55 | if (res.data.success) { |
| 56 | emit("updated") |
| 57 | message.success(res.data?.message || "Sigma queries updated successfully") |
| 58 | } else { |
| 59 | message.warning(res.data?.message || "An error occurred. Please try again later.") |
| 60 | } |
| 61 | }) |
| 62 | .catch(err => { |
| 63 | message.error(err.response?.data?.message || "An error occurred. Please try again later.") |
| 64 | }) |
| 65 | .finally(() => { |
| 66 | loading.value = false |
| 67 | }) |
| 68 | } |
| 69 | </script> |