|
4 | 4 | <div class="loader "></div> |
5 | 5 | <div class="absolute -bottom-1 -right-1 rounded-full bg-lightPrimary w-4 h-4 text-xs flex items-center justify-center text-white"> {{ jobsCount }}</div> |
6 | 6 | </div> |
7 | | - <div class="flex items-center justify-center" v-else-if="jobsCount > 0"> |
| 7 | + <div class="flex items-center justify-center" v-else-if="jobs.length > 0"> |
8 | 8 | <Tooltip> |
9 | 9 | <IconCheckCircleOutline class="w-8 h-8 text-green-500" /> |
10 | 10 | <template #tooltip> |
|
24 | 24 |
|
25 | 25 | <script setup lang="ts"> |
26 | 26 | import type { AdminUser } from 'adminforth'; |
27 | | - import { onMounted, ref, computed } from 'vue'; |
| 27 | + import { onMounted, onUnmounted, ref, computed } from 'vue'; |
28 | 28 | import { IconCheckCircleOutline } from '@iconify-prerendered/vue-flowbite'; |
29 | 29 | import { Tooltip } from '@/afcl'; |
30 | 30 | import { useI18n } from 'vue-i18n'; |
31 | 31 | import JobsList from './JobsList.vue'; |
32 | 32 | import type { IJob } from './utils'; |
33 | 33 | import { callAdminForthApi } from '@/utils'; |
| 34 | + import websocket from '@/websocket'; |
34 | 35 |
|
35 | 36 | const { t } = useI18n(); |
36 | 37 |
|
|
49 | 50 | }) |
50 | 51 |
|
51 | 52 | const jobsCount = computed(() => { |
52 | | - return jobs.value.length; |
| 53 | + return jobs.value.filter(job => job.status === 'IN_PROGRESS').length; |
53 | 54 | }) |
54 | 55 |
|
| 56 | +
|
| 57 | +
|
55 | 58 | onMounted(async () => { |
| 59 | + websocket.subscribe('/background-jobs', (data) => { |
| 60 | + const jobIndex = jobs.value.findIndex(job => job.id === data.jobId); |
| 61 | + if (jobIndex !== -1) { |
| 62 | + if (data.status) { |
| 63 | + jobs.value[jobIndex].status = data.status; |
| 64 | + } |
| 65 | + if (data.progress !== undefined) { |
| 66 | + jobs.value[jobIndex].progress = data.progress; |
| 67 | + } |
| 68 | + } else { |
| 69 | + jobs.value.push({ |
| 70 | + id: data.jobId, |
| 71 | + name: data.name || 'Unknown Job', |
| 72 | + status: data.status || 'IN_PROGRESS', |
| 73 | + progress: data.progress || 0, |
| 74 | + createdAt: data.createdAt || new Date().toISOString(), |
| 75 | + }); |
| 76 | + } |
| 77 | + }); |
| 78 | +
|
| 79 | +
|
56 | 80 | try { |
57 | 81 | const res = await callAdminForthApi({ |
58 | 82 | path: `/plugin/${props.meta.pluginInstanceId}/get-list-of-jobs`, |
|
64 | 88 | } |
65 | 89 | }); |
66 | 90 |
|
| 91 | +
|
| 92 | + onUnmounted(() => { |
| 93 | + websocket.unsubscribe('/background-jobs'); |
| 94 | + }); |
| 95 | +
|
67 | 96 | </script> |
68 | 97 |
|
69 | 98 |
|
|
0 commit comments