| 1 | <template> |
| 2 | <div class="scheduler-list"> |
| 3 | <n-spin :show="loading" class="min-h-48"> |
| 4 | <div class="min-h-52"> |
| 5 | <template v-if="jobs.length"> |
| 6 | <JobCard v-for="job of jobs" :key="job.id" :job class="mb-2" /> |
| 7 | </template> |
| 8 | <template v-else> |
| 9 | <n-empty v-if="!loading" description="No items found" class="h-48 justify-center" /> |
| 10 | </template> |
| 11 | </div> |
| 12 | </n-spin> |
| 13 | </div> |
| 14 | </template> |
| 15 | |
| 16 | <script setup lang="ts"> |
| 17 | import type { Job } from "@/types/scheduler.d" |
| 18 | import { NEmpty, NSpin, useMessage } from "naive-ui" |
| 19 | import { computed, onBeforeMount, ref } from "vue" |
| 20 | import Api from "@/api" |
| 21 | import JobCard from "./Item.vue" |
| 22 | |
| 23 | const message = useMessage() |
| 24 | const loadingJobs = ref(false) |
| 25 | const jobs = ref<Job[]>([]) |
| 26 | const loading = computed(() => loadingJobs.value) |
| 27 | |
| 28 | function getData() { |
| 29 | loadingJobs.value = true |
| 30 | |
| 31 | Api.scheduler |
| 32 | .getAllJobs() |
| 33 | .then(res => { |
| 34 | if (res.data.success) { |
| 35 | jobs.value = res.data.jobs || [] |
| 36 | } else { |
| 37 | message.warning(res.data?.message || "An error occurred. Please try again later.") |
| 38 | } |
| 39 | }) |
| 40 | .catch(err => { |
| 41 | message.error(err.response?.data?.message || "An error occurred. Please try again later.") |
| 42 | }) |
| 43 | .finally(() => { |
| 44 | loadingJobs.value = false |
| 45 | }) |
| 46 | } |
| 47 | |
| 48 | onBeforeMount(() => { |
| 49 | getData() |
| 50 | }) |
| 51 | </script> |