| 1 | <template> |
| 2 | <n-spin :show="loading"> |
| 3 | <div class="header flex items-center justify-end gap-2"> |
| 4 | <div class="info flex grow gap-5"> |
| 5 | <div class="box"> |
| 6 | Total: |
| 7 | <code>{{ flowList.length }}</code> |
| 8 | </div> |
| 9 | </div> |
| 10 | </div> |
| 11 | <div class="my-3 flex min-h-52 flex-col gap-2"> |
| 12 | <template v-if="flowList.length"> |
| 13 | <AgentFlowItem |
| 14 | v-for="item of flowList" |
| 15 | :key="item.id" |
| 16 | :flow="item" |
| 17 | embedded |
| 18 | class="item-appear item-appear-bottom item-appear-005" |
| 19 | /> |
| 20 | </template> |
| 21 | <template v-else> |
| 22 | <n-empty v-if="!loading" description="No items found" class="h-48 justify-center" /> |
| 23 | </template> |
| 24 | </div> |
| 25 | </n-spin> |
| 26 | </template> |
| 27 | |
| 28 | <script setup lang="ts"> |
| 29 | import type { Agent } from "@/types/agents.d" |
| 30 | import type { FlowResult } from "@/types/flow.d" |
| 31 | import { NEmpty, NSpin, useMessage } from "naive-ui" |
| 32 | import { nanoid } from "nanoid" |
| 33 | import { onBeforeMount, ref, toRefs } from "vue" |
| 34 | import Api from "@/api" |
| 35 | import AgentFlowItem from "./AgentFlowItem.vue" |
| 36 | |
| 37 | interface FlowResultExt extends FlowResult { |
| 38 | id?: string |
| 39 | } |
| 40 | |
| 41 | const props = defineProps<{ |
| 42 | agent: Agent |
| 43 | }>() |
| 44 | const { agent } = toRefs(props) |
| 45 | |
| 46 | const message = useMessage() |
| 47 | const loading = ref(false) |
| 48 | const flowList = ref<FlowResultExt[]>([]) |
| 49 | |
| 50 | function getData() { |
| 51 | loading.value = true |
| 52 | |
| 53 | Api.flow |
| 54 | .getAllByAgent(agent.value.hostname) |
| 55 | .then(res => { |
| 56 | if (res.data.success) { |
| 57 | flowList.value = ((res.data.results as FlowResultExt[]) || []).map(o => { |
| 58 | o.id = nanoid() |
| 59 | return o |
| 60 | }) |
| 61 | } else { |
| 62 | message.warning(res.data?.message || "An error occurred. Please try again later.") |
| 63 | } |
| 64 | }) |
| 65 | .catch(err => { |
| 66 | message.error(err.response?.data?.message || "An error occurred. Please try again later.") |
| 67 | |
| 68 | // MOCK |
| 69 | /* |
| 70 | flowList.value = flow_results |
| 71 | */ |
| 72 | }) |
| 73 | .finally(() => { |
| 74 | loading.value = false |
| 75 | }) |
| 76 | } |
| 77 | |
| 78 | onBeforeMount(() => { |
| 79 | getData() |
| 80 | }) |
| 81 | </script> |