| 1 | <template> |
| 2 | <n-tooltip placement="top-end" @update:show="getNextRun()"> |
| 3 | <template #trigger> |
| 4 | <Icon :name="NextIcon" /> |
| 5 | </template> |
| 6 | <template #header>Next run time:</template> |
| 7 | <div> |
| 8 | <n-spin v-if="loadingNext" :size="12" /> |
| 9 | <span v-if="!loadingNext"> |
| 10 | {{ nextRunTime ? formatDate(nextRunTime, dFormats.datetimesec) : "-" }} |
| 11 | </span> |
| 12 | </div> |
| 13 | </n-tooltip> |
| 14 | </template> |
| 15 | |
| 16 | <script setup lang="ts"> |
| 17 | import { NSpin, NTooltip, useMessage } from "naive-ui" |
| 18 | import { ref, toRefs } from "vue" |
| 19 | import Api from "@/api" |
| 20 | import Icon from "@/components/common/Icon.vue" |
| 21 | import { useSettingsStore } from "@/stores/settings" |
| 22 | import { formatDate } from "@/utils/format" |
| 23 | |
| 24 | const props = defineProps<{ jobId: string }>() |
| 25 | const { jobId } = toRefs(props) |
| 26 | |
| 27 | const NextIcon = "carbon:view-next" |
| 28 | |
| 29 | const message = useMessage() |
| 30 | const dFormats = useSettingsStore().dateFormat |
| 31 | const loadingNext = ref(false) |
| 32 | const nextRunTime = ref<Date | null>(null) |
| 33 | |
| 34 | function getNextRun() { |
| 35 | if (nextRunTime.value) { |
| 36 | return |
| 37 | } |
| 38 | loadingNext.value = true |
| 39 | |
| 40 | Api.scheduler |
| 41 | .getNextRun(jobId.value) |
| 42 | .then(res => { |
| 43 | if (res.data.success) { |
| 44 | nextRunTime.value = res.data.next_run_time |
| 45 | } else { |
| 46 | message.warning(res.data?.message || "An error occurred. Please try again later.") |
| 47 | } |
| 48 | }) |
| 49 | .catch(err => { |
| 50 | message.error(err.response?.data?.message || "An error occurred. Please try again later.") |
| 51 | }) |
| 52 | .finally(() => { |
| 53 | loadingNext.value = false |
| 54 | }) |
| 55 | } |
| 56 | </script> |